コード例 #1
0
ファイル: slider.py プロジェクト: wty0512/micropylis
 def size(self, dialog):
     """
     Creates slider components.
     """
     if dialog is None:
         return
     Control.size(self, dialog)
     if self.is_disabled():
         color = dialog.theme['slider']['disabled_color']
     else:
         color = dialog.theme['slider']['gui_color']
     if self.bar is None:
         path = self.IMAGE_BAR
         self.bar = dialog.theme[path]['image'].generate(
             color, dialog.batch, dialog.bg_group)
         self.padding = dialog.theme[path]['padding']
     if self.knob is None:
         path = self.IMAGE_KNOB
         self.knob = dialog.theme[path]['image'].generate(
             color, dialog.batch, dialog.highlight_group)
         self.offset = dialog.theme[path]['offset']
     if not self.markers and self.steps is not None:
         path = self.IMAGE_STEP
         for n in xrange(0, self.steps + 1):
             self.markers.append(dialog.theme[path]['image'].generate(
                 color, dialog.batch, dialog.fg_group))
         self.step_offset = dialog.theme[path]['offset']
     width, height = self.bar.get_needed_size(self.min_width, 0)
     left, right, top, bottom = self.padding
     self.width = width + left + right
     self.height = height + top + bottom
コード例 #2
0
ファイル: document.py プロジェクト: AngelFishy/Kytten
    def size(self, dialog):
        if dialog is None:
            return

        Control.size(self, dialog)
        if not self.set_document_style:
            self.do_set_document_style(dialog)
        if self.content is None:
            self.content = pyglet.text.layout.IncrementalTextLayout(
                self.document,
                self.content_width,
                self.max_height,
                multiline=True, batch=dialog.batch, group=dialog.fg_group)
            if self.is_fixed_size or (self.max_height and
                self.content.content_height > self.max_height):
                self.height = self.max_height
            else:
                self.height = self.content.content_height
            self.content.height = self.height
        if self.always_show_scrollbar or \
           (self.max_height and self.content.content_height > self.max_height):
            if self.scrollbar is None:
                self.scrollbar = VScrollbar(self.max_height)
            self.scrollbar.size(dialog)
            self.scrollbar.set(self.max_height, self.content.content_height)
        if self.scrollbar is not None:
            self.width = self.content_width + self.scrollbar.width
        else:
            self.width = self.content_width
コード例 #3
0
    def size(self, dialog):
        if dialog is None:
            return
        Control.size(self, dialog)

        if self.is_disabled():
            color = dialog.theme['dropdown']['disabled_color']
        else:
            color = dialog.theme['dropdown']['gui_color']

        if self.field is None:
            self.field = dialog.theme['dropdown']['image'].generate(
                color, dialog.batch, dialog.bg_group)
        if self.label is None:
            self.label = KyttenLabel(
                self.selected,
                font_name=dialog.theme['dropdown']['font'],
                font_size=dialog.theme['dropdown']['font_size'],
                color=dialog.theme['dropdown']['text_color'],
                batch=dialog.batch,
                group=dialog.fg_group)
        font = self.label.document.get_font()
        height = font.ascent - font.descent
        self.width, self.height = self.field.get_needed_size(
            self.label.content_width, height)
コード例 #4
0
ファイル: scrollbar.py プロジェクト: wty0512/micropylis
    def size(self, dialog):
        """
        Creates scrollbar components.
        """
        if dialog is None:
            return
        Control.size(self, dialog)
        dialog.set_wheel_hint(self)
        if self.left is None:
            if self.pos > 0.0:
                path = self.IMAGE_LEFT
            else:
                path = self.IMAGE_LEFTMAX
            self.left = dialog.theme[path]['image'].generate(
                dialog.theme[path]['gui_color'], dialog.batch, dialog.fg_group)

            # Left button is our basis for minimum dimension
            self.width, self.height = self.left.width, self.left.height
        if self.space is None:
            path = self.IMAGE_SPACE
            self.space = dialog.theme[path]['image'].generate(
                dialog.theme[path]['gui_color'], dialog.batch, dialog.fg_group)
        if self.bar is None:
            path = self.IMAGE_BAR
            self.bar = dialog.theme[path]['image'].generate(
                dialog.theme[path]['gui_color'], dialog.batch, dialog.fg_group)
        if self.right is None:
            if self.pos < 1.0 - self.bar_width:
                path = self.IMAGE_RIGHT
            else:
                path = self.IMAGE_RIGHTMAX
            self.right = dialog.theme[path]['image'].generate(
                dialog.theme[path]['gui_color'], dialog.batch, dialog.fg_group)
