Rev 5709 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
5465 | leency | 1 | //flac |
2 | //do not open multiple threads |
||
3 | //edit list manually |
||
4 | |||
5 | |||
6 | #define MEMSIZE 0xFFFFF |
||
7 | #include "..\lib\kolibri.h" |
||
8 | #include "..\lib\mem.h" |
||
9 | #include "..\lib\strings.h" |
||
10 | #include "..\lib\dll.h" |
||
11 | #include "..\lib\file_system.h" |
||
12 | #include "..\lib\list_box.h" |
||
5499 | leency | 13 | #include "..\lib\gui.h" |
5465 | leency | 14 | |
5499 | leency | 15 | #include "..\lib\obj\box_lib.h" |
16 | #include "..\lib\obj\libio_lib.h" |
||
17 | #include "..\lib\obj\libimg_lib.h" |
||
18 | #include "..\lib\obj\libini.h" |
||
5465 | leency | 19 | |
20 | #include "..\lib\patterns\libimg_load_skin.h" |
||
21 | |||
22 | scroll_bar scroll1 = { 5,200,398,44,0,2,115,15,0,0xeeeeee,0xBBBbbb,0xeeeeee,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1}; |
||
23 | llist list; |
||
24 | proc_info Form; |
||
25 | |||
26 | char pixie_ini_path[4096]; |
||
27 | |||
28 | enum { |
||
29 | BUTTON_WINDOW_CLOSE = 1, |
||
30 | BUTTON_WINDOW_MINIMIZE, |
||
31 | BUTTON_WINDOW_REDUCE, |
||
32 | BUTTON_PLAYBACK_PLAY_PAUSE = 10, |
||
33 | BUTTON_PLAYBACK_PREV, |
||
34 | BUTTON_PLAYBACK_NEXT |
||
35 | }; |
||
36 | |||
37 | int player_run_id, |
||
38 | notify_run_id; |
||
39 | |||
40 | int current_playing_file_n; |
||
41 | |||
5509 | leency | 42 | word win_x_normal, win_y_normal; |
43 | word win_x_small, win_y_small; |
||
5465 | leency | 44 | |
45 | byte window_mode; |
||
46 | enum { |
||
47 | WINDOW_MODE_NORMAL, |
||
48 | WINDOW_MODE_SMALL |
||
49 | }; |
||
50 | |||
51 | |||
52 | byte playback_mode; |
||
53 | enum { |
||
54 | PLAYBACK_MODE_STOPED, |
||
55 | PLAYBACK_MODE_PLAYING |
||
56 | }; |
||
57 | |||
58 | byte current_theme; |
||
59 | enum { |
||
60 | THEME_DARK, |
||
61 | THEME_LIGHT |
||
62 | }; |
||
63 | |||
5548 | leency | 64 | char work_folder[4096], |
65 | current_filename[256]; |
||
5465 | leency | 66 | |
5548 | leency | 67 | |
5465 | leency | 68 | #include "get_files_list.h" |
69 | #include "settings.h" |
||
70 | #include "check_default_player.h" |
||
71 | |||
72 | |||
73 | void main() |
||
74 | { |
||
5705 | punk_joker | 75 | int id; |
76 | |||
5640 | pavelyakov | 77 | byte mouse_clicked; |
78 | dword tmp_x,tmp_y; |
||
79 | dword z1,z2; |
||
80 | |||
5465 | leency | 81 | mem_Init(); |
82 | SetEventMask(0x27); |
||
5626 | leency | 83 | load_dll(boxlib, #box_lib_init,0); |
5627 | leency | 84 | load_dll(libio, #libio_init,1); |
5626 | leency | 85 | load_dll(libimg, #libimg_init,1); |
86 | load_dll(libini, #lib_init,1); |
||
5465 | leency | 87 | |
88 | id = abspath("pixie.ini"); |
||
89 | strcpy(#pixie_ini_path, id); |
||
90 | LoadIniConfig(); |
||
91 | CheckDefaultForTheFirstStart(); |
||
92 | if (param) |
||
93 | { |
||
94 | strcpy(#work_folder, #param); |
||
95 | work_folder[strrchr(#work_folder, '/')-1]='\0'; |
||
96 | } |
||
5548 | leency | 97 | if (work_folder) |
98 | { |
||
99 | OpenDirectory(#work_folder); |
||
100 | SetOpenedFileFirst(#param); |
||
101 | } |
||
5465 | leency | 102 | |
103 | StartPlayingMp3(); |
||
5709 | leency | 104 | list.SetSizes(1, skin.h, skin.w-1, 198, 18); |
5465 | leency | 105 | if (list.count <= list.visible) |
106 | { |
||
107 | list.h = list.count * list.line_h; |
||
108 | list.visible = list.count; |
||
109 | } |
||
110 | else |
||
111 | { |
||
112 | list.w -= scroll1.size_x; |
||
113 | } |
||
114 | |||
115 | loop() |
||
116 | { |
||
5640 | pavelyakov | 117 | WaitEventTimeout(10); |
118 | |||
119 | //ActivateWindow(Form.ID); |
||
5465 | leency | 120 | switch(EAX & 0xFF) { |
121 | case evMouse: |
||
122 | if (!CheckActiveProcess(Form.ID)) break; |
||
5640 | pavelyakov | 123 | mouse.get(); |
5465 | leency | 124 | scrollbar_v_mouse (#scroll1); |
5640 | pavelyakov | 125 | if (list.first != scroll1.position) |
5465 | leency | 126 | { |
127 | list.first = scroll1.position; |
||
128 | DrawPlayList(); |
||
129 | break; |
||
130 | } |
||
5640 | pavelyakov | 131 | if(mouse.down) |
5465 | leency | 132 | { |
5640 | pavelyakov | 133 | if (mouse.vert) if (list.MouseScroll(mouse.vert)) |
134 | { |
||
135 | DrawPlayList(); |
||
136 | } |
||
137 | if (list.MouseOver(mouse.x, mouse.y)) mouse_clicked = true; |
||
138 | else if(mouse.y < skin.h) && (mouse.x < 13) |
||
139 | { |
||
140 | //drag window - emulate windows header |
||
141 | tmp_x = mouse.x; |
||
142 | tmp_y = mouse.y; |
||
143 | do { |
||
144 | mouse.get(); |
||
145 | if (tmp_x!=mouse.x) || (tmp_y!=mouse.y) |
||
146 | { |
||
147 | z1 = Form.left + mouse.x - tmp_x; |
||
148 | z2 = Form.top + mouse.y - tmp_y; |
||
149 | if(z1<=10)z1=0; |
||
150 | if(z2<=10)z2=0; |
||
151 | if(z1>screen.width-Form.width-10)z1=screen.width-Form.width; |
||
152 | if(z2>screen.height-Form.height-10)z2=screen.height-Form.height; |
||
153 | //if(z2<10)z2=0; |
||
154 | MoveSize(z1 , z2, OLD, OLD); |
||
155 | DrawWindow(); |
||
156 | } |
||
157 | pause(1); |
||
158 | } while (mouse.lkm); |
||
159 | if (mouse.pkm) && (mouse.y > skin.h) |
||
160 | notify("'Pixies Player v1.11\nChange sound volume: Left/Right key\nChange skin: F1/F2\nMute: M key' -St\n"); |
||
161 | break; |
||
162 | } |
||
163 | else if(mouse.up) |
||
164 | { |
||
165 | if (mouse_clicked)&&(list.ProcessMouse(mouse.x, mouse.y)) |
||
5465 | leency | 166 | { |
5640 | pavelyakov | 167 | StartPlayingMp3(); |
168 | mouse_clicked = false; |
||
5465 | leency | 169 | } |
5640 | pavelyakov | 170 | break; |
171 | } |
||
5465 | leency | 172 | } |
173 | case evButton: |
||
174 | id=GetButtonID(); |
||
175 | switch(id) { |
||
176 | case BUTTON_WINDOW_CLOSE: |
||
177 | StopPlayingMp3(); |
||
178 | SaveIniConfig(); |
||
179 | ExitProcess(); |
||
180 | break; |
||
181 | case BUTTON_WINDOW_MINIMIZE: |
||
182 | MinimizeWindow(); |
||
183 | break; |
||
184 | case BUTTON_WINDOW_REDUCE: |
||
185 | if (window_mode == WINDOW_MODE_NORMAL) |
||
186 | { |
||
187 | window_mode = WINDOW_MODE_SMALL; |
||
5509 | leency | 188 | win_x_normal = Form.left; |
189 | win_y_normal = Form.top; |
||
5465 | leency | 190 | MoveSize(OLD, OLD, 99, skin.h - 1); |
5509 | leency | 191 | MoveSize(OLD, win_y_small, OLD, OLD); |
192 | MoveSize(win_x_small, OLD, OLD, OLD); |
||
5465 | leency | 193 | } |
194 | else |
||
195 | { |
||
196 | window_mode = WINDOW_MODE_NORMAL; |
||
5509 | leency | 197 | win_x_small = Form.left; |
198 | win_y_small = Form.top; |
||
199 | MoveSize(win_x_normal, win_y_normal, skin.w -1 ,skin.h + list.h); |
||
5465 | leency | 200 | } |
201 | break; |
||
202 | case BUTTON_PLAYBACK_PREV: |
||
5509 | leency | 203 | if (list.KeyUp()) { |
204 | current_playing_file_n = list.current; |
||
205 | StartPlayingMp3(); |
||
206 | } |
||
5465 | leency | 207 | break; |
208 | case BUTTON_PLAYBACK_NEXT: |
||
5509 | leency | 209 | if (list.KeyDown()) |
210 | { |
||
211 | current_playing_file_n = list.current; |
||
212 | StartPlayingMp3(); |
||
213 | } |
||
5465 | leency | 214 | break; |
215 | case BUTTON_PLAYBACK_PLAY_PAUSE: |
||
216 | if (playback_mode == PLAYBACK_MODE_PLAYING) |
||
217 | { |
||
218 | playback_mode = PLAYBACK_MODE_STOPED; |
||
219 | DrawInactivePlayButton(); |
||
220 | StopPlayingMp3(); |
||
221 | } |
||
222 | else |
||
223 | { |
||
224 | playback_mode = PLAYBACK_MODE_PLAYING; |
||
225 | StartPlayingMp3(); |
||
226 | } |
||
227 | break; |
||
228 | } |
||
229 | break; |
||
230 | |||
231 | case evKey: |
||
5706 | leency | 232 | GetKeys(); |
5705 | punk_joker | 233 | |
234 | if (key_scancode==003) SetColorThemeLight(); |
||
235 | if (key_scancode==004) SetColorThemeDark(); |
||
236 | if (key_scancode==SCAN_CODE_LEFT) RunProgram("@VOLUME", "-"); |
||
237 | if (key_scancode==SCAN_CODE_RIGHT) RunProgram("@VOLUME", "+"); |
||
238 | if (key_scancode==050) RunProgram("@VOLUME", "m"); |
||
239 | if (key_scancode==SCAN_CODE_ENTER) StartPlayingMp3(); |
||
240 | if (key_scancode==025) || (key_scancode==SCAN_CODE_SPACE) |
||
5465 | leency | 241 | { |
242 | if (playback_mode == PLAYBACK_MODE_PLAYING) StopPlayingMp3(); |
||
243 | else StartPlayingMp3(); |
||
244 | } |
||
5705 | punk_joker | 245 | if (list.ProcessKey(key_scancode)) DrawPlayList(); |
5465 | leency | 246 | break; |
247 | |||
248 | case evReDraw: |
||
5640 | pavelyakov | 249 | if (window_mode == WINDOW_MODE_NORMAL) DefineAndDrawWindow(win_x_normal, win_y_normal, skin.w - 1, skin.h + list.h, 0x41,0,0,0); |
250 | if (window_mode == WINDOW_MODE_SMALL) DefineAndDrawWindow(win_x_small, win_y_small, 99, skin.h - 1, 0x41,0,0,0); |
||
5465 | leency | 251 | DrawWindow(); |
252 | break; |
||
253 | |||
254 | default: |
||
255 | if (playback_mode == PLAYBACK_MODE_PLAYING) && (GetProcessSlot(player_run_id)==0) |
||
256 | { |
||
257 | if (current_playing_file_n < list.count) |
||
258 | { |
||
5509 | leency | 259 | current_playing_file_n = list.current; |
5548 | leency | 260 | if (list.KeyDown()) StartPlayingMp3(); |
5465 | leency | 261 | } |
262 | else |
||
263 | { |
||
264 | StopPlayingMp3(); |
||
265 | DrawWindow(); |
||
266 | } |
||
267 | } |
||
268 | } |
||
269 | } |
||
270 | } |
||
271 | |||
272 | |||
273 | void DrawPlayList() |
||
274 | { |
||
275 | int i; |
||
276 | int yyy; |
||
5548 | leency | 277 | char temp_filename[4096]; |
5465 | leency | 278 | |
279 | for (i=0; i |
||
280 | { |
||
281 | strcpy(#temp_filename, files_mas[i + list.first] * 304 + buf + 72); |
||
282 | temp_filename[strlen(#temp_filename)-4] = '\0'; |
||
283 | if (strlen(#temp_filename)>47) strcpy(#temp_filename+44, "..."); |
||
284 | |||
285 | yyy = i*list.line_h+list.y; |
||
286 | |||
287 | //this is selected file |
||
288 | if (list.current - list.first == i) |
||
289 | { |
||
290 | if (i>=list.count) continue; |
||
291 | DrawBar(list.x, yyy, list.w, list.line_h, theme.color_list_active_bg); |
||
292 | WriteText(12,yyy+list.text_y,0x80, theme.color_list_active_text, #temp_filename); |
||
293 | } |
||
294 | //this is not selected file |
||
295 | else |
||
296 | { |
||
297 | if (i>=list.count) continue; |
||
298 | DrawBar(list.x,yyy,list.w, list.line_h, theme.color_list_bg); |
||
299 | WriteText(12,yyy+list.text_y,0x80, theme.color_list_text, #temp_filename); |
||
300 | } |
||
301 | //this is current playing file |
||
302 | if (i + list.first == current_playing_file_n) && (playback_mode == PLAYBACK_MODE_PLAYING) |
||
303 | { |
||
304 | WriteText(3, yyy+list.text_y,0x80, theme.color_list_active_pointer, "\x10"); |
||
305 | WriteText(12,yyy+list.text_y,0x80, theme.color_list_active_text, #temp_filename); |
||
306 | } |
||
307 | } |
||
308 | DrawBar(list.x,list.visible * list.line_h + list.y, list.w, -list.visible * list.line_h + list.h, theme.color_list_bg); |
||
309 | DrawScroller(); |
||
310 | } |
||
311 | |||
312 | |||
313 | void StopPlayingMp3() |
||
314 | { |
||
315 | if (player_run_id) player_run_id = KillProcess(player_run_id); |
||
316 | if (notify_run_id) notify_run_id = KillProcess(notify_run_id); |
||
317 | playback_mode = PLAYBACK_MODE_STOPED; |
||
318 | } |
||
319 | |||
320 | |||
321 | void StartPlayingMp3() |
||
322 | { |
||
323 | word i; |
||
324 | char item_path[4096], notify_message[512]; |
||
325 | dword item_path_end_pointer; |
||
326 | StopPlayingMp3(); |
||
327 | |||
328 | if (list.current > list.count) |
||
329 | { |
||
330 | list.current = list.count; |
||
331 | return; |
||
332 | } |
||
333 | if (!list.count) |
||
334 | { |
||
335 | notify_run_id = notify("'Pixie Player\nStopped, no file specified' -St"); |
||
336 | return; |
||
337 | } |
||
338 | |||
339 | current_playing_file_n = list.current; |
||
340 | |||
341 | playback_mode = PLAYBACK_MODE_PLAYING; |
||
342 | |||
343 | strlcpy(#current_filename, GetCurrentItemName(), sizeof(current_filename)); |
||
344 | strcpy(#item_path, "\""); |
||
345 | strcat(#item_path, #work_folder); |
||
346 | strcat(#item_path, "/"); |
||
347 | strcat(#item_path, #current_filename); |
||
348 | strcat(#item_path, "\""); |
||
349 | |||
350 | DrawPlayList(); |
||
351 | DrawTopPanel(); |
||
352 | |||
353 | item_path_end_pointer = #item_path+strlen(#item_path); |
||
354 | if (strcmpi(item_path_end_pointer-4,".mp3")!=0) player_run_id = RunProgram(abspath("minimp3"), #item_path); |
||
355 | strcpy(#notify_message, "'Now playing:\n"); |
||
356 | strcat(#notify_message, #current_filename); |
||
357 | for (i=2; i |
||
358 | strcat(#notify_message, "' -St"); |
||
359 | notify_run_id = notify(#notify_message); |
||
360 | } |
||
361 | |||
362 | |||
363 | void DrawInactivePlayButton() |
||
364 | { |
||
365 | img_draw stdcall(skin.image, 13, 0, 22, skin.h, 300, 0); |
||
366 | } |
||
367 | |||
368 | void DrawWindow() { |
||
369 | GetProcessInfo(#Form, SelfInfo); |
||
370 | DrawTopPanel(); |
||
371 | IF (Form.status_window>=2) return; |
||
372 | if (window_mode == WINDOW_MODE_NORMAL) |
||
373 | { |
||
374 | DrawListBorder(0, skin.h-1, skin.w-1, list.h+1, theme.color_list_border); |
||
375 | DrawPlayList(); |
||
376 | } |
||
377 | } |
||
378 | |||
379 | |||
380 | void DrawTopPanel() |
||
381 | { |
||
382 | char current_playing_title[245]; |
||
383 | img_draw stdcall(skin.image, 0, 0, Form.width - 14, skin.h, 0, 0); |
||
384 | img_draw stdcall(skin.image, Form.width - 14, 0, 15, skin.h, skin.w - 15, 0); |
||
385 | if (playback_mode == PLAYBACK_MODE_STOPED) DrawInactivePlayButton(); |
||
386 | //Playing control buttons |
||
387 | DefineButton(13, 1, 21, 21, BUTTON_PLAYBACK_PLAY_PAUSE + BT_HIDE, 0); |
||
388 | DefineButton(36, 1, 21, 21, BUTTON_PLAYBACK_PREV + BT_HIDE, 0); |
||
389 | DefineButton(60, 1, 21, 21, BUTTON_PLAYBACK_NEXT + BT_HIDE, 0); |
||
390 | //Window control buttons |
||
391 | DefineButton(Form.width - 14, 1, 11, 11, BUTTON_WINDOW_CLOSE + BT_HIDE, 0); |
||
392 | DefineButton(Form.width - 14, 12, 12, 11, BUTTON_WINDOW_REDUCE + BT_HIDE, 0); |
||
393 | //Mode depended |
||
394 | if (window_mode == WINDOW_MODE_NORMAL) |
||
395 | { |
||
396 | DefineButton(Form.width - 26, 1, 12, 11, BUTTON_WINDOW_MINIMIZE + BT_HIDE, 0); |
||
397 | strcpy(#current_playing_title, #current_filename); |
||
398 | current_playing_title[strlen(#current_playing_title)-4] = '\0'; |
||
399 | if (strlen(#current_playing_title) > 29) strcpy(#current_playing_title + 26, "..."); |
||
400 | WriteText(90, 9, 0x80, theme.color_top_panel_text, #current_playing_title); |
||
401 | } |
||
402 | else |
||
403 | { |
||
404 | DefineButton(0, 0, 12, skin.h, 99 + BT_HIDE + BT_NOFRAME, 0); |
||
405 | } |
||
406 | } |
||
407 | |||
408 | |||
409 | void DrawScroller() |
||
410 | { |
||
411 | scroll1.max_area = list.count; |
||
412 | scroll1.cur_area = list.visible; |
||
413 | scroll1.position = list.first; |
||
414 | |||
415 | scroll1.all_redraw = 0; |
||
416 | scroll1.start_x = skin.w - scroll1.size_x - 1; |
||
417 | scroll1.start_y = list.y-1; |
||
418 | scroll1.size_y = list.h+2; |
||
419 | |||
420 | if (list.count > list.visible) scrollbar_v_draw(#scroll1); |
||
421 | } |
||
422 | |||
423 | void DrawListBorder(dword x,y,w,h,color1) |
||
424 | { |
||
425 | DrawBar(x,y+h,w,1,color1); |
||
426 | DrawBar(x,y,1,h,color1); |
||
427 | DrawBar(x+w,y,1,h+1,color1); |
||
428 | } |
||
429 | |||
430 | |||
431 | stop: |
||
432 | |||
433 | char menu_stak[4096];>10)z2=0; |