Better image panel for custom header option

This commit is contained in:
Charles J. Cliffe
2016-11-01 22:29:58 -04:00
parent 979e5b709c
commit f0d829b6b3
6 changed files with 91 additions and 11 deletions
+50
View File
@@ -0,0 +1,50 @@
#include "ImagePanel.h"
BEGIN_EVENT_TABLE(ImagePanel, wxPanel)
EVT_PAINT(ImagePanel::paintEvent)
END_EVENT_TABLE()
ImagePanel::ImagePanel(wxPanel * parent, wxString file, wxBitmapType format) :
wxPanel(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxFULL_REPAINT_ON_RESIZE) {
image.LoadFile(file, format);
}
void ImagePanel::paintEvent(wxPaintEvent & evt) {
wxPaintDC dc(this);
render(dc);
}
void ImagePanel::paintNow() {
wxClientDC dc(this);
render(dc);
}
void ImagePanel::render(wxDC& dc) {
double imagew = image.GetWidth();
double imageh = image.GetHeight();
wxSize destSize = dc.GetSize();
double destw = destSize.GetWidth();
double desth = destSize.GetHeight();
double sf = 1.0, wf, hf;
wf = destw / imagew;
hf = desth / imageh;
sf = (wf < hf)?wf:hf;
double resulth = imageh * sf;
double resultw = imagew * sf;
dc.SetUserScale(sf, sf);
dc.DrawBitmap( image, (destw/2 - resultw/2)/sf, (desth/2 - resulth/2)/sf, false );
}
+16
View File
@@ -0,0 +1,16 @@
#include <wx/wx.h>
#include <wx/sizer.h>
class ImagePanel : public wxPanel {
wxBitmap image;
public:
ImagePanel(wxPanel* parent, wxString file, wxBitmapType format);
void paintEvent(wxPaintEvent & evt);
void paintNow();
void render(wxDC& dc);
DECLARE_EVENT_TABLE()
};