int main(void) { coord_t swidth, sheight; halInit(); // Initialize the Hardware chSysInit(); // Initialize the OS gdispInit(); // Initialize the display gdispClear(Black); // Get the display dimensions swidth = gdispGetWidth(); sheight = gdispGetHeight(); // Set up IO for our image #if USE_MEMORY_FILE gdispImageSetMemoryReader(&myImage, test_pal8); #else gdispImageSetSimulFileReader(&myImage, "test-pal8.bmp"); #endif gdispImageOpen(&myImage); gdispImageDraw(&myImage, 0, 0, swidth, sheight, 0, 0); gdispImageClose(&myImage); while(1) { chThdSleepMilliseconds(1000); } return 0; }
bool_t gwinImageOpenStream(GHandle gh, void *streamPtr) { if (gdispImageIsOpen(&widget(gh)->image)) gdispImageClose(&widget(gh)->image); if (!gdispImageSetBaseFileStreamReader(&widget(gh)->image, streamPtr)) return FALSE; if (gdispImageOpen(&widget(gh)->image) != GDISP_IMAGE_ERR_OK) return FALSE; if ((gh->flags & GWIN_FLG_VISIBLE)) { // Setting the clip here shouldn't be necessary if the redraw doesn't overdraw // but we put it in for safety anyway #if GDISP_NEED_CLIP gdispSetClip(gh->x, gh->y, gh->width, gh->height); #endif _redraw(gh); } return TRUE; }
static msg_t notepadThread(void *param) { GEventMouse *pem; GEventGWinButton *peb; GHandle ghc; (void)param; /* Get the display dimensions */ swidth = gdispGetWidth(); sheight = gdispGetHeight(); font = gdispOpenFont("UI2"); /* Initialize the mouse */ geventListenerInit(&gl); ginputGetMouse(0); initButtons(); /* Configure the GIF decoder with the toolbar Icon images */ gdispImageSetMemoryReader(&toolbarImageFilmstrip, toolbarIcons); gdispImageOpen(&toolbarImageFilmstrip); /* Set clip to the entire screen */ gdispSetClip(0, 0, swidth, sheight); /* Clear the screen with the window background * Also, draw the title bars */ gdispClear(nCurColorScheme.winBgColor); gdispDrawBox(0, 0, swidth, sheight, nCurColorScheme.titleBarColor); gdispFillArea(0, 0, swidth, NPAD_TITLEBAR_HEIGHT, nCurColorScheme.titleBarColor); gdispDrawStringBox(NPAD_TITLETEXT_START_X, NPAD_TITLETEXT_START_Y, swidth, NPAD_TITLEBAR_HEIGHT, NPAD_TITLETEXT_STR, font, nCurColorScheme.titleTextColor, justifyLeft); /* Create the drawing window, draw its border */ gdispDrawBox(NPAD_DRAWING_AREA_START_X - 1, NPAD_DRAWING_AREA_START_Y - 1, NPAD_DRAWING_AREA_WIDTH + 2, NPAD_DRAWING_AREA_HEIGHT + 2, nCurColorScheme.drawingWinBorder); nDrawingArea = gwinCreateWindow(NULL, NPAD_DRAWING_AREA_START_X, NPAD_DRAWING_AREA_START_Y, NPAD_DRAWING_AREA_WIDTH, NPAD_DRAWING_AREA_HEIGHT); /* Create the bottom status bar console */ ghc = gwinCreateConsole(NULL, NPAD_STATUSBAR_START_X, NPAD_STATUSBAR_START_Y, NPAD_STATUSBAR_WIDTH, NPAD_STATUSBAR_HEIGHT, font); gdispImageDraw(&toolbarImageFilmstrip, NPAD_STATUSBAR_ICON_START_X, NPAD_STATUSBAR_ICON_START_Y, NPAD_ICON_WIDTH, NPAD_ICON_HEIGHT, NPAD_ICON_START(12), 0); gwinSetBgColor(ghc, nCurColorScheme.winBgColor); gwinSetColor(ghc, Black); gstatusConsole = gwinGetConsoleStream(ghc); /* draw the buttons */ gwinSetColor(nDrawingArea, Black); gwinSetBgColor(nDrawingArea, White); gwinClear(nDrawingArea); gwinClear(ghc); drawButtons(); drawVButtons(); chprintf(gstatusConsole, "Welcome to ChibiOS/GFX Notepad demo."); ncoreSpawnDrawThread(nDrawingArea, gstatusConsole); while(TRUE) { pem = (GEventMouse *) geventEventWait(&gl, TIME_INFINITE); /* button pressed... */ if (pem->type == GEVENT_GWIN_BUTTON) { peb = (GEventGWinButton *)pem; if (peb->button == H(btnNew)) { // Reset all the settings selColorIndex = 0; selPenWidth = 0; ncoreSetMode(NCORE_MODE_DRAW); gwinSetColor(nDrawingArea, Black); gwinSetBgColor(nDrawingArea, White); // Refresh the buttons drawButtons(); drawVButtons(); gwinClear(nDrawingArea); chprintf(gstatusConsole, "\nScreen Cleared."); } else if (peb->button == H(btnOpen)) { chprintf(gstatusConsole, "\nFile Open not implemented."); } else if (peb->button == H(btnSave)) { chprintf(gstatusConsole, "\nFile Save not implemented."); } else if (peb->button == H(btnPencil)) { ncoreSetMode(NCORE_MODE_DRAW); drawVButtons(); chprintf(gstatusConsole, "\nPencil Tool Selected."); } else if (peb->button == H(btnEraser)) { ncoreSetMode(NCORE_MODE_ERASE); drawVButtons(); chprintf(gstatusConsole, "\nEraser Tool Selected."); } else if (peb->button == H(btnFill)) { ncoreSetMode(NCORE_MODE_FILL); drawVButtons(); chprintf(gstatusConsole, "\nFill Tool Selected."); } else if (peb->button == H(btnClose)) { break; } } } gwinDestroyWindow(ghc); // No need to destroy the buttons as they are statically allocated gdispCloseFont(font); ncoreTerminateDrawThread(); gdispImageClose(&toolbarImageFilmstrip); return 0; }
/** * Create all the widgets. * With the exception of the Tabs they are all created invisible. */ static void createWidgets(void) { GWidgetInit wi; wi.customDraw = 0; wi.customParam = 0; wi.customStyle = 0; // Create the Tabs wi.g.show = TRUE; wi.customDraw = gwinRadioDraw_Tab; wi.g.width = ScrWidth/7; wi.g.height = TAB_HEIGHT; wi.g.y = 0; wi.g.x = 0*wi.g.width; wi.text = "Buttons"; ghTabButtons = gwinRadioCreate(NULL, &wi, GROUP_TABS); wi.g.x = 1*wi.g.width; wi.text = "Sliders"; ghTabSliders = gwinRadioCreate(NULL, &wi, GROUP_TABS); wi.g.x = 2*wi.g.width; wi.text = "Checkbox"; ghTabCheckboxes = gwinRadioCreate(NULL, &wi, GROUP_TABS); wi.g.x = 3*wi.g.width; wi.text = "Radios"; ghTabRadios = gwinRadioCreate(NULL, &wi, GROUP_TABS); wi.g.x = 4*wi.g.width; wi.text = "Lists"; ghTabLists = gwinRadioCreate(NULL, &wi, GROUP_TABS); wi.g.x = 5*wi.g.width; wi.text = "Labels"; ghTabLabels = gwinRadioCreate(NULL, &wi, GROUP_TABS); wi.g.x = 6*wi.g.width; wi.text = "Images"; ghTabImages = gwinRadioCreate(NULL, &wi, GROUP_TABS); // Buttons wi.g.show = FALSE; wi.customDraw = 0; wi.g.width = BUTTON_WIDTH; wi.g.height = BUTTON_HEIGHT; wi.g.y = TAB_HEIGHT+5; wi.g.x = 0+0*(BUTTON_WIDTH+1); wi.text = "B1"; ghButton1 = gwinButtonCreate(NULL, &wi); wi.g.x = 0+1*(BUTTON_WIDTH+1); wi.text = "B2"; ghButton2 = gwinButtonCreate(NULL, &wi); wi.g.x = 0+2*(BUTTON_WIDTH+1); wi.text = "B3"; ghButton3 = gwinButtonCreate(NULL, &wi); wi.g.x = 0+3*(BUTTON_WIDTH+1); wi.text = "B4"; ghButton4 = gwinButtonCreate(NULL, &wi); // Horizontal Sliders wi.g.width = ScrWidth/2-2; wi.g.height = SLIDER_WIDTH; wi.g.x = ScrWidth/2+1; wi.g.y = ScrHeight/2-2*(SLIDER_WIDTH+1); wi.text = "S1"; ghSlider1 = gwinSliderCreate(NULL, &wi); wi.g.y = ScrHeight/2-1*(SLIDER_WIDTH+1); wi.text = "S2"; ghSlider2 = gwinSliderCreate(NULL, &wi); // Vertical Sliders wi.g.width = SLIDER_WIDTH; wi.g.height = ScrHeight/2-2; wi.g.y = ScrHeight/2+1; wi.g.x = 0+0*(SLIDER_WIDTH+1); wi.text = "S3"; ghSlider3 = gwinSliderCreate(NULL, &wi); wi.g.x = 0+1*(SLIDER_WIDTH+1); wi.text = "S4"; ghSlider4 = gwinSliderCreate(NULL, &wi); // Checkboxes - for the 2nd checkbox we apply special drawing before making it visible wi.g.width = CHECKBOX_WIDTH; wi.g.height = CHECKBOX_HEIGHT; wi.g.x = 0; wi.g.y = TAB_HEIGHT+5+0*(CHECKBOX_HEIGHT+1); wi.text = "C1"; ghCheckbox1 = gwinCheckboxCreate(NULL, &wi); wi.customDraw = gwinCheckboxDraw_CheckOnRight; wi.g.y = TAB_HEIGHT+5+1*(CHECKBOX_HEIGHT+1); wi.text = "C2"; ghCheckbox2 = gwinCheckboxCreate(NULL, &wi); wi.customDraw = 0; wi.g.width = DISABLEALL_WIDTH; wi.g.y = TAB_HEIGHT+5+2*(CHECKBOX_HEIGHT+1); wi.text = "Disable All"; ghCheckDisableAll = gwinCheckboxCreate(NULL, &wi); // Labels wi.g.width = 0; wi.g.height = LABEL_HEIGHT; // dynamic width, fixed height wi.g.y = TAB_HEIGHT+5+2*(CHECKBOX_HEIGHT+1); wi.text = "Label"; ghLabel1 = gwinLabelCreate(NULL, &wi); // Radio Buttons wi.g.width = RADIO_WIDTH; wi.g.height = RADIO_HEIGHT; wi.g.y = TAB_HEIGHT+5; wi.g.x = 0*wi.g.width; wi.text = "Yes"; ghRadio1 = gwinRadioCreate(NULL, &wi, GROUP_YESNO); wi.g.x = 1*wi.g.width; wi.text = "No"; ghRadio2 = gwinRadioCreate(NULL, &wi, GROUP_YESNO); wi.g.width = COLOR_WIDTH; wi.g.y += RADIO_HEIGHT+5; wi.g.x = 0*wi.g.width; wi.text = "Black"; ghRadioBlack = gwinRadioCreate(NULL, &wi, GROUP_COLORS); wi.g.x = 1*wi.g.width; wi.text = "White"; ghRadioWhite = gwinRadioCreate(NULL, &wi, GROUP_COLORS); wi.g.x = 2*wi.g.width; wi.text = "Yellow"; ghRadioYellow = gwinRadioCreate(NULL, &wi, GROUP_COLORS); gwinRadioPress(ghRadioWhite); // Lists wi.g.show = FALSE; wi.customDraw = 0; wi.g.width = LIST_WIDTH; wi.g.height = LIST_HEIGHT; wi.g.y = TAB_HEIGHT+5; wi.g.x = 0+0*(LIST_WIDTH+1); wi.text = "L1"; ghList1 = gwinListCreate(NULL, &wi, FALSE); gwinListAddItem(ghList1, "Item 0", FALSE); gwinListAddItem(ghList1, "Item 1", FALSE); gwinListAddItem(ghList1, "Item 2", FALSE); gwinListAddItem(ghList1, "Item 3", FALSE); gwinListAddItem(ghList1, "Item 4", FALSE); gwinListAddItem(ghList1, "Item 5", FALSE); gwinListAddItem(ghList1, "Item 6", FALSE); gwinListAddItem(ghList1, "Item 7", FALSE); gwinListAddItem(ghList1, "Item 8", FALSE); gwinListAddItem(ghList1, "Item 9", FALSE); gwinListAddItem(ghList1, "Item 10", FALSE); gwinListAddItem(ghList1, "Item 11", FALSE); gwinListAddItem(ghList1, "Item 12", FALSE); gwinListAddItem(ghList1, "Item 13", FALSE); wi.g.x = 0+1*(LIST_WIDTH+1); wi.text = "L2"; ghList2 = gwinListCreate(NULL, &wi, TRUE); gwinListAddItem(ghList2, "Item 0", FALSE); gwinListAddItem(ghList2, "Item 1", FALSE); gwinListAddItem(ghList2, "Item 2", FALSE); gwinListAddItem(ghList2, "Item 3", FALSE); gwinListAddItem(ghList2, "Item 4", FALSE); gwinListAddItem(ghList2, "Item 5", FALSE); gwinListAddItem(ghList2, "Item 6", FALSE); gwinListAddItem(ghList2, "Item 7", FALSE); gwinListAddItem(ghList2, "Item 8", FALSE); gwinListAddItem(ghList2, "Item 9", FALSE); gwinListAddItem(ghList2, "Item 10", FALSE); gwinListAddItem(ghList2, "Item 11", FALSE); gwinListAddItem(ghList2, "Item 12", FALSE); gwinListAddItem(ghList2, "Item 13", FALSE); wi.g.x = 0+2*(LIST_WIDTH+1); wi.text = "L3"; ghList3 = gwinListCreate(NULL, &wi, TRUE); gwinListAddItem(ghList3, "Item 0", FALSE); gwinListAddItem(ghList3, "Item 1", FALSE); gwinListAddItem(ghList3, "Item 2", FALSE); gwinListAddItem(ghList3, "Item 3", FALSE); gdispImageSetMemoryReader(&imgYesNo, image_yesno); gdispImageOpen(&imgYesNo); gwinListItemSetImage(ghList3, 1, &imgYesNo); gwinListItemSetImage(ghList3, 3, &imgYesNo); // Image wi.g.x = ScrWidth-210; wi.g.y = TAB_HEIGHT + 10; wi.g.width = 200; wi.g.height = 200; ghImage1 = gwinImageCreate(NULL, &wi.g); gwinImageOpenMemory(ghImage1, image_chibios); gwinImageCache(ghImage1); // Console - we apply some special colors before making it visible wi.g.width = ScrWidth/2-1; wi.g.height = ScrHeight/2-1; wi.g.x = ScrWidth/2+1; wi.g.y = ScrHeight/2+1; ghConsole = gwinConsoleCreate(NULL, &wi.g); gwinSetColor(ghConsole, Yellow); gwinSetBgColor(ghConsole, Black); }