diff --git a/csrc/u8g2.h b/csrc/u8g2.h index bf34f47e..4cef2332 100644 --- a/csrc/u8g2.h +++ b/csrc/u8g2.h @@ -256,10 +256,12 @@ struct u8g2_struct u8g2_uint_t height; /* ths is the clip box for the user to check if a specific box has an intersection */ + /* use u8g2_IsIntersection from u8g2_intersection.c to test against this intersection */ + /* boundary values are part of the box so that they can be used with u8g2_IsIntersection */ u8g2_uint_t user_x0; /* left corner of the buffer */ - u8g2_uint_t user_x1; /* right corner of the buffer (excluded) */ - u8g2_uint_t user_y0; - u8g2_uint_t user_y1; + u8g2_uint_t user_x1; /* right corner of the buffer (included) */ + u8g2_uint_t user_y0; /* upper edge of the buffer */ + u8g2_uint_t user_y1; /* lower edge of the buffer (included) */ /* information about the current font */ const uint8_t *font; /* current font for all text procedures */ @@ -393,7 +395,11 @@ void u8g2_ll_hvline_horizontal_right_lsb(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_ /*==========================================*/ /* u8g2_hvline.c */ + +/* u8g2_DrawHVLine does not use u8g2_IsIntersection */ void u8g2_DrawHVLine(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, u8g2_uint_t len, uint8_t dir); + +/* the following three function will do an intersection test of this is enabled with U8G2_WITH_INTERSECTION */ 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); diff --git a/csrc/u8g2_hvline.c b/csrc/u8g2_hvline.c index 630026cc..a1a18e90 100644 --- a/csrc/u8g2_hvline.c +++ b/csrc/u8g2_hvline.c @@ -202,16 +202,34 @@ 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) { +#ifdef U8G2_WITH_INTERSECTION + if ( u8g2_IsIntersection(u8g2, x, y, x+len-1, y) == 0 ) + return; +#endif /* U8G2_WITH_INTERSECTION */ u8g2_DrawHVLine(u8g2, x, y, len, 0); } void u8g2_DrawVLine(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, u8g2_uint_t len) { +#ifdef U8G2_WITH_INTERSECTION + if ( u8g2_IsIntersection(u8g2, x, y, x, y+len-1) == 0 ) + return; +#endif /* U8G2_WITH_INTERSECTION */ u8g2_DrawHVLine(u8g2, x, y, len, 1); } void u8g2_DrawPixel(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y) { +#ifdef U8G2_WITH_INTERSECTION + if ( x < u8g2->user_x0 ) + return; + if ( x > u8g2->user_x1 ) + return; + if ( y < u8g2->user_y0 ) + return; + if ( y > u8g2->user_y1 ) + return; +#endif /* U8G2_WITH_INTERSECTION */ u8g2_DrawHVLine(u8g2, x, y, 1, 0); } diff --git a/csrc/u8g2_intersection.c b/csrc/u8g2_intersection.c index e937e5d9..04dcea42 100644 --- a/csrc/u8g2_intersection.c +++ b/csrc/u8g2_intersection.c @@ -61,7 +61,7 @@ /* calculate the intersection between a0/a1 and v0/v1 The intersection check returns one if the range of a0/a1 has an intersection with v0/v1. - The intersection check includes the boundary values a0 and a1. + The intersection check includes the boundary values v1 and a1. The following asserts will succeed: assert( u8g2_is_intersection_decision_tree(4, 6, 7, 9) == 0 ); diff --git a/csrc/u8g2_setup.c b/csrc/u8g2_setup.c index 85879dea..5b3ac7bc 100644 --- a/csrc/u8g2_setup.c +++ b/csrc/u8g2_setup.c @@ -63,9 +63,9 @@ void u8g2_SetupBuffer(u8g2_t *u8g2, uint8_t *buf, uint8_t tile_buf_height, u8g2_ update dimension: calculate the following variables: u8g2_uint_t buf_x0; left corner of the buffer - u8g2_uint_t buf_x1; right corner of the buffer (excluded) + u8g2_uint_t buf_x1; right corner of the buffer (included) u8g2_uint_t buf_y0; - u8g2_uint_t buf_y1; + u8g2_uint_t buf_y1; */ static void u8g2_update_dimension_common(u8g2_t *u8g2) @@ -108,6 +108,9 @@ void u8g2_update_dimension_r0(u8g2_t *u8g2) u8g2->user_y0 = u8g2->buf_y0; u8g2->user_y1 = u8g2->buf_y1; + u8g2->user_x1--; + u8g2->user_y1--; + // printf("x0=%d x1=%d y0=%d y1=%d\n", // u8g2->user_x0, u8g2->user_x1, u8g2->user_y0, u8g2->user_y1); } @@ -125,6 +128,9 @@ void u8g2_update_dimension_r1(u8g2_t *u8g2) u8g2->user_y0 = 0; u8g2->user_y1 = u8g2->pixel_buf_width; + u8g2->user_x1--; + u8g2->user_y1--; + // printf("x0=%d x1=%d y0=%d y1=%d\n", // u8g2->user_x0, u8g2->user_x1, u8g2->user_y0, u8g2->user_y1); } @@ -138,6 +144,9 @@ void u8g2_update_dimension_r2(u8g2_t *u8g2) u8g2->user_y0 = u8g2->height - u8g2->buf_y1; u8g2->user_y1 = u8g2->height - u8g2->buf_y0; + + u8g2->user_x1--; + u8g2->user_y1--; // printf("x0=%d x1=%d y0=%d y1=%d\n", // u8g2->user_x0, u8g2->user_x1, u8g2->user_y0, u8g2->user_y1); @@ -155,6 +164,9 @@ void u8g2_update_dimension_r3(u8g2_t *u8g2) u8g2->user_y0 = 0; u8g2->user_y1 = u8g2->pixel_buf_width; + + u8g2->user_x1--; + u8g2->user_y1--; // printf("x0=%d x1=%d y0=%d y1=%d\n", // u8g2->user_x0, u8g2->user_x1, u8g2->user_y0, u8g2->user_y1); diff --git a/sys/utf8/common/u8x8_d_utf8.c b/sys/utf8/common/u8x8_d_utf8.c index a1d3a761..cc6a4b21 100644 --- a/sys/utf8/common/u8x8_d_utf8.c +++ b/sys/utf8/common/u8x8_d_utf8.c @@ -82,13 +82,13 @@ void chgr_show(void) unsigned x, y; for( y = 0; y < CHGR_HEIGHT/2; y++) { - printf("%02d ", y*2); + printf("%02d|", y*2); for( x = 0; x < CHGR_WIDTH/2; x++) { //printf("%x", chgr_bitmap[y][x]); printf("%s", chgr_to_str(chgr_bitmap[y][x])); } - printf("\n"); + printf("|\n"); } } diff --git a/sys/utf8/intersection_picture_loop/Makefile b/sys/utf8/intersection_picture_loop/Makefile new file mode 100644 index 00000000..00ef8ae8 --- /dev/null +++ b/sys/utf8/intersection_picture_loop/Makefile @@ -0,0 +1,14 @@ +CC = gcc + +CFLAGS = -g -Wall -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 + diff --git a/sys/utf8/intersection_picture_loop/main.c b/sys/utf8/intersection_picture_loop/main.c new file mode 100644 index 00000000..575cb2d8 --- /dev/null +++ b/sys/utf8/intersection_picture_loop/main.c @@ -0,0 +1,48 @@ + +#include "u8g2.h" +#include + + + +u8g2_t u8g2; + +int main(void) +{ + int y; + + u8g2_SetupBuffer_Utf8(&u8g2, &u8g2_cb_r0); + u8x8_InitDisplay(u8g2_GetU8x8(&u8g2)); + u8x8_SetPowerSave(u8g2_GetU8x8(&u8g2), 0); + + u8g2_SetFont(&u8g2, u8g2_font_5x7_tr); + u8g2_SetFontDirection(&u8g2, 0); + + +#ifdef U8G2_WITH_HVLINE_COUNT + u8g2.hv_cnt = 0UL; +#endif /* U8G2_WITH_HVLINE_COUNT */ + + + u8g2_FirstPage(&u8g2); + do + { + for( y = 3; y < 21; y++ ) + { + u8g2_DrawHLine(&u8g2, 3, y, 11); + } + + u8g2_DrawStr(&u8g2, 17, 8, "Test Inter-"); + u8g2_DrawStr(&u8g2, 17, 16, "section:"); + u8g2_DrawStr(&u8g2, 17, 24, "One Block"); + + + } while( u8g2_NextPage(&u8g2) ); +#ifdef U8G2_WITH_HVLINE_COUNT + printf("hv cnt: %ld\n", u8g2.hv_cnt); +#endif /* U8G2_WITH_HVLINE_COUNT */ + + utf8_show(); + + return 0; +} +