1
0
Fork 0
mirror of https://github.com/shlomif/PySolFC.git synced 2025-04-05 00:02:29 -04:00

Kivy version scaling issues

- scaling of redeal image based on card size.
     - correction of fonts size and selection frame thickness.
This commit is contained in:
lufebe16 2022-12-05 13:37:33 +01:00
parent ff85c289ae
commit a7e55513bd
3 changed files with 82 additions and 29 deletions

View file

@ -44,7 +44,6 @@ from kivy.uix.actionbar import ActionPrevious
from kivy.uix.actionbar import ActionView from kivy.uix.actionbar import ActionView
from kivy.uix.behaviors import ButtonBehavior from kivy.uix.behaviors import ButtonBehavior
from kivy.uix.boxlayout import BoxLayout from kivy.uix.boxlayout import BoxLayout
from kivy.uix.button import Button
from kivy.uix.image import Image as KivyImage from kivy.uix.image import Image as KivyImage
from kivy.uix.label import Label from kivy.uix.label import Label
from kivy.uix.scrollview import ScrollView from kivy.uix.scrollview import ScrollView
@ -54,6 +53,7 @@ from kivy.uix.widget import Widget
from kivy.utils import platform from kivy.utils import platform
from pysollib.kivy.androidperms import requestStoragePerm from pysollib.kivy.androidperms import requestStoragePerm
from pysollib.resource import CSI
if platform != 'android': if platform != 'android':
Config.set('input', 'mouse', 'mouse,multitouch_on_demand') Config.set('input', 'mouse', 'mouse,multitouch_on_demand')
@ -333,6 +333,50 @@ def LColorToKivy(outline):
# ============================================================================= # =============================================================================
def cardfactor(canvas):
# heuristic to find some sort of 'fontsize' out of the cardset.
# We take the original small cardsets as reference and calculate
# a correction factor.
def pyth(a, b):
return math.sqrt(a*a+b*b)
cardscale = 1.0
try:
cs = canvas.wmain.app.images.cs
print('Cardset:', cs)
print('Cardset:', cs.type)
cardbase = pyth(73, 97)
if cs.type == CSI.TYPE_FRENCH:
cardbase = pyth(73, 97)
elif cs.type == CSI.TYPE_HANAFUDA:
cardbase = pyth(64, 102)
elif cs.type == CSI.TYPE_MAHJONGG:
cardbase = pyth(38, 54)
elif cs.type == CSI.TYPE_TAROCK:
cardbase = pyth(80, 80)
elif cs.type == CSI.TYPE_HEXADECK:
cardbase = pyth(50, 80)
elif cs.type == CSI.TYPE_MUGHAL_GANJIFA:
cardbase = pyth(80, 80)
elif cs.type == CSI.TYPE_NAVAGRAHA_GANJIFA:
cardbase = pyth(80, 80)
elif cs.type == CSI.TYPE_DASHAVATARA_GANJIFA:
cardbase = pyth(80, 80)
elif cs.type == CSI.TYPE_TRUMP_ONLY:
cardbase = pyth(35, 35)
si = canvas.wmain.app.images.getSize()
cardsize = pyth(si[0], si[1])
cardscale = cardsize/cardbase
except: # noqa: E722
pass
return cardscale
# =============================================================================
class LText(Widget, LBase): class LText(Widget, LBase):
text = StringProperty('') text = StringProperty('')
@ -362,7 +406,7 @@ class LText(Widget, LBase):
# print('LText: text = %s' % (self.text)) # print('LText: text = %s' % (self.text))
kwargs['font'] = font kwargs['font'] = font
kwargs['font_size'] = fontsize kwargs['font_size'] = fontsize * cardfactor(canvas)
class MyLabel(Label, LBase): class MyLabel(Label, LBase):
pass pass
@ -653,9 +697,10 @@ class LRectangle(Widget, LBase):
bpos[0], tpos[1], bpos[0], tpos[1],
bpos[0], bpos[1]] bpos[0], bpos[1]]
cf = cardfactor(self.prnt)
dmy, brd = self.prnt.CoreToKivy( dmy, brd = self.prnt.CoreToKivy(
(0.0, 0.0), (self.border, self.border)) (0.0, 0.0), (self.border, self.border))
border = brd[1] border = brd[1] * cf
self.canvas.clear() self.canvas.clear()
with self.canvas: with self.canvas:
@ -1549,21 +1594,10 @@ class LMainWindow(BoxLayout, LTkBase):
self.toolBarPos = 0 self.toolBarPos = 0
self.bindings = {} self.bindings = {}
self._w = '.' self._w = '.'
self.topLine = Button(
size_hint=(1.0, 0.01),
background_down='atlas:'
'//data/images/defaulttheme/action_item_down',
background_normal='atlas:'
'//data/images/defaulttheme/action_item',
border=(0, 0, 0, 0))
self.topLine1 = Label(size_hint=(1.0, 0.01))
self.add_widget(self.topLine)
self.add_widget(self.menuArea) self.add_widget(self.menuArea)
self.add_widget(self.topLine1)
self.add_widget(self.workContainerO) self.add_widget(self.workContainerO)
self.workContainerO.add_widget(self.workContainer) self.workContainerO.add_widget(self.workContainer)
# self.add_widget(Button(size_hint = (1.0, 0.01)))
self.workStack = LStack() self.workStack = LStack()
self.app = None self.app = None

