issue #364, intermediate checkin

This commit is contained in:
kraus 2018-10-27 17:29:10 +02:00
parent bba287cb7f
commit 6398798c26
4 changed files with 125 additions and 52 deletions

View File

@ -130,24 +130,6 @@
#define U8G2_WITH_UNICODE
/*
Internal performance test for the effect of enabling U8G2_WITH_INTERSECTION
Should not be defined for production code
*/
//#define U8G2_WITH_HVLINE_COUNT
/*
Defining the following variable adds the clipping and check procedures agains the display boundaries.
Clipping procedures are mandatory for the picture loop (u8g2_FirstPage/NextPage).
Clipping procedures will also allow strings to exceed the display boundaries.
On the other side, without clipping, all the setting of pixels must happen within the display boundaries.
WARNING: Adding a comment in front of the following macro or removing the following line
may lead to memory faults if you write any pixel outside the display boundary.
*/
#define U8G2_WITH_CLIPPING
/*==========================================*/
@ -341,10 +323,6 @@ struct u8g2_struct
// the following variable should be renamed to is_buffer_auto_clear
uint8_t is_auto_page_clear; /* set to 0 to disable automatic clear of the buffer in firstPage() and nextPage() */
#ifdef U8G2_WITH_HVLINE_COUNT
unsigned long hv_cnt;
#endif /* U8G2_WITH_HVLINE_COUNT */
// removed, there is now the new index table
//#ifdef __unix__
// uint16_t last_unicode;

View File

@ -47,8 +47,6 @@
#ifdef U8G2_WITH_CLIPPING
/*
Description:
clip range from a (included) to b (excluded) agains c (included) to d (excluded)
@ -112,11 +110,14 @@ static uint8_t u8g2_clip_intersection(u8g2_uint_t *ap, u8g2_uint_t *bp, u8g2_uin
will clip the line and call u8g2_draw_low_level_hv_line()
*/
static void u8g2_draw_hv_line_2dir(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, u8g2_uint_t len, uint8_t dir)
void u8g2_draw_hv_line_2dir(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, u8g2_uint_t len, uint8_t dir)
{
u8g2_uint_t a;
register u8g2_uint_t w, h;
/* transform to pixel buffer coordinates */
y -= u8g2->tile_curr_row*8;
h = u8g2->pixel_buf_height; // this must be the real buffer height
w = u8g2->pixel_buf_width; // this could be replaced by u8g2->u8x8.display_info->pixel_width
@ -147,8 +148,6 @@ static void u8g2_draw_hv_line_2dir(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, u
u8g2->ll_hvline(u8g2, x, y, len, dir);
}
#endif
/*
x,y Upper left position of the line (full screen coordinates)
len length of the line in pixel, len must not be 0
@ -162,12 +161,6 @@ static void u8g2_draw_hv_line_2dir(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, u
*/
void u8g2_draw_hv_line_4dir(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, u8g2_uint_t len, uint8_t dir)
{
#ifdef U8G2_WITH_HVLINE_COUNT
u8g2->hv_cnt++;
#endif /* U8G2_WITH_HVLINE_COUNT */
/* transform to pixel buffer coordinates */
y -= u8g2->tile_curr_row*8;
/* additional optimization for one pixel draw */
/* requires about 60 bytes on the ATMega flash memory */
@ -175,6 +168,8 @@ void u8g2_draw_hv_line_4dir(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, u8g2_uin
#ifdef U8G2_WITH_ONE_PIXEL_OPTIMIZATION
if ( len == 1 )
{
/* transform to pixel buffer coordinates */
y -= u8g2->tile_curr_row*8;
if ( x < u8g2->pixel_buf_width && y < u8g2->pixel_buf_height )
u8g2->ll_hvline(u8g2, x, y, len, dir);
return;
@ -192,16 +187,14 @@ void u8g2_draw_hv_line_4dir(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, u8g2_uin
y++;
}
dir &= 1;
#ifdef U8G2_WITH_CLIPPING
u8g2_draw_hv_line_2dir(u8g2, x, y, len, dir);
#else
u8g2->ll_hvline(u8g2, x, y, len, dir);
#endif
}
/*
This is the toplevel function for the hv line draw procedures.
This function should be called by the user.
"dir" may have 4 directions: 0 (left to right), 1, 2, 3 (down up)
*/
void u8g2_DrawHVLine(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, u8g2_uint_t len, uint8_t dir)
{
@ -209,7 +202,25 @@ void u8g2_DrawHVLine(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, u8g2_uint_t len
/* The callback may rotate the hv line */
/* after rotation this will call u8g2_draw_hv_line_4dir() */
if ( len != 0 )
{
/* convert to dir2 */
if ( len > 1 )
{
if ( dir == 2 )
{
x -= len;
x++;
}
else if ( dir == 3 )
{
y -= len;
y++;
}
}
dir &= 1;
u8g2->cb->draw_l90(u8g2, x, y, len, dir);
}
}
void u8g2_DrawHLine(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, u8g2_uint_t len)

View File

@ -35,6 +35,8 @@
#include "u8g2.h"
#include <string.h>
#include <assert.h>
/*============================================*/
/*
@ -206,12 +208,15 @@ void u8g2_update_dimension_r3(u8g2_t *u8g2)
}
/*============================================*/
extern void u8g2_draw_hv_line_4dir(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, u8g2_uint_t len, uint8_t dir);
extern void u8g2_draw_hv_line_2dir(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, u8g2_uint_t len, uint8_t dir);
void u8g2_draw_l90_r0(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, u8g2_uint_t len, uint8_t dir)
{
u8g2_draw_hv_line_4dir(u8g2, x, y, len, dir);
#ifdef __unix
assert( dir <= 1 );
#endif
u8g2_draw_hv_line_2dir(u8g2, x, y, len, dir);
}
void u8g2_draw_l90_mirrorr_r0(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, u8g2_uint_t len, uint8_t dir)
@ -227,14 +232,17 @@ void u8g2_draw_l90_mirrorr_r0(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, u8g2_u
{
xx--;
}
u8g2_draw_hv_line_4dir(u8g2, xx, y, len, dir);
u8g2_draw_hv_line_2dir(u8g2, xx, y, len, dir);
}
/* dir = 0 or 1 */
void u8g2_draw_l90_r1(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, u8g2_uint_t len, uint8_t dir)
{
u8g2_uint_t xx, yy;
#ifdef __unix
assert( dir <= 1 );
#endif
yy = x;
@ -243,14 +251,21 @@ void u8g2_draw_l90_r1(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, u8g2_uint_t le
xx--;
dir ++;
dir &= 3;
u8g2_draw_hv_line_4dir(u8g2, xx, yy, len, dir);
if ( dir == 2 )
{
xx -= len;
xx++;
dir = 0;
}
u8g2_draw_hv_line_2dir(u8g2, xx, yy, len, dir);
}
void u8g2_draw_l90_r2(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, u8g2_uint_t len, uint8_t dir)
{
u8g2_uint_t xx, yy;
/*
yy = u8g2->height;
yy -= y;
yy--;
@ -259,9 +274,36 @@ void u8g2_draw_l90_r2(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, u8g2_uint_t le
xx -= x;
xx--;
dir +=2;
dir &= 3;
u8g2_draw_hv_line_4dir(u8g2, xx, yy, len, dir);
if ( dir == 0 )
{
xx -= len;
xx++;
}
else if ( dir == 1 )
{
yy -= len;
yy++;
}
*/
yy = u8g2->height;
yy -= y;
xx = u8g2->width;
xx -= x;
if ( dir == 0 )
{
yy--;
xx -= len;
}
else if ( dir == 1 )
{
xx--;
yy -= len;
}
u8g2_draw_hv_line_2dir(u8g2, xx, yy, len, dir);
}
void u8g2_draw_l90_r3(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, u8g2_uint_t len, uint8_t dir)
@ -272,11 +314,22 @@ void u8g2_draw_l90_r3(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, u8g2_uint_t le
yy = u8g2->width;
yy -= x;
yy--;
dir +=3;
dir &= 3;
u8g2_draw_hv_line_4dir(u8g2, xx, yy, len, dir);
if ( dir == 0 )
{
yy--;
yy -= len;
yy++;
dir = 1;
}
else
{
yy--;
dir = 0;
}
u8g2_draw_hv_line_2dir(u8g2, xx, yy, len, dir);
}

View File

@ -18,11 +18,23 @@ u8g2_t u8g2;
void draw(void)
{
u8g2_SetFont(&u8g2, u8g2_font_ncenB24_tf);
u8g2_DrawHLine(&u8g2, u8g2_GetDisplayWidth(&u8g2)-1, 2, 4);
u8g2_SetFontDirection(&u8g2, 0);
u8g2_DrawStr(&u8g2, -4, 20, "Clip/////");
u8g2_DrawStr(&u8g2, -5, 50, "Clip/////");
u8g2_DrawStr(&u8g2, -6, 80, "Clip/////");
u8g2_DrawStr(&u8g2, -6, 110, "Clip/////");
u8g2_SetFontDirection(&u8g2, 0);
u8g2_SetFont(&u8g2, u8g2_font_ncenB12_tf);
u8g2_DrawStr(&u8g2, 40, 40, "F");
u8g2_SetFontDirection(&u8g2, 1);
u8g2_DrawStr(&u8g2, 40, 40, "F");
u8g2_SetFontDirection(&u8g2, 2);
u8g2_DrawStr(&u8g2, 40, 40, "F");
u8g2_SetFontDirection(&u8g2, 3);
u8g2_DrawStr(&u8g2, 40, 40, "F");
}
int main(void)
@ -34,7 +46,6 @@ int main(void)
u8g2_InitDisplay(&u8g2);
u8g2_SetPowerSave(&u8g2, 0);
u8g2_SetFont(&u8g2, u8g2_font_ncenB24_tf);
u8g2_SetFontDirection(&u8g2, 0);
u8g2_SetDisplayRotation(&u8g2, U8G2_R0);
@ -44,6 +55,9 @@ int main(void)
draw();
} while( u8g2_NextPage(&u8g2) );
puts("=======================================");
utf8_show();
u8g2_SetDisplayRotation(&u8g2, U8G2_R1);
u8g2_FirstPage(&u8g2);
do
@ -51,12 +65,18 @@ int main(void)
draw();
} while( u8g2_NextPage(&u8g2) );
puts("=======================================");
utf8_show();
u8g2_SetDisplayRotation(&u8g2, U8G2_R2);
u8g2_FirstPage(&u8g2);
do
{
draw();
} while( u8g2_NextPage(&u8g2) );
puts("=======================================");
utf8_show();
u8g2_SetDisplayRotation(&u8g2, U8G2_R3);
u8g2_FirstPage(&u8g2);
@ -65,6 +85,17 @@ int main(void)
draw();
} while( u8g2_NextPage(&u8g2) );
puts("=======================================");
utf8_show();
u8g2_SetDisplayRotation(&u8g2, U8G2_MIRROR);
u8g2_FirstPage(&u8g2);
do
{
draw();
} while( u8g2_NextPage(&u8g2) );
puts("=======================================");
utf8_show();
printf("DisplayWidth = %d\n", u8g2_GetDisplayWidth(&u8g2));