Subversion Repositories Kolibri OS

Rev

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

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