mirror of
https://github.com/cjcliffe/CubicSDR.git
synced 2026-06-05 07:24:47 -04:00
Better image panel for custom header option
This commit is contained in:
@@ -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 );
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -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()
|
||||
};
|
||||
Reference in New Issue
Block a user