Subversion Repositories Kolibri OS

Rev

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

  1. /*
  2. SOFTWARE CENTER v2.15
  3. */
  4.  
  5. #define MEMSIZE 0x3E80
  6. #include "..\lib\kolibri.h"
  7. #include "..\lib\strings.h"
  8. #include "..\lib\mem.h"
  9. #include "..\lib\file_system.h"
  10. #include "..\lib\dll.h"
  11. #include "..\lib\figures.h"
  12. #include "..\lib\lib.obj\libio_lib.h"
  13. #include "..\lib\lib.obj\libimg_lib.h"
  14. #include "..\lib\lib.obj\libini.h"
  15.  
  16.  
  17. system_colors sc;
  18. proc_info Form;
  19. mouse m;
  20.  
  21. int item_id_need_to_run=-1,
  22.     current_item_id;
  23.  
  24. int window_width,
  25.     window_height;
  26.  
  27. int col_max,
  28.     cell_w,
  29.     cell_h,
  30.     list_pos,
  31.     list_top,
  32.     row,
  33.     col,
  34.     default_icon;
  35.  
  36. char window_title[128],
  37.      settings_ini_path[256] = "/sys/settings/";
  38.  
  39. #define LIST_BACKGROUND_COLOR 0xF3F3F3
  40.  
  41.  
  42.  
  43.  
  44. struct struct_skin {
  45.         dword image, w, h;
  46.         int load();
  47. } skin;
  48.  
  49.  
  50. int struct_skin::load()
  51. {
  52.         int i, max_i;
  53.         dword image_data;
  54.         skin.image = load_image("/sys/iconstrp.png");
  55.         if (!skin.image) notify("'iconstrp.png not found' -E");
  56.         skin.w = DSWORD[skin.image + 4];
  57.         skin.h = DSWORD[skin.image + 8];
  58.         image_data = DSDWORD[skin.image + 24];
  59.         sc.get();
  60.         max_i = w * h * 4 + image_data;
  61.         for (i = image_data; i < max_i; i += 4) if (DSDWORD[i]==0) DSDWORD[i] = LIST_BACKGROUND_COLOR;
  62. }
  63.  
  64. void load_config()
  65. {
  66.         ini_get_str stdcall (#settings_ini_path, "Config", "window_title", #window_title, sizeof(window_title), "Software widget");
  67.         ini_get_int stdcall (#settings_ini_path, "Config", "window_width", 690);
  68.         window_width = EAX;
  69.         ini_get_int stdcall (#settings_ini_path, "Config", "window_height", 540);
  70.         window_height = EAX;
  71.         ini_get_int stdcall (#settings_ini_path, "Config", "cell_w", 66);
  72.         cell_w = EAX;
  73.         ini_get_int stdcall (#settings_ini_path, "Config", "cell_h", 64);
  74.         cell_h = EAX;
  75.         ini_get_int stdcall (#settings_ini_path, "Config", "default_icon", 0);
  76.         default_icon = EAX;
  77. }
  78.  
  79.  
  80. void main()
  81. {  
  82.         int id, key;
  83.         mem_Init();
  84.         if (load_dll2(libio,  #libio_init,1)!=0) notify("Error: library doesn't exists - libio");
  85.         if (load_dll2(libimg, #libimg_init,1)!=0) notify("Error: library doesn't exists - libimg");
  86.         if (load_dll2(libini, #lib_init,1)!=0) notify("Error: library doesn't exists - libini");
  87.         skin.load();
  88.  
  89.         strcat(#settings_ini_path, #program_path + strrchr(#program_path, '/'));
  90.         strcat(#settings_ini_path, ".ini");
  91.         load_config();
  92.  
  93.         loop()
  94.         {
  95.       switch(WaitEvent())
  96.       {
  97.          case evButton:
  98.             id=GetButtonID();              
  99.             if (id==1) ExitProcess();
  100.             if (id>=100)
  101.             {
  102.                 item_id_need_to_run = id - 100;
  103.                 current_item_id = 0;
  104.                 ini_enum_sections stdcall (#settings_ini_path, #draw_section);
  105.                 item_id_need_to_run = -1;
  106.             }
  107.                         break;
  108.  
  109.          case evReDraw:
  110.                         sc.get();
  111.                         DefineAndDrawWindow(GetScreenWidth()-window_width/2,GetScreenHeight()-window_height/2,window_width,window_height,0x74,sc.work," ");
  112.                         GetProcessInfo(#Form, SelfInfo);
  113.                         if (Form.status_window>2) break;
  114.                         col_max = Form.cwidth - 10 / cell_w;
  115.                         current_item_id = 0;
  116.                         draw_top_bar();
  117.                         ini_enum_sections stdcall (#settings_ini_path, #draw_section);
  118.                         DrawBar(0, row + 1 * cell_h + list_pos, Form.cwidth, -row - 1 * cell_h - list_pos + Form.cheight, LIST_BACKGROUND_COLOR);
  119.                         break;
  120.       }
  121.         }
  122. }
  123.  
  124. byte search_for_id_need_to_run(dword key_value, key_name, sec_name, f_name)
  125. {
  126.         int icon_char_pos;
  127.         if (item_id_need_to_run == current_item_id)
  128.         {
  129.                 icon_char_pos = strchr(key_value, ',');
  130.                 if (icon_char_pos) ESBYTE[key_value + icon_char_pos - 1] = 0; //delete icon from string
  131.                 RunProgram(key_value, "");
  132.         }
  133.         current_item_id++;
  134.         return 1;
  135. }
  136.  
  137.  
  138. byte draw_icons_from_section(dword key_value, key_name, sec_name, f_name)
  139. {
  140.         int tmp,
  141.             icon_id,
  142.             icon_char_pos;
  143.  
  144.         if (col==col_max) {
  145.                 row++;
  146.                 col=0;
  147.         }
  148.         if (col==0) DrawBar(0, row * cell_h + list_pos, Form.cwidth, cell_h, LIST_BACKGROUND_COLOR);
  149.         DefineButton(col*cell_w+6,row*cell_h + list_pos,cell_w,cell_h-5,current_item_id + 100 + BT_HIDE,0);
  150.         tmp = cell_w/2;
  151.  
  152.         icon_char_pos = strchr(key_value, ',');
  153.         if (icon_char_pos) icon_id = atoi(key_value + icon_char_pos); else icon_id = default_icon;
  154.         img_draw stdcall(skin.image, col*cell_w+tmp-10, row*cell_h+5 + list_pos, 32, 32, 0, icon_id*32);
  155.         WriteTextCenter(col*cell_w+7,row*cell_h+47 + list_pos,cell_w,0xDCDCDC,key_name);
  156.         WriteTextCenter(col*cell_w+6,row*cell_h+46 + list_pos,cell_w,0x000000,key_name);
  157.         current_item_id++;
  158.         col++;
  159.         return 1;
  160. }
  161.  
  162.  
  163. byte draw_section(dword sec_name, f_name)
  164. {
  165.         if (strcmp(sec_name, "Config")==0) return 1;
  166.  
  167.         if (item_id_need_to_run!=-1)
  168.         {
  169.                 ini_enum_keys stdcall (f_name, sec_name, #search_for_id_need_to_run);
  170.         }
  171.         else
  172.         {
  173.                 row++;
  174.                 col = 0;
  175.                 DrawBar(0, row * cell_h + list_pos, Form.cwidth , 20, LIST_BACKGROUND_COLOR);
  176.                 WriteTextB(10, row * cell_h + 9 + list_pos, 0x90, 0x000000, sec_name);
  177.                 list_pos += 20;
  178.                 ini_enum_keys stdcall (f_name, sec_name, #draw_icons_from_section);
  179.         }
  180.         return 1;
  181. }
  182.  
  183. void draw_top_bar()
  184. {
  185.         int top_position = 25;
  186.         DrawBar(0,0,Form.cwidth, top_position-1, sc.work);
  187.         DrawBar(0,top_position-1, Form.cwidth, 1, sc.work_graph);
  188.         WriteTextB(Form.cwidth/2-70, 9, 0x90, sc.work_text, #window_title);
  189.         list_top = top_position;
  190.         list_pos = list_top;
  191.         row = -1;
  192. }
  193.  
  194.  
  195.  
  196. stop:
  197.