c++ - Drawing any rectangle to a GTK+ DrawingArea fills the whole DrawingArea -


i have gtk+ drawingarea should display rectangle in top left corner. when draw rectangle using cairo, whole drawing area filled color of rectangle. how can prevent that? why cairo that? doing wrong?

#include <gtkmm.h>  class window : public gtk::window {   private:     gtk::drawingarea area;      bool on_area_expose(gdkeventexpose* event)     {       gtk::allocation allocation = area.get_allocation();       cairo::refptr<cairo::context> context =           area.get_window()->create_cairo_context();       int width = allocation.get_width();       int height = allocation.get_height();       context->set_source_rgba(0, 0, 0, 1);       context->rectangle(0, 0, double(width)/10, double(height)/10);       context->paint();       return true;     }    public:     window() : gtk::window()     {       area.signal_expose_event().connect(         sigc::mem_fun(*this, &window::on_area_expose));       add(area);     } };  int main(int argc, char* argv[]) {   gtk::main app(argc, argv);   window window;   window.show_all();   gtk::main::run(window);   return 0; } 

i compiled code using

g++ gtktest.cpp `pkg-config --libs --cflags gtkmm-2.4` -o gtktest 

context->paint() paints current source everywhere within current clip region. proper method call gtk::context::fill.


Comments

Popular posts from this blog

java - SNMP4J General Variable Binding Error -

windows - Python Service Installation - "Could not find PythonClass entry" -

Determine if a XmlNode is empty or null in C#? -