Ejemplo n.º 1
0
/** Draws text from a character string. */
lcd_error_t lcd_draw_text(const char * text, uint8_t x, uint8_t y, lcd_color_t text_color,
			  const lcd_color_t * p_background_color, const uint8_t * p_font,
			  int8_t char_spacing) {
    uint8_t c;
    uint8_t old_x, char_width;
    uint16_t length = 0;
    uint16_t i;
    const uint8_t * p_text = text;
    /* calculate string length */
    while (*p_text++ != '\0') length++;
    
    if (text == NULL)
	return LCD_ERROR;
    // Load font, if necessary
    if (p_font != lcd_p_font)
	lcd_load_font(p_font);
    
    for (i = 0; i < length; i++) {
	c = (uint8_t) text[i];
	
	if (c == 0x20) {
	    if (p_background_color != NULL)
		lcd_fill_rectangle(x, y, x + lcd_font_header.space_width,
				   y + lcd_font_header.height - 1, * p_background_color);
	    x += lcd_font_header.space_width;
	    continue;
	}
	
	char_width = lcd_get_char_width(c, p_font);
	
	if (char_width == 0) {
	    continue;
	}
	
	lcd_draw_char(c, x, y, text_color, p_background_color, p_font);
	
	x += char_width;
	
	if (x >= LCD_WIDTH)
	    break;
	
	old_x = x;
	x += char_spacing + 1;
	
	if ((p_background_color != NULL) && (i != length - 1))
	    lcd_fill_rectangle(old_x, y, x, y + lcd_font_header.height - 1,
			       *p_background_color);
    }
    
    return LCD_NO_ERROR;
}
Ejemplo n.º 2
0
void lcd_draw_string(uint8_t column, uint8_t page, char *string, uint8_t *buff){
    uint8_t i = 0;
    while(string[0] != 0){
        //column += 6; // 6 pixels wide
        //if (column + 6 >= 128) {
        //  column = 0;    // ran out of this line
        //  page++;
        //}
        //if (page >= 8)
        //  return;        // ran out of space :(
        lcd_draw_char(column+(5*i), page, (string[0]), buff);
        string++;
        i++;
    }
}
Ejemplo n.º 3
0
void console_write(console_t* const console, const char* message) {
	char c;
	
	const lcd_color_t prior_background = lcd_set_background(console->lcd, console->background);
	const lcd_color_t prior_foreground = lcd_set_foreground(console->lcd, console->foreground);

	while( (c = *(message++)) != 0 ) {
		const lcd_glyph_t* const glyph = lcd_get_glyph(console->lcd, c);
		if( (console->x + glyph->advance) > console->lcd->size.w ) {
			console_crlf(console);
		}
		lcd_draw_char(
			console->lcd,
			console->x,
			lcd_scroll_area_y(console->lcd, console->y),
			c
		);
		console->x += glyph->advance;
	}

	lcd_set_background(console->lcd, prior_background);
	lcd_set_foreground(console->lcd, prior_foreground);
}