Re: Implementing a LED-like widget



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

I think you have to allocate color before you can use it, there is how
you do it at:
http://gtkmm.org/docs/gtkmm-2.4/docs/tutorial/html/ch14.html

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



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