// 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; }
// Lua: height = u8g.getHeight( self ) static int lu8g_getHeight( lua_State *L ) { lu8g_userdata_t *lud; if ((lud = get_lud( L )) == NULL) return 0; lua_pushinteger( L, u8g_GetHeight( LU8G ) ); return 1; }
/* update local information */ static void m2_u8g_update(void) { m2_u8g_dev_variables.m2_u8g_height_minus_one = u8g_GetHeight(m2_u8g_dev_variables.m2_u8g); m2_u8g_dev_variables.m2_u8g_height_minus_one--; /* force lower left edge of a text as reference */ u8g_SetFontPosBottom(m2_u8g_dev_variables.m2_u8g); m2_u8g_dev_variables.m2_u8g_fg_text_color = u8g_GetDefaultForegroundColor(m2_u8g_dev_variables.m2_u8g); m2_u8g_dev_variables.m2_u8g_bg_text_color = u8g_GetDefaultBackgroundColor(m2_u8g_dev_variables.m2_u8g); m2_u8g_dev_variables.m2_u8g_current_text_color = m2_u8g_dev_variables.m2_u8g_fg_text_color; m2_u8g_dev_variables.m2_u8g_draw_color = u8g_GetDefaultForegroundColor(m2_u8g_dev_variables.m2_u8g); }
void draw_url(void) { u8g_SetFont(&u8g, u8g_font_4x6); if ( u8g_GetHeight(&u8g) < 59 ) { u8g_DrawStr(&u8g, 53,9,"code.google.com"); u8g_DrawStr(&u8g, 77,18,"/p/u8glib"); } else { u8g_DrawStr(&u8g, 1,54,"code.google.com/p/u8glib"); } }
void draw_color_box1(void) { u8g_uint_t w,h; u8g_uint_t r, g, b; w = u8g_GetWidth(&u8g)/64; h = u8g_GetHeight(&u8g)/32; for( b = 0; b < 4; b++ ) for( g = 0; g < 16; g++ ) for( r = 0; r < 32; r++ ) { u8g_SetRGB(&u8g, r<<3, g<<4, b<<6); u8g_DrawBox(&u8g, g*w + b*w*16, r*h, w, h); } }
void draw_color_box2(void) { u8g_uint_t w,h; u8g_uint_t r, g, b; b = 1; w = u8g_GetWidth(&u8g)/64; h = u8g_GetHeight(&u8g)/32; for( g = 0; g < 16; g++ ) for( r = 0; r < 32; r++ ) { u8g_SetRGB(&u8g, r<<3, g<<4, b<<6); u8g_DrawBox(&u8g, g*w + 0*w*16, r*h, w, h); u8g_DrawBox(&u8g, (16-1-g)*w + 1*w*16, r*h, w, h); u8g_DrawBox(&u8g, g*w + 2*w*16, r*h, w, h); u8g_DrawBox(&u8g, (16-1-g)*w + 3*w*16, r*h, w, h); } }
static void pg_hline(pg_struct *pg, u8g_t *u8g) { pg_word_t x1, x2, y; x1 = pg->pge[PG_LEFT].current_x; x2 = pg->pge[PG_RIGHT].current_x; y = pg->pge[PG_RIGHT].current_y; if ( y < 0 ) return; if ( y >= u8g_GetHeight(u8g) ) return; if ( x1 < x2 ) { if ( x2 < 0 ) return; if ( x1 >= u8g_GetWidth(u8g) ) return; if ( x1 < 0 ) x1 = 0; if ( x2 >= u8g_GetWidth(u8g) ) x2 = u8g_GetWidth(u8g); u8g_DrawHLine(u8g, x1, y, x2 - x1); } else { if ( x1 < 0 ) return; if ( x2 >= u8g_GetWidth(u8g) ) return; if ( x2 < 0 ) x1 = 0; if ( x1 >= u8g_GetWidth(u8g) ) x1 = u8g_GetWidth(u8g); u8g_DrawHLine(u8g, x2, y, x1 - x2); } }
uint8_t m2_gh_u8g_cffs(m2_gfx_arg_p arg) { switch(arg->msg) { case M2_GFX_MSG_DRAW_NORMAL_NO_FOCUS: if ( (arg->font & 4) != 0 ) { /* highlight flag is set, draw frame with shadow */ m2_u8g_draw_color_box(arg->x+1, arg->y+1, arg->w-2, arg->h-2, m2_u8g_highlight_bg_color); m2_u8g_draw_color_frame_shadow(arg->x+m2_u8g_dev_variables.m2_gh_u8g_invisible_frame_border_x_size, arg->y, arg->w-2*m2_u8g_dev_variables.m2_gh_u8g_invisible_frame_border_x_size, arg->h, m2_u8g_highlight_frame_color, m2_u8g_highlight_shadow_color); } m2_u8g_dev_variables.m2_u8g_current_text_color = m2_u8g_dev_variables.m2_u8g_fg_text_color; // if ( m2_gh_u8g_invert_at_depth < m2_gh_u8g_current_depth ) // { // m2_u8g_current_text_color = m2_u8g_bg_text_color; // } break; case M2_GFX_MSG_DRAW_NORMAL_PARENT_FOCUS: break; case M2_GFX_MSG_DRAW_NORMAL_FOCUS: if ( (arg->font & 4) != 0 ) { /* highlight version draw frame with shadow together with a filled box */ //m2_u8g_current_text_color = m2_u8g_bg_text_color; m2_u8g_dev_variables.m2_u8g_current_text_color = m2_u8g_dev_variables.m2_u8g_fg_text_color; m2_u8g_draw_color_box(arg->x+1, arg->y+1, arg->w-2, arg->h-2, m2_u8g_highlight_focus_bg_color); m2_u8g_draw_color_frame_shadow(arg->x+m2_u8g_dev_variables.m2_gh_u8g_invisible_frame_border_x_size, arg->y, arg->w-2*m2_u8g_dev_variables.m2_gh_u8g_invisible_frame_border_x_size, arg->h, m2_u8g_highlight_focus_frame_color, m2_u8g_highlight_focus_shadow_color); // m2_gh_u8g_invert_at_depth = m2_gh_u8g_current_depth; } else { /* normal version draw only the frame with shadow */ m2_u8g_dev_variables.m2_u8g_current_text_color = m2_u8g_dev_variables.m2_u8g_fg_text_color; m2_u8g_draw_color_box(arg->x+1, arg->y+1, arg->w-2, arg->h-2, m2_u8g_normal_focus_bg_color); m2_u8g_draw_color_frame_shadow(arg->x+m2_u8g_dev_variables.m2_gh_u8g_invisible_frame_border_x_size, arg->y, arg->w-2*m2_u8g_dev_variables.m2_gh_u8g_invisible_frame_border_x_size, arg->h, m2_u8g_normal_focus_frame_color, m2_u8g_normal_focus_shadow_color); } // printf("invert %d, width %d x:%d y:%d\n", m2_gh_u8g_invert_at_depth, arg->w, arg->x, arg->y); break; case M2_GFX_MSG_DRAW_SMALL_FOCUS: /* m2_u8g_current_text_color = m2_u8g_bg_text_color; m2_u8g_draw_color_box(arg->x, arg->y, arg->w, arg->h, m2_u8g_fg_text_color); */ m2_u8g_dev_variables.m2_u8g_current_text_color = m2_u8g_dev_variables.m2_u8g_fg_text_color; m2_u8g_draw_color_box(arg->x, arg->y, arg->w, arg->h, m2_u8g_small_focus_bg_color); break; case M2_GFX_MSG_DRAW_GO_UP: /* does not work because of missing xor... also: can not be fixed with FRAME_DRAW_AT_END m2_u8g_current_text_color = m2_u8g_bg_text_color; */ m2_u8g_draw_color_box(arg->x, arg->y, arg->w, arg->h/2, m2_u8g_exit_data_entry_color); break; case M2_GFX_MSG_GET_NORMAL_BORDER_HEIGHT: return 3; case M2_GFX_MSG_GET_NORMAL_BORDER_WIDTH: return 3+2*m2_u8g_dev_variables.m2_gh_u8g_invisible_frame_border_x_size+2*m2_u8g_dev_variables.m2_gh_u8g_additional_text_border_x_size; case M2_GFX_MSG_GET_NORMAL_BORDER_X_OFFSET: return 1+m2_u8g_dev_variables.m2_gh_u8g_invisible_frame_border_x_size+m2_u8g_dev_variables.m2_gh_u8g_additional_text_border_x_size; case M2_GFX_MSG_GET_NORMAL_BORDER_Y_OFFSET: return 2; case M2_GFX_MSG_GET_LIST_OVERLAP_HEIGHT: return 0; case M2_GFX_MSG_GET_LIST_OVERLAP_WIDTH: return 0; case M2_GFX_MSG_IS_FRAME_DRAW_AT_END: return 0; /* focus (highlight) is drawn first, then the text string */ case M2_GFX_MSG_START: u8g_SetColorIndex(m2_u8g_dev_variables.m2_u8g, m2_u8g_background_color); u8g_DrawBox(m2_u8g_dev_variables.m2_u8g, 0, 0, u8g_GetWidth(m2_u8g_dev_variables.m2_u8g), u8g_GetHeight(m2_u8g_dev_variables.m2_u8g)); break; } return m2_gh_u8g_base(arg); }