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