Exemple #1
0
 def __init__(self, position: Point, width=0, height=0, back_color=(0, 0, 0)):
     self._position = position
     self._sprite = None
     self.alignment = AlignStyle.NONE
     self._anchors = self.ANCHOR_LEFT
     self.visible = True
     self.flag = False
     self.margin = Margin()
     self._parent = None
     self.activated = False
     self.centeredly_drawn = False
     self._width = width
     self._anc_dist = Margin()
     self._height = height
     self.region = RectangularRegion(position, position + Point(width, 0),
                                     position + Point(width, height),
                                     position + Point(0, height))
     self.click_event = Event(self)
     self.click = Event(self)
     self.released = Event(self)
     self.double_clicked = Event(self)
     self.mouse_press = Event(self)
     self.mouse_motion = Event(self)
     self.mouse_enter = Event(self)
     self.mouse_leave = Event(self)
     self._dock = DockStyle.NONE
     self._mouse_down = False
     self._opacity = 255
     self._mouse_enter = False
     self._mouse_enter_time = 0
     self._color = (0, 0, 0)
     self.fore_color = self._color
     self.back_color = back_color
Exemple #2
0
 def align_center(self):
     if self._parent is not None:
         if self.alignment & AlignStyle.AlignXStyle.CENTER:
             self.position = Point(self.parent.width // 2 - self.width // 2,
                                   self.position.y)
  
         if self.alignment & AlignStyle.AlignYStyle.MIDDLE:
             self.position = Point(self.position.x,
                                   self.parent.height // 2 - self.height // 2)
Exemple #3
0
 def _align_to_anchors(self):
     if self.parent is not None:
         translated_x = self.parent.width - self._anc_dist.right - self.width + self.parent.position.x
         translated_y = self.parent.height - self._anc_dist.top - self.height + self.parent.position.y
         if self.anchors & self.ANCHOR_RIGHT:
             self.position = Point(translated_x, self.position.y)
         if self.anchors & self.ANCHOR_TOP:
             # self.position = Point(self.position.x, (self.parent.height) - self._anc_dist.top)
             self.position = Point(self.position.x, translated_y)
Exemple #4
0
 def _realign(self):
     if self.parent is not None:
         if self.alignment & AlignStyle.AlignXStyle.RIGHT:
             self.position = Point(self.parent.position.x + self.parent.width - self.width - self.margin.right, self.position.y)
         if self.alignment & AlignStyle.AlignYStyle.TOP:
             self.position = Point(self.position.x, self.parent.position.y + self.parent.height - self.height - self.margin.top)
         if self.alignment & AlignStyle.AlignYStyle.MIDDLE:
             self.position.y = self.parent.position.y + (self.parent.height//2) - self.height
         if self.alignment & AlignStyle.AlignYStyle.BOTTOM:
             self.position = Point(self.position.x, self.parent.position.y + self.margin.bottom)
    def init_scrolling_button(self):
        x, y = self.width - self.spacing, 0
        self._btn_next = Button(Point(x, y),
                                "assets/images/ui/Next_button.png", height=75,
                                width=20)
        self._btn_next.click_event += self.on_next
        self._btn_next.visible = False

        self._btn_prev = Button(Point(0, 0),
                                "assets/images/ui/Prev_button.png", height=75,
                                width=20)
        self._btn_prev.click_event += self.on_prev
        self._btn_prev.visible = False
        self.add_child(self._btn_next)
        self.add_child(self._btn_prev)
Exemple #6
0
 def __init__(self,
              position: Point = Point(0, 0),
              text: str = "",
              size: int = 12,
              color: tuple = arcade.color.BLACK,
              align: AlignStyle = AlignStyle.NONE,
              font_name=('calibri', 'arial'),
              cached=False):
     super().__init__(position)
     self.__label__ = pyglet.text.Label(text,
                                        font_size=size,
                                        x=position.x,
                                        y=position.y)
     self.alignment = align
     self._text = text
     r, g, b = color
     self._color = color
     self.fore_color = (r, g, b, self.opacity)
     self._font_name = font_name
     self.__font_size__ = size
     self.cached = cached
     self.blur_factor = 0
     self.width, self.height = PILText.determine_dimensions(self, self.text)
     if self.cached and self.visible:
         self.set_cached_sprite(
             PILText.render_text(self.text,
                                 self.position.x,
                                 self.position.y,
                                 self.fore_color,
                                 self.font_size,
                                 font_name=self.font_name,
                                 align=self._get_text_alignment(),
                                 width=self.width,
                                 anchor_x=self._get_anchors_x(),
                                 anchor_y=self._get_anchors_y()))
 def on_animated(self, *args):
     self._menu_container.position = Point(self._menu_container.position.x, self.position.y - self._menu_container.height + 1)
     for item in self.__items__:
         if item.position.y > self._menu_container.position.y + self._menu_container.height:
             item.visible = False
         else:
             item.visible = True
Exemple #8
0
 def translate_relative(self, control):
     offset = 0, 0
     if self.centeredly_drawn:
         offset = self.width // 2, self.height // 2
     control.position = Point(
         control.position.x + self.position.x - offset[0] +
         self.padding.left, control.position.y + self.position.y -
         offset[1] + self.padding.bottom)
 def __init__(self, position: Point=Point(0,0), width: int=75,
              height: int=500, model: object=None,
              color: tuple=arcade.color.AMARANTH_PURPLE):
     super().__init__(position, width, height, color)
     self.model = model
     self.caption = Label
     self.tooltip = None
     self._generate_from_model()
Exemple #10
0
 def on_mouse_press(self, *args):
     x, y, btn, modifiers = tuple(args[-4:])
     self.mouse_press(*args)
     if self.region.is_point_inside(Point(x, y)) and self.visible:
         self._mouse_down = True
         self.activated = True
         self.click_event(*args)
         self.click(*args)
     else:
         self.activated = False
Exemple #11
0
 def on_mouse_motion(self, *args):
     self.mouse_motion(*args)
     x, y, dx, dy = tuple(args[-4:])
     if self.region.is_point_inside(Point(x, y)) and self.visible:
         if not self._mouse_enter:
             self.mouse_enter(*args)
             self._mouse_enter = True          
             self._mouse_enter_time = time.time()
     else:
         if self._mouse_enter:
             self._mouse_enter = False
             self.mouse_leave(*args)
 def __init__(self, position, width, height, item_height=75, font_size=14):
     super().__init__(position, width, height)
     AnimatedControl.__init__(self)
     self.padding = Padding(20, 10, 10, 10)
     self._item_height = item_height
     self._menu_container = Container(Point(0, 0), color=arcade.color.COPPER_ROSE)
     self._menu_height = DropdownMenu.DEFAULT_ITEM_LIMIT*75
     _chevron_origin = Point(self.position.x + 50, self.position.y + 50)
     _chevron_p2 = Point(self.position.x + 50, self.position.y + 50) + Point(10, 0)
     _chevron_p3 = Point(_chevron_p2.x + _chevron_origin.x // 2, self.position.y)
     # self._chevron = arcade.create_triangles_filled_with_colors([_chevron_p2, _chevron_p3, _chevron_origin], [(255, 255, 255)])
     self.caption = LocalizedLabel(Point(0, 0), size=font_size, custom_font=True)
     self.caption.font_name = "assets/fonts/Roboto-Medium"
     self.caption.fore_color = arcade.color.WHITE
     self.add_child(self.caption)
     self._menu_open = False
     self._shown_items = []
     self.click_event += self.on_click
     self._resize_menu()
     self.duration = 0.75
     self.selected_index_changed_event += self.on_selected_index_change
     self._extra_spacing = 5
Exemple #13
0
 def on_mouse_enter(self, *args):
     x, y, dx, dy = args[-4], args[-3], args[-2], args[-1]
     self.position = Point(x, y)
     self._mouse_enter_time = time.time()
     self._triggered = True
Exemple #14
0
 def set_vertical_position(self, y):
     self.set_position(Point(self.position.x, y))
Exemple #15
0
 def translate_controls(self, x, y):
     dx, dy = x - self.position.x, y - self.position.y
     for c in self.children:
         c.position = Point(c.position.x + dx, c.position.y + dy)
         c.reset_region()
 def _resize_menu(self):
     self._menu_container.width = self.width
     self._menu_container.height = 0
     self._menu_container.position = Point(self.position.x, self.position.y + 1)
     self._menu_container.visible = False
Exemple #17
0
 def reset_region(self):
     self.region = RectangularRegion(self.position,
                                     self.position + Point(self.width, 0),
                                     self.position + Point(self.width,
                                                           self.height),
                                     self.position + Point(0, self.height))
Exemple #18
0
 def set_region_from_center(self):
     x, y = self.position.x - (self.width / 2), self.position.y - (self.height / 2)
     position = Point(x, y)
     self.region = RectangularRegion(position, position + Point(self.width, 0),
                                     position + Point(self.width, self.height),
                                     position + Point(0, self.height))