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