void drawMainMenu(uint8_t menuPosition){ char *mainMenuStrings[MAIN_MENU_ITEMS] = {"Last swim", "New Swim"}; uint8_t i, h; u8g_uint_t w, d; u8g_SetFont(&u8g, u8g_font_6x13); u8g_SetFontRefHeightText(&u8g); u8g_SetFontPosTop(&u8g); h = u8g_GetFontAscent(&u8g) - u8g_GetFontDescent(&u8g); w = u8g_GetWidth(&u8g); char vccChar[10]; my_itoa(vcc, vccChar, 10); // Doing the actual drawing u8g_FirstPage(&u8g); do{ for (i = 0; i < MAIN_MENU_ITEMS; i++){ d = (w - u8g_GetStrWidth(&u8g, mainMenuStrings[i])) / 2; u8g_SetDefaultForegroundColor(&u8g); if (i == menuPosition){ u8g_DrawBox(&u8g, 0, i*h+1, w, h); u8g_SetDefaultBackgroundColor(&u8g); } u8g_DrawStr(&u8g, d, i*h, mainMenuStrings[i]); } u8g_SetDefaultForegroundColor(&u8g); u8g_DrawFrame(&u8g, 0, 0, 128, 64); u8g_DrawStr(&u8g, 5, 50, vccChar); } while (u8g_NextPage(&u8g)); }
/* drawing callback for menu */ int gui_menu_draw_cb(u8g_t *u8g, struct GuiWindow *win, struct GuiPoint abspos) { struct GuiMenu *menu = (struct GuiMenu *)win; int y0 = menu->selected*10; u8g_SetDefaultBackgroundColor(u8g); u8g_DrawBox(u8g, abspos.x, y0, abspos.x+10, abspos.y+70); // u8g_SetDefaultMidColor(u8g); u8g_SetDefaultForegroundColor(u8g); u8g_DrawTriangle(u8g, abspos.x, y0, abspos.x+10, y0+5, abspos.x, y0+10); u8g_SetDefaultForegroundColor(u8g); for (int i = 0; i < 7; ++i) { y0 = (i+1)*10; const char *s = menutext[i]; if (i == menu->selected) { u8g_SetFont(u8g, u8g_font_helvB08); } else { u8g_SetFont(u8g, u8g_font_helvR08); } u8g_DrawStr(u8g, abspos.x+12, y0, s); } return 0; }
// Lua: u8g.setDefaultBackgroundColor( self ) static int lu8g_setDefaultBackgroundColor( lua_State *L ) { lu8g_userdata_t *lud; if ((lud = get_lud( L )) == NULL) return 0; u8g_SetDefaultBackgroundColor( LU8G ); return 0; }
void menu_draw(menu_t *menu, u8g_t *u8g) { uint8_t i, h; static char ramstr[32]; menu_buttons_t *b; u8g_uint_t w, d; if(!menu) return; // Calculate text size u8g_SetFont(u8g, u8g_font_5x7); u8g_SetFontRefHeightText(u8g); u8g_SetFontPosTop(u8g); h = u8g_GetFontAscent(u8g)-u8g_GetFontDescent(u8g); w = u8g_GetWidth(u8g); for( i = 0;; i++ ) { // draw all menu items // Copy string from program memory to a work string in RAM strncpy_P(ramstr, (PGM_P)pgm_read_word(&(menu->strings[i])), sizeof(ramstr)); ramstr[31] = 0; // Zero length string marks end of string list. if(!ramstr[0]) break; // Get its length in pixels d = (w-u8g_GetStrWidth(u8g, ramstr))/2; // Set foreground color u8g_SetDefaultForegroundColor(u8g); // If item selected if ( i == menu->selected ) { // current selected menu item u8g_DrawBox(u8g, 0, i*h+1, w, h); // draw cursor bar u8g_SetDefaultBackgroundColor(u8g); } // Display the string u8g_DrawStr(u8g, d, i*h, ramstr); } // Remember menu item count menu->item_count = i; // Ensure text and background are set back to normal u8g_SetDefaultForegroundColor(u8g); // If there are soft buttons, draw them here if(menu->buttons){ for(b = menu->buttons; b; b = b->next){ strncpy_P(ramstr, b->label, sizeof(ramstr)); ramstr[31] = 0; u8g_DrawStr(u8g, b->col, b->row, ramstr); } } }
/* callback to draw the clock face */ int gui_draw_clock_face_cb(u8g_t *u8g, struct GuiWindow *win, struct GuiPoint abspos) { struct GuiClockface *f = (struct GuiClockface *)win; int center_x = f->center_x + abspos.x; int center_y = f->center_y + abspos.y; /* clear background to white */ u8g_SetDefaultBackgroundColor(u8g); u8g_DrawBox(u8g, center_x-f->radius, center_y-f->radius, 2*f->radius, 2*f->radius); u8g_SetDefaultForegroundColor(u8g); /* face */ u8g_DrawCircle(u8g, center_x, center_y, f->radius, U8G_DRAW_ALL); u8g_DrawCircle(u8g, center_x, center_y, f->radius+1, U8G_DRAW_ALL); /* hour markers */ for (int h = 0; h < 12; ++h) { u8g_DrawCircle(u8g, sintab60[absrot60(h*5+15)] + center_x, sintab60[h*5] + center_y, 2, U8G_DRAW_ALL); } int hours = (f->hours % 12); int minutes = f->minutes % 60; /* hours hand */ int angle = absrot60(-(short)hours*5 - (short)minutes/12 + 15); int x2 = sintab60[absrot60(angle+15)]/2 + center_x; // cos, x-axis is natural direction int y2 = (-sintab60[angle]/2) + center_y; // sin, y-axis is inverted u8g_DrawLine(u8g, center_x, center_y, x2, y2); u8g_DrawLine(u8g, center_x+1, center_y, x2+1, y2); u8g_DrawLine(u8g, center_x, center_y+1, x2, y2+1); u8g_DrawLine(u8g, center_x-1, center_y, x2-1, y2); u8g_DrawLine(u8g, center_x, center_y-1, x2, y2-1); /* minutes hand */ angle = absrot60(-(short)minutes + 15); x2 = sintab60[absrot60(angle+15)]*30/34 + center_x; // cos, x-axis is natural direction y2 = (-sintab60[angle])*30/34 + center_y; // sin, y-axis is inverted u8g_DrawLine(u8g, center_x, center_y, x2, y2); return 0; }
void draw_menu(void) { uint8_t i, h; u8g_uint_t w, d; u8g_SetFont(&u8g, u8g_font_6x13); u8g_SetFontRefHeightText(&u8g); u8g_SetFontPosTop(&u8g); h = u8g_GetFontAscent(&u8g)-u8g_GetFontDescent(&u8g); w = u8g_GetWidth(&u8g); for( i = 0; i < MENU_ITEMS; i++ ) { d = (w-u8g_GetStrWidth(&u8g, menu_strings[i]))/2; u8g_SetDefaultForegroundColor(&u8g); if ( i == menu_current ) { u8g_DrawBox(&u8g, 0, i*h+1, w, h); u8g_SetDefaultBackgroundColor(&u8g); } u8g_DrawStr(&u8g, d, i*h, menu_strings[i]); } }
/******************************************************************************* * Отрисовка и обрадотка команд секундомера ******************************************************************************/ void stopwatch(mtk_t * mtk) { uint8_t i, x, y; uint32_t count; char sTemp[11]; count = sWatch.dsH[sWatch.nums]; if (mtk->command) { switch (mtk->command) { case COMMAND_NEXT: { if (!sWatch.nums) { state.taskList |= TASK_STOPWATCH;//Для отображения на главном экране SysTick_task_add(stopwatchTick, 100); //Задача считать время sWatch.nums = 1; sWatch.select = 1; sWatch.dsH[sWatch.nums] = 0; } else { if (!SysTick_task_check(stopwatchTick) && sWatch.nums == sWatch.select) { SysTick_task_add(stopwatchTick, 100); state.taskList |= TASK_STOPWATCH; } else if (sWatch.select < 9) { sWatch.select++; if (sWatch.select > sWatch.nums) { sWatch.dsH[sWatch.nums + 1] = sWatch.dsH[sWatch.nums]; sWatch.nums++; } } } mtk->command = COMMAND_NULL; } break; case COMMAND_PREV: if (sWatch.select > 1) { sWatch.select--; mtk->command = COMMAND_NULL; } break; case COMMAND_UP: { if (sWatch.nums) { if (SysTick_task_check(stopwatchTick)) { SysTick_task_del(stopwatchTick); } else { SysTick_task_add(stopwatchTick, 100); sWatch.select = sWatch.nums; } state.taskList ^= TASK_STOPWATCH; } mtk->command = COMMAND_NULL; } break; case COMMAND_DOWN: { SysTick_task_del(stopwatchTick); sWatch.nums = 0; sWatch.select = 0; state.taskList |= TASK_REDRAW; state.taskList &= ~ TASK_STOPWATCH; mtk->command = COMMAND_NULL; } break; } } else { u8g_DrawLine(mtk->u8g, 0, 38, 239, 38); x = 8, y = 35; for (i = 0; i < sWatch.nums; i++) { sprintf(sTemp, "%d", i + 1); if (sWatch.select == i + 1) { u8g_DrawRBox(mtk->u8g, x - 4, y - 16, 18, 18, 3); u8g_SetDefaultBackgroundColor(mtk->u8g); u8g_DrawStr(mtk->u8g, x, y, sTemp); u8g_SetDefaultForegroundColor(mtk->u8g); } else u8g_DrawStr(mtk->u8g, x, y, sTemp); x += 18; } if (state.taskList & TASK_STOPWATCH) u8g_DrawStr(mtk->u8g, 190, y, "RUN"); else if (!sWatch.nums) u8g_DrawStr(mtk->u8g, 188, y, "STOP"); else u8g_DrawStr(mtk->u8g, 180, y, "PAUSE"); y = 57; if (sWatch.select > 1) { y -= 6; u8g_DrawLine(mtk->u8g, 0, 105, 239, 105); } //Отрисовка верхнего счетчика интервалов. count = sWatch.dsH[sWatch.select] - sWatch.dsH[sWatch.select - 1]; u8g_SetFont(mtk->u8g, u8g_font_elpaulo32n); u8g_SetScale2x2(mtk->u8g); sprintf(sTemp, "%02d:%02d", (count / 600) % 60, (count / 10) % 60); u8g_DrawStr(mtk->u8g, 0, y, sTemp); u8g_UndoScale(mtk->u8g); sprintf(sTemp, ".%01d", count % 10); u8g_DrawStr(mtk->u8g, 205, y * 2, sTemp); } //Отрисовка нижнего/полного счета. if (sWatch.select > 1) { count = sWatch.dsH[sWatch.select]; sprintf(sTemp, "%01d:%02d:%02d:%01d", (count / 36000), ((count / 600) % 60), ((count / 10) % 60), (count % 10)); if(count/360000) x = 43; else x = 67; u8g_DrawStr(mtk->u8g, x, 138, sTemp); u8g_SetFont(mtk->u8g, u8g_font_elpaulo20); u8g_DrawStr(mtk->u8g, 3, 138, "Total:"); } /* Нарисуем подскуазку*/ u8g_SetFont(mtk->u8g, u8g_font_elpaulo20); x = 0, y = 158; u8g_DrawStr(mtk->u8g, x, y, "\x0AStart"); u8g_DrawStr(mtk->u8g, x + 80, y, "\x0CPause"); u8g_DrawStr(mtk->u8g, x + 160, y, "\x0DReset"); u8g_DrawLine(mtk->u8g, 0, 140, 239, 140); x = 75; for (i = 0; i < 2; i++) { u8g_DrawLine(mtk->u8g, x, 141, x, 159); x += 80; } }