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