// Created: 1998
// RCS-ID: $Id$
// Copyright: (c) 1998-2005 Robert Roebling
+// (c) 2005-2009 Vadim Zeitlin
// License: wxWindows licence
///////////////////////////////////////////////////////////////////////////////
Create(parent, desc, bitmap);
}
+private:
bool Create(wxFrame *parent,
const wxString& desc,
const wxBitmap& bitmap,
return false;
m_bitmap = bitmap;
+ m_zoom = 1.;
wxMenu *menu = new wxMenu;
menu->Append(wxID_SAVE);
"Uncheck this for transparent images");
menu->AppendSeparator();
menu->Append(ID_RESIZE, _T("&Fit to window\tCtrl-F"));
+ menu->Append(wxID_ZOOM_IN, "Zoom &in\tCtrl-+");
+ menu->Append(wxID_ZOOM_OUT, "Zoom &out\tCtrl--");
+ menu->Append(wxID_ZOOM_100, "Reset zoom to &100%\tCtrl-1");
menu->AppendSeparator();
menu->Append(ID_ROTATE_LEFT, _T("Rotate &left\tCtrl-L"));
menu->Append(ID_ROTATE_RIGHT, _T("Rotate &right\tCtrl-R"));
if ( GetMenuBar()->IsChecked(ID_PAINT_BG) )
ClearBackground();
+ dc.SetUserScale(m_zoom, m_zoom);
+
const wxSize size = GetClientSize();
- dc.DrawBitmap(m_bitmap,
- (size.x - m_bitmap.GetWidth())/2,
- (size.y - m_bitmap.GetHeight())/2,
- true /* use mask */);
+ dc.DrawBitmap
+ (
+ m_bitmap,
+ dc.DeviceToLogicalX((size.x - m_zoom*m_bitmap.GetWidth())/2),
+ dc.DeviceToLogicalY((size.y - m_zoom*m_bitmap.GetHeight())/2),
+ true /* use mask */
+ );
}
void OnSave(wxCommandEvent& WXUNUSED(event))
m_bitmap = wxBitmap(img);
UpdateStatusBar();
- Refresh();
+ }
+
+ void OnZoom(wxCommandEvent& event)
+ {
+ if ( event.GetId() == wxID_ZOOM_IN )
+ m_zoom *= 1.2;
+ else if ( event.GetId() == wxID_ZOOM_OUT )
+ m_zoom /= 1.2;
+ else // wxID_ZOOM_100
+ m_zoom = 1.;
+
+ UpdateStatusBar();
}
void OnRotate(wxCommandEvent& event)
m_bitmap = wxBitmap(img);
UpdateStatusBar();
- Refresh();
}
-private:
void UpdateStatusBar()
{
- wxLogStatus(this, _T("Image size: (%d, %d)"),
+ wxLogStatus(this, _T("Image size: (%d, %d), zoom %.2f"),
m_bitmap.GetWidth(),
- m_bitmap.GetHeight());
+ m_bitmap.GetHeight(),
+ m_zoom);
+ Refresh();
}
wxBitmap m_bitmap;
+ double m_zoom;
DECLARE_EVENT_TABLE()
};
EVT_MENU(wxID_SAVE, MyImageFrame::OnSave)
EVT_MENU_RANGE(ID_ROTATE_LEFT, ID_ROTATE_RIGHT, MyImageFrame::OnRotate)
EVT_MENU(ID_RESIZE, MyImageFrame::OnResize)
+
+ EVT_MENU(wxID_ZOOM_IN, MyImageFrame::OnZoom)
+ EVT_MENU(wxID_ZOOM_OUT, MyImageFrame::OnZoom)
+ EVT_MENU(wxID_ZOOM_100, MyImageFrame::OnZoom)
END_EVENT_TABLE()
//-----------------------------------------------------------------------------
void MyFrame::OnAbout( wxCommandEvent &WXUNUSED(event) )
{
- (void)wxMessageBox( _T("wxImage demo\n")
- _T("Robert Roebling (c) 1998,2000"),
- _T("About wxImage Demo"), wxICON_INFORMATION | wxOK );
+ (void)wxMessageBox( "wxImage demo\n"
+ "(c) Robert Roebling 1998-2005"
+ "(c) Vadim Zeitlin 2005-2009",
+ "About wxImage Demo",
+ wxICON_INFORMATION | wxOK );
}
wxString MyFrame::LoadUserImage(wxImage& image)
wxString filename;
#if wxUSE_FILEDLG
- filename = wxFileSelector(_T("Select image file"));
+ filename = wxLoadFileSelector(_T("image"), wxEmptyString);
if ( !filename.empty() )
{
if ( !image.LoadFile(filename) )
void MyFrame::OnThumbnail( wxCommandEvent &WXUNUSED(event) )
{
#if wxUSE_FILEDLG
- wxString filename = wxFileSelector(_T("Select image file"));
+ wxString filename = wxLoadFileSelector(_T("image"), wxEmptyString, wxEmptyString, this);
if ( filename.empty() )
return;