wxWidget实现连续绘图并能够控制绘图的开始与结束(四)

2014-11-24 11:51:20 · 作者: · 浏览: 7
us bar with some information about the used wxWidgets version
80: CreateStatusBar(2);
81: SetStatusText(_("Hello Code::Blocks user!"),0);
82: SetStatusText(wxbuildinfo(short_f), 1);
83: #endif // wxUSE_STATUSBAR
84:
85: timer = new RenderTimer(this);
86: }
87:
88:
89: tmp1Frame::~tmp1Frame()
90: {
91: delete timer;
92: }
93:
94: void tmp1Frame::OnClose(wxCloseEvent &event)
95: {
96: Destroy();
97: }
98:
99: void tmp1Frame::OnQuit(wxCommandEvent &event)
100: {
101: Destroy();
102: }
103:
104: void tmp1Frame::OnAbout(wxCommandEvent &event)
105: {
106: wxString msg = wxbuildinfo(long_f);
107: wxMessageBox(msg, _("Welcome to..."));
108: }
109:
110: // set render_loop_on true, make OnIdle can draw text
111: void tmp1Frame::OnStartLoop(wxCommandEvent& event)
112: {
113: timer->StartLoop();
114: }
115:
116: // set render_loop_on true, make OnIdle can skip draw text
117: void tmp1Frame::OnStopLoop(wxCommandEvent& event)
118: {
119: timer->StopLoop();
120: }
121:
122: void tmp1Frame::PaintNow()
123: {
124: wxClientDC dc(this);
125: render(dc);
126: }
127:
128: // draw text on screen
129: void tmp1Frame::render(wxDC& dc)
130: {
131: static int y = 0;
132: static int y_speed = 2;
133:
134: y += y_speed;
135: if (y < 0) y_speed = 2;
136: if (y > 200) y_speed = -2;
137:
138: dc.SetBackground(*wxWHITE_BRUSH);
139: dc.Clear();
140: dc.DrawText(wxT("Testing"),40,y);
141: }
renderTimer.h

1: /***************************************************************
2: * Name: renderTimer.h
3: * Purpose: used for onTimer
4: * Author: grass in moon
5: * Created: 2012-07-06
6: * Copyright: grass in moon (http://www.cppblog.com/grass-and-moon/)
7: * License:
8: **************************************************************/
9:
10: #ifndef RENDERTIMER_H_INCLUDED
11: #define RENDERTIMER_H_INCLUDED
12:
13: class tmp1Frame;
14:
15: class RenderTimer : public wxTimer
16: {
17: tmp1Frame* tmpFrame;
18: public:
19: RenderTimer(tmp1Frame* tmpFrame);
20: void Notify();
21: void StartLoop();
22: void StopLoop();
23: };
24:
25: #endif // RENDERTIMER_H_INCLUDED
renderTimer.cpp

1: /***************************************************************
2: * Name: renderTimer.cpp
3: * Purpose: used for onTimer
4: * Author: grass in moon
5: * Created: 2012-07-06
6: * Copyright: grass in moon (http://www.cppblog.com/grass-and-moon/)
7: * License:
8: **************************************************************/
9: #include "tmp1Main.h"
10: #include "renderTimer.h"
11:
12: RenderTimer::RenderTimer(tmp1Frame* tmpFrame)
13: {
14: this->tmpFrame = tmpFrame;
15: }
16:
17: // perform the draw text action
18: void RenderTimer::Notify()
19: {
20: tmpFrame->PaintNow();
21: }
22:
23: // set the interval time is 10 ms
24: void RenderTimer::StartLoop()
25: {
26: wxTimer::Start(10);
27: }
28:
29: void RenderTimer::StopLoop()
30: {
31: wxTimer::Stop();
32: }