Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
multitouch
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Taddeüs Kroes
multitouch
Commits
a7a2067c
Commit
a7a2067c
authored
Jun 16, 2012
by
Taddeus Kroes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed offset positioning of events/areas.
parent
53c4d2ba
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
44 additions
and
34 deletions
+44
-34
src/area.py
src/area.py
+29
-24
src/driver.py
src/driver.py
+1
-1
src/event.py
src/event.py
+14
-9
No files found.
src/area.py
View file @
a7a2067c
...
...
@@ -8,9 +8,9 @@ from abc import ABCMeta, abstractmethod
class
Area
(
Positionable
,
Logger
):
"""
Abstract class for area implementations. A area represents a 2D object
on the screen in which gestures can occur. Handlers for a specific gesture
type
can be bound to a area.
Abstract class for area implementations. A area represents a 2D object
on
the screen in which gestures can occur. Handlers for specific gesture types
can be bound to a area.
"""
__metaclass__
=
ABCMeta
...
...
@@ -36,34 +36,32 @@ class Area(Positionable, Logger):
return
self
def
get_screen_
offset
(
self
):
def
get_screen_
position
(
self
):
"""
Get the position relative to the screen.
"""
root
=
self
.
get_root_area
()
return
root
+
self
.
get_offset
(
root
)
if
not
self
.
parent
:
return
self
.
get_position
()
return
self
.
get_position
()
+
self
.
parent
.
get_screen_position
()
def
get_
offset
(
self
,
offset_parent
=
None
):
def
get_
root_position
(
self
):
"""
Get the position relative to an offset parent. If no offset parent is
specified, the position relative to the root area is returned. The
position of the root area itself is (0, 0).
Get the position relative to the root area.
"""
if
not
offset_parent
:
offset_parent
=
self
.
get_root_area
()
if
not
self
.
parent
:
if
offset_parent
is
self
:
return
0
,
0
return
Positionable
(
0
,
0
)
ox
,
oy
=
offset_paret
x
=
y
=
0
else
:
ox
,
oy
=
offset_parent
x
=
self
.
x
y
=
self
.
y
return
self
.
get_position
()
+
self
.
parent
.
get_root_position
()
return
x
-
ox
,
y
-
oy
def
get_offset
(
self
,
offset_area
):
"""
Get the position relative to an ancestor area.
"""
if
self
.
parent
==
offset_area
:
return
self
.
get_position
()
return
self
.
get_position
()
+
self
.
parent
.
get_offset
(
offset_area
)
def
add_area
(
self
,
area
):
"""
...
...
@@ -180,7 +178,7 @@ class Area(Positionable, Logger):
child_found
=
False
if
self
.
children
:
event
.
set_
offset
(
self
.
get_offset
()
)
event
.
set_
area
(
self
)
# Delegate to children in reverse order because areas that are
# added later, should be placed over previously added siblings
...
...
@@ -196,11 +194,18 @@ class Area(Positionable, Logger):
self
.
propagate_event
(
event
)
def
propagate_event
(
self
,
event
):
"""
Delagate an event to all gesture trackers (immediate propagation), then
propagate it to the parent area (if any). Propagation can be stopped by
a tracker.
"""
event
.
set_area
(
self
)
for
tracker
in
self
.
trackers
:
tracker
.
handle_event
(
event
)
if
event
.
is_immediate_propagation_stopped
():
break
return
if
self
.
parent
and
not
event
.
is_propagation_stopped
():
self
.
parent
.
propagate_event
(
event
)
...
...
src/driver.py
View file @
a7a2067c
...
...
@@ -22,7 +22,7 @@ class EventDriver(Logger):
area tree.
"""
if
self
.
root_area
.
contains_event
(
event
):
event
.
set_
root_
area
(
self
.
root_area
)
event
.
set_area
(
self
.
root_area
)
self
.
root_area
.
delegate_event
(
event
)
def
start
(
self
):
...
...
src/event.py
View file @
a7a2067c
...
...
@@ -16,7 +16,7 @@ class Event(Positionable):
super
(
Event
,
self
).
__init__
(
*
touch_object
)
self
.
touch_object
=
touch_object
self
.
stopped
=
self
.
stopped_immidiate
=
False
self
.
offset
=
Positionable
(
0
,
0
)
self
.
area
=
None
def
__getattr__
(
self
,
name
):
if
name
in
OBJECT_NAMES
\
...
...
@@ -26,16 +26,21 @@ class Event(Positionable):
raise
AttributeError
(
"'%s' object has no attribute '%s'"
%
(
self
.
__class__
.
__name__
,
name
))
def
get_offset
(
self
):
return
self
-
self
.
offset
def
set_area
(
self
,
area
):
self
.
area
=
area
def
set_offset
(
self
,
offset
):
self
.
offset
.
set_position
(
*
offset
)
def
get_area
(
self
):
return
self
.
area
def
set_root_area
(
self
,
area
):
x
,
y
=
area
self
.
x
-=
x
self
.
y
-=
y
def
get_root_position
(
self
):
return
self
.
get_offset
(
self
.
area
.
get_root_area
())
def
get_position
(
self
):
return
self
.
get_offset
(
self
.
area
)
def
get_offset
(
self
,
area
):
ox
,
oy
=
area
.
get_screen_position
()
return
Positionable
(
self
.
x
-
ox
,
self
.
y
-
oy
)
def
get_type
(
self
):
return
self
.
_type
...
...
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