From: <Blu...@us...> - 2010-08-08 17:38:30
|
Revision: 363 http://virtplayground.svn.sourceforge.net/virtplayground/?rev=363&view=rev Author: BlueWolf_ Date: 2010-08-08 17:38:24 +0000 (Sun, 08 Aug 2010) Log Message: ----------- Keys with ctrl pressed won't be seen as characters anymore. Can be used as shortkeys now Modified Paths: -------------- trunk/client/gui.py Modified: trunk/client/gui.py =================================================================== --- trunk/client/gui.py 2010-08-08 15:24:53 UTC (rev 362) +++ trunk/client/gui.py 2010-08-08 17:38:24 UTC (rev 363) @@ -485,41 +485,45 @@ def keypress(self, ev): if ev.type == KEYDOWN: - if ev.key == K_LEFT: # Cursorpos change - if self.cursorpos > 0: self.cursorpos -= 1 + if ev.mod & KMOD_CTRL: # Ctrl combination + + if ev.key == K_BACKSPACE: # Remove the whole input + self.input = "" + self.cursorpos = 0 - elif ev.key == K_RIGHT: # Cursorpos change - if self.cursorpos < len(self.input): self.cursorpos += 1 + else: - elif ev.key == K_BACKSPACE: # Backspace - if ev.mod & KMOD_CTRL: - self.input = "" - self.cursorpos = 0 - else: + if ev.key == K_LEFT: # Cursorpos change + if self.cursorpos > 0: self.cursorpos -= 1 + + elif ev.key == K_RIGHT: # Cursorpos change + if self.cursorpos < len(self.input): self.cursorpos += 1 + + elif ev.key == K_BACKSPACE: # Backspace self.input = self.input[:self.cursorpos-1] + \ self.input[self.cursorpos:] if self.cursorpos > 0: self.cursorpos -= 1 - - elif ev.key == K_DELETE: # Delete - self.input = self.input[:self.cursorpos] + \ - self.input[self.cursorpos+1:] - - elif ev.key == K_HOME: # Go to the beginning - self.cursorpos = 0 - - elif ev.key == K_END: # Go to the end - self.cursorpos = len(self.input) - - elif ev.key == K_TAB: # Focus the next object - self.parent.focus_next(self) - - elif ev.unicode == "\r": # Ignore this - pass - elif ev.unicode != "": # Normal text - self.input = self.input[:self.cursorpos] + ev.unicode + \ - self.input[self.cursorpos:] - self.cursorpos += 1 + + elif ev.key == K_DELETE: # Delete + self.input = self.input[:self.cursorpos] + \ + self.input[self.cursorpos+1:] + elif ev.key == K_HOME: # Go to the beginning + self.cursorpos = 0 + + elif ev.key == K_END: # Go to the end + self.cursorpos = len(self.input) + + elif ev.key == K_TAB: # Focus the next object + self.parent.focus_next(self) + + elif ev.unicode == "\r": # Ignore this + pass + elif ev.unicode != "": # Normal text + self.input = self.input[:self.cursorpos] + ev.unicode + \ + self.input[self.cursorpos:] + self.cursorpos += 1 + self.update() if self.cb_keypress: self.cb_keypress(self, ev) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <Blu...@us...> - 2010-08-25 11:45:17
|
Revision: 371 http://virtplayground.svn.sourceforge.net/virtplayground/?rev=371&view=rev Author: BlueWolf_ Date: 2010-08-25 11:45:11 +0000 (Wed, 25 Aug 2010) Log Message: ----------- Forgot the password special case. It now uses *'s instead of the characters to calculate the position Modified Paths: -------------- trunk/client/gui.py Modified: trunk/client/gui.py =================================================================== --- trunk/client/gui.py 2010-08-25 11:42:12 UTC (rev 370) +++ trunk/client/gui.py 2010-08-25 11:45:11 UTC (rev 371) @@ -500,15 +500,19 @@ def click(self, state, pos): if state == 0: - # Calculate position based on pos + + # Calculate position based on the clicked position + inp = self.input + if self.type == "password": + inp = "*"*len(self.input) + actualpos = pos[0]-6-self.textpos - lastsize = 0 - for i in range(len(self.input)+1): - textsize = self.font.size(self.input[:i])[0] + for i in range(len(inp)+1): + textsize = self.font.size(inp[:i])[0] if textsize > actualpos: # Which direction is closer, left or right? - if textsize-actualpos > actualpos-lastsize: + if textsize-actualpos > actualpos-lastsize: # Left i = i -1 break lastsize = textsize @@ -516,6 +520,7 @@ if i == -1: i = 0 self.cursorpos = i + if self.focus: self.update() This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <Blu...@us...> - 2010-09-06 16:00:39
|
Revision: 392 http://virtplayground.svn.sourceforge.net/virtplayground/?rev=392&view=rev Author: BlueWolf_ Date: 2010-09-06 16:00:32 +0000 (Mon, 06 Sep 2010) Log Message: ----------- Fixed a update bug when moving the window very fast to the topleft. Can't figure out yet why the inner-window looks partly transparent Modified Paths: -------------- trunk/client/gui.py Modified: trunk/client/gui.py =================================================================== --- trunk/client/gui.py 2010-09-05 21:06:29 UTC (rev 391) +++ trunk/client/gui.py 2010-09-06 16:00:32 UTC (rev 392) @@ -576,7 +576,7 @@ # 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]) + updaterect.move_ip(-self.rect[0], -self.rect[1]) self.update(updaterect, render=False) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <Blu...@us...> - 2010-09-08 19:11:02
|
Revision: 396 http://virtplayground.svn.sourceforge.net/virtplayground/?rev=396&view=rev Author: BlueWolf_ Date: 2010-09-08 19:10:55 +0000 (Wed, 08 Sep 2010) Log Message: ----------- GUI-objects can now distinguish which mousebutton is pressed. Also fixed a rather annoying bug in the window which happended when pressing a mousebutton while moving the window Modified Paths: -------------- trunk/client/gui.py Modified: trunk/client/gui.py =================================================================== --- trunk/client/gui.py 2010-09-08 15:50:22 UTC (rev 395) +++ trunk/client/gui.py 2010-09-08 19:10:55 UTC (rev 396) @@ -181,7 +181,7 @@ # the interface pos = (ev.pos[0] - self.mousedown[0][0], \ ev.pos[1] - self.mousedown[0][1]) - self.mousedown[1].click(1, pos) + self.mousedown[1].click(1, pos, ev.buttons) return True else: # Check which object we hover @@ -195,24 +195,25 @@ 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) + hover.click(0, pos, ev.button) - self.mousedown = (rect, hover) + if ev.button == 1: + self.mousedown = (rect, hover) - if self.focus != hover: - # Change the focus - if self.focus: - self.focus.focus = False - self.focus.lost_focus() - self.focus = None + if self.focus != hover: + # Change the focus + if self.focus: + self.focus.focus = False + self.focus.lost_focus() + self.focus = None + + self.focus = hover - self.focus = hover + # Tell this object + hover.focus = True + hover.got_focus() + self.feedback.mousedown(hover) - # Tell this object - hover.focus = True - hover.got_focus() - self.feedback.mousedown(hover) - return True else: @@ -229,9 +230,11 @@ obj = self.mousedown[1] obj.frozen = True - obj.click(2, pos) - self.mousedown = None + obj.click(2, pos, ev.button) + if not 1 in pygame.mouse.get_pressed(): + self.mousedown = None + obj.unfreeze() return True @@ -315,9 +318,31 @@ pass def hovering(self, state=None, pos=None): + """ + Executed when a object gets hovered. + State = True - Mouse enters the object + State = False - Mouse leaves the object + State = None - When state doesn't change. When the mouse is already + hovering about the object + + pos will only be a tuple when state is either True or None + """ + pass - def click(self, state, pos): + def click(self, state, pos, button): + """ + When a object gets clicked + State = 0 - Mousebutton got clicked + State = 1 - Mousebutton is clicked, mouse got moved + State = 2 - Mousebutton is released + + pos = Position of the mouse, compared to the object + + button = Which button is pressed. + Please not that with state = 2 'button' is a tuple with all the + pressed buttons! + """ pass def got_focus(self): @@ -573,8 +598,8 @@ self.surf.blit(self.gui, rect, img) - def click(self, state, pos): - if state == 0: + def click(self, state, pos, button): + if state == 0 and button == 1: if self.canclose: border = Rect(9, 9, self.rect.width-51, 28) close = self.calculate_pos(self.pos['close_pos']) @@ -589,22 +614,21 @@ self.closedown = True self.update(close) - elif state == 1: - if self.mousepos != None: - movepos = [pos[0]-self.mousepos[0], pos[1]-self.mousepos[1]] - self.move(movepos) + elif state == 1 and self.mousepos != None: + movepos = [pos[0]-self.mousepos[0], pos[1]-self.mousepos[1]] + self.move(movepos) - if self.closedown: - close = self.calculate_pos(self.pos['close_pos']) - inside = close.collidepoint(pos) - if self.closedown_visible and not inside: - self.closedown_visible = False - self.update(close) - elif self.closedown_visible == False and inside: - self.closedown_visible = True - self.update(close) + elif state == 1 and self.closedown: + close = self.calculate_pos(self.pos['close_pos']) + inside = close.collidepoint(pos) + if self.closedown_visible and not inside: + self.closedown_visible = False + self.update(close) + elif self.closedown_visible == False and inside: + self.closedown_visible = True + self.update(close) - elif state == 2: + elif state == 2 and button == 1: self.mousepos = None if self.closedown: @@ -765,8 +789,8 @@ if self.focus: pygame.draw.line(self.surf, [118, 58, 19], (pos+cursorpos+6, 10), (pos+cursorpos+6, 26), 2) - def click(self, state, pos): - if state == 0: + def click(self, state, pos, button): + if state == 0 and button == 1: # Calculate position based on the clicked position inp = self.input @@ -921,20 +945,20 @@ if state != None: self.update() - def click(self, state, pos): - if state == 0: + def click(self, state, pos, button): + if state == 0 and button == 1: self.clicked = True self.clicked_visible = True self.update() - elif state == 1: + elif state == 1 and self.clicked: hover = bool(Rect(0, 0, self.rect.width, self.rect.height) .collidepoint(pos)) if hover != self.clicked_visible: self.clicked_visible = hover self.update() - elif state == 2: + elif state == 2 and button == 1: waspressed = self.clicked_visible self.clicked = False @@ -1059,19 +1083,19 @@ if state != None: self.update() - def click(self, state, pos): - if state == 0: + def click(self, state, pos, button): + if state == 0 and button == 1: self.clicked = True self.clicked_visible = True self.update() - elif state == 1: + elif state == 1 and self.clicked: hover = bool(Rect(0, 0, self.rect.width, self.rect.height).collidepoint(pos)) if hover != self.clicked_visible: self.clicked_visible = hover self.update() - elif state == 2: + elif state == 2 and button == 1: wasclicked = self.clicked_visible self.clicked = False self.clicked_visible = False This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |