Working double buffering
This commit is contained in:
parent
0748aaf9e2
commit
29601df2a9
3 changed files with 62 additions and 8 deletions
|
@ -63,8 +63,39 @@ void guiModesShow(void) {
|
||||||
|
|
||||||
|
|
||||||
void guiRun(void) {
|
void guiRun(void) {
|
||||||
|
char text[256] = { 0 };
|
||||||
|
GrMouseEvent event;
|
||||||
|
|
||||||
|
#define APPEND (&text[strlen(text)])
|
||||||
|
|
||||||
while (_guiRunning) {
|
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();
|
wmPaint();
|
||||||
|
GrTextXY(0, 0, text, GUI_WHITE, GUI_BLACK);
|
||||||
if (GrKeyRead() == GrKey_Escape) guiStop();
|
if (GrKeyRead() == GrKey_Escape) guiStop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -78,14 +109,17 @@ void guiRegister(WidgetRegisterT widgetRegister) {
|
||||||
|
|
||||||
|
|
||||||
void guiShutdown(void) {
|
void guiShutdown(void) {
|
||||||
wmShutdown();
|
|
||||||
|
|
||||||
while (hmlen(_widgetCatalog) > 0) {
|
while (hmlen(_widgetCatalog) > 0) {
|
||||||
if (_widgetCatalog[0].value->unregister) _widgetCatalog[0].value->unregister(NULL);
|
if (_widgetCatalog[0].value->unregister) _widgetCatalog[0].value->unregister(NULL);
|
||||||
hmdel(_widgetCatalog, _widgetCatalog[0].key);
|
hmdel(_widgetCatalog, _widgetCatalog[0].key);
|
||||||
}
|
}
|
||||||
hmfree(_widgetCatalog);
|
hmfree(_widgetCatalog);
|
||||||
|
|
||||||
|
wmShutdown();
|
||||||
|
|
||||||
|
GrMouseEraseCursor();
|
||||||
|
GrMouseUnInit();
|
||||||
|
|
||||||
DEL(__guiBaseColors);
|
DEL(__guiBaseColors);
|
||||||
|
|
||||||
GrSetMode(GR_default_text);
|
GrSetMode(GR_default_text);
|
||||||
|
@ -96,10 +130,15 @@ void guiStartup(int16_t width, int16_t height, int16_t depth) {
|
||||||
if (!GrSetMode(GR_width_height_bpp_graphics, width, height, depth)) {
|
if (!GrSetMode(GR_width_height_bpp_graphics, width, height, depth)) {
|
||||||
//***TODO*** Die
|
//***TODO*** Die
|
||||||
}
|
}
|
||||||
|
|
||||||
GrSetRGBcolorMode();
|
GrSetRGBcolorMode();
|
||||||
__guiBaseColors = GrAllocEgaColors();
|
__guiBaseColors = GrAllocEgaColors();
|
||||||
|
|
||||||
|
GrMouseInit();
|
||||||
|
GrMouseEventEnable(1, 1);
|
||||||
|
GrMouseSetColors(GUI_WHITE, GUI_BLACK);
|
||||||
|
GrMouseSetCursorMode(GR_M_CUR_NORMAL);
|
||||||
|
GrMouseDisplayCursor();
|
||||||
|
|
||||||
wmStartup();
|
wmStartup();
|
||||||
|
|
||||||
guiRegister(windowRegister);
|
guiRegister(windowRegister);
|
||||||
|
|
|
@ -4,7 +4,9 @@
|
||||||
|
|
||||||
uint8_t __MAGIC_WINDOW = 0;
|
uint8_t __MAGIC_WINDOW = 0;
|
||||||
|
|
||||||
static WindowT **_windowList = NULL;
|
static WindowT **_windowList = NULL;
|
||||||
|
static GrContext *_backBuffer = NULL;
|
||||||
|
static GrContext *_screenBuffer = NULL;
|
||||||
static GrTextOption _textOption;
|
static GrTextOption _textOption;
|
||||||
|
|
||||||
|
|
||||||
|
@ -237,14 +239,18 @@ void wmPaint(void) {
|
||||||
WidgetT *widget;
|
WidgetT *widget;
|
||||||
|
|
||||||
// Paint desktop.
|
// Paint desktop.
|
||||||
GrClearScreen(GUI_CYAN);
|
GrSetContext(_backBuffer);
|
||||||
|
GrClearContext(GUI_CYAN);
|
||||||
|
|
||||||
// Paint all windows.
|
// Paint all windows.
|
||||||
for (i=0; i<arrlen(_windowList); i++) {
|
for (i=0; i<arrlen(_windowList); i++) {
|
||||||
GrSetContext(GrScreenContext());
|
GrSetContext(_backBuffer);
|
||||||
widget = (WidgetT *)_windowList[i];
|
widget = (WidgetT *)_windowList[i];
|
||||||
widget->reg->paint(widget);
|
widget->reg->paint(widget);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Copy to screen.
|
||||||
|
GrBitBltNC(_screenBuffer, 0, 0, _backBuffer, 0, 0, GrMaxX(), GrMaxY(), GrWRITE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -253,9 +259,12 @@ void wmShutdown(void) {
|
||||||
windowDestroy((WidgetT *)_windowList[0]);
|
windowDestroy((WidgetT *)_windowList[0]);
|
||||||
}
|
}
|
||||||
arrfree(_windowList);
|
arrfree(_windowList);
|
||||||
|
|
||||||
|
GrDestroyContext(_backBuffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void wmStartup(void) {
|
void wmStartup(void) {
|
||||||
|
_screenBuffer = GrScreenContext();
|
||||||
|
_backBuffer = GrCreateContext(GrScreenX(), GrScreenY(), NULL, NULL);
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,13 +3,19 @@
|
||||||
|
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[]) {
|
||||||
|
char title[256];
|
||||||
|
uint16_t i;
|
||||||
|
|
||||||
(void)argc;
|
(void)argc;
|
||||||
(void)argv;
|
(void)argv;
|
||||||
|
|
||||||
guiStartup(800, 600, 24);
|
guiStartup(800, 600, 24);
|
||||||
|
|
||||||
windowCreate(50, 50, 300, 200, "Testing", WIN_CLOSE | WIN_MAXIMIZE | WIN_MINIMIZE | WIN_RESIZE);
|
for (i=1; i<4; i++) {
|
||||||
|
sprintf(title, "Testing %d", i);
|
||||||
|
windowCreate(i * 50, i * 50, 300, 200, title, WIN_CLOSE | WIN_MAXIMIZE | WIN_MINIMIZE | WIN_RESIZE);
|
||||||
|
}
|
||||||
|
|
||||||
guiRun();
|
guiRun();
|
||||||
|
|
||||||
guiShutdown();
|
guiShutdown();
|
||||||
|
|
Loading…
Add table
Reference in a new issue