コード例 #5
0
    def size(self, dialog):
        if dialog is None:
            return

        Control.size(self, dialog)
        if not self.set_document_style:
            self.do_set_document_style(dialog)
        if self.content is None:
            self.content = pyglet.text.layout.IncrementalTextLayout(
                self.document,
                self.content_width,
                self.max_height,
                multiline=True,
                batch=dialog.batch,
                group=dialog.fg_group)
            if self.is_fixed_size or (
                    self.max_height
                    and self.content.content_height > self.max_height):
                self.height = self.max_height
            else:
                self.height = self.content.content_height
            self.content.height = self.height
        if self.always_show_scrollbar or \
           (self.max_height and self.content.content_height > self.max_height):
            if self.scrollbar is None:
                self.scrollbar = VScrollbar(self.max_height)
            self.scrollbar.size(dialog)
            self.scrollbar.set(self.max_height, self.content.content_height)
        if self.scrollbar is not None:
            self.width = self.content_width + self.scrollbar.width
        else:
            self.width = self.content_width
コード例 #6
0
ファイル: slider.py プロジェクト: AngelFishy/Kytten
 def size(self, dialog):
     """
     Creates slider components.
     """
     if dialog is None:
         return
     Control.size(self, dialog)
     if self.is_disabled():
         color = dialog.theme['slider']['disabled_color']
     else:
         color = dialog.theme['slider']['gui_color']
     if self.bar is None:
         path = self.IMAGE_BAR
         self.bar = dialog.theme[path]['image'].generate(
             color,
             dialog.batch, dialog.bg_group)
         self.padding = dialog.theme[path]['padding']
     if self.knob is None:
         path = self.IMAGE_KNOB
         self.knob = dialog.theme[path]['image'].generate(
             color,
             dialog.batch, dialog.highlight_group)
         self.offset = dialog.theme[path]['offset']
     if not self.markers and self.steps is not None:
         path = self.IMAGE_STEP
         for n in xrange(0, self.steps + 1):
             self.markers.append(
                 dialog.theme[path]['image'].generate(
                     color,
                     dialog.batch, dialog.fg_group))
         self.step_offset = dialog.theme[path]['offset']
     width, height = self.bar.get_needed_size(self.min_width, 0)
     left, right, top, bottom = self.padding
     self.width = width + left + right
     self.height = height + top + bottom
コード例 #7
0
    def size(self, dialog):
        """
        Sizes the Checkbox.  If necessary, creates the graphic elements.

        @param dialog Dialog which contains the Checkbox
        """
        if dialog is None:
            return
        Control.size(self, dialog)
        if self.is_checked:
            path = ['checkbox', 'checked']
        else:
            path = ['checkbox', 'unchecked']
        if self.is_disabled():
            color = dialog.theme[path]['disabled_color']
        else:
            color = dialog.theme[path]['gui_color']
        if self.checkbox is None:
            self.checkbox = dialog.theme[path]['image'].generate(
                color,
                dialog.batch, dialog.bg_group)
        if self.highlight is None and self.is_highlight():
            self.highlight = dialog.theme[path]['highlight']['image'].generate(
                    dialog.theme[path]['highlight_color'],
                    dialog.batch,
                    dialog.bg_group)
        if self.label is None:
            self.label = KyttenLabel(self.text,
                font_name=dialog.theme[path]['font'],
                font_size=dialog.theme[path]['font_size'],
                color=color,
                batch=dialog.batch, group=dialog.fg_group)

        # Treat the height of the label as ascent + descent
        font = self.label.document.get_font()
        height = font.ascent - font.descent  # descent is negative
        self.width = self.checkbox.width + self.padding + \
            self.label.content_width
        self.height = max(self.checkbox.height, height)
