UNPKG

openfl

Version:

A fast, productive library for 2D cross-platform development.

275 lines (258 loc) 10.9 kB
// Class: openfl.display.SimpleButton var $global = typeof window != "undefined" ? window : typeof global != "undefined" ? global : typeof self != "undefined" ? self : this $global.Object.defineProperty(exports, "__esModule", {value: true}); var __map_reserved = {}; // Imports var $hxClasses = require("./../../hxClasses_stub").default; var $hxEnums = require("./../../hxEnums_stub").default; var $import = require("./../../import_stub").default; var $bind = require("./../../bind_stub").default; var $extend = require("./../../extend_stub").default; function openfl_display_InteractiveObject() {return require("./../../openfl/display/InteractiveObject");} function openfl_geom_Matrix() {return require("./../../openfl/geom/Matrix");} function openfl_display_DisplayObject() {return require("./../../openfl/display/DisplayObject");} function openfl_media_SoundTransform() {return require("./../../openfl/media/SoundTransform");} function openfl__$Vector_Vector_$Impl_$() {return require("./../../openfl/_Vector/Vector_Impl_");} function openfl_VectorData() {return require("./../../openfl/VectorData");} // Constructor var SimpleButton = function(upState,overState,downState,hitTestState) { (openfl_display_InteractiveObject().default).call(this); this.__drawableType = 6; this.enabled = true; this.trackAsMenu = false; this.useHandCursor = true; this.__upState = upState != null ? upState : new (openfl_display_DisplayObject().default)(); this.__overState = overState; this.__downState = downState; this.set_hitTestState(hitTestState != null ? hitTestState : new (openfl_display_DisplayObject().default)()); this.addEventListener("mouseDown",$bind(this,this.__this_onMouseDown)); this.addEventListener("mouseOut",$bind(this,this.__this_onMouseOut)); this.addEventListener("mouseOver",$bind(this,this.__this_onMouseOver)); this.addEventListener("mouseUp",$bind(this,this.__this_onMouseUp)); this.__tabEnabled = true; this.set___currentState(this.__upState); if(SimpleButton.__constructor != null) { var method = SimpleButton.__constructor; SimpleButton.__constructor = null; method(this); } } // Meta SimpleButton.__name__ = "openfl.display.SimpleButton"; SimpleButton.__isInterface__ = false; SimpleButton.__super__ = (openfl_display_InteractiveObject().default); SimpleButton.prototype = $extend((openfl_display_InteractiveObject().default).prototype, { __getBounds: function(rect,matrix) { (openfl_display_InteractiveObject().default).prototype.__getBounds.call(this,rect,matrix); var childWorldTransform = (openfl_geom_Matrix().default).__pool.get(); (openfl_display_DisplayObject().default).__calculateAbsoluteTransform(this.__currentState.__transform,matrix,childWorldTransform); this.__currentState.__getBounds(rect,childWorldTransform); (openfl_geom_Matrix().default).__pool.release(childWorldTransform); }, __getRenderBounds: function(rect,matrix) { if(this.__scrollRect != null) { (openfl_display_InteractiveObject().default).prototype.__getRenderBounds.call(this,rect,matrix); return; } else { (openfl_display_InteractiveObject().default).prototype.__getBounds.call(this,rect,matrix); } var childWorldTransform = (openfl_geom_Matrix().default).__pool.get(); (openfl_display_DisplayObject().default).__calculateAbsoluteTransform(this.__currentState.__transform,matrix,childWorldTransform); this.__currentState.__getRenderBounds(rect,childWorldTransform); (openfl_geom_Matrix().default).__pool.release(childWorldTransform); }, __getCursor: function() { if(this.useHandCursor && !this.__ignoreEvent && this.enabled) { return "button"; } else { return null; } }, __hitTest: function(x,y,shapeFlag,stack,interactiveOnly,hitObject) { var hitTest = false; if(this.get_hitTestState() != null) { if(this.get_hitTestState().__hitTest(x,y,shapeFlag,stack,interactiveOnly,hitObject)) { if(stack != null) { if(stack.length == 0) { stack[0] = hitObject; } else { stack[stack.length - 1] = hitObject; } } hitTest = !interactiveOnly || this.mouseEnabled; } } else if(this.__currentState != null) { if(!hitObject.get_visible() || this.__isMask || interactiveOnly && !this.mouseEnabled || this.get_mask() != null && !this.get_mask().__hitTestMask(x,y)) { hitTest = false; } else if(this.__currentState.__hitTest(x,y,shapeFlag,stack,interactiveOnly,hitObject)) { hitTest = interactiveOnly; } } if(stack != null) { while(stack.length > 1 && stack[stack.length - 1] == stack[stack.length - 2]) stack.pop(); } return hitTest; }, __hitTestMask: function(x,y) { var hitTest = false; if(this.__currentState.__hitTestMask(x,y)) { hitTest = true; } return hitTest; }, __setStageReference: function(stage) { (openfl_display_InteractiveObject().default).prototype.__setStageReference.call(this,stage); if(this.__currentState != null) { this.__currentState.__setStageReference(stage); } if(this.get_hitTestState() != null && this.get_hitTestState() != this.__currentState) { this.get_hitTestState().__setStageReference(stage); } }, __setTransformDirty: function() { (openfl_display_InteractiveObject().default).prototype.__setTransformDirty.call(this); if(this.__currentState != null) { this.__currentState.__setTransformDirty(); } if(this.get_hitTestState() != null && this.get_hitTestState() != this.__currentState) { this.get_hitTestState().__setTransformDirty(); } }, __update: function(transformOnly,updateChildren) { (openfl_display_InteractiveObject().default).prototype.__update.call(this,transformOnly,updateChildren); if(updateChildren) { if(this.__currentState != null) { this.__currentState.__update(transformOnly,true); } if(this.get_hitTestState() != null && this.get_hitTestState() != this.__currentState) { this.get_hitTestState().__update(transformOnly,true); } } }, __updateTransforms: function(overrideTransform) { (openfl_display_InteractiveObject().default).prototype.__updateTransforms.call(this,overrideTransform); if(this.__currentState != null) { this.__currentState.__updateTransforms(); } if(this.get_hitTestState() != null && this.get_hitTestState() != this.__currentState) { this.get_hitTestState().__updateTransforms(); } }, get_downState: function() { return this.__downState; }, set_downState: function(downState) { if(this.__downState != null && this.__currentState == this.__downState) { this.set___currentState(this.__downState); } return this.__downState = downState; }, get_hitTestState: function() { return this.__hitTestState; }, set_hitTestState: function(hitTestState) { if(this.__hitTestState != null && this.__hitTestState != hitTestState) { if(this.__hitTestState != this.get_downState() && this.__hitTestState != this.get_upState() && this.__hitTestState != this.get_overState()) { this.__hitTestState.__renderParent = null; } } if(hitTestState != null) { hitTestState.__renderParent = this; hitTestState.__setRenderDirty(); } return this.__hitTestState = hitTestState; }, get_overState: function() { return this.__overState; }, set_overState: function(overState) { if(this.__overState != null && this.__currentState == this.__overState) { this.set___currentState(overState); } return this.__overState = overState; }, get_soundTransform: function() { if(this.__soundTransform == null) { this.__soundTransform = new (openfl_media_SoundTransform().default)(); } return new (openfl_media_SoundTransform().default)(this.__soundTransform.volume,this.__soundTransform.pan); }, set_soundTransform: function(value) { this.__soundTransform = new (openfl_media_SoundTransform().default)(value.volume,value.pan); return value; }, get_upState: function() { return this.__upState; }, set_upState: function(upState) { if(this.__upState != null && this.__currentState == this.__upState) { this.set___currentState(upState); } return this.__upState = upState; }, set___currentState: function(value) { if(this.__currentState != null && this.__currentState != this.get_hitTestState()) { this.__currentState.__renderParent = null; } if(value != null && value.parent != null) { value.parent.removeChild(value); } if((openfl_display_DisplayObject().default).__supportDOM && this.__previousStates == null) { this.__previousStates = (openfl__$Vector_Vector_$Impl_$().default)._new(); } if(value != this.__currentState) { if((openfl_display_DisplayObject().default).__supportDOM) { if(this.__currentState != null) { this.__currentState.__setStageReference(null); (openfl__$Vector_Vector_$Impl_$().default).push(this.__previousStates,this.__currentState); } var this1 = this.__previousStates; var index = (Array.prototype.indexOf.call)(this1,value,0); if(index > -1) { var this2 = this.__previousStates; (openfl_VectorData().default).ofArray((Array.prototype.splice.call)(this2,index,1)); } } if(value != null) { value.__renderParent = this; value.__setRenderDirty(); } this.__setRenderDirty(); } this.__currentState = value; return value; }, __this_onMouseDown: function(event) { if(this.enabled) { this.set___currentState(this.get_downState()); } }, __this_onMouseOut: function(event) { this.__ignoreEvent = false; if(this.get_upState() != this.__currentState) { this.set___currentState(this.get_upState()); } }, __this_onMouseOver: function(event) { if(event.buttonDown) { this.__ignoreEvent = true; } if(this.get_overState() != this.__currentState && this.get_overState() != null && !this.__ignoreEvent && this.enabled) { this.set___currentState(this.get_overState()); } }, __this_onMouseUp: function(event) { this.__ignoreEvent = false; if(this.enabled && this.get_overState() != null) { this.set___currentState(this.get_overState()); } else { this.set___currentState(this.get_upState()); } } }); SimpleButton.prototype.__class__ = SimpleButton.prototype.constructor = $hxClasses["openfl.display.SimpleButton"] = SimpleButton; // Init Object.defineProperties(SimpleButton.prototype,{ downState : { get : function () { return this.get_downState (); }, set : function (v) { return this.set_downState (v); }}, hitTestState : { get : function () { return this.get_hitTestState (); }, set : function (v) { return this.set_hitTestState (v); }}, overState : { get : function () { return this.get_overState (); }, set : function (v) { return this.set_overState (v); }}, soundTransform : { get : function () { return this.get_soundTransform (); }, set : function (v) { return this.set_soundTransform (v); }}, upState : { get : function () { return this.get_upState (); }, set : function (v) { return this.set_upState (v); }}}); // Statics // Export exports.default = SimpleButton;