Re: A simple GdkDrawingArea question



On Fri, 29 Oct 2004 12:26:38 -0400 (EDT), Jack Chen
<jacks_small_world yahoo com> wrote:
> Do you want to draw something in a GtkDrawingArea widget or do you want
> to customize any widget, like specifying its background color,
> mouse-move-in color, or background image?

Basically, I want to create a widget from scratch using a
GtkDrawingArea to do so. Basically is a rectangle of some color (it
depends on the state of the widget) and with some messages in it. I
need some of this controls on my application, so I thought it was a
good idea to create a widget, but creating a true widget it's very
very difficult and I don't know if I'm going to do that. Maybe I'll
add some GtkDrawingArea to the GUI and manage them in the application.

> If you just want to draw/paint something in drawing_area you just use
> many of the functions of gdk_draw_...(). If you want to always have a
> backgound image/rectangle of a certain color or a picture, you can
> create a GdkPixbuf that contains the colored/image_mapped background
> rectangle before hand, and when you want to add something else on top
> of the big rectangle you can first copy the GdkPixbuf to a background
> GdkPixmap (back buffer), then draw those "something" into the pixmap,
> then copy the pixmap onto the screen (widget->window). It won't
> flicker.
> 
> If you want to customize the look of a widget, for example a button,
> you need to create a GtkStyle, get all the colors or background images
> for that "style", and then apply that style to the button. I don't have
> a lot of experiences with GtkStyle because I don't need it for my
> application right now, but I'll need it in the future.
> 
> GtkStyle's reference is at
> 
> http://developer.gnome.org/doc/API/2.0/gtk/GtkStyle.html#gtk-style-new
> 
> I know Gtk's reference sucks because it neglects a lot of things, like
> GtkStyle. The information I got about GtkStyle is from the book
> "Gnome/Gtk+ Programming Bible, by Arthur Griffith". After reading that
> I could specify the foreground/background/mouse-enter color and
> background image of a widget, though I don't have any more experience
> in that area.
> 
> I did some search for you. For any drawings you need a GdkGC. To create
> a GdkGC you can use either of the 2 methods:
> 
> 1. gdk_gc_new_with_values ();
> 2. gdk_gc_new ();
>    then
>    gdk_gc_set_foreground ();
>    gdk_gc_set_background ();
>    ....
I tried that. My problem is that, being new in Gtk, I don't know
nothing about colormaps. That was the problem. Those two functions
don't work if the color you're using is not on the colormap of the
graphic context (by the way, I don't know what's a colormap). Using
gdk_gc_set_rgb_fg did the work.

> I don't like that many steps, as you need to dig deeper and deeper to
> get everything you want, but that's the way I learned Gtk, and I think
> that's how all other people learn it, too, considering its
> documentation is so broken.
> 
> GdkGC's reference is here
> 
> http://developer.gnome.org/doc/API/2.0/gdk/gdk-Graphics-Contexts.html#GdkGC
> 
> By the way, you said you were using Cairo and GtkCairo. Do you know if
> they have a premade binary for Win32 or does everything have to be
> compiled from source? I am interested in using vector graphics in my
> own application.

I only have seen it for Linux. Looking to the mailing list of Cairo,
I've seen that there is no Win32 binaries yet and that nobody has got
it working on Mingw. The problem is that there is no backend for
win32, only for xlibs, glitz (those are the only two supported by
GtkCairo) and some more but there are plans to release a version of
Cairo using Win32 backend.

> Thank you.
> 
> Jack
> 
> 
> 
> 
>  --- José Antonio Sánchez <getaceres gmail com> wrote:
> > The problem with the first is that:
> >
> > gdk_draw_arc (widget->window,
> >                 widget->style->fg_gc[GTK_WIDGET_STATE (widget)],
> >                 TRUE,
> >                 0, 0, widget->allocation.width,
> > widget->allocation.height,
> >                 0, 64 * 360);
> >
> > They use a premade graphic context:
> > widget->style->fg_gc[GTK_WIDGET_STATE (widget)]
> >
> > But not a custom graphic context with a custom color.
> > On the second, to draw a rectangle:
> >
> > void        gdk_draw_rectangle              (GdkDrawable *drawable,
> >                                              GdkGC *gc,
> >                                              gboolean filled,
> >                                              gint x,
> >                                              gint y,
> >                                              gint width,
> >                                              gint height);
> >
> > I need a pointer to a graphic context and that's my problem. I don't
> > know how to create a custom graphic context. I don't know how to
> > parse
> > a foreground or background color to the graphic context, because as I
> > said, the gdk_gc_set_foreground and gdk_gc_set_background calls
> > aren't
> > working like I think they must work and I don't know what I'm doing
> > wrong.
> > I can't find a good example of drawing using a custom color and not a
> > graphic context that is on gtk like widget->style->something.
> >
> 
> 
> ______________________________________________________________________
> 
> 
> Post your free ad now! http://personals.yahoo.ca
>



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