From: <Blu...@us...> - 2010-07-28 20:51:53
|
Revision: 343 http://virtplayground.svn.sourceforge.net/virtplayground/?rev=343&view=rev Author: BlueWolf_ Date: 2010-07-28 20:51:47 +0000 (Wed, 28 Jul 2010) Log Message: ----------- The topnav reacts to hovers. And then I discovered the image isn't perfect symmetric, hence the weird block box that appears next to the right button. grr.. Modified Paths: -------------- trunk/client/layout.py trunk/client/playground.py Modified: trunk/client/layout.py =================================================================== --- trunk/client/layout.py 2010-07-28 19:19:04 UTC (rev 342) +++ trunk/client/layout.py 2010-07-28 20:51:47 UTC (rev 343) @@ -1,6 +1,12 @@ from functions import * +TOPBUTTONS = 3 +TOPLEFT = 44 +TOPBUTTONWIDTH = 304 +TOPHEIGHT = 65 + class Layout(): + def __init__(self, sh): self.sh = sh @@ -9,6 +15,9 @@ self.status = None + self.selected = None + self.hover = None + # Login stuff self.loginbg = None self.loginfont = None @@ -17,9 +26,27 @@ self.topbar = None def event(self, ev): - pass + if self.status == "playground": + if ev.type == MOUSEMOTION: + if ev.pos[0] > 44 and ev.pos[0] < 926 and \ + ev.pos[1] < 55: + + index = (ev.pos[0]-TOPLEFT)/ \ + TOPBUTTONWIDTH + + if self.hover == index: return True + self.hover = index + self.updatetop() + + return True + else: + if self.hover == None: return + self.hover = None + self.updatetop() + + def changestatus(self, status): login_list = ['connecting', 'login', 'logging in'] if status in login_list and self.status not in login_list: @@ -33,6 +60,28 @@ load_image(True, "images", "topbar3.png") ] + self.selected = None + self.hover = None # [TODO] This can be better self.surf.blit(self.topbar[0], (0,0)) - - self.sh['update']() + self.updatetop() + + self.status = status + + + def updatetop(self): + for i in range(TOPBUTTONS): + left = TOPLEFT + (TOPBUTTONWIDTH*i) + rect = (left, 0, TOPBUTTONWIDTH, TOPHEIGHT) + + self.surf.fill([0,0,0,0], rect) + + if self.selected == i: # This button is selected + self.surf.blit(self.topbar[2], rect, rect) + + elif self.hover == i: # This button is hovered + self.surf.blit(self.topbar[1], rect, rect) + + else: + self.surf.blit(self.topbar[0], rect, rect) + + self.sh['update']() Modified: trunk/client/playground.py =================================================================== --- trunk/client/playground.py 2010-07-28 19:19:04 UTC (rev 342) +++ trunk/client/playground.py 2010-07-28 20:51:47 UTC (rev 343) @@ -22,7 +22,7 @@ if ev.type == KEYDOWN and ev.unicode == "\r": # Fake login self.drawlogin("logging in") - self.sh['client'].login("myname", "mypass") + self.sh['client'].login("BlueWolf", "mypass") def changestatus(self, status): This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |