Inform on relative position to touch event.
This commit is contained in:
parent
2aaa27a824
commit
f2dc566667
|
@ -4,6 +4,7 @@ BoxLayout:
|
||||||
orientation: 'horizontal'
|
orientation: 'horizontal'
|
||||||
HexMap:
|
HexMap:
|
||||||
id: map
|
id: map
|
||||||
|
coords_display: coords
|
||||||
size_hint: .8, 1
|
size_hint: .8, 1
|
||||||
MapLabel:
|
MapLabel:
|
||||||
id: coords
|
id: coords
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
from kivy.app import App
|
from kivy.app import App
|
||||||
from kivy.graphics import *
|
from kivy.graphics import *
|
||||||
|
from kivy.properties import ObjectProperty
|
||||||
from kivy.uix.widget import Widget
|
from kivy.uix.widget import Widget
|
||||||
from kivy.utils import get_color_from_hex
|
from kivy.utils import get_color_from_hex
|
||||||
|
|
||||||
|
@ -9,6 +10,7 @@ VERTICAL_BUFFER = 0.8
|
||||||
|
|
||||||
|
|
||||||
class HexMap(Widget):
|
class HexMap(Widget):
|
||||||
|
coords_display = ObjectProperty(None)
|
||||||
|
|
||||||
def __init__(self, **kwargs):
|
def __init__(self, **kwargs):
|
||||||
super(HexMap, self).__init__(**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.
|
# It is crucial to redraw the scene whenever the scene or position changes.
|
||||||
self.bind(size=self.redraw_scene, pos=self.redraw_scene)
|
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):
|
def redraw_scene(self, *args):
|
||||||
with self.canvas:
|
with self.canvas:
|
||||||
# Clear scene
|
# Clear scene
|
||||||
|
@ -52,6 +57,10 @@ class HexMap(Widget):
|
||||||
size=(HEX_SIZE, HEX_SIZE),
|
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):
|
class HexMapApp(App):
|
||||||
pass
|
pass
|
||||||
|
|
Loading…
Reference in New Issue