diff --git a/client/assets/mouse.png b/client/assets/mouse.png new file mode 100644 index 0000000..2e0e81b --- /dev/null +++ b/client/assets/mouse.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d3b2222b2872dad2ddd16fb8fb061a51f9fe8a9cb70281a4841dd68b305a7da0 +size 5748 diff --git a/client/src/gui/gui.c b/client/src/gui/gui.c index 3fb21a6..834f168 100644 --- a/client/src/gui/gui.c +++ b/client/src/gui/gui.c @@ -15,12 +15,20 @@ typedef struct WidgetCatalogS { } WidgetCatalogT; -GrColor *__guiBaseColors = NULL; +GrColor *__guiBaseColors = NULL; +GrContext *__guiBackBuffer = NULL; +GrContext *__guiScreenBuffer = NULL; -static uint8_t _magicCount = 0; -static WidgetCatalogT *_widgetCatalog = NULL; -static uint8_t _guiRunning = 1; +static uint8_t _magicCount = 0; +static WidgetCatalogT *_widgetCatalog = NULL; +static uint8_t _guiRunning = 1; +static GrContext *_mousePointer = NULL; +static GrColor _mouseTransparency; + + +// This is a total hack to prevent GRX from drawing the mouse pointer. +extern struct _GR_mouseInfo _GrMouseInfo; void guiModesShow(void) { @@ -63,40 +71,27 @@ void guiModesShow(void) { void guiRun(void) { - char text[256] = { 0 }; GrMouseEvent event; -#define APPEND (&text[strlen(text)]) - while (_guiRunning) { - GrMouseGetEvent(GR_M_EVENT, &event); - if (event.flags != 0) { - strcpy(text, "Events: "); - if(event.flags & GR_M_MOTION) strcpy( APPEND,"[moved] "); - if(event.flags & GR_M_LEFT_DOWN) strcpy( APPEND,"[left down] "); - if(event.flags & GR_M_MIDDLE_DOWN) strcpy( APPEND,"[middle down] "); - if(event.flags & GR_M_RIGHT_DOWN) strcpy( APPEND,"[right down] "); - if(event.flags & GR_M_P4_DOWN) strcpy( APPEND,"[p4 down] "); - if(event.flags & GR_M_P5_DOWN) strcpy( APPEND,"[p5 down] "); - if(event.flags & GR_M_LEFT_UP) strcpy( APPEND,"[left up] "); - if(event.flags & GR_M_MIDDLE_UP) strcpy( APPEND,"[middle up] "); - if(event.flags & GR_M_RIGHT_UP) strcpy( APPEND,"[right up] "); - if(event.flags & GR_M_P4_UP) strcpy( APPEND,"[p4 up] "); - if(event.flags & GR_M_P5_UP) strcpy( APPEND,"[p5 up] "); - if(event.flags & GR_M_KEYPRESS) sprintf(APPEND,"[key (0x%03x)] ",event.key); - sprintf(APPEND,"at X=%d, Y=%d, ",event.x,event.y); - sprintf(APPEND, - "buttons=%c%c%c, ", - (event.buttons & GR_M_LEFT) ? 'L' : 'l', - (event.buttons & GR_M_MIDDLE) ? 'M' : 'm', - (event.buttons & GR_M_RIGHT) ? 'R' : 'r' - ); - sprintf(APPEND,"deltaT=%ld (ms)",event.dtime); - strcpy (APPEND," "); - } - wmPaint(); - GrTextXY(0, 0, text, GUI_WHITE, GUI_BLACK); - if (GrKeyRead() == GrKey_Escape) guiStop(); + // Read mouse & keyboard. + GrMouseGetEventT(GR_M_EVENT, &event, 0); + + // Paint desktop. + GrSetContext(__guiBackBuffer); + GrClearContext(GUI_CYAN); + + // Paint GUI. + wmPaint(&event); + + // Paint mouse pointer. + GrBitBlt(__guiBackBuffer, event.x, event.y, _mousePointer, 0, 0, _mousePointer->gc_xmax, _mousePointer->gc_ymax, GrIMAGE | _mouseTransparency); + + // Copy to screen. + GrBitBltNC(__guiScreenBuffer, 0, 0, __guiBackBuffer, 0, 0, __guiBackBuffer->gc_xmax, __guiBackBuffer->gc_ymax, GrWRITE); + + // Emergency Exit? + if (event.flags & GR_M_KEYPRESS && event.key == GrKey_Escape) guiStop(); } } @@ -120,24 +115,43 @@ void guiShutdown(void) { GrMouseEraseCursor(); GrMouseUnInit(); + GrDestroyContext(_mousePointer); + DEL(__guiBaseColors); + GrDestroyContext(__guiBackBuffer); GrSetMode(GR_default_text); } void guiStartup(int16_t width, int16_t height, int16_t depth) { + + int32_t x; + int32_t y; + + // Set up graphics environment. if (!GrSetMode(GR_width_height_bpp_graphics, width, height, depth)) { //***TODO*** Die } GrSetRGBcolorMode(); __guiBaseColors = GrAllocEgaColors(); + __guiScreenBuffer = GrScreenContext(); + __guiBackBuffer = GrCreateContext(GrScreenX(), GrScreenY(), NULL, NULL); + // Set up mouse. GrMouseInit(); GrMouseEventEnable(1, 1); - GrMouseSetColors(GUI_WHITE, GUI_BLACK); GrMouseSetCursorMode(GR_M_CUR_NORMAL); - GrMouseDisplayCursor(); + // This is a total hack to prevent GRX from drawing the mouse pointer. + _GrMouseInfo.cursor = NULL; + + // Load mouse pointer. + if (!GrQueryPng("mouse.png", &x, &y)) { + //***TODO*** Die + } + _mousePointer = GrCreateContext(x, y, NULL, NULL); + GrLoadContextFromPng(_mousePointer, "mouse.png", 0); + _mouseTransparency = GrPixelC(_mousePointer, x - 1, 0); // Find our transparency color. wmStartup(); diff --git a/client/src/gui/gui.h b/client/src/gui/gui.h index ae596c0..3eb8e23 100644 --- a/client/src/gui/gui.h +++ b/client/src/gui/gui.h @@ -42,7 +42,9 @@ typedef struct WidgetS { typedef RegisterT *(*WidgetRegisterT)(uint8_t); -extern GrColor *__guiBaseColors; +extern GrContext *__guiBackBuffer; +extern GrContext *__guiScreenBuffer; +extern GrColor *__guiBaseColors; #define GUI_BLACK __guiBaseColors[0] diff --git a/client/src/gui/wmwindow.c b/client/src/gui/wmwindow.c index 9a5f550..aacbee3 100644 --- a/client/src/gui/wmwindow.c +++ b/client/src/gui/wmwindow.c @@ -5,8 +5,6 @@ uint8_t __MAGIC_WINDOW = 0; static WindowT **_windowList = NULL; -static GrContext *_backBuffer = NULL; -static GrContext *_screenBuffer = NULL; static GrTextOption _textOption; @@ -234,23 +232,44 @@ RegisterT *windowRegister(uint8_t magic) { } -void wmPaint(void) { - uint16_t i; - WidgetT *widget; +void wmPaint(GrMouseEvent *event) { + uint16_t i; + WidgetT *widget; + static char text[256] = { 0 }; - // Paint desktop. - GrSetContext(_backBuffer); - GrClearContext(GUI_CYAN); + // Paint event debug info. +#define APPEND (&text[strlen(text)]) +// if (event->flags != 0) { + strcpy(text, "Events: "); + if(event->flags & GR_M_MOTION) strcpy( APPEND, "[moved] "); + if(event->flags & GR_M_LEFT_DOWN) strcpy( APPEND, "[left down] "); + if(event->flags & GR_M_MIDDLE_DOWN) strcpy( APPEND, "[middle down] "); + if(event->flags & GR_M_RIGHT_DOWN) strcpy( APPEND, "[right down] "); + if(event->flags & GR_M_P4_DOWN) strcpy( APPEND, "[p4 down] "); + if(event->flags & GR_M_P5_DOWN) strcpy( APPEND, "[p5 down] "); + if(event->flags & GR_M_LEFT_UP) strcpy( APPEND, "[left up] "); + if(event->flags & GR_M_MIDDLE_UP) strcpy( APPEND, "[middle up] "); + if(event->flags & GR_M_RIGHT_UP) strcpy( APPEND, "[right up] "); + if(event->flags & GR_M_P4_UP) strcpy( APPEND, "[p4 up] "); + if(event->flags & GR_M_P5_UP) strcpy( APPEND, "[p5 up] "); + if(event->flags & GR_M_KEYPRESS) sprintf(APPEND, "[key (0x%03x)] ", event->key); + sprintf(APPEND, "at X=%d, Y=%d, ", event->x, event->y); + sprintf(APPEND, + "buttons=%c%c%c, ", + (event->buttons & GR_M_LEFT) ? 'L' : 'l', + (event->buttons & GR_M_MIDDLE) ? 'M' : 'm', + (event->buttons & GR_M_RIGHT) ? 'R' : 'r' + ); + sprintf(APPEND, "deltaT=%ld (ms)", event->dtime); +// } + GrTextXY(0, 0, text, GUI_WHITE, GUI_BLACK); // Paint all windows. for (i=0; ireg->paint(widget); } - - // Copy to screen. - GrBitBltNC(_screenBuffer, 0, 0, _backBuffer, 0, 0, GrMaxX(), GrMaxY(), GrWRITE); } @@ -259,12 +278,8 @@ void wmShutdown(void) { windowDestroy((WidgetT *)_windowList[0]); } arrfree(_windowList); - - GrDestroyContext(_backBuffer); } void wmStartup(void) { - _screenBuffer = GrScreenContext(); - _backBuffer = GrCreateContext(GrScreenX(), GrScreenY(), NULL, NULL); } diff --git a/client/src/gui/wmwindow.h b/client/src/gui/wmwindow.h index cedbae6..3c97525 100644 --- a/client/src/gui/wmwindow.h +++ b/client/src/gui/wmwindow.h @@ -32,7 +32,7 @@ void windowPaint(struct WidgetS *widget, ...); RegisterT *windowRegister(uint8_t magic); -void wmPaint(void); +void wmPaint(GrMouseEvent *event); void wmShutdown(void); void wmStartup(void);