Subversion Repositories Kolibri OS

Compare Revisions

Regard whitespace Rev 6864 → Rev 6865

/contrib/sdk/samples/freetype/txview/main.c
1,3 → 1,4
 
#include <stdio.h>
#include <string.h>
#include <ft2build.h>
4,50 → 5,32
#include FT_FREETYPE_H
#include FT_GLYPH_H
#include <kos32sys.h>
#include <pixlib2.h>
 
typedef struct
{
int l;
int t;
int r;
int b;
}rect_t;
#include "winlib.h"
 
typedef struct
{
FT_Face face;
int height;
int base;
 
FT_Glyph glyph[256];
typedef struct tview *tview_t;
 
}font_t;
tview_t *create_tview(ctx_t *ctx, int width, int height);
void txv_get_margins(const tview_t *txv, rect_t *margins);
void txv_set_margins(tview_t *txv, const rect_t *margins);
void txv_set_size(tview_t *txv, int txw, int txh);
void txv_set_font_size(tview_t *txv, int size);
int txv_get_font_size(tview_t *txv);
void txv_set_text(tview_t *txv, char *text, int size);
int txv_scroll_up(tview_t *txv);
int txv_scroll_down(tview_t *txv);
int txv_page_up(tview_t *txv);
int txv_page_down(tview_t *txv);
 
typedef struct
{
bitmap_t bitmap;
font_t *font;
volatile int lock;
unsigned int handle;
}mutex_t;
 
char *text;
char **line;
int lines;
int txlines;
int startline;
int endline;
int w;
int h;
}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);
 
void* init_fontlib();
int draw_text_ext(bitmap_t *winbitmap, FT_Face face, char *text, int len, rect_t *rc, int color);
 
void draw_window(void)
{
56,15 → 39,21
EndDraw();
}
 
tview_t txv;
tview_t *txv;
 
 
 
int main(int argc, char *argv[])
{
ufile_t uf;
oskey_t key;
ctx_t *ctx;
rect_t margins = {4,2,20,0};
 
int clw = 640;
int clh = 480;
 
 
__asm__ __volatile__(
"int $0x40"
::"a"(40), "b"(0xc0000027));
77,16 → 66,18
uf.size == 0)
return 0;
 
init_pixlib(0);
ctx = create_context(TYPE_3_BORDER_WIDTH, get_skin_height(), clw, clh);
 
init_fontlib();
 
init_tview(&txv, clw, clh, uf.data, uf.size);
txv = create_tview(ctx, clw, clh);
txv_set_margins(txv, &margins);
txv_set_text(txv, uf.data, uf.size);
 
BeginDraw();
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);
 
show_context(ctx);
EndDraw();
 
for (;;)
102,8 → 93,14
char proc_info[1024];
int winx, winy, winw, winh;
int txw, txh;
char state;
 
draw_window();
 
get_proc_info(proc_info);
state = *(char*)(proc_info+70);
if(state & (WIN_STATE_MINIMIZED|WIN_STATE_ROLLED))
continue;
 
winx = *(uint32_t*)(proc_info+34);
winy = *(uint32_t*)(proc_info+38);
116,47 → 113,56
if( (txw != clw) ||
(txh != clh) )
{
txv_set_size(&txv, txw, txh);
resize_context(ctx, txw, txh);
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);
show_context(ctx);
break;
}
case 2:
key = get_key();
printf("key %d\n", key.code);
// printf("key %d\n", key.code);
switch(key.code)
{
case 27:
return;
return 0;
 
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);
txv_set_font_size(txv, txv_get_font_size(txv) - 2);
show_context(ctx);
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);
txv_set_font_size(txv, txv_get_font_size(txv) + 2);
show_context(ctx);
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);
if( txv_scroll_down(txv) )
show_context(ctx);
break;
 
case 178:
if( txv_scroll_down(&txv) )
blit_bitmap(&txv.bitmap, TYPE_3_BORDER_WIDTH, get_skin_height(), txv.w, txv.h, 0, 0);
if( txv_scroll_up(txv) )
show_context(ctx);
break;
case 183:
if( txv_page_down(txv) )
show_context(ctx);
break;
case 184:
if( txv_page_up(txv) )
show_context(ctx);
break;
}
break;
 
case 3:
// button pressed; we have only one button, close
return;
return 0;
 
case 6:
// pos = get_mouse_pos();
165,15 → 171,15
 
if( wheels & 0xFFFF)
{
int r;
int r = 0;
 
if((short)wheels > 0)
r = txv_scroll_up(&txv);
else
r = txv_scroll_down(&txv);
r = txv_scroll_down(txv);
else if((short)wheels < 0)
r = txv_scroll_up(txv);
 
if( r )
blit_bitmap(&txv.bitmap, TYPE_3_BORDER_WIDTH, get_skin_height(), txv.w, txv.h, 0, 0);
show_context(ctx);
}
}
}