Commit Graph

19 Commits

Author SHA1 Message Date
PB
5ba37d867c Support creating wxBitmapBundle from SVG in application resource
Allow creating wxBitmapBitmap from SVG image stored in an application
resource on the platforms where wxHAS_IMAGE_RESOURCES is defined.

On Windows, load the bundle from a resource with RT_RCDATA type and on
MacOS from a file with an extension "svg" placed in the "Resources"
subdirectory of the application bundle.

Closes #22061.
2022-01-27 14:39:35 +01:00
Alexander Koshelev
b2629a97e5 Add wxBitmapBundle::GetPreferredLogicalSizeFor()
We often need the logical bitmap size when using it in size computations
involving window size, so add a function returning it directly to
wxBitmapBundle, similarly to wxBitmap::GetLogicalSize(), to avoid using
FromPhys() everywhere.

Also rename the existing wxBitmapBundle::GetPreferredSizeFor() to
GetPreferredBitmapSizeFor() to make it more clear that this is similar
to wxBitmap::GetSize() and so returns the size in physical units.

Closes #22056.
2022-01-27 14:29:25 +01:00
Vadim Zeitlin
fc2b7e5266 Add wxBitmapBundle::GetIconFor()
This is to GetBitmapFor() as GetIcon() is to GetBitmap().
2022-01-23 16:04:50 +01:00
Vadim Zeitlin
84b5e4639e Add wxBitmapBundle::IsSameAs()
This is useful if only for compatibility with wxBitmap or wxIcon, that
have the same member function with the same semantics.
2022-01-23 16:04:50 +01:00
Vadim Zeitlin
fe2aba3b99 Add wxBitmapBundle::GetIcon()
This is just a convenient wrapper for GetBitmap() that will be useful in
the classes using wxIcon in their public API to preserve compatibility
after switching to using wxBitmapBundle instead of wxIcon internally.
2022-01-23 16:04:50 +01:00
Vadim Zeitlin
99445aa64c Document wxBitmapBundle::GetBitmap(wxDefaultSize) behaviour
The size parameter is explicitly allowed to be wxDefaultSize here,
meaning to return the bitmap in the default bundle size.
2022-01-23 16:04:50 +01:00
Vadim Zeitlin
8adfaa37f7 Add wxBitmapBundle::FromSVGFile() helper
This is just a trivial wrapper for wxBitmapBundle::FromSVG(), but it can
still be convenient to have.
2021-11-29 12:55:22 +00:00
Stefan Csomor
a7f5e3c5c3
OSX wxBitmapBundle::FromFiles implementation for macOS (#2561)
* adding macOS wxBitmapBundle::FromFiles implementation

* adding FromFiles overload, generic implementation

* Update interface/wx/bmpbndl.h

* Removing outdated comment

Co-authored-by: VZ <vz-github@zeitlins.org>
2021-10-26 22:27:36 +02:00
Vadim Zeitlin
9326aa3b6c Add wxBitmapBundle::GetBitmapFor() helper
This can be used to get the bitmap of the size appropriate for the DPI
scaling used for the given window.
2021-10-25 13:40:18 +01:00
Vadim Zeitlin
e5a7e9ccbd Take const wxWindow in wxBitmapBundle::GetPreferredSizeFor()
This function should be usable in const methods of wxWindow-derived
classes too.
2021-10-25 12:21:15 +01:00
Vadim Zeitlin
b20552116c Allow wxBitmapBundle to specify its preferred bitmap size
Using bitmaps of preferred size avoids scaling and results in much
better appearance, so add methods allowing querying the bundle about the
bitmaps it supports and implement them in the various implementations.

This is not actually used anywhere yet, but will be soon.
2021-10-19 02:20:26 +01:00
Vadim Zeitlin
630e6b898f Add conversion ctor from wxIcon to wxBitmapBundle too
Existing code may call functions taking wxBitmap with wxIcon, due to an
existing conversion from wxIcon to wxBitmap, so we need to provide a
similar conversion to wxBitmapBundle for compatibility.
2021-10-18 11:50:10 +02:00
Vadim Zeitlin
e8a15050d2 Add missing references to wxSize parameters in wxBitmapBundle
Pass wxSize by const reference instead of "const" value.

Note that passing wxSize by value might be not such a bad thing,
actually, but we use const reference for it everywhere else, so do it
here as well for consistency (and the original intention was to do it
like this, missing "&" was just a typo subsequently propagated through
copy-pasting).

No real changes.
2021-10-16 15:56:40 +02:00
Vadim Zeitlin
fb4e188cea Add wxHAS_SVG feature test macro
This is more clear and future-proof than using wxHAS_RAW_BITMAP for
checking for SVG availability.
2021-10-05 16:12:01 +01:00
Vadim Zeitlin
0216654272 Make wxBitmapBundleImpl public and show how to use it
Show how a custom implementation of wxBitmapBundleImpl can be defined in
the toolbar sample.
2021-10-05 16:06:43 +01:00
Vadim Zeitlin
ab619010bd Add FromSVG() overload taking const data
Passing non-const data is inconvenient and error-prone, as data can't be
used again after it was modified by Nano SVG, which resulted in the
button using SVG bitmap not working any longer in the toolbar sample
after recreating the toolbar.

So make it easier to do the right thing, while still keeping the
overload taking non-const data for the situations when avoiding an extra
copy is worth it.
2021-10-05 16:06:43 +01:00
Vadim Zeitlin
ac02ae877f Add simple wxBitmapBundle::FromSVG() implementation using NanoSVG
Add nanosvg submodule and use it in the generic implementation of this
function.

This is incomplete yet and, notably, doesn't cache the rasterized
images, but already shows that using SVG images works (at least in the
toolbar sample).
2021-10-05 16:06:43 +01:00
Vadim Zeitlin
b33df7360a Implement loading resource bundle from Windows resources
This allows to use resources defined in the .rc files under MSW instead
of embedding them in the program text as arrays.
2021-10-05 15:49:43 +01:00
Vadim Zeitlin
97f6c85d9b Add first version of wxBitmapBundle and use it in wxToolBar
This first version provides only a generic implementation of
wxBitmapBundle using a collection of bitmaps and only supports using it
in wxToolBar in wxMSW and wxGTK.

More methods of creating wxBitmapBundle will be provided later and more
functions taking wxBitmap will be changed to take wxBitmapBundle later
too and, of course, all the other ports will be updated to use the new
API too.
2021-10-05 15:49:43 +01:00