mirror of
https://github.com/shlomif/PySolFC.git
synced 2025-04-05 00:02:29 -04:00
Split spread stacks logic from auto-scale logic.
This commit is contained in:
parent
c792b7ff77
commit
dba55c20fd
6 changed files with 77 additions and 36 deletions
pysollib
|
@ -833,7 +833,8 @@ Please select a %(correct_type)s type cardset.
|
||||||
changed = False
|
changed = False
|
||||||
if USE_PIL:
|
if USE_PIL:
|
||||||
if (self.opt.scale_x, self.opt.scale_y,
|
if (self.opt.scale_x, self.opt.scale_y,
|
||||||
self.opt.auto_scale, self.opt.preserve_aspect_ratio) != \
|
self.opt.auto_scale, self.opt.spread_stacks,
|
||||||
|
self.opt.preserve_aspect_ratio) != \
|
||||||
d.scale_values or \
|
d.scale_values or \
|
||||||
(cs.CARD_XOFFSET, cs.CARD_YOFFSET) != d.cardset_values:
|
(cs.CARD_XOFFSET, cs.CARD_YOFFSET) != d.cardset_values:
|
||||||
changed = True
|
changed = True
|
||||||
|
@ -843,6 +844,7 @@ Please select a %(correct_type)s type cardset.
|
||||||
(self.opt.scale_x,
|
(self.opt.scale_x,
|
||||||
self.opt.scale_y,
|
self.opt.scale_y,
|
||||||
self.opt.auto_scale,
|
self.opt.auto_scale,
|
||||||
|
self.opt.spread_stacks,
|
||||||
self.opt.preserve_aspect_ratio) = d.scale_values
|
self.opt.preserve_aspect_ratio) = d.scale_values
|
||||||
if not self.opt.auto_scale:
|
if not self.opt.auto_scale:
|
||||||
self.images.resize(self.opt.scale_x, self.opt.scale_y)
|
self.images.resize(self.opt.scale_x, self.opt.scale_y)
|
||||||
|
|
|
@ -984,7 +984,8 @@ class Game(object):
|
||||||
|
|
||||||
def resizeImages(self, manually=False):
|
def resizeImages(self, manually=False):
|
||||||
# resizing images and cards
|
# resizing images and cards
|
||||||
if self.app.opt.auto_scale and not manually:
|
if (self.app.opt.auto_scale or
|
||||||
|
(self.app.opt.spread_stacks and not manually)):
|
||||||
if self.canvas.winfo_ismapped():
|
if self.canvas.winfo_ismapped():
|
||||||
# apparent size of canvas
|
# apparent size of canvas
|
||||||
vw = self.canvas.winfo_width()
|
vw = self.canvas.winfo_width()
|
||||||
|
@ -1002,10 +1003,12 @@ class Game(object):
|
||||||
# calculate factor of resizing
|
# calculate factor of resizing
|
||||||
xf = float(vw)/iw
|
xf = float(vw)/iw
|
||||||
yf = float(vh)/ih
|
yf = float(vh)/ih
|
||||||
if self.app.opt.preserve_aspect_ratio:
|
if (self.app.opt.preserve_aspect_ratio
|
||||||
|
and not self.app.opt.spread_stacks):
|
||||||
xf = yf = min(xf, yf)
|
xf = yf = min(xf, yf)
|
||||||
else:
|
else:
|
||||||
xf, yf = self.app.opt.scale_x, self.app.opt.scale_y
|
xf, yf = self.app.opt.scale_x, self.app.opt.scale_y
|
||||||
|
if (not self.app.opt.spread_stacks or manually):
|
||||||
# images
|
# images
|
||||||
self.app.images.resize(xf, yf)
|
self.app.images.resize(xf, yf)
|
||||||
# cards
|
# cards
|
||||||
|
@ -1024,20 +1027,23 @@ class Game(object):
|
||||||
x0, y0 = stack.init_coord
|
x0, y0 = stack.init_coord
|
||||||
x, y = int(round(x0*xf)), int(round(y0*yf))
|
x, y = int(round(x0*xf)), int(round(y0*yf))
|
||||||
|
|
||||||
# Do not move Talons
|
if (self.app.opt.spread_stacks):
|
||||||
# (because one would need to reposition
|
# Do not move Talons
|
||||||
# 'empty cross' and 'redeal' figures)
|
# (because one would need to reposition
|
||||||
# But in that case,
|
# 'empty cross' and 'redeal' figures)
|
||||||
# games with talon not placed top-left corner
|
# But in that case,
|
||||||
# will get it misplaced when auto_scale
|
# games with talon not placed top-left corner
|
||||||
# e.g. Suit Elevens
|
# will get it misplaced when auto_scale
|
||||||
# => player can fix that issue by setting auto_scale false
|
# e.g. Suit Elevens
|
||||||
if stack is self.s.talon:
|
# => player can fix that issue by setting auto_scale false
|
||||||
# stack.init_coord=(x, y)
|
if stack is self.s.talon:
|
||||||
if card_size_manually:
|
# stack.init_coord=(x, y)
|
||||||
stack.resize(xf, yf0)
|
if card_size_manually:
|
||||||
|
stack.resize(xf, yf0)
|
||||||
|
else:
|
||||||
|
stack.resize(xf0, yf0)
|
||||||
else:
|
else:
|
||||||
stack.resize(xf0, yf0)
|
stack.resize(xf, yf0)
|
||||||
else:
|
else:
|
||||||
stack.resize(xf, yf0)
|
stack.resize(xf, yf0)
|
||||||
stack.updatePositions()
|
stack.updatePositions()
|
||||||
|
|
|
@ -435,6 +435,7 @@ class Options:
|
||||||
self.scale_x = 1.0
|
self.scale_x = 1.0
|
||||||
self.scale_y = 1.0
|
self.scale_y = 1.0
|
||||||
self.auto_scale = False
|
self.auto_scale = False
|
||||||
|
self.spread_stacks = False
|
||||||
self.preserve_aspect_ratio = True
|
self.preserve_aspect_ratio = True
|
||||||
# solver
|
# solver
|
||||||
self.solver_presets = [
|
self.solver_presets = [
|
||||||
|
@ -574,7 +575,8 @@ class Options:
|
||||||
for key, val in self.cardset.items():
|
for key, val in self.cardset.items():
|
||||||
config['cardsets'][str(key)] = val
|
config['cardsets'][str(key)] = val
|
||||||
for key in ('scale_cards', 'scale_x', 'scale_y',
|
for key in ('scale_cards', 'scale_x', 'scale_y',
|
||||||
'auto_scale', 'preserve_aspect_ratio'):
|
'auto_scale', 'spread_stacks',
|
||||||
|
'preserve_aspect_ratio'):
|
||||||
config['cardsets'][key] = getattr(self, key)
|
config['cardsets'][key] = getattr(self, key)
|
||||||
|
|
||||||
# games_geometry
|
# games_geometry
|
||||||
|
@ -744,6 +746,7 @@ class Options:
|
||||||
('scale_x', 'float'),
|
('scale_x', 'float'),
|
||||||
('scale_y', 'float'),
|
('scale_y', 'float'),
|
||||||
('auto_scale', 'bool'),
|
('auto_scale', 'bool'),
|
||||||
|
('spread_stacks', 'bool'),
|
||||||
('preserve_aspect_ratio', 'bool')):
|
('preserve_aspect_ratio', 'bool')):
|
||||||
val = self._getOption('cardsets', key, t)
|
val = self._getOption('cardsets', key, t)
|
||||||
if val is not None:
|
if val is not None:
|
||||||
|
|
|
@ -309,6 +309,7 @@ class SelectCardsetDialogWithPreview(MfxDialog):
|
||||||
)
|
)
|
||||||
self.aspect_check.grid(row=6, column=0, sticky='ew',
|
self.aspect_check.grid(row=6, column=0, sticky='ew',
|
||||||
padx=padx, pady=pady)
|
padx=padx, pady=pady)
|
||||||
|
|
||||||
self._updateAutoScale()
|
self._updateAutoScale()
|
||||||
#
|
#
|
||||||
left_frame.rowconfigure(0, weight=1)
|
left_frame.rowconfigure(0, weight=1)
|
||||||
|
@ -358,24 +359,27 @@ class SelectCardsetDialogWithPreview(MfxDialog):
|
||||||
|
|
||||||
if USE_PIL:
|
if USE_PIL:
|
||||||
auto_scale = bool(self.auto_scale.get())
|
auto_scale = bool(self.auto_scale.get())
|
||||||
if button == 1: # Cancel
|
if button == 1:
|
||||||
# no changes
|
# no changes
|
||||||
self.cardset_values = None
|
self.cardset_values = None
|
||||||
elif button == 0: # OK
|
|
||||||
|
elif button == 0:
|
||||||
self.app.menubar.tkopt.auto_scale.set(auto_scale)
|
self.app.menubar.tkopt.auto_scale.set(auto_scale)
|
||||||
|
|
||||||
self.app.opt.scale_x = self.scale_x.get()
|
if auto_scale:
|
||||||
self.app.opt.scale_y = self.scale_y.get()
|
self.app.menubar.tkopt.spread_stacks.set(False)
|
||||||
self.app.opt.preserve_aspect_ratio = \
|
self.scale_values = (self.app.opt.scale_x,
|
||||||
self.preserve_aspect.get()
|
self.app.opt.scale_y,
|
||||||
|
auto_scale,
|
||||||
self.scale_values = (self.app.opt.scale_x,
|
False,
|
||||||
self.app.opt.scale_y,
|
bool(self.preserve_aspect.get()))
|
||||||
auto_scale,
|
else:
|
||||||
self.app.opt.preserve_aspect_ratio)
|
self.scale_values = (self.scale_x.get(),
|
||||||
self.app.game.resizeGame(card_size_manually=True)
|
self.scale_y.get(),
|
||||||
self.app.game.resizeGame(card_size_manually=False)
|
auto_scale,
|
||||||
|
self.app.opt.spread_stacks,
|
||||||
|
self.app.opt.
|
||||||
|
preserve_aspect_ratio)
|
||||||
if button == 10: # Info
|
if button == 10: # Info
|
||||||
cs = self.manager.get(self.tree.selection_key)
|
cs = self.manager.get(self.tree.selection_key)
|
||||||
if not cs:
|
if not cs:
|
||||||
|
|
|
@ -101,6 +101,7 @@ class PysolMenubarTk(PysolMenubarTkCommon):
|
||||||
changed = (self.app.opt.scale_x,
|
changed = (self.app.opt.scale_x,
|
||||||
self.app.opt.scale_y,
|
self.app.opt.scale_y,
|
||||||
self.app.opt.auto_scale,
|
self.app.opt.auto_scale,
|
||||||
|
self.app.opt.spread_stacks,
|
||||||
self.app.opt.preserve_aspect_ratio) != d.scale_values
|
self.app.opt.preserve_aspect_ratio) != d.scale_values
|
||||||
else:
|
else:
|
||||||
changed = False
|
changed = False
|
||||||
|
|
|
@ -171,6 +171,7 @@ class PysolMenubarTkCommon:
|
||||||
shisen_show_hint=tkinter.BooleanVar(),
|
shisen_show_hint=tkinter.BooleanVar(),
|
||||||
sound=tkinter.BooleanVar(),
|
sound=tkinter.BooleanVar(),
|
||||||
auto_scale=tkinter.BooleanVar(),
|
auto_scale=tkinter.BooleanVar(),
|
||||||
|
spread_stacks=tkinter.BooleanVar(),
|
||||||
cardback=tkinter.IntVar(),
|
cardback=tkinter.IntVar(),
|
||||||
tabletile=tkinter.IntVar(),
|
tabletile=tkinter.IntVar(),
|
||||||
animations=tkinter.IntVar(),
|
animations=tkinter.IntVar(),
|
||||||
|
@ -222,6 +223,7 @@ class PysolMenubarTkCommon:
|
||||||
tkopt.shisen_show_hint.set(opt.shisen_show_hint)
|
tkopt.shisen_show_hint.set(opt.shisen_show_hint)
|
||||||
tkopt.sound.set(opt.sound)
|
tkopt.sound.set(opt.sound)
|
||||||
tkopt.auto_scale.set(opt.auto_scale)
|
tkopt.auto_scale.set(opt.auto_scale)
|
||||||
|
tkopt.spread_stacks.set(opt.spread_stacks)
|
||||||
tkopt.cardback.set(self.app.cardset.backindex)
|
tkopt.cardback.set(self.app.cardset.backindex)
|
||||||
tkopt.tabletile.set(self.app.tabletile_index)
|
tkopt.tabletile.set(self.app.tabletile_index)
|
||||||
tkopt.animations.set(opt.animations)
|
tkopt.animations.set(opt.animations)
|
||||||
|
@ -534,6 +536,9 @@ class PysolMenubarTkCommon:
|
||||||
submenu.add_checkbutton(
|
submenu.add_checkbutton(
|
||||||
label=n_("&Auto scaling"), variable=self.tkopt.auto_scale,
|
label=n_("&Auto scaling"), variable=self.tkopt.auto_scale,
|
||||||
command=self.mOptAutoScale, accelerator=m+'0')
|
command=self.mOptAutoScale, accelerator=m+'0')
|
||||||
|
submenu.add_checkbutton(
|
||||||
|
label=n_("&Spread stacks"), variable=self.tkopt.spread_stacks,
|
||||||
|
command=self.mOptSpreadStacks)
|
||||||
# manager = self.app.cardset_manager
|
# manager = self.app.cardset_manager
|
||||||
# n = manager.len()
|
# n = manager.len()
|
||||||
menu.add_command(
|
menu.add_command(
|
||||||
|
@ -1440,7 +1445,7 @@ Unsupported game for import.
|
||||||
self.app.canvas.winfo_height())
|
self.app.canvas.winfo_height())
|
||||||
self.app.opt.game_geometry = geom
|
self.app.opt.game_geometry = geom
|
||||||
self.app.game.resizeGame(card_size_manually=True)
|
self.app.game.resizeGame(card_size_manually=True)
|
||||||
if self.app.opt.auto_scale:
|
if self.app.opt.auto_scale or self.app.opt.spread_stacks:
|
||||||
w, h = self.app.opt.game_geometry
|
w, h = self.app.opt.game_geometry
|
||||||
self.app.canvas.setInitialSize(w, h, scrollregion=False)
|
self.app.canvas.setInitialSize(w, h, scrollregion=False)
|
||||||
# Resize a second time to auto scale
|
# Resize a second time to auto scale
|
||||||
|
@ -1463,8 +1468,8 @@ Unsupported game for import.
|
||||||
self.app.opt.scale_y += 0.1
|
self.app.opt.scale_y += 0.1
|
||||||
else:
|
else:
|
||||||
return
|
return
|
||||||
# self.app.opt.auto_scale = False
|
self.app.opt.auto_scale = False
|
||||||
# self.tkopt.auto_scale.set(False)
|
self.tkopt.auto_scale.set(False)
|
||||||
self._updateCardSize()
|
self._updateCardSize()
|
||||||
|
|
||||||
def mDecreaseCardset(self, *event):
|
def mDecreaseCardset(self, *event):
|
||||||
|
@ -1478,18 +1483,38 @@ Unsupported game for import.
|
||||||
self.app.opt.scale_y -= 0.1
|
self.app.opt.scale_y -= 0.1
|
||||||
else:
|
else:
|
||||||
return
|
return
|
||||||
# self.app.opt.auto_scale = False
|
self.app.opt.auto_scale = False
|
||||||
# self.tkopt.auto_scale.set(False)
|
self.tkopt.auto_scale.set(False)
|
||||||
self._updateCardSize()
|
self._updateCardSize()
|
||||||
|
|
||||||
def mOptAutoScale(self, *event):
|
def mOptAutoScale(self, *event):
|
||||||
if self._cancelDrag(break_pause=True):
|
if self._cancelDrag(break_pause=True):
|
||||||
return
|
return
|
||||||
auto_scale = not self.app.opt.auto_scale
|
auto_scale = not self.app.opt.auto_scale
|
||||||
|
|
||||||
|
# In the future, it should be possible to use both options together,
|
||||||
|
# but the current logic conflicts, so not allowed for now.
|
||||||
|
self.app.opt.spread_stacks = False
|
||||||
|
self.tkopt.spread_stacks.set(False)
|
||||||
|
|
||||||
self.app.opt.auto_scale = auto_scale
|
self.app.opt.auto_scale = auto_scale
|
||||||
self.tkopt.auto_scale.set(auto_scale)
|
self.tkopt.auto_scale.set(auto_scale)
|
||||||
self._updateCardSize()
|
self._updateCardSize()
|
||||||
|
|
||||||
|
def mOptSpreadStacks(self, *event):
|
||||||
|
if self._cancelDrag(break_pause=True):
|
||||||
|
return
|
||||||
|
spread_stacks = not self.app.opt.spread_stacks
|
||||||
|
|
||||||
|
# In the future, it should be possible to use both options together,
|
||||||
|
# but the current logic conflicts, so not allowed for now.
|
||||||
|
self.app.opt.auto_scale = False
|
||||||
|
self.tkopt.auto_scale.set(False)
|
||||||
|
|
||||||
|
self.app.opt.spread_stacks = spread_stacks
|
||||||
|
self.tkopt.spread_stacks.set(spread_stacks)
|
||||||
|
self._updateCardSize()
|
||||||
|
|
||||||
def _mOptCardback(self, index):
|
def _mOptCardback(self, index):
|
||||||
if self._cancelDrag(break_pause=False):
|
if self._cancelDrag(break_pause=False):
|
||||||
return
|
return
|
||||||
|
|
Loading…
Add table
Reference in a new issue