View file

@ -25,6 +25,7 @@
from __future__ import division from __future__ import division
import logging import logging
import math
from kivy.clock import Clock from kivy.clock import Clock
from kivy.graphics import Color from kivy.graphics import Color
@ -153,6 +154,17 @@ class MfxCanvasGroup():
return None return None
def cardmagnif(canvas, size):
def pyth(s):
return math.sqrt(s[0]*s[0]+s[1]*s[1])
cs = canvas.wmain.app.images.getSize()
csl = pyth(cs)
sl = pyth(size)
return csl/sl
class MfxCanvasImage(object): class MfxCanvasImage(object):
def __init__(self, canvas, *args, **kwargs): def __init__(self, canvas, *args, **kwargs):
@ -168,6 +180,9 @@ class MfxCanvasImage(object):
self._anchor = None self._anchor = None
if 'anchor' in kwargs: if 'anchor' in kwargs:
self._anchor = kwargs['anchor'] self._anchor = kwargs['anchor']
self.hint = None
if 'hint' in kwargs:
self.hint = kwargs['hint']
super(MfxCanvasImage, self).__init__() super(MfxCanvasImage, self).__init__()
self.canvas = canvas self.canvas = canvas
@ -179,19 +194,17 @@ class MfxCanvasImage(object):
if type(ed) is LImageItem: if type(ed) is LImageItem:
aimage = ed aimage = ed
else: else:
if (ed.source is None): image = LImage(texture=ed.texture)
image = LImage(texture=ed.texture) if self.hint == "redeal_image":
image.size = [ed.getWidth(), ed.getHeight()] cm = cardmagnif(canvas, size)/3.0
aimage = LImageItem(size=image.size, group=group) image.size = [cm*ed.getWidth(), cm*ed.getHeight()]
aimage.add_widget(image)
size = image.size
else: else:
image = LImage(texture=ed.texture)
# image = LImage(source=ed.source)
image.size = [ed.getWidth(), ed.getHeight()] image.size = [ed.getWidth(), ed.getHeight()]
aimage = LImageItem(size=ed.size, group=group)
aimage.add_widget(image) aimage = LImageItem(size=ed.size, group=group)
size = image.size aimage.add_widget(image)
aimage.size = image.size
size = image.size
xy = addAnchorOffset(args, self._anchor, size) xy = addAnchorOffset(args, self._anchor, size)

View file

@ -1867,6 +1867,7 @@ class TalonStack(Stack,
def _addRedealImage(self): def _addRedealImage(self):
# add or remove the redeal image/text # add or remove the redeal image/text
if not self.is_visible or self.images.bottom is None: if not self.is_visible or self.images.bottom is None:
return return
if self.game.preview > 1: if self.game.preview > 1:
@ -1892,13 +1893,18 @@ class TalonStack(Stack,
img = (self.getRedealImages())[self.max_rounds != 1] img = (self.getRedealImages())[self.max_rounds != 1]
if img is not None: if img is not None:
self.images.redeal_img = img self.images.redeal_img = img
self.images.redeal = MfxCanvasImage(self.canvas,
cx, cy, image=img,
anchor="center",
group=self.group)
if TOOLKIT == 'tk': if TOOLKIT == 'tk':
self.images.redeal = MfxCanvasImage(self.canvas,
cx, cy, image=img,
anchor="center",
group=self.group)
self.images.redeal.tkraise(self.top_bottom) self.images.redeal.tkraise(self.top_bottom)
elif TOOLKIT == 'kivy': elif TOOLKIT == 'kivy':
self.images.redeal = MfxCanvasImage(self.canvas,
cx, cy, image=img,
anchor="center",
group=self.group,
hint="redeal_image")
self.images.redeal.tkraise(self.top_bottom) self.images.redeal.tkraise(self.top_bottom)
elif TOOLKIT == 'gtk': elif TOOLKIT == 'gtk':
# FIXME # FIXME