Skip to content

Commit

Permalink
Android/Kivy:
Browse files Browse the repository at this point in the history
- Event handling: Pass through for empty stacks.
- Menu entry to reset zoom.
  • Loading branch information
lufebe16 committed Nov 12, 2024
1 parent 70909f6 commit 0135e38
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
12 changes: 8 additions & 4 deletions pysollib/kivy/LApp.py
Original file line number Diff line number Diff line change
Expand Up @@ -806,6 +806,10 @@ def get_image_type(self):
- Most events return EVENT_HANDLED even if they did not change anything
in current situations. I would expect specifically for stack base cards
that they return HANDLE_PROPAGATE if nothing happened.
- stack __defaultclickhandler__ returns EVENT_HANDLED in any case so some
code here is obsolete or for future.
- A pragmatic way to handle this: If an empty stack is still empty
after the click then we propagate otherwise not.
LB241111.
'''

Expand Down Expand Up @@ -851,7 +855,6 @@ def on_touch_down(self, touch):
self.dragstart = touch.pos
event.cardid = i
r = self.send_event_pressed(touch, event)
# print("********* event return = ",r)
if r == EVENT_HANDLED:
AndroidScreenRotation.lock(toaster=False)
print('grab')
Expand All @@ -869,7 +872,8 @@ def on_touch_down(self, touch):
event.y = ppos[1]
r = self.group.bindings['<1>'](event)
if r == EVENT_HANDLED:
return True
if len(self.group.stack.cards) > 0:
return True
return False

if self.card is None:
Expand Down Expand Up @@ -907,7 +911,6 @@ def on_touch_up(self, touch):
event.y = ppos[1]
event.cardid = i
r = self.send_event_released_1(event)
# print("********* event return = ",r)
if r == EVENT_HANDLED:
return True
return False
Expand All @@ -922,7 +925,8 @@ def on_touch_up(self, touch):
event.y = ppos[1]
r = self.group.bindings['<ButtonRelease-1>'](event)
if r == EVENT_HANDLED:
return True
if len(self.group.stack.cards) > 0:
return True
return False

if self.card is None:
Expand Down
6 changes: 6 additions & 0 deletions pysollib/kivy/menubar.py
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,9 @@ def buildTree(self, tv, node):
text=_('Shuffle tiles'), command=self.menubar.mShuffle))
tv.add_node(LTreeNode(
text=_('Deal cards'), command=self.menubar.mDeal))
tv.add_node(LTreeNode(
text=_('Reset zoom'),
command=self.auto_close(self.menubar.mResetZoom)))

self.addCheckNode(tv, None,
_('Pause'),
Expand Down Expand Up @@ -2141,6 +2144,9 @@ def mSaveAs(self, *event):
toast.show(parent=baseWindow, duration=5.0)
self.updateMenus()

def mResetZoom(self, *args):
self.tkopt.table_zoom.value = [1.0, 0.0, 0.0]

def mPause(self, *args):
if not self.game:
return
Expand Down
5 changes: 5 additions & 0 deletions pysollib/kivy/tkwidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,10 @@ def set_scale(self,zoom):
yoff = zoom[2]
self.offset = (xoff,yoff)

def _change_command(self,inst,val):
if self.lock_pos is None:
self.set_scale(val)

def _update(self):
# initialisation
if self.tkopt is None:
Expand All @@ -407,6 +411,7 @@ def _update(self):
self.tkopt = tkopt
self.set_scale(tkopt.table_zoom.value)
print("table_zoom",tkopt.table_zoom.value)
tkopt.table_zoom.bind(value=self._change_command)

# update
if self.lock_pos is None:
Expand Down

0 comments on commit 0135e38

Please sign in to comment.