starling-framework
Version:
A fast, productive library for 2D cross-platform development.
120 lines (103 loc) • 4.79 kB
JavaScript
// Class: starling.events.TouchMarker
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 $extend = require("./../../extend_stub").default;
function starling_display_Sprite() {return require("./../../starling/display/Sprite");}
function starling_core_Starling() {return require("./../../starling/core/Starling");}
function Std() {return require("./../../Std");}
function openfl_display_Shape() {return $import(require("openfl/display/Shape"));}
function openfl_display_BitmapData() {return $import(require("openfl/display/BitmapData"));}
function starling_textures_Texture() {return require("./../../starling/textures/Texture");}
function js_Boot() {return require("./../../js/Boot");}
function starling_display_Image() {return require("./../../starling/display/Image");}
function openfl_geom_Point() {return $import(require("openfl/geom/Point"));}
// Constructor
var TouchMarker = function() {
(starling_display_Sprite().default).call(this);
this.__center = new (openfl_geom_Point().default)();
this.__texture = this.createTexture();
var marker = new (starling_display_Image().default)(this.__texture);
marker.set_pivotX(this.__texture.get_width() / 2);
marker.set_pivotY(this.__texture.get_height() / 2);
marker.set_touchable(false);
this.addChild(marker);
var marker1 = new (starling_display_Image().default)(this.__texture);
marker1.set_pivotX(this.__texture.get_width() / 2);
marker1.set_pivotY(this.__texture.get_height() / 2);
marker1.set_touchable(false);
this.addChild(marker1);
}
// Meta
TouchMarker.__name__ = "starling.events.TouchMarker";
TouchMarker.__isInterface__ = false;
TouchMarker.__super__ = (starling_display_Sprite().default);
TouchMarker.prototype = $extend((starling_display_Sprite().default).prototype, {
dispose: function() {
this.__texture.dispose();
(starling_display_Sprite().default).prototype.dispose.call(this);
},
moveMarker: function(x,y,withCenter) {
if(withCenter == null) {
withCenter = false;
}
if(withCenter) {
this.__center.x += x - this.get_realMarker().get_x();
this.__center.y += y - this.get_realMarker().get_y();
}
this.get_realMarker().set_x(x);
this.get_realMarker().set_y(y);
this.get_mockMarker().set_x(2 * this.__center.x - x);
this.get_mockMarker().set_y(2 * this.__center.y - y);
},
moveCenter: function(x,y) {
this.__center.x = x;
this.__center.y = y;
this.moveMarker(this.get_realX(),this.get_realY());
},
createTexture: function() {
var scale = (starling_core_Starling().default).get_current().get_contentScaleFactor();
var radius = 12 * scale;
var width = (Std().default).int(32 * scale);
var height = (Std().default).int(32 * scale);
var thickness = 1.5 * scale;
var shape = new (openfl_display_Shape().default)();
shape.get_graphics().lineStyle(thickness,0,0.3);
shape.get_graphics().drawCircle(width / 2,height / 2,radius + thickness);
shape.get_graphics().beginFill(16777215,0.4);
shape.get_graphics().lineStyle(thickness,16777215);
shape.get_graphics().drawCircle(width / 2,height / 2,radius);
shape.get_graphics().endFill();
var bmpData = new (openfl_display_BitmapData().default)(width,height,true,0);
bmpData.draw(shape);
return (starling_textures_Texture().default).fromBitmapData(bmpData,false,false,scale);
},
get_realMarker: function() {
return (js_Boot().default).__cast(this.getChildAt(0) , (starling_display_Image().default));
},
get_mockMarker: function() {
return (js_Boot().default).__cast(this.getChildAt(1) , (starling_display_Image().default));
},
get_realX: function() {
return this.get_realMarker().get_x();
},
get_realY: function() {
return this.get_realMarker().get_y();
},
get_mockX: function() {
return this.get_mockMarker().get_x();
},
get_mockY: function() {
return this.get_mockMarker().get_y();
}
});
TouchMarker.prototype.__class__ = TouchMarker.prototype.constructor = $hxClasses["starling.events.TouchMarker"] = TouchMarker;
// Init
Object.defineProperties(TouchMarker.prototype,{ realMarker : { get : function () { return this.get_realMarker(); }}, mockMarker : { get : function () { return this.get_mockMarker (); }}, realX : { get : function () { return this.get_realX (); }}, realY : { get : function () { return this.get_realY (); }}, mockX : { get : function () { return this.get_mockX (); }}, mockY : { get : function () { return this.get_mockY (); }}});
// Statics
// Export
exports.default = TouchMarker;