wxWidgets如何才能正确的调用OnPaint函数进行绘图?
界面的结构如下:wxFrame-wxBoxSizer-DrawablePanel。其中,DrawablePanel是我单独分离出来的,继承自wxScrollWindow,主要是想在这个Panel上进行图片的绘制,并且共享给其他类使用。但是现在出了一个问题,OnPaint函数总是无法被调用,从而使得绘图工作无法正常进行。
哪位给看看如何才能实现OnPaint函数周期调用的问题。另外还有一个疑问,wxWindows有没有一个函数,只要子类重写了这个函数,父类就自动调用,而不是添加事件处理(就像Java里的Paint函数一样)?
相关代码如下:
drawablepanel.h
drawablepanel.cpp
哪位给看看如何才能实现OnPaint函数周期调用的问题。另外还有一个疑问,wxWindows有没有一个函数,只要子类重写了这个函数,父类就自动调用,而不是添加事件处理(就像Java里的Paint函数一样)?
相关代码如下:
drawablepanel.h
#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__
drawablepanel.cpp
#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();
}
...全文
相关推荐
在CodeBlocks中用wxWidgets创建不规则窗口
NULL 博文链接:https://emonkey.iteye.com/blog/1620417
wxWidgets嵌入CEF3的源码,以及JavaScript调用C++代码
由于项目中用到了wxWidgets,并且需要嵌入CEF3,经过一番研究终于搞定了,这里上传源码,以供需要的朋友下载,由于代码量不大wxWebVeiw和CEF的几个类都放到了同一个.h和.cpp文件中
wxWidgets教程(中文)
wxWidgetsGUI《Cross-Platform GUI Programming with wxWidgets》的清晰中文版
wxWidgets实现图片和文件按钮
主要为大家详细介绍了wxWidgets实现图片和文件按钮,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
使用wxwidgets进行跨平台程序开发(中文版)_wxWidgets学习_wxWidgets_
这是一部学习wxWidgets的基础文档,能够让你快速的学习


