From 08f70e80b44aa0673d6fde9901566ad3360923f6 Mon Sep 17 00:00:00 2001 From: kraus Date: Sun, 23 Jul 2023 15:55:31 +0200 Subject: [PATCH] issue #2228 --- csrc/u8g2_font.c | 2 +- sys/sdl/issue2228/Makefile | 12 +++++++ sys/sdl/issue2228/main.c | 64 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 77 insertions(+), 1 deletion(-) create mode 100644 sys/sdl/issue2228/Makefile create mode 100644 sys/sdl/issue2228/main.c diff --git a/csrc/u8g2_font.c b/csrc/u8g2_font.c index 18b41fcd..35be0129 100644 --- a/csrc/u8g2_font.c +++ b/csrc/u8g2_font.c @@ -742,7 +742,7 @@ int8_t u8g2_font_2x_decode_glyph(u8g2_t *u8g2, const uint8_t *glyph_data) y1 += 2*h; if ( u8g2_IsIntersection(u8g2, x0, y0, x1, y1) == 0 ) - return d; + return 2*d; } #endif /* U8G2_WITH_INTERSECTION */ diff --git a/sys/sdl/issue2228/Makefile b/sys/sdl/issue2228/Makefile new file mode 100644 index 00000000..2dc1ad96 --- /dev/null +++ b/sys/sdl/issue2228/Makefile @@ -0,0 +1,12 @@ +CFLAGS = -g -Wall -I../../../csrc/. `sdl2-config --cflags` + +SRC = $(shell ls ../../../csrc/*.c) $(shell ls ../common/*.c ) main.c + +OBJ = $(SRC:.c=.o) + +helloworld: $(OBJ) + $(CC) $(CFLAGS) $(LDFLAGS) $(OBJ) `sdl2-config --libs` -o u8g2_sdl + +clean: + -rm $(OBJ) u8g2_sdl + diff --git a/sys/sdl/issue2228/main.c b/sys/sdl/issue2228/main.c new file mode 100644 index 00000000..665f7d76 --- /dev/null +++ b/sys/sdl/issue2228/main.c @@ -0,0 +1,64 @@ + +#include "u8g2.h" +#include +#include + + +char str1[100]; +char str2[100]; + +u8g2_t u8g2; + +int main(void) +{ + int x, y; + int k; + int offset = 100; + + + u8g2_SetupBuffer_SDL_128x64_4(&u8g2, &u8g2_cb_r0); + u8x8_InitDisplay(u8g2_GetU8x8(&u8g2)); + u8x8_SetPowerSave(u8g2_GetU8x8(&u8g2), 0); + + + u8g2_SetFont(&u8g2, u8g2_font_wqy16_t_gb2312); + + x = 4; // use as height for the box + y = 0; + + for(;;) + { + printf("offset=%d\n", offset); + u8g2_FirstPage(&u8g2); + do + { + u8g2_DrawUTF8(&u8g2, offset,30,"123456789QWERTYUIOPASDFGHJKLZXCVBNM123456789QWERTYUIOPASDFGHJKLZXCVBNM"); + u8g2_DrawUTF8X2(&u8g2, offset,60,"123456789QWERTYUIOPASDFGHJKLZXCVBNM123456789QWERTYUIOPASDFGHJKLZXCVBNM"); + } while( u8g2_NextPage(&u8g2) ); + + do + { + k = u8g_sdl_get_key(); + } while( k < 0 ); + + if ( k == 273 ) y -= 1; + if ( k == 274 ) y += 1; + if ( k == 276 ) x -= 1; + if ( k == 275 ) x += 1; + + if ( k == 'e' ) y -= 1; + if ( k == 'x' ) y += 1; + if ( k == 's' ) x -= 1; + if ( k == 'd' ) x += 1; + if ( k == 'q' ) break; + + if ( k == 32 ) + offset -= 1; + + if ( x < 0 ) + x = 0; + + } + return 0; +} +