64,282
社区成员
发帖
与我相关
我的任务
分享
#ifndef __DRAWABLE_PANEL_H__
#define __DRAWABLE_PANEL_H__
#include <wx/scrolwin.h>
#include <wx/bitmap.h>
class DrawablePanel : public wxScrolledWindow
{
public:
DrawablePanel();
~DrawablePanel();
void SetImage(wxBitmap& img);
void SetZoom(int zoom);
int GetZoom();
void SetGridVisible(bool visible);
bool GetGridVisible();
void RefreshNotify();
protected:
void OnPaint(wxPaintEvent& event);
private:
wxBitmap image;
wxBitmap bufferImage;
int zoomLevel ;
bool isGridVisible;
DECLARE_EVENT_TABLE()
};
#endif //__DRAWABLE_PANEL_H__
#include "drawablepanel.h"
BEGIN_EVENT_TABLE(DrawablePanel,wxScrolledWindow)
EVT_PAINT(DrawablePanel::OnPaint)
END_EVENT_TABLE()
DrawablePanel::DrawablePanel() : wxScrolledWindow()
{
zoomLevel = 0;
isGridVisible = false;
}
DrawablePanel::~DrawablePanel()
{
}
void DrawablePanel::SetImage(wxBitmap& img)
{
image = img;
RefreshNotify();
}
void DrawablePanel::SetGridVisible(bool visible)
{
if(isGridVisible != visible)
{
isGridVisible = visible;
RefreshNotify();
}
}
bool DrawablePanel::GetGridVisible()
{
return this->isGridVisible;
}
void DrawablePanel::SetZoom(int zoom)
{
int newZoom = zoomLevel + zoom;
if(zoomLevel != newZoom)
{
zoomLevel = newZoom;
RefreshNotify();
}
}
int DrawablePanel::GetZoom()
{
return this->zoomLevel;
}
void DrawablePanel::OnPaint(wxPaintEvent& event)
{
wxMessageBox(wxT("重绘图!"));
wxPaintDC dc(this);
dc.DrawBitmap(image,0,0,true);
}
void DrawablePanel::RefreshNotify()
{
Refresh(true);
Update();
}