Rev 5407 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
4870 | leency | 1 | /* |
5409 | leency | 2 | SOFTWARE CENTER v2.21 |
4870 | leency | 3 | */ |
4 | |||
5 | #define MEMSIZE 0x3E80 |
||
6 | #include "..\lib\kolibri.h" |
||
7 | #include "..\lib\strings.h" |
||
8 | #include "..\lib\mem.h" |
||
9 | #include "..\lib\file_system.h" |
||
10 | #include "..\lib\dll.h" |
||
11 | #include "..\lib\figures.h" |
||
5409 | leency | 12 | |
4870 | leency | 13 | #include "..\lib\lib.obj\libio_lib.h" |
14 | #include "..\lib\lib.obj\libimg_lib.h" |
||
5151 | leency | 15 | #include "..\lib\lib.obj\libini.h" |
4870 | leency | 16 | |
5409 | leency | 17 | #include "..\lib\patterns\libimg_load_skin.h" |
5405 | leency | 18 | |
4870 | leency | 19 | system_colors sc; |
20 | proc_info Form; |
||
5403 | leency | 21 | mouse m; |
4870 | leency | 22 | |
5405 | leency | 23 | int item_id_need_to_run=-1, |
24 | current_item_id; |
||
5403 | leency | 25 | |
5405 | leency | 26 | int window_width, |
27 | window_height; |
||
5403 | leency | 28 | |
5405 | leency | 29 | int col_max, |
30 | cell_w, |
||
31 | cell_h, |
||
32 | list_pos, |
||
33 | list_top, |
||
34 | row, |
||
35 | col, |
||
36 | default_icon; |
||
5403 | leency | 37 | |
5405 | leency | 38 | char window_title[128], |
39 | settings_ini_path[256] = "/sys/settings/"; |
||
40 | |||
5403 | leency | 41 | #define LIST_BACKGROUND_COLOR 0xF3F3F3 |
42 | |||
5409 | leency | 43 | libimg_image skin; |
5403 | leency | 44 | |
45 | void load_config() |
||
46 | { |
||
47 | 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); |
||
49 | window_width = EAX; |
||
50 | ini_get_int stdcall (#settings_ini_path, "Config", "window_height", 540); |
||
51 | window_height = EAX; |
||
5404 | leency | 52 | ini_get_int stdcall (#settings_ini_path, "Config", "cell_w", 66); |
53 | cell_w = EAX; |
||
54 | ini_get_int stdcall (#settings_ini_path, "Config", "cell_h", 64); |
||
55 | cell_h = EAX; |
||
5405 | leency | 56 | ini_get_int stdcall (#settings_ini_path, "Config", "default_icon", 0); |
57 | default_icon = EAX; |
||
4870 | leency | 58 | } |
59 | |||
60 | |||
61 | void main() |
||
62 | { |
||
5409 | leency | 63 | dword id, key; |
4870 | leency | 64 | mem_Init(); |
5403 | leency | 65 | if (load_dll2(libio, #libio_init,1)!=0) notify("Error: library doesn't exists - libio"); |
4870 | leency | 66 | if (load_dll2(libimg, #libimg_init,1)!=0) notify("Error: library doesn't exists - libimg"); |
5151 | leency | 67 | if (load_dll2(libini, #lib_init,1)!=0) notify("Error: library doesn't exists - libini"); |
5403 | leency | 68 | |
5409 | leency | 69 | Libimg_LoadImage(#skin, "/sys/iconstrp.png"); |
70 | Libimg_FillTransparent(skin.image, skin.w, skin.h, LIST_BACKGROUND_COLOR); |
||
71 | |||
5407 | leency | 72 | if (param) |
5406 | leency | 73 | { |
74 | strcpy(#settings_ini_path, #param); |
||
75 | } |
||
76 | else |
||
77 | { |
||
78 | strcat(#settings_ini_path, #program_path + strrchr(#program_path, '/')); |
||
79 | strcat(#settings_ini_path, ".ini"); |
||
80 | } |
||
5403 | leency | 81 | load_config(); |
82 | |||
4870 | leency | 83 | loop() |
5403 | leency | 84 | { |
4870 | leency | 85 | switch(WaitEvent()) |
86 | { |
||
87 | case evButton: |
||
88 | id=GetButtonID(); |
||
89 | if (id==1) ExitProcess(); |
||
5151 | leency | 90 | if (id>=100) |
91 | { |
||
5403 | leency | 92 | item_id_need_to_run = id - 100; |
93 | current_item_id = 0; |
||
94 | ini_enum_sections stdcall (#settings_ini_path, #draw_section); |
||
5404 | leency | 95 | item_id_need_to_run = -1; |
5151 | leency | 96 | } |
4870 | leency | 97 | break; |
5403 | leency | 98 | |
4870 | leency | 99 | case evReDraw: |
100 | sc.get(); |
||
5406 | leency | 101 | DefineAndDrawWindow(GetScreenWidth()-window_width/2,GetScreenHeight()-window_height/2,window_width,window_height,0x74,sc.work,""); |
4870 | leency | 102 | GetProcessInfo(#Form, SelfInfo); |
5406 | leency | 103 | if (Form.status_window>2) { DrawTitle(#window_title); break; } else DrawTitle(""); |
5404 | leency | 104 | col_max = Form.cwidth - 10 / cell_w; |
5403 | leency | 105 | current_item_id = 0; |
106 | draw_top_bar(); |
||
107 | ini_enum_sections stdcall (#settings_ini_path, #draw_section); |
||
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, ','); |
120 | if (icon_char_pos) ESBYTE[key_value + icon_char_pos - 1] = 0; //delete icon from string |
||
5403 | leency | 121 | RunProgram(key_value, ""); |
5151 | leency | 122 | } |
5403 | leency | 123 | current_item_id++; |
5151 | leency | 124 | return 1; |
125 | } |
||
4870 | leency | 126 | |
5151 | leency | 127 | |
5403 | leency | 128 | byte draw_icons_from_section(dword key_value, key_name, sec_name, f_name) |
5151 | leency | 129 | { |
5405 | leency | 130 | int tmp, |
131 | icon_id, |
||
132 | icon_char_pos; |
||
5151 | leency | 133 | |
134 | if (col==col_max) { |
||
135 | row++; |
||
136 | col=0; |
||
137 | } |
||
5404 | leency | 138 | if (col==0) DrawBar(0, row * cell_h + list_pos, Form.cwidth, cell_h, LIST_BACKGROUND_COLOR); |
139 | DefineButton(col*cell_w+6,row*cell_h + list_pos,cell_w,cell_h-5,current_item_id + 100 + BT_HIDE,0); |
||
140 | tmp = cell_w/2; |
||
5405 | leency | 141 | |
142 | icon_char_pos = strchr(key_value, ','); |
||
143 | if (icon_char_pos) icon_id = atoi(key_value + icon_char_pos); else icon_id = default_icon; |
||
5404 | leency | 144 | img_draw stdcall(skin.image, col*cell_w+tmp-10, row*cell_h+5 + list_pos, 32, 32, 0, icon_id*32); |
5405 | leency | 145 | WriteTextCenter(col*cell_w+7,row*cell_h+47 + list_pos,cell_w,0xDCDCDC,key_name); |
5404 | leency | 146 | WriteTextCenter(col*cell_w+6,row*cell_h+46 + list_pos,cell_w,0x000000,key_name); |
5403 | leency | 147 | current_item_id++; |
5151 | leency | 148 | col++; |
149 | return 1; |
||
150 | } |
||
151 | |||
5403 | leency | 152 | |
153 | byte draw_section(dword sec_name, f_name) |
||
4870 | leency | 154 | { |
5403 | leency | 155 | if (strcmp(sec_name, "Config")==0) return 1; |
4870 | leency | 156 | |
5404 | leency | 157 | if (item_id_need_to_run!=-1) |
5403 | leency | 158 | { |
159 | ini_enum_keys stdcall (f_name, sec_name, #search_for_id_need_to_run); |
||
160 | } |
||
161 | else |
||
162 | { |
||
163 | row++; |
||
164 | col = 0; |
||
5404 | leency | 165 | DrawBar(0, row * cell_h + list_pos, Form.cwidth , 20, LIST_BACKGROUND_COLOR); |
166 | WriteTextB(10, row * cell_h + 9 + list_pos, 0x90, 0x000000, sec_name); |
||
5403 | leency | 167 | list_pos += 20; |
168 | ini_enum_keys stdcall (f_name, sec_name, #draw_icons_from_section); |
||
169 | } |
||
170 | return 1; |
||
4870 | leency | 171 | } |
172 | |||
5403 | leency | 173 | void draw_top_bar() |
174 | { |
||
175 | int top_position = 25; |
||
176 | DrawBar(0,0,Form.cwidth, top_position-1, sc.work); |
||
177 | DrawBar(0,top_position-1, Form.cwidth, 1, sc.work_graph); |
||
178 | WriteTextB(Form.cwidth/2-70, 9, 0x90, sc.work_text, #window_title); |
||
179 | list_top = top_position; |
||
180 | list_pos = list_top; |
||
181 | row = -1; |
||
182 | } |
||
4870 | leency | 183 | |
184 | |||
5403 | leency | 185 | |
4870 | leency | 186 | stop: |