Rev 5465 | 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 | //open last folder at start up |
||
3 | //do not open multiple threads |
||
4 | //edit list manually |
||
5 | |||
6 | |||
7 | #define MEMSIZE 0xFFFFF |
||
8 | #include "..\lib\kolibri.h" |
||
9 | #include "..\lib\mem.h" |
||
10 | #include "..\lib\strings.h" |
||
11 | #include "..\lib\dll.h" |
||
12 | #include "..\lib\file_system.h" |
||
13 | #include "..\lib\list_box.h" |
||
5499 | leency | 14 | #include "..\lib\gui.h" |
5465 | leency | 15 | |
5499 | leency | 16 | #include "..\lib\obj\box_lib.h" |
17 | #include "..\lib\obj\libio_lib.h" |
||
18 | #include "..\lib\obj\libimg_lib.h" |
||
19 | #include "..\lib\obj\libini.h" |
||
5465 | leency | 20 | |
21 | #include "..\lib\patterns\libimg_load_skin.h" |
||
22 | |||
23 | 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}; |
||
24 | llist list; |
||
25 | proc_info Form; |
||
26 | libimg_image skin; |
||
27 | |||
28 | char pixie_ini_path[4096]; |
||
29 | |||
30 | enum { |
||
31 | BUTTON_WINDOW_CLOSE = 1, |
||
32 | BUTTON_WINDOW_MINIMIZE, |
||
33 | BUTTON_WINDOW_REDUCE, |
||
34 | BUTTON_PLAYBACK_PLAY_PAUSE = 10, |
||
35 | BUTTON_PLAYBACK_PREV, |
||
36 | BUTTON_PLAYBACK_NEXT |
||
37 | }; |
||
38 | |||
39 | int player_run_id, |
||
40 | notify_run_id; |
||
41 | |||
42 | int current_playing_file_n; |
||
43 | |||
44 | word win_x, win_y; |
||
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) |
||
146 | notify("'Pixies Player v1.01\nChange sound volume: Left/Right key\nChange skin: F1/F2\nMute: M key' -St\n"); |
||
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; |
||
164 | MoveSize(OLD, OLD, 99, skin.h - 1); |
||
165 | MoveSize(OLD, GetClientHeight() - skin.h + 1, OLD, OLD); |
||
166 | MoveSize(2000, OLD, OLD, OLD); |
||
167 | } |
||
168 | else |
||
169 | { |
||
170 | window_mode = WINDOW_MODE_NORMAL; |
||
171 | MoveSize(30,80,skin.w -1 ,skin.h + list.h); |
||
172 | } |
||
173 | break; |
||
174 | case BUTTON_PLAYBACK_PREV: |
||
175 | if (list.KeyUp()) StartPlayingMp3(); |
||
176 | break; |
||
177 | case BUTTON_PLAYBACK_NEXT: |
||
178 | if (list.KeyDown()) StartPlayingMp3(); |
||
179 | break; |
||
180 | case BUTTON_PLAYBACK_PLAY_PAUSE: |
||
181 | if (playback_mode == PLAYBACK_MODE_PLAYING) |
||
182 | { |
||
183 | playback_mode = PLAYBACK_MODE_STOPED; |
||
184 | DrawInactivePlayButton(); |
||
185 | StopPlayingMp3(); |
||
186 | } |
||
187 | else |
||
188 | { |
||
189 | playback_mode = PLAYBACK_MODE_PLAYING; |
||
190 | StartPlayingMp3(); |
||
191 | } |
||
192 | break; |
||
193 | } |
||
194 | break; |
||
195 | |||
196 | case evKey: |
||
197 | key = GetKey(); |
||
198 | if (key==50) SetColorThemeLight(); |
||
199 | if (key==51) SetColorThemeDark(); |
||
200 | if (key==ASCII_KEY_LEFT) RunProgram("@VOLUME", "-"); |
||
201 | if (key==ASCII_KEY_RIGHT) RunProgram("@VOLUME", "+"); |
||
202 | if (key=='m') RunProgram("@VOLUME", "m"); |
||
203 | if (key==ASCII_KEY_ENTER) StartPlayingMp3(); |
||
204 | if (key=='p') || (key==ASCII_KEY_SPACE) |
||
205 | { |
||
206 | if (playback_mode == PLAYBACK_MODE_PLAYING) StopPlayingMp3(); |
||
207 | else StartPlayingMp3(); |
||
208 | } |
||
209 | if (list.ProcessKey(key)) DrawPlayList(); |
||
210 | break; |
||
211 | |||
212 | case evReDraw: |
||
213 | if (window_mode == WINDOW_MODE_NORMAL) DefineAndDrawWindow(win_x, win_y, skin.w - 1, skin.h + list.h, 0x01,0,0,0); |
||
214 | if (window_mode == WINDOW_MODE_SMALL) DefineAndDrawWindow(win_x, win_y, 99, skin.h - 1, 0x01,0,0,0); |
||
215 | DrawWindow(); |
||
216 | break; |
||
217 | |||
218 | default: |
||
219 | if (playback_mode == PLAYBACK_MODE_PLAYING) && (GetProcessSlot(player_run_id)==0) |
||
220 | { |
||
221 | if (current_playing_file_n < list.count) |
||
222 | { |
||
223 | //пиздец тут быдлокод пошёл |
||
224 | id = list.current; |
||
225 | current_playing_file_n++; |
||
226 | list.current = current_playing_file_n; |
||
227 | StartPlayingMp3(); |
||
228 | list.current = id; |
||
229 | DrawPlayList(); |
||
230 | } |
||
231 | else |
||
232 | { |
||
233 | StopPlayingMp3(); |
||
234 | DrawWindow(); |
||
235 | } |
||
236 | } |
||
237 | } |
||
238 | } |
||
239 | } |
||
240 | |||
241 | |||
242 | void DrawPlayList() |
||
243 | { |
||
244 | int i; |
||
245 | int yyy; |
||
246 | |||
247 | for (i=0; i |
||
248 | { |
||
249 | strcpy(#temp_filename, files_mas[i + list.first] * 304 + buf + 72); |
||
250 | temp_filename[strlen(#temp_filename)-4] = '\0'; |
||
251 | if (strlen(#temp_filename)>47) strcpy(#temp_filename+44, "..."); |
||
252 | |||
253 | yyy = i*list.line_h+list.y; |
||
254 | |||
255 | //this is selected file |
||
256 | if (list.current - list.first == i) |
||
257 | { |
||
258 | if (i>=list.count) continue; |
||
259 | DrawBar(list.x, yyy, list.w, list.line_h, theme.color_list_active_bg); |
||
260 | WriteText(12,yyy+list.text_y,0x80, theme.color_list_active_text, #temp_filename); |
||
261 | } |
||
262 | //this is not selected file |
||
263 | else |
||
264 | { |
||
265 | if (i>=list.count) continue; |
||
266 | DrawBar(list.x,yyy,list.w, list.line_h, theme.color_list_bg); |
||
267 | WriteText(12,yyy+list.text_y,0x80, theme.color_list_text, #temp_filename); |
||
268 | } |
||
269 | //this is current playing file |
||
270 | if (i + list.first == current_playing_file_n) && (playback_mode == PLAYBACK_MODE_PLAYING) |
||
271 | { |
||
272 | WriteText(3, yyy+list.text_y,0x80, theme.color_list_active_pointer, "\x10"); |
||
273 | WriteText(12,yyy+list.text_y,0x80, theme.color_list_active_text, #temp_filename); |
||
274 | } |
||
275 | } |
||
276 | DrawBar(list.x,list.visible * list.line_h + list.y, list.w, -list.visible * list.line_h + list.h, theme.color_list_bg); |
||
277 | DrawScroller(); |
||
278 | } |
||
279 | |||
280 | |||
281 | void StopPlayingMp3() |
||
282 | { |
||
283 | if (player_run_id) player_run_id = KillProcess(player_run_id); |
||
284 | if (notify_run_id) notify_run_id = KillProcess(notify_run_id); |
||
285 | playback_mode = PLAYBACK_MODE_STOPED; |
||
286 | } |
||
287 | |||
288 | |||
289 | void StartPlayingMp3() |
||
290 | { |
||
291 | word i; |
||
292 | char item_path[4096], notify_message[512]; |
||
293 | dword item_path_end_pointer; |
||
294 | StopPlayingMp3(); |
||
295 | |||
296 | if (list.current > list.count) |
||
297 | { |
||
298 | list.current = list.count; |
||
299 | return; |
||
300 | } |
||
301 | if (!list.count) |
||
302 | { |
||
303 | notify_run_id = notify("'Pixie Player\nStopped, no file specified' -St"); |
||
304 | return; |
||
305 | } |
||
306 | |||
307 | current_playing_file_n = list.current; |
||
308 | |||
309 | playback_mode = PLAYBACK_MODE_PLAYING; |
||
310 | |||
311 | strlcpy(#current_filename, GetCurrentItemName(), sizeof(current_filename)); |
||
312 | strcpy(#item_path, "\""); |
||
313 | strcat(#item_path, #work_folder); |
||
314 | strcat(#item_path, "/"); |
||
315 | strcat(#item_path, #current_filename); |
||
316 | strcat(#item_path, "\""); |
||
317 | |||
318 | DrawPlayList(); |
||
319 | DrawTopPanel(); |
||
320 | |||
321 | item_path_end_pointer = #item_path+strlen(#item_path); |
||
322 | if (strcmpi(item_path_end_pointer-4,".mp3")!=0) player_run_id = RunProgram(abspath("minimp3"), #item_path); |
||
323 | strcpy(#notify_message, "'Now playing:\n"); |
||
324 | strcat(#notify_message, #current_filename); |
||
325 | for (i=2; i |
||
326 | strcat(#notify_message, "' -St"); |
||
327 | notify_run_id = notify(#notify_message); |
||
328 | } |
||
329 | |||
330 | |||
331 | void DrawInactivePlayButton() |
||
332 | { |
||
333 | img_draw stdcall(skin.image, 13, 0, 22, skin.h, 300, 0); |
||
334 | } |
||
335 | |||
336 | void DrawWindow() { |
||
337 | GetProcessInfo(#Form, SelfInfo); |
||
338 | DrawTopPanel(); |
||
339 | IF (Form.status_window>=2) return; |
||
340 | if (window_mode == WINDOW_MODE_NORMAL) |
||
341 | { |
||
342 | DrawListBorder(0, skin.h-1, skin.w-1, list.h+1, theme.color_list_border); |
||
343 | DrawPlayList(); |
||
344 | } |
||
345 | } |
||
346 | |||
347 | |||
348 | void DrawTopPanel() |
||
349 | { |
||
350 | char current_playing_title[245]; |
||
351 | img_draw stdcall(skin.image, 0, 0, Form.width - 14, skin.h, 0, 0); |
||
352 | img_draw stdcall(skin.image, Form.width - 14, 0, 15, skin.h, skin.w - 15, 0); |
||
353 | if (playback_mode == PLAYBACK_MODE_STOPED) DrawInactivePlayButton(); |
||
354 | //Playing control buttons |
||
355 | DefineButton(13, 1, 21, 21, BUTTON_PLAYBACK_PLAY_PAUSE + BT_HIDE, 0); |
||
356 | DefineButton(36, 1, 21, 21, BUTTON_PLAYBACK_PREV + BT_HIDE, 0); |
||
357 | DefineButton(60, 1, 21, 21, BUTTON_PLAYBACK_NEXT + BT_HIDE, 0); |
||
358 | //Window control buttons |
||
359 | DefineButton(Form.width - 14, 1, 11, 11, BUTTON_WINDOW_CLOSE + BT_HIDE, 0); |
||
360 | DefineButton(Form.width - 14, 12, 12, 11, BUTTON_WINDOW_REDUCE + BT_HIDE, 0); |
||
361 | //Mode depended |
||
362 | if (window_mode == WINDOW_MODE_NORMAL) |
||
363 | { |
||
364 | DefineButton(Form.width - 26, 1, 12, 11, BUTTON_WINDOW_MINIMIZE + BT_HIDE, 0); |
||
365 | strcpy(#current_playing_title, #current_filename); |
||
366 | current_playing_title[strlen(#current_playing_title)-4] = '\0'; |
||
367 | if (strlen(#current_playing_title) > 29) strcpy(#current_playing_title + 26, "..."); |
||
368 | WriteText(90, 9, 0x80, theme.color_top_panel_text, #current_playing_title); |
||
369 | } |
||
370 | else |
||
371 | { |
||
372 | DefineButton(0, 0, 12, skin.h, 99 + BT_HIDE + BT_NOFRAME, 0); |
||
373 | } |
||
374 | } |
||
375 | |||
376 | |||
377 | void DrawScroller() |
||
378 | { |
||
379 | scroll1.max_area = list.count; |
||
380 | scroll1.cur_area = list.visible; |
||
381 | scroll1.position = list.first; |
||
382 | |||
383 | scroll1.all_redraw = 0; |
||
384 | scroll1.start_x = skin.w - scroll1.size_x - 1; |
||
385 | scroll1.start_y = list.y-1; |
||
386 | scroll1.size_y = list.h+2; |
||
387 | |||
388 | if (list.count > list.visible) scrollbar_v_draw(#scroll1); |
||
389 | } |
||
390 | |||
391 | void DrawListBorder(dword x,y,w,h,color1) |
||
392 | { |
||
393 | DrawBar(x,y+h,w,1,color1); |
||
394 | DrawBar(x,y,1,h,color1); |
||
395 | DrawBar(x+w,y,1,h+1,color1); |
||
396 | } |
||
397 | |||
398 | |||
399 | stop: |
||
400 | |||
401 | char menu_stak[4096];>>>>=> |