From 06a6d7492e392ac9fdd229da91e92e565d6f7121 Mon Sep 17 00:00:00 2001 From: skomoroh Date: Wed, 29 Aug 2007 21:23:19 +0000 Subject: [PATCH] * improved mahjongg tile highlighting git-svn-id: file:///home/shlomif/Backup/svn-dumps/PySolFC/svnsync-repos/pysolfc/PySolFC/trunk@202 efabe8c0-fbe8-4139-b769-b5e6d273206e --- pysollib/games/mahjongg/mahjongg.py | 9 ++++++--- pysollib/images.py | 12 ++++++++++++ pysollib/tile/tkutil.py | 4 +--- pysollib/tk/tkutil.py | 4 +--- 4 files changed, 20 insertions(+), 9 deletions(-) diff --git a/pysollib/games/mahjongg/mahjongg.py b/pysollib/games/mahjongg/mahjongg.py index 90c6fdd6..3ec33e66 100644 --- a/pysollib/games/mahjongg/mahjongg.py +++ b/pysollib/games/mahjongg/mahjongg.py @@ -83,7 +83,7 @@ class Mahjongg_Hint(AbstractHint): len(rb.all_left) + len(rb.all_right) + \ len(tb.all_left) + len(tb.all_right) self.addHint(score, 1, r, t) - i = i + 1 + i += 1 # /*********************************************************************** @@ -899,12 +899,15 @@ a solvable configuration.'''), assert c1 in s.cards tkraise = False x, y = s.x, s.y - img = self.app.images.getShadowCard(c1.deck, c1.suit, c1.rank) + img = self.app.images.getHighlightCard(c1.deck, c1.suit, c1.rank) if img is None: continue img = MfxCanvasImage(self.canvas, x, y, image=img, anchor=ANCHOR_NW, group=s.group) - img.tkraise(c1.item) + if self.drag.stack and s is self.drag.stack: + img.tkraise(self.drag.shade_img) + else: + img.tkraise(c1.item) items.append(img) if not items: return 0 diff --git a/pysollib/images.py b/pysollib/images.py index 7dc1a202..babf8214 100644 --- a/pysollib/images.py +++ b/pysollib/images.py @@ -90,6 +90,7 @@ class Images: self._xshadow = [] self._shade = [] self._shadow_cards = {} # key: (suit, rank) + self._highlight_cards = {} # for mahjongg self._shadow_back = None self._pil_shadow = {} # key: (width, height) self._pil_shadow_image = None @@ -375,6 +376,17 @@ class Images: return self.getShade() return shade + def getHighlightCard(self, deck, suit, rank): + if (suit, rank) in self._highlight_cards: + shade = self._highlight_cards[(suit, rank)] + else: + image = self.getFace(deck, suit, rank) + shade = shadowImage(image, color='black', factor=0.3) + self._highlight_cards[(suit, rank)] = shade + if not shade: + return self.getShade() + return shade + def getShadowBack(self): if self._shadow_back: return self._shadow_back diff --git a/pysollib/tile/tkutil.py b/pysollib/tile/tkutil.py index 789e21b4..d8e43389 100644 --- a/pysollib/tile/tkutil.py +++ b/pysollib/tile/tkutil.py @@ -345,12 +345,10 @@ def createImage(width, height, fill, outline=None): fillImage(image, fill, outline) return image -def shadowImage(image): +def shadowImage(image, color='#3896f8', factor=0.3): if not hasattr(image, '_pil_image'): return None im = image._pil_image - #color, factor = 'black', 0.2 - color, factor = '#3896f8', 0.3 sh = Image.new('RGBA', im.size, color) tmp = Image.blend(im, sh, factor) out = Image.composite(tmp, im, im) diff --git a/pysollib/tk/tkutil.py b/pysollib/tk/tkutil.py index 789e21b4..d8e43389 100644 --- a/pysollib/tk/tkutil.py +++ b/pysollib/tk/tkutil.py @@ -345,12 +345,10 @@ def createImage(width, height, fill, outline=None): fillImage(image, fill, outline) return image -def shadowImage(image): +def shadowImage(image, color='#3896f8', factor=0.3): if not hasattr(image, '_pil_image'): return None im = image._pil_image - #color, factor = 'black', 0.2 - color, factor = '#3896f8', 0.3 sh = Image.new('RGBA', im.size, color) tmp = Image.blend(im, sh, factor) out = Image.composite(tmp, im, im)