def add_baseimage(self, x: NumberType, y: NumberType, image: 'pygame_menu.BaseImage', prev: bool = True, centered: bool = False, **kwargs) -> str: """ Adds a :py:class:`pygame_menu.baseimage.BaseImage` object. .. note:: If your :py:class:`pygame_menu.baseimage.BaseImage` object changes over time set ``decorator.cache=False`` or force cache manually by calling :py:meth:`pygame_menu._decorator.Decorator.force_cache_update`. kwargs (Optional) - ``use_center_positioning`` (bool) – Uses object center position as *(0, 0)*. ``True`` by default :param x: X position in px, being ``0`` the center of the object :param y: Y position in px, being ``0`` the center of the object :param image: ``BaseImage`` object :param prev: If ``True`` draw previous the object, else draws post :param centered: If ``True`` the image is centered :param kwargs: Optional keyword arguments :return: ID of the decoration """ coords = [(x, y)] assert_list_vector(coords, 2) assert isinstance(image, pygame_menu.BaseImage) return self._add_decor(DECORATION_BASEIMAGE, prev, (tuple(coords), image, centered, kwargs))
def add_ellipse(self, x: NumberType, y: NumberType, rx: NumberType, ry: NumberType, color: ColorInputType, filled: bool, prev: bool = True, **kwargs) -> str: """ Adds an ellipse. kwargs (Optional) - ``use_center_positioning`` (bool) – Uses object center position as *(0, 0)*. ``True`` by default :param x: X position in px, being ``0`` the center of the object :param y: Y position in px, being ``0`` the center of the object :param rx: Horizontal radius of the ellipse :param ry: Vertical radius of the ellipse :param color: Color of the polygon :param filled: If ``True`` fills the polygon with the given color :param prev: If ``True`` draw previous the object, else draws post :param kwargs: Optional keyword arguments :return: ID of the decoration """ coords = [(x, y)] assert_list_vector(coords, 2) color = assert_color(color) assert isinstance(rx, NumberInstance) and rx > 0 assert isinstance(ry, NumberInstance) and ry > 0 assert isinstance(filled, bool) return self._add_decor(DECORATION_ELLIPSE, prev, (tuple(coords), rx, ry, color, filled, kwargs))
def add_pie(self, x: NumberType, y: NumberType, radius: NumberType, init_angle: NumberType, final_angle: NumberType, color: ColorType, prev: bool = True) -> str: """ Add a unfilled pie. :param x: X position (px), being ``0`` the center of the object :param y: Y position (px), being ``0`` the center of the object :param radius: Circle radius (px) :param init_angle: Initial angle in degrees ``(0-360)`` :param final_angle: Final angle in degrees ``(0-360)`` :param color: Color of the polygon :param prev: If ``True`` draw previous the object, else draws post :return: ID of the decoration """ coords = [(x, y)] assert_list_vector(coords, 2) assert_color(color) assert isinstance(radius, (int, float)) and radius > 0 assert isinstance(init_angle, (int, float)) assert isinstance(final_angle, (int, float)) assert init_angle != final_angle return self._add_decor( DECORATION_PIE, prev, (tuple(coords), int(radius), init_angle, final_angle, color))
def add_pie(self, x: NumberType, y: NumberType, radius: NumberType, init_angle: NumberType, final_angle: NumberType, color: ColorInputType, prev: bool = True, **kwargs) -> str: """ Adds a unfilled pie. kwargs (Optional) - ``use_center_positioning`` (bool) – Uses object center position as *(0, 0)*. ``True`` by default :param x: X position in px, being ``0`` the center of the object :param y: Y position in px, being ``0`` the center of the object :param radius: Circle radius in px :param init_angle: Initial angle in degrees, from ``0`` to ``360`` :param final_angle: Final angle in degrees, from ``0`` to ``360`` :param color: Color of the polygon :param prev: If ``True`` draw previous the object, else draws post :param kwargs: Optional keyword arguments :return: ID of the decoration """ coords = [(x, y)] assert_list_vector(coords, 2) color = assert_color(color) assert isinstance(radius, NumberInstance) and radius > 0 assert isinstance(init_angle, NumberInstance) assert isinstance(final_angle, NumberInstance) assert init_angle != final_angle return self._add_decor(DECORATION_PIE, prev, (tuple(coords), int(radius), init_angle, final_angle, color, kwargs))
def add_bezier( self, coords: Union[List[Tuple2NumberType], Tuple[Tuple2NumberType, ...]], color: ColorInputType, steps: int = 5, prev: bool = True, **kwargs ) -> str: """ Add bezier curve. .. note:: Consider ``(0, 0)`` coordinates as the center of the object. kwargs (Optional) - ``use_center_positioning`` Uses object center position as *(0, 0)*. ``True`` by default :param coords: Coordinate list, being ``(0, 0)`` the center of the object :param color: Color of the polygon :param steps: Interpolation steps :param prev: If ``True`` draw previous the object, else draws post :param kwargs: Optional keyword arguments :return: ID of the decoration """ assert_list_vector(coords, 2) color = assert_color(color) assert len(coords) >= 3 assert isinstance(steps, int) and steps >= 1 return self._add_decor(DECORATION_BEZIER, prev, (tuple(coords), color, steps, kwargs))
def add_text(self, x: NumberType, y: NumberType, text: str, font: Union[str, 'Font', 'Path'], size: int, color: ColorType, prev: bool = True, antialias=True, centered=False) -> str: """ Adds a text. :param x: X position (px), being ``0`` the center of the object :param y: Y position (px), being ``0`` the center of the object :param text: Text to draw :param font: Font path or pygame object :param size: Size of the font to render :param color: Font color :param prev: If ``True`` draw previous the object, else draws post :param antialias: Font antialias enabled :param centered: If ``True`` the text is centered into the position :return: ID of the decoration """ coords = [(x, y)] assert_list_vector(coords, 2) text = str(text) font_obj = pygame_menu.font.get_font(font, size) surface_font = font_obj.render(text, antialias, color) surface = make_surface( width=surface_font.get_width(), height=surface_font.get_height(), alpha=True ) surface.blit(surface_font, (0, 0)) return self._add_decor(DECORATION_TEXT, prev, (tuple(coords), surface, centered))
def add_arc(self, x: NumberType, y: NumberType, radius: NumberType, init_angle: NumberType, final_angle: NumberType, color: ColorType, width: int = 0, prev: bool = True, gfx: bool = True) -> str: """ Add arc. :param x: X position (px), being ``0`` the center of the object :param y: Y position (px), being ``0`` the center of the object :param radius: Circle radius (px) :param init_angle: Initial angle in degrees ``(0-360)`` :param final_angle: Final angle in degrees ``(0-360)`` :param color: Color of the polygon :param width: Line border width. Only valid if ``filled=False`` :param prev: If ``True`` draw previous the object, else draws post :param gfx: If ``True`` uses pygame gfxdraw instead of draw :return: ID of the decoration """ coords = [(x, y)] assert_list_vector(coords, 2) assert_color(color) assert isinstance(radius, (int, float)) and radius > 0 assert isinstance(init_angle, (int, float)) assert isinstance(final_angle, (int, float)) assert isinstance(width, int) and width >= 0 assert init_angle != final_angle return self._add_decor(DECORATION_ARC, prev, (tuple(coords), int(radius), init_angle, final_angle, color, width, gfx))
def add_surface( self, x: NumberType, y: NumberType, surface: 'pygame.Surface', prev: bool = True, centered: bool = False, **kwargs ) -> str: """ Adds a surface. .. note:: Consider ``(0, 0)`` coordinates as the center of the object. kwargs (Optional) - ``use_center_positioning`` Uses object center position as *(0, 0)*. ``True`` by default :param x: X position (px), being ``0`` the center of the object :param y: Y position (px), being ``0`` the center of the object :param surface: Surface :param prev: If ``True`` draw previous the object, else draws post :param centered: If ``True`` the text is centered into the position :param kwargs: Optional keyword arguments :return: ID of the decoration """ coords = [(x, y)] assert_list_vector(coords, 2) assert isinstance(surface, pygame.Surface) return self._add_decor(DECORATION_SURFACE, prev, (tuple(coords), surface, centered, kwargs))
def add_rect( self, x: NumberType, y: NumberType, rect: 'pygame.Rect', color: ColorInputType, width: int = 0, prev: bool = True, **kwargs ) -> str: """ Adds a BaseImage object. .. note:: Consider ``(0, 0)`` coordinates as the center of the object. kwargs (Optional) - ``use_center_positioning`` Uses object center position as *(0, 0)*. ``True`` by default :param x: X position (px), being ``0`` the center of the object :param y: Y position (px), being ``0`` the center of the object :param rect: Rect to draw :param color: Color of the rect :param width: Border width of the rect. If ``0`` draw a filled rectangle :param prev: If ``True`` draw previous the object, else draws post :param kwargs: Optional keyword arguments :return: ID of the decoration """ assert isinstance(width, int) and width >= 0 coords = [(x, y)] assert_list_vector(coords, 2) color = assert_color(color) assert isinstance(rect, pygame.Rect) return self._add_decor(DECORATION_RECT, prev, (tuple(coords), rect, color, width, kwargs))
def add_circle(self, x: NumberType, y: NumberType, radius: NumberType, color: ColorType, filled: bool, width: int = 0, prev: bool = True, gfx: bool = True) -> str: """ Add circle. :param x: X position (px), being ``0`` the center of the object :param y: Y position (px), being ``0`` the center of the object :param radius: Circle radius (px) :param color: Color of the polygon :param filled: If ``True`` fills the polygon with the given color :param width: Line border width. Only valid if ``filled=False`` :param prev: If ``True`` draw previous the object, else draws post :param gfx: If ``True`` uses pygame gfxdraw instead of draw :return: ID of the decoration """ coords = [(x, y)] assert_list_vector(coords, 2) assert_color(color) assert isinstance(radius, (int, float)) and radius > 0 assert isinstance(filled, bool) assert isinstance(width, int) and width >= 0 if filled: assert width == 0, 'width must be 0 if the circle is filled' else: if width != 0 and gfx: gfx = False # gfx don't support width return self._add_decor(DECORATION_CIRCLE, prev, (tuple(coords), int(radius), color, filled, width, gfx))
def add_polygon(self, coords: Union[List[Tuple2NumberType], Tuple[Tuple2NumberType, ...]], color: ColorType, filled: bool, width: int = 0, prev: bool = True, gfx: bool = True) -> str: """ Add polygon. :param coords: Coordinate list, being ``(0, 0)`` the center of the object :param color: Color of the polygon :param filled: If ``True`` fills the polygon with the given color :param width: Line border width. Only valid if ``filled=False`` :param prev: If ``True`` draw previous the object, else draws post :param gfx: If ``True`` uses pygame gfxdraw instead of draw :return: ID of the decoration """ assert_list_vector(coords, 2) assert_color(color) assert len(coords) >= 3 assert isinstance(filled, bool) assert isinstance(width, int) and width >= 0 if filled: assert width == 0, 'width must be 0 if the polygon is filled' assert gfx, 'only gfxdraw support filled polygon, then gfx should be True' else: if width != 0 and gfx: gfx = False # gfx don't support width return self._add_decor(DECORATION_POLYGON, prev, (tuple(coords), color, filled, width, gfx))
def add_ellipse(self, x: NumberType, y: NumberType, rx: NumberType, ry: NumberType, color: ColorType, filled: bool, prev: bool = True) -> str: """ Add an ellipse. :param x: X position (px), being ``0`` the center of the object :param y: Y position (px), being ``0`` the center of the object :param rx: Horizontal radius of the ellipse :param ry: Vertical radius of the ellipse :param color: Color of the polygon :param filled: If ``True`` fills the polygon with the given color :param prev: If ``True`` draw previous the object, else draws post :return: ID of the decoration """ coords = [(x, y)] assert_list_vector(coords, 2) assert_color(color) assert isinstance(rx, (int, float)) and rx > 0 assert isinstance(ry, (int, float)) and ry > 0 assert isinstance(filled, bool) return self._add_decor(DECORATION_ELLIPSE, prev, (tuple(coords), rx, ry, color, filled))
def add_baseimage(self, x: NumberType, y: NumberType, image: '_baseimage.BaseImage', prev: bool = True, centered: bool = False) -> str: """ Adds a :py:class:`pygame_menu.baseimage.BaseImage` object. .. note:: If your :py:class:`pygame_menu.baseimage.BaseImage` object changes over time set ``decorator.cache=False`` or force cache manually by calling :py:class:`pygame_menu.decorator.Decorator.force_cache_update`. :param x: X position (px), being ``0`` the center of the object :param y: Y position (px), being ``0`` the center of the object :param image: ``BaseImage`` object :param prev: If ``True`` draw previous the object, else draws post :param centered: If ``True`` the text is centered into the position :return: ID of the decoration """ coords = [(x, y)] assert_list_vector(coords, 2) assert isinstance(image, _baseimage.BaseImage) return self._add_decor(DECORATION_BASEIMAGE, prev, (tuple(coords), image, centered))
def add_textured_polygon(self, coords: Union[List[Tuple2NumberType], Tuple[Tuple2NumberType, ...]], texture: Union['pygame.Surface', 'pygame_menu.BaseImage'], tx: int = 0, ty: int = 0, prev: bool = True, **kwargs) -> str: """ Adds a textured polygon. .. note:: If your :py:class:`pygame_menu.baseimage.BaseImage` object changes over time set ``decorator.cache=False`` or force cache manually by calling :py:class:`pygame_menu._decorator.Decorator.force_cache_update`. kwargs (Optional) - ``use_center_positioning`` (bool) – Uses object center position as *(0, 0)*. ``True`` by default :param coords: Coordinate list, being ``(0, 0)`` the center of the object :param texture: Texture (Surface) or Baseimage object :param tx: X offset of the texture in px :param ty: Y offset of the texture in px :param prev: If ``True`` draw previous the object, else draws post :param kwargs: Optional keyword arguments :return: ID of the decoration """ assert_list_vector(coords, 2) assert len(coords) >= 3 assert isinstance(texture, (pygame.Surface, pygame_menu.BaseImage)) assert isinstance(tx, int) and isinstance(ty, int) return self._add_decor(DECORATION_TEXTURE_POLYGON, prev, (tuple(coords), texture, tx, ty, kwargs))
def add_pixel( self, x: NumberType, y: NumberType, color: ColorInputType, prev: bool = True, **kwargs ) -> str: """ Add a pixel. .. note:: Consider ``(0, 0)`` coordinates as the center of the object. kwargs (Optional) - ``use_center_positioning`` Uses object center position as *(0, 0)*. ``True`` by default :param x: X position (px), being ``0`` the center of the object :param y: Y position (px), being ``0`` the center of the object :param color: Color of the pixel :param prev: If ``True`` draw previous the object, else draws post :param kwargs: Optional keyword arguments :return: ID of the decoration """ coords = [(x, y)] assert_list_vector(coords, 2) color = assert_color(color) return self._add_decor(DECORATION_PIXEL, prev, (tuple(coords), color, kwargs))
def add_pixel(self, x: NumberType, y: NumberType, color: ColorType, prev: bool = True) -> str: """ Add a pixel. :param x: X position (px), being ``0`` the center of the object :param y: Y position (px), being ``0`` the center of the object :param color: Color of the pixel :param prev: If ``True`` draw previous the object, else draws post :return: ID of the decoration """ coords = [(x, y)] assert_list_vector(coords, 2) assert_color(color) return self._add_decor(DECORATION_PIXEL, prev, (tuple(coords), color))
def add_text( self, x: NumberType, y: NumberType, text: str, font: FontType, size: int, color: ColorInputType, prev: bool = True, antialias=True, centered=False, **kwargs ) -> str: """ Adds a text. .. note:: Consider ``(0, 0)`` coordinates as the center of the object. kwargs (Optional) - ``use_center_positioning`` Uses object center position as *(0, 0)*. ``True`` by default :param x: X position (px), being ``0`` the center of the object :param y: Y position (px), being ``0`` the center of the object :param text: Text to draw :param font: Font path or pygame object :param size: Size of the font to render :param color: Font color :param prev: If ``True`` draw previous the object, else draws post :param antialias: Font antialias enabled :param centered: If ``True`` the text is centered into the position :param kwargs: Optional keyword arguments :return: ID of the decoration """ coords = [(x, y)] assert_list_vector(coords, 2) text = str(text) font_obj = pygame_menu.font.get_font(font, size) color = assert_color(color) surface_font = font_obj.render(text, antialias, color) surface = make_surface( width=surface_font.get_width(), height=surface_font.get_height(), alpha=True ) surface.blit(surface_font, (0, 0)) return self._add_decor(DECORATION_TEXT, prev, (tuple(coords), surface, centered, kwargs))
def add_bezier(self, coords: Union[List[Tuple2NumberType], Tuple[Tuple2NumberType, ...]], color: ColorType, steps: int = 5, prev: bool = True) -> str: """ Add bezier curve. :param coords: Coordinate list, being ``(0, 0)`` the center of the object :param color: Color of the polygon :param steps: Interpolation steps :param prev: If ``True`` draw previous the object, else draws post :return: ID of the decoration """ assert_list_vector(coords, 2) assert_color(color) assert len(coords) >= 3 assert isinstance(steps, int) and steps >= 1 return self._add_decor(DECORATION_BEZIER, prev, (tuple(coords), color, steps))
def add_surface(self, x: NumberType, y: NumberType, surface: 'pygame.Surface', prev: bool = True, centered: bool = False) -> str: """ Adds a surface. :param x: X position (px), being ``0`` the center of the object :param y: Y position (px), being ``0`` the center of the object :param surface: Surface :param prev: If ``True`` draw previous the object, else draws post :param centered: If ``True`` the text is centered into the position :return: ID of the decoration """ coords = [(x, y)] assert_list_vector(coords, 2) assert isinstance(surface, pygame.Surface) return self._add_decor(DECORATION_SURFACE, prev, (tuple(coords), surface, centered))
def add_circle( self, x: NumberType, y: NumberType, radius: NumberType, color: ColorInputType, filled: bool, width: int = 0, prev: bool = True, gfx: bool = True, **kwargs ) -> str: """ Add circle. .. note:: Consider ``(0, 0)`` coordinates as the center of the object. kwargs (Optional) - ``use_center_positioning`` Uses object center position as *(0, 0)*. ``True`` by default :param x: X position (px), being ``0`` the center of the object :param y: Y position (px), being ``0`` the center of the object :param radius: Circle radius (px) :param color: Color of the polygon :param filled: If ``True`` fills the polygon with the given color :param width: Line border width. Only valid if ``filled=False`` :param prev: If ``True`` draw previous the object, else draws post :param gfx: If ``True`` uses pygame gfxdraw instead of draw :param kwargs: Optional keyword arguments :return: ID of the decoration """ coords = [(x, y)] assert_list_vector(coords, 2) color = assert_color(color) assert isinstance(radius, NumberInstance) and radius > 0 assert isinstance(filled, bool) assert isinstance(width, int) and width >= 0 if filled: assert width == 0, 'width must be 0 if the circle is filled' else: if width != 0 and gfx: gfx = False # gfx don't support width return self._add_decor(DECORATION_CIRCLE, prev, (tuple(coords), int(radius), color, filled, width, gfx, kwargs))
def add_rect(self, x: NumberType, y: NumberType, rect: 'pygame.Rect', color: ColorType, width: int = 0, prev: bool = True) -> str: """ Adds a BaseImage object. :param x: X position (px), being ``0`` the center of the object :param y: Y position (px), being ``0`` the center of the object :param rect: Rect to draw :param color: Color of the rect :param width: Width of the rect. If ``0`` draw a filled rectangle :param prev: If ``True`` draw previous the object, else draws post :return: ID of the decoration """ coords = [(x, y)] assert_list_vector(coords, 2) assert isinstance(rect, pygame.Rect) return self._add_decor(DECORATION_RECT, prev, (tuple(coords), rect, color, width))
def add_arc( self, x: NumberType, y: NumberType, radius: NumberType, init_angle: NumberType, final_angle: NumberType, color: ColorInputType, width: int = 0, prev: bool = True, gfx: bool = True, **kwargs ) -> str: """ Add arc. .. note:: Consider ``(0, 0)`` coordinates as the center of the object. kwargs (Optional) - ``use_center_positioning`` Uses object center position as *(0, 0)*. ``True`` by default :param x: X position (px), being ``0`` the center of the object :param y: Y position (px), being ``0`` the center of the object :param radius: Circle radius (px) :param init_angle: Initial angle in degrees, from ``0`` to ``360`` :param final_angle: Final angle in degrees, from ``0`` to ``360`` :param color: Color of the polygon :param width: Line border width. Only valid if ``filled=False`` :param prev: If ``True`` draw previous the object, else draws post :param gfx: If ``True`` uses pygame gfxdraw instead of draw :param kwargs: Optional keyword arguments :return: ID of the decoration """ coords = [(x, y)] assert_list_vector(coords, 2) color = assert_color(color) assert isinstance(radius, NumberInstance) and radius > 0 assert isinstance(init_angle, NumberInstance) assert isinstance(final_angle, NumberInstance) assert isinstance(width, int) and width >= 0 assert init_angle != final_angle return self._add_decor(DECORATION_ARC, prev, (tuple(coords), int(radius), init_angle, final_angle, color, width, gfx, kwargs))
def add_pie(self, x: NumberType, y: NumberType, radius: NumberType, init_angle: NumberType, final_angle: NumberType, color: ColorType, prev: bool = True, **kwargs) -> str: """ Add a unfilled pie. .. note:: Consider ``(0, 0)`` coordinates as the center of the object. kwargs (Optional) - ``use_center_positioning`` Uses object center position as *(0, 0)*. ``True`` by default :param x: X position (px), being ``0`` the center of the object :param y: Y position (px), being ``0`` the center of the object :param radius: Circle radius (px) :param init_angle: Initial angle in degrees ``(0-360)`` :param final_angle: Final angle in degrees ``(0-360)`` :param color: Color of the polygon :param prev: If ``True`` draw previous the object, else draws post :param kwargs: Optional keyword arguments :return: ID of the decoration """ coords = [(x, y)] assert_list_vector(coords, 2) assert_color(color) assert isinstance(radius, (int, float)) and radius > 0 assert isinstance(init_angle, (int, float)) assert isinstance(final_angle, (int, float)) assert init_angle != final_angle return self._add_decor(DECORATION_PIE, prev, (tuple(coords), int(radius), init_angle, final_angle, color, kwargs))