meerk40t / meerk40t

Hackable Laser software for K40 / GRBL / Fibre Lasers
MIT License
233 stars 62 forks source link

Icon translation fix #2668

Closed jpirnay closed 1 week ago

jpirnay commented 1 week ago

After: image

Summary by Sourcery

Fix icon boundary calculation to correct shifted appearances and add functionality to set icon background colors for improved visual consistency.

Bug Fixes:

Enhancements:

sourcery-ai[bot] commented 1 week ago

Reviewer's Guide by Sourcery

This PR fixes icon translation issues and adds functionality to set custom background colors for icons. The main changes involve replacing the use of GraphicsPath.Box with direct bbox calculations from Geomstr and implementing a new forced background color feature.

Sequence diagram for icon preparation with forced background

sequenceDiagram
    participant User
    participant IconManager
    participant wxMemoryDC as wx.MemoryDC
    participant wxGraphicsContext as wx.GraphicsContext

    User->>IconManager: GetBitmap(..., forced_background)
    IconManager->>IconManager: retrieve_bitmap(..., forced_background)
    IconManager->>IconManager: prepare_bitmap(..., forced_background)
    IconManager->>wxMemoryDC: Create MemoryDC
    wxMemoryDC->>wxGraphicsContext: Create GraphicsContext
    wxGraphicsContext-->>IconManager: Return GraphicsContext
    IconManager-->>User: Return Bitmap with forced background

Class diagram for icon translation and background color changes

classDiagram
    class IconManager {
        - wx.Colour _background
        - wx.Pen _pen
        + prepare_bitmap(final_icon_width, final_icon_height, buffer, forced_background)
        + retrieve_bitmap(color_dark, final_icon_width, final_icon_height, buffer, forced_background)
        + GetBitmap(color, final_icon_width, final_icon_height, force_darkmode, force_lightmode, buffer, resolution, forced_background)
    }
    class Geomstr {
        + bbox()
    }
    IconManager --> Geomstr : uses
    note for IconManager "Added forced_background parameter to methods for custom icon background colors"

File-Level Changes

Change Details Files
Fixed icon boundary calculation by replacing GraphicsPath.Box with direct bbox calculations
  • Replaced gp.Box calls with direct bbox calculations from geom.bbox()
  • Split translation matrix construction into separate x and y components for better readability
  • Modified coordinate calculations to use bbox values instead of GraphicsPath boundaries
meerk40t/gui/icons.py
Added support for custom background colors in icons
  • Added forced_background parameter to prepare_bitmap and retrieve_bitmap methods
  • Implemented background color setting in prepare_bitmap using wx.Brush
  • Added forced_background parameter to GetBitmap method
meerk40t/gui/icons.py
Enhanced material manager with colorful icon backgrounds
  • Added COLORFUL_BACKGROUND flag to control background coloring
  • Implemented automatic foreground color selection based on background contrast
  • Modified bitmap generation to use forced backgrounds for operation icons
meerk40t/gui/materialmanager.py
Improved debug window initialization
  • Added automatic first icon selection on window load
  • Implemented show_first method to display initial icon
meerk40t/gui/mkdebug.py

Tips and commands #### Interacting with Sourcery - **Trigger a new review:** Comment `@sourcery-ai review` on the pull request. - **Continue discussions:** Reply directly to Sourcery's review comments. - **Generate a GitHub issue from a review comment:** Ask Sourcery to create an issue from a review comment by replying to it. - **Generate a pull request title:** Write `@sourcery-ai` anywhere in the pull request title to generate a title at any time. - **Generate a pull request summary:** Write `@sourcery-ai summary` anywhere in the pull request body to generate a PR summary at any time. You can also use this command to specify where the summary should be inserted. #### Customizing Your Experience Access your [dashboard](https://app.sourcery.ai) to: - Enable or disable review features such as the Sourcery-generated pull request summary, the reviewer's guide, and others. - Change the review language. - Add, remove or edit custom review instructions. - Adjust other review settings. #### Getting Help - [Contact our support team](mailto:support@sourcery.ai) for questions or feedback. - Visit our [documentation](https://docs.sourcery.ai) for detailed guides and information. - Keep in touch with the Sourcery team by following us on [X/Twitter](https://x.com/SourceryAI), [LinkedIn](https://www.linkedin.com/company/sourcery-ai/) or [GitHub](https://github.com/sourcery-ai).