From: <Blu...@us...> - 2010-09-05 21:06:36
|
Revision: 391 http://virtplayground.svn.sourceforge.net/virtplayground/?rev=391&view=rev Author: BlueWolf_ Date: 2010-09-05 21:06:29 +0000 (Sun, 05 Sep 2010) Log Message: ----------- Windows can now be moved and stacked. I also miiiight have forgotten to add the gui-window images in my last commit. So I'm adding it now. There seems to be a minor pygame/SDL bug with transparent images above transparant images. It's barely noticable though Modified Paths: -------------- trunk/client/gui.py trunk/client/playground.py Added Paths: ----------- trunk/client/images/gui/window.png Modified: trunk/client/gui.py =================================================================== --- trunk/client/gui.py 2010-09-04 22:48:33 UTC (rev 390) +++ trunk/client/gui.py 2010-09-05 21:06:29 UTC (rev 391) @@ -183,7 +183,7 @@ elif ev.type == MOUSEBUTTONDOWN: # Clicking # Check which object we've focused - rect, hover = self.this_pos(ev.pos) + rect, hover = self.this_pos(ev.pos, bringontop = True) if hover: pos = (ev.pos[0] - rect[0], ev.pos[1] - rect[1]) hover.click(0, pos) @@ -230,15 +230,15 @@ elif (ev.type == KEYDOWN or ev.type == KEYUP) and self.focus: self.focus.keypress(ev) - def this_pos(self, pos): + def this_pos(self, pos, bringontop = False): # Return the object and their actual rect on this position - for child in self.children: + for child in reversed(self.children): if not child.rect.collidepoint(pos): continue child_pos = (pos[0] - child.rect[0], pos[1] - child.rect[1]) - rect, hover = child.this_pos(child_pos) + rect, hover = child.this_pos(child_pos, bringontop) if hover: return rect, hover @@ -326,14 +326,15 @@ return obj - def update(self, rect = None): + def update(self, rect = None, render = True): """ Update this part of the object """ # Send a message to our parent, telling them this rect needs to be # updated - self.needs_update = True + if render: + self.needs_update = True if self.frozen: return @@ -376,19 +377,30 @@ if isparent: self.main_parent.update_mouse() self.frozen = False - self.update() + + if self.needs_update: + self.update() else: self.frozen = False - def this_pos(self, pos): + def this_pos(self, pos, bringontop = False): # Return the object on this position - for child in self.children: + # Bring to the foreground if needed + if bringontop and self.canrise: + # Find ourself in our parent's children-list + i = self.parent.children.index(self) + del self.parent.children[i] + self.parent.children.append(self) + self.update() + + # Find the child on this position + for child in reversed(self.children): if not child.rect.collidepoint(pos): continue child_pos = (pos[0] - child.rect[0], pos[1] - child.rect[1]) - rect, hover = child.this_pos(child_pos) + rect, hover = child.this_pos(child_pos, bringontop) rect.move_ip(child.rect[0], child.rect[1]) return rect, hover @@ -416,9 +428,9 @@ self.backgroundsurf = self.surf.copy() self.font = pygame.font.Font(real_path("fonts", \ "DejaVuSans-Bold.ttf"), 14) + self.buttonstate = 0 # 0 = Nothing, 1 = Hover, 2 = Click + self.mousepos = None # Mouse position when clicking the title - self.buttonstate = 0 - self.pos = { # img is the position on the image # pos is the rendered position @@ -504,6 +516,8 @@ inner = self.calculate_pos(self.pos['inner_pos']) self.backgroundsurf.fill(self.colors['bgcolor'], inner) + self.update() + def render(self): self.surf.fill([0, 0, 0, 0]) self.surf.blit(self.backgroundsurf, (0,0)) @@ -537,13 +551,33 @@ self.surf.blit(self.gui, rect, img) + def click(self, state, pos): + if state == 0: + if self.canclose: + border = Rect(9, 9, self.rect.width-51, 28) + else: + border = Rect(9, 9, self.rect.width-18, 28) + if border.collidepoint(pos): + # Get the REAL pos, not the one relative to self.rect + self.mousepos = (pos[0]-self.rect[0], pos[1]-self.rect[1]) + elif state == 1: + if self.mousepos != None: + movepos = [pos[0]-self.mousepos[0], pos[1]-self.mousepos[1]] + self.move(movepos) + elif state == 2: + self.mousepos = None + def move(self, newpos): + # Move the current window + oldrect = self.rect.move(0,0) # Where is .copy? + self.rect.topleft = newpos - def move(self, topos): - # [TODO] - pass + # Combina the old rect and the new rect to update our whole move + updaterect = oldrect.union(self.rect) + updaterect.topleft = (oldrect[0]-self.rect[0], oldrect[1]-self.rect[1]) + self.update(updaterect, render=False) Added: trunk/client/images/gui/window.png =================================================================== (Binary files differ) Property changes on: trunk/client/images/gui/window.png ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Modified: trunk/client/playground.py =================================================================== --- trunk/client/playground.py 2010-09-04 22:48:33 UTC (rev 390) +++ trunk/client/playground.py 2010-09-05 21:06:29 UTC (rev 391) @@ -352,7 +352,7 @@ # Create signup window window = self.parent.logingui.add(gui.Window, "signup", \ - Rect(0, 0, 200, 200), SignupFeedback()) + Rect(50, 50, 200, 200), SignupFeedback()) window.caption = "Signup" window.unfreeze() This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |