Re: Drawing in separate thread to Gtk::DrawingArea



Hi,

You could create a Cairo::ImageSurface and operate on that from the worker thread. Have additional variables to indicate status of drawing, area updated as member variables of this class. Then use Glib::Dispatcher to notify UI thread when its time to 'Blit' something on to screen. Needless to say it requires additional memory but its far better compared to trying to synchronize worker and UI threads so that they don't end up fighting with each other!

Regards,
Mohith Manoj

On 26-07-2014 22:20, Szőke Szabolcs wrote:
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);
}


_______________________________________________
gtkmm-list mailing list
gtkmm-list gnome org
https://mail.gnome.org/mailman/listinfo/gtkmm-list


Please consider the Environment before printing this e-mail.

The information contained in this message (including any attachments) is confidential and may be privileged or otherwise protected from disclosure.  If you are not the intended recipient, you must not copy this message or attachment or disclose the contents to any other person.  If you have received this transmission in error, please notify the sender immediately by return e-mail and permanently delete this message and any attachments from your system.  Any dissemination, use, review, distribution, printing or copying of this message in whole or in part is strictly prohibited.  Please note that e-mails are susceptible to change.
 
SKANRAY(including its group of companies) shall not be liable for any omission or error in the message, improper or incomplete transmission of the information contained in this communication or for any delay in its receipt or damage to your system.  SKANRAY(or its group of companies) does not guarantee that the integrity of this communication has been maintained or that this communication is free of viruses, interceptions or interference.


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