This commit is contained in:
olikraus 2016-04-27 18:29:18 +02:00
parent 8a6ac4c0f7
commit 7518f8f12e
6 changed files with 173 additions and 6 deletions

View File

@ -214,6 +214,8 @@ struct _u8g2_font_decode_t
uint8_t decode_bit_pos; /* bitpos inside a byte of the compressed data */
uint8_t is_transparent;
uint8_t fg_color;
uint8_t bg_color;
#ifdef U8G2_WITH_FONT_ROTATION
uint8_t dir; /* direction */
#endif
@ -275,7 +277,8 @@ struct u8g2_struct
int8_t font_ref_ascent;
int8_t font_ref_descent;
uint8_t draw_color; /* 0: clear pixel, 1: set pixel */
uint8_t draw_color; /* 0: clear pixel, 1: set pixel, modified and restored by font procedures */
/* draw_color can be used also directly by the user API */
#ifdef U8G2_WITH_HVLINE_COUNT
unsigned long hv_cnt;
@ -405,7 +408,7 @@ void u8g2_DrawHVLine(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, u8g2_uint_t len
void u8g2_DrawHLine(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, u8g2_uint_t len);
void u8g2_DrawVLine(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, u8g2_uint_t len);
void u8g2_DrawPixel(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y);
void u8g2_SetDrawColor(u8g2_t *u8g2, uint8_t color) U8G2_NOINLINE; /* u8g: u8g_SetColorIndex(u8g_t *u8g, uint8_t idx); */
/*==========================================*/

View File

@ -406,7 +406,7 @@ void u8g2_font_decode_len(u8g2_t *u8g2, uint8_t len, uint8_t is_foreground)
/* draw foreground and background (if required) */
if ( is_foreground )
{
u8g2->draw_color = 1; /* Fix me: Must be the glyph color (additional variable) */
u8g2->draw_color = decode->fg_color; /* draw_color will be restored later */
u8g2_DrawHVLine(u8g2,
x,
y,
@ -420,7 +420,7 @@ void u8g2_font_decode_len(u8g2_t *u8g2, uint8_t len, uint8_t is_foreground)
}
else if ( decode->is_transparent == 0 )
{
u8g2->draw_color = 0; /* Fix me: Must be the complement of the glyph color (additional variable) */
u8g2->draw_color = decode->bg_color; /* draw_color will be restored later */
u8g2_DrawHVLine(u8g2,
x,
y,
@ -461,6 +461,10 @@ static void u8g2_font_setup_decode(u8g2_t *u8g2, const uint8_t *glyph_data)
decode->glyph_width = u8g2_font_decode_get_unsigned_bits(decode, u8g2->font_info.bits_per_char_width);
decode->glyph_height = u8g2_font_decode_get_unsigned_bits(decode,u8g2->font_info.bits_per_char_height);
decode->fg_color = u8g2->draw_color;
decode->bg_color = decode->fg_color;
decode->bg_color ^= 1;
}
@ -560,6 +564,9 @@ int8_t u8g2_font_decode_glyph(u8g2_t *u8g2, const uint8_t *glyph_data)
if ( decode->y >= h )
break;
}
/* restore the u8g2 draw color, because this is modified by the decode algo */
u8g2->draw_color = decode->fg_color;
}
return d;
}

View File

@ -233,7 +233,20 @@ void u8g2_DrawPixel(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y)
u8g2_DrawHVLine(u8g2, x, y, 1, 0);
}
/*
Assign the draw color for all drawing functions.
color may be 0 or 1. The actual color is defined by the display.
With color = 1 the drawing function will set the display memory to 1.
For OLEDs this ususally means, that the pixel is enabled and the LED
at the pixel is turned on.
On an LCD it usually means that the LCD segment of the pixel is enabled,
which absorbs the light.
*/
void u8g2_SetDrawColor(u8g2_t *u8g2, uint8_t color)
{
u8g2->draw_color = 0;
if ( color )
u8g2->draw_color = 1;
}

View File

