Subversion Repositories Kolibri OS

Rev

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

  1. // Mouse Configuration Utility ver 1.51
  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. proc_info Form;
  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. unsigned char panels_img_data[] = FROM "mouse_image.raw";
  47. raw_image panels_img = { 59, 101, #panels_img_data };
  48.  
  49. _ini ini = { "/sys/settings/system.ini", "mouse" };
  50.  
  51. dword click_status;
  52.  
  53.  
  54.  
  55. void main() {
  56.         int id;
  57.        
  58.         load_dll(libini, #lib_init,1);
  59.         load_dll(boxlib, #box_lib_init,0);
  60.        
  61.         LoadCfg();
  62.  
  63.         SetEventMask(EVM_REDRAW+EVM_KEY+EVM_BUTTON+EVM_MOUSE+EVM_MOUSE_FILTER);
  64.  
  65.         loop() switch(WaitEvent())
  66.         {
  67.                 case evMouse:
  68.                                 mouse.get();
  69.                                 if (mouse.down) && (click_status==0) && (mouse_frame.hovered()) {
  70.                                         if (mouse.key&MOUSE_LEFT) click_status = 1;
  71.                                         if (mouse.key&MOUSE_RIGHT) click_status = 2;
  72.                                         if (mouse.key&MOUSE_CENTER) click_status = 3;
  73.                                         DrawMouseImage();
  74.                                 }
  75.                                 if (mouse.up) {
  76.                                         click_status=0;
  77.                                         DrawMouseImage();
  78.                                 }
  79.                                 break;
  80.  
  81.                 case evButton:
  82.                                 id = GetButtonID();
  83.                                 if (1 == id) ExitApp();
  84.                                 else if (pointer_speed.click(id)) ApplyCfg();
  85.                                 else if (acceleration.click(id)) ApplyCfg();
  86.                                 else if (double_click_delay.click(id)) ApplyCfg();
  87.                                 else if (emulation.click(id)) {
  88.                                         if (emulation.checked == true) RunProgram("/sys/mousemul", 0);
  89.                                         else KillProcessByName("/sys/mousemul", SINGLE);
  90.                                         break;
  91.                                 }
  92.                                 else if (madmouse.click(id)) {                                         
  93.                                         if (madmouse.checked == true) RunProgram("/sys/madmouse", 0);
  94.                                         else KillProcessByName("/sys/madmouse", SINGLE);
  95.                                         break;
  96.                                 }
  97.                                 break;
  98.  
  99.                 case evKey:
  100.                                 GetKeys();
  101.                                 if (key_scancode == SCAN_CODE_ESC) ExitApp();
  102.                                 break;
  103.                        
  104.                 case evReDraw:
  105.                                 system.color.get();
  106.                                 DefineAndDrawWindow(430, 150, 424, 310+skin_height,0x34,system.color.work,WINDOW_TITLE,0);
  107.                                 GetProcessInfo(#Form, SelfInfo);
  108.                                 if (Form.status_window>2) break;
  109.                                 mouse_frame.w = - mouse_frame.x * 2 + Form.cwidth;
  110.                                 DefineButton(mouse_frame.x, mouse_frame.y, mouse_frame.w,
  111.                                         mouse_frame.h, 99+BT_NOFRAME, 0xF0F2F3); //needed to handle mouse_up and refresh mouse image
  112.                                 WriteText(mouse_frame.x + 110, mouse_frame.y + 25, 0x90, 0x2C343C, CHECK_MOUSE_1);
  113.                                 WriteText(mouse_frame.x + 110, mouse_frame.y + 45, 0x90, 0x2C343C, CHECK_MOUSE_2);
  114.                                 DrawMouseImage();
  115.                                 DrawControls();
  116.         }
  117. }
  118.  
  119.  
  120. void DrawMouseImage() {
  121.         _PutImage(mouse_frame.x+30, mouse_frame.y + 15,  panels_img.w, panels_img.h,
  122.                 click_status * panels_img.w * panels_img.h * 3 + panels_img.data);
  123. }
  124.  
  125. void DrawControls() {
  126.         incn y;
  127.         y.n = mouse_frame.y+115;
  128.         pointer_speed.draw(mouse_frame.x, y.inc(30));
  129.         acceleration.draw(mouse_frame.x, y.inc(30));
  130.         double_click_delay.draw(mouse_frame.x, y.inc(30));
  131.         emulation.draw(mouse_frame.x, y.inc(33));
  132.         madmouse.draw(mouse_frame.x, y.inc(27));
  133. }
  134.  
  135. void LoadCfg() {
  136.         acceleration.value = ini.GetInt("acceleration", GetMouseAcceleration());
  137.         pointer_speed.value = ini.GetInt("speed", GetMouseSpeed());
  138.         double_click_delay.value = ini.GetInt("double_click_delay", GetMouseDoubleClickDelay());
  139.         madmouse.checked = CheckProcessExists("MADMOUSE");
  140.         emulation.checked = CheckProcessExists("MOUSEMUL");
  141. }
  142.  
  143. void ExitApp() {
  144.         ini.SetInt("acceleration", acceleration.value);
  145.         ini.SetInt("speed", pointer_speed.value);
  146.         ini.SetInt("double_click_delay", double_click_delay.value);
  147.         ExitProcess();
  148. }
  149.  
  150. void ApplyCfg() {
  151.         SetMouseSpeed(pointer_speed.value);
  152.         SetMouseAcceleration(acceleration.value);
  153.         SetMouseDoubleClickDelay(double_click_delay.value);
  154. }
  155.  
  156. stop: