Re: Implementing a LED-like widget



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);

As far as I can tell your constructor should be ok ...


The method setting the LED in on-state:

From the nature of the code, I think you are calling this in on_realize() ...


     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 as far as I know, you should only do

//////////////////////////////////////////////////////////////////////////////////////////////////
Glib::RefPtr<Gdk::Window> win = display->get_window();
Glib::RefPtr<Gdk::GC> gc = Gdk::GC::create(win);
gc->set_foreground(Gdk::Color("Yellow"));
//////////////////////////////////////////////////////////////////////////////////////////////////

in your overiden version of Gtk::DrawingArea::on_realize().
Assuming that gc is a member variable, calling

//////////////////////////////////////////////////////////////////////////////////////////////////
int width, height;
Glib::RefPtr<Gdk::Window> win = display->get_window();
win->get_size(width, height);
win->draw_rectangle(gc, true, 0, 0, width, height);
/////////////////////////////////////////////////////////////////////////////////////////////////
from your version of Gtk::DrawingArea::on_expose_event(GdkEventExpose*)
should have the desired effect.

Antonio


----------------------------------

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 <mailto:>
http://mail.gnome.org/mailman/listinfo/gtkmm-list





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