// calculate new output values int uiStep(u8g_t *u8g) { int key = u8g_sdl_get_key(); switch( key ) { case ' ': return 1; case 273: case 'x': if ( cursor_y >= 0 + uiIncrement ) cursor_y -= uiIncrement; return 1; case 274: case 's': if ( cursor_y <= u8g_GetHeight(u8g) - uiIncrement ) cursor_y += uiIncrement; return 1; case 276: case 'c': if ( cursor_x >= 0 + uiIncrement ) cursor_x -= uiIncrement; return 1; case 275: case 'v': if ( cursor_x <= u8g_GetWidth(u8g) - uiIncrement ) cursor_x += uiIncrement; return 1; case 'q': exit(0); } return 0; }
uint8_t get_key_code(void) { uint8_t chess_key; int sdl_key; sdl_key = u8g_sdl_get_key(); chess_key = CHESS_KEY_NONE; switch ( sdl_key ) { case 'n': case 274: // arrow down case 275: // arrow right chess_key = CHESS_KEY_NEXT; break; case 'p': case 273: // arrow up case 276: // arrow left chess_key = CHESS_KEY_PREV; break; case ' ': chess_key = CHESS_KEY_SELECT; break; case 'q': exit(0); break; } return chess_key; }
// calculate new output values void uiStep(void) { #if USE_SDL int key = u8g_sdl_get_key(); switch (key) { case 'q': case ' ': exit(0); } #endif }
int main(void) { u8g_Init(&u8g, &u8g_dev_sdl_1bit); u8g_FirstPage(&u8g); do { draw(); } while( u8g_NextPage(&u8g) ); while( u8g_sdl_get_key() < 0 ) ; }
int main(void) { u8g_uint_t w,h; u8g_uint_t r, g, b, x, y; u8g_t u8g; u8g_Init(&u8g, &u8g_dev_sdl_8bit); u8g_FirstPage(&u8g); do { u8g_SetFont(&u8g, u8g_font_10x20); u8g_SetFont(&u8g, u8g_font_fur25); /* for ( x = 0; x < 128; x++ ) for ( y = 0; y < 64; y++ ) { u8g_SetColorIndex(&u8g, ((x&3)+y*4) & 255); u8g_DrawPixel(&u8g, x, y); } */ w = 4; h = 4; for( b = 0; b < 4; b++ ) for( g = 0; g < 8; g++ ) for( r = 0; r < 8; r++ ) { u8g_SetColorIndex(&u8g, (r<<5) | (g<<2) | b ); u8g_DrawBox(&u8g, g*w + b*w*8, r*h, w, h); u8g_DrawBox(&u8g, g*w + b*w*8, r*h+32, w, h); } w = u8g_GetFontBBXWidth(&u8g); h = u8g_GetFontBBXHeight(&u8g); u8g_SetColorIndex(&u8g, 1); u8g_DrawStr(&u8g, 20, 40, "U8glib"); u8g_SetColorIndex(&u8g, 2); u8g_DrawStr(&u8g, 20+1, 40+1, "U8glib"); u8g_SetColorIndex(&u8g, 3); u8g_DrawStr(&u8g, 20+2, 40+2, "U8glib"); }while( u8g_NextPage(&u8g) ); while( u8g_sdl_get_key() < 0 ) ; return 0; }
uint8_t getButton(void) { int8_t key = BUTTON_NULL; key = u8g_sdl_get_key() - 16; switch(key){ case 1: return BUTTON_UP; case 2: return BUTTON_DOWN; case 3: return BUTTON_RIGHT; case 4: return BUTTON_LEFT; } if (key > 0) { printf("Key: %d\n", key); return key; } return BUTTON_NULL; }
int main(void) { u8g2_SetupBuffer_SDL_128x64(&u8g2, &u8g2_cb_r0); u8x8_InitDisplay(u8g2_GetU8x8(&u8g2)); u8x8_SetPowerSave(u8g2_GetU8x8(&u8g2), 0); u8g2_DrawHVLine(&u8g2, 5, 20, 40, 0); u8g2_DrawHVLine(&u8g2, 5, 22, 40, 0); u8g2_DrawHVLine(&u8g2, 5, 24, 40, 0); u8g2_DrawHVLine(&u8g2, 5, 24, 40, 1); /* clipping tests */ u8g2_DrawHVLine(&u8g2, 60000, 10000, 39, 0); u8g2_DrawHVLine(&u8g2, 140, 40, 40, 0); u8g2_DrawHVLine(&u8g2, 120, 41, 40, 0); u8g2_DrawHVLine(&u8g2, 120, 42, 0xff8f, 0); /* rare case */ u8g2_DrawHVLine(&u8g2, 120, 43, 6, 0); u8g2_DrawHVLine(&u8g2, 0, 40, 10, 0); u8g2_DrawHVLine(&u8g2, -2, 41, 5, 0); u8g2_DrawHVLine(&u8g2, -3, 42, 5, 0); u8g2_DrawHVLine(&u8g2, -8, 43, 5, 0); u8g2_DrawHVLine(&u8g2, 0, 44, 10, 0); u8g2_DrawHVLine(&u8g2, 99, 70, 40, 1); u8g2_DrawHVLine(&u8g2, 98, 60, 40, 1); u8g2_DrawHVLine(&u8g2, 97, 60, 0xfff0, 1); /* rare case */ u8g2_DrawHVLine(&u8g2, 96, 60, 3, 1); u8g2_SendBuffer(&u8g2); u8x8_Set8x8Font(u8g2_GetU8x8(&u8g2), bdf_font); u8x8_Draw8x8String(u8g2_GetU8x8(&u8g2), 0, 0, "Hello World!"); while( u8g_sdl_get_key() < 0 ) ; return 0; }
int xmain(void) { u8g_uint_t w,h; u8g_t u8g; u8g_Init(&u8g, &u8g_dev_sdl_1bit); u8g_FirstPage(&u8g); u8g_SetCursorFont(&u8g, u8g_font_cursor); do { u8g_SetColorIndex(&u8g, 1); u8g_SetFont(&u8g, u8g_font_9x18); //u8g_SetFont(&u8g, u8g_font_fur17); w = u8g_GetFontBBXWidth(&u8g); h = u8g_GetFontBBXHeight(&u8g); //u8g_DrawStr(&u8g, 0, 2*h, 0, "ABCgdef"); u8g_DrawStrDir(&u8g, 0, 5, 0, "g"); u8g_DrawStrDir(&u8g, 10, 7, 0, "g"); u8g_DrawStrDir(&u8g, 20, 9, 0, "g"); u8g_DrawStrDir(&u8g, 20, 9, 0, "ga"); //u8g_DrawStr(&u8g, 40, 9, 0, "g"); u8g_DrawStr(&u8g, 70+3, 25, "gabc"); u8g_DrawStr90(&u8g, 70, 25+3, "gabc"); u8g_DrawStr180(&u8g, 70-3, 25, "gabc"); u8g_DrawStr270(&u8g, 70, 25-3, "gabc"); //u8g_DrawFrame(&u8g, 2, 2, 9, 3); //u8g_DrawFrame(&u8g, 0, 0, 13, 7); //u8g_DrawHLine( &u8g, 0, 16, 50 ); u8g_SetColorIndex(&u8g, 1); u8g_DrawHLine( &u8g, 0, 3, 127 ); u8g_SetColorIndex(&u8g, 0); u8g_DrawHLine( &u8g, 0, 4, 127 ); }while( u8g_NextPage(&u8g) ); while( u8g_sdl_get_key() < 0 ) ; return 0; }
int main(void) { u8x8_Setup_SDL_128x64(&u8g2); u8x8_InitDisplay(&u8g2); u8x8_SetFont(&u8g2, u8x8_font_amstrad_cpc_extended_f); u8x8_DrawString(&u8g2, 0, 0, "UTF-8 Test"); u8x8_DrawString(&u8g2, 0, 1, "M\xfcnchen");/* works: select umlaut-u directly with code 0xfc */ u8x8_DrawString(&u8g2, 0, 2, "München"); /* does not work: umlaut-u is translated to utf-8, broken output */ u8x8_DrawUTF8(&u8g2, 0, 3, "M\xfcnchen"); /* does not work: Codes above 127 are reserved for UTF-8 encoding */ u8x8_DrawUTF8(&u8g2, 0, 4, "München"); /* works: u8x8 can handle UTF-8 code correctly */ while( u8g_sdl_get_key() < 0 ) ; return 0; }
int main(void) { u8g_t u8g; u8g_Init(&u8g, &u8g_dev_sdl_1bit); u8g_FirstPage(&u8g); do { u8g_SetFont(&u8g, u8g_font_unifont); //u8g_SetFont(&u8g, u8g_font_osb18r); u8g_DrawStr(&u8g, 0, 20, "Hello World!"); } while( u8g_NextPage(&u8g) ); while( u8g_sdl_get_key() < 0 ) ; }
uint8_t get_key_code(void) { uint8_t chess_key; int sdl_key; sdl_key = u8g_sdl_get_key(); chess_key = CHESS_KEY_NONE; if ( sdl_key > 0 ) { if ( sdl_key == 'n' ) chess_key = CHESS_KEY_NEXT; else if ( sdl_key == 'p' ) chess_key = CHESS_KEY_PREV; else if ( sdl_key == ' ' ) chess_key = CHESS_KEY_SELECT; else if ( sdl_key == 'q' ) exit(0); } return chess_key; }
int main(void) { u8g_t u8g; u8g_Init(&u8g, &u8g_dev_sdl_1bit_h); u8g_FirstPage(&u8g); do { u8g_SetColorIndex(&u8g, 1); u8g_DrawPixel(&u8g,0,0); u8g_DrawPixel(&u8g,0,1); u8g_SetFont(&u8g, u8g_font_unifont); //u8g_SetFont(&u8g, u8g_font_10x20); //u8g_SetFont(&u8g, u8g_font_gdb17); u8g_SetFontRefHeightText(&u8g); //u8g_SetRefHeightAll(&u8g); //u8g_SetFontPosBaseline(&u8g); //u8g_SetFontPosCenter(&u8g); u8g_SetFontPosTop(&u8g); glyph(&u8g, 5,25, 'g'); u8g_SetFontPosCenter(&u8g); glyph(&u8g, 5+25,25, 'g'); u8g_SetFontPosBaseline(&u8g); glyph(&u8g, 5+2*25,25, 'g'); u8g_SetFontPosBottom(&u8g); glyph(&u8g, 5+3*25,25, 'g'); }while( u8g_NextPage(&u8g) ); while( u8g_sdl_get_key() < 0 ) ; return 0; }
// calculate new output values void uiStep(void) { int key = u8g_sdl_get_key(); isFire = 0; switch( key ) { case ' ': isFire = 1; break; case 274: case 'x': if ( shipLocation >= 0+ uiIncrement ) shipLocation -= uiIncrement; //printf("%d\n", shipLocation); break; case 273: case 's': if ( shipLocation <= 255 - uiIncrement ) shipLocation += uiIncrement; //printf("%d\n", shipLocation); break; case 'q': exit(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; }
int main(void) { u8g_t u8g; uint8_t rad; u8g_Init(&u8g, &u8g_dev_sdl_1bit); u8g_FirstPage(&u8g); do { //u8g_SetFont(&u8g, u8g_font_unifont); //u8g_SetFont(&u8g, u8g_font_osb18r); for( rad = 2+3*2; rad < 30; rad += 3 ) { u8g_DrawEmpCirc(&u8g, 0, 35, rad, U8G_DRAW_UPPER_RIGHT); u8g_DrawCircle(&u8g, 0, 35+35, rad, U8G_DRAW_UPPER_RIGHT); u8g_DrawEmpCirc(&u8g, 0+31, 5, rad, U8G_DRAW_LOWER_RIGHT); u8g_DrawCircle(&u8g, 0+31, 5+35, rad, U8G_DRAW_LOWER_RIGHT); u8g_DrawEmpCirc(&u8g, 30+31*2, 5, rad, U8G_DRAW_LOWER_LEFT); u8g_DrawCircle(&u8g, 30+31*2, 5+35, rad, U8G_DRAW_LOWER_LEFT); u8g_DrawEmpCirc(&u8g, 0+31*4, 35, rad, U8G_DRAW_UPPER_LEFT); u8g_DrawCircle(&u8g, 0+31*4, 35+35, rad, U8G_DRAW_UPPER_LEFT); } } while( u8g_NextPage(&u8g) ); while( u8g_sdl_get_key() < 0 ) ; for( rad = 2+3*2; rad < 30; rad += 3 ) { u8g_FirstPage(&u8g); do { //u8g_SetFont(&u8g, u8g_font_unifont); //u8g_SetFont(&u8g, u8g_font_osb18r); u8g_DrawFillCirc(&u8g, 0, 35, rad, U8G_DRAW_UPPER_RIGHT); u8g_DrawDisc(&u8g, 0, 35+35, rad, U8G_DRAW_UPPER_RIGHT); u8g_DrawFillCirc(&u8g, 0+31, 5, rad, U8G_DRAW_LOWER_RIGHT); u8g_DrawDisc(&u8g, 0+31, 5+35, rad, U8G_DRAW_LOWER_RIGHT); u8g_DrawFillCirc(&u8g, 30+31*2, 5, rad, U8G_DRAW_LOWER_LEFT); u8g_DrawDisc(&u8g, 30+31*2, 5+35, rad, U8G_DRAW_LOWER_LEFT); u8g_DrawFillCirc(&u8g, 0+31*4, 35, rad, U8G_DRAW_UPPER_LEFT); u8g_DrawDisc(&u8g, 0+31*4, 35+35, rad, U8G_DRAW_UPPER_LEFT); } while( u8g_NextPage(&u8g) ); while( u8g_sdl_get_key() < 0 ) ; } return 0; }