forked from KolibriOS/kolibrios
freetype sample: resize window and font
git-svn-id: svn://kolibrios.org@5025 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
parent
d370c3c94f
commit
9238841fbd
@ -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 );
|
||||
|
||||
|
@ -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();
|
||||
@ -93,16 +98,50 @@ int main(int argc, char *argv[])
|
||||
switch (get_os_event())
|
||||
{
|
||||
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);
|
||||
|
Loading…
Reference in New Issue
Block a user