@ -549,6 +549,100 @@ int main(void)
tga_save_png("u8g2_triangle.png");
/*=========================================*/
/* u8g2_color.png */
u8x8_ClearDisplay(u8g2_GetU8x8(&desc));
u8g2_SetFontPosCenter(&u8g2);
u8g2_FirstPage(&u8g2);
do
{
u8g2_uint_t x,y;
u8g2_SetDrawColor(&u8g2, 1);
for( y = 0; y < u8g2_GetDisplayHeight(&u8g2); y++ )
for( x = 0; x < u8g2_GetDisplayWidth(&u8g2); x++ )
if ( (x ^ y) & 1 )
u8g2_DrawPixel(&u8g2, x, y);
u8g2_SetFont(&u8g2, u8g2_font_9x15B_mf);
u8g2_SetDrawColor(&u8g2, 1);
u8g2_DrawStr(&u8g2, 3, 20, "Color = 1");
u8g2_SetDrawColor(&u8g2, 0);
u8g2_DrawStr(&u8g2, 3, 40, "Color = 0");
} while( u8g2_NextPage(&u8g2) );
u8g2_SetDrawColor(&u8g2, 1);
tga_is_transparent = 1;
u8g2_FirstPage(&desc);
do
{
ra(3,20, "x=3, y=20");
ra(3,40, "x=3, y=40");
//vm(62,19-u8g2_GetDescent(&u8g2), -u8g2_GetDescent(&u8g2));
} while( u8g2_NextPage(&desc) );
tga_is_transparent = 0;
u8g2_SetFontPosBaseline(&u8g2);
tga_save_png("u8g2_color.png");
/*=========================================*/
/* u8g2_fontmode.png */
u8x8_ClearDisplay(u8g2_GetU8x8(&desc));
u8g2_SetFontPosCenter(&u8g2);
u8g2_FirstPage(&u8g2);
do
{
u8g2_uint_t x,y;
u8g2_SetDrawColor(&u8g2, 1);
for( y = 0; y < u8g2_GetDisplayHeight(&u8g2); y++ )
for( x = 0; x < u8g2_GetDisplayWidth(&u8g2); x++ )
if ( (x ^ y) & 1 )
u8g2_DrawPixel(&u8g2, x, y);
u8g2_SetFont(&u8g2, u8g2_font_8x13B_mf);
u8g2_SetFontMode(&u8g2, 0);
u8g2_SetDrawColor(&u8g2, 1);
u8g2_DrawStr(&u8g2, 3, 15, "Color=1, Mode 0");
u8g2_SetDrawColor(&u8g2, 0);
u8g2_DrawStr(&u8g2, 3, 30, "Color=0, Mode 0");
u8g2_SetFontMode(&u8g2, 1);
u8g2_SetDrawColor(&u8g2, 1);
u8g2_DrawStr(&u8g2, 3, 45, "Color=1, Mode 1");
u8g2_SetDrawColor(&u8g2, 0);
u8g2_DrawStr(&u8g2, 3, 60, "Color=0, Mode 1");
} while( u8g2_NextPage(&u8g2) );
u8g2_SetDrawColor(&u8g2, 1);
u8g2_SetFontMode(&u8g2, 1);
tga_is_transparent = 1;
u8g2_FirstPage(&desc);
do
{
ra(3,15, "x=3, y=15");
ra(3,30, "x=3, y=30");
ra(3,45, "x=3, y=45");
ra(3,60, "x=3, y=60");
//vm(62,19-u8g2_GetDescent(&u8g2), -u8g2_GetDescent(&u8g2));
} while( u8g2_NextPage(&desc) );
tga_is_transparent = 0;
u8g2_SetFontPosBaseline(&u8g2);
tga_save_png("u8g2_fontmode.png");
/*=========================================*/

View File

@ -0,0 +1,14 @@
CC = gcc
CFLAGS = -g -W -Wall -Wextra -Wcast-qual -Wno-overlength-strings -Wno-unused-parameter -I../../../csrc/.
SRC = $(shell ls ../../../csrc/*.c) $(shell ls ../common/*.c ) main.c
OBJ = $(SRC:.c=.o)
u8g2_utf8: $(OBJ)
$(CC) $(CFLAGS) $(LDFLAGS) $(OBJ) -o u8g2_utf8
clean:
-rm $(OBJ) u8g2_utf8

View File

@ -0,0 +1,36 @@
#include "u8g2.h"
#include <stdio.h>
u8g2_t u8g2;
int main(void)
{
u8g2_SetupBuffer_Utf8(&u8g2, U8G2_R0);
u8g2_InitDisplay(&u8g2);
u8g2_SetPowerSave(&u8g2, 0);
u8g2_SetFont(&u8g2, u8g2_font_6x13_mf);
u8g2_SetFontDirection(&u8g2, 0);
u8g2_FirstPage(&u8g2);
do
{
u8g2.draw_color = 1;
u8g2_DrawBox(&u8g2, 2, 8, 70, 20);
u8g2.draw_color = 0;
u8g2_DrawStr(&u8g2, 10, 14, "Hello World!");
u8g2.draw_color = 0;
u8g2_DrawBox(&u8g2, 9, 15, 31, 2);
} while( u8g2_NextPage(&u8g2) );
utf8_show();
return 0;
}