KeyWorksRW / wxUiEditor

RAD tool used to create and maintain wxWidgets UI elements.
Apache License 2.0
62 stars 6 forks source link

Refactor ProjectImages class #1441

Closed Randalphwa closed 3 months ago

Randalphwa commented 3 months ago

The PR changes the EmbeddedImage structure to store all of the different resolutions of an image (e.g., foo_1_x.png, foo_2x.png, etc.). It also adds a get_bundle() that creates a wxBitmapBundle when it is called, rather than storing it anywhere. For the Mockup panel, this is all that's needed.

Note that get_bundle() will reload the image if it has changed, making the Mockup panel more accurate (the image will be reloaded as part of code generation if it has changed).

The ImageBundle structure no longer has a wxBitmapBundle field -- you need to call EmbeddedImage::get_bundle() to get the wxBitmapBundle.

AddEmbeddedBundleImage() still calls AddEmbeddedBundleImage() for every image in a bundle which makes it possible for code generation to use m_bundles (ImageBundle) for every image. However, m_map_embedded already contains all the filenames and data, so this duplicates that data. It would be better to use m_map_embedded directly and eliminate m_bundles. However, I'm leaving it in place for this PR as it only affects memory, and even then only for multiple Embed images (i.e., not for single bitmaps or SVGs).

One of the problems with XPM files is that they are normally declared using a static variable, which means the data gets duplicated in every translation unit that #includes it. It also runs the risk of the variable name being used elsewhere in the module (rare, but it could happen). By contrast, if it used the wxUiEditor Embed mechanism, the variable name specified within the XPM file would be ignored, and the data would only be stored in one location. That's not going to be how people are used to seeing it, but of course neither is our entire embed method.

This PR does embed XPM files using the same compression algorithm as SVG files, however this is only used by EmbeddedImage::get_bundle(). Code generation still includes the XPM file directly.