Subversion Repositories Kolibri OS

Rev

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

  1. // Mouse Configuration Utility ver 1.62
  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\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.         ?define COMMOUSE "‡ £à㧨âì ¤à ©¢¥à ¬ëè¨ ¤«ï COM-¯®àâ  (F10)"
  28.         ?define COMMOUSE_LOADED "'„à ©¢¥à ¤«ï COM ¬ëè¨ ¡ë« § £à㦥­' -O"
  29.         ?define COMMOUSE_CAN_NOT_UNLOAD "'Žáâ ­®¢ª  ¤à ©¢¥à  ­¥¢®§¬®¦­ ' -W"
  30. #else
  31.         ?define WINDOW_TITLE "Mouse testing and configuration"
  32.         ?define CHECK_MOUSE_1 "Click on this area to"
  33.         ?define CHECK_MOUSE_2 "check your mouse buttons"
  34.         ?define POINTER_SPEED "Mouse pointer speed divider"
  35.         ?define ACCELERATION_TEXT "Mouse pointer sensitivity"
  36.         ?define DOUBLE_CLICK_TEXT "Mouse double click delay"
  37.         ?define MOUSE_EMULATION "Enable mouse emulation using keyboard NumPad"
  38.         ?define MADMOUSE "Through screen sides for pointer"
  39.         ?define COMMOUSE "Load mouse driver for COM-port (F10)"
  40.         ?define COMMOUSE_LOADED "'Driver for COM mouse loaded' -O"
  41.         ?define COMMOUSE_CAN_NOT_UNLOAD "'Driver stop is impossible' -W"
  42. #endif
  43.  
  44. #define FRAME_X 18
  45. #define FRAME_Y 18
  46. :block mouse_frame = { FRAME_X, FRAME_Y, NULL, 130 };
  47. :more_less_box pointer_speed      = { NULL, 0, 64, POINTER_SPEED };
  48. :more_less_box acceleration       = { NULL, 0, 64, ACCELERATION_TEXT };
  49. :more_less_box double_click_delay = { NULL, 0, 999, DOUBLE_CLICK_TEXT, 8 };
  50. :checkbox emulation = { MOUSE_EMULATION, NULL };
  51. :checkbox madmouse = { MADMOUSE, NULL };
  52. :checkbox com_mouse = { COMMOUSE, NULL };
  53.  
  54. _ini ini = { "/sys/settings/system.ini", "loaded drivers" };
  55.  
  56. void main() {
  57.         proc_info Form;
  58.         int id;
  59.        
  60.         load_dll(libini, #lib_init,1);
  61.        
  62.         LoadCfg();
  63.  
  64.         SetEventMask(EVM_REDRAW+EVM_KEY+EVM_BUTTON+EVM_MOUSE+EVM_MOUSE_FILTER);
  65.  
  66.         loop() switch(WaitEvent())
  67.         {
  68.                 case evMouse:
  69.                                 mouse.get();
  70.                                 IF (mouse_frame.hovered()) DrawMouseImage(mouse.lkm,mouse.pkm,mouse.mkm,mouse.vert);
  71.                                 IF (mouse.click) || (mouse.up) DrawMouseImage(0,0,0,0);
  72.                                 break;
  73.  
  74.                 CASE evButton:
  75.                                 id = GetButtonID();
  76.                                 IF (1 == id) ExitApp();
  77.                                 else IF (pointer_speed.click(id)) ApplyCfg();
  78.                                 else IF (acceleration.click(id)) ApplyCfg();
  79.                                 else IF (double_click_delay.click(id)) ApplyCfg();
  80.                                 else IF (emulation.click(id)) {
  81.                                         IF (emulation.checked == true) RunProgram("/sys/mousemul", 0);
  82.                                         ELSE KillProcessByName("mousemul", SINGLE);
  83.                                         break;
  84.                                 }
  85.                                 else IF (madmouse.click(id)) {                                         
  86.                                         IF (madmouse.checked == true) RunProgram("/sys/madmouse", 0);
  87.                                         ELSE KillProcessByName("madmouse", SINGLE);
  88.                                         break;
  89.                                 }
  90.                                 else IF (id == com_mouse.id) {
  91.                                         EventClickComMouse();
  92.                                 }
  93.                                 break;
  94.  
  95.                 case evKey:
  96.                                 GetKeys();
  97.                                 IF (key_scancode == SCAN_CODE_ESC) ExitApp();
  98.                                 IF (key_scancode == SCAN_CODE_F10) EventClickComMouse();
  99.                                 break;
  100.                        
  101.                 case evReDraw:
  102.                                 sc.get();
  103.                                 DefineAndDrawWindow(430, 150, 424, 343+skin_height,0x34,sc.work,WINDOW_TITLE,0);
  104.                                 GetProcessInfo(#Form, SelfInfo);
  105.                                 if (Form.status_window>2) break;
  106.                                 mouse_frame.w = - FRAME_X * 2 + Form.cwidth;
  107.                                 DefineButton(FRAME_X, FRAME_Y, mouse_frame.w,
  108.                                         mouse_frame.h, 99+BT_NOFRAME, 0xF0F2F3); //needed to handle mouse_up and refresh mouse image
  109.                                 WriteText(FRAME_X + 110, FRAME_Y + 25, 0x90, 0x2C343C, CHECK_MOUSE_1);
  110.                                 WriteText(FRAME_X + 110, FRAME_Y + 45, 0x90, 0x2C343C, CHECK_MOUSE_2);
  111.                                 DrawMouseImage(0,0,0,0);
  112.                                 DrawControls();
  113.         }
  114. }
  115.  
  116. :byte panels_img_data[] = FROM "mouse_image.raw";
  117.  
  118. #define red    0xff0000
  119. #define yellow 0xfff600
  120. #define white  0xffffff
  121. #define dgrey  0x2d353d
  122.  
  123. :struct IMG_PAL{ dword back, shad1, contour, left,  right, middle, mwhite; }
  124.          pal = { 0xF0F2F3,0xABB0B2, dgrey,   white, white, dgrey,  white  };
  125.  
  126. void DrawMouseImage(dword l,r,m,v) {
  127.         #define IMG_W 59
  128.         #define IMG_H 101
  129.  
  130.         IF (l) pal.left = red;
  131.         IF (m) pal.middle = red;
  132.         IF (r) pal.right = red;
  133.         IF (v) pal.middle = yellow;
  134.  
  135.         PutPaletteImage(#panels_img_data,IMG_W,IMG_H,18+30,18+15,8,#pal);
  136.         pal.left = pal.right = white;
  137.         pal.middle = dgrey;
  138.         IF (v) {
  139.                 pause(10);
  140.                 DrawMouseImage(l,r,m,0);
  141.         }
  142. }
  143.  
  144. void DrawControls() {
  145.         incn y;
  146.         y.n = FRAME_Y+115;
  147.         pointer_speed.draw(FRAME_X, y.inc(30));
  148.         acceleration.draw(FRAME_X, y.inc(30));
  149.         double_click_delay.draw(FRAME_X, y.inc(30));
  150.         emulation.draw(FRAME_X, y.inc(33));
  151.         madmouse.draw(FRAME_X, y.inc(27));
  152.         com_mouse.draw(FRAME_X, y.inc(27));
  153. }
  154.  
  155. void LoadCfg() {
  156.         acceleration.value = GetMouseAcceleration();
  157.         pointer_speed.value = GetMouseSpeed();
  158.         double_click_delay.value = GetMouseDoubleClickDelay();
  159.         com_mouse.checked = ini.GetInt("com_mouse", 0);
  160.         madmouse.checked = CheckProcessExists("MADMOUSE");
  161.         emulation.checked = CheckProcessExists("MOUSEMUL");
  162. }
  163.  
  164. void ExitApp() {
  165.         ini.SetInt("com_mouse", com_mouse.checked);
  166.         ExitProcess();
  167. }
  168.  
  169. void ApplyCfg() {
  170.         SetMouseSpeed(pointer_speed.value);
  171.         SetMouseAcceleration(acceleration.value);
  172.         SetMouseDoubleClickDelay(double_click_delay.value);
  173. }
  174.  
  175. void EventClickComMouse()
  176. {
  177.         if (!com_mouse.checked)
  178.         {
  179.                 if (RunProgram("/sys/loaddrv", "COMMOUSE")>=0) {
  180.                         notify(COMMOUSE_LOADED);
  181.                         com_mouse.click(com_mouse.id);
  182.                 }
  183.                 else {
  184.                         notify("'Error running LOADDRV' -E");
  185.                 }
  186.         }
  187.         else
  188.         {
  189.                 notify(COMMOUSE_CAN_NOT_UNLOAD);
  190.         }
  191. }
  192.  
  193. stop:
  194.