Subversion Repositories Kolibri OS

Rev

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

Rev Author Line No. Line
7227 leency 1
// Mouse Configuration Utility ver 1.5
5857 leency 2
 
5622 leency 3
#ifndef AUTOBUILD
4
#include "lang.h--"
5
#endif
6
 
7
#define MEMSIZE 0x23E80
8
#include "..\lib\strings.h"
9
#include "..\lib\mem.h"
7219 leency 10
#include "..\lib\fs.h"
5622 leency 11
#include "..\lib\gui.h"
7049 leency 12
#include "..\lib\obj\libio.h"
5622 leency 13
#include "..\lib\obj\box_lib.h"
5857 leency 14
#include "..\lib\obj\libini.h"
5622 leency 15
#include "..\lib\patterns\restart_process.h"
16
 
7051 leency 17
// Translatiions
5630 leency 18
#ifdef LANG_RUS
19
	?define WINDOW_TITLE "Проверка и настройка параметров мыши"
20
	?define CHECK_MOUSE_1 "Нажмите на этой области"
21
	?define CHECK_MOUSE_2 "для проверки кнопок мыши"
6231 pathoswith 22
	?define POINTER_SPEED "Делитель скорости указателя мыши"
23
	?define ACCELERATION_TEXT "Чувствительность указателя мыши"
5970 leency 24
	?define DOUBLE_CLICK_TEXT "Задержка двойного клика мышью"
6197 leency 25
	?define MOUSE_EMULATION "Управление указателем мыши через клавиатуру"
5654 leency 26
	?define MADMOUSE "Сквозные для курсора стороны экрана"
5630 leency 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"
6231 pathoswith 31
	?define POINTER_SPEED "Mouse pointer speed divider"
32
	?define ACCELERATION_TEXT "Mouse pointer sensitivity"
5970 leency 33
	?define DOUBLE_CLICK_TEXT "Mouse double click delay"
5630 leency 34
	?define MOUSE_EMULATION "Enable mouse emulation using keyboard NumPad"
35
	?define MADMOUSE "Through screen sides for pointer"
7227 leency 36
#endif
5622 leency 37
 
5970 leency 38
proc_info Form;
5622 leency 39
 
7227 leency 40
#define PD 18 //padding
41
block mouse_frame = { PD, PD, NULL, 130 };
42
 
7243 leency 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 };
7227 leency 46
 
5630 leency 47
unsigned char panels_img_data[] = FROM "mouse_image.raw";
48
raw_image panels_img = { 59, 101, #panels_img_data };
5970 leency 49
 
7051 leency 50
_ini ini = { "/sys/settings/system.ini", "mouse" };
5630 leency 51
 
5970 leency 52
struct _mouse_cfg {
7227 leency 53
	bool emulation;
54
	bool madmouse;
55
	int click_status;
5622 leency 56
} mouse_cfg;
57
 
58
 
59
void main() {
7227 leency 60
	char id;
7051 leency 61
 
5857 leency 62
	load_dll(libini, #lib_init,1);
5626 leency 63
	load_dll(boxlib, #box_lib_init,0);
7051 leency 64
 
5622 leency 65
	LoadCfg();
66
 
7051 leency 67
	SetEventMask(EVM_REDRAW+EVM_KEY+EVM_BUTTON+EVM_MOUSE+EVM_MOUSE_FILTER);
68
 
5622 leency 69
	loop() switch(WaitEvent())
70
	{
5630 leency 71
		case evMouse:
5640 pavelyakov 72
				mouse.get();
7227 leency 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
				}
5630 leency 83
				break;
84
 
5622 leency 85
		case evButton:
7227 leency 86
				id = GetButtonID();
7051 leency 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;
7227 leency 95
						DrawControls();
7051 leency 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;
7227 leency 101
						DrawControls();
7051 leency 102
						break;
7227 leency 103
					default:
104
						if (pointer_speed.click(id)) ApplyCfg();;
105
						if (acceleration.click(id)) ApplyCfg();;
106
						if (double_click_delay.click(id)) ApplyCfg();;
5622 leency 107
				}
108
				break;
7051 leency 109
 
5622 leency 110
		case evKey:
7051 leency 111
				GetKeys();
112
				if (key_scancode == SCAN_CODE_ESC) ExitApp();
5622 leency 113
				break;
114
 
115
		case evReDraw:
5674 pavelyakov 116
				system.color.get();
7051 leency 117
				DefineAndDrawWindow(430, 150, 424, 310+skin_height,0x34,system.color.work,WINDOW_TITLE,0);
5622 leency 118
				GetProcessInfo(#Form, SelfInfo);
119
				if (Form.status_window>2) break;
7227 leency 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);
5642 leency 125
				DrawMouseImage();
126
				DrawControls();
5622 leency 127
	}
128
}
129
 
130
 
5630 leency 131
void DrawMouseImage() {
7227 leency 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);
5630 leency 134
}
5622 leency 135
 
5642 leency 136
void DrawControls() {
7243 leency 137
	pointer_speed.draw(PD, PD+142);
138
	acceleration.draw(PD, PD+172);
139
	double_click_delay.draw(PD+202);
7227 leency 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);
5642 leency 142
}
143
 
5622 leency 144
void LoadCfg() {
7227 leency 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());
5630 leency 148
	mouse_cfg.madmouse = CheckProcessExists("MADMOUSE");
149
	mouse_cfg.emulation = CheckProcessExists("MOUSEMUL");
5622 leency 150
}
151
 
5857 leency 152
void ExitApp() {
7227 leency 153
	ini.SetInt("acceleration", acceleration.value);
154
	ini.SetInt("speed", pointer_speed.value);
155
	ini.SetInt("double_click_delay", double_click_delay.value);
5857 leency 156
	ExitProcess();
157
}
5630 leency 158
 
7051 leency 159
void ApplyCfg() {
7227 leency 160
	SetMouseSpeed(pointer_speed.value);
161
	SetMouseAcceleration(acceleration.value);
162
	SetMouseDoubleClickDelay(double_click_delay.value);
7051 leency 163
}
5630 leency 164
 
5622 leency 165
stop: