Subversion Repositories Kolibri OS

Rev

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