[ Index ] |
PHP Cross Reference of Phabricator |
[Summary view] [Print] [Text view]
1 <?php 2 3 final class PHUIImageMaskView extends AphrontTagView { 4 5 private $image; 6 private $withMask; 7 8 private $displayWidth; 9 private $displayHeight; 10 11 private $centerX; 12 private $centerY; 13 private $maskH; 14 private $maskW; 15 16 public function setImage($image) { 17 $this->image = $image; 18 return $this; 19 } 20 21 public function setDisplayWidth($width) { 22 $this->displayWidth = $width; 23 return $this; 24 } 25 26 public function setDisplayHeight($height) { 27 $this->displayHeight = $height; 28 return $this; 29 } 30 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; 37 } 38 39 public function withMask($mask) { 40 $this->withMask = $mask; 41 return $this; 42 } 43 44 public function getTagName() { 45 return 'div'; 46 } 47 48 public function getTagAttributes() { 49 require_celerity_resource('phui-image-mask-css'); 50 51 $classes = array(); 52 $classes[] = 'phui-image-mask'; 53 54 $styles = array(); 55 $styles[] = 'height: '.$this->displayHeight.'px;'; 56 $styles[] = 'width: '.$this->displayWidth.'px;'; 57 58 return array( 59 'class' => implode(' ', $classes), 60 'styles' => implode(' ', $styles), 61 ); 62 63 } 64 65 public function getTagContent() { 66 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)); 72 73 $center_x = -$center_x; 74 $center_y = -$center_y; 75 76 $classes = array(); 77 $classes[] = 'phui-image-mask-image'; 78 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;'; 84 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); 92 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;'; 98 99 $mask = phutil_tag( 100 'span', 101 array( 102 'class' => 'phui-image-mask-mask', 103 'style' => implode(' ', $mstyles), 104 ), 105 null); 106 } 107 108 return phutil_tag( 109 'div', 110 array( 111 'class' => implode(' ', $classes), 112 'style' => implode(' ', $styles), 113 ), 114 $mask); 115 } 116 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Sun Nov 30 09:20:46 2014 | Cross-referenced by PHPXref 0.7.1 |