Path: blob/master/src/view/phui/PHUIImageMaskView.php
12249 views
<?php12final class PHUIImageMaskView extends AphrontTagView {34private $image;5private $withMask;67private $displayWidth;8private $displayHeight;910private $centerX;11private $centerY;12private $maskH;13private $maskW;1415public function setImage($image) {16$this->image = $image;17return $this;18}1920public function setDisplayWidth($width) {21$this->displayWidth = $width;22return $this;23}2425public function setDisplayHeight($height) {26$this->displayHeight = $height;27return $this;28}2930public function centerViewOnPoint($x, $y, $h, $w) {31$this->centerX = $x;32$this->centerY = $y;33$this->maskH = $h;34$this->maskW = $w;35return $this;36}3738public function withMask($mask) {39$this->withMask = $mask;40return $this;41}4243protected function getTagName() {44return 'div';45}4647protected function getTagAttributes() {48require_celerity_resource('phui-image-mask-css');4950$classes = array();51$classes[] = 'phui-image-mask';5253$styles = array();54$styles[] = 'height: '.$this->displayHeight.'px;';55$styles[] = 'width: '.$this->displayWidth.'px;';5657return array(58'class' => implode(' ', $classes),59'styles' => implode(' ', $styles),60);6162}6364protected function getTagContent() {6566/* Center it in the middle of the selected area */67$center_x = round($this->centerX + ($this->maskW / 2));68$center_y = round($this->centerY + ($this->maskH / 2));69$center_x = round($center_x - ($this->displayWidth / 2));70$center_y = round($center_y - ($this->displayHeight / 2));7172$center_x = -$center_x;73$center_y = -$center_y;7475$classes = array();76$classes[] = 'phui-image-mask-image';7778$styles = array();79$styles[] = 'height: '.$this->displayHeight.'px;';80$styles[] = 'width: '.$this->displayWidth.'px;';81$styles[] = 'background-image: url('.$this->image.');';82$styles[] = 'background-position: '.$center_x.'px '.$center_y.'px;';8384$mask = null;85if ($this->withMask) {86/* The mask is a 300px border around a transparent box.87so we do the math here to position the box correctly. */88$border = 300;89$left = round((($this->displayWidth - $this->maskW) / 2) - $border);90$top = round((($this->displayHeight - $this->maskH) / 2) - $border);9192$mstyles = array();93$mstyles[] = 'left: '.$left.'px;';94$mstyles[] = 'top: '.$top.'px;';95$mstyles[] = 'height: '.$this->maskH.'px;';96$mstyles[] = 'width: '.$this->maskW.'px;';9798$mask = phutil_tag(99'span',100array(101'class' => 'phui-image-mask-mask',102'style' => implode(' ', $mstyles),103),104null);105}106107return phutil_tag(108'div',109array(110'class' => implode(' ', $classes),111'style' => implode(' ', $styles),112),113$mask);114}115}116117118