Subversion Repositories Kolibri OS

Rev

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

Rev Author Line No. Line
5970 leency 1
// Mouse Configuration Utility ver 1.4
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"
10
#include "..\lib\file_system.h"
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"
5674 pavelyakov 36
	#endif
5622 leency 37
 
5970 leency 38
proc_info Form;
5630 leency 39
frame mouse_frame = { 0, 000, 14, 130, 14, 0x000111, 0xFFFfff, 0, 0, 0, 0, 6, 0x000111, 0xCCCccc };
5642 leency 40
char pos_x = 22;
5622 leency 41
 
5630 leency 42
unsigned char panels_img_data[] = FROM "mouse_image.raw";
43
raw_image panels_img = { 59, 101, #panels_img_data };
5970 leency 44
 
7051 leency 45
_ini ini = { "/sys/settings/system.ini", "mouse" };
5630 leency 46
 
5970 leency 47
struct _mouse_cfg {
5630 leency 48
	char pointer_speed,
5970 leency 49
	acceleration,
5630 leency 50
	emulation,
51
	madmouse,
52
	button_clicked;
5970 leency 53
	word double_click_delay;
5622 leency 54
} mouse_cfg;
55
 
56
 
57
void main() {
5630 leency 58
	char id, old_button_clicked;
7051 leency 59
 
5857 leency 60
	load_dll(libini, #lib_init,1);
5626 leency 61
	load_dll(boxlib, #box_lib_init,0);
7051 leency 62
 
5622 leency 63
	LoadCfg();
64
 
7051 leency 65
	SetEventMask(EVM_REDRAW+EVM_KEY+EVM_BUTTON+EVM_MOUSE+EVM_MOUSE_FILTER);
66
 
5622 leency 67
	loop() switch(WaitEvent())
68
	{
5630 leency 69
		case evMouse:
5640 pavelyakov 70
				mouse.get();
71
				if (mouse.y <= mouse_frame.start_y) || (mouse.y >= mouse_frame.start_y + mouse_frame.size_y)
72
				|| (mouse.x >= mouse_frame.start_x + mouse_frame.size_x) || (mouse.x <= mouse_frame.start_x) break;
5630 leency 73
				old_button_clicked = mouse_cfg.button_clicked;
5640 pavelyakov 74
				if (mouse.lkm) mouse_cfg.button_clicked=1;
75
				else if (mouse.pkm) mouse_cfg.button_clicked=2;
76
				else if (mouse.mkm) mouse_cfg.button_clicked=3;
5630 leency 77
				else mouse_cfg.button_clicked=0;
78
				if (mouse_cfg.button_clicked != old_button_clicked) DrawMouseImage();
79
				break;
80
 
5622 leency 81
		case evButton:
82
				id=GetButtonID();
7051 leency 83
				switch (id) {
84
					case 1:
85
						ExitApp();
86
						break;
87
					case 99:
88
						mouse_cfg.button_clicked=0;
89
						DrawMouseImage();
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
						break;
96
					case 101:
97
						if (mouse_cfg.madmouse==true) KillProcessByName("madmouse", SINGLE);
98
						else RunProgram("/sys/madmouse", 0);
99
						mouse_cfg.madmouse ^= 1;
100
						break;
101
					case 120: mouse_cfg.pointer_speed++; break;
102
					case 121: if (mouse_cfg.pointer_speed>0) mouse_cfg.pointer_speed--; break;
103
					case 122: mouse_cfg.acceleration++; break;
104
					case 123: if (mouse_cfg.acceleration>0) mouse_cfg.acceleration--; break;
105
					case 124: mouse_cfg.double_click_delay+=8; break;
106
					case 125: if (mouse_cfg.double_click_delay>0) mouse_cfg.double_click_delay-=8; break;
5622 leency 107
				}
5642 leency 108
				DrawControls();
7051 leency 109
				ApplyCfg();
110
 
5622 leency 111
				break;
7051 leency 112
 
5622 leency 113
		case evKey:
7051 leency 114
				GetKeys();
115
				if (key_scancode == SCAN_CODE_ESC) ExitApp();
5622 leency 116
				break;
117
 
118
		case evReDraw:
5674 pavelyakov 119
				system.color.get();
7051 leency 120
				DefineAndDrawWindow(430, 150, 424, 310+skin_height,0x34,system.color.work,WINDOW_TITLE,0);
5622 leency 121
				GetProcessInfo(#Form, SelfInfo);
122
				if (Form.status_window>2) break;
5642 leency 123
				SetFrameColors();
124
				DefineButton(mouse_frame.start_x+2, mouse_frame.start_y+2, mouse_frame.size_x-4,
125
					mouse_frame.size_y-4, 99+BT_NOFRAME, 0xF0F2F3); //needed to handle mouse_up and refresh mouse image
126
				frame_draw stdcall (#mouse_frame);
5857 leency 127
				WriteText(pos_x + 110, mouse_frame.start_y + 25, 0x90, 0x2C343C, CHECK_MOUSE_1);
128
				WriteText(pos_x + 110, mouse_frame.start_y + 45, 0x90, 0x2C343C, CHECK_MOUSE_2);
5642 leency 129
				DrawMouseImage();
130
				DrawControls();
5622 leency 131
	}
132
}
133
 
134
 
5630 leency 135
void DrawMouseImage() {
5642 leency 136
	_PutImage(mouse_frame.start_x+30, mouse_frame.start_y + 15,  panels_img.w, panels_img.h,
137
		mouse_cfg.button_clicked * panels_img.w * panels_img.h * 3 + panels_img.data);
5630 leency 138
}
5622 leency 139
 
5642 leency 140
void DrawControls() {
6176 leency 141
	MoreLessBox(pos_x, mouse_frame.start_y + 142, 120, 121, mouse_cfg.pointer_speed, POINTER_SPEED);
6197 leency 142
	MoreLessBox(pos_x, mouse_frame.start_y + 172, 122, 123, mouse_cfg.acceleration, ACCELERATION_TEXT);
143
	MoreLessBox(pos_x, mouse_frame.start_y + 202, 124, 125, mouse_cfg.double_click_delay, DOUBLE_CLICK_TEXT);
144
	CheckBox(pos_x, mouse_frame.start_y + 236, 100, MOUSE_EMULATION, mouse_cfg.emulation);
145
	CheckBox(pos_x, mouse_frame.start_y + 262, 101, MADMOUSE, mouse_cfg.madmouse);
5642 leency 146
}
147
 
148
void SetFrameColors() {
149
	mouse_frame.size_x = - mouse_frame.start_x * 2 + Form.cwidth;
5674 pavelyakov 150
	mouse_frame.font_color = system.color.work_text;
151
	mouse_frame.font_backgr_color = system.color.work;
152
	mouse_frame.ext_col = system.color.work_graph;
5642 leency 153
}
154
 
5622 leency 155
void LoadCfg() {
7051 leency 156
	mouse_cfg.acceleration = ini.GetInt("acceleration", GetMouseAcceleration());
157
	mouse_cfg.pointer_speed = ini.GetInt("speed", GetMouseSpeed());
158
	mouse_cfg.double_click_delay = ini.GetInt("double_click_delay", GetMouseDoubleClickDelay());
5630 leency 159
	mouse_cfg.madmouse = CheckProcessExists("MADMOUSE");
160
	mouse_cfg.emulation = CheckProcessExists("MOUSEMUL");
5622 leency 161
}
162
 
5857 leency 163
void ExitApp() {
7051 leency 164
	ini.SetInt("acceleration", mouse_cfg.acceleration);
165
	ini.SetInt("speed", mouse_cfg.pointer_speed);
166
	ini.SetInt("double_click_delay", mouse_cfg.double_click_delay);
5857 leency 167
	ExitProcess();
168
}
5630 leency 169
 
7051 leency 170
void ApplyCfg() {
171
	SetMouseSpeed(mouse_cfg.pointer_speed);
172
	SetMouseAcceleration(mouse_cfg.acceleration);
173
	SetMouseDoubleClickDelay(mouse_cfg.double_click_delay);
174
}
5630 leency 175
 
5622 leency 176
stop: