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); }
void printNextBrickWindow() { char* str; int i,j; font16 = gdispOpenFont("DejaVuSans16"); gdispDrawString(360, 100, "Next", font16, tetrisShapeColors[8]); gdispCloseFont(font16); //draw block //For every piece in the next block needs to be changed to nextPiece for (i = 0; i < nextPiece->size; i++) { for (j = 0; j < nextPiece->size; j++) { //If this isn't a blank char then print it if (nextPiece->graphic[i][j] != ' ') { // mvprintw(currentPiece->y + i, currentPiece->x + j, "%c", currentPiece->graphic[i][j]); //padding gdispFillArea(360+(j*BLOCK_SIZE),130+(i*(BLOCK_SIZE)),BLOCK_SIZE-2, BLOCK_SIZE-2, tetrisShapeColors[0]); //shape gdispFillArea(361+(j*BLOCK_SIZE),131+(i*(BLOCK_SIZE)),BLOCK_SIZE-2, BLOCK_SIZE-2, tetrisShapeColors[nextPiece->blockID]); } } } }
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 gwinPutChar(GHandle gh, char c) { #define gcw ((GConsoleObject *)gh) uint8_t width, fy, fp; if (gh->vmt != &consoleVMT || !gh->font) return; fy = gdispGetFontMetric(gh->font, fontHeight); fp = gdispGetFontMetric(gh->font, fontCharPadding); #if GDISP_NEED_CLIP gdispSetClip(gh->x, gh->y, gh->width, gh->height); #endif if (c == '\n') { gcw->cx = 0; gcw->cy += fy; // We use lazy scrolling here and only scroll when the next char arrives } else if (c == '\r') { // gcw->cx = 0; } else { width = gdispGetCharWidth(c, gh->font) + fp; if (gcw->cx + width >= gh->width) { gcw->cx = 0; gcw->cy += fy; } if (gcw->cy + fy > gh->height) { #if GDISP_NEED_SCROLL /* scroll the console */ gdispVerticalScroll(gh->x, gh->y, gh->width, gh->height, fy, gh->bgcolor); /* reset the cursor to the start of the last line */ gcw->cx = 0; gcw->cy = (((coord_t)(gh->height/fy))-1)*fy; #else /* clear the console */ gdispFillArea(gh->x, gh->y, gh->width, gh->height, gh->bgcolor); /* reset the cursor to the top of the window */ gcw->cx = 0; gcw->cy = 0; #endif } #if GWIN_CONSOLE_USE_CLEAR_LINES /* clear to the end of the line */ if (gcw->cx == 0) gdispFillArea(gh->x, gh->y + gcw->cy, gh->width, fy, gh->bgcolor); #endif #if GWIN_CONSOLE_USE_FILLED_CHARS gdispFillChar(gh->x + gcw->cx, gh->y + gcw->cy, c, gh->font, gh->color, gh->bgcolor); #else gdispDrawChar(gh->x + gcw->cx, gh->y + gcw->cy, c, gh->font, gh->color); #endif /* update cursor */ gcw->cx += width; } #undef gcw }
msg_t lcdConsolePut(GConsole *console, char c) { uint8_t width; if(c == '\n') { /* clear the text at the end of the line */ if(console->cx < console->sx) gdispFillArea(console->x0 + console->cx, console->y0 + console->cy, console->sx - console->cx, console->fy, console->bkcolor); console->cx = 0; console->cy += console->fy; } else if(c == '\r') { /* TODO: work backwards through the buffer to the start of the current line */ //console->cx = 0; } else { width = gdispGetCharWidth(c, console->font) + console->fp; if((console->cx + width) >= console->sx) { /* clear the text at the end of the line */ if (console->cy <= console->sy) gdispFillArea(console->x0 + console->cx, console->y0 + console->cy, console->sx - (console->cx + width), console->fy, console->bkcolor); console->cx = 0; console->cy += console->fy; } if((console->cy > console->sy)) { #if GDISP_NEED_SCROLL /* scroll the console */ gdispVerticalScroll(console->x0, console->y0, console->sx, console->sy + console->fy, console->fy, console->bkcolor); /* reset the cursor to the start of the line */ console->cx = 0; console->cy = console->sy; #else /* clear the console */ gdispFillArea(console->x0, console->y0, console->sx, console->sy + console->fy, console->bkcolor); /* reset the cursor to the top of the console */ console->cx = 0; console->cy = 0; #endif } gdispDrawChar(console->x0 + console->cx, console->y0 + console->cy, c, console->font, console->color); /* update cursor */ console->cx += width; } return RDY_OK; }
void gdispFillString(coord_t x, coord_t y, const char *str, font_t font, color_t color, color_t bgcolor) { /* No mutex required as we only call high level functions which have their own mutex */ coord_t w, h, p; char c; int first; if (!str) return; first = 1; h = font->height * font->yscale; p = font->charPadding * font->xscale; while(*str) { /* Get the next printable character */ c = *str++; w = _getCharWidth(font, c) * font->xscale; if (!w) continue; /* Handle inter-character padding */ if (p) { if (!first) { gdispFillArea(x, y, p, h, bgcolor); x += p; } else first = 0; } /* Print the character */ gdispFillChar(x, y, c, font, color, bgcolor); x += w; } }
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 gdispFillRoundedBox(coord_t x, coord_t y, coord_t cx, coord_t cy, coord_t radius, color_t color) { coord_t radius2; radius2 = radius*2; if (radius2 > cx || radius2 > cy) { gdispFillArea(x, y, cx, cy, color); return; } gdispFillArc(x+radius, y+radius, radius, 90, 180, color); gdispFillArea(x+radius+1, y, cx-radius2, radius, color); gdispFillArc(x+cx-1-radius, y+radius, radius, 0, 90, color); gdispFillArc(x+cx-1-radius, y+cy-1-radius, radius, 270, 360, color); gdispFillArea(x+radius+1, y+cy-radius, cx-radius2, radius, color); gdispFillArc(x+radius, y+cy-1-radius, radius, 180, 270, color); gdispFillArea(x, y+radius, cx, cy-radius2, 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 gwinFillArea(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 gdispFillArea(gh->x+x, gh->y+y, cx, cy, gh->color); }
//Clear the next piece area void clearNextPieceArea(){ int i, j; for (i = 0; i < nextPiece->size; i++) { for (j = 0; j < nextPiece->size; j++) { gdispFillArea(((360)+(j*BLOCK_SIZE)),(((130) )+(i*BLOCK_SIZE)),BLOCK_SIZE, BLOCK_SIZE, tetrisShapeColors[0]); } } }
//Erase the block void eraseBlock(){ int i, j; //For every piece in the currently moving block for (i = 0; i < currentPiece->size; i++) { for (j = 0; j < currentPiece->size; j++) { //If this isn't a blank char then print it gdispFillArea(((bucket.x + (lastDrawnX * BLOCK_SIZE))+(j*BLOCK_SIZE)),(((bucket.y) + (lastDrawnY* BLOCK_SIZE))+(i*BLOCK_SIZE)),BLOCK_SIZE, BLOCK_SIZE, tetrisShapeColors[0]); } } }
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 }
void gwinClear(GHandle gh) { if (!((gh->flags & GWIN_FLG_VISIBLE))) return; #if GDISP_NEED_CLIP gdispSetClip(gh->x, gh->y, gh->width, gh->height); #endif gdispFillArea(gh->x, gh->y, gh->width, gh->height, gh->bgcolor); if (gh->vmt->AfterClear) gh->vmt->AfterClear(gh); }
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 printScoreWindow() { char* str; font16 = gdispOpenFont("DejaVuSans16"); gdispDrawString(360, 20, "Score", font16, tetrisShapeColors[8]); // gdispDrawLine(365, 40, 380, 20, Purple); gdispFillArea(365, 35, 35, 1, Purple); //draw current score sprintf(str,"%d",Score); gdispDrawString(378, 42, str, font16, Purple); gdispCloseFont(font16); }
void benchmark(void) { uint32_t i, pixels, ms, pps; char pps_str[25]; coord_t height, width, rx, ry, rcx, rcy; color_t random_color; font_t font; gdispSetOrientation(GDISP_ROTATE_90); width = gdispGetWidth(); height = gdispGetHeight(); font = gdispOpenFont("UI2 Double"); gdispDrawStringBox(0, 0, width, 30, "ChibiOS/GFX - Benchmark", font, White, justifyCenter); font = gdispOpenFont("UI2"); gdispDrawStringBox(0, height/2, width, 30, "5000 random rectangles", font, White, justifyCenter); gfxSleepMilliseconds(3000); /* seed for the rand() */ srand(DWT_CYCCNT); pixels = 0; CPU_RESET_CYCLECOUNTER; for (i = 0; i < 5000; i++) { random_color = (rand() % 65535); rx = (rand() % (width-10)); ry = (rand() % (height-10)); rcx = (rand() % ((width-rx)-10))+10; rcy = (rand() % ((height-ry)-10))+10; gdispFillArea(rx, ry, rcx, rcy, random_color); pixels += (rcx+1)*(rcy+1); } ms = DWT_CYCCNT / 168000; pps = (float)pixels/((float)ms/1000.0f); memset (pps_str, 0, sizeof(pps_str)); uitoa(pps, pps_str, sizeof(pps_str)); strcat(pps_str, " Pixels/s"); font = gdispOpenFont("UI2 Double"); gdispClear(Black); gdispDrawStringBox(0, 0, width, 30, "ChibiOS/GFX - Benchmark", font, White, justifyCenter); gdispDrawStringBox(0, height/2, width, 30, pps_str, font, White, justifyCenter); //gdispDrawString(20, height/2, pps_str, font, White); }
msg_t lcdConsoleInit(GConsole *console, coord_t x0, coord_t y0, coord_t width, coord_t height, font_t font, pixel_t bkcolor, pixel_t color) { console->vmt = &vmt; /* read font, get height & padding */ console->fy = gdispGetFontMetric(font, fontHeight); console->fp = gdispGetFontMetric(font, fontCharPadding); /* calculate the size of the console as an integer multiple of characters height*/ console->sx = width; console->sy = (((int16_t)(height/console->fy))-1)*console->fy; console->cx = 0; console->cy = 0; console->x0 = x0; console->y0 = y0; console->bkcolor = bkcolor; console->color = color; console->font = font; gdispFillArea(x0, y0, x0 + width, y0 + height, console->bkcolor); return RDY_OK; }
int main(void) { GEventMouse ev; #if !JG10_SHOW_SPLASH font_t font; #endif gfxInit(); ginputGetMouse(0); jg10Init(); #if JG10_SHOW_SPLASH jg10ShowSplash(); #else font = gdispOpenFont("DejaVuSans16_aa"); gdispDrawString((gdispGetWidth()/2)-(gdispGetStringWidth("Touch to start!", font)/2), gdispGetHeight()/2, "Touch to start!", font, White); gdispCloseFont(font); #endif while (TRUE) { ginputGetMouseStatus(0, &ev); if (ev.buttons & GINPUT_MOUSE_BTN_LEFT) { while (ev.buttons & GINPUT_MOUSE_BTN_LEFT) { // Wait until release ginputGetMouseStatus(0, &ev); } #if !JG10_SHOW_SPLASH font = gdispOpenFont("DejaVuSans16"); gdispFillArea((gdispGetWidth()/2)-(gdispGetStringWidth("Touch to start!", font)/2), gdispGetHeight()/2, gdispGetWidth()/2, 17, Black); gdispCloseFont(font); #endif jg10Start(); } } }
/** * Our main function. * There are two prototypes - one for systems with a command line and one for embedded systems without one. */ int main(proto_args) { uint16_t cmd[5]; unsigned cnt; // Initialize and clear the display gfxInit(); font = gdispOpenFont("UI2"); // Open the connection gdispDrawStringBox(0, 0, gdispGetWidth(), gdispGetHeight(), "Connecting to host...", font, White, justifyCenter); StartSockets(); netfd = doConnect(cmd_args); if (netfd == (SOCKET_TYPE)-1) gfxHalt("Could not connect to the specified server"); gdispClear(Black); // Get the initial packet from the host if (!getpkt(cmd, 2)) goto alldone; if (cmd[0] != GNETCODE_INIT || cmd[1] != GNETCODE_VERSION) gfxHalt("Oops - The protocol doesn't look like one we understand"); // Get the rest of the initial arguments if (!getpkt(cmd, 4)) goto alldone; // cmd[] = width, height, pixelformat, hasmouse // We will ignore size mismatches but the pixel format must match if (cmd[2] != GDISP_PIXELFORMAT) gfxHalt("Oops - The remote display is using a different pixel format to us.\nTry defining GDISP_PIXELFORMAT in your gfxconf.h file."); #if GFX_USE_GINPUT && GINPUT_NEED_MOUSE // Start the mouse thread if needed if (cmd[3]) gfxThreadClose(gfxThreadCreate(waNetThread, sizeof(waNetThread), HIGH_PRIORITY, NetThread, 0)); #endif // Process incoming instructions while(getpkt(cmd, 1)) { switch(cmd[0]) { case GNETCODE_FLUSH: gdispFlush(); break; case GNETCODE_PIXEL: if (!getpkt(cmd, 3)) goto alldone; // cmd[] = x, y, color gdispDrawPixel(cmd[0], cmd[1], cmd[2]); break; case GNETCODE_FILL: if (!getpkt(cmd, 5)) goto alldone; // cmd[] = x, y, cx, cy, color gdispFillArea(cmd[0], cmd[1], cmd[2], cmd[3], cmd[4]); break; case GNETCODE_BLIT: if (!getpkt(cmd, 4)) goto alldone; // cmd[] = x, y, cx, cy - Followed by cx * cy pixels gdispStreamStart(cmd[0],cmd[1],cmd[2],cmd[3]); for(cnt = (unsigned)cmd[2] * cmd[3]; cnt; cnt--) { if (!getpkt(cmd, 1)) goto alldone; gdispStreamColor(cmd[0]); } gdispStreamStop(); break; #if GDISP_NEED_PIXELREAD case GNETCODE_READ: if (!getpkt(cmd, 2)) goto alldone; // cmd[] = x, y - Response is GNETCODE_READ,color cmd[1] = gdispGetPixelColor(cmd[0], cmd[1]); cmd[0] = GNETCODE_READ; if (!sendpkt(cmd, 2)) goto alldone; break; #endif #if GDISP_NEED_SCROLL case GNETCODE_SCROLL: if (!getpkt(cmd, 5)) goto alldone; // cmd[] = x, y, cx, cy, lines gdispVerticalScroll(cmd[0], cmd[1], cmd[2], cmd[3], cmd[4], Black); break; #endif case GNETCODE_CONTROL: if (!getpkt(cmd, 2)) goto alldone; // cmd[] = what,data - Response is GNETCODE_CONTROL, 0x0000 (fail) or GNETCODE_CONTROL, 0x0001 (success) gdispControl(cmd[0], (void *)(unsigned)cmd[1]); switch(cmd[0]) { case GDISP_CONTROL_ORIENTATION: cmd[1] = (uint16_t)gdispGetOrientation() == cmd[1] ? 1 : 0; break; case GDISP_CONTROL_POWER: cmd[1] = (uint16_t)gdispGetPowerMode() == cmd[1] ? 1 : 0; break; case GDISP_CONTROL_BACKLIGHT: cmd[1] = (uint16_t)gdispGetBacklight() == cmd[1] ? 1 : 0; break; default: cmd[1] = 0; break; } cmd[0] = GNETCODE_CONTROL; if (!sendpkt(cmd, 2)) goto alldone; break; default: gfxHalt("Oops - The host has sent invalid commands"); break; } } alldone: closesocket(netfd); gfxHalt("Connection closed"); return 0; }
static inline void _tsClearCross(const MousePoint *pp) { gdispFillArea(pp->x - 15, pp->y - 15, 42, 42, Blue); }
int main(void) { GEvent * pe; // Initialize the display gfxInit(); // Set the widget defaults gwinSetDefaultFont(gdispOpenFont("*")); gwinSetDefaultStyle(&WhiteWidgetStyle, FALSE); gdispClear(White); // Connect the mouse #if GINPUT_NEED_MOUSE gwinAttachMouse(0); #endif // Create the gwin windows/widgets createWidgets(); // Assign toggles and dials to specific buttons & sliders etc. #if GINPUT_NEED_TOGGLE gwinAttachToggle(ghButton1, 0, 0); gwinAttachToggle(ghButton2, 0, 1); #endif #if GINPUT_NEED_DIAL gwinAttachDial(ghSlider1, 0, 0); gwinAttachDial(ghSlider3, 0, 1); #endif // Make the console visible gwinSetVisible(ghConsole, TRUE); gwinClear(ghConsole); // We want to listen for widget events geventListenerInit(&gl); gwinAttachListener(&gl); // Press the Tab we want visible gwinRadioPress(ghTabButtons); while(1) { // Get an Event pe = geventEventWait(&gl, TIME_INFINITE); switch(pe->type) { case GEVENT_GWIN_BUTTON: gwinPrintf(ghConsole, "Button %s\n", gwinGetText(((GEventGWinButton *)pe)->button)); break; case GEVENT_GWIN_SLIDER: gwinPrintf(ghConsole, "Slider %s=%d\n", gwinGetText(((GEventGWinSlider *)pe)->slider), ((GEventGWinSlider *)pe)->position); break; case GEVENT_GWIN_CHECKBOX: gwinPrintf(ghConsole, "Checkbox %s=%s\n", gwinGetText(((GEventGWinCheckbox *)pe)->checkbox), ((GEventGWinCheckbox *)pe)->isChecked ? "Checked" : "UnChecked"); // If it is the Disable All checkbox then do that. if (((GEventGWinCheckbox *)pe)->checkbox == ghCheckDisableAll) { gwinPrintf(ghConsole, "%s All\n", ((GEventGWinCheckbox *)pe)->isChecked ? "Disable" : "Enable"); setEnabled(!((GEventGWinCheckbox *)pe)->isChecked); } break; case GEVENT_GWIN_LIST: gwinPrintf(ghConsole, "List %s Item %d %s\n", gwinGetText(((GEventGWinList *)pe)->list), ((GEventGWinList *)pe)->item, gwinListItemIsSelected(((GEventGWinList *)pe)->list, ((GEventGWinList *)pe)->item) ? "Selected" : "Unselected"); break; case GEVENT_GWIN_RADIO: gwinPrintf(ghConsole, "Radio Group %u=%s\n", ((GEventGWinRadio *)pe)->group, gwinGetText(((GEventGWinRadio *)pe)->radio)); switch(((GEventGWinRadio *)pe)->group) { case GROUP_TABS: // Set control visibility depending on the tab selected setTab(((GEventGWinRadio *)pe)->radio); // Do some special animation for Label1 to demonstrate auto width sizing if (((GEventGWinRadio *)pe)->radio == ghTabLabels) { gwinPrintf(ghConsole, "Change Label Text\n"); gfxSleepMilliseconds(1000); gwinSetText(ghLabel1, "Very Big Label", FALSE); gfxSleepMilliseconds(1000); gwinSetText(ghLabel1, "Label", FALSE); } break; case GROUP_COLORS: { const GWidgetStyle *pstyle; gwinPrintf(ghConsole, "Change Color Scheme\n"); if (((GEventGWinRadio *)pe)->radio == ghRadioYellow) pstyle = &YellowWidgetStyle; else if (((GEventGWinRadio *)pe)->radio == ghRadioBlack) pstyle = &BlackWidgetStyle; else pstyle = &WhiteWidgetStyle; // Clear the screen to the new color - we avoid the console area as it can't redraw itself #if GDISP_NEED_CLIP gdispUnsetClip(); #endif gdispFillArea(0, 0, ScrWidth, ScrHeight/2, pstyle->background); gdispFillArea(0, ScrHeight/2, ScrWidth/2, ScrHeight/2, pstyle->background); // Update the style on all controls gwinSetDefaultStyle(pstyle, TRUE); } break; } break; default: gwinPrintf(ghConsole, "Unknown %d\n", pe->type); break; } } return 0; }
static void _redraw(GHandle gh) { coord_t x, y, w, h, dx, dy; color_t bg; #if GWIN_NEED_IMAGE_ANIMATION delaytime_t delay; #endif // The default display area dx = 0; dy = 0; x = gh->x; y = gh->y; w = gh->width; h = gh->height; bg = gwinGetDefaultBgColor(); // If the image isn't open just clear the area if (!gdispImageIsOpen(&widget(gh)->image)) { gdispFillArea(x, y, w, h, bg); return; } // Center horizontally if the area is larger than the image if (widget(gh)->image.width < w) { w = widget(gh)->image.width; dx = (gh->width-w)/2; x += dx; if (dx) gdispFillArea(gh->x, y, dx, h, bg); gdispFillArea(x+w, y, gh->width-dx-w, h, bg); dx = 0; } // Center image horizontally if the area is smaller than the image else if (widget(gh)->image.width > w) { dx = (widget(gh)->image.width - w)/2; } // Center vertically if the area is larger than the image if (widget(gh)->image.height < h) { h = widget(gh)->image.height; dy = (gh->height-h)/2; y += dy; if (dy) gdispFillArea(x, gh->y, w, dy, bg); gdispFillArea(x, y+h, w, gh->height-dy-h, bg); dy = 0; } // Center image vertically if the area is smaller than the image else if (widget(gh)->image.height > h) { dy = (widget(gh)->image.height - h)/2; } // Reset the background color in case it has changed gdispImageSetBgColor(&widget(gh)->image, bg); // Display the image gdispImageDraw(&widget(gh)->image, x, y, w, h, dx, dy); #if GWIN_NEED_IMAGE_ANIMATION // read the delay for the next frame delay = gdispImageNext(&widget((GHandle)gh)->image); // Wait for that delay if required switch(delay) { case TIME_INFINITE: // Everything is done break; case TIME_IMMEDIATE: // We can't allow a continuous loop here as it would lock the system up so we delay for the minimum period delay = 1; // Fall through default: // Start the timer to draw the next frame of the animation gtimerStart(&widget((GHandle)gh)->timer, _timer, (void*)gh, FALSE, delay); break; } #endif }
bool_t ginputCalibrateMouse(uint16_t instance) { #if !GINPUT_MOUSE_NEED_CALIBRATION (void) instance; return FALSE; #else const coord_t height = gdispGetHeight(); const coord_t width = gdispGetWidth(); const MousePoint cross[] = {{(width / 4), (height / 4)}, {(width - (width / 4)) , (height / 4)}, {(width - (width / 4)) , (height - (height / 4))}, {(width / 2), (height / 2)}}; /* Check point */ MousePoint points[GINPUT_MOUSE_CALIBRATION_POINTS]; const MousePoint *pc; MousePoint *pt; int32_t px, py; unsigned i, j; font_t font1, font2; #if GINPUT_MOUSE_MAX_CALIBRATION_ERROR >= 0 unsigned err; #endif if (instance || (MouseConfig.flags & FLG_IN_CAL)) return FALSE; font1 = gdispOpenFont(GINPUT_MOUSE_CALIBRATION_FONT); font2 = gdispOpenFont(GINPUT_MOUSE_CALIBRATION_FONT2); MouseConfig.flags |= FLG_IN_CAL; gtimerStop(&MouseTimer); MouseConfig.flags &= ~(FLG_CAL_OK|FLG_CAL_SAVED); #if GDISP_NEED_CONTROL gdispSetOrientation(GDISP_ROTATE_0); #endif #if GDISP_NEED_CLIP gdispSetClip(0, 0, width, height); #endif #if GINPUT_MOUSE_MAX_CALIBRATION_ERROR >= 0 while(1) { #endif gdispClear(Blue); gdispFillStringBox(0, 5, width, 30, GINPUT_MOUSE_CALIBRATION_TEXT, font1, White, Blue, justifyCenter); for(i = 0, pt = points, pc = cross; i < GINPUT_MOUSE_CALIBRATION_POINTS; i++, pt++, pc++) { _tsDrawCross(pc); do { /* Wait for the mouse to be pressed */ while(get_raw_reading(&MouseConfig.t), !(MouseConfig.t.buttons & GINPUT_MOUSE_BTN_LEFT)) chThdSleepMilliseconds(20); /* Average all the samples while the mouse is down */ for(px = py = 0, j = 0; chThdSleepMilliseconds(20), /* Settling time between readings */ get_raw_reading(&MouseConfig.t), (MouseConfig.t.buttons & GINPUT_MOUSE_BTN_LEFT); j++) { px += MouseConfig.t.x; py += MouseConfig.t.y; } } while(!j); pt->x = px / j; pt->y = py / j; _tsClearCross(pc); if (i >= 1 && pt->x == (pt-1)->x && pt->y == (pt-1)->y) { gdispFillStringBox(0, 35, width, 40, GINPUT_MOUSE_CALIBRATION_SAME_TEXT, font2, Red, Yellow, justifyCenter); chThdSleepMilliseconds(5000); gdispFillArea(0, 35, width, 40, Blue); } } /* Apply 3 point calibration algorithm */ _tsDo3PointCalibration(cross, points, &MouseConfig.caldata); /* Verification of correctness of calibration (optional) : * See if the 4th point (Middle of the screen) coincides with the calibrated * result. If point is within +/- Squareroot(ERROR) pixel margin, then successful calibration * Else, start from the beginning. */ #if GINPUT_MOUSE_MAX_CALIBRATION_ERROR >= 0 /* Transform the co-ordinates */ MouseConfig.t.x = points[3].x; MouseConfig.t.y = points[3].y; _tsTransform(&MouseConfig.t, &MouseConfig.caldata); /* Calculate the delta */ err = (MouseConfig.t.x - cross[3].x) * (MouseConfig.t.x - cross[3].x) + (MouseConfig.t.y - cross[3].y) * (MouseConfig.t.y - cross[3].y); if (err <= GINPUT_MOUSE_MAX_CALIBRATION_ERROR * GINPUT_MOUSE_MAX_CALIBRATION_ERROR) break; gdispFillStringBox(0, 35, width, 40, GINPUT_MOUSE_CALIBRATION_ERROR_TEXT, font2, Red, Yellow, justifyCenter); chThdSleepMilliseconds(5000); } #endif // Restart everything gdispCloseFont(font1); gdispCloseFont(font2); MouseConfig.flags |= FLG_CAL_OK; MouseConfig.last_buttons = 0; get_calibrated_reading(&MouseConfig.t); MouseConfig.flags &= ~FLG_IN_CAL; if ((MouseConfig.flags & FLG_INIT_DONE)) gtimerStart(&MouseTimer, MousePoll, 0, TRUE, GINPUT_MOUSE_POLL_PERIOD); // Save the calibration data (if possible) if (MouseConfig.fnsavecal) { MouseConfig.fnsavecal(instance, (const uint8_t *)&MouseConfig.caldata, sizeof(MouseConfig.caldata)); MouseConfig.flags |= FLG_CAL_SAVED; } return TRUE; #endif }
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; }
// 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 }
void printTetrisBucket() { int i, j; //Placement of bucket on screen bucket.x = 120; bucket.y = 3; //For every cell in the tetris bucket // gdispFillArea(100,100, 50, 50, Red); for (i = 0; i < bucket.height; i++) { for (j = 0; j < bucket.width; j++) { // mvprintw(bucket.y + i, bucket.x + j, "%c", bucket.bucket[i][j].value); if((bucket.bucket[i][j] != ' ')){ //draws the bucket if(bucket.bucket[i][j] == '#'){ if( bucket.height-1 ==i){ gdispFillArea((bucket.x + (j*BLOCK_SIZE)), (bucket.y + (i*BLOCK_SIZE)), 15, 5, tetrisShapeColors[8]); } else if(j ==0){ gdispFillArea((bucket.x+10 + (j*BLOCK_SIZE)), (bucket.y + (i*BLOCK_SIZE)), 5, 15, tetrisShapeColors[8]); } else{ gdispFillArea((bucket.x + (j*BLOCK_SIZE)), (bucket.y + (i*BLOCK_SIZE)), 5, 15, tetrisShapeColors[8]); } } ///draws shapes that collided with the bottom else { //padding gdispFillArea((bucket.x + (j*BLOCK_SIZE)), (bucket.y + (i*BLOCK_SIZE)), BLOCK_SIZE, BLOCK_SIZE, tetrisShapeColors[0]); //shape gdispFillArea((bucket.x + (j*BLOCK_SIZE)+1), (bucket.y + (i*BLOCK_SIZE)+1), BLOCK_SIZE-2, BLOCK_SIZE-2, tetrisShapeColors[bucket.bucket[i][j]]); } } } } //For every piece in the currently moving block for (i = 0; i < currentPiece->size; i++) { for (j = 0; j < currentPiece->size; j++) { //If this isn't a blank char then print it if (currentPiece->graphic[i][j] != ' ') { // mvprintw(currentPiece->y + i, currentPiece->x + j, "%c", currentPiece->graphic[i][j]); //padding gdispFillArea(((bucket.x + (currentPiece->x * BLOCK_SIZE))+(j*BLOCK_SIZE)),(((bucket.y) + (currentPiece->y* BLOCK_SIZE))+(i*BLOCK_SIZE)),BLOCK_SIZE, BLOCK_SIZE, tetrisShapeColors[0]); //shape gdispFillArea(((bucket.x + (currentPiece->x * BLOCK_SIZE))+(j*BLOCK_SIZE)+1),(((bucket.y) + (currentPiece->y* BLOCK_SIZE))+(i*BLOCK_SIZE)+1),BLOCK_SIZE-2, BLOCK_SIZE-2, tetrisShapeColors[currentPiece->blockID]); } } } //Set last drawn block coordinates (for purposes of erasing display) lastDrawnX = currentPiece->x; lastDrawnY = currentPiece->y; }
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 }
void gdispFillStringBox(coord_t x, coord_t y, coord_t cx, coord_t cy, const char* str, font_t font, color_t color, color_t bgcolor, justify_t justify) { /* No mutex required as we only call high level functions which have their own mutex */ coord_t w, h, p, ypos, xpos; char c; int first; const char *rstr; if (!str) str = ""; h = font->height * font->yscale; p = font->charPadding * font->xscale; /* Oops - font too large for the area */ if (h > cy) return; /* See if we need to fill above the font */ ypos = (cy - h + 1)/2; if (ypos > 0) { gdispFillArea(x, y, cx, ypos, bgcolor); y += ypos; cy -= ypos; } /* See if we need to fill below the font */ ypos = cy - h; if (ypos > 0) { gdispFillArea(x, y+cy-ypos, cx, ypos, bgcolor); cy -= ypos; } /* get the start of the printable string and the xpos */ switch(justify) { case justifyCenter: /* Get the length of the entire string */ w = gdispGetStringWidth(str, font); if (w <= cx) xpos = x + (cx - w)/2; else { /* Calculate how much of the string we need to get rid of */ ypos = (w - cx)/2; xpos = 0; first = 1; while(*str) { /* Get the next printable character */ c = *str++; w = _getCharWidth(font, c) * font->xscale; if (!w) continue; /* Handle inter-character padding */ if (p) { if (!first) { xpos += p; if (xpos > ypos) break; } else first = 0; } /* Print the character */ xpos += w; if (xpos > ypos) break; } xpos = ypos - xpos + x; } break; case justifyRight: /* Find the end of the string */ for(rstr = str; *str; str++); xpos = x+cx - 2; first = 1; for(str--; str >= rstr; str--) { /* Get the next printable character */ c = *str; w = _getCharWidth(font, c) * font->xscale; if (!w) continue; /* Handle inter-character padding */ if (p) { if (!first) { if (xpos - p < x) break; xpos -= p; } else first = 0; } /* Print the character */ if (xpos - w < x) break; xpos -= w; } str++; break; case justifyLeft: /* Fall through */ default: xpos = x+1; break; } /* Fill any space to the left */ if (x < xpos) gdispFillArea(x, y, xpos-x, cy, bgcolor); /* Print characters until we run out of room */ first = 1; while(*str) { /* Get the next printable character */ c = *str++; w = _getCharWidth(font, c) * font->xscale; if (!w) continue; /* Handle inter-character padding */ if (p) { if (!first) { if (xpos + p > x+cx) break; gdispFillArea(xpos, y, p, cy, bgcolor); xpos += p; } else first = 0; } /* Print the character */ if (xpos + w > x+cx) break; gdispFillChar(xpos, y, c, font, color, bgcolor); xpos += w; } /* Fill any space to the right */ if (xpos < x+cx) gdispFillArea(xpos, y, x+cx-xpos, cy, bgcolor); }
void menuScreen(){ //color_t colorrange[9] = {White, Yellow, Red, Blue, Magenta, SkyBlue, Orange,Lime,Black}; // 0 1 2 3 4 5 6 7 8 // Main menu Background gdispFillArea(433, 247, 20, 20, tetrisShapeColors[2]); gdispFillArea(112, 247, 20, 20, tetrisShapeColors[7]); gdispFillArea(455, 247, 20, 20, tetrisShapeColors[2]); gdispFillArea(0, 204, 20, 20, tetrisShapeColors[3]); gdispFillArea(23, 225, 20, 20, tetrisShapeColors[1]); gdispFillArea(455, 224, 20, 20, tetrisShapeColors[2]); gdispFillArea(91, 247, 20, 20, tetrisShapeColors[7]); gdispFillArea(83, 80, 20, 20, tetrisShapeColors[4]); gdispFillArea(432, 203, 20, 20, tetrisShapeColors[6]); gdispFillArea(178, 247, 20, 20, tetrisShapeColors[5]); gdispFillArea(134, 247, 20, 20, tetrisShapeColors[7]); gdispFillArea(455, 201, 20, 20, tetrisShapeColors[2]); gdispFillArea(22, 247, 20, 20, tetrisShapeColors[3]); gdispFillArea(46, 248, 20, 20, tetrisShapeColors[1]); gdispFillArea(46, 225, 20, 20, tetrisShapeColors[1]); gdispFillArea(82, 102, 21, 20, tetrisShapeColors[4]); gdispFillArea(70, 247, 20, 20, tetrisShapeColors[7]); gdispFillArea(60, 102, 20, 20, tetrisShapeColors[4]); gdispFillArea(410, 225, 20, 20, tetrisShapeColors[6]); gdispFillArea(156, 247, 20, 20, tetrisShapeColors[5]); gdispFillArea(134, 225, 20, 20, tetrisShapeColors[5]); gdispFillArea(410, 247, 20, 20, tetrisShapeColors[6]); gdispFillArea(0, 226, 20, 20, tetrisShapeColors[3]); gdispFillArea(47, 227, 20, 20, tetrisShapeColors[1]); gdispFillArea(60, 80, 20, 20, tetrisShapeColors[4]); gdispFillArea(69, 225, 20, 20, tetrisShapeColors[1]); gdispFillArea(0, 247, 20, 20, tetrisShapeColors[3]); gdispFillArea(432, 225, 20, 20, tetrisShapeColors[6]); gdispFillArea(157, 225, 20, 20, tetrisShapeColors[5]); //Button gdispFillArea(200,60,80,30,Grey); gdispFillArea(200+3,60+3,80-6,30-6,Silver); //text font16 = gdispOpenFont("DejaVuSans16"); gdispDrawString(225, 66, "Play", font16, tetrisShapeColors[8]); gdispCloseFont(font16); //Button gdispFillArea(200,110,96,30,Grey); gdispFillArea(200+3,110+3,96-6,30-6,Silver); //text font16 = gdispOpenFont("DejaVuSans16"); gdispDrawString(205, 116, "Dark Mode", font16, tetrisShapeColors[8]); gdispCloseFont(font16); //Button gdispFillArea(200,160,126,30,Grey); gdispFillArea(200+3,160+3,126-6,30-6,Silver); //text font16 = gdispOpenFont("DejaVuSans16"); gdispDrawString(205, 166, "Random Mode", font16, tetrisShapeColors[8]); gdispCloseFont(font16); }