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. |