Go to the documentation of this file.00001 '''
00002 Anoria (c) Gsk 2010
00003 '''
00004
00005
00006 import BigWorld, GUI
00007 import Helpers.PyGUI as PyGUI
00008
00009
00010 """
00011 This class implements a text field by creating a GUI.Window container
00012 and a GUI.Text component as its child. This set up allows positioning of the Text
00013 i.e left/center/right align
00014 """
00015 class TextField( PyGUI.PyGUIBase ):
00016
00017 factoryString = "AnGUI.TextField"
00018
00019 def __init__(self, component):
00020 PyGUI.PyGUIBase.__init__( self, component )
00021 component.script = self
00022 self.component.materialFX = "BLEND"
00023 self.component.colour = ( 64, 64, 64, 255)
00024 self.alignment = "LEFT"
00025
00026
00027 def alignText(self, alignment):
00028 if alignment == "LEFT":
00029 self.component.text.horizontalAnchor = "LEFT"
00030 self.component.text.verticalAnchor = "TOP"
00031 self.component.text.position = (-1.0, 1.0, 1.0)
00032 self.alignment = alignment
00033 if alignment == "RIGHT":
00034 self.component.text.horizontalAnchor = "RIGHT"
00035 self.component.text.verticalAnchor = "TOP"
00036 self.component.text.position = (1.0, 1.0, 1.0)
00037 self.alignment = alignment
00038
00039
00040 def resize(self):
00041 print "resizing ..."
00042 c = self.component
00043 dim = c.text.stringDimensions(c.text.text)
00044 c.width = dim[0]
00045 c.height = dim[1]
00046
00047 @staticmethod
00048 def create(t_text="foobar", texture="", font=None):
00049
00050 c = GUI.Window(texture)
00051 c.horizontalAnchor = "LEFT"
00052 c.verticalAnchor = "TOP"
00053 c.horizontalPositionMode = "CLIP"
00054 c.verticalPositionMode = "CLIP"
00055 c.position = (-1.0, 1.0, 1.0)
00056
00057 c.widthMode="PIXEL"
00058 c.heightMode="PIXEL"
00059
00060
00061
00062
00063 text = GUI.Text(t_text)
00064 if font != None:
00065 text.font=font
00066 else:
00067 text.font="default_small.font"
00068
00069 c.addChild(text, "text")
00070
00071 text.horizontalAnchor = "LEFT"
00072 text.verticalAnchor = "TOP"
00073 text.horizontalPositionMode = "CLIP"
00074 text.verticalPositionMode = "CLIP"
00075 text.position = (-1.0, 1.0, 1.0)
00076
00077 return TextField(c).component