Use wxBitmapBundle in combo sample

Replace PNG files with SVG ones.

Closes #22103.
This commit is contained in:
Alexander Koshelev 2022-02-07 12:44:02 +03:00 committed by Vadim Zeitlin
parent bd058106a3
commit 685e3af613
13 changed files with 37 additions and 42 deletions

View File

@ -16,7 +16,7 @@ wx_add_sample(calendar DEPENDS wxUSE_CALENDARCTRL)
wx_add_sample(caret DEPENDS wxUSE_CARET) wx_add_sample(caret DEPENDS wxUSE_CARET)
wx_add_sample(clipboard DEPENDS wxUSE_CLIPBOARD) wx_add_sample(clipboard DEPENDS wxUSE_CLIPBOARD)
wx_add_sample(collpane DEPENDS wxUSE_COLLPANE) wx_add_sample(collpane DEPENDS wxUSE_COLLPANE)
wx_add_sample(combo DATA dropbuth.png dropbutn.png dropbutp.png DEPENDS wxUSE_COMBOCTRL) wx_add_sample(combo DATA dropbuth.svg dropbutn.svg dropbutp.svg three-dots.svg DEPENDS wxUSE_COMBOCTRL)
wx_add_sample(config conftest.cpp DEPENDS wxUSE_CONFIG) wx_add_sample(config conftest.cpp DEPENDS wxUSE_CONFIG)
wx_add_sample(console CONSOLE IMPORTANT) wx_add_sample(console CONSOLE IMPORTANT)
wx_add_sample(dataview IMPORTANT dataview.cpp mymodels.cpp mymodels.h DEPENDS wxUSE_DATAVIEWCTRL) wx_add_sample(dataview IMPORTANT dataview.cpp mymodels.cpp mymodels.h DEPENDS wxUSE_DATAVIEWCTRL)

View File

@ -184,7 +184,7 @@ combo$(EXEEXT): $(COMBO_OBJECTS) $(__combo___win32rc)
data: data:
@mkdir -p . @mkdir -p .
@for f in dropbuth.png dropbutn.png dropbutp.png; do \ @for f in dropbuth.svg dropbutn.svg dropbutp.svg three-dots.svg; do \
if test ! -f ./$$f -a ! -d ./$$f ; \ if test ! -f ./$$f -a ! -d ./$$f ; \
then x=yep ; \ then x=yep ; \
else x=`find $(srcdir)/$$f -newer ./$$f -print` ; \ else x=`find $(srcdir)/$$f -newer ./$$f -print` ; \

View File

@ -12,9 +12,10 @@
<wx-data id="data"> <wx-data id="data">
<files> <files>
dropbuth.png dropbuth.svg
dropbutn.png dropbutn.svg
dropbutp.png dropbutp.svg
three-dots.svg
</files> </files>
</wx-data> </wx-data>

View File

@ -538,32 +538,7 @@ public:
style | wxCC_STD_BUTTON, style | wxCC_STD_BUTTON,
validator,name); validator,name);
// SetButtonBitmaps(wxBitmapBundle::FromSVGFile("three-dots.svg", wxSize(16, 16)), true);
// Prepare custom button bitmap (just '...' text)
wxMemoryDC dc;
wxBitmap bmp(12,16);
dc.SelectObject(bmp);
// Draw transparent background
wxColour magic(255,0,255);
wxBrush magicBrush(magic);
dc.SetBrush( magicBrush );
dc.SetPen( *wxTRANSPARENT_PEN );
dc.DrawRectangle(0,0,bmp.GetWidth(),bmp.GetHeight());
// Draw text
wxString str = "...";
int w,h;
dc.GetTextExtent(str, &w, &h, 0, 0);
dc.DrawText(str, (bmp.GetWidth()-w)/2, (bmp.GetHeight()-h)/2);
dc.SelectObject( wxNullBitmap );
// Finalize transparency with a mask
wxMask *mask = new wxMask( bmp, magic );
bmp.SetMask( mask );
SetButtonBitmaps(bmp,true);
} }
virtual void OnButtonClick() wxOVERRIDE virtual void OnButtonClick() wxOVERRIDE
@ -852,17 +827,14 @@ MyFrame::MyFrame(const wxString& title)
); );
// Load images from disk // Load images from disk
wxImage imgNormal("dropbutn.png"); wxBitmapBundle bmpNormal = wxBitmapBundle::FromSVGFile("dropbutn.svg", wxSize(16, 16));
wxImage imgPressed("dropbutp.png"); wxBitmapBundle bmpPressed = wxBitmapBundle::FromSVGFile("dropbutp.svg", wxSize(16, 16));
wxImage imgHover("dropbuth.png"); wxBitmapBundle bmpHover = wxBitmapBundle::FromSVGFile("dropbuth.svg", wxSize(16, 16));
if ( imgNormal.IsOk() && imgPressed.IsOk() && imgHover.IsOk() ) if ( bmpNormal.IsOk() && bmpPressed.IsOk() && bmpHover.IsOk() )
{ {
wxBitmap bmpNormal(imgNormal); odc->SetButtonBitmaps(bmpNormal, false, bmpPressed, bmpHover);
wxBitmap bmpPressed(imgPressed); odc2->SetButtonBitmaps(bmpNormal, true, bmpPressed, bmpHover);
wxBitmap bmpHover(imgHover);
odc->SetButtonBitmaps(bmpNormal,false,bmpPressed,bmpHover);
odc2->SetButtonBitmaps(bmpNormal,true,bmpPressed,bmpHover);
} }
else else
wxLogError("Dropbutton images not found"); wxLogError("Dropbutton images not found");

