/com/zehfernando/display/shapes/BoxMarker.as

https://github.com/duponce/as3
ActionScript | 100 lines | 67 code | 21 blank | 12 comment | 6 complexity | a4d5cfd97e2391b91512b93139e3cf75 MD5 | raw file
  1. package com.zehfernando.display.shapes {
  2. import com.zehfernando.data.types.Color;
  3. import flash.display.CapsStyle;
  4. import flash.display.JointStyle;
  5. import flash.display.LineScaleMode;
  6. import flash.display.Shape;
  7. import flash.display.Sprite;
  8. /**
  9. * @author zeh
  10. */
  11. public class BoxMarker extends Sprite {
  12. // Properties
  13. protected var _lineColor:int;
  14. protected var _width:Number;
  15. protected var _height:Number;
  16. // Instances
  17. protected var background:Box;
  18. protected var foreground:Shape;
  19. // ================================================================================================================
  20. // CONSTRUCTOR ----------------------------------------------------------------------------------------------------
  21. public function BoxMarker(__width:Number = 100, __height:Number = 100, __lineColor:int = 0x555555, __backgroundColor:int = 0xe3e3e3) {
  22. _width = __width;
  23. _height = __height;
  24. background = new Box(100, 100, __backgroundColor);
  25. addChild(background);
  26. foreground = new Shape();
  27. foreground.graphics.lineStyle(1.6, 0x000000, 1, false, LineScaleMode.NONE, CapsStyle.ROUND, JointStyle.MITER);
  28. foreground.graphics.drawRect(0, 0, 100, 100);
  29. foreground.graphics.moveTo(0, 0);
  30. foreground.graphics.lineTo(100, 100);
  31. foreground.graphics.moveTo(100, 0);
  32. foreground.graphics.lineTo(0, 100);
  33. foreground.graphics.endFill();
  34. addChild(foreground);
  35. lineColor = __lineColor;
  36. redraw();
  37. }
  38. // ================================================================================================================
  39. // INTERNAL INTERFACE ---------------------------------------------------------------------------------------------
  40. protected function redraw(): void {
  41. background.width = _width;
  42. background.height = _height;
  43. foreground.scaleX = _width/100;
  44. foreground.scaleY = _height/100;
  45. }
  46. // ================================================================================================================
  47. // ACCESSOR functions ---------------------------------------------------------------------------------------------
  48. public function get color(): int {
  49. return background.color;
  50. }
  51. public function set color(__value:int): void {
  52. background.color = __value;
  53. }
  54. public function get lineColor(): int {
  55. return _lineColor;
  56. }
  57. public function set lineColor(__value:int): void {
  58. if (_lineColor != __value) {
  59. _lineColor = __value;
  60. foreground.transform.colorTransform = Color.fromRRGGBB(_lineColor).toColorTransform();
  61. }
  62. }
  63. // TODO: use invalidate
  64. override public function get width(): Number { return _width; }
  65. override public function set width(__value:Number): void {
  66. if (_width != __value) {
  67. _width = __value;
  68. redraw();
  69. }
  70. }
  71. override public function get height(): Number { return _height; }
  72. override public function set height(__value:Number): void {
  73. if (_height != __value) {
  74. _height = __value;
  75. redraw();
  76. }
  77. }
  78. }
  79. }