/* Name: me_cb_0_9 Val: uint8_t * */ int me_cb_0_9(menu_t *menu, const me_t *me, uint8_t msg) { switch(msg) { case ME_MSG_IS_FOCUS: return 1; case ME_MSG_DRAW_FOCUS: u8g2_SetFont(menu->u8g2, MENU_BIG_NUM); menu_DrawBoxFocus(menu, me->x+MENU_BIG_NUM_FOCUS_XO, me->y - u8g2_GetAscent(menu->u8g2)-1, u8g2_GetGlyphWidth(menu->u8g2, '0')+MENU_BIG_NUM_FOCUS_EXTRAX, u8g2_GetAscent(menu->u8g2) + 2); return 1; case ME_MSG_SELECT: { uint8_t val = *(uint8_t *)(me->val); val++; if ( val > 9 ) val = 0; *(uint8_t *)(me->val) = val; } return 1; case ME_MSG_DRAW: u8g2_SetFont(menu->u8g2, MENU_BIG_NUM); u8g2_DrawGlyph(menu->u8g2, me->x, me->y, *(uint8_t *)(me->val) + '0'); return 1; } return 0; }
int main(void) { u8g2_SetupBuffer_SDL_128x64_4(&u8g2, &u8g2_cb_r0); u8x8_InitDisplay(u8g2_GetU8x8(&u8g2)); u8x8_SetPowerSave(u8g2_GetU8x8(&u8g2), 0); u8g2_SetFont(&u8g2, u8g2_font_helvB08_tr); u8g2_SetFontDirection(&u8g2, 0); u8g2_SetFontRefHeightAll(&u8g2); u8g2_UserInterfaceSelectionList(&u8g2, "Title", 0, "abc\ndef\nghi\njkl\n12345\n67890"); /* do { k = u8g_sdl_get_key(); } while( k < 0 ); if ( k == 273 ) y -= 7; if ( k == 274 ) y += 7; if ( k == 276 ) x -= 7; if ( k == 275 ) x += 7; if ( k == 'e' ) y -= 1; if ( k == 'x' ) y += 1; if ( k == 's' ) x -= 1; if ( k == 'd' ) x += 1; if ( k == 'q' ) break; */ return 0; }
int main(void) { uint8_t i, cnt; u8g2_SetupBuffer_Utf8(&u8g2, &u8g2_cb_r0); u8x8_InitDisplay(u8g2_GetU8x8(&u8g2)); u8x8_SetPowerSave(u8g2_GetU8x8(&u8g2), 0); u8g2_SetFont(&u8g2, u8g2_font_helvB10_tr); #ifdef U8G2_WITH_HVLINE_COUNT u8g2.hv_cnt = 0UL; #endif /* U8G2_WITH_HVLINE_COUNT */ u8g2_FirstPage(&u8g2); i = 0; cnt = u8x8_GetStringLineCnt(str); do { for( i = 0; i < cnt; i++ ) { u8g2_DrawStr(&u8g2, 0, i*12+11, u8x8_GetStringLine(i, str)); } } while( u8g2_NextPage(&u8g2) ); #ifdef U8G2_WITH_HVLINE_COUNT printf("hv cnt: %ld\n", u8g2.hv_cnt); #endif /* U8G2_WITH_HVLINE_COUNT */ utf8_show(); return 0; }
/* Name: me_cb_button_full_line Val: callback function Arg: char * */ int me_cb_button_half_line(menu_t *menu, const me_t *me, uint8_t msg) { int r = 0; switch(msg) { case ME_MSG_IS_FOCUS: return 1; case ME_MSG_DRAW_FOCUS: menu_DrawBoxFocus(menu, me->x, me->y - u8g2_GetAscent(menu->u8g2)-1, u8g2_GetDisplayWidth(menu->u8g2)/2, u8g2_GetAscent(menu->u8g2) - u8g2_GetDescent(menu->u8g2) +1); r = 1; break; case ME_MSG_DRAW: u8g2_SetFont(menu->u8g2, MENU_NORMAL_FONT); u8g2_DrawUTF8(menu->u8g2, me->x+4, me->y, (char *)(me->arg) ); r = 1; break; } /* pass all messages except for the IS_FOCUS also to the callback function */ if ( me->val != NULL ) return ((me_cb)(me->val))(menu, me, msg) | r; return r; }
int main(void) { u8g2_SetupBuffer_Utf8(&u8g2, U8G2_R0); u8g2_InitDisplay(&u8g2); u8g2_SetPowerSave(&u8g2, 0); u8g2_SetFont(&u8g2, u8g2_font_6x13_tf); u8g2_SetFontDirection(&u8g2, 0); u8g2_FirstPage(&u8g2); do { u8g2_DrawRBox(&u8g2, 2, 3, 8, 9, 3); u8g2_DrawRBox(&u8g2, 12, 3, 5, 13, 2); u8g2_DrawRBox(&u8g2, 12,17, 13, 3, 1); u8g2_DrawRFrame(&u8g2, 2,21, 11, 7, 3); u8g2_DrawRFrame(&u8g2, 25,24, 27, 5, 2); u8g2_DrawRFrame(&u8g2, 23,22, 31, 9, 3); u8g2_DrawStr(&u8g2, 30, 10, "RBox"); u8g2_DrawStr(&u8g2, 30, 20, "RFrame"); } while( u8g2_NextPage(&u8g2) ); utf8_show(); return 0; }
/* Name: me_cb_0_23 Val: uint8_t * */ int me_cb_0_23(menu_t *menu, const me_t *me, uint8_t msg) { char s[4]; switch(msg) { case ME_MSG_IS_FOCUS: return 1; case ME_MSG_DRAW_FOCUS: u8g2_SetFont(menu->u8g2, MENU_BIG_NUM); menu_DrawBoxFocus(menu, me->x+MENU_BIG_NUM_FOCUS_XO, me->y - u8g2_GetAscent(menu->u8g2)-1, u8g2_GetGlyphWidth(menu->u8g2, '0')*2+MENU_BIG_NUM_FOCUS_EXTRAX, u8g2_GetAscent(menu->u8g2) + 2); return 1; case ME_MSG_SELECT: { uint8_t val = *(uint8_t *)(me->val); val++; if ( val > 23 ) val = 0; *(uint8_t *)(me->val) = val; } return 1; case ME_MSG_DRAW: u8g2_SetFont(menu->u8g2, MENU_BIG_NUM); s[0] = *(uint8_t *)(me->val); s[1] = s[0]; s[1] %= 10; s[1] += '0'; s[0] /= 10; s[0] += '0'; s[2] = '\0'; u8g2_DrawUTF8(menu->u8g2, me->x, me->y, s); return 1; } return 0; }
/* Name: me_cb_label can not get focus Arg: char * */ int me_cb_label(menu_t *menu, const me_t *me, uint8_t msg) { switch(msg) { case ME_MSG_IS_FOCUS: case ME_MSG_DRAW_FOCUS: case ME_MSG_SELECT: break; case ME_MSG_DRAW: u8g2_SetFont(menu->u8g2, MENU_NORMAL_FONT); u8g2_DrawUTF8(menu->u8g2, me->x, me->y, (char *)(me->arg) ); return 1; } return 0; }
void write_tga_map(const char *filename) { static u8g2_t u8g2; int x, y, i; unsigned tile; if ( map_phase != PHASE_MAPDATA ) return; u8x8_tga_info.tile_width = map_width*2; u8x8_tga_info.tile_height = map_height*2; u8x8_tga_info.pixel_width = map_width*16; u8x8_tga_info.pixel_height = map_height*16; u8g2_SetupBuffer_TGA(&u8g2, &u8g2_cb_r0); u8x8_InitDisplay(u8g2_GetU8x8(&u8g2)); u8x8_SetPowerSave(u8g2_GetU8x8(&u8g2), 0); u8g2_SetFont(&u8g2, scrollosprites); u8g2_FirstPage(&u8g2); do { for( y = 0; y < map_height; y++ ) { for( x = 0; x < map_width; x++ ) { tile = map2[y][x]; /* check if there is a fg_tile, if so, use that tile instead */ for( i = 0; i < tile_cnt; i++ ) { if ( tile_list[i].item_index >= 0 ) { if ( tile_list[i].ascii == map[y][x] ) { tile = item_list[tile_list[i].item_index].fg_tile; } } } u8g2_DrawGlyph(&u8g2, x*16, y*16+16, tile); } } } while( u8g2_NextPage(&u8g2) ); tga_save(filename); }
int me_cb_0_9_small_ro(menu_t *menu, const me_t *me, uint8_t msg) { switch(msg) { case ME_MSG_IS_FOCUS: return 0; case ME_MSG_DRAW_FOCUS: return 1; case ME_MSG_SELECT: return 1; case ME_MSG_DRAW: u8g2_SetFont(menu->u8g2, MENU_SMALL_FONT); u8g2_DrawGlyph(menu->u8g2, me->x, me->y, *(uint8_t *)(me->val) + '0'); return 1; } return 0; }
int main(void) { u8g2_SetupBuffer_Utf8(&u8g2, &u8g2_cb_r0); u8x8_InitDisplay(u8g2_GetU8x8(&u8g2)); u8x8_SetPowerSave(u8g2_GetU8x8(&u8g2), 0); u8g2_SetFont(&u8g2, u8g2_font_unifont_t_chinese2); u8g2_SetFontDirection(&u8g2, 0); u8g2_FirstPage(&u8g2); do { u8g2_DrawUTF8(&u8g2, 2, 15, "你好世界"); u8g2_DrawStr(&u8g2, 2, 30, "Hello World"); } while( u8g2_NextPage(&u8g2) ); utf8_show(); return 0; }
int main(void) { int y; u8g2_SetupBuffer_Utf8(&u8g2, &u8g2_cb_r0); u8x8_InitDisplay(u8g2_GetU8x8(&u8g2)); u8x8_SetPowerSave(u8g2_GetU8x8(&u8g2), 0); u8g2_SetFont(&u8g2, u8g2_font_5x7_tr); u8g2_SetFontDirection(&u8g2, 0); #ifdef U8G2_WITH_HVLINE_COUNT u8g2.hv_cnt = 0UL; #endif /* U8G2_WITH_HVLINE_COUNT */ u8g2_FirstPage(&u8g2); do { for( y = 3; y < 21; y++ ) { u8g2_DrawHLine(&u8g2, 3, y, 11); } u8g2_DrawStr(&u8g2, 17, 8, "Test Inter-"); u8g2_DrawStr(&u8g2, 17, 16, "section:"); u8g2_DrawStr(&u8g2, 17, 24, "One Block"); } while( u8g2_NextPage(&u8g2) ); #ifdef U8G2_WITH_HVLINE_COUNT printf("hv cnt: %ld\n", u8g2.hv_cnt); #endif /* U8G2_WITH_HVLINE_COUNT */ utf8_show(); return 0; }
/* Name: me_cb_wd_toggle Val: uint8_t * Arg: char * */ int me_cb_wd_toggle(menu_t *menu, const me_t *me, uint8_t msg) { uint8_t val = *(uint8_t *)(me->val); u8g2_uint_t x, y, w, h; u8g2_SetFont(menu->u8g2, MENU_SMALL_FONT); w = 13; h = u8g2_GetAscent(menu->u8g2)+2; x = me->x-2; y = me->y - u8g2_GetAscent(menu->u8g2)-1; switch(msg) { case ME_MSG_IS_FOCUS: return 1; case ME_MSG_DRAW_FOCUS: menu_DrawFrameFocus(menu, x, y, w, h); return 1; case ME_MSG_SELECT: { val++; if ( val > 1 ) val = 0; *(uint8_t *)(me->val) = val; } return 1; case ME_MSG_DRAW: u8g2_DrawUTF8(menu->u8g2, me->x, me->y, (const char *)(me->arg)); if ( val > 0 ) { menu_DrawBoxFocus(menu, x,y,w,h); } //u8g2_DrawRFrame(menu->u8g2, x, y, w, h, 1); return 1; } return 0; }
int main(void) { u8g2_SetupBuffer_Utf8(&u8g2, U8G2_R0); u8g2_InitDisplay(&u8g2); u8g2_SetPowerSave(&u8g2, 0); u8g2_SetFont(&u8g2, u8g2_font_6x13_tf); u8g2_SetFontDirection(&u8g2, 0); u8g2_FirstPage(&u8g2); do { u8g2_DrawXBM(&u8g2, 1, 1, 19, 29, b); u8g2_DrawStr(&u8g2, 30, 20, "XBM"); } while( u8g2_NextPage(&u8g2) ); utf8_show(); return 0; }
int main(void) { uint8_t value = 0; u8g2_SetupBuffer_SDL_128x64_4(&u8g2, &u8g2_cb_r0); u8x8_InitDisplay(u8g2_GetU8x8(&u8g2)); u8x8_SetPowerSave(u8g2_GetU8x8(&u8g2), 0); //u8g2_SetFont(&u8g2, u8g2_font_helvB08_tr); u8g2_SetFont(&u8g2, u8g2_font_6x10_tr); u8g2_SetFontDirection(&u8g2, 0); u8g2_SetFontRefHeightAll(&u8g2); u8g2_UserInterfaceInputValue(&u8g2, "Title\n-----\n", "X=", &value, 0, 19, 2, "m"); /* do { k = u8g_sdl_get_key(); } while( k < 0 ); if ( k == 273 ) y -= 7; if ( k == 274 ) y += 7; if ( k == 276 ) x -= 7; if ( k == 275 ) x += 7; if ( k == 'e' ) y -= 1; if ( k == 'x' ) y += 1; if ( k == 's' ) x -= 1; if ( k == 'd' ) x += 1; if ( k == 'q' ) break; */ return 0; }
int main(void) { int x, y; int k; int i; u8g2_SetupBuffer_TGA_LCD(&u8g2, &u8g2_cb_r0); u8x8_InitDisplay(u8g2_GetU8x8(&u8g2)); u8x8_SetPowerSave(u8g2_GetU8x8(&u8g2), 0); u8g2_SetFont(&u8g2, u8g2_font_helvB18_tr); x = 50; y = 30+0; #ifdef U8G2_WITH_HVLINE_COUNT u8g2.hv_cnt = 0UL; #endif /* U8G2_WITH_HVLINE_COUNT */ /* u8g2_ClearBuffer(&u8g2); u8g2_SetFontDirection(&u8g2, 0); u8g2_DrawStr(&u8g2, x, y, "ABC"); u8g2_SetFontDirection(&u8g2, 1); u8g2_DrawStr(&u8g2, x, y, "abc"); u8g2_SetFontDirection(&u8g2, 2); u8g2_DrawStr(&u8g2, x, y, "abc"); u8g2_SetFontDirection(&u8g2, 3); u8g2_DrawStr(&u8g2, x, y, "abc"); u8g2_SendBuffer(&u8g2); */ u8g2_FirstPage(&u8g2); i = 0; do { u8g2_SetFontDirection(&u8g2, 0); u8g2_DrawStr(&u8g2, x, y, "ABC"); u8g2_SetFontDirection(&u8g2, 1); u8g2_DrawStr(&u8g2, x, y, "abc"); u8g2_SetFontDirection(&u8g2, 2); u8g2_DrawStr(&u8g2, x, y, "abc"); u8g2_SetFontDirection(&u8g2, 3); u8g2_DrawStr(&u8g2, x, y, "abc"); if ( i == 1 ) { u8g2_DrawHVLine(&u8g2, u8g2.user_x0, u8g2.user_y0, 1, 0); u8g2_DrawHVLine(&u8g2, u8g2.user_x0, u8g2.user_y1-1, 1, 0); u8g2_DrawHVLine(&u8g2, u8g2.user_x1-1, u8g2.user_y1-1, 1, 0); u8g2_DrawHVLine(&u8g2, u8g2.user_x1-1, u8g2.user_y0, 1, 0); } i++; } while( u8g2_NextPage(&u8g2) ); #ifdef U8G2_WITH_HVLINE_COUNT printf("hv cnt: %ld\n", u8g2.hv_cnt); #endif /* U8G2_WITH_HVLINE_COUNT */ tga_save("u8g2.tga"); return 0; }
int main(void) { uint32_t screen = 0; u8g2_t u8g2; /* initialize to stdout */ #if TEST_U8G2_OUTPUT == TEST_U8G2_OUTPUT_STDOUT puts("initializing to stdout."); u8g2_SetupBuffer_Utf8(&u8g2, U8G2_R0); #endif /* initialize to virtual SDL (native only) */ #if TEST_U8G2_OUTPUT == TEST_U8G2_OUTPUT_SDL puts("initializing to SDL."); u8g2_SetupBuffer_SDL_128x64_4(&u8g2, U8G2_R0); #endif /* initialize to SPI */ #if TEST_U8G2_OUTPUT == TEST_U8G2_OUTPUT_SPI puts("initializing to SPI."); TEST_U8G2_DISPLAY(&u8g2, U8G2_R0, u8x8_byte_riotos_hw_spi, u8x8_gpio_and_delay_riotos); u8g2_SetPins(&u8g2, pins, pins_enabled); u8g2_SetDevice(&u8g2, TEST_U8G2_SPI); #endif /* initialize to I2C */ #if TEST_U8G2_OUTPUT == TEST_U8G2_OUTPUT_I2C puts("initializing to I2C."); TEST_U8G2_DISPLAY(&u8g2, U8G2_R0, u8x8_byte_riotos_hw_i2c, u8x8_gpio_and_delay_riotos); u8g2_SetPins(&u8g2, pins, pins_enabled); u8g2_SetDevice(&u8g2, TEST_U8G2_I2C); u8g2_SetI2CAddress(&u8g2, TEST_U8G2_ADDR); #endif /* initialize the display */ puts("Initializing display."); u8g2_InitDisplay(&u8g2); u8g2_SetPowerSave(&u8g2, 0); /* start drawing in a loop */ puts("Drawing on screen."); while (true) { u8g2_FirstPage(&u8g2); do { u8g2_SetDrawColor(&u8g2, 1); u8g2_SetFont(&u8g2, u8g2_font_helvB12_tf); if (screen == 0) { u8g2_DrawStr(&u8g2, 12, 22, "THIS"); } else if (screen == 1) { u8g2_DrawStr(&u8g2, 24, 22, "IS"); } else if (screen == 2) { u8g2_DrawBitmap(&u8g2, 0, 0, 8, 32, logo); } } while (u8g2_NextPage(&u8g2)); #if TEST_U8G2_OUTPUT == TEST_U8G2_OUTPUT_STDOUT /* transfer screen buffer to stdout */ utf8_show(); #endif /* show screen in next iteration */ screen = (screen + 1) % 3; /* sleep a little */ xtimer_sleep(1); } return 0; }
int main(void) { int x, y; int k; int i; u8g2_SetupBuffer_SDL_128x64_4(&u8g2, &u8g2_cb_r0); u8x8_InitDisplay(u8g2_GetU8x8(&u8g2)); u8x8_SetPowerSave(u8g2_GetU8x8(&u8g2), 0); u8g2_SetFont(&u8g2, u8g2_font_helvB18_tn); x = 50; y = 30; for(;;) { #ifdef U8G2_WITH_HVLINE_COUNT u8g2.hv_cnt = 0UL; #endif /* U8G2_WITH_HVLINE_COUNT */ /* u8g2_ClearBuffer(&u8g2); u8g2_SetFontDirection(&u8g2, 0); u8g2_DrawStr(&u8g2, x, y, "ABC"); u8g2_SetFontDirection(&u8g2, 1); u8g2_DrawStr(&u8g2, x, y, "abc"); u8g2_SetFontDirection(&u8g2, 2); u8g2_DrawStr(&u8g2, x, y, "abc"); u8g2_SetFontDirection(&u8g2, 3); u8g2_DrawStr(&u8g2, x, y, "abc"); u8g2_SendBuffer(&u8g2); */ u8g2_FirstPage(&u8g2); i = 0; do { u8g2_SetFontDirection(&u8g2, 0); u8g2_DrawStr(&u8g2, x, y, "123"); u8g2_SetFontDirection(&u8g2, 1); u8g2_DrawStr(&u8g2, x, y, "123"); u8g2_SetFontDirection(&u8g2, 2); u8g2_DrawStr(&u8g2, x, y, "123"); u8g2_SetFontDirection(&u8g2, 3); u8g2_DrawStr(&u8g2, x, y, "123"); if ( i == 1 ) { u8g2_DrawHVLine(&u8g2, u8g2.user_x0, u8g2.user_y0, 1, 0); u8g2_DrawHVLine(&u8g2, u8g2.user_x0, u8g2.user_y1-1, 1, 0); u8g2_DrawHVLine(&u8g2, u8g2.user_x1-1, u8g2.user_y1-1, 1, 0); u8g2_DrawHVLine(&u8g2, u8g2.user_x1-1, u8g2.user_y0, 1, 0); } i++; } while( u8g2_NextPage(&u8g2) ); #ifdef U8G2_WITH_HVLINE_COUNT printf("hv cnt: %ld\n", u8g2.hv_cnt); #endif /* U8G2_WITH_HVLINE_COUNT */ do { k = u8g_sdl_get_key(); } while( k < 0 ); if ( k == 273 ) y -= 7; if ( k == 274 ) y += 7; if ( k == 276 ) x -= 7; if ( k == 275 ) x += 7; if ( k == 'e' ) y -= 1; if ( k == 'x' ) y += 1; if ( k == 's' ) x -= 1; if ( k == 'd' ) x += 1; if ( k == 'q' ) break; } //u8x8_Set8x8Font(u8g2_GetU8x8(&u8g2), bdf_font); //u8x8_Draw8x8String(u8g2_GetU8x8(&u8g2), 0, 0, "Hello World!"); return 0; }