Re: Pixel



KOUACH Mustapha wrote:
> 
> Hi,
>         How can I put a pixel using Gtk and C under Linux.
>         Thanks every body.

Since Gtk is a widget toolkit, you don't just plot a pixel in a window;
you need to create an area into which you can draw. This is called,
strangely enough, a GtkDrawingArea. Once you have a drawing area, you
can use the GDK drawing primitives on this area. These primitives
include gdk_draw_line, gdk_draw_arc, and the function you need,
gdk_draw_point.

The following is a cheap and nasty example;
---------------
#include <gtk/gtk.h>

int main(int argc, char *argv[])
{
   GtkWidget *darea;
   GtkWidget *window;

   gtk_init(&argc,&argv);

   window = gtk_window_new(GTK_WINDOW_TOPLEVEL);

   darea = gtk_drawing_area_new();
   gtk_container_add (GTK_CONTAINER (window), darea);

   gtk_widget_show(darea);
   gtk_widget_show(window);

   gdk_draw_point(darea->window,darea->style->black_gc,10,20);   

   gtk_main();

   return 0;
}
-----------

This will create a window, add a drawing area to it, and draw a black
pixel at coordinates x=10, y=20 within this area. Be warned; this is a
trivial example - the black pixel will not be remembered if you obscure
the parent window. 

The easiest way to do this is to create a backing pixmap, draw to that,
and use expose events to render the backing pixmap to the drawing_area.
Check the API pages on gtk_drawing_area to find out how to do this. They
can be found at:

http://developer.gnome.org/doc/API/gtk/gtkdrawingarea.html

Enjoy,
Russ Magee

-- 
-----------------------------------------------------------
Russell Keith-Magee
PhD Research Student
School of Computing, Curtin University of Technology
email: keithmag cs curtin edu au OR russ magee computer org
WWW:   http://www.cs.curtin.edu.au/~keithmag
Ph: +61 8 9266 2129    FAX +61 8 9266 2819
-----------------------------------------------------------
The future lies ahead.




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