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): ...@@ -43,25 +43,28 @@ class Area(Positionable, Logger):
if not self.parent: if not self.parent:
return self.get_position() 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): def get_root_position(self):
""" """
Get the position relative to the root area. Get the position relative to the root area.
""" """
if not self.parent: 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): def get_offset(self, offset_area):
""" """
Get the position relative to an ancestor area. Get the position relative to an ancestor area.
""" """
if self.parent == offset_area: if self == offset_area:
return self.get_position() 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): def add_area(self, area):
""" """
...@@ -178,11 +181,11 @@ class Area(Positionable, Logger): ...@@ -178,11 +181,11 @@ class Area(Positionable, Logger):
child_found = False child_found = False
if self.children: if self.children:
event.set_area(self)
# Delegate to children in reverse order because areas that are # Delegate to children in reverse order because areas that are
# added later, should be placed over previously added siblings # added later, should be placed over previously added siblings
for child in reversed(self.children): for child in reversed(self.children):
event.set_area(self)
if child.contains_event(event): if child.contains_event(event):
child_found = True child_found = True
child.delegate_event(event) child.delegate_event(event)
......
...@@ -26,9 +26,9 @@ class RectangularArea(Area): ...@@ -26,9 +26,9 @@ class RectangularArea(Area):
return self.width, self.height return self.width, self.height
def contains_event(self, event): def contains_event(self, event):
x, y = event.get_offset() ex, ey = event.get_position()
return self.x <= x <= self.x + self.width \ return self.x <= ex <= self.x + self.width \
and self.y <= y <= self.y + self.height and self.y <= ey <= self.y + self.height
class CircularArea(Area): class CircularArea(Area):
......
...@@ -21,9 +21,7 @@ class EventDriver(Logger): ...@@ -21,9 +21,7 @@ class EventDriver(Logger):
Delegate an event that has been triggered by the event driver to the Delegate an event that has been triggered by the event driver to the
area tree. area tree.
""" """
if self.root_area.contains_event(event): self.root_area.delegate_event(event)
event.set_area(self.root_area)
self.root_area.delegate_event(event)
def start(self): def start(self):
""" """
......
from copy import copy
from geometry import Positionable from geometry import Positionable
from touch_objects import OBJECT_NAMES from touch_objects import OBJECT_NAMES
...@@ -40,7 +42,7 @@ class Event(Positionable): ...@@ -40,7 +42,7 @@ class Event(Positionable):
def get_offset(self, area): def get_offset(self, area):
ox, oy = area.get_screen_position() 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): def get_type(self):
return self._type return self._type
...@@ -60,3 +62,6 @@ class Event(Positionable): ...@@ -60,3 +62,6 @@ class Event(Positionable):
def is_immediate_propagation_stopped(self): def is_immediate_propagation_stopped(self):
return self.stopped_immidiate 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