/debug/nfDrawRect.as

https://github.com/dareksob/nextFramework
ActionScript | 201 lines | 138 code | 31 blank | 32 comment | 8 complexity | ca9bf0f1a5051ce6a70d00ade3685595 MD5 | raw file
  1. package nextFramework.debug
  2. {
  3. import caurina.transitions.SpecialProperty;
  4. import flash.display.Graphics;
  5. import flash.display.Sprite;
  6. import flash.geom.Point;
  7. import flash.geom.Rectangle;
  8. import nextFramework.nfProperties;
  9. import nextFramework.utils.nfBoxPoints;
  10. /*
  11. * @author Darius Sobczak
  12. * @website dsobczak.de
  13. * @mail mail@dsobczak.de
  14. *
  15. * @website nextframework.de
  16. * @version 1.0 beta
  17. */
  18. public class nfDrawRect
  19. {
  20. function nfDrawRect(drawingonsprite:Sprite, object:Object, conf:Object = null) {
  21. nfProperties.setObjectProperties(this, conf);
  22. this.drawingOnSprite = drawingonsprite;
  23. this.object = object;
  24. }
  25. public function draw(clear:Boolean = true):Boolean {
  26. if (this.drawingOnSprite is Sprite && this.object != null) {
  27. this.drawing(clear);
  28. return true;
  29. }
  30. return false;
  31. }
  32. static public function drawOn(drawingonsprite:Sprite, object:Object, conf:Object = null, clear:Boolean = true):Boolean {
  33. return (new nfDrawRect(drawingonsprite, object, conf)).draw(clear);
  34. }
  35. private function drawing(clear:Boolean = true):void {
  36. var boxPoints:nfBoxPoints = nfBoxPoints.create(this.object);
  37. if (clear) { this.drawingOnSprite.graphics.clear(); }
  38. if (this.showRectPoints) {
  39. this.drawDot(this.drawingOnSprite.graphics, boxPoints.getByStage('leftTop'), dotColor.corner, 1, dotSize.corner);
  40. this.drawDot(this.drawingOnSprite.graphics, boxPoints.getByStage('rightTop'), dotColor.corner, 1, dotSize.corner);
  41. this.drawDot(this.drawingOnSprite.graphics, boxPoints.getByStage('leftBottom'), dotColor.corner, 1, dotSize.corner);
  42. this.drawDot(this.drawingOnSprite.graphics, boxPoints.getByStage('rightBottom'), dotColor.corner, 1, dotSize.corner);
  43. }
  44. if(this.showCenterPoint){
  45. this.drawDot(this.drawingOnSprite.graphics, boxPoints.getByStage('centerPoint'), dotColor.center, 1, dotSize.center);
  46. }
  47. if(this.showPositionPoint){
  48. this.drawDot(this.drawingOnSprite.graphics, boxPoints.stagePostition, dotColor.position, 1, dotSize.position);
  49. }
  50. if(this.showAbsLeftTop){
  51. this.drawDot(this.drawingOnSprite.graphics, boxPoints.getByStage('absLeftTop'), dotColor.position, 0.5, dotSize.center);
  52. }
  53. }
  54. private function drawDot(graphics:Graphics, position:Point, color:uint, alpha:Number, dotSize:Number) {
  55. graphics.beginFill(color, alpha);
  56. graphics.drawCircle(position.x, position.y, dotSize);
  57. graphics.endFill();
  58. }
  59. /*
  60. * spriteOn
  61. */
  62. private var _drawingOnSprite:Sprite;
  63. public function get drawingOnSprite():Sprite {
  64. return this._drawingOnSprite;
  65. }
  66. public function set drawingOnSprite(value:Sprite) {
  67. this._drawingOnSprite = value;
  68. }
  69. /*
  70. * object
  71. */
  72. private var _object:Object;
  73. public function get object():Object {
  74. return this._object;
  75. }
  76. public function set object(value:Object) {
  77. this._object = value;
  78. }
  79. /*
  80. * showRectPoints
  81. */
  82. private var _showRectPoints:Boolean = true;
  83. public function get showRectPoints():Boolean {
  84. return this._showRectPoints;
  85. }
  86. public function set showRectPoints(value:Boolean) {
  87. this._showRectPoints = value;
  88. }
  89. /*
  90. * showPositionPoint
  91. */
  92. private var _showPositionPoint:Boolean = true;
  93. public function get showPositionPoint():Boolean {
  94. return this._showPositionPoint;
  95. }
  96. public function set showPositionPoint(value:Boolean) {
  97. this._showPositionPoint = value;
  98. }
  99. /*
  100. * showCenterPoint
  101. */
  102. private var _showCenterPoint:Boolean = true;
  103. public function get showCenterPoint():Boolean {
  104. return this._showCenterPoint;
  105. }
  106. public function set showCenterPoint(value:Boolean) {
  107. this._showCenterPoint = value;
  108. }
  109. /*
  110. * showAbsLeftTop
  111. */
  112. private var _showAbsLeftTop:Boolean = true;
  113. public function get showAbsLeftTop():Boolean {
  114. return this._showAbsLeftTop;
  115. }
  116. public function set showAbsLeftTop(value:Boolean) {
  117. this._showAbsLeftTop = value;
  118. }
  119. /*
  120. * dotSize
  121. */
  122. private var _dotSize:Object = { center: 2, corner: 1, position: 3 };
  123. public function get dotSize():Object {
  124. return this._dotSize;
  125. }
  126. public function get dotSizeCorner():Number {
  127. return this._dotSize.corner;
  128. }
  129. public function set dotSizeCorner(value:Number) {
  130. this._dotSize.corner = value;
  131. }
  132. public function get dotSizeCenter():Number {
  133. return this._dotSize.center;
  134. }
  135. public function set dotSizeCenter(value:Number) {
  136. this._dotSize.center = value;
  137. }
  138. public function get dotSizePosition():Number {
  139. return this._dotSize.position;
  140. }
  141. public function set dotSizePosition(value:Number) {
  142. this._dotSize.position = value;
  143. }
  144. /*
  145. * color
  146. */
  147. private var _dotColor:Object = { center: 0xFF0000, corner: 0x00FF00, position: 0x0000FF };
  148. public function get dotColor():Object {
  149. return this._dotColor;
  150. }
  151. public function get dotColorCorner():uint {
  152. return this._dotColor.corner;
  153. }
  154. public function set dotColorCorner(value:uint) {
  155. this._dotColor.corner = value;
  156. }
  157. public function get dotColorCenter():uint {
  158. return this._dotColor.center;
  159. }
  160. public function set dotColorCenter(value:uint) {
  161. this._dotColor.center = value;
  162. }
  163. public function get dotColorPosition():uint {
  164. return this._dotColor.position;
  165. }
  166. public function set dotColorPosition(value:uint) {
  167. this._dotColor.position = value;
  168. }
  169. }
  170. }