I'm developing a graphic software with GTK+ (gtkmm) and want to build a free hand drawing feature.
I connect to the signal_motion_notify_event
on a Gtk::EventBox
and set set_event_compression
to false
on the event box. I also set set_event_compression(false)
on the window containing the event box, but nothing seems to work. The program is not running so fluently that it would allow drawn trough lines, instead I get multiple single dots or short dashes.
I also tried using Gdk::Window::get_pointer(int,int,Gdk::ModifierType)
in an extra thread
, but this doesn't work either (no drawn through lines also).
Here is some example code to illustrate (I use Gtk::Image
-class to draw the a pixbuf):
Toolbox.cc
// eb means EventBox
Gtk::EventBox& eb = drawingWin->getEventBox();
eb.signal_motion_notify_event().connect(sigc::mem_fun(image, &Image::motionEvent));
DrawingWindow.cc
DrawingWindow::DrawingWindow(int x, int y) : area(x, y), background("/home/tux/Pictures/Arch_Linux_Wallpaper_by_james66.jpg")
{
// eb means EventBox
eb.get_window()->set_event_compression(false);
}
Image.cc
bool Image::motionEvent(_GdkEventMotion* event)
{
if(event)
{
mutex.lock();
//custom set_pixel function on Gdk::Pixbuf using guint8* Gdk::Pixbuf::get_pixels() const
this->set_pixel(event->x, event->y, 0x000000ff);
//updates the Gtk::Image by calling Gtk::Image::set(Glib::RefPtr<Gdk::Pixbuf>)
this->_udpate();
mutex.unlock();
}
}