Beispiel #1
0
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));
}
Beispiel #2
0
static void calculate_dimensions() {

    // When we query font dimensions, base them on the largest extent of all
    // the glyphs in the font:
    u8g_SetFontRefHeightAll( u8g );

    u8g_SetFont( u8g, num_selector_num_font );
    num_font_height = u8g_GetFontAscent( u8g );
    num_font_vsize = num_font_height - u8g_GetFontDescent( u8g );

    u8g_SetFont( u8g, menu_title_font );
    menu_title_font_height = u8g_GetFontAscent( u8g );
    menu_title_font_vsize = menu_title_font_height - u8g_GetFontDescent( u8g );

    u8g_SetFont( u8g, menu_list_font );
    menu_list_font_height = u8g_GetFontAscent( u8g );
    menu_list_font_vsize = menu_list_font_height - u8g_GetFontDescent( u8g );

}
Beispiel #3
0
uint8_t m2_u8g_get_box_icon_size(uint8_t font)
{
    int8_t x;
    u8g_SetFont(m2_u8g, m2_u8g_get_font(font));
    x = u8g_GetFontAscent(m2_u8g)-u8g_GetFontDescent(m2_u8g);
    x*=5;
    x >>=3;
    if ( x < 6 )
      x = 6;
    return x;
}
Beispiel #4
0
// Lua: int = u8g.getFontDescent( self )
static int lu8g_getFontDescent( lua_State *L )
{
    lu8g_userdata_t *lud;

    if ((lud = get_lud( L )) == NULL)
        return 0;

    lua_pushinteger( L, u8g_GetFontDescent( LU8G ) );

    return 1;
}
Beispiel #5
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);
		}
	}
}
Beispiel #6
0
uint8_t m2_u8g_get_font_icon_height(uint8_t font, uint8_t icon)
{
  if ( icon == M2_ICON_TOGGLE_ACTIVE || icon == M2_ICON_TOGGLE_INACTIVE )
  {
    u8g_SetFont(m2_u8g, m2_u8g_toggle_icon_font);
  }
  else if ( icon == M2_ICON_RADIO_ACTIVE || icon == M2_ICON_RADIO_INACTIVE )
  {
    u8g_SetFont(m2_u8g, m2_u8g_radio_icon_font);
  }
  else
  {
    return 0;
  }
  return u8g_GetFontAscent(m2_u8g)-u8g_GetFontDescent(m2_u8g);
}
Beispiel #7
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]);
    }
}