Subversion Repositories Kolibri OS

Rev

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

  1. // Mouse Configuration Utility ver 1.5
  2.  
  3. #ifndef AUTOBUILD
  4. #include "lang.h--"
  5. #endif
  6.  
  7. #define MEMSIZE 0x23E80
  8. #include "..\lib\strings.h"
  9. #include "..\lib\mem.h"
  10. #include "..\lib\fs.h"
  11. #include "..\lib\gui.h"
  12. #include "..\lib\obj\libio.h"
  13. #include "..\lib\obj\box_lib.h"
  14. #include "..\lib\obj\libini.h"
  15. #include "..\lib\patterns\restart_process.h"
  16.  
  17. // Translatiions
  18. #ifdef LANG_RUS
  19.         ?define WINDOW_TITLE "à®¢¥àª  ¨ ­ áâனª  ¯ à ¬¥â஢ ¬ëè¨"
  20.         ?define CHECK_MOUSE_1 " ¦¬¨â¥ ­  í⮩ ®¡« áâ¨"
  21.         ?define CHECK_MOUSE_2 "¤«ï ¯à®¢¥àª¨ ª­®¯®ª ¬ëè¨"
  22.         ?define POINTER_SPEED "„¥«¨â¥«ì ᪮à®á⨠㪠§ â¥«ï ¬ëè¨"
  23.         ?define ACCELERATION_TEXT "—ã¢á⢨⥫쭮áâì 㪠§ â¥«ï ¬ëè¨"
  24.         ?define DOUBLE_CLICK_TEXT "‡ ¤¥à¦ª  ¤¢®©­®£® ª«¨ª  ¬ëèìî"
  25.         ?define MOUSE_EMULATION "“¯à ¢«¥­¨¥ 㪠§ â¥«¥¬ ¬ëè¨ ç¥à¥§ ª« ¢¨ âãàã"
  26.         ?define MADMOUSE "‘ª¢®§­ë¥ ¤«ï ªãàá®à  áâ®à®­ë íªà ­ "
  27. #else
  28.         ?define WINDOW_TITLE "Mouse testing and configuration"
  29.         ?define CHECK_MOUSE_1 "Click on this area to"
  30.         ?define CHECK_MOUSE_2 "check your mouse buttons"
  31.         ?define POINTER_SPEED "Mouse pointer speed divider"
  32.         ?define ACCELERATION_TEXT "Mouse pointer sensitivity"
  33.         ?define DOUBLE_CLICK_TEXT "Mouse double click delay"
  34.         ?define MOUSE_EMULATION "Enable mouse emulation using keyboard NumPad"
  35.         ?define MADMOUSE "Through screen sides for pointer"
  36. #endif
  37.  
  38. proc_info Form;
  39.  
  40. #define PD 18 //padding
  41. block mouse_frame = { PD, PD, NULL, 130 };
  42.  
  43. more_less_box pointer_speed      = { NULL, 0, 64, POINTER_SPEED };
  44. more_less_box acceleration       = { NULL, 0, 64, ACCELERATION_TEXT };
  45. more_less_box double_click_delay = { NULL, 0, 999, DOUBLE_CLICK_TEXT, 8 };
  46.  
  47. unsigned char panels_img_data[] = FROM "mouse_image.raw";
  48. raw_image panels_img = { 59, 101, #panels_img_data };
  49.  
  50. _ini ini = { "/sys/settings/system.ini", "mouse" };
  51.  
  52. struct _mouse_cfg {
  53.         bool emulation;
  54.         bool madmouse;
  55.         int click_status;
  56. } mouse_cfg;
  57.  
  58.  
  59. void main() {
  60.         char id;
  61.        
  62.         load_dll(libini, #lib_init,1);
  63.         load_dll(boxlib, #box_lib_init,0);
  64.        
  65.         LoadCfg();
  66.  
  67.         SetEventMask(EVM_REDRAW+EVM_KEY+EVM_BUTTON+EVM_MOUSE+EVM_MOUSE_FILTER);
  68.  
  69.         loop() switch(WaitEvent())
  70.         {
  71.                 case evMouse:
  72.                                 mouse.get();
  73.                                 if (mouse.down) && (mouse_cfg.click_status==0) && (mouse_frame.hovered()) {
  74.                                         if (mouse.key&MOUSE_LEFT) mouse_cfg.click_status = 1;
  75.                                         if (mouse.key&MOUSE_RIGHT) mouse_cfg.click_status = 2;
  76.                                         if (mouse.key&MOUSE_CENTER) mouse_cfg.click_status = 3;
  77.                                         DrawMouseImage();
  78.                                 }
  79.                                 if (mouse.up) {
  80.                                         mouse_cfg.click_status=0;
  81.                                         DrawMouseImage();
  82.                                 }
  83.                                 break;
  84.  
  85.                 case evButton:
  86.                                 id = GetButtonID();
  87.                                 switch (id) {
  88.                                         case 1:
  89.                                                 ExitApp();
  90.                                                 break;
  91.                                         case 100:
  92.                                                 if (mouse_cfg.emulation==true) KillProcessByName("mousemul", SINGLE);
  93.                                                 else RunProgram("/sys/mousemul", 0);
  94.                                                 mouse_cfg.emulation ^= 1;
  95.                                                 DrawControls();
  96.                                                 break;
  97.                                         case 101:
  98.                                                 if (mouse_cfg.madmouse==true) KillProcessByName("madmouse", SINGLE);
  99.                                                 else RunProgram("/sys/madmouse", 0);
  100.                                                 mouse_cfg.madmouse ^= 1;
  101.                                                 DrawControls();
  102.                                                 break;
  103.                                         default:
  104.                                                 if (pointer_speed.click(id)) ApplyCfg();;
  105.                                                 if (acceleration.click(id)) ApplyCfg();;
  106.                                                 if (double_click_delay.click(id)) ApplyCfg();;
  107.                                 }
  108.                                 break;
  109.  
  110.                 case evKey:
  111.                                 GetKeys();
  112.                                 if (key_scancode == SCAN_CODE_ESC) ExitApp();
  113.                                 break;
  114.                        
  115.                 case evReDraw:
  116.                                 system.color.get();
  117.                                 DefineAndDrawWindow(430, 150, 424, 310+skin_height,0x34,system.color.work,WINDOW_TITLE,0);
  118.                                 GetProcessInfo(#Form, SelfInfo);
  119.                                 if (Form.status_window>2) break;
  120.                                 mouse_frame.w = - mouse_frame.x * 2 + Form.cwidth;
  121.                                 DefineButton(mouse_frame.x, mouse_frame.y, mouse_frame.w,
  122.                                         mouse_frame.h, 99+BT_NOFRAME, 0xF0F2F3); //needed to handle mouse_up and refresh mouse image
  123.                                 WriteText(mouse_frame.x + 110, mouse_frame.y + 25, 0x90, 0x2C343C, CHECK_MOUSE_1);
  124.                                 WriteText(mouse_frame.x + 110, mouse_frame.y + 45, 0x90, 0x2C343C, CHECK_MOUSE_2);
  125.                                 DrawMouseImage();
  126.                                 DrawControls();
  127.         }
  128. }
  129.  
  130.  
  131. void DrawMouseImage() {
  132.         _PutImage(mouse_frame.x+30, mouse_frame.y + 15,  panels_img.w, panels_img.h,
  133.                 mouse_cfg.click_status * panels_img.w * panels_img.h * 3 + panels_img.data);
  134. }
  135.  
  136. void DrawControls() {
  137.         pointer_speed.draw(PD, PD+142);
  138.         acceleration.draw(PD, PD+172);
  139.         double_click_delay.draw(PD+202);
  140.         CheckBox(mouse_frame.x, mouse_frame.y + 236, 100, MOUSE_EMULATION, mouse_cfg.emulation);
  141.         CheckBox(mouse_frame.x, mouse_frame.y + 262, 101, MADMOUSE, mouse_cfg.madmouse);
  142. }
  143.  
  144. void LoadCfg() {
  145.         acceleration.value = ini.GetInt("acceleration", GetMouseAcceleration());
  146.         pointer_speed.value = ini.GetInt("speed", GetMouseSpeed());
  147.         double_click_delay.value = ini.GetInt("double_click_delay", GetMouseDoubleClickDelay());
  148.         mouse_cfg.madmouse = CheckProcessExists("MADMOUSE");
  149.         mouse_cfg.emulation = CheckProcessExists("MOUSEMUL");
  150. }
  151.  
  152. void ExitApp() {
  153.         ini.SetInt("acceleration", acceleration.value);
  154.         ini.SetInt("speed", pointer_speed.value);
  155.         ini.SetInt("double_click_delay", double_click_delay.value);
  156.         ExitProcess();
  157. }
  158.  
  159. void ApplyCfg() {
  160.         SetMouseSpeed(pointer_speed.value);
  161.         SetMouseAcceleration(acceleration.value);
  162.         SetMouseDoubleClickDelay(double_click_delay.value);
  163. }
  164.  
  165. stop: