Combine click events

feature/coffeescript
Sven Slootweg 10 years ago
parent 8ba19bf92b
commit 82a362a54b

@ -1453,8 +1453,6 @@
this.iteration = __bind(this.iteration, this); this.iteration = __bind(this.iteration, this);
this.checkActive = __bind(this.checkActive, this); this.checkActive = __bind(this.checkActive, this);
this.removeTargetSurface = __bind(this.removeTargetSurface, this); this.removeTargetSurface = __bind(this.removeTargetSurface, this);
this.handleMouseDown = __bind(this.handleMouseDown, this);
this.handleMouseUp = __bind(this.handleMouseUp, this);
this.handleClick = __bind(this.handleClick, this); this.handleClick = __bind(this.handleClick, this);
this.addTargetSurface = __bind(this.addTargetSurface, this); this.addTargetSurface = __bind(this.addTargetSurface, this);
this.instances = {}; this.instances = {};
@ -1482,34 +1480,34 @@
})(this)); })(this));
$(surface).on("click.radium", (function(_this) { $(surface).on("click.radium", (function(_this) {
return function(event) { return function(event) {
return _this.handleClick(event); return _this.handleClick("click", event);
}; };
})(this)); })(this));
$(surface).on("mouseup.radium", (function(_this) { $(surface).on("mouseup.radium", (function(_this) {
return function(event) { return function(event) {
return _this.handleMouseUp(event); return _this.handleClick("mouse_up", event);
}; };
})(this)); })(this));
$(surface).on("mousedown.radium", (function(_this) { $(surface).on("mousedown.radium", (function(_this) {
return function(event) { return function(event) {
return _this.handleMouseDown(event); return _this.handleClick("mouse_down", event);
}; };
})(this)); })(this));
return this.checkActive(); return this.checkActive();
}; };
Scene.prototype.handleClick = function(event) { Scene.prototype.handleClick = function(event_name, event) {
var id, instance, _ref; var id, instance, _ref;
_ref = this.instances; _ref = this.instances;
for (id in _ref) { for (id in _ref) {
instance = _ref[id]; instance = _ref[id];
instance.callEvent("click_global", { instance.callEvent("" + event_name + "_global", {
x: this.mouse_x, x: this.mouse_x,
y: this.mouse_y, y: this.mouse_y,
button: event.which button: event.which
}); });
if (instance.checkPointCollision(this.mouse_x, this.mouse_y)) { if (instance.checkPointCollision(this.mouse_x, this.mouse_y)) {
instance.callEvent("click", { instance.callEvent(event_name, {
x: this.mouse_x, x: this.mouse_x,
y: this.mouse_y, y: this.mouse_y,
button: event.which button: event.which
@ -1521,14 +1519,6 @@
return false; return false;
}; };
Scene.prototype.handleMouseUp = function(event) {
return pass;
};
Scene.prototype.handleMouseDown = function(event) {
return pass;
};
Scene.prototype.removeTargetSurface = function(surface) { Scene.prototype.removeTargetSurface = function(surface) {
this.surfaces = this.surfaces.filter(function(obj) { this.surfaces = this.surfaces.filter(function(obj) {
return obj !== surface; return obj !== surface;

@ -22,37 +22,31 @@ class Scene
) )
$(surface).on("click.radium", (event) => $(surface).on("click.radium", (event) =>
@handleClick(event) @handleClick("click", event)
) )
$(surface).on("mouseup.radium", (event) => $(surface).on("mouseup.radium", (event) =>
@handleMouseUp(event) @handleClick("mouse_up", event)
) )
$(surface).on("mousedown.radium", (event) => $(surface).on("mousedown.radium", (event) =>
@handleMouseDown(event) @handleClick("mouse_down", event)
) )
@checkActive() @checkActive()
handleClick: (event) => handleClick: (event_name, event) =>
for id, instance of @instances for id, instance of @instances
instance.callEvent("click_global", {x: @mouse_x, y: @mouse_y, button: event.which}) instance.callEvent("#{event_name}_global", {x: @mouse_x, y: @mouse_y, button: event.which})
if instance.checkPointCollision(@mouse_x, @mouse_y) if instance.checkPointCollision(@mouse_x, @mouse_y)
instance.callEvent("click", {x: @mouse_x, y: @mouse_y, button: event.which}) instance.callEvent(event_name, {x: @mouse_x, y: @mouse_y, button: event.which})
# Prevent default browser events from occurring on eg. right or middle click # Prevent default browser events from occurring on eg. right or middle click
event.preventDefault() event.preventDefault()
event.stopPropagation() event.stopPropagation()
return false return false
handleMouseUp: (event) =>
pass
handleMouseDown: (event) =>
pass
removeTargetSurface: (surface) => removeTargetSurface: (surface) =>
@surfaces = @surfaces.filter (obj) -> obj isnt surface @surfaces = @surfaces.filter (obj) -> obj isnt surface
$(surface).off("mousemove.radium") $(surface).off("mousemove.radium")

Loading…
Cancel
Save