PageRenderTime 36ms CodeModel.GetById 27ms RepoModel.GetById 0ms app.codeStats 0ms

/lib/Jaris/src/jaris/player/newcontrols/AspectRatioIcon.hx

https://gitlab.com/dali99/shimmie2-Material-Theme
Haxe | 130 lines | 84 code | 20 blank | 26 comment | 0 complexity | ac569f6f5c2a8bf1839e327479dda283 MD5 | raw file
  1. /**
  2. * @author Jefferson González
  3. * @copyright 2010 Jefferson González
  4. *
  5. * @license
  6. * This file is part of Jaris FLV Player.
  7. *
  8. * Jaris FLV Player is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License or GNU LESSER GENERAL
  10. * PUBLIC LICENSE as published by the Free Software Foundation, either version
  11. * 3 of the License, or (at your option) any later version.
  12. *
  13. * Jaris FLV Player is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License and
  19. * GNU LESSER GENERAL PUBLIC LICENSE along with Jaris FLV Player. If not,
  20. * see <http://www.gnu.org/licenses/>.
  21. */
  22. package jaris.player.newcontrols;
  23. import flash.display.Sprite;
  24. import flash.events.MouseEvent;
  25. import flash.geom.Matrix;
  26. import jaris.utils.Utils;
  27. import flash.display.GradientType;
  28. class AspectRatioIcon extends Sprite
  29. {
  30. private var _width:Float;
  31. private var _height:Float;
  32. private var _normalColor:UInt;
  33. private var _hoverColor:UInt;
  34. public function new(x:Float, y:Float, width:Float, height:Float, normalColor:UInt, hoverColor:UInt)
  35. {
  36. super();
  37. this.x = x;
  38. this.y = y;
  39. this.buttonMode = true;
  40. this.useHandCursor = true;
  41. this.tabEnabled = false;
  42. _width = width;
  43. _height = height;
  44. _normalColor = normalColor;
  45. _hoverColor = hoverColor;
  46. addEventListener(MouseEvent.MOUSE_OVER, onMouseOver);
  47. addEventListener(MouseEvent.MOUSE_OUT, onMouseOut);
  48. draw(_normalColor);
  49. }
  50. private function onMouseOver(event:MouseEvent):Void
  51. {
  52. draw(_hoverColor);
  53. }
  54. private function onMouseOut(event:MouseEvent):Void
  55. {
  56. draw(_normalColor);
  57. }
  58. //{Private Methods
  59. private function draw(color:UInt):Void
  60. {
  61. graphics.clear();
  62. graphics.lineStyle(0, color, 0.0);
  63. graphics.beginFill(color, 0);
  64. graphics.drawRect(0, 0, _width, _height);
  65. graphics.endFill();
  66. var matrix:Matrix = new Matrix( );
  67. matrix.createGradientBox(_width, _height, Utils.degreesToRadians(-90), _width, 0);
  68. var colors:Array<UInt> = [color, color];
  69. var alphas:Array<Float> = [0.75, 1];
  70. var ratios:Array<UInt> = [0, 255];
  71. var innerWidth:Float = (70 / 100) * width;
  72. var innerHeight:Float = (40 / 100) * height;
  73. var innerX:Float = (width / 2) - (innerWidth / 2) + 1 ;
  74. var innerY:Float = (height / 2) - (innerHeight / 2) + 1;
  75. graphics.lineStyle();
  76. graphics.beginGradientFill(GradientType.LINEAR, colors, alphas, ratios, matrix);
  77. //graphics.beginFill(color, 1);
  78. graphics.drawRect(0, 0, 1, _height+1);
  79. graphics.drawRect(0, 0, _width+1, 1);
  80. graphics.drawRect(_width+1, 0, 1, _height+1);
  81. graphics.drawRect(0, _height+1, _width+1, 1);
  82. graphics.drawRect(innerX, innerY, innerWidth, innerHeight);
  83. graphics.endFill();
  84. }
  85. //}
  86. //{Setters
  87. public function setNormalColor(color:UInt):Void
  88. {
  89. _normalColor = color;
  90. draw(_normalColor);
  91. }
  92. public function setHoverColor(color:UInt):Void
  93. {
  94. _hoverColor = color;
  95. draw(_hoverColor);
  96. }
  97. public function setPosition(x:Float, y:Float):Void
  98. {
  99. this.x = x;
  100. this.y = y;
  101. draw(_normalColor);
  102. }
  103. public function setSize(width:Float, height:Float):Void
  104. {
  105. _width = width;
  106. _height = height;
  107. draw(_normalColor);
  108. }
  109. //}
  110. }