예제 #1
0
파일: menu.c 프로젝트: basilfx/u8g2
/*
  Name: 	me_cb_0_9
  Val:	uint8_t *
*/
int me_cb_0_9(menu_t *menu, const me_t *me, uint8_t msg)
{  
  switch(msg)
  {
    case ME_MSG_IS_FOCUS:
      return 1;
    case ME_MSG_DRAW_FOCUS:
      u8g2_SetFont(menu->u8g2, MENU_BIG_NUM);
      menu_DrawBoxFocus(menu, 
	  me->x+MENU_BIG_NUM_FOCUS_XO, 
	  me->y - u8g2_GetAscent(menu->u8g2)-1, 
	  u8g2_GetGlyphWidth(menu->u8g2, '0')+MENU_BIG_NUM_FOCUS_EXTRAX, 
	  u8g2_GetAscent(menu->u8g2) + 2);
      return 1;
    case ME_MSG_SELECT:
      {
	uint8_t val = *(uint8_t *)(me->val);
	val++;
	if ( val > 9 )
	  val = 0;
	*(uint8_t *)(me->val) = val;
      }
      return 1;
    case ME_MSG_DRAW:
      u8g2_SetFont(menu->u8g2, MENU_BIG_NUM);
      u8g2_DrawGlyph(menu->u8g2, me->x, me->y, *(uint8_t *)(me->val) + '0');
      return 1;
  }
  return 0;
}
예제 #2
0
u8g2_uint_t u8g2_DrawExtUTF8(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, uint8_t to_left, const uint16_t *kerning_table, const char *str)
{
  u8g2->u8x8.next_cb = u8x8_utf8_next;
  uint16_t e_prev = 0x0ffff;
  uint16_t e;
  u8g2_uint_t delta, sum, k;
  u8x8_utf8_init(u8g2_GetU8x8(u8g2));
  sum = 0;
  for(;;)
  {
    e = u8g2->u8x8.next_cb(u8g2_GetU8x8(u8g2), (uint8_t)*str);
    if ( e == 0x0ffff )
      break;
    str++;
    if ( e != 0x0fffe )
    {
      delta = u8g2_GetGlyphWidth(u8g2, e);
	    
      if ( to_left )
      {
        k = u8g2_GetKerningByTable(u8g2, kerning_table, e, e_prev);
	delta -= k;
	x -= delta;
      }
      else
      {
        k = u8g2_GetKerningByTable(u8g2, kerning_table, e_prev, e);
	delta -= k;
      }
      e_prev = e;

      if ( to_left )
      {
      }
      else
      {
	x += delta;
      }
      u8g2_DrawGlyph(u8g2, x, y, e);
      if ( to_left )
      {
      }
      else
      {
	//x += delta;
	//x -= k;
      }
      
      sum += delta;    
    }
  }
  return sum;
}
예제 #3
0
파일: mapgen.c 프로젝트: basilfx/u8g2
void write_tga_map(const char *filename)
{
  static u8g2_t u8g2;
  int x, y, i;
  unsigned tile;
  if ( map_phase != PHASE_MAPDATA )
    return;
  
  u8x8_tga_info.tile_width = map_width*2;
  u8x8_tga_info.tile_height  = map_height*2;
  u8x8_tga_info.pixel_width = map_width*16;
  u8x8_tga_info.pixel_height  = map_height*16;
  
  u8g2_SetupBuffer_TGA(&u8g2, &u8g2_cb_r0);
  u8x8_InitDisplay(u8g2_GetU8x8(&u8g2));
  u8x8_SetPowerSave(u8g2_GetU8x8(&u8g2), 0);  
  u8g2_SetFont(&u8g2, scrollosprites);
  
  
  u8g2_FirstPage(&u8g2);
  do
  {
    for( y = 0; y < map_height; y++ )
    {
      for( x = 0; x < map_width; x++ )
      {
	tile = map2[y][x];
	/* check if there is a fg_tile, if so, use that tile instead */
	for( i = 0; i < tile_cnt; i++ )
	{
	  if ( tile_list[i].item_index >= 0 )
	  {
	    if ( tile_list[i].ascii == map[y][x] )
	    {
	      tile = item_list[tile_list[i].item_index].fg_tile;
	    }
	  }
	}
	
	u8g2_DrawGlyph(&u8g2, x*16, y*16+16, tile);
      }
    }
    
  } while( u8g2_NextPage(&u8g2) );
    
  tga_save(filename);
  
}
예제 #4
0
파일: menu.c 프로젝트: basilfx/u8g2
int me_cb_0_9_small_ro(menu_t *menu, const me_t *me, uint8_t msg)
{  
  switch(msg)
  {
    case ME_MSG_IS_FOCUS:
      return 0;
    case ME_MSG_DRAW_FOCUS:
      return 1;
    case ME_MSG_SELECT:
      return 1;
    case ME_MSG_DRAW:
      u8g2_SetFont(menu->u8g2, MENU_SMALL_FONT);
      u8g2_DrawGlyph(menu->u8g2, me->x, me->y, *(uint8_t *)(me->val) + '0');
      return 1;
  }
  return 0;
}
예제 #5
0
파일: u8g2_font.c 프로젝트: radiumray/mdxly
static u8g2_uint_t u8g2_draw_string(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, const char *str)
{
  uint16_t e;
  u8g2_uint_t delta, sum;
  u8x8_utf8_init(u8g2_GetU8x8(u8g2));
  sum = 0;
  for(;;)
  {
    e = u8g2->u8x8.next_cb(u8g2_GetU8x8(u8g2), (uint8_t)*str);
    if ( e == 0x0ffff )
      break;
    str++;
    if ( e != 0x0fffe )
    {
      delta = u8g2_DrawGlyph(u8g2, x, y, e);
    
#ifdef U8G2_WITH_FONT_ROTATION
      switch(u8g2->font_decode.dir)
      {
	case 0:
	  x += delta;
	  break;
	case 1:
	  y += delta;
	  break;
	case 2:
	  x -= delta;
	  break;
	case 3:
	  y -= delta;
	  break;
      }
#else
      x += delta;
#endif

      sum += delta;    
    }
  }
  return sum;
}