Subversion Repositories Kolibri OS

Rev

Rev 6169 | Rev 6251 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. //11.03.12 - start!
  2. //ver 2.0
  3.  
  4. #ifndef AUTOBUILD
  5.         ?include "lang.h--"
  6. #endif
  7.  
  8. #define MEMSIZE 0xFE800
  9. #include "..\lib\mem.h"
  10. #include "..\lib\strings.h"
  11. #include "..\lib\io.h"
  12. #include "..\lib\list_box.h"
  13. #include "..\lib\menu.h"
  14. #include "..\lib\gui.h"
  15. #include "..\lib\obj\box_lib.h"
  16.  
  17.  
  18. //===================================================//
  19. //                                                   //
  20. //                       DATA                        //
  21. //                                                   //
  22. //===================================================//
  23.  
  24. #ifdef LANG_RUS
  25.         ?define WINDOW_HEADER " áâனª¨ ®ä®à¬«¥­¨ï"
  26.         ?define T_SKINS       "   ‘â¨«ì ®ª®­"
  27.         ?define T_WALLPAPERS  "   Ž¡®¨"
  28. #else
  29.         ?define WINDOW_HEADER "Appearance"
  30.         ?define T_SKINS       "   Skins"
  31.         ?define T_WALLPAPERS  "   Wallpappers"
  32. #endif
  33.  
  34. unsigned char icons[]= FROM "icons.raw";
  35.  
  36. #define PANEL_H 40
  37. #define LIST_PADDING 20
  38. #define TAB_PADDING 16
  39. #define TAB_HEIGHT 25
  40. #define SKINS_STANDART_PATH "/kolibrios/res/skins"                                                     
  41. #define WALP_STANDART_PATH "/kolibrios/res/wallpapers"
  42.  
  43. llist list;
  44. signed int active_tab, active_skin=-1, active_wallpaper=-1;
  45. enum { SKINS=2, WALLPAPERS };
  46.  
  47. char folder_path[4096];
  48. char cur_file_path[4096];
  49. char temp_filename[4096];
  50. int files_mas[400];
  51.  
  52. int cur;
  53.  
  54. proc_info Form;
  55.  
  56. scroll_bar scroll1 = { 18,200,398, 44,18,0,115,15,0,0xeeeeee,0xD2CED0,0x555555,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1};
  57.  
  58.  
  59. //===================================================//
  60. //                                                   //
  61. //                       CODE                        //
  62. //                                                   //
  63. //===================================================//
  64.  
  65. void main()
  66. {  
  67.         int id, mouse_clicked;
  68.  
  69.         SetEventMask(0x27);
  70.         load_dll(boxlib, #box_lib_init,0);
  71.         EventTabClick(SKINS);
  72.         loop() switch(WaitEvent())
  73.         {
  74.                 case evMouse:
  75.                         if (!CheckActiveProcess(Form.ID)) break;
  76.                         mouse.get();
  77.                         scrollbar_v_mouse (#scroll1);
  78.                         if (list.first != scroll1.position)
  79.                         {
  80.                                 list.first = scroll1.position;
  81.                                 Draw_List();
  82.                                 break;
  83.                         }
  84.  
  85.                         if (mouse.vert) && (list.MouseScroll(mouse.vert)) Draw_List();
  86.  
  87.                         if (mouse.up)&&(mouse_clicked)
  88.                         {
  89.                                 if (mouse.lkm) && (list.ProcessMouse(mouse.x, mouse.y)) EventApply();
  90.                                 mouse_clicked=false;
  91.                         }
  92.                         else if (mouse.down)&&(mouse.lkm) && (list.MouseOver(mouse.x, mouse.y)) mouse_clicked=true;
  93.  
  94.                         if (mouse.down)&&(mouse.pkm) {
  95.                                 list.ProcessMouse(mouse.x, mouse.y);
  96.                                 Draw_List();
  97.                                 menu.show(Form.left+mouse.x, Form.top+mouse.y+skin_height, 136, "Open file     Enter\nDelete          Del", 10);
  98.                         }
  99.  
  100.                         break;
  101.  
  102.  
  103.                 case evButton:
  104.                         id=GetButtonID();
  105.                         if (id==1) ExitProcess();
  106.                         if (id==SKINS) EventTabClick(SKINS);
  107.                         if (id==WALLPAPERS) EventTabClick(WALLPAPERS);
  108.                         break;
  109.          
  110.                 case evKey:
  111.                         GetKeys();
  112.                         if (list.ProcessKey(key_scancode)) EventApply();
  113.                         if (key_scancode==SCAN_CODE_ENTER) EventOpenFile();
  114.                         if (key_scancode==SCAN_CODE_TAB) if (active_tab==SKINS) EventTabClick(WALLPAPERS); else EventTabClick(SKINS);
  115.                         if (key_scancode==SCAN_CODE_DEL) EventDeleteFile();
  116.                         for (id=list.cur_y+1; id<list.count; id++)
  117.                         {
  118.                                 strcpy(#temp_filename, io.dir.position(files_mas[id]));
  119.                                 if (temp_filename[0]==key_ascii) || (temp_filename[0]==key_ascii-32)
  120.                                 {
  121.                                         list.cur_y = id - 1;
  122.                                         list.KeyDown();
  123.                                         EventApply();
  124.                                         break;
  125.                                 }
  126.                         }
  127.                         break;
  128.                  
  129.                  case evReDraw:
  130.                         system.color.get();                    
  131.                         DefineAndDrawWindow(screen.width-400/2,80,400,404+skin_height,0x73,0xE4DFE1,WINDOW_HEADER,0);
  132.                         GetProcessInfo(#Form, SelfInfo);
  133.                         IF (Form.status_window>=2) break;
  134.                         DrawWindowContent();
  135.                         debugi(menu.list.cur_y);
  136.                         if (menu.list.cur_y) {
  137.                                 if (menu.list.cur_y == 10) EventOpenFile();
  138.                                 if (menu.list.cur_y == 11) EventDeleteFile();
  139.                                 menu.list.cur_y = 0;
  140.                         };
  141.    }
  142. }
  143.  
  144. void DrawWindowContent()
  145. {
  146.         int id;
  147.         list.SetFont(8, 14, 0x90);
  148.         id = list.cur_y;
  149.         list.SetSizes(LIST_PADDING, PANEL_H, Form.cwidth-scroll1.size_x-LIST_PADDING-LIST_PADDING, Form.cheight-PANEL_H-LIST_PADDING, 20);
  150.         list.cur_y = id;
  151.  
  152.         DrawBar(0,0, Form.cwidth, PANEL_H-LIST_PADDING, system.color.work);
  153.         DrawRectangle3D(list.x-2, list.y-2, list.w+3+scroll1.size_x, list.h+3, system.color.work_dark, system.color.work_light);
  154.         DrawWideRectangle(list.x-LIST_PADDING, list.y-LIST_PADDING, LIST_PADDING*2+list.w+scroll1.size_x, LIST_PADDING*2+list.h, LIST_PADDING-2, system.color.work);
  155.         DrawTab(list.x+10, list.y, SKINS, T_SKINS);
  156.         if (isdir(WALP_STANDART_PATH)) DrawTab(strlen(T_SKINS)*8+TAB_PADDING+list.x+21, list.y, WALLPAPERS, T_WALLPAPERS);
  157.         DrawRectangle(list.x-1, list.y-1, list.w+1+scroll1.size_x, list.h+1, system.color.work_graph);
  158.  
  159.         Draw_List();
  160. }
  161.  
  162. void DrawTab(dword x,y, but_id, text)
  163. {
  164.         dword col_bg, col_text;
  165.         dword w=strlen(text)*8+TAB_PADDING, h=TAB_HEIGHT;
  166.         y -= h;
  167.  
  168.         if (but_id==active_tab)
  169.         {
  170.                 col_bg=system.color.work_button;
  171.                 col_text=system.color.work_button_text;
  172.         }
  173.         else
  174.         {
  175.                 col_bg=system.color.work;
  176.                 col_text=system.color.work_text;
  177.         }
  178.         DrawCaptButton(x,y, w-1,h+1, but_id, col_bg, col_text, text);
  179.         _PutImage(x+10,h-16/2+y+1,  16,15,   but_id-2*16*15*3+#icons);
  180. }
  181.  
  182. void DrawScroller()
  183. {
  184.         scroll1.bckg_col = 0xBBBbbb;
  185.         scroll1.frnt_col = system.color.work;
  186.         scroll1.line_col = system.color.work_graph;
  187.  
  188.         scroll1.max_area = list.count;
  189.         scroll1.cur_area = list.visible;
  190.         scroll1.position = list.first;
  191.  
  192.         scroll1.all_redraw=1;
  193.         scroll1.start_x = list.x + list.w;
  194.         scroll1.start_y = list.y-1;
  195.         scroll1.size_y = list.h+2;
  196.  
  197.         scrollbar_v_draw(#scroll1);
  198. }
  199.  
  200. void Open_Dir()
  201. {
  202.         int j;
  203.         list.count = 0;
  204.         if(io.dir.buffer)free(io.dir.buffer);
  205.         io.dir.load(#folder_path,DIR_ONLYREAL);
  206.         for (j=0; j<io.dir.count; j++)
  207.         {
  208.                 strcpy(#temp_filename, io.dir.position(j));
  209.                 strlwr(#temp_filename);
  210.                 if (active_tab==SKINS) if (strcmpi(#temp_filename+strlen(#temp_filename)-4,".skn")!=0) continue;
  211.                 if (active_tab==WALLPAPERS) if (strcmpi(#temp_filename+strlen(#temp_filename)-4,".txt")==0) continue;
  212.                 cur = list.count;
  213.                 files_mas[cur]=j;
  214.                 if (!strcmpi("default.skn",#temp_filename)) files_mas[0]><files_mas[list.count];
  215.                 list.count++;
  216.         }
  217. }
  218.  
  219. void Draw_List()
  220. {
  221.         int i, yyy, list_last;
  222.  
  223.         if (list.count > list.visible) list_last = list.visible; else list_last = list.count;
  224.  
  225.         for (i=0; (i<list_last); i++;)
  226.         {
  227.                 cur = list.first + i;
  228.                 strcpy(#temp_filename, io.dir.position(files_mas[cur]));
  229.                 temp_filename[strlen(#temp_filename)-4] = 0;
  230.                 yyy = i*list.item_h+list.y;
  231.                
  232.                 if (list.cur_y-list.first==i)
  233.                 {
  234.                         DrawBar(list.x, yyy, list.w, list.item_h, system.color.work_button);
  235.                         WriteText(list.x+12,yyy+list.text_y,list.font_type,system.color.work_button_text, #temp_filename);
  236.                 }
  237.                 else
  238.                 {
  239.                         DrawBar(list.x,yyy,list.w, list.item_h, 0xFFFfff);
  240.                         WriteText(list.x+12,yyy+list.text_y,list.font_type,0, #temp_filename);
  241.                 }
  242.         }
  243.         DrawBar(list.x,i*list.item_h+list.y, list.w, -i*list.item_h+ list.h, 0xFFFfff);
  244.         DrawScroller();
  245. }
  246.  
  247. //===================================================//
  248. //                                                   //
  249. //                     EVENTS                        //
  250. //                                                   //
  251. //===================================================//
  252.  
  253. void EventTabClick(int N)
  254. {
  255.         active_tab = N;
  256.         if (active_tab == SKINS)
  257.         {
  258.                 active_wallpaper = list.cur_y;
  259.                 strcpy(#folder_path, SKINS_STANDART_PATH);
  260.                 list.ClearList();
  261.                 Open_Dir();
  262.                 if (!list.count) notify("'No skins were found' -E");
  263.                 list.cur_y = active_skin;
  264.         }
  265.         if (active_tab == WALLPAPERS)
  266.         {
  267.                 active_skin = list.cur_y;
  268.                 strcpy(#folder_path, WALP_STANDART_PATH);
  269.                 list.ClearList();
  270.                 Open_Dir();
  271.                 if (!list.count) notify("'No wallpapers were found' -E");
  272.                 list.cur_y = active_wallpaper;
  273.         }
  274.         if (list.w) DrawWindowContent();
  275. }
  276.  
  277. void EventDeleteFile()
  278. {
  279.         io.del(#cur_file_path);
  280.         Open_Dir();
  281.         EventApply();
  282. }
  283.  
  284. void EventApply()
  285. {
  286.         if (active_tab==SKINS)
  287.         {
  288.                 cur = list.cur_y;
  289.                 sprintf(#cur_file_path,"%s/%s",#folder_path,io.dir.position(files_mas[cur]));
  290.                 SetSystemSkin(#cur_file_path);
  291.         }
  292.         if (active_tab==WALLPAPERS)
  293.         {
  294.                 cur = list.cur_y;
  295.                 sprintf(#cur_file_path,"\\S__%s/%s",#folder_path,io.dir.position(files_mas[cur]));
  296.                 RunProgram("/sys/media/kiv", #cur_file_path);
  297.                 Draw_List();
  298.         }
  299. }
  300.  
  301. void EventOpenFile()
  302. {
  303.         if (active_tab==SKINS) RunProgram("/sys/skincfg", #cur_file_path);
  304.         if (active_tab==WALLPAPERS) RunProgram("/sys/media/kiv", #cur_file_path);
  305. }
  306.  
  307. stop:
  308.