Correct Aphlict websocket URI construction after PHP8 compatibility changes
[phabricator.git] / src / view / phui / PHUIImageMaskView.php
blob6d899841c3cc15cfa4283708cc5607ec2186789e
1 <?php
3 final class PHUIImageMaskView extends AphrontTagView {
5 private $image;
6 private $withMask;
8 private $displayWidth;
9 private $displayHeight;
11 private $centerX;
12 private $centerY;
13 private $maskH;
14 private $maskW;
16 public function setImage($image) {
17 $this->image = $image;
18 return $this;
21 public function setDisplayWidth($width) {
22 $this->displayWidth = $width;
23 return $this;
26 public function setDisplayHeight($height) {
27 $this->displayHeight = $height;
28 return $this;
31 public function centerViewOnPoint($x, $y, $h, $w) {
32 $this->centerX = $x;
33 $this->centerY = $y;
34 $this->maskH = $h;
35 $this->maskW = $w;
36 return $this;
39 public function withMask($mask) {
40 $this->withMask = $mask;
41 return $this;
44 protected function getTagName() {
45 return 'div';
48 protected function getTagAttributes() {
49 require_celerity_resource('phui-image-mask-css');
51 $classes = array();
52 $classes[] = 'phui-image-mask';
54 $styles = array();
55 $styles[] = 'height: '.$this->displayHeight.'px;';
56 $styles[] = 'width: '.$this->displayWidth.'px;';
58 return array(
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;
76 $classes = array();
77 $classes[] = 'phui-image-mask-image';
79 $styles = array();
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;';
85 $mask = null;
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. */
89 $border = 300;
90 $left = round((($this->displayWidth - $this->maskW) / 2) - $border);
91 $top = round((($this->displayHeight - $this->maskH) / 2) - $border);
93 $mstyles = array();
94 $mstyles[] = 'left: '.$left.'px;';
95 $mstyles[] = 'top: '.$top.'px;';
96 $mstyles[] = 'height: '.$this->maskH.'px;';
97 $mstyles[] = 'width: '.$this->maskW.'px;';
99 $mask = phutil_tag(
100 'span',
101 array(
102 'class' => 'phui-image-mask-mask',
103 'style' => implode(' ', $mstyles),
105 null);
108 return phutil_tag(
109 'div',
110 array(
111 'class' => implode(' ', $classes),
112 'style' => implode(' ', $styles),
114 $mask);