Re: Implementing a LED-like widget



Oops, forgot to CC to everyone.

***********************************************************************

Marcus,

Can you possibly post more code?   In particular, where does the second
code fragment reside?  Is it called from on_realize() or on_expose_event()?

Drawing should normally be done in on_expose_event(...), whereas the first four
lines should most likely belong to on_realize.  Please remember that the sizes
are not defined until your widget has been realized.

This might just be my personal opinion, but why use DrawingArea at all rather
than draw on the window directly?  DrawingArea has little, if any, additional
functionality, so you can easily emulate it yourself.


Regards,

Nickolai
> 
> 
> 
> On Mon, Aug 22, 2005 at 08:28:57PM +0200, Marcus Lundblad wrote:
> > I'm trying to implement a widget simulating a LED.
> > What I have is a widget derived from Gtk::Frame (with style SHADOW_IN).
> > This frame holds a Gtk::DrawingArea (display in the follwing code..)
> > 
> > I have the following code intended to turn the inside of the widget yellow 
> > (as an example).
> > 
> > --------------------------------
> > 
> > Constructor contains this:
> > 
> >   set_shadow_type(Gtk::SHADOW_IN);
> >   set_size_request(10,10);
> >   display = new Gtk::DrawingArea;
> >   display->set_size_request(8,8);
> >   add(*display);
> > 
> > The method setting the LED in on-state:
> > 
> >     int width, height;
> >     Glib::RefPtr<Gdk::Window> win = display->get_window();
> >     win->get_size(width, height);
> >     Glib::RefPtr<Gdk::GC> gc = Gdk::GC::create(win);
> >     gc->set_foreground(Gdk::Color("Yellow"));
> >     win->draw_rectangle(gc, true, 0, 0, width, height);
> > 
> > ----------------------------------
> > 
> > but nothing happens when calling the code to turn it on.
> > And by the way, I've set the minimum size of the frame and the drawing 
> > area using set_size_request.
> > 
> > Isn't this the correct way of using a Gtk::DrawingArea?
> > It seems to me not too far from the example code "example_drawingarea.cc".
> > 
> > //Marcus
> > _______________________________________________
> > gtkmm-list mailing list
> > gtkmm-list gnome org
> > http://mail.gnome.org/mailman/listinfo/gtkmm-list



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