[qwaq] Offset event mouse coordinates

Each level of the object hierarchy has its own offset relative to the
level above, but mouse coordinates are absolute.
This commit is contained in:
Bill Currie 2020-03-19 18:40:21 +09:00
parent 28a9e041e6
commit cce6837fe8
2 changed files with 9 additions and 0 deletions

View file

@ -23,6 +23,7 @@
-draw
{
[super draw];
[textContext blitFromBuffer: icon[pressed]
to: pos
from: [icon[pressed] rect]];

View file

@ -94,6 +94,12 @@ find_mouse_view(Group *group, Point pos)
[[views objectAtIndex:focused] handleEvent: event];
}
} else if (event.what & qe_positional) {
Point origin = {};
if (owner) {
origin = [owner origin];
}
event.mouse.x -= origin.x;
event.mouse.y -= origin.y;
Point pos = {event.mouse.x, event.mouse.y};
if (mouse_grabbed) {
[mouse_grabbed handleEvent: event];
@ -112,6 +118,8 @@ find_mouse_view(Group *group, Point pos)
[mouse_within handleEvent: event];
}
}
event.mouse.x += origin.x;
event.mouse.y += origin.y;
} else {
// broadcast
[views makeObjectsPerformSelector: @selector(draw) withObject: event];