[qwaq] Clamp window motion to owner's bounds

This commit is contained in:
Bill Currie 2020-03-19 21:28:55 +09:00
parent f329ca83b6
commit ac23156ecd
3 changed files with 44 additions and 3 deletions

View file

@ -20,6 +20,9 @@
-initWithContext: (id<TextContext>) context owner: (View *) owner;
-insert: (View *) view;
-remove: (View *) view;
-(Rect) rect;
-(Point) origin;
-(Extent) size;
-draw;
-redraw;
-handleEvent: (qwaq_event_t *) event;

View file

@ -46,6 +46,30 @@
return self;
}
-(Rect) rect
{
if (owner) {
return [owner rect];
}
return {[self origin], [self size]};
}
-(Point) origin
{
if (owner) {
return [owner origin];
}
return {0, 0};
}
-(Extent) size
{
if (owner) {
return [owner size];
}
return [context size];
}
static BOOL
not_dont_draw (id aView, void *aGroup)
{

View file

@ -46,9 +46,23 @@
- (void) dragWindow: (Button *) sender
{
Point delta = [sender delta];
xpos += delta.x;
ypos += delta.y;
move_panel (panel, xpos, ypos);
Point p = {xpos + delta.x, ypos + delta.y};
Extent bounds = [owner size];
if (p.x < 0) {
p.x = 0;
}
if (p.x + xlen > bounds.width) {
p.x = bounds.width - xlen;
}
if (p.y < 0) {
p.y = 0;
}
if (p.y + ylen > bounds.height) {
p.y = bounds.height - ylen;
}
xpos = p.x;
ypos = p.y;
move_panel (panel, p.x, p.y);
[owner redraw];
}