Rev 5024 | Rev 6865 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
5024 | Serge | 1 | #include |
2 | #include |
||
3 | #include |
||
4 | #include FT_FREETYPE_H |
||
5 | #include FT_GLYPH_H |
||
6 | #include |
||
7 | #include |
||
8 | |||
9 | typedef struct |
||
10 | { |
||
11 | int l; |
||
12 | int t; |
||
13 | int r; |
||
14 | int b; |
||
15 | }rect_t; |
||
16 | |||
17 | typedef struct |
||
18 | { |
||
19 | FT_Face face; |
||
20 | int height; |
||
21 | int base; |
||
22 | |||
23 | FT_Glyph glyph[256]; |
||
24 | |||
25 | }font_t; |
||
26 | |||
27 | typedef struct |
||
28 | { |
||
29 | bitmap_t bitmap; |
||
30 | font_t *font; |
||
31 | |||
32 | char *text; |
||
33 | char **line; |
||
34 | int lines; |
||
35 | int txlines; |
||
36 | int startline; |
||
37 | int endline; |
||
38 | int w; |
||
39 | int h; |
||
40 | }tview_t; |
||
41 | |||
42 | int init_tview(tview_t *txv, int width, int height, char *text, int size); |
||
5025 | Serge | 43 | void txv_set_size(tview_t *txv, int txw, int txh); |
44 | void txv_set_font_size(tview_t *txv, int size); |
||
45 | |||
5024 | Serge | 46 | int txv_scroll_up(tview_t *txv); |
47 | int txv_scroll_down(tview_t *txv); |
||
48 | |||
49 | void* init_fontlib(); |
||
50 | int draw_text_ext(bitmap_t *winbitmap, FT_Face face, char *text, int len, rect_t *rc, int color); |
||
51 | |||
52 | void draw_window(void) |
||
53 | { |
||
54 | BeginDraw(); |
||
5025 | Serge | 55 | DrawWindow(0,0,0,0,NULL,0,0x73); |
5024 | Serge | 56 | EndDraw(); |
57 | } |
||
58 | |||
59 | tview_t txv; |
||
60 | |||
61 | int main(int argc, char *argv[]) |
||
62 | { |
||
63 | ufile_t uf; |
||
64 | oskey_t key; |
||
5025 | Serge | 65 | int clw = 640; |
66 | int clh = 480; |
||
5024 | Serge | 67 | |
68 | __asm__ __volatile__( |
||
69 | "int $0x40" |
||
70 | ::"a"(40), "b"(0xc0000027)); |
||
71 | |||
72 | if(argc < 2) |
||
73 | uf = load_file("/RD/1/EXAMPLE.ASM"); |
||
74 | else uf = load_file(argv[1]); |
||
75 | |||
76 | if(uf.data == NULL || |
||
77 | uf.size == 0) |
||
78 | return 0; |
||
79 | |||
80 | init_pixlib(0); |
||
81 | init_fontlib(); |
||
82 | |||
5025 | Serge | 83 | init_tview(&txv, clw, clh, uf.data, uf.size); |
5024 | Serge | 84 | |
85 | BeginDraw(); |
||
5025 | Serge | 86 | DrawWindow(10, 40, clw+TYPE_3_BORDER_WIDTH*2, |
87 | clh+TYPE_3_BORDER_WIDTH+get_skin_height(), "Text example", 0x000000, 0x73); |
||
5024 | Serge | 88 | blit_bitmap(&txv.bitmap, TYPE_3_BORDER_WIDTH, get_skin_height(), txv.w, txv.h, 0, 0); |
89 | |||
90 | EndDraw(); |
||
91 | |||
92 | for (;;) |
||
93 | { |
||
94 | uint32_t wheels; |
||
95 | int buttons; |
||
96 | pos_t pos; |
||
97 | |||
98 | switch (get_os_event()) |
||
99 | { |
||
5025 | Serge | 100 | case 1: |
101 | { |
||
102 | char proc_info[1024]; |
||
103 | int winx, winy, winw, winh; |
||
104 | int txw, txh; |
||
105 | |||
106 | get_proc_info(proc_info); |
||
107 | |||
108 | winx = *(uint32_t*)(proc_info+34); |
||
109 | winy = *(uint32_t*)(proc_info+38); |
||
110 | winw = *(uint32_t*)(proc_info+42)+1; |
||
111 | winh = *(uint32_t*)(proc_info+46)+1; |
||
112 | |||
113 | txw = winw - TYPE_3_BORDER_WIDTH*2; |
||
114 | txh = winh - TYPE_3_BORDER_WIDTH - get_skin_height(); |
||
115 | |||
116 | if( (txw != clw) || |
||
117 | (txh != clh) ) |
||
118 | { |
||
119 | txv_set_size(&txv, txw, txh); |
||
120 | clw = txw; |
||
121 | clh = txh; |
||
122 | }; |
||
123 | |||
124 | draw_window(); |
||
125 | blit_bitmap(&txv.bitmap, TYPE_3_BORDER_WIDTH, get_skin_height(), txv.w, txv.h, 0, 0); |
||
126 | break; |
||
127 | } |
||
5024 | Serge | 128 | case 2: |
129 | key = get_key(); |
||
5025 | Serge | 130 | printf("key %d\n", key.code); |
5024 | Serge | 131 | switch(key.code) |
132 | { |
||
133 | case 27: |
||
134 | return; |
||
135 | |||
5025 | Serge | 136 | case 45: |
137 | txv_set_font_size(&txv, txv.font->height-3); |
||
138 | blit_bitmap(&txv.bitmap, TYPE_3_BORDER_WIDTH, get_skin_height(), txv.w, txv.h, 0, 0); |
||
139 | break; |
||
140 | |||
141 | case 61: |
||
142 | txv_set_font_size(&txv, txv.font->height+1); |
||
143 | blit_bitmap(&txv.bitmap, TYPE_3_BORDER_WIDTH, get_skin_height(), txv.w, txv.h, 0, 0); |
||
144 | break; |
||
5024 | Serge | 145 | case 177: |
146 | if( txv_scroll_up(&txv) ) |
||
147 | blit_bitmap(&txv.bitmap, TYPE_3_BORDER_WIDTH, get_skin_height(), txv.w, txv.h, 0, 0); |
||
148 | break; |
||
149 | |||
150 | case 178: |
||
151 | if( txv_scroll_down(&txv) ) |
||
152 | blit_bitmap(&txv.bitmap, TYPE_3_BORDER_WIDTH, get_skin_height(), txv.w, txv.h, 0, 0); |
||
153 | break; |
||
154 | } |
||
155 | break; |
||
156 | |||
157 | case 3: |
||
158 | // button pressed; we have only one button, close |
||
159 | return; |
||
160 | |||
161 | case 6: |
||
162 | // pos = get_mouse_pos(); |
||
163 | // buttons = get_mouse_buttons(); |
||
164 | wheels = get_mouse_wheels(); |
||
165 | |||
166 | if( wheels & 0xFFFF) |
||
167 | { |
||
168 | int r; |
||
169 | |||
170 | if((short)wheels > 0) |
||
171 | r = txv_scroll_up(&txv); |
||
172 | else |
||
173 | r = txv_scroll_down(&txv); |
||
174 | |||
175 | if( r ) |
||
176 | blit_bitmap(&txv.bitmap, TYPE_3_BORDER_WIDTH, get_skin_height(), txv.w, txv.h, 0, 0); |
||
177 | } |
||
178 | } |
||
179 | } |
||
180 | return 0; |
||
181 | }> |