Add a possibility to show SVG images to the image sample too
This is useful at least for demonstrating wx SVG support.
This commit is contained in:
parent
8adfaa37f7
commit
2435ceb2bb
@ -70,7 +70,7 @@ endif()
|
||||
wx_add_sample(image image.cpp canvas.cpp canvas.h cursor_png.c RES image.rc
|
||||
DATA horse.png horse.jpg horse.bmp horse.gif horse.pcx horse.pnm
|
||||
horse_ag.pnm horse_rg.pnm horse.tif horse.tga horse.xpm horse.cur
|
||||
horse.ico horse3.ani smile.xbm toucan.png cmyk.jpg cursor.png
|
||||
horse.ico horse3.ani horse.svg smile.xbm toucan.png cmyk.jpg cursor.png
|
||||
NAME imagesample DEPENDS wxUSE_IMAGE)
|
||||
foreach(lang ar bg cs de fr it ka pl ru sv ja ja_JP.EUC-JP)
|
||||
list(APPEND INTERNAT_DATA_FILES ${lang}/internat.po ${lang}/internat.mo)
|
||||
|
@ -186,7 +186,7 @@ image$(EXEEXT): $(IMAGE_OBJECTS) $(__image___win32rc)
|
||||
|
||||
data:
|
||||
@mkdir -p .
|
||||
@for f in horse.png horse.jpg horse.bmp horse.gif horse.pcx horse.pnm horse_ag.pnm horse_rg.pnm horse.tif horse.tga horse.xpm horse.cur horse.ico horse3.ani smile.xbm toucan.png cmyk.jpg cursor.png; do \
|
||||
@for f in horse.png horse.jpg horse.bmp horse.gif horse.pcx horse.pnm horse_ag.pnm horse_rg.pnm horse.tif horse.tga horse.xpm horse.cur horse.ico horse3.ani horse.svg smile.xbm toucan.png cmyk.jpg cursor.png; do \
|
||||
if test ! -f ./$$f -a ! -d ./$$f ; \
|
||||
then x=yep ; \
|
||||
else x=`find $(srcdir)/$$f -newer ./$$f -print` ; \
|
||||
|
8
samples/image/horse.svg
Normal file
8
samples/image/horse.svg
Normal file
@ -0,0 +1,8 @@
|
||||
<?xml version='1.0' encoding='utf-8'?>
|
||||
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 511 511" xmlns:xlink="http://www.w3.org/1999/xlink" enable-background="new 0 0 511 511">
|
||||
<g>
|
||||
<path d="m298.342,455.5c0,4.142 3.358,7.5 7.5,7.5h16.004c4.142,0 7.5-3.358 7.5-7.5s-3.358-7.5-7.5-7.5h-16.004c-4.142,0-7.5,3.358-7.5,7.5z"/>
|
||||
<path d="m412.37,195.5c0-2.527 0.984-4.902 2.771-6.689 3.556-3.555 5.514-8.283 5.514-13.311s-1.958-9.755-5.514-13.311l-95.421-95.42c6.022-9.682 14.336-30.793 1.031-62.194-1.059-2.499-3.386-4.231-6.084-4.529-2.698-0.298-5.346,0.886-6.924,3.096-11.593,16.23-34.789,30.977-61.646,48.051-30.521,19.403-65.113,41.395-92.336,71.958-31.905,35.82-47.415,76.495-47.415,124.351 0,90.446 48.19,129.689 62.96,139.562 3.854,2.576 8.362,3.938 13.037,3.938h3.503c4.687,0 8.5,3.813 8.5,8.5s-3.813,8.5-8.5,8.5h-39.998c-1.754,0-3.454,0.615-4.801,1.738l-42.244,35.202c-5.375,4.478-8.457,11.058-8.457,18.054v40.504c0,4.142 3.358,7.5 7.5,7.5h304c4.142,0 7.5-3.358 7.5-7.5v-40.506c0-6.996-3.082-13.576-8.456-18.053l-42.244-35.203c-1.348-1.123-3.047-1.738-4.801-1.738h-39.999c-4.687,0-8.5-3.813-8.5-8.5s3.813-8.5 8.5-8.5h7.132c8.156,0 15.606-4.129 19.928-11.045l15.684-25.094c13.354-21.367 10.621-49.104-6.648-67.453l-85.432-90.772c8.883,1.34 20.024,2.364 33.337,2.364 30.493,0 44.728,15.705 57.287,29.561 4.204,4.639 8.175,9.02 12.461,12.389 6.195,4.87 15.047,4.362 20.592-1.183l26.963-26.964c2.929-2.929 2.922-7.685-0.007-10.614-1.788-1.786-2.773-4.162-2.773-6.689zm-31.241,252.5h-27.282c-4.142,0-7.5,3.358-7.5,7.5s3.358,7.5 7.5,7.5h39.998c0.168,0 0.333-0.014 0.499-0.025 0,0.006 0.001,0.013 0.001,0.019v33.006h-289v-33.006c0-0.006 0.001-0.013 0.001-0.019 0.166,0.011 0.331,0.025 0.499,0.025h168.003c4.142,0 7.5-3.358 7.5-7.5s-3.358-7.5-7.5-7.5h-155.286l30.001-25h202.566l30,25zm-89.186-40h-84.195c1.027-2.638 1.597-5.503 1.597-8.5s-0.57-5.862-1.597-8.5h84.195c-1.027,2.638-1.597,5.503-1.597,8.5s0.569,5.862 1.597,8.5zm112.592-229.795c-4.62,4.62-7.165,10.762-7.165,17.296 0,3.952 0.931,7.761 2.691,11.178l-22.482,22.483c-0.215,0.215-0.521,0.149-0.715-0.003-3.292-2.587-6.687-6.333-10.618-10.67-13.192-14.556-31.258-34.489-68.401-34.489-34.426,0-52.973-7.365-53.132-7.43-0.041-0.017-0.083-0.029-0.124-0.045-0.088-0.035-0.178-0.066-0.268-0.097-0.148-0.052-0.297-0.099-0.446-0.142-0.043-0.012-0.084-0.029-0.127-0.04-11.495-3.015-20.6-10.181-25.638-20.176-5.249-10.414-5.724-22.728-1.301-33.784 1.539-3.846-0.332-8.211-4.178-9.749-3.847-1.541-8.211,0.332-9.749,4.178-6.02,15.048-5.351,31.854 1.833,46.107 6.678,13.248 18.373,22.871 33.072,27.311l101.23,107.557c12.602,13.39 14.597,33.63 4.852,49.222l-15.684,25.094c-1.563,2.501-4.258,3.995-7.208,3.995h-138.635c-1.697,0-3.322-0.487-4.701-1.409-52.236-34.918-56.296-106.105-56.296-127.091 0-99.226 73.633-146.037 132.798-183.65 22.698-14.43 42.902-27.274 56.849-41.448 6.455,25.896-5.894,39.212-6.45,39.794-2.929,2.929-2.929,7.678 0,10.606l99.993,99.993c0.722,0.722 1.12,1.683 1.12,2.704s-0.398,1.982-1.12,2.705z"/>
|
||||
<path d="m317.437,104.916c-17.317-9.447-29.686-2.67-38.716,2.278-4.707,2.579-8.772,4.806-12.875,4.806-4.142,0-7.5,3.358-7.5,7.5s3.358,7.5 7.5,7.5c7.943,0 14.392-3.534 20.083-6.651 1.538-0.843 2.997-1.642 4.417-2.348v1.499c0,4.142 3.358,7.5 7.5,7.5s7.5-3.358 7.5-7.5v-3.516c1.536,0.468 3.157,1.145 4.909,2.1 3.637,1.985 8.192,0.644 10.175-2.993 1.983-3.635 0.643-8.191-2.993-10.175z"/>
|
||||
</g>
|
||||
</svg>
|
After Width: | Height: | Size: 3.3 KiB |
@ -21,7 +21,7 @@
|
||||
<wx-data id="data">
|
||||
<files>
|
||||
horse.png horse.jpg horse.bmp horse.gif horse.pcx horse.pnm horse_ag.pnm horse_rg.pnm
|
||||
horse.tif horse.tga horse.xpm horse.cur horse.ico horse3.ani
|
||||
horse.tif horse.tga horse.xpm horse.cur horse.ico horse3.ani horse.svg
|
||||
smile.xbm toucan.png cmyk.jpg cursor.png
|
||||
</files>
|
||||
</wx-data>
|
||||
|
@ -78,6 +78,9 @@ public:
|
||||
void OnAbout( wxCommandEvent &event );
|
||||
void OnNewFrame( wxCommandEvent &event );
|
||||
void OnNewFrameHiDPI(wxCommandEvent&);
|
||||
#ifdef wxHAS_SVG
|
||||
void OnNewSVGFrame(wxCommandEvent&);
|
||||
#endif // wxHAS_SVG
|
||||
void OnImageInfo( wxCommandEvent &event );
|
||||
void OnThumbnail( wxCommandEvent &event );
|
||||
void OnFilters(wxCommandEvent& event);
|
||||
@ -967,6 +970,7 @@ enum
|
||||
ID_ABOUT = wxID_ABOUT,
|
||||
ID_NEW = 100,
|
||||
ID_NEW_HIDPI,
|
||||
ID_NEW_SVG,
|
||||
ID_INFO,
|
||||
ID_SHOWRAW,
|
||||
ID_GRAPHICS,
|
||||
@ -982,6 +986,9 @@ wxBEGIN_EVENT_TABLE(MyFrame, wxFrame)
|
||||
EVT_MENU (ID_QUIT, MyFrame::OnQuit)
|
||||
EVT_MENU (ID_NEW, MyFrame::OnNewFrame)
|
||||
EVT_MENU (ID_NEW_HIDPI, MyFrame::OnNewFrameHiDPI)
|
||||
#ifdef wxHAS_SVG
|
||||
EVT_MENU (ID_NEW_SVG, MyFrame::OnNewSVGFrame)
|
||||
#endif // wxHAS_SVG
|
||||
EVT_MENU (ID_INFO, MyFrame::OnImageInfo)
|
||||
EVT_MENU (ID_SHOWTHUMBNAIL, MyFrame::OnThumbnail)
|
||||
EVT_MENU (ID_FILTERS, MyFrame::OnFilters)
|
||||
@ -1011,6 +1018,9 @@ MyFrame::MyFrame()
|
||||
wxMenu *menuImage = new wxMenu;
|
||||
menuImage->Append( ID_NEW, "&Show any image...\tCtrl-O");
|
||||
menuImage->Append(ID_NEW_HIDPI, "Show any image as &HiDPI...\tCtrl-H");
|
||||
#ifdef wxHAS_SVG
|
||||
menuImage->Append( ID_NEW_SVG, "Show &SVG image...\tCtrl-S");
|
||||
#endif // wxHAS_SVG
|
||||
menuImage->Append( ID_INFO, "Show image &information...\tCtrl-I");
|
||||
#ifdef wxHAVE_RAW_BITMAP
|
||||
menuImage->AppendSeparator();
|
||||
@ -1131,6 +1141,76 @@ void MyFrame::OnNewFrameHiDPI(wxCommandEvent&)
|
||||
new MyImageFrame(this, filename, image, GetContentScaleFactor());
|
||||
}
|
||||
|
||||
#ifdef wxHAS_SVG
|
||||
|
||||
class MySVGFrame : public wxFrame
|
||||
{
|
||||
public:
|
||||
explicit MySVGFrame(wxFrame* parent,
|
||||
const wxString& filename,
|
||||
const wxBitmapBundle& bundle)
|
||||
: wxFrame(parent, wxID_ANY, wxString::Format("SVG image %s", filename),
|
||||
wxDefaultPosition, wxDefaultSize,
|
||||
wxDEFAULT_FRAME_STYLE | wxFULL_REPAINT_ON_RESIZE),
|
||||
m_bundle(bundle)
|
||||
{
|
||||
Bind(wxEVT_PAINT, &MySVGFrame::OnPaint, this);
|
||||
|
||||
SetClientSize(bundle.GetDefaultSize());
|
||||
|
||||
Show();
|
||||
}
|
||||
|
||||
private:
|
||||
void OnPaint(wxPaintEvent&)
|
||||
{
|
||||
wxPaintDC dc(this);
|
||||
|
||||
// Check if the bitmap needs to be re-rendered at the new size. Note
|
||||
// that the bitmap size is in physical pixels, which can be different
|
||||
// from the logical pixels in which the window size is expressed.
|
||||
const wxSize sizeWin = GetClientSize();
|
||||
const wxSize sizeBmp = sizeWin*GetContentScaleFactor();
|
||||
if ( !m_bitmap.IsOk() || m_bitmap.GetSize() != sizeBmp )
|
||||
{
|
||||
m_bitmap = m_bundle.GetBitmap(sizeBmp);
|
||||
}
|
||||
|
||||
// Use wxGraphicsContext if available for alpha support.
|
||||
#if wxUSE_GRAPHICS_CONTEXT
|
||||
wxScopedPtr<wxGraphicsContext> const
|
||||
gc(wxGraphicsRenderer::GetDefaultRenderer()->CreateContext(dc));
|
||||
|
||||
gc->DrawBitmap(m_bitmap, 0, 0, sizeWin.x, sizeWin.y);
|
||||
#else
|
||||
dc.DrawBitmap(m_bitmap, wxPoint(0, 0), true);
|
||||
#endif
|
||||
}
|
||||
|
||||
const wxBitmapBundle m_bundle;
|
||||
wxBitmap m_bitmap;
|
||||
|
||||
wxDECLARE_NO_COPY_CLASS(MySVGFrame);
|
||||
};
|
||||
|
||||
void MyFrame::OnNewSVGFrame(wxCommandEvent&)
|
||||
{
|
||||
const wxString
|
||||
filename = wxLoadFileSelector("SVG document", ".svg", "image", this);
|
||||
if ( filename.empty() )
|
||||
return;
|
||||
|
||||
// The default size here is completely arbitrary, as we don't know anything
|
||||
// about the SVG being loaded.
|
||||
wxBitmapBundle bb = wxBitmapBundle::FromSVGFile(filename, wxSize(200, 200));
|
||||
if ( !bb.IsOk() )
|
||||
return;
|
||||
|
||||
new MySVGFrame(this, filename, bb);
|
||||
}
|
||||
|
||||
#endif // wxHAS_SVG
|
||||
|
||||
void MyFrame::OnUpdateNewFrameHiDPI(wxUpdateUIEvent& event)
|
||||
{
|
||||
event.Enable(GetContentScaleFactor() > 1);
|
||||
|
@ -223,7 +223,7 @@ $(OBJS)\image.exe: $(IMAGE_OBJECTS) $(OBJS)\image_image_rc.o
|
||||
|
||||
data:
|
||||
if not exist $(OBJS) mkdir $(OBJS)
|
||||
for %%f in (horse.png horse.jpg horse.bmp horse.gif horse.pcx horse.pnm horse_ag.pnm horse_rg.pnm horse.tif horse.tga horse.xpm horse.cur horse.ico horse3.ani smile.xbm toucan.png cmyk.jpg cursor.png) do if not exist $(OBJS)\%%f copy .\%%f $(OBJS)
|
||||
for %%f in (horse.png horse.jpg horse.bmp horse.gif horse.pcx horse.pnm horse_ag.pnm horse_rg.pnm horse.tif horse.tga horse.xpm horse.cur horse.ico horse3.ani horse.svg smile.xbm toucan.png cmyk.jpg cursor.png) do if not exist $(OBJS)\%%f copy .\%%f $(OBJS)
|
||||
|
||||
$(OBJS)\image_image.o: ./image.cpp
|
||||
$(CXX) -c -o $@ $(IMAGE_CXXFLAGS) $(CPPDEPS) $<
|
||||
|
@ -568,7 +568,7 @@ $(OBJS)\image.exe: $(IMAGE_OBJECTS) $(OBJS)\image_image.res
|
||||
|
||||
data:
|
||||
if not exist $(OBJS) mkdir $(OBJS)
|
||||
for %f in (horse.png horse.jpg horse.bmp horse.gif horse.pcx horse.pnm horse_ag.pnm horse_rg.pnm horse.tif horse.tga horse.xpm horse.cur horse.ico horse3.ani smile.xbm toucan.png cmyk.jpg cursor.png) do if not exist $(OBJS)\%f copy .\%f $(OBJS)
|
||||
for %f in (horse.png horse.jpg horse.bmp horse.gif horse.pcx horse.pnm horse_ag.pnm horse_rg.pnm horse.tif horse.tga horse.xpm horse.cur horse.ico horse3.ani horse.svg smile.xbm toucan.png cmyk.jpg cursor.png) do if not exist $(OBJS)\%f copy .\%f $(OBJS)
|
||||
|
||||
$(OBJS)\image_image.obj: .\image.cpp
|
||||
$(CXX) /c /nologo /TP /Fo$@ $(IMAGE_CXXFLAGS) .\image.cpp
|
||||
|
Loading…
Reference in New Issue
Block a user