Rev 7424 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 7424 | Rev 7493 | ||
---|---|---|---|
1 | /* |
1 | /* |
2 | SOFTWARE CENTER v2.81 |
2 | SOFTWARE CENTER v2.81 |
3 | */ |
3 | */ |
4 | 4 | ||
5 | #define MEMSIZE 4096 * 15 |
5 | #define MEMSIZE 4096 * 15 |
6 | #include "..\lib\strings.h" |
6 | #include "..\lib\strings.h" |
7 | #include "..\lib\mem.h" |
7 | #include "..\lib\mem.h" |
8 | #include "..\lib\io.h" |
8 | #include "..\lib\io.h" |
9 | #include "..\lib\gui.h" |
9 | #include "..\lib\gui.h" |
10 | 10 | ||
11 | #include "..\lib\obj\libio.h" |
11 | #include "..\lib\obj\libio.h" |
12 | #include "..\lib\obj\libimg.h" |
12 | #include "..\lib\obj\libimg.h" |
13 | #include "..\lib\obj\libini.h" |
13 | #include "..\lib\obj\libini.h" |
14 | #include "..\lib\kfont.h" |
14 | #include "..\lib\kfont.h" |
15 | #include "..\lib\list_box.h" |
15 | #include "..\lib\list_box.h" |
16 | #include "..\lib\collection.h" |
16 | #include "..\lib\collection.h" |
17 | 17 | ||
18 | proc_info Form; |
18 | proc_info Form; |
19 | llist list; |
19 | llist list; |
20 | collection app_path_collection; |
20 | collection app_path_collection; |
21 | byte kolibrios_mounted; |
21 | byte kolibrios_mounted; |
22 | 22 | ||
23 | int window_width, |
23 | int window_width, |
24 | window_height; |
24 | window_height; |
25 | 25 | ||
26 | int list_pos, |
26 | int list_pos, |
27 | row, |
27 | row, |
28 | col, |
28 | col, |
29 | default_icon; |
29 | default_icon; |
30 | 30 | ||
31 | char window_title[128], |
31 | char window_title[128], |
32 | settings_ini_path[256] = "/sys/settings/"; |
32 | settings_ini_path[256] = "/sys/settings/"; |
33 | 33 | ||
34 | #define LIST_BACKGROUND_COLOR 0xF3F3F3 |
34 | #define LIST_BACKGROUND_COLOR 0xF3F3F3 |
- | 35 | ||
- | 36 | block ipos[128]; |
|
35 | 37 | ||
36 | void load_config() |
38 | void load_config() |
37 | { |
39 | { |
38 | ini_get_str stdcall (#settings_ini_path, "Config", "window_title", #window_title, sizeof(window_title), "Software widget"); |
40 | ini_get_str stdcall (#settings_ini_path, "Config", "window_title", #window_title, sizeof(window_title), "Software widget"); |
39 | ini_get_int stdcall (#settings_ini_path, "Config", "window_width", 690); |
41 | ini_get_int stdcall (#settings_ini_path, "Config", "window_width", 690); |
40 | window_width = EAX; |
42 | window_width = EAX; |
41 | ini_get_int stdcall (#settings_ini_path, "Config", "cell_w", 73); |
43 | ini_get_int stdcall (#settings_ini_path, "Config", "cell_w", 73); |
42 | list.item_w = EAX; |
44 | list.item_w = EAX; |
43 | ini_get_int stdcall (#settings_ini_path, "Config", "cell_h", 71); |
45 | ini_get_int stdcall (#settings_ini_path, "Config", "cell_h", 71); |
44 | list.item_h = EAX; |
46 | list.item_h = EAX; |
45 | ini_get_int stdcall (#settings_ini_path, "Config", "default_icon", 0); |
47 | ini_get_int stdcall (#settings_ini_path, "Config", "default_icon", 0); |
46 | default_icon = EAX; |
48 | default_icon = EAX; |
47 | } |
49 | } |
48 | 50 | ||
49 | 51 | ||
50 | void main() |
52 | void main() |
51 | { |
53 | { |
52 | dword id; |
54 | dword id; |
53 | kfont.init(DEFAULT_FONT); |
55 | kfont.init(DEFAULT_FONT); |
54 | load_dll(libio, #libio_init,1); |
56 | load_dll(libio, #libio_init,1); |
55 | load_dll(libimg, #libimg_init,1); |
57 | load_dll(libimg, #libimg_init,1); |
56 | load_dll(libini, #lib_init,1); |
58 | load_dll(libini, #lib_init,1); |
57 | 59 | ||
58 | Libimg_LoadImage(#skin, "/sys/icons32.png"); |
60 | Libimg_LoadImage(#skin, "/sys/icons32.png"); |
59 | Libimg_FillTransparent(skin.image, skin.w, skin.h, LIST_BACKGROUND_COLOR); |
61 | Libimg_FillTransparent(skin.image, skin.w, skin.h, LIST_BACKGROUND_COLOR); |
60 | kolibrios_mounted = dir_exists("/kolibrios"); |
62 | kolibrios_mounted = dir_exists("/kolibrios"); |
61 | 63 | ||
62 | if (param) |
64 | if (param) |
63 | { |
65 | { |
64 | strcpy(#settings_ini_path, #param); |
66 | strcpy(#settings_ini_path, #param); |
65 | } |
67 | } |
66 | else |
68 | else |
67 | { |
69 | { |
68 | strcat(#settings_ini_path, I_Path + strrchr(I_Path, '/')); |
70 | strcat(#settings_ini_path, I_Path + strrchr(I_Path, '/')); |
69 | strcat(#settings_ini_path, ".ini"); |
71 | strcat(#settings_ini_path, ".ini"); |
70 | } |
72 | } |
71 | 73 | ||
72 | load_config(); |
74 | load_config(); |
73 | list.cur_y = -1; |
75 | list.cur_y = -1; |
74 | list.y = 32; |
76 | list.y = 32; |
75 | 77 | ||
76 | DrawList(); |
78 | DrawList(); |
77 | window_height = row+1*list.item_h + list_pos + skin_height + 15; |
79 | window_height = row+1*list.item_h + list_pos + skin_height + 15; |
78 | 80 | ||
79 | loop() switch(WaitEvent()) |
81 | loop() switch(WaitEvent()) |
80 | { |
82 | { |
81 | // case evKey: |
83 | case evKey: |
82 | // GetKeys(); |
84 | GetKeys(); |
- | 85 | if (SCAN_CODE_LEFT == key_scancode) key_scancode = SCAN_CODE_UP; |
|
- | 86 | if (SCAN_CODE_RIGHT == key_scancode) key_scancode = SCAN_CODE_DOWN; |
|
83 | // if (list.ProcessKey(key_scancode)) DrawList(); |
87 | if (list.ProcessKey(key_scancode)) DrawSelection(); |
- | 88 | if (SCAN_CODE_ENTER == key_scancode) EventRunApp(list.cur_y); |
|
84 | // break; |
89 | break; |
85 | 90 | ||
86 | case evButton: |
91 | case evButton: |
87 | id=GetButtonID(); |
92 | id=GetButtonID(); |
88 | if (id==1) ExitProcess(); |
93 | if (id==1) ExitProcess(); |
89 | if (id>=100) EventRunApp(id-100); |
94 | if (id>=100) EventRunApp(id-100); |
90 | break; |
95 | break; |
91 | 96 | ||
92 | case evReDraw: |
97 | case evReDraw: |
93 | system.color.get(); |
98 | system.color.get(); |
94 | DefineAndDrawWindow(screen.width-window_width/2,screen.height-window_height/2,window_width,window_height,0x74,system.color.work,"",0); |
99 | DefineAndDrawWindow(screen.width-window_width/2,screen.height-window_height/2,window_width,window_height,0x74,system.color.work,"",0); |
95 | GetProcessInfo(#Form, SelfInfo); |
100 | GetProcessInfo(#Form, SelfInfo); |
96 | if (Form.status_window>2) { DrawTitle(#window_title); break; } else DrawTitle(""); |
101 | if (Form.status_window>2) { DrawTitle(#window_title); break; } else DrawTitle(""); |
97 | draw_top_bar(); |
102 | draw_top_bar(); |
98 | DrawList(); |
103 | DrawList(); |
99 | DrawBar(0, row + 1 * list.item_h + list_pos, Form.cwidth, -row - 1 * list.item_h - list_pos + Form.cheight, LIST_BACKGROUND_COLOR); |
104 | DrawBar(0, row +1 * list.item_h + list_pos, Form.cwidth, -row - 1 * list.item_h - list_pos + Form.cheight, LIST_BACKGROUND_COLOR); |
- | 105 | //if (list.cur_y == list.count) |
|
- | 106 | DrawSelection(); |
|
100 | break; |
107 | break; |
101 | } |
108 | } |
102 | } |
109 | } |
103 | 110 | ||
104 | void DrawList() { |
111 | void DrawList() { |
105 | list.count = 0; |
112 | list.count = 0; |
106 | row = -1; |
113 | row = -1; |
107 | app_path_collection.drop(); |
114 | app_path_collection.drop(); |
108 | list_pos = list.y; |
115 | list_pos = list.y; |
109 | list.column_max = window_width - 10 / list.item_w; |
116 | list.column_max = window_width - 10 / list.item_w; |
110 | ini_enum_sections stdcall (#settings_ini_path, #process_sections); |
117 | ini_enum_sections stdcall (#settings_ini_path, #process_sections); |
111 | list.visible = list.count; |
118 | list.visible = list.count; |
112 | } |
119 | } |
113 | 120 | ||
114 | byte draw_icons_from_section(dword key_value, key_name, sec_name, f_name) |
121 | byte draw_icons_from_section(dword key_value, key_name, sec_name, f_name) |
115 | { |
122 | { |
116 | int tmp, |
123 | int tmp, |
117 | icon_id, |
124 | icon_id, |
118 | icon_char_pos; |
125 | icon_char_pos; |
- | 126 | int text_w; |
|
119 | 127 | ||
120 | //do not show items located in /kolibrios/ if this directory not mounted |
128 | //do not show items located in /kolibrios/ if this directory not mounted |
121 | if (!strncmp(key_value, "/kolibrios/", 11)) || (!strncmp(key_value, "/k/", 3)) |
129 | if (!strncmp(key_value, "/kolibrios/", 11)) || (!strncmp(key_value, "/k/", 3)) |
122 | if (!kolibrios_mounted) return true; |
130 | if (!kolibrios_mounted) return true; |
123 | 131 | ||
124 | if (col==list.column_max) { |
132 | if (col==list.column_max) { |
125 | row++; |
133 | row++; |
126 | col=0; |
134 | col=0; |
127 | } |
135 | } |
128 | 136 | ||
129 | if (col==0) DrawBar(0, row * list.item_h + list_pos, Form.cwidth, list.item_h, LIST_BACKGROUND_COLOR); |
137 | if (col==0) DrawBar(0, row * list.item_h + list_pos, Form.cwidth, list.item_h, LIST_BACKGROUND_COLOR); |
130 | DefineButton(col*list.item_w+6, row*list.item_h + list_pos,list.item_w,list.item_h-5,list.count + 100 + BT_HIDE,0); |
138 | DefineButton(col*list.item_w+6, row*list.item_h + list_pos,list.item_w,list.item_h-5,list.count + 100 + BT_HIDE,0); |
131 | tmp = list.item_w/2; |
139 | tmp = list.item_w/2; |
132 | 140 | ||
133 | icon_char_pos = strchr(key_value, ','); |
141 | icon_char_pos = strchr(key_value, ','); |
134 | if (icon_char_pos) icon_id = atoi(icon_char_pos+1); else icon_id = default_icon; |
142 | if (icon_char_pos) icon_id = atoi(icon_char_pos+1); else icon_id = default_icon; |
135 | img_draw stdcall(skin.image, col*list.item_w+tmp-10, row*list.item_h+5 + list_pos, 32, 32, 0, icon_id*32); |
143 | img_draw stdcall(skin.image, col*list.item_w+tmp-10, row*list.item_h+5 + list_pos, 32, 32, 0, icon_id*32); |
136 | if (icon_char_pos) ESBYTE[icon_char_pos] = '\0'; //delete icon from string |
144 | if (icon_char_pos) ESBYTE[icon_char_pos] = '\0'; //delete icon from string |
137 | app_path_collection.add(key_value); |
145 | app_path_collection.add(key_value); |
138 | //kfont.WriteIntoWindowCenter(col*list.item_w+7,row*list.item_h+47 + list_pos, list.item_w,0, LIST_BACKGROUND_COLOR, 0xDCDCDC, 12, key_name); |
146 | //kfont.WriteIntoWindowCenter(col*list.item_w+7,row*list.item_h+47 + list_pos, list.item_w,0, LIST_BACKGROUND_COLOR, 0xDCDCDC, 12, key_name); |
139 | kfont.WriteIntoWindowCenter(col*list.item_w+5,row*list.item_h+46 + list_pos, list.item_w,0, LIST_BACKGROUND_COLOR, 0x000000, 12, key_name); |
147 | text_w = kfont.WriteIntoWindowCenter(col*list.item_w+5,row*list.item_h+46 + list_pos, list.item_w,0, LIST_BACKGROUND_COLOR, 0x000000, 12, key_name); |
140 | if (list.cur_y == list.count) DrawWideRectangle(col*list.item_w+6, row*list.item_h + list_pos,list.item_w,list.item_h-5, 2, 0x0080FF); |
148 | ipos[list.count].x = list.item_w-text_w/2+calc(col*list.item_w)+5; |
- | 149 | ipos[list.count].y = row*list.item_h+46 + list_pos + 16; |
|
- | 150 | ipos[list.count].w = text_w; |
|
141 | list.count++; |
151 | list.count++; |
142 | col++; |
152 | col++; |
143 | return true; |
153 | return true; |
144 | } |
154 | } |
145 | 155 | ||
146 | 156 | ||
147 | int old_row; //to detect empty sections |
157 | int old_row; //to detect empty sections |
148 | byte process_sections(dword sec_name, f_name) |
158 | byte process_sections(dword sec_name, f_name) |
149 | { |
159 | { |
150 | int text_len; |
160 | int text_len; |
151 | if (!strcmp(sec_name, "Config")) return true; |
161 | if (!strcmp(sec_name, "Config")) return true; |
152 | 162 | ||
153 | if ((col==0) && (row==old_row)) |
163 | if ((col==0) && (row==old_row)) |
154 | { |
164 | { |
155 | list_pos -= 28; |
165 | list_pos -= 28; |
156 | } |
166 | } |
157 | else |
167 | else |
158 | { |
168 | { |
159 | row++; |
169 | row++; |
160 | } |
170 | } |
161 | col = 0; |
171 | col = 0; |
162 | old_row = row; |
172 | old_row = row; |
163 | DrawBar(0, row * list.item_h + list_pos, Form.cwidth , 29, LIST_BACKGROUND_COLOR); |
173 | DrawBar(0, row * list.item_h + list_pos, Form.cwidth , 29, LIST_BACKGROUND_COLOR); |
164 | text_len = kfont.WriteIntoWindow(10, row * list.item_h + 10 + list_pos, LIST_BACKGROUND_COLOR, 0, 15, sec_name); |
174 | text_len = kfont.WriteIntoWindow(10, row * list.item_h + 10 + list_pos, LIST_BACKGROUND_COLOR, 0, 15, sec_name); |
165 | DrawBar(text_len+20, row * list.item_h + list_pos + 20, Form.cwidth-text_len-20, 1, 0xDCDCDC); |
175 | DrawBar(text_len+20, row * list.item_h + list_pos + 20, Form.cwidth-text_len-20, 1, 0xDCDCDC); |
166 | DrawBar(text_len+20, row * list.item_h + list_pos + 21, Form.cwidth-text_len-20, 1, 0xFCFCFC); |
176 | DrawBar(text_len+20, row * list.item_h + list_pos + 21, Form.cwidth-text_len-20, 1, 0xFCFCFC); |
167 | list_pos += 29; |
177 | list_pos += 29; |
168 | ini_enum_keys stdcall (f_name, sec_name, #draw_icons_from_section); |
178 | ini_enum_keys stdcall (f_name, sec_name, #draw_icons_from_section); |
169 | return true; |
179 | return true; |
170 | } |
180 | } |
171 | 181 | ||
172 | void draw_top_bar() |
182 | void draw_top_bar() |
173 | { |
183 | { |
174 | DrawBar(0,0,Form.cwidth, list.y-2, system.color.work); |
184 | DrawBar(0,0,Form.cwidth, list.y-2, system.color.work); |
175 | DrawBar(0,list.y-2, Form.cwidth, 1, MixColors(system.color.work, system.color.work_graph, 180)); |
185 | DrawBar(0,list.y-2, Form.cwidth, 1, MixColors(system.color.work, system.color.work_graph, 180)); |
176 | DrawBar(0,list.y-1, Form.cwidth, 1, system.color.work_graph); |
186 | DrawBar(0,list.y-1, Form.cwidth, 1, system.color.work_graph); |
177 | kfont.WriteIntoWindowCenter(0,5, Form.cwidth, list.y, system.color.work, system.color.work_text, 16, #window_title); |
187 | kfont.WriteIntoWindowCenter(0,5, Form.cwidth, list.y, system.color.work, system.color.work_text, 16, #window_title); |
178 | } |
188 | } |
179 | 189 | ||
180 | void EventRunApp(dword appid) |
190 | void EventRunApp(dword appid) |
181 | { |
191 | { |
182 | char run_app_path[4096]=0; |
192 | char run_app_path[4096]=0; |
183 | dword app_path = app_path_collection.get(appid); |
193 | dword app_path = app_path_collection.get(appid); |
184 | dword param_pos = strchr(app_path, '|'); |
194 | dword param_pos = strchr(app_path, '|'); |
185 | if (param_pos) { |
195 | if (param_pos) { |
186 | ESBYTE[param_pos] = NULL; |
196 | ESBYTE[param_pos] = NULL; |
187 | param_pos++; |
197 | param_pos++; |
188 | } |
198 | } |
189 | 199 | ||
190 | // the next block is created to save some space in ramdisk{ |
200 | // the next block is created to save some space in ramdisk{ |
191 | // |
201 | // |
192 | // convert relative path to absolute "calc" => "/sys/calc" |
202 | // convert relative path to absolute "calc" => "/sys/calc" |
193 | // convert short kolibrios path to full "/k/calc" => "/kolibrios/calc" |
203 | // convert short kolibrios path to full "/k/calc" => "/kolibrios/calc" |
194 | // other copy => as is |
204 | // other copy => as is |
195 | if (ESBYTE[app_path]!='/') { |
205 | if (ESBYTE[app_path]!='/') { |
196 | strcpy(#run_app_path, "/sys/"); |
206 | strcpy(#run_app_path, "/sys/"); |
197 | } |
207 | } |
198 | else if (!strncmp(app_path, "/k/",3)) { |
208 | else if (!strncmp(app_path, "/k/",3)) { |
199 | strcpy(#run_app_path, "/kolibrios/"); |
209 | strcpy(#run_app_path, "/kolibrios/"); |
200 | app_path+=3; |
210 | app_path+=3; |
201 | } |
211 | } |
202 | strcat(#run_app_path, app_path); |
212 | strcat(#run_app_path, app_path); |
203 | // }end |
213 | // }end |
204 | 214 | ||
205 | if (file_exists(#run_app_path)) |
215 | if (file_exists(#run_app_path)) |
206 | { |
216 | { |
207 | io.run(#run_app_path, param_pos); //0 or offset |
217 | io.run(#run_app_path, param_pos); //0 or offset |
208 | if (param_pos) ESBYTE[param_pos - 1] = '|'; |
218 | if (param_pos) ESBYTE[param_pos - 1] = '|'; |
209 | } |
219 | } |
210 | else |
220 | else |
211 | { |
221 | { |
212 | notify("'Application not found' -E"); |
222 | notify("'Application not found' -E"); |
213 | } |
223 | } |
214 | - | ||
215 | } |
224 | } |
- | 225 | ||
- | 226 | void DrawSelection() |
|
- | 227 | { |
|
- | 228 | int i; |
|
- | 229 | dword col; |
|
- | 230 | for (i=0; i |
|
- | 231 | if (i==list.cur_y) col=0x0080FF; else col=LIST_BACKGROUND_COLOR; |
|
- | 232 | DrawBar(ipos[i].x, ipos[i].y, ipos[i].w+2, 3, col); |
|
- | 233 | } |
|
216 | 234 | } |
|
217 | 235 | ||
218 | 236 | ||
219 | stop: |
237 | stop: |