Ejemplo n.º 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));
}
Ejemplo n.º 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 );

}
Ejemplo n.º 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;
}
Ejemplo n.º 4
0
// Lua: int = u8g.getFontAscent( self )
static int lu8g_getFontAscent( lua_State *L )
{
    lu8g_userdata_t *lud;

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

    lua_pushinteger( L, u8g_GetFontAscent( LU8G ) );

    return 1;
}
Ejemplo n.º 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);
		}
	}
}
Ejemplo n.º 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);
}
Ejemplo n.º 7
0
Archivo: menu.c Proyecto: gnkarn/u8glib
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]);
    }
}
Ejemplo n.º 8
0
ICACHE_FLASH_ATTR
static void draw_normal(DrawingState *state) {
    uint8_t buf[50];
    u8g_SetColorIndex(&(state->u8g), 1);

    drawingRefreshIcons(state);

    uint8_t iconWidth = 40;
    //current measured temperature
    u8g_SetFont(&(state->u8g), u8g_font_helvB18);
    u8g_SetFontPosTop(&(state->u8g));
    os_sprintf(buf, "%d", state->currentTemp / 100);
    uint8_t currentTempWidth = u8g_GetStrWidth(&(state->u8g), buf);
    uint8_t cWidth = u8g_GetStrWidth(&(state->u8g), "C");
    uint8_t strHeight = u8g_GetFontAscent(&(state->u8g));

    u8g_SetFont(&(state->u8g), u8g_font_helvR08);
    u8g_SetFontPosBaseline(&(state->u8g));
    os_sprintf(buf, "%02d", abs(state->currentTemp % 100));
    uint8_t webTempWidth = u8g_GetStrWidth(&(state->u8g), buf);
    u8g_DrawStr(&(state->u8g),
                iconWidth + (128 - iconWidth) / 2 - (currentTempWidth + cWidth + webTempWidth) / 2 + currentTempWidth,
                16 + strHeight, buf);

    u8g_SetFont(&(state->u8g), u8g_font_helvB18);
    u8g_SetFontPosTop(&(state->u8g));
    os_sprintf(buf, "%d", state->currentTemp / 100);
    u8g_DrawStr(&(state->u8g), iconWidth + (128 - iconWidth) / 2 - (currentTempWidth + cWidth + webTempWidth) / 2, 16,
                buf);
    u8g_DrawStr(&(state->u8g),
                iconWidth + (128 - iconWidth) / 2 - (currentTempWidth + cWidth + webTempWidth) / 2 + currentTempWidth +
                webTempWidth, 16, "C");

    //web text
    if (state->weather.code != 255) {
        u8g_SetFont(&(state->u8g), u8g_font_6x10);
        u8g_SetFontPosBottom(&(state->u8g));
        os_sprintf(buf, "%s", state->weather.text);
        currentTempWidth = u8g_GetStrWidth(&(state->u8g), buf);
        strHeight = u8g_GetFontBBXHeight(&(state->u8g));
        u8g_DrawStr(&(state->u8g), iconWidth + (128 - iconWidth) / 2 - currentTempWidth / 2, 64, buf);
    }

    //web temperature
    u8g_SetFont(&(state->u8g), u8g_font_6x10);
    u8g_SetFontPosBottom(&(state->u8g));
    os_sprintf(buf, "%dC", state->weather.temp);
    uint8_t outsideTempWidth = u8g_GetStrWidth(&(state->u8g), buf);
    u8g_DrawStr(&(state->u8g), iconWidth + (128 - iconWidth) / 2 - outsideTempWidth / 2, 64 - strHeight, buf);

    u8g_SetFont(&(state->u8g), u8g_font_6x10);
    u8g_SetFontPosCenter(&(state->u8g));

    if (state->temperatureMode == MANUAL) {
        os_sprintf(buf, "Manual: %d.%02dC", state->manualTemp / 100, abs(state->manualTemp % 100));
    } else if (state->temperatureMode == AUTOMATIC) {
        if (state->automaticTempCurrentState == NULL) {
            os_sprintf(buf, "Auto");
        } else {
            os_sprintf(buf, "A:%d.%02dC, %d:%02d", state->automaticTempCurrentState->temp / 100,
                       abs(state->automaticTempCurrentState->temp % 100),
                       state->automaticTempCurrentState->time / 60, state->automaticTempCurrentState->time % 60);
        }
    }

    u8g_DrawStr(&(state->u8g), 0, 8, buf);

}