Go to the documentation of this file.00001 import BigWorld, GUI, Keys
00002
00003 from PyGUIBase import PyGUIBase
00004
00005 """
00006 This classes implements a scroll window.
00007 """
00008 class ScrollWindow( PyGUIBase ):
00009
00010 factoryString="PyGUI.ScrollWindow"
00011
00012 def __init__( self, component ):
00013 PyGUIBase.__init__( self, component )
00014
00015
00016
00017
00018 def handleKeyEvent( self, down, key, modifiers ):
00019 c = self.component
00020 if ( down ):
00021 if ( key == Keys.KEY_JOYDUP or key == Keys.KEY_UPARROW ) :
00022 (x,y) = c.scroll
00023 y += 0.1
00024 c.scroll = (x,y)
00025 BigWorld.playSound("ui/tick")
00026 return 1
00027 elif ( key == Keys.KEY_JOYDDOWN or key == Keys.KEY_DOWNARROW ) :
00028 (x,y) = c.scroll
00029 y -= 0.1
00030 c.scroll = (x,y)
00031 BigWorld.playSound("ui/tick")
00032 return 1
00033 elif ( key == Keys.KEY_JOYDRIGHT or key == Keys.KEY_RIGHTARROW ) :
00034 (x,y) = c.scroll
00035 x += 0.1
00036 c.scroll = (x,y)
00037 BigWorld.playSound("ui/tick")
00038 return 1
00039 elif ( key == Keys.KEY_JOYDLEFT or key == Keys.KEY_LEFTARROW ) :
00040 (x,y) = c.scroll
00041 x -= 0.1
00042 c.scroll = (x,y)
00043 BigWorld.playSound("ui/tick")
00044 return 1
00045
00046 return 0
00047
00048
00049 """
00050 This classes implements a zoom + scroll window.
00051 """
00052 class ZoomScrollWindow( ScrollWindow ):
00053
00054 factoryString="PyGUI.ZoomScrollWindow"
00055
00056 def __init__( self, component ):
00057 ScrollWindow.__init__( self, component )
00058 self.zoomFactor = 1
00059
00060 def updateScrollLimits( self ):
00061 c = self.component.children[0][1]
00062 (w,h) = (c.width, c.height)
00063 (x,y) = self.component.maxScroll
00064 x = (w-self.component.width) / 2
00065 y = (h-self.component.height) / 2
00066 self.component.maxScroll = (x,y)
00067 self.component.minScroll = (-x,-y)
00068
00069
00070
00071
00072
00073 def handleKeyEvent( self, down, key, modifiers ):
00074 handled = ScrollWindow.handleKeyEvent( self, down, key, modifiers )
00075 if not handled and down:
00076 if ( key == Keys.KEY_JOYALPUSH ) :
00077 if self.zoomFactor > 1:
00078 c = self.component.children[0][1]
00079 c.width = c.width / 2
00080 c.height = c.height / 2
00081 self.updateScrollLimits()
00082 self.zoomFactor = self.zoomFactor - 1
00083 BigWorld.playSound("ui/boop")
00084 return 1
00085 elif key in [ Keys.KEY_JOYARPUSH, Keys.KEY_MIDDLEMOUSE ]:
00086 c = self.component.children[0][1]
00087 c.width = c.width * 2
00088 c.height = c.height * 2
00089 self.updateScrollLimits()
00090 self.zoomFactor = self.zoomFactor + 1
00091 BigWorld.playSound("ui/boop")
00092 return 1
00093
00094 return 0
00095