#include "gui.h" #include "font.h" #include "wmwindow.h" #include "image.h" #include "array.h" typedef struct WidgetCatalogS { uint8_t key; // Magic RegisterT *value; } WidgetCatalogT; ColorT *__guiBaseColors = NULL; SurfaceT *__guiBackBuffer = NULL; FontT *__guiFontVGA8x8 = NULL; FontT *__guiFontVGA8x14 = NULL; FontT *__guiFontVGA8x16 = NULL; static uint8_t _magicCount = 0; static WidgetCatalogT *_widgetCatalog = NULL; static uint8_t _guiRunning = 1; static SurfaceT *_mousePointer[MOUSE_COUNT] = { 0 }; static ColorT _mouseTransparency = 0; static uint8_t _mouseCurrent = MOUSE_POINTER; static PointT _mouseHotspot[MOUSE_COUNT] = { { 0, 0 }, { 8, 8 } }; void guiEventsDo(void) { EventT event = { 0 }; // Paint desktop. surfaceSet(__guiBackBuffer); surfaceClear(GUI_CYAN); // Read mouse & keyboard. platformEventGet(&event); // Handle GUI window manager and widgets. wmUpdate(&event); // Paint mouse pointer. surfaceSet(__guiBackBuffer); surfaceBlitWithTransparency(event.x - _mouseHotspot[_mouseCurrent].x, event.y - _mouseHotspot[_mouseCurrent].y, _mousePointer[_mouseCurrent], _mouseTransparency); // Copy to screen. videoBlit(0, 0, __guiBackBuffer); // Emergency Exit? if (event.flags & EVENT_FLAG_KEYPRESS && event.key == KEY_ESC) guiStop(); } uint8_t guiMousePointerGet(void) { return _mouseCurrent; } void guiMousePointerSet(uint8_t pointer) { _mouseCurrent = pointer; } void guiRegister(WidgetRegisterT widgetRegister) { RegisterT *reg = widgetRegister(_magicCount); hmput(_widgetCatalog, _magicCount, reg); _magicCount++; } void guiRun(void) { while (_guiRunning) { // Process all GUI events. guiEventsDo(); } } void guiShutdown(void) { uint8_t i; DEL(__guiBaseColors); while (hmlen(_widgetCatalog) > 0) { if (_widgetCatalog[0].value->unregister) _widgetCatalog[0].value->unregister(NULL); hmdel(_widgetCatalog, _widgetCatalog[0].key); } hmfree(_widgetCatalog); wmShutdown(); fontUnload(&__guiFontVGA8x16); fontUnload(&__guiFontVGA8x14); fontUnload(&__guiFontVGA8x8); for (i=0; imagic = magic; widget->r.x = x; widget->r.y = y; widget->r.w = w; widget->r.h = h; widget->reg = hmget(_widgetCatalog, magic); widget->dirty = 1; // Everything starts dirty to force a paint. } uint8_t guiWidgetDirtyGet(WidgetT *widget) { return widget->dirty; } void guiWidgetDirtySet(WidgetT *widget, uint8_t dirty) { widget->dirty = dirty; }