fix draw
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
|
||||
var layout = use('layout')
|
||||
var geometry = use('geometry')
|
||||
var draw = use('draw2d')
|
||||
var draw = use('prosperon/draw2d')
|
||||
var graphics = use('graphics')
|
||||
var util = use('util')
|
||||
var input = use('input')
|
||||
@@ -242,9 +242,6 @@ clay.button = function button(str, action, config = {})
|
||||
config.action = action;
|
||||
}
|
||||
|
||||
var hovered = null;
|
||||
clay.newframe = function() { hovered = null; }
|
||||
|
||||
function point_add(a,b) {
|
||||
return {x: a.x+b.x, y: a.y+b.y}
|
||||
}
|
||||
@@ -252,6 +249,10 @@ function point_add(a,b) {
|
||||
// mousepos given in hud coordinates
|
||||
clay.draw_commands = function draw_commands(cmds, pos = {x:0, y:0}, mousepos = {x:0,y:0})
|
||||
{
|
||||
cmds.hovered = null
|
||||
mousepos = Object.create(mousepos)
|
||||
mousepos.y = -mousepos.y + 360
|
||||
|
||||
for (var cmd of cmds) {
|
||||
var config = cmd.config;
|
||||
var boundingbox = geometry.rect_move(cmd.boundingbox,point_add(pos,config.offset));
|
||||
@@ -260,7 +261,7 @@ clay.draw_commands = function draw_commands(cmds, pos = {x:0, y:0}, mousepos = {
|
||||
if (config.hovered && geometry.rect_point_inside(boundingbox, mousepos)) {
|
||||
config.hovered.__proto__ = config;
|
||||
config = config.hovered;
|
||||
hovered = config;
|
||||
cmds.hovered = config;
|
||||
}
|
||||
|
||||
if (config.background_image)
|
||||
@@ -295,11 +296,4 @@ clay.draw_debug = function draw_debug(cmds, pos = {x:0, y:0})
|
||||
}
|
||||
}
|
||||
|
||||
clay.inputs = {};
|
||||
clay.inputs.mouse = {}
|
||||
clay.inputs.mouse.left = function()
|
||||
{
|
||||
if (hovered && hovered.action) hovered.action();
|
||||
}
|
||||
|
||||
return clay
|
||||
|
||||
@@ -208,4 +208,9 @@ draw.grid = function grid(rect, spacing, thickness = 1, offset = {x: 0, y: 0}, m
|
||||
}
|
||||
}
|
||||
|
||||
draw.add_command = function(cmd)
|
||||
{
|
||||
current_list.push(cmd)
|
||||
}
|
||||
|
||||
return draw
|
||||
@@ -114,6 +114,28 @@ $_.receiver(function(msg) {
|
||||
break;
|
||||
case 'input':
|
||||
response = input.get_events();
|
||||
// Transform mouse coordinates from window to renderer coordinates
|
||||
if (ren && Array.isArray(response)) {
|
||||
for (var i = 0; i < response.length; i++) {
|
||||
var event = response[i];
|
||||
// Check if this is a mouse event with position data
|
||||
if (event.pos && (event.type == 'mouse_motion' ||
|
||||
event.type == 'mouse_button_down' ||
|
||||
event.type == 'mouse_button_up' ||
|
||||
event.type == 'mouse_wheel')) {
|
||||
// Convert window coordinates to renderer logical coordinates
|
||||
var logicalPos = ren.coordsFromWindow(event.pos);
|
||||
event.pos = logicalPos;
|
||||
}
|
||||
// Handle drop events which also have position
|
||||
if (event.pos && (event.type == 'drop_file' ||
|
||||
event.type == 'drop_text' ||
|
||||
event.type == 'drop_position')) {
|
||||
var logicalPos = ren.coordsFromWindow(event.pos);
|
||||
event.pos = logicalPos;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
response = {error: "Unknown kind: " + msg.kind};
|
||||
|
||||
Reference in New Issue
Block a user