class Expander(Window): BASE_PATH = "%s/controls/common/expander/" % illumina.BASE_PATH IMAGES = { 'LEFT' : { ExpanderState.COLLAPSED : "left_01_normal.tga", ExpanderState.EXPANDED : "left_02_hover.tga" }, 'CENTER' : { ExpanderState.COLLAPSED : "center_01_normal.tga", ExpanderState.EXPANDED : "center_02_hover.tga" }, 'RIGHT' : { ExpanderState.COLLAPSED : "right_01_normal.tga", ExpanderState.EXPANDED : "right_02_hover.tga" } } MIN_WIDTH = 30 HEIGHT = 30 def __init__(self, layer = "UI"): Window.__init__(self, layer) self.__state = ExpanderState.COLLAPSED self.__arrowRotation = 0.0 self.__CreateUI() self.__SetEventListeners() self.SetWidth(0) self.SetState(ExpanderState.COLLAPSED) def __del__(self): Window.__del__(self) def __CreateUI(self): self.__dictImages = { 'LEFT' : { ExpanderState.EXPANDED : ImageBox(), ExpanderState.COLLAPSED : ImageBox() }, 'CENTER' : { ExpanderState.EXPANDED : ExpandedImageBox(), ExpanderState.COLLAPSED : ExpandedImageBox() }, 'RIGHT' : { ExpanderState.EXPANDED : ImageBox(), ExpanderState.COLLAPSED : 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("%s/%s" % (Expander.BASE_PATH, Expander.IMAGES[position][state])) image.Hide() self.__imgArrowBackground = ImageBox() self.__imgArrowBackground.SetParent(self) self.__imgArrowBackground.AddFlag("not_pick") self.__imgArrowBackground.SetPosition(0, 0) self.__imgArrowBackground.LoadImage("%s/arrow_bg.tga" % Expander.BASE_PATH) self.__imgArrowBackground.Show() self.__imgArrow = ExpandedImageBox() self.__imgArrow.SetParent(self.__imgArrowBackground) self.__imgArrow.AddFlag("not_pick") self.__imgArrow.SetPosition(0, 0) self.__imgArrow.LoadImage("%s/arrow.tga" % Expander.BASE_PATH) self.__imgArrow.SetHorizontalAlign(wndMgr.HORIZONTAL_ALIGN_CENTER) self.__imgArrow.SetVerticalAlign(wndMgr.VERTICAL_ALIGN_CENTER) self.__imgArrow.Show() def __SetEventListeners(self): self.AddEventListener(Expander.Events.ON_MOUSE_OVER_IN, lambda : self.__RefreshButton(ExpanderState.EXPANDED)) self.AddEventListener(Expander.Events.ON_MOUSE_OVER_OUT, lambda : self.__RefreshButton(ExpanderState.COLLAPSED)) self.AddEventListener(Expander.Events.ON_MOUSE_LEFT_BUTTON_UP, lambda : self.SetState(ExpanderState.EXPANDED if self.GetState() == ExpanderState.COLLAPSED else ExpanderState.COLLAPSED)) def __RefreshButton(self, expandingState): for position, imageDictByState in self.__dictImages.iteritems(): for state, image in imageDictByState.iteritems(): if state != expandingState: image.Hide() else: image.Show() if self.GetState() == ExpanderState.COLLAPSED: self.__imgArrow.SetRotation(self.__arrowRotation) else: self.__imgArrow.SetRotation(180.0 + self.__arrowRotation) def GetState(self): return self.__state def SetState(self, state): self.__state = state self.__RefreshButton(self.__state) def SetWidth(self, width): width = max(Expander.MIN_WIDTH, width) self.SetSize(width, Expander.HEIGHT) for image in self.__dictImages['CENTER'].itervalues(): image.SetPosition(5, 0) image.SetScale(float(width - 10), 1.0) for image in self.__dictImages['RIGHT'].itervalues(): image.SetPosition(width - 5, 0) self.UpdateText() def SetArrowRotation(self, rotation): self.__arrowRotation = rotation self.__imgArrow.SetRotation(rotation) ## Text def SetText(self, text): if not self.__txtText: self.__txtText = TextLine() self.__txtText.SetParent(self) self.__txtText.AddFlag("not_pick") self.__txtText.SetVerticalAlignCenter() self.__txtText.SetPackedFontColor(0xFFE6D0A2) self.__txtText.Show() self.UpdateText() 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(35, self.GetHeight() / 2 - 2) ################################################## ## EVENTS class Events(Window.Events): ON_EXPAND = EventEnum() ON_COLLAPSE = EventEnum()
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 Board(_BoardBase): class _Shadow(_BoardBase): BASE_PATH = "%s/controls/common/board/" % illumina.BASE_PATH FILE_NAME_POSTFIX = "shadow_" DIMENSIONS = { 'CORNER': { 'WIDTH': 73, 'HEIGHT': 73 }, 'BAR_VERTICAL': { 'WIDTH': 1, 'HEIGHT': 73 }, 'BAR_HORIZONTAL': { 'WIDTH': 73, 'HEIGHT': 1 }, 'FILL': { 'WIDTH': 1, 'HEIGHT': 1 } } MIN_WIDTH = 55 * 2 MIN_HEIGHT = 55 * 2 def SetOpacity(self, opacity): for imageDictKey in (['CORNER', 'BAR']): for position, image in self._dictImages[ imageDictKey].iteritems(): image.SetDiffuseColor(1.0, 1.0, 1.0, opacity) self._dictImages['FILL'].SetDiffuseColor(1.0, 1.0, 1.0, opacity) BASE_PATH = "%s/controls/common/board/" % illumina.BASE_PATH DIMENSIONS = { 'CORNER': { 'WIDTH': 55, 'HEIGHT': 55 }, 'BAR_VERTICAL': { 'WIDTH': 128, 'HEIGHT': 55 }, 'BAR_HORIZONTAL': { 'WIDTH': 55, 'HEIGHT': 128 }, 'FILL': { 'WIDTH': 128, 'HEIGHT': 128 } } MIN_WIDTH = 55 * 2 MIN_HEIGHT = 55 * 2 def __init__(self, shadowSize=-1, layer="UI"): self.__hasShadow = shadowSize != -1 self.__shadowSize = shadowSize _BoardBase.__init__(self, layer) def __del__(self): _BoardBase.__del__(self) def _CreateUI(self): if self.__hasShadow: self.__CreateShadow() else: self.__wndShadow = None self.__imgDecoration = ImageBox() self.__imgDecoration.SetParent(self) self.__imgDecoration.LoadImage("%s/decoration_leftbottom.tga" % self.BASE_PATH) self.__imgDecoration.SetVerticalAlign(wndMgr.VERTICAL_ALIGN_BOTTOM) self.__imgDecoration.Show() _BoardBase._CreateUI(self) self.__wndTitleBar = None def SetSize(self, width, height): _BoardBase.SetSize(self, width, height) self.__imgDecoration.SetPosition(-5, 52) self.UpdateTitleBar() if self.__hasShadow: self.UpdateShadow() ## TitleBar def AddTitleBar(self): self.__wndTitleBar = TitleBar() self.__wndTitleBar.SetParent(self) self.__wndTitleBar.SetPosition(9, 11) self.__wndTitleBar.Show() self.UpdateTitleBar() def GetTitleBar(self): return self.__wndTitleBar def UpdateTitleBar(self): if not self.__wndTitleBar: return self.__wndTitleBar.SetWidth(self.GetWidth() - 18) ## Shadow def __CreateShadow(self): self.__wndShadow = Board._Shadow() self.__wndShadow.SetParent(self) self.__wndShadow.SetPosition(-self.__shadowSize, -self.__shadowSize) self.__wndShadow.Show() self.__wndShadow.SetOpacity(0.0) def UpdateShadow(self): self.__wndShadow.SetSize(self.GetWidth() + self.__shadowSize * 2, self.GetHeight() + self.__shadowSize * 2) def GetShadow(self): return self.__wndShadow