Rev 5403 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
4870 | leency | 1 | /* |
5404 | leency | 2 | SOFTWARE CENTER v2.1 |
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" |
||
12 | |||
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 | |
17 | system_colors sc; |
||
18 | proc_info Form; |
||
5403 | leency | 19 | mouse m; |
4870 | leency | 20 | |
5404 | leency | 21 | int item_id_need_to_run=-1, current_item_id; |
5403 | leency | 22 | |
5404 | leency | 23 | int col_max, cell_w, cell_h, list_pos, list_top; |
5403 | leency | 24 | int row, col; |
25 | |||
26 | char window_title[128]; |
||
27 | char settings_ini_path[256] = "/sys/settings/"; |
||
28 | int window_width; |
||
29 | int window_height; |
||
30 | |||
31 | #define LIST_BACKGROUND_COLOR 0xF3F3F3 |
||
32 | |||
33 | |||
34 | |||
4870 | leency | 35 | struct struct_skin { |
36 | dword image, w, h; |
||
5403 | leency | 37 | int load(); |
4870 | leency | 38 | } skin; |
39 | |||
5403 | leency | 40 | |
41 | int struct_skin::load() |
||
4870 | leency | 42 | { |
5403 | leency | 43 | int i, max_i; |
4870 | leency | 44 | dword image_data; |
45 | skin.image = load_image("/sys/iconstrp.png"); |
||
46 | if (!skin.image) notify("'iconstrp.png not found' -E"); |
||
5403 | leency | 47 | skin.w = DSWORD[skin.image + 4]; |
48 | skin.h = DSWORD[skin.image + 8]; |
||
49 | image_data = DSDWORD[skin.image + 24]; |
||
4870 | leency | 50 | sc.get(); |
5403 | leency | 51 | max_i = w * h * 4 + image_data; |
52 | for (i = image_data; i < max_i; i += 4) if (DSDWORD[i]==0) DSDWORD[i] = LIST_BACKGROUND_COLOR; |
||
53 | } |
||
4870 | leency | 54 | |
5403 | leency | 55 | void load_config() |
56 | { |
||
57 | ini_get_str stdcall (#settings_ini_path, "Config", "window_title", #window_title, sizeof(window_title), "Software widget"); |
||
58 | ini_get_int stdcall (#settings_ini_path, "Config", "window_width", 690); |
||
59 | window_width = EAX; |
||
60 | ini_get_int stdcall (#settings_ini_path, "Config", "window_height", 540); |
||
61 | window_height = EAX; |
||
5404 | leency | 62 | ini_get_int stdcall (#settings_ini_path, "Config", "cell_w", 66); |
63 | cell_w = EAX; |
||
64 | ini_get_int stdcall (#settings_ini_path, "Config", "cell_h", 64); |
||
65 | cell_h = EAX; |
||
4870 | leency | 66 | } |
67 | |||
68 | |||
69 | void main() |
||
70 | { |
||
71 | int id, key; |
||
72 | mem_Init(); |
||
5403 | leency | 73 | if (load_dll2(libio, #libio_init,1)!=0) notify("Error: library doesn't exists - libio"); |
4870 | leency | 74 | if (load_dll2(libimg, #libimg_init,1)!=0) notify("Error: library doesn't exists - libimg"); |
5151 | leency | 75 | if (load_dll2(libini, #lib_init,1)!=0) notify("Error: library doesn't exists - libini"); |
5403 | leency | 76 | skin.load(); |
77 | |||
78 | strcat(#settings_ini_path, #program_path + strrchr(#program_path, '/')); |
||
79 | strcat(#settings_ini_path, ".ini"); |
||
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; |
||
93 | ini_enum_sections stdcall (#settings_ini_path, #draw_section); |
||
5404 | leency | 94 | item_id_need_to_run = -1; |
5151 | leency | 95 | } |
4870 | leency | 96 | break; |
5403 | leency | 97 | |
4870 | leency | 98 | case evReDraw: |
99 | sc.get(); |
||
5403 | leency | 100 | DefineAndDrawWindow(GetScreenWidth()-window_width/2,GetScreenHeight()-window_height/2,window_width,window_height,0x74,sc.work," "); |
4870 | leency | 101 | GetProcessInfo(#Form, SelfInfo); |
102 | if (Form.status_window>2) break; |
||
5404 | leency | 103 | col_max = Form.cwidth - 10 / cell_w; |
5403 | leency | 104 | current_item_id = 0; |
105 | draw_top_bar(); |
||
106 | ini_enum_sections stdcall (#settings_ini_path, #draw_section); |
||
5404 | leency | 107 | DrawBar(0, row + 1 * cell_h + list_pos, Form.cwidth, -row - 1 * cell_h - list_pos + Form.cheight, LIST_BACKGROUND_COLOR); |
4870 | leency | 108 | break; |
109 | } |
||
5403 | leency | 110 | } |
4870 | leency | 111 | } |
112 | |||
5403 | leency | 113 | byte search_for_id_need_to_run(dword key_value, key_name, sec_name, f_name) |
5151 | leency | 114 | { |
5404 | leency | 115 | int icon_char_pos; |
5403 | leency | 116 | if (item_id_need_to_run == current_item_id) |
5151 | leency | 117 | { |
5404 | leency | 118 | icon_char_pos = strchr(key_value, ','); |
119 | if (icon_char_pos) ESBYTE[key_value + icon_char_pos - 1] = 0; //delete icon from string |
||
5403 | leency | 120 | RunProgram(key_value, ""); |
5151 | leency | 121 | } |
5403 | leency | 122 | current_item_id++; |
5151 | leency | 123 | return 1; |
124 | } |
||
4870 | leency | 125 | |
5151 | leency | 126 | |
5403 | leency | 127 | byte draw_icons_from_section(dword key_value, key_name, sec_name, f_name) |
5151 | leency | 128 | { |
129 | int tmp; |
||
5403 | leency | 130 | int icon_id; |
5151 | leency | 131 | |
132 | if (col==col_max) { |
||
133 | row++; |
||
134 | col=0; |
||
135 | } |
||
5404 | leency | 136 | if (col==0) DrawBar(0, row * cell_h + list_pos, Form.cwidth, cell_h, LIST_BACKGROUND_COLOR); |
137 | DefineButton(col*cell_w+6,row*cell_h + list_pos,cell_w,cell_h-5,current_item_id + 100 + BT_HIDE,0); |
||
138 | tmp = cell_w/2; |
||
5403 | leency | 139 | icon_id = atoi(key_value + strchr(key_value, ',')); |
5404 | leency | 140 | img_draw stdcall(skin.image, col*cell_w+tmp-10, row*cell_h+5 + list_pos, 32, 32, 0, icon_id*32); |
141 | WriteTextCenter(col*cell_w+7,row*cell_h+47 + list_pos,cell_w,0xD4D4d4,key_name); |
||
142 | WriteTextCenter(col*cell_w+6,row*cell_h+46 + list_pos,cell_w,0x000000,key_name); |
||
5403 | leency | 143 | current_item_id++; |
5151 | leency | 144 | col++; |
145 | return 1; |
||
146 | } |
||
147 | |||
5403 | leency | 148 | |
149 | byte draw_section(dword sec_name, f_name) |
||
4870 | leency | 150 | { |
5403 | leency | 151 | if (strcmp(sec_name, "Config")==0) return 1; |
4870 | leency | 152 | |
5404 | leency | 153 | if (item_id_need_to_run!=-1) |
5403 | leency | 154 | { |
155 | ini_enum_keys stdcall (f_name, sec_name, #search_for_id_need_to_run); |
||
156 | } |
||
157 | else |
||
158 | { |
||
159 | row++; |
||
160 | col = 0; |
||
5404 | leency | 161 | DrawBar(0, row * cell_h + list_pos, Form.cwidth , 20, LIST_BACKGROUND_COLOR); |
162 | WriteTextB(10, row * cell_h + 9 + list_pos, 0x90, 0x000000, sec_name); |
||
5403 | leency | 163 | list_pos += 20; |
164 | ini_enum_keys stdcall (f_name, sec_name, #draw_icons_from_section); |
||
165 | } |
||
166 | return 1; |
||
4870 | leency | 167 | } |
168 | |||
5403 | leency | 169 | void draw_top_bar() |
170 | { |
||
171 | int top_position = 25; |
||
172 | DrawBar(0,0,Form.cwidth, top_position-1, sc.work); |
||
173 | DrawBar(0,top_position-1, Form.cwidth, 1, sc.work_graph); |
||
174 | WriteTextB(Form.cwidth/2-70, 9, 0x90, sc.work_text, #window_title); |
||
175 | list_top = top_position; |
||
176 | list_pos = list_top; |
||
177 | row = -1; |
||
178 | } |
||
4870 | leency | 179 | |
180 | |||
5403 | leency | 181 | |
4870 | leency | 182 | stop:> |