Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
K
kicad-source-mirror
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Commits
Open sidebar
Elphel
kicad-source-mirror
Commits
9daa1ab5
Commit
9daa1ab5
authored
Sep 10, 2013
by
tomasz.wlostowski@cern.ch
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
TOOL_DISPATCHER: improve mouse handling
parent
6ac8188f
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
13 deletions
+21
-13
tool_dispatcher.cpp
common/tool/tool_dispatcher.cpp
+19
-13
tool_dispatcher.h
include/tool/tool_dispatcher.h
+2
-0
No files found.
common/tool/tool_dispatcher.cpp
View file @
9daa1ab5
...
...
@@ -55,6 +55,8 @@ struct TOOL_DISPATCHER::ButtonState
bool
pressed
;
VECTOR2D
dragOrigin
;
VECTOR2D
downPosition
;
double
dragMaxDelta
;
TOOL_MouseButtons
button
;
...
...
@@ -117,13 +119,21 @@ int TOOL_DISPATCHER::decodeModifiers( const wxKeyboardState* aState ) const
return
mods
;
}
wxPoint
TOOL_DISPATCHER
::
getCurrentMousePos
()
{
wxPoint
msp
=
wxGetMousePosition
()
;
wxPoint
winp
=
m_editFrame
->
GetGalCanvas
()
->
GetScreenPosition
();
return
wxPoint
(
msp
.
x
-
winp
.
x
,
msp
.
y
-
winp
.
y
);
}
bool
TOOL_DISPATCHER
::
handleMouseButton
(
wxEvent
&
aEvent
,
int
aIndex
,
bool
aMotion
)
{
ButtonState
*
st
=
m_buttons
[
aIndex
];
wxEventType
type
=
aEvent
.
GetEventType
();
optional
<
TOOL_EVENT
>
evt
;
bool
isClick
=
false
;
bool
up
=
type
==
st
->
upEvent
;
bool
down
=
type
==
st
->
downEvent
;
...
...
@@ -134,20 +144,20 @@ bool TOOL_DISPATCHER::handleMouseButton( wxEvent& aEvent, int aIndex, bool aMoti
{
st
->
downTimestamp
=
wxGetLocalTimeMillis
();
st
->
dragOrigin
=
m_lastMousePos
;
st
->
downPosition
=
m_lastMousePos
;
st
->
dragMaxDelta
=
0
;
st
->
pressed
=
true
;
evt
=
TOOL_EVENT
(
TC_Mouse
,
TA_MouseDown
,
args
);
}
else
if
(
up
)
{
bool
isClick
=
false
;
st
->
pressed
=
false
;
if
(
st
->
dragging
)
{
wxLongLong
t
=
wxGetLocalTimeMillis
();
if
(
t
-
st
->
downTimestamp
<
DragTimeThreshold
&&
if
(
t
-
st
->
downTimestamp
<
DragTimeThreshold
||
st
->
dragMaxDelta
<
DragDistanceThreshold
)
isClick
=
true
;
else
...
...
@@ -158,13 +168,7 @@ bool TOOL_DISPATCHER::handleMouseButton( wxEvent& aEvent, int aIndex, bool aMoti
if
(
isClick
)
{
if
(
st
->
triggerContextMenu
&&
!
mods
)
{}
// evt = TOOL_EVENT( TC_Command, TA_ContextMenu );
else
evt
=
TOOL_EVENT
(
TC_Mouse
,
TA_MouseClick
,
args
);
}
evt
=
TOOL_EVENT
(
TC_Mouse
,
TA_MouseClick
,
args
);
st
->
dragging
=
false
;
}
...
...
@@ -177,7 +181,7 @@ bool TOOL_DISPATCHER::handleMouseButton( wxEvent& aEvent, int aIndex, bool aMoti
wxLongLong
t
=
wxGetLocalTimeMillis
();
if
(
t
-
st
->
downTimestamp
>
DragTimeThreshold
||
st
->
dragMaxDelta
>
DragDistanceThreshold
)
if
(
t
-
st
->
downTimestamp
>
DragTimeThreshold
&&
st
->
dragMaxDelta
>
DragDistanceThreshold
)
{
evt
=
TOOL_EVENT
(
TC_Mouse
,
TA_MouseDrag
,
args
);
evt
->
SetMouseDragOrigin
(
st
->
dragOrigin
);
...
...
@@ -187,7 +191,7 @@ bool TOOL_DISPATCHER::handleMouseButton( wxEvent& aEvent, int aIndex, bool aMoti
if
(
evt
)
{
evt
->
SetMousePosition
(
m_lastMousePos
);
evt
->
SetMousePosition
(
isClick
?
st
->
downPosition
:
m_lastMousePos
);
m_toolMgr
->
ProcessEvent
(
*
evt
);
return
true
;
...
...
@@ -212,7 +216,9 @@ void TOOL_DISPATCHER::DispatchWxEvent( wxEvent& aEvent )
type
==
wxEVT_RIGHT_DOWN
||
type
==
wxEVT_RIGHT_UP
)
{
wxMouseEvent
*
me
=
static_cast
<
wxMouseEvent
*>
(
&
aEvent
);
pos
=
getView
()
->
ToWorld
(
VECTOR2D
(
me
->
GetX
(),
me
->
GetY
()
)
);
pos
=
getView
()
->
ToWorld
(
getCurrentMousePos
()
);
if
(
pos
!=
m_lastMousePos
)
{
motion
=
true
;
...
...
include/tool/tool_dispatcher.h
View file @
9daa1ab5
...
...
@@ -73,6 +73,8 @@ private:
bool
handleMouseButton
(
wxEvent
&
aEvent
,
int
aIndex
,
bool
aMotion
);
bool
handlePopupMenu
(
wxEvent
&
aEvent
);
wxPoint
getCurrentMousePos
();
int
decodeModifiers
(
const
wxKeyboardState
*
aState
)
const
;
struct
ButtonState
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment