Beispiel #1
0
Datei: ui.py Projekt: rdb/hexima
class LevelButton:
    font = None

    def __init__(self,
                 parent,
                 number=1,
                 pos=(0, 0),
                 command=None,
                 extraArgs=[],
                 locked=False):
        text = '⚀⚁⚂⚃⚄⚅'[number - 1]
        self.path = DirectButton(parent=parent.path,
                                 text_fg=UI_COLOR,
                                 text_font=base.symbol_font,
                                 relief=None,
                                 text=text,
                                 scale=0.07,
                                 text_scale=2,
                                 pos=(pos[0], 0, pos[1]),
                                 command=command,
                                 extraArgs=extraArgs)

        #text = ''[number - 1]
        #self.path = DirectButton(parent=parent.path, text_fg=UI_COLOR, text_font=self.font, relief=None, text=text, scale=0.07, pos=(pos[0], 0, pos[1]))
        self.path.set_shader_off(1)
        self.path.set_color_scale_off(1)

        self.badge = None
        if locked:
            self.path.set_color_scale((1, 1, 1, 0.5))
            self.set_badge('')

    def set_badge(self, icon, style='solid', color=UI_COLOR):
        if self.badge:
            self.badge.destroy()

        font = base.icon_fonts[style]
        self.badge = OnscreenText(parent=self.path,
                                  text=icon,
                                  font=font,
                                  scale=0.6,
                                  pos=(0.28, -0.08),
                                  fg=UI_COLOR)
        self.badge.set_color_scale(color, 2)
Beispiel #2
0
Datei: ui.py Projekt: rdb/hexima
class Button:
    def __init__(self,
                 parent,
                 text="",
                 pos=(0, 0),
                 size=(0.4, 0.2),
                 command=None,
                 extraArgs=[],
                 icon=None,
                 icon_style='solid',
                 disabled=False,
                 anchor=None):
        parent_path = parent.path if anchor is None else parent.anchors[anchor]

        #frame = (-size[0] * 0.5, size[0] * 0.5, -size[1] * 0.5, size[1] * 0.5)
        frame = (-0.15, 0.25 if icon else 0.15, -0.03, 0.08)
        self.path = DirectButton(parent=parent_path,
                                 text_fg=UI_COLOR,
                                 relief=None,
                                 frameSize=frame,
                                 text=text,
                                 text_scale=0.09,
                                 pos=(pos[0], 0, pos[1]),
                                 command=command,
                                 extraArgs=extraArgs)
        #generate_border(self.path, frame)

        if disabled:
            self.path['state'] = DGG.DISABLED

        if icon is not None:
            self.icon_pivot = self.path.attach_new_node('pivot')
            self.icon_pivot.set_pos(-0.1, 0, 0.025)
            font = base.icon_fonts[icon_style]
            text = OnscreenText(parent=self.icon_pivot,
                                text=icon,
                                fg=(1, 1, 1, 1),
                                font=font,
                                align=core.TextNode.A_center,
                                scale=0.07,
                                pos=(-0.002, -0.025))
        else:
            self.icon_pivot = None

        self.path.bind('enter-', self.on_focus)
        self.path.bind('exit-', self.on_blur)
        self.path.bind('fin-', self.on_focus)
        self.path.bind('fout-', self.on_blur)

        self.path.set_shader_off(1)

        self.path.set_color_scale((1, 1, 1, 0.6))

        parent._child_item_added(self.path)

    def set_text(self, text):
        self.path['text'] = text

    def focus(self):
        self.path.guiItem.set_focus(True)

    def enable(self):
        self.path['state'] = DGG.NORMAL

    def disable(self):
        self.path['state'] = DGG.DISABLED

    def on_focus(self, param=None):
        if self.icon_pivot is not None:
            self.icon_pivot.hprInterval(0.2, (0, 0, 360),
                                        blendType='easeInOut').start()

        self.path.colorScaleInterval(0.2, (1, 1, 1, 1),
                                     blendType='easeInOut').start()
        self.path.guiItem.set_state(2)

    def on_blur(self, param=None):
        if self.icon_pivot is not None:
            self.icon_pivot.hprInterval(0.2, (0, 0, 0),
                                        blendType='easeInOut').start()

        self.path.colorScaleInterval(0.2, (1, 1, 1, 0.6),
                                     blendType='easeInOut').start()
        self.path.guiItem.set_state(0)