diff options
author | Gonzalo Odiard <godiard@gmail.com> | 2014-07-23 21:12:30 (GMT) |
---|---|---|
committer | Gonzalo Odiard <godiard@gmail.com> | 2014-07-23 21:15:21 (GMT) |
commit | 98e25166c0a891f5c5b44ada3a7350031b5f4158 (patch) | |
tree | 6c84d1324da2af0a090545ff56bb80a41b3df328 | |
parent | c1cf72793bb694558778eaaff9ba97acd2fa68c9 (diff) |
Improve resize of table when the screen is rotated
The cardtable used to load a new game when the screen was rotated.
The problem was the game state was lost.
This patch add a resie method to the SvgCard class, and implement
resizing the cards. Also remove the old code used to reset the game.
-rw-r--r-- | activity.py | 6 | ||||
-rw-r--r-- | cardtable.py | 12 | ||||
-rw-r--r-- | scoreboard.py | 7 | ||||
-rw-r--r-- | svgcard.py | 7 |
4 files changed, 11 insertions, 21 deletions
diff --git a/activity.py b/activity.py index 1038fa6..c02c1e2 100644 --- a/activity.py +++ b/activity.py @@ -141,7 +141,6 @@ class MemorizeActivity(Activity): self.connect('key-press-event', self.table.key_press_event) self.table.connect('card-flipped', self.game.card_flipped) self.table.connect('card-highlighted', self.game.card_highlighted) - self.table.connect('resize-table', self.__resize_table_cb) self.game.connect('set-border', self.table.set_border) self.game.connect('flop-card', self.table.flop_card) @@ -239,11 +238,6 @@ class MemorizeActivity(Activity): self.table.resize(width, height - style.GRID_CELL_SIZE) self.show_all() - def __resize_table_cb(self, widget): - # need reset the game - # because we reload the cards in the table - self.game.last_flipped = -1 - def _change_mode_bt(self, button): if button.get_active(): self._change_mode(_MODE_CREATE) diff --git a/cardtable.py b/cardtable.py index b2afd5c..78f16c8 100644 --- a/cardtable.py +++ b/cardtable.py @@ -37,9 +37,7 @@ class CardTable(Gtk.EventBox): 'card-flipped': (GObject.SignalFlags.RUN_FIRST, None, [int, GObject.TYPE_PYOBJECT]), 'card-highlighted': (GObject.SignalFlags.RUN_FIRST, - None, [int, GObject.TYPE_PYOBJECT]), - 'resize-table': (GObject.SignalFlags.RUN_FIRST, - None, []), } + None, [int, GObject.TYPE_PYOBJECT]), } def __init__(self): Gtk.EventBox.__init__(self) @@ -80,11 +78,9 @@ class CardTable(Gtk.EventBox): self.set_size_request(width, height) self._workspace_size = min(width, height) if self.data: - if change: - self.change_game(None, self.data, self.cards_data) - else: - self.load_game(None, self.data, self.cards_data) - self.emit('resize-table') + self.card_size = self.get_card_size(self.size) + for child in self.table.get_children(): + child.resize(self.card_size) def _allocate_cb(self, widget, allocation): size = allocation.height diff --git a/scoreboard.py b/scoreboard.py index 9882ad2..5ff3f21 100644 --- a/scoreboard.py +++ b/scoreboard.py @@ -25,7 +25,6 @@ class Scoreboard(Gtk.EventBox): def __init__(self): Gtk.EventBox.__init__(self) self.modify_bg(Gtk.StateType.NORMAL, Gdk.color_parse('#666666')) - self.connect('size-allocate', self._allocate_cb) self._width = self.get_allocation().width self.players = {} self.current_buddy = None @@ -35,12 +34,6 @@ class Scoreboard(Gtk.EventBox): self.add(self.hbox) self.show_all() - def _allocate_cb(self, widget, allocation): - # check if the width changes (when the screen rotates - if allocation.width != self._width: - self._width = allocation.width - self.reset(widget) - def change_game(self, widget, data, grid): for buddy in self.players.keys(): self.players[buddy].change_game(len(grid)) @@ -99,6 +99,13 @@ class SvgCard(Gtk.EventBox): self.add(self.workspace) self.show_all() + def resize(self, new_size): + self.size = new_size + self.set_size_request(self.size, self.size) + self._cached_surface = {True: None, False: None} + self.jpeg = None + self.text_layouts = [None, None] + def __draw_cb(self, widget, context): flipped = self.flipped highlighted = self._highlighted |