Advertisement
Guest User

Untitled

a guest
Jun 27th, 2016
381
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.43 KB | None | 0 0
  1. class TextLink(ui.Window):
  2.  
  3.     ## COLORS
  4.     NORMAL_COLOR = grp.GenerateColor(0.7607, 0.7607, 0.7607, 1.0)
  5.     OVER_COLOR = 0xff1457c7
  6.     DOWN_COLOR = 0xff0f3e8c
  7.    
  8.     def __init__(self):
  9.         ui.Window.__init__(self)
  10.        
  11.         self.eventFunc = None
  12.         self.eventArgs = None
  13.        
  14.         self.text = ui.TextLine()
  15.         self.text.SetParent(self)
  16.         self.text.Show()
  17.  
  18.         self.underline = ui.Line()
  19.         self.underline.SetParent(self)
  20.         self.underline.SetColor(self.NORMAL_COLOR)
  21.         self.underline.Hide()
  22.        
  23.     def __del__(self):
  24.         ui.Window.__del__(self)
  25.        
  26.     def SetText(self, text):
  27.         self.text.SetText(text)
  28.         self.SetSize(self.text.GetTextSize()[0], self.text.GetTextSize()[1])
  29.         self.underline.SetPosition(0, self.text.GetTextSize()[1])
  30.         self.underline.SetWindowHorizontalAlignCenter()
  31.         self.underline.SetSize(self.text.GetTextSize()[0], 0)
  32.        
  33.     def OnMouseOverIn(self):
  34.         self.text.SetPackedFontColor(self.OVER_COLOR)
  35.         self.underline.SetColor(self.OVER_COLOR)
  36.         self.underline.Show()
  37.        
  38.     def OnMouseOverOut(self):
  39.         self.text.SetPackedFontColor(self.NORMAL_COLOR)
  40.         self.underline.Hide()
  41.        
  42.     def OnMouseLeftButtonDown(self):
  43.         self.text.SetPackedFontColor(self.DOWN_COLOR)
  44.         self.underline.SetColor(self.DOWN_COLOR)
  45.         self.underline.Show()
  46.        
  47.     def OnMouseLeftButtonUp(self):
  48.         if self.eventFunc:
  49.             apply(self.eventFunc, self.eventArgs)
  50.         self.OnMouseOverOut()
  51.            
  52.     def SetEvent(self, event, *args):
  53.         self.eventFunc = event
  54.         self.eventArgs = args
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement