예제 #1
0
파일: main.c 프로젝트: 88kacper8/u8glib
// 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;
}
예제 #2
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));
}
예제 #3
0
파일: u8g.c 프로젝트: rudg/nodemcu-firmware
// Lua: width = u8g.getWidth( self )
static int lu8g_getWidth( lua_State *L )
{
    lu8g_userdata_t *lud;

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

    lua_pushinteger( L, u8g_GetWidth( LU8G ) );

    return 1;
}
예제 #4
0
파일: menu.c 프로젝트: hwstar/FW-AC-Emeter
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);
		}
	}
}
예제 #5
0
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);
	  
      }
}
예제 #6
0
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);
	  
      }
}
예제 #7
0
파일: menu.c 프로젝트: 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]);
    }
}
예제 #8
0
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);
  }
}
예제 #9
0
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);
}