Drawing in separate thread to Gtk::DrawingArea



Hi everybody. I found the tutorial on gtkmm developer page about multi-threading. But when I wanted to adapt for my needs, I couldn't figure out how to do it. I have a DrawingArea widget within a window and I want to do the drawing in separate thread because as the drawing became more complex, the gui thread gets locked every time when something is drawn. I know the theory: I should use a Dispatcher to send the data to gui thread, but in tutorial I saw that when the worker thread completed the job, the gui thread is notified. But I can't do that, or at least I don't know how to do that in this situation. Any help will be appreciated.

Here is the code:

#include <gtkmm.h>

class DrawingArea : public Gtk::DrawingArea
{
public:
DrawingArea()
{
this->set_hexpand();
this->set_vexpand();
}
~DrawingArea() {};
protected:
bool on_draw(const Cairo::RefPtr<Cairo::Context>& context)
{
// drawing stuff
return true;
}
};

class Window : public Gtk::Window
{
public:
Window()
{
this->set_default_size(800, 600);
this->add(this->m_drawing_area);
}
~Window() {};
protected:
DrawingArea m_drawing_area;
};

int main(int argc, char* argv[])
{
Glib::RefPtr<Gtk::Application> application = Gtk::Application::create(argc, argv, "org.draw_in_separate_thread");
Window window;
return application->run(window);
}


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]