Mouse pointer working
This commit is contained in:
parent
29601df2a9
commit
b5af19dd12
5 changed files with 89 additions and 55 deletions
BIN
client/assets/mouse.png
(Stored with Git LFS)
Normal file
BIN
client/assets/mouse.png
(Stored with Git LFS)
Normal file
Binary file not shown.
|
@ -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();
|
||||
|
||||
|
|
|
@ -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]
|
||||
|
|
|
@ -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; i<arrlen(_windowList); i++) {
|
||||
GrSetContext(_backBuffer);
|
||||
GrSetContext(__guiBackBuffer);
|
||||
widget = (WidgetT *)_windowList[i];
|
||||
widget->reg->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);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue