Skip to content

Commit

Permalink
Kivy/Android
Browse files Browse the repository at this point in the history
- reworked positioning during animations
  • Loading branch information
lufebe16 committed Nov 29, 2023
1 parent ce0e6ff commit 288bd92
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 27 deletions.
2 changes: 1 addition & 1 deletion pysollib/game/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1455,7 +1455,7 @@ def animatedMoveTo(self, from_stack, to_stack, cards, x, y,
c0 = cards[0]
dx, dy = (x - c0.x), (y - c0.y)
base = float(self.app.opt.animations)
duration = base*base/20.0 + 0.05
duration = base*base/25.0 + 0.05
for card in cards:
card.animatedMove(dx, dy, duration)
# self.top.waitAnimation(swallow=True, pickup=True)
Expand Down
2 changes: 1 addition & 1 deletion pysollib/kivy/LApp.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ def __init__(self, anim, spos, widget, delay):
self.anim = anim
self.spos = spos
self.widget = widget
# print(self.widget.card)
print(self.widget.card)
self.delay = delay

def start(self):
Expand Down
66 changes: 41 additions & 25 deletions pysollib/kivy/tkcanvas.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,7 @@ def __init__(self, canvas, *args, **kwargs):
# animation support:
self.animation = None
self.deferred_raises = []
self.deferred_pos = []

ed = kwargs['image']
size = ed.size
Expand Down Expand Up @@ -369,23 +370,37 @@ def move(self, dx, dy):
image.corePos = dpos
if not self.animation:
image.pos, image.size = self.canvas.CoreToKivy(dpos, dsize)
else:
pos, size = self.canvas.CoreToKivy(dpos, dsize)
self.deferred_pos.append(pos)

def makeAnimStart(self):
def animStart(anim, widget):
# print('MfxCanvasImage: animStart %s' % self)
for cb in self.deferred_raises:
cb()
self.deferred_raises = []

# raise to top if reqested for this move
if self.deferred_raises:
self.deferred_raises[0]()
self.deferred_raises = self.deferred_raises[1:]

# fix destination position (hack into animation class - not nice)
if self.deferred_pos:
widgets = anim._widgets
for uid in list(widgets.keys()):
anim = widgets[uid]
p = anim['properties']
# print (p)
p['x'] = (p['x'][0], self.deferred_pos[0][0])
p['y'] = (p['y'][0], self.deferred_pos[0][1])
# print (p)
self.deferred_pos = self.deferred_pos[1:]
return animStart

def makeAnimEnd(self, dpos, dsize):
def animEnd(anim, widget):
# print('MfxCanvasImage: animEnd %s' % self)
self.animation = False
self.deferred_raises = []
image = self.image
image.pos, image.size = self.canvas.CoreToKivy(dpos, dsize)
# print('MfxCanvasImage: animEnd moved to %s, %s' % (dpos[0], dpos[1])) # noqa
return animEnd

def animatedMove(self, dx, dy, duration=0.2):
Expand Down Expand Up @@ -745,28 +760,29 @@ def tag_raise(self, itm, abitm=None):
if (itm is not None):
if (abitm is None):
# print('MfxCanvas: tag_raise: to top')
self.clear_widgets([itm])
self.remove_widget(itm)
self.add_widget(itm)
else:
print('MfxCanvas: tag_raise: to specified position')
ws = []
for c in reversed(self.children): # reversed!
if c != itm and c != abitm:
ws.append(c)
if c == itm:
continue
if c == abitm:
ws.append(abitm)
ws.append(itm)
self.clear_widgets()
for w in ws:
self.add_widget(w)

def tag_lower(self, id, belowThis=None):
print('MfxCanvas: tag_lower(%s, %s)' % (id, belowThis))
# y = self.yy # kommt das vor ?
pass
# print('MfxCanvas: tag_raise: to specified position')
self.remove_widget(itm)
k = self.children.index(abitm)
self.add_widget(itm, index=k)

def tag_lower(self, itm, belowThis=None):
print('MfxCanvas: tag_lower(%s, %s)' % (itm, belowThis))

if (itm is not None):
if (belowThis is None):
# print('MfxCanvas: tag_lower: to bottom')
self.remove_widget(itm)
k = len(self.children.index)
self.add_widget(itm,index=k)
else:
# print('MfxCanvas: tag_lower: to specified position')
self.remove_widget(itm)
k = self.children.index(belowThis)
k += 1
self.add_widget(itm, index=k)
#
#
#
Expand Down

0 comments on commit 288bd92

Please sign in to comment.