wxGrid支持动画播放的自定义wxGridCellRenderer实现 Topic is solved

这是wxWidgets论坛的中文版本。在这里,您可以用您的母语汉语讨论上面任一子论坛所涉及的所有关于wxWidgets的话题。欢迎大家参与到对有价值的帖子的中英互译工作中来!
Post Reply
kingkamg
I live to help wx-kind
I live to help wx-kind
Posts: 187
Joined: Tue Apr 08, 2008 1:45 pm

wxGrid支持动画播放的自定义wxGridCellRenderer实现

Post by kingkamg » Fri Dec 12, 2008 2:20 am

想在wxGrid的某个cell里面实现一个动画效果,继承wxGridCellRenderer重载
virtual void Draw(wxGrid& grid,wxGridCellAttr& attr,wxDC& dc,const wxRect& rect,int row, int col,bool isSelected);这个方法,动画的图像数据是通过wxAnimation来获得的,因为要让图片动起来,需要不断的刷新单元格,为此又继承了wxEvtHandler并加入wxTimer对象来通过刷新单元格实现动画,单计时器的事件除了第一次收到外,其他时候均未收到,实在想不明白是什么原因导致,对于想在某个单元格里面增加动画显示,大家谁有好的建议和思路吗?

Code: Select all

#include <wx/grid.h>
#include <wx/animate.h>

class GridCellAnimationRenderer :
	public wxGridCellRenderer, public wxEvtHandler
{
	DECLARE_EVENT_TABLE()
public:
	GridCellAnimationRenderer( wxGrid* pGrid = NULL );
public:
	~GridCellAnimationRenderer(void);

public:
	virtual void Draw(wxGrid& grid,
		wxGridCellAttr& attr,
		wxDC& dc,
		const wxRect& rect,
		int row, int col,
		bool isSelected);

	virtual wxSize GetBestSize(wxGrid& grid,
		wxGridCellAttr& attr,
		wxDC& dc,
		int row, int col){ return wxSize(50,10); }

	virtual GridCellAnimationRenderer *Clone() const
	{ return new GridCellAnimationRenderer; }

	virtual void Stop();

private:
	void OnTimer(wxTimerEvent& event);

	void DisposeToBackground();
	void DisposeToBackground(wxDC& dc);
	void DisposeToBackground(wxDC& dc, const wxPoint &pos, const wxSize &sz);

	void IncrementalUpdateBackingStore();
	bool RebuildBackingStoreUpToFrame(unsigned int);
	void DrawFrame(wxDC &dc, unsigned int);

	void DrawCurrentFrame(wxDC& dc);

protected:
	unsigned int  m_currentFrame;     // Current frame
	bool          m_looped;           // Looped, or not
	wxTimer       m_timer;            // The timer
	wxAnimation   m_animation;        // The animation

	bool          m_isPlaying;        // Is the animation playing?
	bool          m_useWinBackgroundColour; // Use animation bg colour or window bg colour?

	wxBitmap      m_backingStore;     // The frames are drawn here and then blitted

	wxGrid* m_pGrid;
	wxRect  m_Rect;

};
:o

Utensil
Moderator
Moderator
Posts: 423
Joined: Sun Feb 03, 2008 11:38 am
Location: China

Post by Utensil » Sun Dec 14, 2008 8:42 am

请问你是如何调用m_timer的Start()的?是否不小心设置了oneShot?

-Utensil
In fascination of creating worlds by words, and in pursuit of words behind the world.

On Github: http://utensil.github.com
Technical Blog in Chinese: http://utensil.iteye.com/

kingkamg
I live to help wx-kind
I live to help wx-kind
Posts: 187
Joined: Tue Apr 08, 2008 1:45 pm

Post by kingkamg » Mon Dec 15, 2008 2:39 am

其实老外已经给出了解答,在grid里面做计时器刷新,不用单元格内刷新,仔细想想也对,我前面是想每个单元格都独立的动画,不过后来发现消息接受会有问题,唉,可能是哪里代码写错了

Post Reply