From: <Blu...@us...> - 2010-09-04 22:48:39
|
Revision: 390 http://virtplayground.svn.sourceforge.net/virtplayground/?rev=390&view=rev Author: BlueWolf_ Date: 2010-09-04 22:48:33 +0000 (Sat, 04 Sep 2010) Log Message: ----------- Window now has a GUI and opening one works now Modified Paths: -------------- trunk/client/gui.py trunk/client/playground.py Modified: trunk/client/gui.py =================================================================== --- trunk/client/gui.py 2010-09-04 20:55:38 UTC (rev 389) +++ trunk/client/gui.py 2010-09-04 22:48:33 UTC (rev 390) @@ -412,6 +412,135 @@ self.caption = "" self.canclose = True + self.gui = load_image(True, "images", "gui", "window.png") + self.backgroundsurf = self.surf.copy() + self.font = pygame.font.Font(real_path("fonts", \ + "DejaVuSans-Bold.ttf"), 14) + + self.buttonstate = 0 + + self.pos = { + # img is the position on the image + # pos is the rendered position + # If the pos or size it's negative, it's (-value - width or + # height). + + # Corners + "topleft_img": (0, 0, 29, 37), + "topleft_pos": (0, 0, 29, 37), + + "topright_img": (32, 0, 29, 37), + "topright_pos": (-29, 0, 29, 37), + + "bottomleft_img": (0, 40, 14, 14), + "bottomleft_pos": (0, -14, 14, 14), + + "bottomright_img": (47, 40, 14, 14), + "bottomright_pos": (-14, -14, 14, 14), + + # Middle parts + "topmiddle_img": (30, 0, 1, 37), + "topmiddle_pos": (29, 0, -58, 37), + + "bottommiddle_img": (30, 40, 1, 14), + "bottommiddle_pos": (14, -14, -28, 14), + + "leftmiddle_img": (0, 38, 14, 1), + "leftmiddle_pos": (0, 37, 14, -51), + + "rightmiddle_img": (47, 38, 14, 1), + "rightmiddle_pos": (-14, 37, 14, -51), + + # Close button + "close_img": (61, 0, 28, 28), + "closeH_img": (90, 0, 28, 28), + "closeC_img": (119, 0, 28, 28), + "close_pos": (-42, 9, 28, 28), + + # Other + "inner_pos": (14, 37, -28, -51) + } + + self.colors = { + "bgcolor": (51, 51, 51), + "title": (230, 230, 230), + "title_shadow": (0, 0, 0), + } + + self.create_layout() + + def calculate_pos(self, pos): + rect = Rect(0, 0, 0, 0) + for posid, rectid in zip((0, 1, 2, 3), (2, 3, 2, 3)): + if pos[posid] < 0: + rect[posid] = self.rect[rectid] + pos[posid] + else: + rect[posid] = pos[posid] + return rect + + def create_layout(self): + # Calculate every position in self.pos and blit it + for name in ["topleft", "topright", "bottomleft", "bottomright", \ + "topmiddle", "bottommiddle", "leftmiddle", "rightmiddle"]: + + img = self.pos[name + "_img"] + pos = self.pos[name + "_pos"] + + # Calculate the position + rect = self.calculate_pos(pos) + + # Blit the image + + # Do we need to resize it? + if (pos[2], pos[3]) != (rect[2], rect[3]): + tempsurf = pygame.Surface((img[2], img[3]), SRCALPHA).convert_alpha() + tempsurf.blit(self.gui, (0,0), img) + tempsurf = pygame.transform.scale(tempsurf, (rect[2], rect[3])) + self.backgroundsurf.blit(tempsurf, rect) + else: + self.backgroundsurf.blit(self.gui, rect, img) + + # Fill inner part + inner = self.calculate_pos(self.pos['inner_pos']) + self.backgroundsurf.fill(self.colors['bgcolor'], inner) + + def render(self): + self.surf.fill([0, 0, 0, 0]) + self.surf.blit(self.backgroundsurf, (0,0)) + + # Create title + if self.canclose: + width = self.rect.width - 56 + else: + width = self.rect.width - 28 + + textwidth = self.font.size(self.caption)[0] + pos = ((width/2) - (textwidth/2)) + 14 + + # Shadow + text = self.font.render(self.caption, True, self.colors['title_shadow']) + self.surf.blit(text, (pos+1, 15)) + + # Foreground + text = self.font.render(self.caption, True, self.colors['title']) + self.surf.blit(text, (pos, 14)) + + # Create button + if self.canclose: + if self.buttonstate == 0: + img = self.pos['close_img'] + elif self.buttonstate == 1: + img = self.pos['closeH_img'] + elif self.buttonstate == 2: + img = self.pos['closeC_img'] + rect = self.calculate_pos(self.pos['close_pos']) + + self.surf.blit(self.gui, rect, img) + + + + + def move(self, topos): # [TODO] pass Modified: trunk/client/playground.py =================================================================== --- trunk/client/playground.py 2010-09-04 20:55:38 UTC (rev 389) +++ trunk/client/playground.py 2010-09-04 22:48:33 UTC (rev 390) @@ -349,7 +349,14 @@ sh['client'].login(usr, pwd) elif obj.name == "signup": - print "signup!" + + # Create signup window + window = self.parent.logingui.add(gui.Window, "signup", \ + Rect(0, 0, 200, 200), SignupFeedback()) + window.caption = "Signup" + + window.unfreeze() + def mousedown(self, obj): if obj.name == "usrlabel": @@ -357,3 +364,7 @@ elif obj.name == "pwdlabel": self.parent.logingui.give_focus('pwd') + + +class SignupFeedback(gui.Feedback): + pass This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |