From 9238841fbdab9fcca2f53f0067b942138ac16b2b Mon Sep 17 00:00:00 2001 From: "Sergey Semyonov (Serge)" Date: Sat, 9 Aug 2014 18:20:25 +0000 Subject: [PATCH] freetype sample: resize window and font git-svn-id: svn://kolibrios.org@5025 a494cfbc-eb01-0410-851d-a64ba20cac60 --- contrib/sdk/samples/freetype/txview/fontlib.c | 7 ++- contrib/sdk/samples/freetype/txview/main.c | 55 ++++++++++++++++--- 2 files changed, 52 insertions(+), 10 deletions(-) diff --git a/contrib/sdk/samples/freetype/txview/fontlib.c b/contrib/sdk/samples/freetype/txview/fontlib.c index dfe8cf2418..6192698ce7 100644 --- a/contrib/sdk/samples/freetype/txview/fontlib.c +++ b/contrib/sdk/samples/freetype/txview/fontlib.c @@ -176,8 +176,11 @@ int init_fontlib() goto done; } - err = FT_New_Face( library, "/kolibrios/Fonts/IstokWeb.ttf", 0, &face ); +// err = FT_New_Face( library, "/kolibrios/Fonts/IstokWeb.ttf", 0, &face ); // err = FT_New_Face( library, "/kolibrios/Fonts/lucon.ttf", 0, &face ); + + err = FT_New_Face( library, "/kolibrios/Fonts/DroidSansMono.ttf", 0, &face ); + if ( err == FT_Err_Unknown_File_Format ) { printf("font format is unsupported\n"); @@ -233,7 +236,7 @@ font_t *create_font(FT_Face xface, int size) memset(font, 0, sizeof(*font)); font->face = (xface == NULL) ? def_face : xface; - font->height = size; + font->height = size+1; err = FT_Set_Pixel_Sizes( font->face, 0, size ); diff --git a/contrib/sdk/samples/freetype/txview/main.c b/contrib/sdk/samples/freetype/txview/main.c index e91a340fbf..57f5a274cd 100644 --- a/contrib/sdk/samples/freetype/txview/main.c +++ b/contrib/sdk/samples/freetype/txview/main.c @@ -40,6 +40,9 @@ typedef struct }tview_t; int init_tview(tview_t *txv, int width, int height, char *text, int size); +void txv_set_size(tview_t *txv, int txw, int txh); +void txv_set_font_size(tview_t *txv, int size); + int txv_scroll_up(tview_t *txv); int txv_scroll_down(tview_t *txv); @@ -49,7 +52,7 @@ int draw_text_ext(bitmap_t *winbitmap, FT_Face face, char *text, int len, rect_t void draw_window(void) { BeginDraw(); - DrawWindow(0,0,0,0,NULL,0,0x74); + DrawWindow(0,0,0,0,NULL,0,0x73); EndDraw(); } @@ -59,6 +62,8 @@ int main(int argc, char *argv[]) { ufile_t uf; oskey_t key; + int clw = 640; + int clh = 480; __asm__ __volatile__( "int $0x40" @@ -75,11 +80,11 @@ int main(int argc, char *argv[]) init_pixlib(0); init_fontlib(); - init_tview(&txv, 480, 600, uf.data, uf.size); + init_tview(&txv, clw, clh, uf.data, uf.size); BeginDraw(); - DrawWindow(10, 40, txv.w+TYPE_3_BORDER_WIDTH*2, - txv.h+TYPE_3_BORDER_WIDTH+get_skin_height(), "Text example", 0x000000, 0x74); + DrawWindow(10, 40, clw+TYPE_3_BORDER_WIDTH*2, + clh+TYPE_3_BORDER_WIDTH+get_skin_height(), "Text example", 0x000000, 0x73); blit_bitmap(&txv.bitmap, TYPE_3_BORDER_WIDTH, get_skin_height(), txv.w, txv.h, 0, 0); EndDraw(); @@ -92,17 +97,51 @@ int main(int argc, char *argv[]) switch (get_os_event()) { - case 1: - draw_window(); - blit_bitmap(&txv.bitmap, TYPE_3_BORDER_WIDTH, get_skin_height(), txv.w, txv.h, 0, 0); - break; + case 1: + { + char proc_info[1024]; + int winx, winy, winw, winh; + int txw, txh; + + get_proc_info(proc_info); + + winx = *(uint32_t*)(proc_info+34); + winy = *(uint32_t*)(proc_info+38); + winw = *(uint32_t*)(proc_info+42)+1; + winh = *(uint32_t*)(proc_info+46)+1; + + txw = winw - TYPE_3_BORDER_WIDTH*2; + txh = winh - TYPE_3_BORDER_WIDTH - get_skin_height(); + + if( (txw != clw) || + (txh != clh) ) + { + txv_set_size(&txv, txw, txh); + clw = txw; + clh = txh; + }; + + draw_window(); + blit_bitmap(&txv.bitmap, TYPE_3_BORDER_WIDTH, get_skin_height(), txv.w, txv.h, 0, 0); + break; + } case 2: key = get_key(); + printf("key %d\n", key.code); switch(key.code) { case 27: return; + case 45: + txv_set_font_size(&txv, txv.font->height-3); + blit_bitmap(&txv.bitmap, TYPE_3_BORDER_WIDTH, get_skin_height(), txv.w, txv.h, 0, 0); + break; + + case 61: + txv_set_font_size(&txv, txv.font->height+1); + blit_bitmap(&txv.bitmap, TYPE_3_BORDER_WIDTH, get_skin_height(), txv.w, txv.h, 0, 0); + break; case 177: if( txv_scroll_up(&txv) ) blit_bitmap(&txv.bitmap, TYPE_3_BORDER_WIDTH, get_skin_height(), txv.w, txv.h, 0, 0);