Go to the documentation of this file.00001 import BigWorld, GUI, Keys
00002
00003 from PyGUIBase import PyGUIBase
00004
00005 class Grid( PyGUIBase ):
00006
00007 factoryString="PyGUI.Grid"
00008
00009 def __init__( self, component ):
00010 PyGUIBase.__init__( self, component )
00011 component.script = self
00012
00013 self.component.focus = True
00014 self.component.moveFocus = True
00015 self.component.crossFocus = True
00016
00017 self.horizontalFirst = True
00018 self.gridWidth = 1
00019 self.gridHeight = 1
00020 self.borderTop = 0
00021 self.borderBottom = 0
00022 self.borderLeft = 0
00023 self.borderRight = 0
00024 self.horizontalGap = 0
00025 self.verticalGap = 0
00026
00027
00028 def onSave( self, dataSection ):
00029 dataSection.writeBool( "horizontalFirst", self.horizontalFirst )
00030 dataSection.writeFloat( "gridWidth", self.gridWidth )
00031 dataSection.writeFloat( "gridHeight", self.gridHeight )
00032 dataSection.writeFloat( "borderTop", self.borderTop )
00033 dataSection.writeFloat( "borderBottom", self.borderBottom )
00034 dataSection.writeFloat( "borderLeft", self.borderLeft )
00035 dataSection.writeFloat( "borderRight", self.borderRight )
00036 dataSection.writeFloat( "horizontalGap", self.horizontalGap )
00037 dataSection.writeFloat( "verticalGap", self.verticalGap )
00038
00039
00040 def onLoad( self, dataSection ):
00041 self.horizontalFirst = dataSection.readBool( "horizontalFirst", self.horizontalFirst )
00042 self.gridWidth = dataSection.readFloat( "gridWidth", self.gridWidth )
00043 self.gridHeight = dataSection.readFloat( "gridHeight", self.gridHeight )
00044 self.borderTop = dataSection.readFloat( "borderTop", self.borderTop )
00045 self.borderBottom = dataSection.readFloat( "borderBottom", self.borderBottom )
00046 self.borderLeft = dataSection.readFloat( "borderLeft", self.borderLeft )
00047 self.borderRight = dataSection.readFloat( "borderRight", self.borderRight )
00048 self.horizontalGap = dataSection.readFloat( "horizontalGap", self.horizontalGap )
00049 self.verticalGap = dataSection.readFloat( "verticalGap", self.verticalGap )
00050
00051
00052 def doLayout( self ):
00053 widthMode = self.component.widthMode
00054 heightMode = self.component.heightMode
00055
00056 if widthMode == 'PIXEL':
00057 horizSize = (self.component.width - self.borderLeft - self.borderRight \
00058 - self.horizontalGap * (self.gridWidth - 1)) / self.gridWidth
00059 horizOffset = horizSize + self.horizontalGap
00060 horizStart = self.borderLeft
00061 if widthMode == 'CLIP':
00062 horizSize = (2.0 - self.borderLeft - self.borderRight \
00063 - self.horizontalGap * (self.gridWidth - 1)) / self.gridWidth
00064 horizOffset = horizSize + self.horizontalGap
00065 horizStart = -1.0 + self.borderLeft
00066
00067 if heightMode == 'PIXEL':
00068 vertSize = (self.component.height - self.borderTop - self.borderBottom \
00069 - self.verticalGap * (self.gridHeight - 1)) / self.gridHeight
00070 vertOffset = vertSize + self.verticalGap
00071 vertStart = self.borderTop
00072 if heightMode == 'CLIP':
00073 vertSize = (2.0 - self.borderTop - self.borderBottom \
00074 - self.verticalGap * (self.gridHeight - 1)) / self.gridHeight
00075 vertOffset = -(vertSize + self.verticalGap)
00076 vertStart = 1.0 - self.borderTop
00077
00078 horizPos = horizStart
00079 vertPos = vertStart
00080 count = 1
00081
00082 for (discard,i) in self.component.children:
00083 i.widthMode = widthMode
00084 i.width = horizSize
00085 i.heightMode = heightMode
00086 i.height = vertSize
00087 i.horizontalPositionMode = widthMode
00088 i.verticalPositionMode = heightMode
00089 i.horizontalAnchor = 'LEFT'
00090 i.verticalAnchor = 'TOP'
00091 i.position = (horizPos, vertPos, i.position[2])
00092
00093 if self.horizontalFirst:
00094 if count == self.gridWidth:
00095 count = 1
00096 horizPos = horizStart
00097 vertPos += vertOffset
00098 else:
00099 count += 1
00100 horizPos += horizOffset
00101 else:
00102 if count == self.gridHeight:
00103 count = 1
00104 vertPos = vertStart
00105 horizPos += horizOffset
00106 else:
00107 count += 1
00108 vertPos += vertOffset
00109
00110
00111 @staticmethod
00112 def create( texture, gridSize = (1,1), horizontalFirst = True, **kwargs ):
00113 c = GUI.Window( texture )
00114 c.materialFX = "BLEND"
00115 c.widthMode = 'CLIP'
00116 c.heightMode = 'CLIP'
00117 c.horizontalPositionMode = 'CLIP'
00118 c.verticalPositionMode = 'CLIP'
00119
00120 g = Grid( c, **kwargs )
00121 if len( gridSize ) == 2:
00122 g.gridWidth = gridSize[0]
00123 g.gridHeight = gridSize[1]
00124 else:
00125 g.gridWidth = 1
00126 g.gridHeight = 1
00127
00128 g.horizontalFirst = horizontalFirst
00129
00130
00131 return g.component
00132