Go to the documentation of this file.00001 '''
00002 TextField2 text display GUI with two text components
00003
00004 Anoria (c) Gsk 2010
00005 '''
00006
00007
00008 import BigWorld, GUI
00009 import AnGUI
00010 import Helpers.PyGUI as PyGUI
00011
00012
00013
00014 class TextField2(AnGUI.Base):
00015 """
00016 This class implements a double text field by creating a GUI.Window container
00017 and two GUI.Text component as its children. This set up allows positioning of the Text
00018 i.e left/center/right align in both fields and is well suited for use in stats displays or similar
00019 By default the "label" text component is left aligned and the "text" component is right aligned
00020 """
00021
00022 factoryString = "AnGUI.TextField2"
00023
00024 def __init__(self, component):
00025 AnGUI.Base.__init__( self, component )
00026 component.script = self
00027 self.component.materialFX = "BLEND"
00028
00029 self.hlTextColour = ( 255, 255, 255, 255 )
00030 self.stdTextColour = ( 0, 0, 0, 255 )
00031 self.canActivate = True
00032 self.canHighlight = True
00033
00034
00035
00036
00037
00038
00039
00040 def onBound(self):
00041 self.name = 'tf_%s' % (self.component.label.text)
00042
00043
00044
00045 def handleMouseEnterEvent(self, comp):
00046
00047 self.component.label.colour = self.hlTextColour
00048 self.component.text.colour = self.hlTextColour
00049 return True
00050
00051 def handleMouseLeaveEvent(self, comp):
00052
00053 self.component.label.colour = self.stdTextColour
00054 self.component.text.colour = self.stdTextColour
00055 return True
00056
00057
00058 def resize(self):
00059 print "resizing ..."
00060 c = self.component
00061 dim = c.label.stringDimensions(c.text.text)
00062 c.width = dim[0]
00063 c.height = dim[1]
00064 dim = c.text.stringDimensions(c.text.text)
00065 c.width = c.width+dim[0]
00066
00067 @staticmethod
00068 def create(t_label="foo", t_text="bar", texture="", font=None):
00069
00070 c = GUI.Window(texture)
00071 c.horizontalAnchor = "LEFT"
00072 c.verticalAnchor = "TOP"
00073 c.horizontalPositionMode = "CLIP"
00074 c.verticalPositionMode = "CLIP"
00075 c.position = (-1.0, 1.0, 1.0)
00076
00077 c.widthMode="PIXEL"
00078 c.heightMode="PIXEL"
00079
00080
00081
00082
00083 label = GUI.Text(t_label)
00084 if font != None:
00085 label.font=font
00086 else:
00087 label.font="default_small.font"
00088
00089 text = GUI.Text(t_text)
00090 if font != None:
00091 text.font=font
00092 else:
00093 text.font="default_small.font"
00094
00095 c.addChild(label, "label")
00096 c.addChild(text, "text")
00097
00098 label.horizontalAnchor = "LEFT"
00099 label.verticalAnchor = "TOP"
00100 label.horizontalPositionMode = "CLIP"
00101 label.verticalPositionMode = "CLIP"
00102 label.position = (-1.0, 1.0, 1.0)
00103
00104 text.horizontalAnchor = "RIGHT"
00105 text.verticalAnchor = "TOP"
00106 text.horizontalPositionMode = "CLIP"
00107 text.verticalPositionMode = "CLIP"
00108 text.position = (1.0, 1.0, 1.0)
00109
00110 return TextField2(c).component