Binary file not shown.

Before

Width:  |  Height:  |  Size: 371 B

View File

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<svg width="17.526" height="17.526" style="" version="1.1" xml:space="preserve" xmlns="http://www.w3.org/2000/svg"><rect id="backgroundrect" class="" width="100%" height="100%" fill="none" style=""/>
<g class="currentLayer" style=""><title>Layer 1</title><g id="svg_1" class="selected" fill="#6767e7">
<g id="svg_2" fill="#6767e7">
<path id="svg_3" d="m8.417 17.279s0.444 0.518 0.909 0.053c0.639-0.64 6.547-6.742 6.547-6.742s0.818-0.813-0.266-0.813h-2.811s0-0.471 0-1.19v-8.199s0.012-0.388-0.488-0.388h-6.911c-0.702 0-0.58 0.464-0.58 0.464v8.181 1.326s-2.155 0-3.045 0c-0.891 0-0.071 0.776-0.071 0.776l6.716 6.532z" fill="#6767e7" style=""/>
</g>
</g></g></svg>

After

Width:  |  Height:  |  Size: 705 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 237 B

View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<svg id="Capa_1" enable-background="new 0 0 17.526 17.526" version="1.1" viewBox="0 0 17.526 17.526" xml:space="preserve" xmlns="http://www.w3.org/2000/svg">
<path d="m8.417 17.279s0.444 0.518 0.909 0.053c0.639-0.64 6.547-6.742 6.547-6.742s0.818-0.813-0.266-0.813h-2.811s0-0.471 0-1.19v-8.199s0.012-0.388-0.488-0.388h-6.911c-0.702 0-0.58 0.464-0.58 0.464v8.181 1.326s-2.155 0-3.045 0c-0.891 0-0.071 0.776-0.071 0.776l6.716 6.532z" fill="#030104"/>
</svg>

After

Width:  |  Height:  |  Size: 498 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 366 B

View File

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<svg width="17.526" height="17.526" style="" version="1.1" xml:space="preserve" xmlns="http://www.w3.org/2000/svg"><rect id="backgroundrect" class="" width="100%" height="100%" fill="none" style=""/>
<g class="currentLayer" style=""><title>Layer 1</title><g id="svg_1" class="selected" fill="#0404b8">
<g id="svg_2" fill="#0404b8">
<path id="svg_3" d="m8.417 17.279s0.444 0.518 0.909 0.053c0.639-0.64 6.547-6.742 6.547-6.742s0.818-0.813-0.266-0.813h-2.811s0-0.471 0-1.19v-8.199s0.012-0.388-0.488-0.388h-6.911c-0.702 0-0.58 0.464-0.58 0.464v8.181 1.326s-2.155 0-3.045 0c-0.891 0-0.071 0.776-0.071 0.776l6.716 6.532z" fill="#0404b8" style=""/>
</g>
</g></g></svg>

After

Width:  |  Height:  |  Size: 705 B

View File

@ -222,7 +222,7 @@ $(OBJS)\combo.exe: $(COMBO_OBJECTS) $(OBJS)\combo_sample_rc.o
data: data:
if not exist $(OBJS) mkdir $(OBJS) if not exist $(OBJS) mkdir $(OBJS)
for %%f in (dropbuth.png dropbutn.png dropbutp.png) do if not exist $(OBJS)\%%f copy .\%%f $(OBJS) for %%f in (dropbuth.svg dropbutn.svg dropbutp.svg three-dots.svg) do if not exist $(OBJS)\%%f copy .\%%f $(OBJS)
$(OBJS)\combo_sample_rc.o: ./../../samples/sample.rc $(OBJS)\combo_sample_rc.o: ./../../samples/sample.rc
$(WINDRES) -i$< -o$@ --define __WXMSW__ $(__WXUNIV_DEFINE_p_1) $(__DEBUG_DEFINE_p_1) $(__NDEBUG_DEFINE_p_1) $(__EXCEPTIONS_DEFINE_p_1) $(__RTTI_DEFINE_p_1) $(__THREAD_DEFINE_p_1) $(__UNICODE_DEFINE_p_1) --include-dir $(SETUPHDIR) --include-dir ./../../include $(__CAIRO_INCLUDEDIR_p) --include-dir . $(__DLLFLAG_p_1) --define wxUSE_DPI_AWARE_MANIFEST=$(USE_DPI_AWARE_MANIFEST) --include-dir ./../../samples --define NOPCH $(WINDRES) -i$< -o$@ --define __WXMSW__ $(__WXUNIV_DEFINE_p_1) $(__DEBUG_DEFINE_p_1) $(__NDEBUG_DEFINE_p_1) $(__EXCEPTIONS_DEFINE_p_1) $(__RTTI_DEFINE_p_1) $(__THREAD_DEFINE_p_1) $(__UNICODE_DEFINE_p_1) --include-dir $(SETUPHDIR) --include-dir ./../../include $(__CAIRO_INCLUDEDIR_p) --include-dir . $(__DLLFLAG_p_1) --define wxUSE_DPI_AWARE_MANIFEST=$(USE_DPI_AWARE_MANIFEST) --include-dir ./../../samples --define NOPCH

