Subversion Repositories Kolibri OS

Rev

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