Skip to content

Commit

Permalink
Android/Kivy version
Browse files Browse the repository at this point in the history
- Zoom: bug fixes and refactoring
  • Loading branch information
lufebe16 committed Nov 9, 2024
1 parent 552585f commit 2bfc6bd
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 73 deletions.
8 changes: 8 additions & 0 deletions buildozer/buildozer.run
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ export GRADLE_OPTS="-Xms1724m -Xmx5048m -Dorg.gradle.jvmargs='-Xms1724m -Xmx5048

echo '### run buildozer'


if [ "$1" == "test" ]
then
echo '### ... release.test'
buildozer --profile test android release
exit 0
fi

if [ "$1" ]
then
echo '### ... release'
Expand Down
4 changes: 4 additions & 0 deletions buildozer/buildozer.spec
Original file line number Diff line number Diff line change
Expand Up @@ -441,3 +441,7 @@ warn_on_root = 1
# Then, invoke the command line with the "demo" profile:
#
#buildozer --profile demo android debug

[app@test]
title = PySolFC.test
package.name = pysolfc.test
15 changes: 15 additions & 0 deletions pysollib/kivy/tkcanvas.py
Original file line number Diff line number Diff line change
Expand Up @@ -653,6 +653,21 @@ def __init__(self, wmain, *args, **kw):
self.bind(pos=self.pos_update_widget)
self.bind(size=self.size_update_widget)

def on_touch_down(self,touch):
ret = False
ret = super(MfxCanvas,self).on_touch_down(touch)
return ret

def on_touch_up(self,touch):
ret = False
ret = super(MfxCanvas,self).on_touch_up(touch)
return ret

def on_touch_move(self,touch):
ret = False
ret = super(MfxCanvas,self).on_touch_move(touch)
return ret

def KivyToCoreP(self, pos, size, scale):
cpos = pos
cpos = (cpos[0] - self.pos[0], self.pos[1] +
Expand Down
125 changes: 52 additions & 73 deletions pysollib/kivy/tkwidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -383,27 +383,29 @@ def __init__(self, inner, **kw):
self.inner = inner
self.add_widget(inner)
self.bind(pos=self._updatepos)
self.bind(size=self._update)
self.bind(size=self._updatesize)
self.do_rotation = False
self.scale_min = 1.0
self.scale_max = 2.5
self.do_collide_after_children = True
self.saved_pos = None
self.scale_max = 2.2
self.lock_pos = None
self.offset = None

def _update(self,instance,value):
print("_update",self.pos,self.size)
self.inner.size = self.size

def _updatepos(self,instance,value):
print("_updatepos",self.pos,self.size)
def _update(self):
if self.lock_pos is None:
self.lock_pos = "locked"
if self.saved_pos is not None:
px = self.parent.pos[0]+self.saved_pos[0]
py = self.parent.pos[1]+self.saved_pos[1]
self.pos = (px,py)
if self.offset is not None:
dx = round(self.offset[0] * (self.bbox[1][0] - self.size[0]))
dy = round(self.offset[1] * (self.bbox[1][1] - self.size[1]))
self.pos = (self.parent.pos[0]-dx,self.parent.pos[1]-dy)
self.lock_pos = None
print("_update",self.pos,self.size)

def _updatesize(self,instance,value):
self.inner.size = self.size
self._update()

def _updatepos(self,instance,value):
self._update()

def collide_point(self,x,y):
px,py = self.parent.pos
Expand All @@ -413,85 +415,62 @@ def collide_point(self,x,y):
return False

def on_touch_down(self, touch):
ret = False
if touch.is_double_tap: return False
x,y = touch.pos
if self.collide_point(x,y):
ret = super(LScatterFrame, self).on_touch_down(touch)
return ret
return super(LScatterFrame, self).on_touch_down(touch)
return False

def on_touch_up(self, touch):
ret = False
if touch.grab_current == self:
return super(LScatterFrame, self).on_touch_up(touch)

x,y = touch.pos
if self.collide_point(x,y):
ret = super(LScatterFrame, self).on_touch_up(touch)
return ret
return super(LScatterFrame, self).on_touch_up(touch)
return False

def on_touch_move(self, touch):
ret = False
x,y = touch.pos
if self.collide_point(x,y):
self.lock_pos = "locked"
ret = super(LScatterFrame, self).on_touch_move(touch)
self.lock_pos = None
self.lock_pos = "locked"
ret = super(LScatterFrame, self).on_touch_move(touch)
self.lock_pos = None
return ret

def on_transform_with_touch(self,touch):
print("on_transform",self.transform)

# Restrict translation so that the widget remains fully
# filled and the game cannot leave the screen completely.

# calculate appearant size. As we do not allow rotation
# this will work.
pw,ph = self.parent.size
il = self.transform.transform_point(0,0,0)
iu = self.transform.transform_point(pw,ph,0)
print ("il",il)
print ("iu",iu)

# Our Edge points are now:
w = iu[0] - il[0]
h = iu[1] - il[1]
x,y = self.pos
self.chk_bnd()

def chk_bnd(self):
# Keep the game on the screen.

# limiting parameters:
pos,size = self.bbox
w,h = size
x,y = pos
px,py = self.parent.pos
sx,sy = self.parent.size

print("dim-inner",x,y,w,h)
print("dim-parent",px,py,sx,sy)

# calculate correction matrices
tmx = None
tmy = None
tmxx = None
tmyy = None
# calculate correction matrix and apply
tm = Matrix()
if (x>px):
tmx = Matrix().translate(px-x,0,0)
print("x0")
tm = tm.multiply(Matrix().translate(px-x,0,0))
if (y>py):
tmy = Matrix().translate(0,py-y,0)
print("y0")
tm = tm.multiply(Matrix().translate(0,py-y,0))
if ((x+w) <= (px+sx)):
tmxx = Matrix().translate(px+sx-x-w,0,0)
print("x1")
tm = tm.multiply(Matrix().translate(px+sx-x-w,0,0))
if ((y+h) <= (py+sy)):
tmyy = Matrix().translate(0,py+sy-y-h,0)
print("y1")

# combine and apply
tm = Matrix()
if tmx is not None:
tm = tm.multiply(tmx)
if tmy is not None:
tm = tm.multiply(tmy)
if tmxx is not None:
tm = tm.multiply(tmxx)
if tmyy is not None:
tm = tm.multiply(tmyy)

tm = tm.multiply(Matrix().translate(0,py+sy-y-h,0))
self.apply_transform(tm)
offx = self.pos[0] - self.parent.pos[0]
offy = self.pos[1] - self.parent.pos[1]
self.saved_pos = (offx,offy)

# save current offset.
self.offset = None
offx = self.parent.pos[0] - self.pos[0]
offy = self.parent.pos[1] - self.pos[1]
offmx = float(self.bbox[1][0] - self.size[0])
offmy = float(self.bbox[1][1] - self.size[1])
if (offmx>0 and offmy>0):
self.offset = (offx/offmx,offy/offmy)
# print ("offset = ",self.offset)


class LScrollFrame(BoxLayout,StencilView):
Expand Down

0 comments on commit 2bfc6bd

Please sign in to comment.