View File

@ -431,7 +431,7 @@ $(OBJS)\combo.exe: $(COMBO_OBJECTS) $(OBJS)\combo_sample.res
data: data:
if not exist $(OBJS) mkdir $(OBJS) if not exist $(OBJS) mkdir $(OBJS)
for %f in (dropbuth.png dropbutn.png dropbutp.png) do if not exist $(OBJS)\%f copy .\%f $(OBJS) for %f in (dropbuth.svg dropbutn.svg dropbutp.svg three-dots.svg) do if not exist $(OBJS)\%f copy .\%f $(OBJS)
$(OBJS)\combo_sample.res: .\..\..\samples\sample.rc $(OBJS)\combo_sample.res: .\..\..\samples\sample.rc
rc /fo$@ /d WIN32 $(____DEBUGRUNTIME_3_p_1) /d _CRT_SECURE_NO_DEPRECATE=1 /d _CRT_NON_CONFORMING_SWPRINTFS=1 /d _SCL_SECURE_NO_WARNINGS=1 $(__NO_VC_CRTDBG_p_1) $(__TARGET_CPU_COMPFLAG_p_1) /d __WXMSW__ $(__WXUNIV_DEFINE_p_1) $(__DEBUG_DEFINE_p_1) $(__NDEBUG_DEFINE_p_1) $(__EXCEPTIONS_DEFINE_p_1) $(__RTTI_DEFINE_p_1) $(__THREAD_DEFINE_p_1) $(__UNICODE_DEFINE_p_1) /i $(SETUPHDIR) /i .\..\..\include $(____CAIRO_INCLUDEDIR_FILENAMES_1_p) /i . $(__DLLFLAG_p_1) /d _WINDOWS /i .\..\..\samples /d NOPCH .\..\..\samples\sample.rc rc /fo$@ /d WIN32 $(____DEBUGRUNTIME_3_p_1) /d _CRT_SECURE_NO_DEPRECATE=1 /d _CRT_NON_CONFORMING_SWPRINTFS=1 /d _SCL_SECURE_NO_WARNINGS=1 $(__NO_VC_CRTDBG_p_1) $(__TARGET_CPU_COMPFLAG_p_1) /d __WXMSW__ $(__WXUNIV_DEFINE_p_1) $(__DEBUG_DEFINE_p_1) $(__NDEBUG_DEFINE_p_1) $(__EXCEPTIONS_DEFINE_p_1) $(__RTTI_DEFINE_p_1) $(__THREAD_DEFINE_p_1) $(__UNICODE_DEFINE_p_1) /i $(SETUPHDIR) /i .\..\..\include $(____CAIRO_INCLUDEDIR_FILENAMES_1_p) /i . $(__DLLFLAG_p_1) /d _WINDOWS /i .\..\..\samples /d NOPCH .\..\..\samples\sample.rc

View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<svg id="Capa_1" enable-background="new 0 0 32.055 32.055" version="1.1" viewBox="0 0 32.055 32.055" xml:space="preserve" xmlns="http://www.w3.org/2000/svg">
<path d="m3.968 12.061c-2.193 0-3.968 1.774-3.968 3.966s1.773 3.967 3.968 3.967c2.189 0 3.966-1.772 3.966-3.967 0-2.192-1.777-3.966-3.966-3.966zm12.265 0c-2.188 0-3.968 1.773-3.968 3.965s1.778 3.967 3.968 3.967 3.97-1.772 3.97-3.967c-2e-3 -2.191-1.78-3.965-3.97-3.965zm11.857 0c-2.192 0-3.969 1.774-3.969 3.967 0 2.19 1.774 3.965 3.969 3.965 2.188 0 3.965-1.772 3.965-3.965s-1.777-3.967-3.965-3.967z"/>
</svg>

After

Width:  |  Height:  |  Size: 611 B