Rev 5656 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 5656 | Rev 5674 | ||
---|---|---|---|
1 | /* |
1 | /* |
2 | SOFTWARE CENTER v2.32 |
2 | SOFTWARE CENTER v2.32 |
3 | */ |
3 | */ |
4 | 4 | ||
5 | #define MEMSIZE 0x5000 |
5 | #define MEMSIZE 0x5000 |
6 | #include "..\lib\strings.h" |
6 | #include "..\lib\strings.h" |
7 | #include "..\lib\mem.h" |
7 | #include "..\lib\mem.h" |
8 | #include "..\lib\file_system.h" |
8 | #include "..\lib\file_system.h" |
9 | #include "..\lib\gui.h" |
9 | #include "..\lib\gui.h" |
10 | 10 | ||
11 | #include "..\lib\obj\libio_lib.h" |
11 | #include "..\lib\obj\libio_lib.h" |
12 | #include "..\lib\obj\libimg_lib.h" |
12 | #include "..\lib\obj\libimg_lib.h" |
13 | #include "..\lib\obj\libini.h" |
13 | #include "..\lib\obj\libini.h" |
14 | 14 | ||
15 | #include "..\lib\patterns\libimg_load_skin.h" |
15 | #include "..\lib\patterns\libimg_load_skin.h" |
16 | - | ||
17 | system_colors sc; |
16 | |
18 | proc_info Form; |
17 | proc_info Form; |
19 | 18 | ||
20 | byte kolibrios_mounted; |
19 | byte kolibrios_mounted; |
21 | 20 | ||
22 | int item_id_need_to_run=-1, |
21 | int item_id_need_to_run=-1, |
23 | current_item_id; |
22 | current_item_id; |
24 | 23 | ||
25 | int window_width, |
24 | int window_width, |
26 | window_height; |
25 | window_height; |
27 | 26 | ||
28 | int col_max, |
27 | int col_max, |
29 | cell_w, |
28 | cell_w, |
30 | cell_h, |
29 | cell_h, |
31 | list_pos, |
30 | list_pos, |
32 | list_top, |
31 | list_top, |
33 | row, |
32 | row, |
34 | old_row, //to detect empty sections |
33 | old_row, //to detect empty sections |
35 | col, |
34 | col, |
36 | default_icon; |
35 | default_icon; |
37 | 36 | ||
38 | char window_title[128], |
37 | char window_title[128], |
39 | settings_ini_path[256] = "/sys/settings/"; |
38 | settings_ini_path[256] = "/sys/settings/"; |
40 | 39 | ||
41 | #define LIST_BACKGROUND_COLOR 0xF3F3F3 |
40 | #define LIST_BACKGROUND_COLOR 0xF3F3F3 |
42 | 41 | ||
43 | libimg_image skin; |
42 | libimg_image skin; |
44 | 43 | ||
45 | void load_config() |
44 | void load_config() |
46 | { |
45 | { |
47 | ini_get_str stdcall (#settings_ini_path, "Config", "window_title", #window_title, sizeof(window_title), "Software widget"); |
46 | ini_get_str stdcall (#settings_ini_path, "Config", "window_title", #window_title, sizeof(window_title), "Software widget"); |
48 | ini_get_int stdcall (#settings_ini_path, "Config", "window_width", 690); |
47 | ini_get_int stdcall (#settings_ini_path, "Config", "window_width", 690); |
49 | window_width = EAX; |
48 | window_width = EAX; |
50 | ini_get_int stdcall (#settings_ini_path, "Config", "window_height", 540); |
49 | ini_get_int stdcall (#settings_ini_path, "Config", "window_height", 540); |
51 | window_height = EAX; |
50 | window_height = EAX; |
52 | ini_get_int stdcall (#settings_ini_path, "Config", "cell_w", 66); |
51 | ini_get_int stdcall (#settings_ini_path, "Config", "cell_w", 66); |
53 | cell_w = EAX; |
52 | cell_w = EAX; |
54 | ini_get_int stdcall (#settings_ini_path, "Config", "cell_h", 64); |
53 | ini_get_int stdcall (#settings_ini_path, "Config", "cell_h", 64); |
55 | cell_h = EAX; |
54 | cell_h = EAX; |
56 | ini_get_int stdcall (#settings_ini_path, "Config", "default_icon", 0); |
55 | ini_get_int stdcall (#settings_ini_path, "Config", "default_icon", 0); |
57 | default_icon = EAX; |
56 | default_icon = EAX; |
58 | } |
57 | } |
59 | 58 | ||
60 | 59 | ||
61 | void main() |
60 | void main() |
62 | { |
61 | { |
63 | dword id, key; |
62 | dword id, key; |
64 | 63 | ||
65 | load_dll(libio, #libio_init,1); |
64 | load_dll(libio, #libio_init,1); |
66 | load_dll(libimg, #libimg_init,1); |
65 | load_dll(libimg, #libimg_init,1); |
67 | load_dll(libini, #lib_init,1); |
66 | load_dll(libini, #lib_init,1); |
68 | 67 | ||
69 | Libimg_LoadImage(#skin, "/sys/icons32.png"); |
68 | Libimg_LoadImage(#skin, "/sys/icons32.png"); |
70 | Libimg_FillTransparent(skin.image, skin.w, skin.h, LIST_BACKGROUND_COLOR); |
69 | Libimg_FillTransparent(skin.image, skin.w, skin.h, LIST_BACKGROUND_COLOR); |
71 | 70 | ||
72 | if (param) |
71 | if (param) |
73 | { |
72 | { |
74 | strcpy(#settings_ini_path, #param); |
73 | strcpy(#settings_ini_path, #param); |
75 | } |
74 | } |
76 | else |
75 | else |
77 | { |
76 | { |
78 | strcat(#settings_ini_path, #program_path + strrchr(#program_path, '/')); |
77 | strcat(#settings_ini_path, #program_path + strrchr(#program_path, '/')); |
79 | strcat(#settings_ini_path, ".ini"); |
78 | strcat(#settings_ini_path, ".ini"); |
80 | } |
79 | } |
81 | load_config(); |
80 | load_config(); |
82 | 81 | ||
83 | loop() |
82 | loop() |
84 | { |
83 | { |
85 | switch(WaitEvent()) |
84 | switch(WaitEvent()) |
86 | { |
85 | { |
87 | case evButton: |
86 | case evButton: |
88 | id=GetButtonID(); |
87 | id=GetButtonID(); |
89 | if (id==1) ExitProcess(); |
88 | if (id==1) ExitProcess(); |
90 | if (id>=100) |
89 | if (id>=100) |
91 | { |
90 | { |
92 | item_id_need_to_run = id - 100; |
91 | item_id_need_to_run = id - 100; |
93 | current_item_id = 0; |
92 | current_item_id = 0; |
94 | ini_enum_sections stdcall (#settings_ini_path, #process_sections); |
93 | ini_enum_sections stdcall (#settings_ini_path, #process_sections); |
95 | item_id_need_to_run = -1; |
94 | item_id_need_to_run = -1; |
96 | } |
95 | } |
97 | break; |
96 | break; |
98 | 97 | ||
99 | case evReDraw: |
98 | case evReDraw: |
100 | sc.get(); |
99 | system.color.get(); |
101 | DefineAndDrawWindow(GetScreenWidth()-window_width/2,GetScreenHeight()-window_height/2,window_width,window_height,0x74,sc.work,""); |
100 | DefineAndDrawWindow(GetScreenWidth()-window_width/2,GetScreenHeight()-window_height/2,window_width,window_height,0x74,system.color.work,""); |
102 | GetProcessInfo(#Form, SelfInfo); |
101 | GetProcessInfo(#Form, SelfInfo); |
103 | if (Form.status_window>2) { DrawTitle(#window_title); break; } else DrawTitle(""); |
102 | if (Form.status_window>2) { DrawTitle(#window_title); break; } else DrawTitle(""); |
104 | kolibrios_mounted = isdir("/kolibrios"); |
103 | kolibrios_mounted = isdir("/kolibrios"); |
105 | col_max = Form.cwidth - 10 / cell_w; |
104 | col_max = Form.cwidth - 10 / cell_w; |
106 | current_item_id = 0; |
105 | current_item_id = 0; |
107 | draw_top_bar(); |
106 | draw_top_bar(); |
108 | ini_enum_sections stdcall (#settings_ini_path, #process_sections); |
107 | ini_enum_sections stdcall (#settings_ini_path, #process_sections); |
109 | DrawBar(0, row + 1 * cell_h + list_pos, Form.cwidth, -row - 1 * cell_h - list_pos + Form.cheight, LIST_BACKGROUND_COLOR); |
108 | DrawBar(0, row + 1 * cell_h + list_pos, Form.cwidth, -row - 1 * cell_h - list_pos + Form.cheight, LIST_BACKGROUND_COLOR); |
110 | break; |
109 | break; |
111 | } |
110 | } |
112 | } |
111 | } |
113 | } |
112 | } |
114 | 113 | ||
115 | byte search_for_id_need_to_run(dword key_value, key_name, sec_name, f_name) |
114 | byte search_for_id_need_to_run(dword key_value, key_name, sec_name, f_name) |
116 | { |
115 | { |
117 | int icon_char_pos; |
116 | int icon_char_pos; |
118 | if (item_id_need_to_run == current_item_id) |
117 | if (item_id_need_to_run == current_item_id) |
119 | { |
118 | { |
120 | icon_char_pos = strchr(key_value, ','); |
119 | icon_char_pos = strchr(key_value, ','); |
121 | if (icon_char_pos) ESBYTE[icon_char_pos] = 0; //delete icon from string |
120 | if (icon_char_pos) ESBYTE[icon_char_pos] = 0; //delete icon from string |
122 | RunProgram(key_value, ""); |
121 | RunProgram(key_value, ""); |
123 | } |
122 | } |
124 | current_item_id++; |
123 | current_item_id++; |
125 | if (!strncmp(key_value, "/kolibrios/", 11)) && (!kolibrios_mounted) current_item_id--; |
124 | if (!strncmp(key_value, "/kolibrios/", 11)) && (!kolibrios_mounted) current_item_id--; |
126 | return true; |
125 | return true; |
127 | } |
126 | } |
128 | 127 | ||
129 | 128 | ||
130 | byte draw_icons_from_section(dword key_value, key_name, sec_name, f_name) |
129 | byte draw_icons_from_section(dword key_value, key_name, sec_name, f_name) |
131 | { |
130 | { |
132 | int tmp, |
131 | int tmp, |
133 | icon_id, |
132 | icon_id, |
134 | icon_char_pos; |
133 | icon_char_pos; |
135 | 134 | ||
136 | if (col==col_max) { |
135 | if (col==col_max) { |
137 | row++; |
136 | row++; |
138 | col=0; |
137 | col=0; |
139 | } |
138 | } |
140 | 139 | ||
141 | //do not show items located in /kolibrios/ if this directory not mounted |
140 | //do not show items located in /kolibrios/ if this directory not mounted |
142 | if (!strncmp(key_value, "/kolibrios/", 11)) && (!kolibrios_mounted) return true; |
141 | if (!strncmp(key_value, "/kolibrios/", 11)) && (!kolibrios_mounted) return true; |
143 | 142 | ||
144 | if (col==0) DrawBar(0, row * cell_h + list_pos, Form.cwidth, cell_h, LIST_BACKGROUND_COLOR); |
143 | if (col==0) DrawBar(0, row * cell_h + list_pos, Form.cwidth, cell_h, LIST_BACKGROUND_COLOR); |
145 | DefineButton(col*cell_w+6,row*cell_h + list_pos,cell_w,cell_h-5,current_item_id + 100 + BT_HIDE,0); |
144 | DefineButton(col*cell_w+6,row*cell_h + list_pos,cell_w,cell_h-5,current_item_id + 100 + BT_HIDE,0); |
146 | tmp = cell_w/2; |
145 | tmp = cell_w/2; |
147 | 146 | ||
148 | icon_char_pos = strchr(key_value, ','); |
147 | icon_char_pos = strchr(key_value, ','); |
149 | if (icon_char_pos) icon_id = atoi(icon_char_pos+1); else icon_id = default_icon; |
148 | if (icon_char_pos) icon_id = atoi(icon_char_pos+1); else icon_id = default_icon; |
150 | img_draw stdcall(skin.image, col*cell_w+tmp-10, row*cell_h+5 + list_pos, 32, 32, 0, icon_id*32); |
149 | img_draw stdcall(skin.image, col*cell_w+tmp-10, row*cell_h+5 + list_pos, 32, 32, 0, icon_id*32); |
151 | WriteTextCenter(col*cell_w+7,row*cell_h+47 + list_pos,cell_w,0xDCDCDC,key_name); |
150 | WriteTextCenter(col*cell_w+7,row*cell_h+47 + list_pos,cell_w,0xDCDCDC,key_name); |
152 | WriteTextCenter(col*cell_w+6,row*cell_h+46 + list_pos,cell_w,0x000000,key_name); |
151 | WriteTextCenter(col*cell_w+6,row*cell_h+46 + list_pos,cell_w,0x000000,key_name); |
153 | current_item_id++; |
152 | current_item_id++; |
154 | col++; |
153 | col++; |
155 | return true; |
154 | return true; |
156 | } |
155 | } |
157 | 156 | ||
158 | 157 | ||
159 | byte process_sections(dword sec_name, f_name) |
158 | byte process_sections(dword sec_name, f_name) |
160 | { |
159 | { |
161 | if (!strcmp(sec_name, "Config")) return true; |
160 | if (!strcmp(sec_name, "Config")) return true; |
162 | 161 | ||
163 | if (item_id_need_to_run!=-1) |
162 | if (item_id_need_to_run!=-1) |
164 | { |
163 | { |
165 | ini_enum_keys stdcall (f_name, sec_name, #search_for_id_need_to_run); |
164 | ini_enum_keys stdcall (f_name, sec_name, #search_for_id_need_to_run); |
166 | } |
165 | } |
167 | else |
166 | else |
168 | { |
167 | { |
169 | if ((col==0) && (row==old_row)) |
168 | if ((col==0) && (row==old_row)) |
170 | { |
169 | { |
171 | list_pos -= 20; |
170 | list_pos -= 20; |
172 | } |
171 | } |
173 | else |
172 | else |
174 | { |
173 | { |
175 | row++; |
174 | row++; |
176 | } |
175 | } |
177 | col = 0; |
176 | col = 0; |
178 | old_row = row; |
177 | old_row = row; |
179 | DrawBar(0, row * cell_h + list_pos, Form.cwidth , 20, LIST_BACKGROUND_COLOR); |
178 | DrawBar(0, row * cell_h + list_pos, Form.cwidth , 20, LIST_BACKGROUND_COLOR); |
180 | WriteTextB(10, row * cell_h + 9 + list_pos, 0x90, 0x000000, sec_name); |
179 | WriteTextB(10, row * cell_h + 9 + list_pos, 0x90, 0x000000, sec_name); |
181 | list_pos += 20; |
180 | list_pos += 20; |
182 | ini_enum_keys stdcall (f_name, sec_name, #draw_icons_from_section); |
181 | ini_enum_keys stdcall (f_name, sec_name, #draw_icons_from_section); |
183 | } |
182 | } |
184 | return true; |
183 | return true; |
185 | } |
184 | } |
186 | 185 | ||
187 | void draw_top_bar() |
186 | void draw_top_bar() |
188 | { |
187 | { |
189 | int top_position = 25; |
188 | int top_position = 25; |
190 | DrawBar(0,0,Form.cwidth, top_position-1, sc.work); |
189 | DrawBar(0,0,Form.cwidth, top_position-1, system.color.work); |
191 | DrawBar(0,top_position-1, Form.cwidth, 1, sc.work_graph); |
190 | DrawBar(0,top_position-1, Form.cwidth, 1, system.color.work_graph); |
192 | WriteTextB(Form.cwidth/2-70, 9, 0x90, sc.work_text, #window_title); |
191 | WriteTextB(Form.cwidth/2-70, 9, 0x90, system.color.work_text, #window_title); |
193 | list_top = top_position; |
192 | list_top = top_position; |
194 | list_pos = list_top; |
193 | list_pos = list_top; |
195 | row = -1; |
194 | row = -1; |
196 | } |
195 | } |
197 | 196 | ||
198 | 197 | ||
199 | 198 | ||
200 | stop: |
199 | stop: |