コード例 #8
0
    def size(self, dialog):
        """
        Sizes the Button.  If necessary, creates the graphic elements.

        @param dialog Dialog which contains the Button
        """
        if dialog is None:
            return
        Control.size(self, dialog)
        if self.is_pressed:
            path = ['button', 'down']
        else:
            path = ['button', 'up']
        if self.is_disabled():
            color = dialog.theme[path]['disabled_color']
        else:
            color = dialog.theme[path]['gui_color']
        if self.button is None:
            self.button = dialog.theme[path]['image'].generate(
                color, dialog.batch, dialog.bg_group)
        if self.highlight is None and self.is_highlight():
            self.highlight = dialog.theme[path]['highlight']['image'].\
                generate(dialog.theme[path]['highlight_color'],
                         dialog.batch,
                         dialog.bg_group)
        if self.label is None:
            self.label = KyttenLabel(self.text,
                                     font_name=dialog.theme[path]['font'],
                                     font_size=dialog.theme[path]['font_size'],
                                     color=dialog.theme[path]['text_color'],
                                     batch=dialog.batch,
                                     group=dialog.fg_group)

        # Treat the height of the label as ascent + descent
        font = self.label.document.get_font()
        height = font.ascent - font.descent  # descent is negative
        self.width, self.height = self.button.get_needed_size(
            self.label.content_width, height)
コード例 #9
0
ファイル: button.py プロジェクト: AngelFishy/Kytten
    def size(self, dialog):
        """
        Sizes the Button.  If necessary, creates the graphic elements.

        @param dialog Dialog which contains the Button
        """
        if dialog is None:
            return
        Control.size(self, dialog)
        if self.is_pressed:
            path = ['button', 'down']
        else:
            path = ['button', 'up']
        if self.is_disabled():
            color = dialog.theme[path]['disabled_color']
        else:
            color = dialog.theme[path]['gui_color']
        if self.button is None:
            self.button = dialog.theme[path]['image'].generate(
                color,
                dialog.batch, dialog.bg_group)
        if self.highlight is None and self.is_highlight():
            self.highlight = dialog.theme[path]['highlight']['image'].\
                generate(dialog.theme[path]['highlight_color'],
                         dialog.batch,
                         dialog.bg_group)
        if self.label is None:
            self.label = KyttenLabel(self.text,
                font_name=dialog.theme[path]['font'],
                font_size=dialog.theme[path]['font_size'],
                color=dialog.theme[path]['text_color'],
                batch=dialog.batch, group=dialog.fg_group)

        # Treat the height of the label as ascent + descent
        font = self.label.document.get_font()
        height = font.ascent - font.descent # descent is negative
        self.width, self.height = self.button.get_needed_size(
            self.label.content_width, height)
コード例 #10
0
ファイル: checkbox.py プロジェクト: wty0512/micropylis
    def size(self, dialog):
        """
        Sizes the Checkbox.  If necessary, creates the graphic elements.

        @param dialog Dialog which contains the Checkbox
        """
        if dialog is None:
            return
        Control.size(self, dialog)
        if self.is_checked:
            path = ['checkbox', 'checked']
        else:
            path = ['checkbox', 'unchecked']
        if self.is_disabled():
            color = dialog.theme[path]['disabled_color']
        else:
            color = dialog.theme[path]['gui_color']
        if self.checkbox is None:
            self.checkbox = dialog.theme[path]['image'].generate(
                color, dialog.batch, dialog.bg_group)
        if self.highlight is None and self.is_highlight():
            self.highlight = dialog.theme[path]['highlight']['image'].generate(
                dialog.theme[path]['highlight_color'], dialog.batch,
                dialog.bg_group)
        if self.label is None:
            self.label = KyttenLabel(self.text,
                                     font_name=dialog.theme[path]['font'],
                                     font_size=dialog.theme[path]['font_size'],
                                     color=color,
                                     batch=dialog.batch,
                                     group=dialog.fg_group)

        # Treat the height of the label as ascent + descent
        font = self.label.document.get_font()
        height = font.ascent - font.descent  # descent is negative
        self.width = self.checkbox.width + self.padding + \
            self.label.content_width
        self.height = max(self.checkbox.height, height)
