Inform on relative position to touch event.

This commit is contained in:
Dorian 2017-07-27 17:53:12 -04:00
parent 2aaa27a824
commit f2dc566667
2 changed files with 10 additions and 0 deletions

View File

@ -4,6 +4,7 @@ BoxLayout:
orientation: 'horizontal'
HexMap:
id: map
coords_display: coords
size_hint: .8, 1
MapLabel:
id: coords

View File

@ -1,5 +1,6 @@
from kivy.app import App
from kivy.graphics import *
from kivy.properties import ObjectProperty
from kivy.uix.widget import Widget
from kivy.utils import get_color_from_hex
@ -9,6 +10,7 @@ VERTICAL_BUFFER = 0.8
class HexMap(Widget):
coords_display = ObjectProperty(None)
def __init__(self, **kwargs):
super(HexMap, self).__init__(**kwargs)
@ -17,6 +19,9 @@ class HexMap(Widget):
# It is crucial to redraw the scene whenever the scene or position changes.
self.bind(size=self.redraw_scene, pos=self.redraw_scene)
self.updates = 0
self.on_touch_down = self.update_coords
def redraw_scene(self, *args):
with self.canvas:
# Clear scene
@ -52,6 +57,10 @@ class HexMap(Widget):
size=(HEX_SIZE, HEX_SIZE),
)
def update_coords(self, touch_event):
self.coords_display.text = "Touched at {}".format(touch_event.spos)
return True
class HexMapApp(App):
pass