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