Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
multitouch
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Taddeüs Kroes
multitouch
Commits
a7a2067c
Commit
a7a2067c
authored
12 years ago
by
Taddeus Kroes
Browse files
Options
Downloads
Patches
Plain Diff
Fixed offset positioning of events/areas.
parent
53c4d2ba
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/area.py
+29
-24
29 additions, 24 deletions
src/area.py
src/driver.py
+1
-1
1 addition, 1 deletion
src/driver.py
src/event.py
+14
-9
14 additions, 9 deletions
src/event.py
with
44 additions
and
34 deletions
src/area.py
+
29
−
24
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
():
b
re
ak
re
turn
if
self
.
parent
and
not
event
.
is_propagation_stopped
():
self
.
parent
.
propagate_event
(
event
)
...
...
This diff is collapsed.
Click to expand it.
src/driver.py
+
1
−
1
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
):
...
...
This diff is collapsed.
Click to expand it.
src/event.py
+
14
−
9
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
g
et_
offset
(
self
):
return
self
-
self
.
offset
def
s
et_
area
(
self
,
area
):
self
.
area
=
area
def
s
et_
offset
(
self
,
offset
):
self
.
offset
.
set_position
(
*
offset
)
def
g
et_
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
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment