On Drawing a Red Line
- From: Derrick Williams <adw derrickwilliams com>
- To: gtk-list redhat com
- Subject: On Drawing a Red Line
- Date: Wed, 3 Nov 1999 22:20:41 -0500 (EST)
Hello!
I have just started to learn how to use gtk--, and I have run into
a small puzzle, and it is my hope that the finest human beings on
the planet, all of which read this mailing list, may shine some
illumination on the problem I am experiencing.
As a test, I wrote a little program which draws a line in a window.
If I stick with the black or white graphics context, it works just
fine. The problem is that, because of weak moral character and
unsolvenly upbringing, I would like to draw the same line in color.
In my case, a red line.
Here is the class I wrote, called 'RedLine', which is the result of
my poor deductive skills and slow comprehension, and questionable
programming skills. As you may see, there is probably something I am
doing terribly wrong. I would be interested if I'm taking the wrong
approach in drawing my line, or of any boneheaded code I am writing.
Here, I attempt to allocate a new color (red), and set the 'fg'
(foreground) color to red, and draw the line. I do not get a red
line, just the black background. You will note that if you uncomment
the line where I reference the 'white_gc', the program works and I
see the white line.
---------------------------- RedLine: ----------------------------------
#include <gtk--.h>
#include <gdk--.h>
#include <gtk/gtk.h>
class RedLine : public Gtk_Window{
public:
Gdk_Pixmap pixmap;
Gdk_GC gc;
configure_event_impl (GdkEventConfigure *){
if(pixmap){
pixmap.free();
}
pixmap.create(get_window(),500,500);
draw_a_line();
return TRUE;
}
draw_a_line(){
GdkColor red={0,0x555,0,0};
Gdk_Color new_color(&red);
Gdk_Colormap sysmap;
sysmap=Gdk_Colormap::get_system();
sysmap.alloc(new_color);
gc = get_style()->gtkobj()->black_gc;
pixmap.draw_rectangle(gc,TRUE,0,0,500,500);
get_style()->set_fg(GTK_STATE_NORMAL,red);
gc = get_style()->gtkobj()->fg_gc[GTK_STATE_NORMAL];
// If the next line is uncommented, a white line is drawn
// gc = get_style()->gtkobj()->white_gc;
pixmap.draw_line(gc,10,100,180,100);
get_window().draw_pixmap(gc,pixmap,0,0,0,0,500,500);
}
expose_event_impl(GdkEventExpose *event){
gc = get_style()->gtkobj()->fg_gc[GTK_WIDGET_STATE(GTK_WIDGET(gtkobj()))];
get_window().draw_pixmap(gc,pixmap,
event->area.x, event->area.y,
event->area.x, event->area.y,
event->area.width, event->area.height);
return FALSE;
}
RedLine(){
//set the events to listen for
set_events(GDK_EXPOSURE_MASK);
}
};
int main( int argc, char **argv )
{
Gtk_Main m( &argc, &argv );
RedLine w;
w.show();
m.run();
return 0;
}
-----------------------------END--------------------------------------------
The above is compiled with:
gcc `gnome-config gnomemm --cflags` redline.C `gnome-config gnomemm --libs` -o redline
No error messages or warnings appear.
I am using RedHat 6.1, with the stock GDK that came with it. I am using
gtk-- 1.03, and there are no modifications I made to any of the libraries.
Any help or pointers to references would be much appreciated.
I remain,
Derrick Williams
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]