Commit 918eb1b3 authored by Taddeus Kroes's avatar Taddeus Kroes

Positions are now expressed in numbers instead of objects.

parent a7a2067c
......@@ -43,25 +43,28 @@ class Area(Positionable, Logger):
if not self.parent:
return self.get_position()
return self.get_position() + self.parent.get_screen_position()
ox, oy = self.parent.get_screen_position()
return ox + self.x, oy + self.y
def get_root_position(self):
"""
Get the position relative to the root area.
"""
if not self.parent:
return Positionable(0, 0)
return 0, 0
return self.get_position() + self.parent.get_root_position()
ox, oy = self.parent.get_root_position()
return ox + self.x, oy + self.y
def get_offset(self, offset_area):
"""
Get the position relative to an ancestor area.
"""
if self.parent == offset_area:
return self.get_position()
if self == offset_area:
return 0, 0
return self.get_position() + self.parent.get_offset(offset_area)
ox, oy = self.parent.get_offset(offset_area)
return ox + self.x, oy + self.y
def add_area(self, area):
"""
......@@ -178,11 +181,11 @@ class Area(Positionable, Logger):
child_found = False
if self.children:
event.set_area(self)
# Delegate to children in reverse order because areas that are
# added later, should be placed over previously added siblings
for child in reversed(self.children):
event.set_area(self)
if child.contains_event(event):
child_found = True
child.delegate_event(event)
......
......@@ -26,9 +26,9 @@ class RectangularArea(Area):
return self.width, self.height
def contains_event(self, event):
x, y = event.get_offset()
return self.x <= x <= self.x + self.width \
and self.y <= y <= self.y + self.height
ex, ey = event.get_position()
return self.x <= ex <= self.x + self.width \
and self.y <= ey <= self.y + self.height
class CircularArea(Area):
......
......@@ -21,8 +21,6 @@ class EventDriver(Logger):
Delegate an event that has been triggered by the event driver to the
area tree.
"""
if self.root_area.contains_event(event):
event.set_area(self.root_area)
self.root_area.delegate_event(event)
def start(self):
......
from copy import copy
from geometry import Positionable
from touch_objects import OBJECT_NAMES
......@@ -40,7 +42,7 @@ class Event(Positionable):
def get_offset(self, area):
ox, oy = area.get_screen_position()
return Positionable(self.x - ox, self.y - oy)
return self.x - ox, self.y - oy
def get_type(self):
return self._type
......@@ -60,3 +62,6 @@ class Event(Positionable):
def is_immediate_propagation_stopped(self):
return self.stopped_immidiate
def clone(self):
return copy(self)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment