diff options
author | Aleksey Lim <alsroot@member.fsf.org> | 2009-05-30 18:20:48 (GMT) |
---|---|---|
committer | Aleksey Lim <alsroot@member.fsf.org> | 2009-05-30 18:20:48 (GMT) |
commit | 8146630829382637c088ab9d20d3048e48796017 (patch) | |
tree | 1d5ad850dd716a269645c130095f7754bba7e1e9 | |
parent | 24714a9fb78e3a3b3b97ac1bd476e9a83374a3a2 (diff) |
Scale game workspace to current screen resolution
-rw-r--r-- | StoryBuilder.py | 80 | ||||
-rw-r--r-- | data/layout.png | bin | 39969 -> 30805 bytes | |||
-rw-r--r-- | data/layout.png.orig | bin | 0 -> 39969 bytes |
3 files changed, 48 insertions, 32 deletions
diff --git a/StoryBuilder.py b/StoryBuilder.py index 76b2473..ebf2e78 100644 --- a/StoryBuilder.py +++ b/StoryBuilder.py @@ -20,6 +20,7 @@ # info@WorldWideWorkshop.org ! # +import gtk import os, sys import random import pickle @@ -39,19 +40,34 @@ from pgu import text from pgu import gui from pgu import html +from sugar.graphics import style + FPS = 30 # Frames Per Second -GAME_WIDTH = 1024 -GAME_HEIGHT = 700 +ORIG_WIDTH = 1024 +ORIG_HEIGHT = 700 + +FACTOR = min((gtk.gdk.screen_width() / float(ORIG_WIDTH)), + (gtk.gdk.screen_height()-style.MEDIUM_ICON_SIZE) / float(ORIG_HEIGHT)) + +def scale(x): + if isinstance(x, int): + return int(x * FACTOR) + return tuple([scale(i) for i in x]) + +GAME_WIDTH = scale(ORIG_WIDTH) +GAME_HEIGHT = scale(ORIG_HEIGHT) + +CHAR_PANEL_SIZE = 5 # button positions -CHARACTER_BAR_UP = pygame.rect.Rect((46, 93, 46, 33)) -CHARACTER_BAR_DOWN = pygame.rect.Rect((46, 491, 46, 33)) -CLEAR = pygame.rect.Rect((932, 435, 46, 33)) -SOUND = pygame.rect.Rect((932, 114, 46, 33)) -THEME_LEFT = pygame.rect.Rect((410, 506, 46, 33)) -THEME_RIGHT = pygame.rect.Rect((567, 506, 46, 33)) -TEXTAREA = pygame.rect.Rect((62, 560, 875, 114)) +CHARACTER_BAR_UP = pygame.rect.Rect(scale((46, 93, 46, 33))) +CHARACTER_BAR_DOWN = pygame.rect.Rect(scale((46, 491, 46, 33))) +CLEAR = pygame.rect.Rect(scale((932, 435, 46, 33))) +SOUND = pygame.rect.Rect(scale((932, 114, 46, 33))) +THEME_LEFT = pygame.rect.Rect(scale((410, 506, 46, 33))) +THEME_RIGHT = pygame.rect.Rect(scale((567, 506, 46, 33))) +TEXTAREA = pygame.rect.Rect(scale((62, 560, 875, 114))) def load_image(name, (x, y)=(None, None)): """Load an image from a specific file. @@ -62,7 +78,7 @@ def load_image(name, (x, y)=(None, None)): fullname = os.path.join('data', name) image = pygame.image.load(fullname).convert_alpha() if x and y: - image = pygame.transform.scale(image, (x, y)) + image = pygame.transform.scale(image, (scale(x), scale(y))) return image, image.get_rect() def load_sound(name): @@ -83,8 +99,8 @@ class Background(pygame.sprite.Sprite): pygame.sprite.Sprite.__init__(self) self.image, self.rect = load_image(theme.background, (754, 393)) - x = layout.rect.left + 153 - y = layout.rect.top + 95 + x = layout.rect.left + scale(153) + y = layout.rect.top + scale(95) self.rect.topleft = (x, y) @@ -100,7 +116,7 @@ class ButtonBar: self.buttonlist = buttonlist self.layout = layout self.spritegroup = spritegroup - # We can display 5 buttons at a time + # We can display CHAR_PANEL_SIZE buttons at a time self.startbutton = 0 self.show() @@ -111,10 +127,10 @@ class ButtonBar: returns (x, y) """ - if int(index) not in range(0,5): + if int(index) not in range(0,CHAR_PANEL_SIZE): raise ValueError, "index out of range" - x = 37 - y = 138 + index*70 + x = scale(37) + y = scale(138) + scale(index*70) try: x += self.layout.rect.left y += self.layout.rect.top @@ -123,29 +139,29 @@ class ButtonBar: return (x, y) def up(self): - """Show previous 5 buttons""" - self.startbutton -= 5 + """Show previous CHAR_PANEL_SIZE buttons""" + self.startbutton -= CHAR_PANEL_SIZE if self.startbutton < 0: buttons = len(self.buttonlist) - if buttons % 5: - highest = buttons / 5 * 5 + if buttons % CHAR_PANEL_SIZE: + highest = buttons / CHAR_PANEL_SIZE * CHAR_PANEL_SIZE else: - highest = (buttons / 5) - 1 + highest = (buttons / CHAR_PANEL_SIZE) - 1 self.startbutton = highest self.show() def down(self): - """Show next 5 buttons""" - self.startbutton += 5 + """Show next CHAR_PANEL_SIZE buttons""" + self.startbutton += CHAR_PANEL_SIZE if self.startbutton >= len(self.buttonlist): self.startbutton = 0 self.show() def show(self): - """Show the current 5 buttons""" + """Show the current CHAR_PANEL_SIZE buttons""" self.spritegroup.empty() self.current_buttons = self.buttonlist[ - self.startbutton:self.startbutton+5] + self.startbutton:self.startbutton+CHAR_PANEL_SIZE] for index in range(0, len(self.current_buttons)): button = self.current_buttons[index] button.rect.topleft = self.coord(index) @@ -282,7 +298,7 @@ class Layout(pygame.sprite.Sprite): surfsize: (optional tuple) size of surface to center on """ pygame.sprite.Sprite.__init__(self) - self.image, self.rect = load_image(name) + self.image, self.rect = load_image(name, (ORIG_WIDTH, ORIG_HEIGHT)) if surfsize: mid_x = surfsize[0] / 2 mid_y = surfsize[1] / 2 @@ -295,7 +311,7 @@ class Layout(pygame.sprite.Sprite): class Game: """Represent the layout, buttons, stuff happening""" - + def __init__(self): pygame.init() self.screen = pygame.display.set_mode((GAME_WIDTH, GAME_HEIGHT)) @@ -306,7 +322,7 @@ class Game: self._themes = load_themes() self.current_theme = 0 - self.layout = Layout('layout.png', surfsize=self.screen.get_size()) + self.layout = Layout('layout.png') self.set_theme() self.text = '' @@ -324,8 +340,8 @@ class Game: lesson_plan_button = gui.Button(_('Lesson Plans')) lesson_plan_button.connect(gui.CLICK, self.lesson_plan_cb) - guicontainer.add(lesson_plan_button, 394+self.layout.rect.left, - 25+self.layout.rect.top) + guicontainer.add(lesson_plan_button, scale(394)+self.layout.rect.left, + scale(25)+self.layout.rect.top) self.lesson_plan_texts = [] self.lesson_plan_area = None @@ -586,8 +602,8 @@ class Icon(pygame.sprite.Sprite): self.image, self.rect = load_image(theme.icon, (100, 51)) if layout: - x = layout.rect.left + 462 - y = layout.rect.top + 498 + x = layout.rect.left + scale(462) + y = layout.rect.top + scale(498) self.rect.topleft = (x, y) diff --git a/data/layout.png b/data/layout.png Binary files differindex 59d781e..f7e769a 100644 --- a/data/layout.png +++ b/data/layout.png diff --git a/data/layout.png.orig b/data/layout.png.orig Binary files differnew file mode 100644 index 0000000..59d781e --- /dev/null +++ b/data/layout.png.orig |