Subversion Repositories Kolibri OS

Rev

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