class HorizontalBar(ExpandedImageBox): BASE_PATH = "%s/controls/common/horizontal_bar/" % illumina.BASE_PATH WIDTH = 208 HEIGHT = 32 def __init__(self, layer = "UI"): ExpandedImageBox.__init__(self, layer) self.__width = 0 self.__CreateUI() self.SetWidth(HorizontalBar.WIDTH) def __del__(self): ExpandedImageBox.__del__(self) def __CreateUI(self): self.__txtTitle = None self.LoadImage("%s/center.tga" % HorizontalBar.BASE_PATH) self.Show() def SetWidth(self, width): self.__width = width self.SetScale(float(width) / float(HorizontalBar.WIDTH), 1.0) self.UpdateTitle() ## Title def SetTitle(self, title): if not self.__txtTitle: self.__txtTitle = TextLine() self.__txtTitle.SetParent(self) self.__txtTitle.SetPackedFontColor(0xFFCAA76F) self.__txtTitle.SetHorizontalAlignCenter() self.__txtTitle.Show() self.__txtTitle.SetText(title) self.UpdateTitle() def UpdateTitle(self): if not self.__txtTitle: return self.__txtTitle.SetPosition(self.__width / 2, 5)
class _BaseInput(Window): BASE_PATH = "%s/controls/common/input/" % illumina.BASE_PATH FILE_NAME_PREFIX = "" MIN_WIDTH = 0 HEIGHT = 0 TEXT_PADDING = (3, 3) TEXT_COLOR = 0xffffffff def __init__(self, layer = "UI"): Window.__init__(self, layer) self.__CreateUI() self.AddEventListener(Window.Events.ON_SET_FOCUS, self.__OnSetFocus) def __del__(self): Window.__del__(self) def __CreateUI(self): self.__dictImages = { 'LEFT' : ImageBox(), 'CENTER' : ExpandedImageBox(), 'RIGHT' : ImageBox() } for position, image in self.__dictImages.iteritems(): image.SetParent(self) image.AddFlag("not_pick") image.LoadImage("%s/%s_%s.tga" % (self.BASE_PATH, self.FILE_NAME_PREFIX, position.lower())) image.Show() self.__dictImages['CENTER'].SetPosition(self.__dictImages['LEFT'].GetWidth(), 0) self.__txtInput = None self.__textAlign = _BaseInput.TextAlign.LEFT def SetWidth(self, width): width = max(self.__dictImages['LEFT'].GetWidth() + self.__dictImages['RIGHT'].GetWidth(), width) Window.SetSize(self, width, self.HEIGHT) self.__dictImages['CENTER'].SetScale((width - (self.__dictImages['LEFT'].GetWidth() + self.__dictImages['RIGHT'].GetWidth())) / self.__dictImages['CENTER'].GetWidth(), 1.0) self.__dictImages['RIGHT'].SetPosition(width - self.__dictImages['RIGHT'].GetWidth(), 0) if self.__txtInput: self.__txtInput.SetSize(self.GetWidth() - self.TEXT_PADDING[0], self.GetHeight() - self.TEXT_PADDING[1]) self.ArrangeText() def __OnSetFocus(self): if not self.__txtInput: return self.__txtInput.SetFocus() ## TEXT def SetTextInstance(self, allowEdit = True): if self.__txtInput: self.DeleteTextInstance() if allowEdit: self.__txtInput = EditLine() else: self.__txtInput = TextLine() self.__txtInput.SetParent(self) self.__txtInput.SetSize(self.GetWidth() - self.TEXT_PADDING[0] * 2, self.GetHeight() - self.TEXT_PADDING[1] * 2) self.__txtInput.SetPackedFontColor(self.TEXT_COLOR) self.__txtInput.Show() self.ArrangeText() def DeleteTextInstance(self): if not self.__txtInput: return self.__txtInput.Hide() del self.__txtInput def GetTextInstance(self): return self.__txtInput class TextAlign: LEFT = 0 CENTER = 1 RIGHT = 2 def SetTextAlign(self, align): self.__textAlign = align self.ArrangeText() def ArrangeText(self): if not self.__txtInput: return if self.__textAlign == _BaseInput.TextAlign.LEFT: self.__txtInput.SetPosition(self.TEXT_PADDING[0], self.TEXT_PADDING[1]) self.__txtInput.SetHorizontalAlignLeft() elif self.__textAlign == _BaseInput.TextAlign.CENTER: self.__txtInput.SetPosition(self.GetWidth() / 2, self.TEXT_PADDING[1]) self.__txtInput.SetHorizontalAlignCenter() elif self.__textAlign == _BaseInput.TextAlign.RIGHT: self.__txtInput.SetPosition(self.GetWidth() - self.TEXT_PADDING[0], self.TEXT_PADDING[1]) self.__txtInput.SetHorizontalAlignRight()
class TitleBar(Window): BASE_PATH = "%s/controls/common/titlebar/" % illumina.BASE_PATH HEIGHT = 28 MIN_WIDTH = 70 def __init__(self, layer="UI"): Window.__init__(self, layer) self.__CreateUI() self.SetWidth(0) def __del__(self): Window.__del__(self) def __CreateUI(self): self.__dictImages = { 'LEFT': ImageBox(), 'CENTER': ExpandedImageBox(), 'RIGHT': ImageBox() } self.__imgCloseButtonDecoration = None self.__btnClose = None self.__txtTitle = None for image in self.__dictImages.itervalues(): image.SetParent(self) image.AddFlag("not_pick") image.Show() self.__dictImages['LEFT'].LoadImage("%s/left.tga" % TitleBar.BASE_PATH) self.__dictImages['CENTER'].LoadImage("%s/center.tga" % TitleBar.BASE_PATH) self.__dictImages['RIGHT'].LoadImage("%s/right.tga" % TitleBar.BASE_PATH) def UpdateGeneralUIPosition(self): self.__dictImages['LEFT'].SetPosition( 0, TitleBar.HEIGHT - self.__dictImages['LEFT'].GetHeight()) self.__dictImages['CENTER'].SetPosition( self.__dictImages['LEFT'].GetWidth(), TitleBar.HEIGHT - self.__dictImages['CENTER'].GetHeight()) self.__dictImages['RIGHT'].SetPosition( self.GetWidth() - self.__dictImages['RIGHT'].GetWidth(), TitleBar.HEIGHT - self.__dictImages['RIGHT'].GetHeight()) self.__dictImages['CENTER'].SetScale( float(self.GetWidth() - (self.__dictImages['LEFT'].GetWidth() + self.__dictImages['RIGHT'].GetWidth())) / float(self.__dictImages['CENTER'].GetWidth()), 1.0) def SetWidth(self, width): width = max(TitleBar.MIN_WIDTH, width) self.SetSize(width, TitleBar.HEIGHT) self.UpdateGeneralUIPosition() self.UpdateTitlePosition() self.UpdateCloseButtonAndDecorationPosition() ## TITLE def SetTitle(self, title): if not self.__txtTitle: self.__txtTitle = TextLine() self.__txtTitle.SetParent(self) self.__txtTitle.SetPackedFontColor(0xFFE6D0A2) self.__txtTitle.SetHorizontalAlignCenter() self.__txtTitle.SetVerticalAlignBottom() self.__txtTitle.Show() self.__txtTitle.SetText(title) self.UpdateTitlePosition() def UpdateTitlePosition(self): if not self.__txtTitle: return self.__txtTitle.SetPosition(self.GetWidth() / 2, 17) ## CLOSE BUTTON def AddCloseButton(self): self.__imgCloseButtonDecoration = ImageBox() self.__imgCloseButtonDecoration.SetParent(self) self.__imgCloseButtonDecoration.AddFlag("not_pick") self.__imgCloseButtonDecoration.LoadImage("%s/decoration_right.tga" % TitleBar.BASE_PATH) self.__imgCloseButtonDecoration.SetHorizontalAlign( wndMgr.HORIZONTAL_ALIGN_RIGHT) self.__imgCloseButtonDecoration.Show() self.__btnClose = SimpleButton() self.__btnClose.SetParent(self) self.__btnClose.SetUpVisual( "%s/controls/common/button/board_close_01_normal.tga" % illumina.BASE_PATH) self.__btnClose.SetOverVisual( "%s/controls/common/button/board_close_02_hover.tga" % illumina.BASE_PATH) self.__btnClose.SetDownVisual( "%s/controls/common/button/board_close_03_active.tga" % illumina.BASE_PATH) self.__btnClose.SetHorizontalAlign(wndMgr.HORIZONTAL_ALIGN_RIGHT) self.__btnClose.Show() self.UpdateGeneralUIPosition() self.UpdateTitlePosition() self.UpdateCloseButtonAndDecorationPosition() def GetCloseButton(self): return self.__btnClose def HasCloseButton(self): return (self.__imgCloseButtonDecoration and self.__btnClose) def UpdateCloseButtonAndDecorationPosition(self): if not self.HasCloseButton(): return self.__imgCloseButtonDecoration.SetPosition( self.__imgCloseButtonDecoration.GetWidth() - 13, -18) self.__btnClose.SetPosition(self.__btnClose.GetWidth() - 1, 0)
class _BaseButton(Window): class WidthType(object): STRETCH = 0 REPEAT = 1 BASE_PATH = "%s/controls/common/button/" % illumina.BASE_PATH IMAGES = None OPACITY = { _ButtonState.NORMAL: 1.0, _ButtonState.HOVER: 1.0, _ButtonState.ACTIVE: 1.0, _ButtonState.DISABLED: 1.0 } WIDTH = None HEIGHT = None WIDTH_TYPE = None TEXT_COLOR = None def __init__(self, layer="UI"): Window.__init__(self, layer) self.__state = _ButtonState.NORMAL self.__CreateUI() self._SetEventListeners() self.SetWidth(0) self.SetState(_ButtonState.NORMAL) def __del__(self): Window.__del__(self) def __CreateUI(self): self.__dictImages = { 'LEFT': { _ButtonState.NORMAL: ImageBox(), _ButtonState.HOVER: ImageBox(), _ButtonState.ACTIVE: ImageBox(), _ButtonState.DISABLED: ImageBox() }, 'CENTER': { _ButtonState.NORMAL: ExpandedImageBox(), _ButtonState.HOVER: ExpandedImageBox(), _ButtonState.ACTIVE: ExpandedImageBox(), _ButtonState.DISABLED: ExpandedImageBox() }, 'RIGHT': { _ButtonState.NORMAL: ImageBox(), _ButtonState.HOVER: ImageBox(), _ButtonState.ACTIVE: ImageBox(), _ButtonState.DISABLED: ImageBox() } } self.__txtText = None for position, imageDictByState in self.__dictImages.iteritems(): for state, image in imageDictByState.iteritems(): image.SetParent(self) image.AddFlag("not_pick") image.LoadImage(self.IMAGES[position][state]) image.Hide() def _SetEventListeners(self): self.AddEventListener( _BaseButton.Events.ON_MOUSE_OVER_IN, lambda state=_ButtonState.HOVER: self.SetState(state, True)) self.AddEventListener( _BaseButton.Events.ON_MOUSE_OVER_OUT, lambda state=_ButtonState.NORMAL: self.SetState(state, True)) self.AddEventListener( _BaseButton.Events.ON_MOUSE_LEFT_BUTTON_DOWN, lambda state=_ButtonState.ACTIVE: self.SetState(state, True)) self.AddEventListener(_BaseButton.Events.ON_MOUSE_LEFT_BUTTON_UP, self.OnClick) self.AddEventListener(_BaseButton.Events.ON_CLICK, lambda state=-1: self.SetState(state, True)) def __RefreshButton(self): for position, imageDictByState in self.__dictImages.iteritems(): for state, image in imageDictByState.iteritems(): if state != self.GetState(): image.Hide() else: image.SetAlpha(self.OPACITY[self.GetState()]) image.Show() self.UpdateTextColor() def GetState(self): return self.__state def SetState(self, state, byEvent=False): if byEvent and self.IsDisabled(): return callEnableEvent = self.GetState() == _ButtonState.DISABLED self.__state = state if self.GetState() < _ButtonState.NORMAL or self.GetState( ) > _ButtonState.DISABLED: if self.IsIn(): self.__state = _ButtonState.HOVER else: self.__state = _ButtonState.NORMAL self.__RefreshButton() if callEnableEvent: self.CallEventListener(_BaseButton.Events.ON_ENABLE) elif self.IsDisabled(): self.CallEventListener(_BaseButton.Events.ON_DISABLE) def SetEnabled(self, enabled=True): if enabled and self.IsDisabled(): self.SetState(_ButtonState.NORMAL) elif not enabled and not self.IsDisabled(): self.SetState(_ButtonState.DISABLED) def IsDisabled(self): return self.GetState() == _ButtonState.DISABLED def SetWidth(self, width): width = max(self.WIDTH['LEFT'] + self.WIDTH['RIGHT'], width) self.SetSize(width, self.HEIGHT) for image in self.__dictImages['CENTER'].itervalues(): image.SetPosition(self.WIDTH['LEFT'], 0) rect = float(width - (self.WIDTH['LEFT'] + self.WIDTH['RIGHT'])) / float( self.WIDTH['CENTER']) if self.WIDTH_TYPE == _BaseButton.WidthType.STRETCH: image.SetScale(rect, 1.0) else: image.SetRenderingRect(0.0, 0.0, -1.0 + rect, 0.0) for image in self.__dictImages['RIGHT'].itervalues(): image.SetPosition(width - self.WIDTH['RIGHT'], 0) self.UpdateText() ## Text def SetText(self, text): if not self.__txtText: self.__txtText = TextLine() self.__txtText.SetParent(self) self.__txtText.AddFlag("not_pick") self.__txtText.SetHorizontalAlignCenter() self.__txtText.SetVerticalAlignCenter() self.__txtText.Show() self.UpdateText() self.UpdateTextColor() self.__txtText.SetText(text) def GetText(self): if not self.__txtText: return "" return self.__txtText.GetText() def UpdateText(self): if not self.__txtText: return self.__txtText.SetPosition(self.GetWidth() / 2, self.GetHeight() / 2 - 2) def UpdateTextColor(self): if not self.__txtText: return self.__txtText.SetPackedFontColor(self.TEXT_COLOR[self.GetState()]) ################################################## ## EVENTS class Events(Window.Events): ON_CLICK = EventEnum() ON_DISABLE = EventEnum() ON_ENABLE = EventEnum() def OnClick(self): if self.IsDisabled(): return self.CallEventListener(_BaseButton.Events.ON_CLICK)