Esempio n. 1
0
/*
  Description:
    Draw a line with "cnt" pixel as fore- or background color.
  Args:
    cnt: 					Length of the line
    is_foreground			foreground/background?
    ucg->font_decode.target_x		X position
    ucg->font_decode.target_y		Y position
    ucg->font_decode.is_transparent	Transparent mode
  Return:
    -
  Calls:
    ucg_font_decode_draw_pixel()
  Called by:
    ucg_font_decode_len()
*/
void ICACHE_FLASH_ATTR ucg_font_decode_draw_pixel(ucg_t *ucg, uint8_t lx, uint8_t ly, uint8_t cnt, uint8_t is_foreground)
{
  ucg_int_t x, y;
  ucg_font_decode_t *decode = &(ucg->font_decode);
  
  x = decode->target_x;
  y = decode->target_y;

  x = ucg_add_vector_x(x, lx, ly, decode->dir);
  y = ucg_add_vector_y(y, lx, ly, decode->dir);
  
  //ucg_add_vector(&x, &y, ucg->font_decode.x, ucg->font_decode.y, ucg->font_decode.dir);

  if ( is_foreground )
  {
    ucg_Draw90Line(ucg, 
      x, 
      y, 
      cnt, 
      /* dir */ decode->dir, 
      /* col_idx */ 0);   
  }
  else if ( decode->is_transparent == 0 )    
  {
    ucg_Draw90Line(ucg, 
      x, 
      y, 
      cnt, 
      /* dir */ decode->dir, 
      /* col_idx */ 1);   
  }
}
Esempio n. 2
0
// Lua: ucg.draw90Line( self, x, y, len, dir, col_idx )
static int lucg_draw90Line( lua_State *L )
{
    lucg_userdata_t *lud;

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

    ucg_int_t args[5];
    lucg_get_int_args( L, 2, 5, args );

    ucg_Draw90Line( LUCG, args[0], args[1], args[2], args[3], args[4] );

    return 0;
}
Esempio n. 3
0
void ucg_DrawHRLine(ucg_t *ucg, ucg_int_t x, ucg_int_t y, ucg_int_t len)
{
  ucg_Draw90Line(ucg, x, y, len, 2, 0);
}
Esempio n. 4
0
ucg_int_t ucg_draw_solid_glyph(ucg_t *ucg, ucg_int_t x, ucg_int_t y, uint8_t dir, uint8_t encoding)
{
  const ucg_pgm_uint8_t *data;
  uint8_t j;
  ucg_int_t dx, dy;
  uint8_t bytes_per_line;
  ucg_int_t above;
  ucg_int_t below;
  ucg_int_t right;
  ucg_int_t left;

  {
    ucg_glyph_t g = ucg_GetGlyph(ucg, encoding);
    if ( g == NULL  )
      return 0;
    data = ucg_font_GetGlyphDataStart(ucg->font, g);
  }
  
  above = ucg->font_ref_ascent;
  above -= ucg->glyph_height;
  above -= ucg->glyph_y;
  if ( above < 0 )
    above = 0;
  
  below = ucg->font_ref_descent; 
  below -= ucg->glyph_y;
  if ( below > 0 )
    below = 0;
  
  right = ucg->glyph_dx;
  right -= ucg->glyph_width;
  right -= ucg->glyph_x;
  if ( right < 0 )
    right = 0;
  
  left = ucg->glyph_x;
  if ( left < 0 )
    left = 0;
  
  bytes_per_line = ucg->glyph_width;
  bytes_per_line += 7;
  bytes_per_line /= 8;
    
  dx = 0;
  dy = 0;
  switch(dir)
  {
    case 0:
      x += ucg->glyph_x;
      y -= ucg->glyph_y;
      y -= ucg->glyph_height;
      y -= above;		/* solid */
      dy = 1;
      break;
    case 1:
      x += ucg->glyph_y;
      y += ucg->glyph_x;
      x += ucg->glyph_height;
      x += above;		/* solid */
      dx = -1;
      break;
    case 2:
      x -= ucg->glyph_x;
      y += ucg->glyph_y;
      y += ucg->glyph_height;
      y += above;		/* solid */
      dy = -1;
      break;
    case 3:
      x -= ucg->glyph_y;
      y -= ucg->glyph_x;
      x -= ucg->glyph_height;
      x -= above;		/* solid */
      dx = 1;
      break;
  }

  while( above > 0 )
  {
    ucg_Draw90Line(ucg, x, y, ucg->glyph_width, dir, 1);
    y+=dy;
    x+=dx;
    above--;
  }
  for( j = 0; j < ucg->glyph_height; j++ )
  {
    ucg_DrawBitmapLine(ucg, x, y, dir, ucg->glyph_width, data);
    data += bytes_per_line;
    y+=dy;
    x+=dx;
  }
  while( below < 0 )
  {
    ucg_Draw90Line(ucg, x, y, ucg->glyph_width, dir, 1);
    y+=dy;
    x+=dx;
    below++;
  }
  y-=dy;
  x-=dx;
  
  for( j = 0; j < left; j++ )
  {
    x-=dy;
    y-=dx;
    ucg_Draw90Line(ucg, x, y, ucg->font_ref_ascent-ucg->font_ref_descent, (dir+3)&3, 1);
  }
  x+=dy*(ucg->glyph_width+left);
  y+=dx*(ucg->glyph_width+left);      
  while( right > 0 )
  {
    ucg_Draw90Line(ucg, x, y, ucg->font_ref_ascent-ucg->font_ref_descent, (dir+3)&3, 1);
    x+=dy;
    y+=dx;
    right--;
  }
  
  return ucg->glyph_dx;
}
Esempio n. 5
0
/* optimized */
void ICACHE_FLASH_ATTR ucg_font_decode_len(ucg_t *ucg, uint8_t len, uint8_t is_foreground)
{
  uint8_t cnt;	/* total number of remaining pixels, which have to be drawn */
  uint8_t rem; 	/* remaining pixel to the right edge of the glyph */
  uint8_t current;	/* number of pixels, which need to be drawn for the draw procedure */
    /* current is either equal to cnt or equal to rem */
  
  /* local coordinates of the glyph */
  uint8_t lx,ly;
  
  /* target position on the screen */
  ucg_int_t x, y;
  
  ucg_font_decode_t *decode = &(ucg->font_decode);
  
  cnt = len;
  
  /* get the local position */
  lx = decode->x;
  ly = decode->y;
  
  for(;;)
  {
    /* calculate the number of pixel to the right edge of the glyph */
    rem = decode->glyph_width;
    rem -= lx;
    
    /* calculate how many pixel to draw. This is either to the right edge */
    /* or lesser, if not enough pixel are left */
    current = rem;
    if ( cnt < rem )
      current = cnt;
    
    
    /* now draw the line, but apply the rotation around the glyph target position */
    //ucg_font_decode_draw_pixel(ucg, lx,ly,current, is_foreground);

    /* get target position */
    x = decode->target_x;
    y = decode->target_y;

    /* apply rotation */
    x = ucg_add_vector_x(x, lx, ly, decode->dir);
    y = ucg_add_vector_y(y, lx, ly, decode->dir);
    
    /* draw foreground and background (if required) */
    if ( is_foreground )
    {
      ucg_Draw90Line(ucg, 
	x, 
	y, 
	current, 
	/* dir */ decode->dir, 
	/* col_idx */ 0);   
    }
    else if ( decode->is_transparent == 0 )    
    {
      ucg_Draw90Line(ucg, 
	x, 
	y, 
	current, 
	/* dir */ decode->dir, 
	/* col_idx */ 1);   
    }
    
    /* check, whether the end of the run length code has been reached */
    if ( cnt < rem )
      break;
    cnt -= rem;
    lx = 0;
    ly++;
  }
  //ucg_font_decode_draw_pixel(ucg, x,y, cnt, is_foreground);
  lx += cnt;
  
  decode->x = lx;
  decode->y = ly;
  
}