static void pointto(GGraphObject *gg, coord_t x, coord_t y, const GGraphPointStyle *style) { if (style->type == GGRAPH_POINT_NONE) return; // Convert to device space. Note the y-axis is inverted. x += gg->g.x + gg->xorigin; y = gg->g.y + gg->g.height - 1 - gg->yorigin - y; if (style->size <= 1) { gdispDrawPixel(x, y, style->color); return; } switch(style->type) { case GGRAPH_POINT_SQUARE: gdispDrawBox(x-style->size, y-style->size, 2*style->size, 2*style->size, style->color); break; #if GDISP_NEED_CIRCLE case GGRAPH_POINT_CIRCLE: gdispDrawCircle(x, y, style->size, style->color); break; #endif case GGRAPH_POINT_DOT: default: gdispDrawPixel(x, y, style->color); break; } }
void drawScreen(void) { char *msg = "ChibiOS/GFX"; font_t font1, font2; font1 = gdispOpenFont("UI2 Double"); font2 = gdispOpenFont("LargeNumbers"); gdispClear(White); gdispDrawString(gdispGetWidth()-gdispGetStringWidth(msg, font1)-3, 3, msg, font1, Black); /* colors */ gdispFillArea(0 * COLOR_SIZE + 3, 3, COLOR_SIZE, COLOR_SIZE, Black); /* Black */ gdispFillArea(1 * COLOR_SIZE + 3, 3, COLOR_SIZE, COLOR_SIZE, Red); /* Red */ gdispFillArea(2 * COLOR_SIZE + 3, 3, COLOR_SIZE, COLOR_SIZE, Yellow); /* Yellow */ gdispFillArea(3 * COLOR_SIZE + 3, 3, COLOR_SIZE, COLOR_SIZE, Green); /* Green */ gdispFillArea(4 * COLOR_SIZE + 3, 3, COLOR_SIZE, COLOR_SIZE, Blue); /* Blue */ gdispDrawBox (5 * COLOR_SIZE + 3, 3, COLOR_SIZE, COLOR_SIZE, Black); /* White */ /* pens */ gdispDrawString(OFFSET * 2, DRAW_PEN(1), "1", font2, Black); gdispDrawString(OFFSET * 2, DRAW_PEN(2), "2", font2, Black); gdispDrawString(OFFSET * 2, DRAW_PEN(3), "3", font2, Black); gdispDrawString(OFFSET * 2, DRAW_PEN(4), "4", font2, Black); gdispDrawString(OFFSET * 2, DRAW_PEN(5), "5", font2, Black); gdispCloseFont(font1); gdispCloseFont(font2); }
void drawScreen(void) { char *msg = "uGFX"; font_t font1, font2; font1 = gdispOpenFont("DejaVuSans24*"); font2 = gdispOpenFont("DejaVuSans12*"); gdispClear(White); gdispDrawString(gdispGetWidth()-gdispGetStringWidth(msg, font1)-3, 3, msg, font1, Black); /* colors */ gdispFillArea(0 * COLOR_SIZE + 3, 3, COLOR_SIZE, COLOR_SIZE, Black); /* Black */ gdispFillArea(1 * COLOR_SIZE + 3, 3, COLOR_SIZE, COLOR_SIZE, Red); /* Red */ gdispFillArea(2 * COLOR_SIZE + 3, 3, COLOR_SIZE, COLOR_SIZE, Yellow); /* Yellow */ gdispFillArea(3 * COLOR_SIZE + 3, 3, COLOR_SIZE, COLOR_SIZE, Green); /* Green */ gdispFillArea(4 * COLOR_SIZE + 3, 3, COLOR_SIZE, COLOR_SIZE, Blue); /* Blue */ gdispDrawBox (5 * COLOR_SIZE + 3, 3, COLOR_SIZE, COLOR_SIZE, Black); /* White */ /* pens */ gdispFillStringBox(OFFSET * 2, DRAW_PEN(1), PEN_SIZE, PEN_SIZE, "1", font2, White, Black, justifyCenter); gdispFillStringBox(OFFSET * 2, DRAW_PEN(2), PEN_SIZE, PEN_SIZE, "2", font2, White, Black, justifyCenter); gdispFillStringBox(OFFSET * 2, DRAW_PEN(3), PEN_SIZE, PEN_SIZE, "3", font2, White, Black, justifyCenter); gdispFillStringBox(OFFSET * 2, DRAW_PEN(4), PEN_SIZE, PEN_SIZE, "4", font2, White, Black, justifyCenter); gdispFillStringBox(OFFSET * 2, DRAW_PEN(5), PEN_SIZE, PEN_SIZE, "5", font2, White, Black, justifyCenter); gdispCloseFont(font1); gdispCloseFont(font2); }
int main(void) { coord_t width, height; coord_t i, j; halInit(); chSysInit(); /* Initialize and clear the display */ gdispInit(); gdispClear(Black); // Get the screen size width = gdispGetWidth(); height = gdispGetHeight(); // Code Here gdispDrawBox(10, 10, width/2, height/2, Yellow); gdispFillArea(width/2, height/2, width/2-10, height/2-10, Blue); gdispDrawLine(5, 30, width-50, height-40, Red); for(i = 5, j = 0; i < width && j < height; i += 7, j += i/20) gdispDrawPixel (i, j, White); while(TRUE) { chThdSleepMilliseconds(500); } }
void gwinDrawBox(GHandle gh, coord_t x, coord_t y, coord_t cx, coord_t cy) { if (!((gh->flags & GWIN_FLG_VISIBLE))) return; #if GDISP_NEED_CLIP gdispSetClip(gh->x, gh->y, gh->width, gh->height); #endif gdispDrawBox(gh->x+x, gh->y+y, cx, cy, gh->color); }
static void nToolbarImageButtonDraw(GHandle gh, bool_t isenabled, bool_t isdown, const char *txt, const GButtonDrawStyle *pstyle, void *param) { (void)txt; (void)pstyle; (void)isenabled; color_t cl = isdown ? nCurColorScheme.toolbarBgActive : nCurColorScheme.toolbarBgUnsel; gdispImageSetBgColor(&toolbarImageFilmstrip, cl); gdispFillArea(gh->x, gh->y, gh->width, gh->height, cl); gwinImageDraw(gh, &toolbarImageFilmstrip, 2, 2, NPAD_ICON_WIDTH, NPAD_ICON_HEIGHT, NPAD_ICON_START((int) param), 0); if (isdown || ((int)param - 5) == ncoreGetMode()) gdispDrawBox(gh->x, gh->y, gh->width, gh->height, nCurColorScheme.toolbarSeparator); }
void gdispDrawRoundedBox(coord_t x, coord_t y, coord_t cx, coord_t cy, coord_t radius, color_t color) { if (2*radius > cx || 2*radius > cy) { gdispDrawBox(x, y, cx, cy, color); return; } gdispDrawArc(x+radius, y+radius, radius, 90, 180, color); gdispDrawLine(x+radius+1, y, x+cx-2-radius, y, color); gdispDrawArc(x+cx-1-radius, y+radius, radius, 0, 90, color); gdispDrawLine(x+cx-1, y+radius+1, x+cx-1, y+cy-2-radius, color); gdispDrawArc(x+cx-1-radius, y+cy-1-radius, radius, 270, 360, color); gdispDrawLine(x+radius+1, y+cy-1, x+cx-2-radius, y+cy-1, color); gdispDrawArc(x+radius, y+cy-1-radius, radius, 180, 270, color); gdispDrawLine(x, y+radius+1, x, y+cy-2-radius, color); }
void gwinFrameDraw_Transparent(GWidgetObject *gw, void *param) { const GColorSet *pcol; coord_t pos; color_t contrast; color_t btn; (void)param; if (gw->g.vmt != (gwinVMT *)&frameVMT) return; pcol = (gw->g.flags & GWIN_FLG_SYSENABLED) ? &gw->pstyle->enabled : &gw->pstyle->disabled; contrast = gdispContrastColor(pcol->edge); btn = gdispBlendColor(pcol->edge, contrast, 128); // Render the frame gdispGFillStringBox(gw->g.display, gw->g.x, gw->g.y, gw->g.width, FRM_BORDER_T, gw->text, gw->g.font, contrast, pcol->edge, justifyCenter); gdispGFillArea(gw->g.display, gw->g.x, gw->g.y+FRM_BORDER_T, FRM_BORDER_L, gw->g.height-(FRM_BORDER_T+FRM_BORDER_B), pcol->edge); gdispGFillArea(gw->g.display, gw->g.x+gw->g.width-FRM_BORDER_R, gw->g.y+FRM_BORDER_T, FRM_BORDER_R, gw->g.height-(FRM_BORDER_T+FRM_BORDER_B), pcol->edge); gdispGFillArea(gw->g.display, gw->g.x, gw->g.y+gw->g.height-FRM_BORDER_B, gw->g.width, FRM_BORDER_B, pcol->edge); // Add the buttons pos = gw->g.x+gw->g.width - (FRM_BORDER_R+FRM_BUTTON_X); if ((gw->g.flags & GWIN_FRAME_CLOSE_BTN)) { if ((gw->g.flags & GWIN_FRAME_CLOSE_PRESSED)) gdispFillArea(pos, gw->g.y+FRM_BUTTON_T, FRM_BUTTON_X, FRM_BUTTON_Y, btn); gdispDrawLine(pos+FRM_BUTTON_I, gw->g.y+(FRM_BUTTON_T+FRM_BUTTON_I), pos+(FRM_BUTTON_X-FRM_BUTTON_I-1), gw->g.y+(FRM_BUTTON_T+FRM_BUTTON_Y-FRM_BUTTON_I-1), contrast); gdispDrawLine(pos+(FRM_BUTTON_X-FRM_BUTTON_I-1), gw->g.y+(FRM_BUTTON_T+FRM_BUTTON_I), pos+FRM_BUTTON_I, gw->g.y+(FRM_BUTTON_T+FRM_BUTTON_Y-FRM_BUTTON_I-1), contrast); pos -= FRM_BUTTON_X; } if ((gw->g.flags & GWIN_FRAME_MINMAX_BTN)) { if ((gw->g.flags & GWIN_FRAME_MAX_PRESSED)) gdispFillArea(pos, gw->g.y+FRM_BUTTON_T, FRM_BUTTON_X, FRM_BUTTON_Y, btn); // the symbol gdispDrawBox(pos+FRM_BUTTON_I, gw->g.y+(FRM_BUTTON_T+FRM_BUTTON_I), FRM_BUTTON_X-2*FRM_BUTTON_I, FRM_BUTTON_Y-2*FRM_BUTTON_I, contrast); gdispDrawLine(pos+(FRM_BUTTON_I+1), gw->g.y+(FRM_BUTTON_T+FRM_BUTTON_I+1), pos+(FRM_BUTTON_X-FRM_BUTTON_I-2), gw->g.y+(FRM_BUTTON_T+FRM_BUTTON_I+1), contrast); gdispDrawLine(pos+(FRM_BUTTON_I+1), gw->g.y+(FRM_BUTTON_T+FRM_BUTTON_I+2), pos+(FRM_BUTTON_X-FRM_BUTTON_I-2), gw->g.y+(FRM_BUTTON_T+FRM_BUTTON_I+2), contrast); pos -= FRM_BUTTON_X; if ((gw->g.flags & GWIN_FRAME_MIN_PRESSED)) gdispFillArea(pos, gw->g.y+FRM_BUTTON_T, FRM_BUTTON_X, FRM_BUTTON_Y, btn); gdispDrawLine(pos+FRM_BUTTON_I, gw->g.y+(FRM_BUTTON_T+FRM_BUTTON_Y-FRM_BUTTON_I-1), pos+(FRM_BUTTON_X-FRM_BUTTON_I-1), gw->g.y+(FRM_BUTTON_T+FRM_BUTTON_Y-FRM_BUTTON_I-1), contrast); pos -= FRM_BUTTON_X; } // Don't touch the client area }
void gwinCheckboxDraw_CheckOnLeft(GWidgetObject *gw, void *param) { #define gcw ((GCheckboxObject *)gw) coord_t ld, df; const GColorSet * pcol; (void) param; if (gw->g.vmt != (gwinVMT *)&checkboxVMT) return; pcol = getDrawColors(gw); ld = gw->g.width < gw->g.height ? gw->g.width : gw->g.height; gdispFillArea(gw->g.x+1, gw->g.y+1, ld, ld-2, gw->pstyle->background); gdispDrawBox(gw->g.x, gw->g.y, ld, ld, pcol->edge); df = ld < 4 ? 1 : 2; if (gw->g.flags & GCHECKBOX_FLG_CHECKED) gdispFillArea(gw->g.x+df, gw->g.y+df, ld-2*df, ld-2*df, pcol->fill); gdispFillStringBox(gw->g.x+ld+1, gw->g.y, gw->g.width-ld-1, gw->g.height, gw->text, gw->g.font, pcol->text, gw->pstyle->background, justifyLeft); #undef gcw }
// Custom drawing functions for the buttons static void nbtnColorBarDraw(GHandle gh, bool_t enabled, bool_t isdown, const char *txt, const GButtonDrawStyle *pstyle, void *param) { #define ccs nCurColorScheme int i, j, k; (void)txt; (void)pstyle; (void)param; (void)enabled; ginputGetMouseStatus(0, &curPtr); // Draw the toolbars according to the mode if (tbMode == 0) { k = (curPtr.x - gh->x) / (NPAD_COLORBAR_WIDTH / 8); for (i = 0; i < 8; i++) { j = gh->x + (NPAD_TOOLBAR_BTN_WIDTH / 2) + NPAD_TOOLBAR_BTN_WIDTH * i; if (isdown == TRUE) { // Update selection - this is like lazy release. if (k >= 0 && k <= 7) { selPenWidth = k + 1; ncoreSetPenWidth((uint8_t) selPenWidth); } gdispFillArea(gh->x + NPAD_TOOLBAR_BTN_WIDTH * i, gh->y, NPAD_TOOLBAR_BTN_WIDTH, NPAD_TOOLBAR_BTN_HEIGHT, selPenWidth - i == 1 ? ccs.toolbarBgActive : ccs.toolbarBgUnsel); } else { gdispFillArea(gh->x + NPAD_TOOLBAR_BTN_WIDTH * i, gh->y, NPAD_TOOLBAR_BTN_WIDTH, NPAD_TOOLBAR_BTN_HEIGHT, selPenWidth - i == 1 ? ccs.toolbarBgSel : ccs.toolbarBgUnsel); gdispDrawBox(gh->x + NPAD_TOOLBAR_BTN_WIDTH * i, gh->y, NPAD_TOOLBAR_BTN_WIDTH, NPAD_TOOLBAR_BTN_HEIGHT, selPenWidth - i == 1 ? ccs.toolbarSeparator: ccs.toolbarBgUnsel); } gdispFillCircle(j, gh->y + 10, i + 1, myColors[selColorIndex]); } } else { k = (curPtr.x - gh->x) / (NPAD_COLORBAR_WIDTH / 8); for (i = 0; i < 8; i++) { j = gh->x + (NPAD_TOOLBAR_BTN_WIDTH / 2) + NPAD_TOOLBAR_BTN_WIDTH * i; if (isdown == TRUE) { // Update selection - this is like lazy release. if (k >= 0 && k <= 7) { selColorIndex = k; selColor = myColors[k]; ncoreSetPenColor(selColor); } gdispFillArea(gh->x + NPAD_TOOLBAR_BTN_WIDTH * i, gh->y, NPAD_TOOLBAR_BTN_WIDTH, NPAD_TOOLBAR_BTN_HEIGHT, k == i ? ccs.toolbarBgActive : ccs.toolbarBgUnsel); } else { gdispFillArea(gh->x + NPAD_TOOLBAR_BTN_WIDTH * i, gh->y, NPAD_TOOLBAR_BTN_WIDTH, NPAD_TOOLBAR_BTN_HEIGHT, selColorIndex == i ? ccs.toolbarBgSel : ccs.toolbarBgUnsel); gdispDrawBox(gh->x + NPAD_TOOLBAR_BTN_WIDTH * i, gh->y, NPAD_TOOLBAR_BTN_WIDTH, NPAD_TOOLBAR_BTN_HEIGHT, selColorIndex == i ? ccs.toolbarSeparator: ccs.toolbarBgUnsel); } gdispFillCircle(j, gh->y + (NPAD_TOOLBAR_BTN_HEIGHT / 2), 3, myColors[i] ); } } #undef ccs }
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; }
static void nbtnColorBarSelDraw(GHandle gh, bool_t enabled, bool_t isdown, const char *txt, const GButtonDrawStyle *pstyle, void *param) { #define ccs nCurColorScheme int i, j = 0, k; color_t ca, cb; GEventMouse ptr; (void)txt; (void)pstyle; (void)param; (void)enabled; // Get a copy of the pointer location ginputGetMouseStatus(0, &ptr); // Get which button the pointer is on right now k = (ptr.x - gh->x) / NPAD_TOOLBAR_BTN_WIDTH; gdispDrawBox(gh->x, gh->y, gh->width, gh->height, ccs.toolbarBgUnsel); gdispDrawBox(gh->x + 1, gh->y + 1, gh->width - 2, gh->height - 2, ccs.toolbarBgUnsel); for (i = 0; i < 2; i++) { if (isdown == TRUE) { // Update selection - this is like lazy release. if (k == 0 || k == 1) { tbMode = k; j = 1; } ca = (tbMode == i ? ccs.toolbarBgActive : ccs.toolbarBgUnsel); } else { ca = (tbMode == i ? ccs.toolbarBgSel : ccs.toolbarBgUnsel); } cb = (tbMode == i ? ccs.toolbarSeparator : ccs.toolbarBgUnsel); gdispFillArea(gh->x + NPAD_TOOLBAR_BTN_WIDTH * i, gh->y, NPAD_TOOLBAR_BTN_WIDTH, NPAD_TOOLBAR_BTN_HEIGHT, ca); gdispImageSetBgColor(&toolbarImageFilmstrip, ca); gdispDrawBox(gh->x + NPAD_TOOLBAR_BTN_WIDTH * i, gh->y, NPAD_TOOLBAR_BTN_WIDTH, NPAD_TOOLBAR_BTN_HEIGHT, cb); /* Draw both the icons */ gwinImageDraw(gh, &toolbarImageFilmstrip, 2 + NPAD_TOOLBAR_BTN_WIDTH * i, 2, NPAD_ICON_WIDTH, NPAD_ICON_HEIGHT, NPAD_ICON_START(3 + i), 0); } if (j) gwinButtonDraw(H(btnColorBar)); #undef ccs }