3 final class PHUIImageMaskView
extends AphrontTagView
{
9 private $displayHeight;
16 public function setImage($image) {
17 $this->image
= $image;
21 public function setDisplayWidth($width) {
22 $this->displayWidth
= $width;
26 public function setDisplayHeight($height) {
27 $this->displayHeight
= $height;
31 public function centerViewOnPoint($x, $y, $h, $w) {
39 public function withMask($mask) {
40 $this->withMask
= $mask;
44 protected function getTagName() {
48 protected function getTagAttributes() {
49 require_celerity_resource('phui-image-mask-css');
52 $classes[] = 'phui-image-mask';
55 $styles[] = 'height: '.$this->displayHeight
.'px;';
56 $styles[] = 'width: '.$this->displayWidth
.'px;';
59 'class' => implode(' ', $classes),
60 'styles' => implode(' ', $styles),
65 protected function getTagContent() {
67 /* Center it in the middle of the selected area */
68 $center_x = round($this->centerX +
($this->maskW
/ 2));
69 $center_y = round($this->centerY +
($this->maskH
/ 2));
70 $center_x = round($center_x - ($this->displayWidth
/ 2));
71 $center_y = round($center_y - ($this->displayHeight
/ 2));
73 $center_x = -$center_x;
74 $center_y = -$center_y;
77 $classes[] = 'phui-image-mask-image';
80 $styles[] = 'height: '.$this->displayHeight
.'px;';
81 $styles[] = 'width: '.$this->displayWidth
.'px;';
82 $styles[] = 'background-image: url('.$this->image
.');';
83 $styles[] = 'background-position: '.$center_x.'px '.$center_y.'px;';
86 if ($this->withMask
) {
87 /* The mask is a 300px border around a transparent box.
88 so we do the math here to position the box correctly. */
90 $left = round((($this->displayWidth
- $this->maskW
) / 2) - $border);
91 $top = round((($this->displayHeight
- $this->maskH
) / 2) - $border);
94 $mstyles[] = 'left: '.$left.'px;';
95 $mstyles[] = 'top: '.$top.'px;';
96 $mstyles[] = 'height: '.$this->maskH
.'px;';
97 $mstyles[] = 'width: '.$this->maskW
.'px;';
102 'class' => 'phui-image-mask-mask',
103 'style' => implode(' ', $mstyles),
111 'class' => implode(' ', $classes),
112 'style' => implode(' ', $styles),