[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;
-remove: (View *) view;
-(Rect) rect;
-(Rect) absRect;
-(Point) origin;
-(Extent) size;
-draw;
-redraw;
-updateAbsPos: (Point) absPos;
-resize: (Extent) delta;
-handleEvent: (qwaq_event_t *) event;
-takeFocus;

View file

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

View file

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

View file

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

View file

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

View file

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