Subversion Repositories Kolibri OS

Rev

Rev 5627 | Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

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