Visitar URL original
NinePatchTexture.create_rounded_corners(..) · Issue #2295 · pythonarcade/arcade · GitHub
Skip to content

NinePatchTexture.create_rounded_corners(..) #2295

Description

@einarf

Make it possible to create rounded corner nine patch images just from a few parameters including a color. This is extremely useful for things like buttons and makes it fast to prototype something quick.

Optionally a method to create a texture with rounded corners can be in the texture module so we don't have to make this extra initializer.

Activity

  1. added
    guiRelated to arcade GUI (sub module arcade.gui)
    on Jul 22, 2024
  2. modified the milestones: Future, 3.1 on Jul 22, 2024
  3. added theissue type on Mar 3, 2025
  4. pushfoo commented on Mar 3, 2025

    @pushfoo
    Member

    To my understanding, are two ways to go about this:

    1. Pillow + create a texture
    2. Render directly into a texture as in the PerfGraph
      class PerfGraph(arcade.Sprite):
  5. einarf commented on Mar 27, 2025

    @einarf
    MemberAuthor

    @eruvanos Something like this acceptable?

    from PIL import Image, ImageDraw
    
    def create_rounded_button(size: int, radius: int, background_color, border_color=None, border_size=0):
        im = Image.new("RGBA", (size, size), (0, 0, 0, 0))
        draw_button = ImageDraw.Draw(im)
        if border_color and border_size:
            draw_button.rounded_rectangle((0, 0, size-1, size-1), radius=radius, fill=border_color)
            draw_button.rounded_rectangle(
                (border_size, border_size, size-1-border_size, size-1-border_size),
                radius=radius,
                fill=background_color,
            )
        else:
            draw_button.rounded_rectangle((0, 0, size-1, size-1), radius=radius, fill=background_color)
        return im
    
    button = create_rounded_button(
        size=200,
        radius=20,
        background_color=(64, 64, 64, 255),
        border_color=(255, 255, 255, 255),
        border_size=2,
    )
    button.show()
  6. eruvanos commented on Mar 28, 2025

    @eruvanos
    Member

    yes, that looks fine to me :)

  7. modified the milestones: 3.1, Future on Mar 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    guiRelated to arcade GUI (sub module arcade.gui)

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions