-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmousewheel.c
103 lines (95 loc) · 3.06 KB
/
mousewheel.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/**********************************************************************
imgcalkap - Simple map calibration tool for imgcap
Copyright (C) 2014 - David Giardini - dgiardini@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
************************************************************************/
#include <stdio.h>
#include "proc.h"
/***** Windows handlers **************/
#ifndef COMPILE_LINUX
#include <windows.h>
HHOOK MouseHook;
LRESULT CALLBACK LowLevelMouseProc (int code, WPARAM wParam, LPARAM lParam);
/* Function called when init the main application */
void SetMouseWheelCallback(void)
{
// HANDLE Proc= GetCurrentProcess();
MouseHook = SetWindowsHookEx(WH_MOUSE_LL, &LowLevelMouseProc,GetModuleHandle(0),0);
}
/* Windows procedure to hook mouse events ans filter mouse wheel events for zooming */
LRESULT CALLBACK LowLevelMouseProc (int code, WPARAM wParam, LPARAM lParam)
{
MSLLHOOKSTRUCT *mouseInfo;
int mouse_dir=0;
HWND focus=GetFocus();
/* Don't process mouse wheel events from other windows */
if(focus==NULL)
return 0;
if (code == HC_ACTION)
{
/* Filter only mouse wheel events */
switch (wParam)
{
case WM_MOUSEWHEEL:
mouseInfo = (MSLLHOOKSTRUCT*)lParam;
if((long int)(mouseInfo->mouseData) > 0)
{
mouse_dir=1;
}
else
{
mouse_dir=0;
}
break;
default:
/* Go to default hook */
return CallNextHookEx(MouseHook, code, wParam, lParam);
break;
}
if(verbose)
printf("MouseWheel event. Mouse direction:%d\n",mouse_dir);
ProcessMouseWheel(mouse_dir); // in proc.c
}
return 0;
}
#else
/***************** LINUX WORLD ***********************/
#include "gtk/gtk.h"
#include "gdk/gdkkeysyms.h"
#include <stdio.h>
static void gd_scroll_event(GtkWidget *widget, GdkEventScroll *scroll, void * s);
void SetMouseWheelCallback(void)
{
GtkWidget * widget;
widget=(GtkWidget * )cvGetWindowHandle(MAIN_WINDOW);
g_signal_connect(widget, "scroll-event", G_CALLBACK(gd_scroll_event),NULL);
}
static void gd_scroll_event(GtkWidget *widget, GdkEventScroll *scroll, void * s)
{
s=s;
int mouse_dir;
if (scroll->direction == GDK_SCROLL_UP)
{
mouse_dir=1;
}
else if (scroll->direction == GDK_SCROLL_DOWN)
{
mouse_dir=0;
}
else
{
return ; // No scroll
}
ProcessMouseWheel(mouse_dir); // in proc.c
return;
}
#endif