コード例 #11
0
ファイル: scrollbar.py プロジェクト: AngelFishy/Kytten
    def size(self, dialog):
        """
        Creates scrollbar components.
        """
        if dialog is None:
            return
        Control.size(self, dialog)
        dialog.set_wheel_hint(self)
        if self.left is None:
            if self.pos > 0.0:
                path = self.IMAGE_LEFT
            else:
                path = self.IMAGE_LEFTMAX
            self.left = dialog.theme[path]['image'].generate(
                dialog.theme[path]['gui_color'],
                dialog.batch, dialog.fg_group)

            # Left button is our basis for minimum dimension
            self.width, self.height = self.left.width, self.left.height
        if self.space is None:
            path = self.IMAGE_SPACE
            self.space = dialog.theme[path]['image'].generate(
                dialog.theme[path]['gui_color'],
                dialog.batch, dialog.fg_group)
        if self.bar is None:
            path = self.IMAGE_BAR
            self.bar = dialog.theme[path]['image'].generate(
                dialog.theme[path]['gui_color'],
                dialog.batch, dialog.fg_group)
        if self.right is None:
            if self.pos < 1.0 - self.bar_width:
                path = self.IMAGE_RIGHT
            else:
                path = self.IMAGE_RIGHTMAX
            self.right = dialog.theme[path]['image'].generate(
                dialog.theme[path]['gui_color'],
                dialog.batch, dialog.fg_group)
コード例 #12
0
ファイル: menu.py プロジェクト: isS/sy-game
    def size(self, dialog):
        if dialog is None:
            return
        Control.size(self, dialog)
        if self.is_selected:
            path = ['menuoption', 'selection']
        else:
            path = ['menuoption']
        if self.label is None:
            if self.is_disabled():
                color = dialog.theme[path]['disabled_color']
            else:
                color = dialog.theme[path]['text_color']
            self.label = KyttenLabel(self.text,
                color=color,
                font_name=dialog.theme[path]['font'],
                font_size=dialog.theme[path]['font_size'],
                batch=dialog.batch,
                group=dialog.fg_group)
            font = self.label.document.get_font()
            self.width = self.label.content_width
            self.height = font.ascent - font.descent

        if self.background is None:
            if self.is_selected:
                self.background = \
                    dialog.theme[path]['highlight']['image'].generate(
                        dialog.theme[path]['gui_color'],
                        dialog.batch,
                        dialog.bg_group)
        if self.highlight is None:
            if self.is_highlight():
                self.highlight = \
                    dialog.theme[path]['highlight']['image'].generate(
                        dialog.theme[path]['highlight_color'],
                        dialog.batch,
                        dialog.highlight_group)
コード例 #13
0
    def size(self, dialog):
        if dialog is None:
            return
        Control.size(self, dialog)
        if self.is_selected:
            path = ['menuoption', 'selection']
        else:
            path = ['menuoption']
        if self.label is None:
            if self.is_disabled():
                color = dialog.theme[path]['disabled_color']
            else:
                color = dialog.theme[path]['text_color']
            self.label = KyttenLabel(self.text,
                                     color=color,
                                     font_name=dialog.theme[path]['font'],
                                     font_size=dialog.theme[path]['font_size'],
                                     batch=dialog.batch,
                                     group=dialog.fg_group)
            font = self.label.document.get_font()
            self.width = self.label.content_width + self.option_padding_x
            self.height = font.ascent - font.descent + self.option_padding_y

        if self.background is None:
            if self.is_selected:
                self.background = \
                    dialog.theme[path]['highlight']['image'].generate(
                        dialog.theme[path]['gui_color'],
                        dialog.batch,
                        dialog.bg_group)
        if self.highlight is None:
            if self.is_highlight():
                self.highlight = \
                    dialog.theme[path]['highlight']['image'].generate(
                        dialog.theme[path]['highlight_color'],
                        dialog.batch,
                        dialog.highlight_group)
コード例 #14
0
ファイル: menu.py プロジェクト: isS/sy-game
    def size(self, dialog):
        if dialog is None:
            return
        Control.size(self, dialog)

        if self.is_disabled():
            color = dialog.theme['dropdown']['disabled_color']
        else:
            color = dialog.theme['dropdown']['gui_color']

        if self.field is None:
            self.field = dialog.theme['dropdown']['image'].generate(
                color,
                dialog.batch, dialog.bg_group)
        if self.label is None:
            self.label = KyttenLabel(self.selected,
                font_name=dialog.theme['dropdown']['font'],
                font_size=dialog.theme['dropdown']['font_size'],
                color=dialog.theme['dropdown']['text_color'],
                batch=dialog.batch, group=dialog.fg_group)
        font = self.label.document.get_font()
        height = font.ascent - font.descent
        self.width, self.height = self.field.get_needed_size(
            self.label.content_width, height)
コード例 #15
0
ファイル: text_input.py プロジェクト: chrisbiggar/micropylis
    def size(self, dialog):
        if dialog is None:
            return
        Control.size(self, dialog)

        if self.is_disabled():
            color = dialog.theme['input']['disabled_color']
        else:
            color = dialog.theme['input']['text_color']

        # We set the style once.  We shouldn't have to do so again because
        # it's an UnformattedDocument.
        if not self.document_style_set:
            self.document.set_style(0, len(self.document.text),
                                    dict(color=color,
                                         font_name=dialog.theme['font'],
                                         font_size=dialog.theme['font_size']))
            self.document_style_set = True

        # Calculate the needed size based on the font size
        font = self.document.get_font(0)
        height = font.ascent - font.descent
        glyphs = font.get_glyphs('A_')
        width = max([x.width for x in glyphs])
        if self.abs_width == 0:
            needed_width = self.length * width + 2 * self.padding
        else:
            needed_width = self.abs_width
        needed_height = height + 2 * self.padding

        if self.is_focus():
            if self.text_layout is None:
                self.text_layout = pyglet.text.layout.IncrementalTextLayout(
                    self.document, needed_width, needed_height,
                    multiline=False,
                    batch=dialog.batch, group=dialog.fg_group)
                assert self.caret is None
            assert self.label is None
            if self.caret is None:
                self.caret = pyglet.text.caret.Caret(
                    self.text_layout,
                    color=dialog.theme['input']['gui_color'][0:3])
                self.caret.visible = True
                self.caret.mark = 0
                self.caret.position = len(self.document.text)
        else:
            if self.label is None:
                self.label = KyttenInputLabel(self.document.text,
                                              multiline=False,
                                              width=self.width-self.padding*2,
                                              color=color,
                                              batch=dialog.batch,
                                              group=dialog.fg_group)
            assert self.text_layout is None and self.caret is None
        if self.field is None:
            if self.is_disabled():
                color = dialog.theme['input']['disabled_color']
            else:
                color = dialog.theme['input']['gui_color']
            self.field = dialog.theme['input']['image'].generate(
                color=color,
                batch=dialog.batch,
                group=dialog.bg_group)
        if self.highlight is None and self.is_highlight():
            self.set_highlight()

        self.width, self.height = self.field.get_needed_size(
            needed_width, needed_height)