[qwaq] Get the cursor mostly working

It's a little flakey with respect to redraws and changes of focus, but I
think that's just updating the cursor state in more places.
This commit is contained in:
Bill Currie 2021-06-07 15:58:19 +09:00
parent d36a75e3de
commit 48bf6fff13
2 changed files with 43 additions and 23 deletions

View file

@ -3,6 +3,7 @@
#include "ruamoko/qwaq/ui/group.h" #include "ruamoko/qwaq/ui/group.h"
#include "ruamoko/qwaq/ui/scrollbar.h" #include "ruamoko/qwaq/ui/scrollbar.h"
#include "ruamoko/qwaq/ui/view.h" #include "ruamoko/qwaq/ui/view.h"
#include "ruamoko/qwaq/debugger/debug.h"
@implementation View @implementation View
@ -122,32 +123,41 @@ setScrollBar (View *self, ScrollBar **sb, ScrollBar *scrollbar)
return self; return self;
} }
-(window_t) window
{
return nil;
}
static void updateScreenCursor (View *view);
-updateScreenCursor
{
updateScreenCursor (self);
return self;
}
static void static void
updateScreenCursor (View *view) updateScreenCursor (View *view)
{ {
// XXX this does not work
/* while ((view.state & sfInFocus) && view.owner) {
View *owner = (View *) view.owner;
if (view.cursor.x >= 0 && view.cursor.x < view.xlen
&& view.cursor.y >= 0 && view.cursor.y < view.ylen) {
owner.cursor.x = view.cursor.x + view.xpos;
owner.cursor.y = view.cursor.y + view.ypos;
owner.cursorState = view.cursorState;
} else {
owner.cursorState = 0;
}
view = owner;
}
*/
if (view.state & sfInFocus) { if (view.state & sfInFocus) {
if (view.cursorPos.x >= 0 && view.cursorPos.x < view.xlen if (view.owner) {
&& view.cursorPos.y >= 0 && view.cursorPos.y < view.ylen) { View *owner = [view.owner owner];
curs_set (view.cursorState); if (view.cursorPos.x >= 0 && view.cursorPos.x < view.xlen
move(view.cursorPos.x, view.cursorPos.y); && view.cursorPos.y >= 0 && view.cursorPos.y < view.ylen) {
owner.cursorPos.x = view.cursorPos.x + view.xpos;
owner.cursorPos.y = view.cursorPos.y + view.ypos;
owner.cursorState = view.cursorState;
} else {
owner.cursorState = 0;
}
[owner updateScreenCursor];
} else { } else {
curs_set (0);
} }
} }
/*
curs_set (cursorState);
wmove (get_window (view), cursorPos.x, cursorPos.y);
*/
} }
-hideCursor -hideCursor
@ -164,7 +174,7 @@ updateScreenCursor (View *view)
{ {
cursorState = visible; cursorState = visible;
if ((state & (sfInFocus | sfDrawn)) == (sfInFocus | sfDrawn)) { if ((state & (sfInFocus | sfDrawn)) == (sfInFocus | sfDrawn)) {
updateScreenCursor (self); [self updateScreenCursor];
} }
return self; return self;
} }
@ -173,7 +183,7 @@ updateScreenCursor (View *view)
{ {
cursorPos = pos; cursorPos = pos;
if ((state & (sfInFocus | sfDrawn)) == (sfInFocus | sfDrawn)) { if ((state & (sfInFocus | sfDrawn)) == (sfInFocus | sfDrawn)) {
updateScreenCursor (self); [self updateScreenCursor];
} }
return self; return self;
} }
@ -181,7 +191,7 @@ updateScreenCursor (View *view)
-draw -draw
{ {
state |= sfDrawn; state |= sfDrawn;
updateScreenCursor (self); [self updateScreenCursor];
return self; return self;
} }
@ -189,7 +199,7 @@ updateScreenCursor (View *view)
{ {
if (state & sfDrawn) { if (state & sfDrawn) {
state &= ~sfDrawn; state &= ~sfDrawn;
updateScreenCursor (self); [self updateScreenCursor];
} }
return self; return self;
} }
@ -432,6 +442,7 @@ updateScreenCursor (View *view)
-takeFocus -takeFocus
{ {
state |= sfInFocus; state |= sfInFocus;
[self updateScreenCursor];
[onReceiveFocus respond:self]; [onReceiveFocus respond:self];
return self; return self;
} }
@ -439,6 +450,7 @@ updateScreenCursor (View *view)
-loseFocus -loseFocus
{ {
state &= ~sfInFocus; state &= ~sfInFocus;
[self updateScreenCursor];
[onReleaseFocus respond:self]; [onReleaseFocus respond:self];
return self; return self;
} }

View file

@ -71,6 +71,14 @@
return self; return self;
} }
-updateScreenCursor
{
window_t window = [(id)textContext window];
curs_set (cursorState);
wmove (window, cursorPos.x, cursorPos.y);
return self;
}
-setTitle:(string) title -setTitle:(string) title
{ {
[titleBar setTitle:title]; [titleBar setTitle:title];