Commit 92f52c05 authored by Gonzalo Odiard's avatar Gonzalo Odiard

Reorbanize main screen and scoreboard

Now, the scoreboard is always below the table game.
That limit the space to show users, but anyway we are allowing play
only to 2 players, due to problems with the collaboration.
This reorganization try to put the focus in the game space.
More work is neede to center the board.

This commit also replace the use of SvgLabel for a standard sugar Icon,
then, remove two files and simplify a lot the code on the scoreboard.
parent 6f539114
......@@ -80,8 +80,6 @@ class MemorizeActivity(Activity):
self.play_mode = None
self._calculate_sizes()
toolbar_box = ToolbarBox()
self.set_toolbar_box(toolbar_box)
......@@ -173,12 +171,15 @@ class MemorizeActivity(Activity):
self._memorizeToolbarBuilder.connect('game_changed',
self.change_game)
self.portrait_mode = Gdk.Screen.width() < Gdk.Screen.height()
self.box = Gtk.HBox(orientation=Gtk.Orientation.HORIZONTAL,
self.box = Gtk.HBox(orientation=Gtk.Orientation.VERTICAL,
homogeneous=False)
self.box.pack_start(self.table, False, False, 0)
self.box.pack_start(self.scoreboard, True, True, 0)
width = Gdk.Screen.width()
height = Gdk.Screen.height() - style.GRID_CELL_SIZE
self.table.resize(width, height - style.GRID_CELL_SIZE)
self.scoreboard.set_size_request(-1, style.GRID_CELL_SIZE)
self.box.pack_start(self.table, True, True, 0)
self.box.pack_start(self.scoreboard, False, False, 0)
self.set_canvas(self.box)
# connect to the in/out events of the memorize activity
......@@ -227,36 +228,13 @@ class MemorizeActivity(Activity):
self.game.add_buddy(self.owner)
self.show_all()
def _calculate_sizes(self):
width = Gdk.Screen.width()
height = Gdk.Screen.height()
if width < height:
self.table_size = (width, width)
self.score_size = (width, height - width - style.GRID_CELL_SIZE)
else:
self.table_size = (height - style.GRID_CELL_SIZE,
height - style.GRID_CELL_SIZE)
self.score_size = (width - self.table_size[0],
height - style.GRID_CELL_SIZE)
def __configure_cb(self, event):
''' Screen size has changed '''
width = Gdk.Screen.width()
height = Gdk.Screen.height() - style.GRID_CELL_SIZE
self.box.set_size_request(width, height)
self._calculate_sizes()
portrait_mode = width < height
if portrait_mode != self.portrait_mode:
self.table.resize(self.table_size[0])
if portrait_mode:
self.box.set_orientation(Gtk.Orientation.VERTICAL)
else:
self.box.set_orientation(Gtk.Orientation.HORIZONTAL)
self.portrait_mode = portrait_mode
self.scoreboard.set_size_request(self.score_size[0],
self.score_size[1])
self.scoreboard.set_size_request(-1, style.GRID_CELL_SIZE)
self.table.resize(width, height - style.GRID_CELL_SIZE)
self.show_all()
def _change_mode_bt(self, button):
......@@ -380,9 +358,8 @@ class MemorizeActivity(Activity):
self.box.remove(self.cardlist)
if self.play_mode in (False, None):
self.box.pack_start(self.table, False, False, 0)
self.box.pack_start(self.scoreboard, True, True, 0)
self._calculate_sizes()
self.box.pack_start(self.table, True, True, 0)
self.box.pack_start(self.scoreboard, False, False, 0)
self.play_mode = True
self._memorizeToolbarBuilder.update_controls(mode == _MODE_PLAY)
self._createToolbarBuilder.update_controls(mode == _MODE_CREATE)
......
......@@ -70,10 +70,10 @@ class CardTable(Gtk.EventBox):
self.dict = None
self.show_all()
def resize(self, size, change=True):
_logger.debug('set size request %dx%d' % (size, size))
self.set_size_request(size, size)
self._workspace_size = size
def resize(self, width, height, change=True):
_logger.debug('set size request %dx%d' % (width, height))
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)
......@@ -84,11 +84,7 @@ class CardTable(Gtk.EventBox):
size = allocation.height
width = Gdk.Screen.width()
height = Gdk.Screen.height()
if width < height:
size = allocation.width
else:
size = allocation.height
size = min(width, height)
if size == 100:
# skip first time sizing
return
......@@ -96,7 +92,7 @@ class CardTable(Gtk.EventBox):
# do it once
if self._workspace_size:
return
self.resize(size, change=False)
self.resize(width, height, change=False)
def load_game(self, widget, data, grid):
self.data = data
......
......@@ -18,10 +18,10 @@
from gi.repository import Gtk
from gi.repository import Gdk
import svglabel
from sugar3.graphics.icon import Icon
from sugar3.graphics import style
import logging
from os.path import join, dirname
from score import Score
import math
import theme
......@@ -34,9 +34,9 @@ class PlayerScoreboard(Gtk.EventBox):
def __init__(self, nick, fill_color, stroke_color, score=0):
Gtk.EventBox.__init__(self)
self.default_color = '#4c4d4f'
self.default_color = '#666666'
self.selected_color = '#818286'
self.current_color = '#4c4d4f'
self.current_color = '#666666'
self.status = False
self._score_width = 0
self._score_cols = 0
......@@ -50,9 +50,9 @@ class PlayerScoreboard(Gtk.EventBox):
self.table = Gtk.Table(2, 2, False)
self.modify_bg(Gtk.StateType.NORMAL,
Gdk.color_parse(self.current_color))
self.table.set_row_spacings(theme.PAD / 2)
self.table.set_col_spacings(theme.PAD / 2)
self.table.set_border_width(theme.PAD)
self.table.set_row_spacings(0)
self.table.set_col_spacings(0)
self.table.set_border_width(theme.PAD / 2)
# Score table
self.score_table = Gtk.Table()
......@@ -64,16 +64,10 @@ class PlayerScoreboard(Gtk.EventBox):
self.current_y = 0
# Set buddy icon
self.xo_buddy = join(dirname(__file__), 'images', 'stock-buddy.svg')
self.icon = svglabel.SvgLabel(
self.xo_buddy, fill_color, stroke_color,
False, self.current_color, theme.BODY_WIDTH, theme.BODY_HEIGHT)
# Set waiting buddy icon
self.waiting_icon = svglabel.SvgLabel(
self.xo_buddy,
self.default_color, '#ffffff', False, self.current_color,
theme.BODY_WIDTH, theme.BODY_HEIGHT)
self.icon = Icon(icon_name='computer-xo',
pixel_size=style.STANDARD_ICON_SIZE)
self.icon.set_fill_color(fill_color)
self.icon.set_stroke_color(stroke_color)
# Set nick label
self.nick = Gtk.Label(label=nick)
......@@ -113,17 +107,11 @@ class PlayerScoreboard(Gtk.EventBox):
-1, (theme.SCORE_SIZE + theme.PAD / 2) * (rows) - theme.PAD / 2)
def increase_score(self):
if len(self.scores) == 0:
# Cache the score icon
score_label = Score(self.fill_color, self.stroke_color)
score_pixbuf_unsel = score_label.get_pixbuf()
score_pixbuf_sel = score_label.get_pixbuf_sel()
else:
score_pixbuf_unsel = None
score_pixbuf_sel = None
new_score = Icon(icon_name='score',
pixel_size=style.SMALL_ICON_SIZE)
new_score.set_fill_color(self.fill_color)
new_score.set_stroke_color(self.stroke_color)
new_score = Score(self.fill_color, self.stroke_color,
score_pixbuf_sel, score_pixbuf_unsel, self.status)
self.scores.append(new_score)
new_score.show()
self.score_table.attach(
......@@ -160,14 +148,11 @@ class PlayerScoreboard(Gtk.EventBox):
def set_wait_mode(self, status):
if status:
self.table.remove(self.icon)
self.table.attach(self.waiting_icon, 0, 1, 0, 2)
self.icon.set_fill_color('#ffffff')
if len(self.scores) == 0:
self.table.attach(self.msg, 1, 2, 1, 2)
else:
self.table.remove(self.waiting_icon)
self.table.attach(self.icon, 0, 1, 0, 2)
self.table.remove(self.msg)
self.icon.set_fill_color(self.fill_color)
if len(self.scores) == 0:
self.table.remove(self.msg)
self.queue_draw()
......
# Copyright (C) 2006, 2007, 2008 One Laptop Per Child
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#
import svglabel
import os
from gi.repository import Gtk
from gi.repository import Gdk
import theme
class Score(svglabel.SvgLabel):
selected_color = "#818286"
default_color = "#4c4d4f"
status = False
def __init__(self, fill_color, stroke_color, pixbuf=None,
pixbuf_sel=None, status=False):
filename = os.path.join(os.path.dirname(__file__), "images/score.svg")
self.pixbuf_un = pixbuf
self.pixbuf_sel = pixbuf_sel
self.status = status
if self.pixbuf_un is None:
self.pixbuf_un = svglabel.SvgLabel(filename, fill_color,
stroke_color, False,
self.default_color).get_pixbuf()
if self.pixbuf_sel is None:
label = svglabel.SvgLabel(filename, fill_color, stroke_color,
False, self.selected_color)
self.pixbuf_sel = label.get_pixbuf()
if status:
self.pixbuf = self.pixbuf_sel
else:
self.pixbuf = self.pixbuf_un
svglabel.SvgLabel.__init__(
self, filename, fill_color, stroke_color,
self.pixbuf, self.default_color, theme.SCORE_SIZE,
theme.SCORE_SIZE)
self.set_selected(status)
def set_selected(self, status):
self.status = status
if status:
self.pixbuf = self.pixbuf_sel
self.modify_bg(Gtk.StateType.NORMAL,
Gdk.color_parse(self.selected_color))
else:
self.pixbuf = self.pixbuf_un
self.modify_bg(Gtk.StateType.NORMAL,
Gdk.color_parse(self.default_color))
self.queue_draw()
def get_pixbuf_un(self):
return self.pixbuf_un
def get_pixbuf_sel(self):
return self.pixbuf_sel
......@@ -35,7 +35,7 @@ class Scoreboard(Gtk.EventBox):
self.vbox = Gtk.VBox(False)
fill_box = Gtk.EventBox()
fill_box.modify_bg(Gtk.StateType.NORMAL, Gdk.color_parse('#4c4d4f'))
fill_box.modify_bg(Gtk.StateType.NORMAL, Gdk.color_parse('#666666'))
fill_box.show()
self.vbox.pack_end(fill_box, True, True, 0)
......
# Copyright (C) 2006, 2007, 2008 One Laptop Per Child
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#
from gi.repository import Gtk
from gi.repository import Gdk
from gi.repository import Rsvg
import re
class SvgLabel(Gtk.DrawingArea):
filename = ''
fill_color = ''
stroke_color = ''
background_color = ''
def __init__(self, filename, fill_color, stroke_color, pixbuf=False,
background_color='', request_x=45, request_y=45):
Gtk.DrawingArea.__init__(self)
self.set_size_request(request_x, request_y)
self.filename = filename
self.background_color = background_color
self.fill_color = fill_color
self.stroke_color = stroke_color
self.modify_bg(Gtk.StateType.NORMAL, Gdk.color_parse(background_color))
if pixbuf:
self.pixbuf = pixbuf
else:
self.pixbuf = self._read_icon_data(self.filename, self.fill_color,
self.stroke_color)
self.connect('draw', self.__draw_cb)
def __draw_cb(self, widget, context):
Gdk.cairo_set_source_pixbuf(context, self.pixbuf, 0, 0)
context.paint()
return False
def _read_icon_data(self, filename, fill_color, stroke_color):
icon_file = open(filename, 'r')
data = icon_file.read()
icon_file.close()
if fill_color:
entity = '<!ENTITY fill_color "%s">' % fill_color
data = re.sub('<!ENTITY fill_color .*>', entity, data)
if stroke_color:
entity = '<!ENTITY stroke_color "%s">' % stroke_color
data = re.sub('<!ENTITY stroke_color .*>', entity, data)
self.data_size = len(data)
return Rsvg.Handle.new_from_data(data).get_pixbuf()
def set_color(self, fill_color, stroke_color):
self.fill_color = fill_color
self.stroke_color = stroke_color
self.pixmap = self._read_icon_data(self.filename, self.fill_color,
self.stroke_color)
self.queue_draw()
def set_fill_color(self, fill_color):
self.fill_color = fill_color
self.pixmap = self._read_icon_data(self.filename, self.fill_color,
self.stroke_color)
self.queue_draw()
def get_fill_color(self):
return self.fill_color
def set_stroke_color(self, stroke_color):
self.stroke_color = stroke_color
self.pixmap = self._read_icon_data(self.filename, self.fill_color,
self.stroke_color)
self.queue_draw()
def get_stroke_color(self):
return self.stroke_color
def get_pixbuf(self):
return self.pixbuf
def set_pixbuf(self, pixbuf):
self.pixbuf = pixbuf
self.queue_draw()
def set_background(self, background_color):
self.background_color = background_color
self.modify_bg(Gtk.StateType.NORMAL,
Gdk.color_parse(self.background_color))
self.queue_draw()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment