Drawing in one timer
- From: "BC Zhu" <zhubicen gmail com>
- To: gtkmm-list <gtkmm-list gnome org>
- Subject: Drawing in one timer
- Date: Sat, 6 Dec 2008 23:53:45 +0800
When i drawing something in one timer, error occoured.
glibmm:error: Unhandled exception(type std::exception) in signal handler.
I used following code to reproduce the error.
I am wondering about the reason of this error.Could someone help me?
#include <gtkmm/drawingarea.h>
#include <gtkmm/main.h>
#include <gtkmm/window.h>
#include <cairomm/context.h>
#include <iostream>
class MyArea : public Gtk::DrawingArea
{
public:
MyArea();
virtual ~MyArea();
protected:
virtual bool on_expose_event(GdkEventExpose* event);
private:
typedef Cairo::RefPtr<Cairo::Context> CR;
CR cr_;
class Chess
{
public:
Chess(CR);
bool on_timer(CR);
};
Chess* pChess_;
};
MyArea::MyArea()
{
}
MyArea::~MyArea()
{
}
MyArea::Chess::Chess(CR cr)
{
sigc::slot<bool> timer_slot =sigc::bind(
sigc::mem_fun(*this, &MyArea::Chess::on_timer), cr);
sigc::connection conn = Glib::signal_timeout().connect(timer_slot,
1000);
}
bool MyArea::Chess::on_timer(CR cr)
{
static int x = 0;
static int y = 0;
std::cout << "on_timer:(" << x << ", " << y << ")" << std::endl;
cr->move_to(x, 0);
cr->line_to(x++, y++);
cr->stroke();
return true;
}
bool MyArea::on_expose_event(GdkEventExpose* event)
{
Glib::RefPtr<Gdk::Window> window = get_window();
Cairo::RefPtr<Cairo::Context> cr = window->create_cairo_context();
pChess_ = new Chess(cr);
return true;
}
int main(int argc, char** argv)
{
Gtk::Main kit(argc, argv);
Gtk::Window win;
win.set_title("DrawingArea");
MyArea area;
win.add(area);
area.show();
Gtk::Main::run(win);
return 0;
}
--
Best Regards
Bicen.Zhu
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]