[qwaq] Start work on cursor management

For now, the cursor is always hidden, but the plan is to have it visible
in only the focused view if that view has enabled the cursor.
This commit is contained in:
Bill Currie 2021-06-01 12:59:01 +09:00
parent bcc5686606
commit d98c92a5c4
6 changed files with 92 additions and 9 deletions

View file

@ -26,10 +26,12 @@
-insertSelected: (View *) view; -insertSelected: (View *) view;
-remove: (View *) view; -remove: (View *) view;
-(Rect) rect; -(Rect) rect;
-(Rect) absRect;
-(Point) origin; -(Point) origin;
-(Extent) size; -(Extent) size;
-draw; -draw;
-redraw; -redraw;
-updateAbsPos: (Point) absPos;
-resize: (Extent) delta; -resize: (Extent) delta;
-handleEvent: (qwaq_event_t *) event; -handleEvent: (qwaq_event_t *) event;
-takeFocus; -takeFocus;

View file

@ -190,6 +190,14 @@ trySetFocus (Group *self, int viewIndex)
return {[self origin], [self size]}; return {[self origin], [self size]};
} }
-(Rect) absRect
{
if (owner) {
return [owner absRect];
}
return {[self origin], [self size]};
}
-(Point) origin -(Point) origin
{ {
if (owner) { if (owner) {
@ -236,6 +244,14 @@ not_dont_draw (id aView, void *aGroup)
return self; return self;
} }
-updateAbsPos: (Point) absPos
{
for (int i = [views count]; i-- > 0; ) {
[[views objectAtIndex: i] updateAbsPos: absPos];
}
return self;
}
-resize: (Extent) delta -resize: (Extent) delta
{ {
for (int i = [views count]; i-- > 0; ) { for (int i = [views count]; i-- > 0; ) {

View file

@ -86,6 +86,13 @@
return onScrollBarModified; return onScrollBarModified;
} }
-updateAbsPos: (Point) absPos
{
[super updateAbsPos: absPos];
[objects updateAbsPos: absRect.offset];
return self;
}
-draw -draw
{ {
[super draw]; [super draw];

View file

@ -50,6 +50,7 @@ enum {
-setGrowMode: (int) mode; -setGrowMode: (int) mode;
-(Rect)rect; -(Rect)rect;
-(Rect)absRect;
-(Point)origin; -(Point)origin;
-(Extent)size; -(Extent)size;
@ -70,6 +71,7 @@ enum {
-hide; -hide;
-redraw; -redraw;
-move: (Point) delta; -move: (Point) delta;
-updateAbsPos: (Point) absPos;
-resize: (Extent) delta; -resize: (Extent) delta;
-move:(Point)dpos andResize:(Extent)dsize; -move:(Point)dpos andResize:(Extent)dsize;
-moveTo:(Point)pos; // does not redraw -moveTo:(Point)pos; // does not redraw
@ -82,6 +84,10 @@ enum {
-(ListenerGroup *) onReceiveFocus; -(ListenerGroup *) onReceiveFocus;
-(ListenerGroup *) onReleaseFocus; -(ListenerGroup *) onReleaseFocus;
-raise; -raise;
-hideCursor;
-showCursor;
-setCursorVisible:(int) visible;
-moveCursor:(Point) pos;
- (void) onMouseEnter: (Point) pos; - (void) onMouseEnter: (Point) pos;
- (void) onMouseLeave: (Point) pos; - (void) onMouseLeave: (Point) pos;
@ -115,7 +121,7 @@ enum {
int options; int options;
int growMode; int growMode;
int cursorState; int cursorState;
Point cursor; Point cursorPos;
ListenerGroup *onReceiveFocus; ListenerGroup *onReceiveFocus;
ListenerGroup *onReleaseFocus; ListenerGroup *onReleaseFocus;
ListenerGroup *onEvent; ListenerGroup *onEvent;

View file

@ -138,15 +138,44 @@ updateScreenCursor (View *view)
} }
view = owner; view = owner;
} }
*/
if (view.state & sfInFocus) { if (view.state & sfInFocus) {
if (view.cursor.x >= 0 && view.cursor.x < view.xlen if (view.cursorPos.x >= 0 && view.cursorPos.x < view.xlen
&& view.cursor.y >= 0 && view.cursor.y < view.ylen) { && view.cursorPos.y >= 0 && view.cursorPos.y < view.ylen) {
curs_set (view.cursorState); curs_set (view.cursorState);
move(view.cursor.x, view.cursor.y); move(view.cursorPos.x, view.cursorPos.y);
} else { } else {
curs_set (0); curs_set (0);
} }
}*/ }
}
-hideCursor
{
return [self setCursorVisible: 0];
}
-showCursor
{
return [self setCursorVisible: 1];
}
-setCursorVisible: (int) visible
{
cursorState = visible;
if ((state & (sfInFocus | sfDrawn)) == (sfInFocus | sfDrawn)) {
updateScreenCursor (self);
}
return self;
}
-moveCursor: (Point) pos
{
cursorPos = pos;
if ((state & (sfInFocus | sfDrawn)) == (sfInFocus | sfDrawn)) {
updateScreenCursor (self);
}
return self;
} }
-draw -draw
@ -191,6 +220,11 @@ updateScreenCursor (View *view)
return rect; return rect;
} }
- (Rect) absRect
{
return rect;
}
-(Point)origin -(Point)origin
{ {
return pos; return pos;
@ -280,17 +314,28 @@ updateScreenCursor (View *view)
ypos = 0; ypos = 0;
} }
if (owner) { if (owner) {
Rect r = [owner absRect];
Extent s = [owner size]; Extent s = [owner size];
if (xpos > s.width - 1) { if (xpos > r.extent.width - 1) {
xpos = s.width - 1; xpos = r.extent.width - 1;
} }
if (ypos > s.height - 1) { if (ypos > r.extent.height - 1) {
ypos = s.height - 1; ypos = r.extent.height - 1;
} }
[self updateAbsPos: r.offset];
} else {
[self updateAbsPos: nil];
} }
return self; return self;
} }
-updateAbsPos: (Point) absPos
{
absRect.offset.x = absPos.x + xpos;
absRect.offset.y = absPos.y + ypos;
return self;
}
-resize: (Extent) delta -resize: (Extent) delta
{ {
xlen += delta.width; xlen += delta.width;

View file

@ -241,6 +241,13 @@
return self; return self;
} }
-updateAbsPos: (Point) absPos
{
[super updateAbsPos: absPos];
[objects updateAbsPos: absRect.offset];
return self;
}
-draw -draw
{ {
static box_sides_t box_sides = { static box_sides_t box_sides = {