Trouble with drawing area
- From: Valery Avaux <vavaux ulb ac be>
- To: "gtk-list gnome org" <gtk-list gnome org>, "glade-users helixcode com" <glade-users helixcode com>
- Subject: Trouble with drawing area
- Date: Thu, 12 Apr 2001 21:43:12 +0200
Hello,
I currently trying to put two drawing area on a main window of a project
genrated by Glade.
The first area works fine but when I program the second one, it shows
the same as the first one. The only call for the second drawing area is
a call to "trace" in a function located in callbacks.c
Here is the code of the main.c I used
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <gtk/gtk.h>
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include "interface.h"
#include "support.h"
#include "callbacks.h"
#include <gdk/gdk.h>
/* variables globales du programme */
int matrice[102][102][102];
long int nbsweep = 10000;
int nbflip = 10;
int genre = 1;
int tx = 20;
int ty = 20;
int tz = 20;
int slide = 1;
float temp = 50.0;
float field =0.;
gboolean interrupt = FALSE;
GtkWidget *window1;
GtkWidget *area,*area2;
GdkPixmap *pixmap = NULL; /* offscreen drawable */
GdkGC *gc = NULL;
GdkColor blue;
GdkColor red;
GdkColor white;
GdkColor grey;
GdkColor black;
void allocate_colors(GtkWidget *);
void repaint(GtkWidget *);
void repaint2(GtkWidget *);
int configure_event(GtkWidget *, GdkEventConfigure *);
int expose_event(GtkWidget *, GdkEventExpose *);
gboolean on_graphs_expose_event (GtkWidget *widget,
GdkEventExpose *event,
gpointer user_data);
gboolean on_graphs_configure_event (GtkWidget *widget,
GdkEventConfigure *event,
gpointer user_data);
void repaintclear(GtkWidget *area2);
void trace(GtkWidget *area2, int i, int j);
int
main (int argc, char *argv[])
{
GtkWidget *temper;
GtkWidget *magnfield;
GtkWidget *kind;
GtkWidget *current;
#ifdef ENABLE_NLS
bindtextdomain (PACKAGE, PACKAGE_LOCALE_DIR);
textdomain (PACKAGE);
#endif
gtk_set_locale ();
gtk_init (&argc, &argv);
add_pixmap_directory (PACKAGE_DATA_DIR "/pixmaps");
add_pixmap_directory (PACKAGE_SOURCE_DIR "/pixmaps");
initmat();
window1 = create_window1 ();
gc=NULL;
temper = lookup_widget (window1, "tempsc");
magnfield = lookup_widget (window1, "hscale2");
current = lookup_widget (window1, "spinbutton6");
kind = lookup_widget (window1, "combo1");
area = lookup_widget (window1, "drawingarea1");
area2 = lookup_widget (window1, "graphs");
gtk_signal_connect (GTK_OBJECT (GTK_RANGE(temper) -> adjustment),
"value_changed", GTK_SIGNAL_FUNC ( on_tempsc_value_changed), temper);
gtk_signal_connect (GTK_OBJECT (GTK_RANGE(magnfield) -> adjustment),
"value_changed", GTK_SIGNAL_FUNC (on_hscale2_value_changed),magnfield);
gtk_signal_connect (GTK_OBJECT (GTK_SPIN_BUTTON(current) ->
adjustment), "value_changed", GTK_SIGNAL_FUNC (
on_current_value_changed), current);
gtk_signal_connect (GTK_OBJECT (GTK_COMBO(kind)-> entry),"activate",
GTK_SIGNAL_FUNC(on_combo_entry1_changed),NULL);
gtk_signal_connect(GTK_OBJECT(area), "expose_event",(GtkSignalFunc)
expose_event, NULL);
gtk_signal_connect(GTK_OBJECT(area), "configure_event",(GtkSignalFunc)
configure_event, NULL);
gtk_signal_connect (GTK_OBJECT (area),"realize",GTK_SIGNAL_FUNC
(repaint),NULL);
gtk_signal_connect(GTK_OBJECT(area2), "expose_event",(GtkSignalFunc)
on_graphs_expose_event, NULL);
gtk_signal_connect(GTK_OBJECT(area2),
"configure_event",(GtkSignalFunc) on_graphs_configure_event, NULL);
gtk_signal_connect (GTK_OBJECT (area2),"realize",GTK_SIGNAL_FUNC
(repaintclear),NULL);
gtk_widget_show (window1);
gtk_main ();
return 0;
}
void init_colors(GtkWidget *area)
{
GdkColormap *colormap;
colormap = gtk_widget_get_colormap(area);
if (!colormap)
exit(1);
blue.red = 0;
blue.green = 0;
blue.blue = 0xff * 0x100;
gdk_colormap_alloc_color(colormap, &blue, FALSE, TRUE);
red.red = 0xff * 0x100;
red.green = 0;
red.blue = 0;
gdk_colormap_alloc_color(colormap, &red, FALSE, TRUE);
white.red = 0xff * 0x100;
white.green = 0xff * 0x100;
white.blue = 0xff * 0x100;
gdk_colormap_alloc_color(colormap, &white, FALSE, TRUE);
grey.red = 112 * 0x100;
grey.green = 128 * 0x100;
grey.blue = 144 * 0x100;
gdk_colormap_alloc_color(colormap, &grey, FALSE, TRUE);
black.red = 0;
black.green = 0;
black.blue = 0;
gdk_colormap_alloc_color(colormap, &white, FALSE, TRUE);
}
void repaint(GtkWidget *area)
{
int i, j;
GdkColor *color;
for (i =1 ; i < tx+1; i++)
for (j = 1; j < ty+1; j++) {
color = (matrice[i][j][slide] == 1) ? &red : &blue;
gdk_gc_set_foreground(gc, color);
gdk_draw_rectangle(pixmap, gc, TRUE,
(i-1) * 400/tx, (j-1) * 400/ty , 400/tx ,400/ty
);
}
gdk_draw_pixmap( area->window,
area->style->fg_gc[GTK_WIDGET_STATE(area)],
pixmap, 0, 0, 0, 0,
area->allocation.width, area->allocation.height );
}
void repaint2(GtkWidget *area)
{
int i, j;
GdkColor *color;
for (j = 1; j < ty+1; j++)
for (i =1 ; i < tx+1; i++)
{
color = (matrice[i][j][slide] == 1) ? &red : &blue;
gdk_gc_set_foreground(gc, color);
gdk_draw_rectangle(pixmap, gc, TRUE,
(i-1) * 400/tx , (j-1) * 400/ty , 400/tx ,400/ty
);
color = (matrice[i+1][j][slide] == 1) ? &red : &blue;
gdk_gc_set_foreground(gc, color);
gdk_draw_rectangle(pixmap, gc, TRUE,
i * 400/tx , (j-.5) * 400/ty ,400/tx ,400/ty );
color = &grey;
gdk_gc_set_foreground(gc, color);
gdk_draw_rectangle(pixmap, gc, TRUE,
i*400/tx , 0 ,400/tx ,200/ty );
++i;
}
gdk_draw_pixmap( area->window,
area->style->fg_gc[GTK_WIDGET_STATE(area)],
pixmap, 0, 0, 0, 0,
area->allocation.width, area->allocation.height );
}
int configure_event(GtkWidget *widget, GdkEventConfigure *event)
{
if (!gc) {
gc = gdk_gc_new(widget->window);
init_colors(widget);
}
if (pixmap)
gdk_pixmap_unref(pixmap);
pixmap = gdk_pixmap_new( widget->window,
widget->allocation.width,
widget->allocation.height,
-1 );
gdk_draw_rectangle( pixmap,
widget->style->white_gc,
TRUE, 0, 0,
widget->allocation.width,
widget->allocation.height );
repaint(widget);
return FALSE;
}
int expose_event(GtkWidget *widget, GdkEventExpose *event)
{
gdk_draw_pixmap( widget->window,
widget->style->fg_gc[GTK_WIDGET_STATE(widget)],
pixmap,
event->area.x, event->area.y,
event->area.x, event->area.y,
event->area.width, event->area.height );
return FALSE;
}
gboolean
on_graphs_expose_event (GtkWidget *widget,
GdkEventExpose *event,
gpointer user_data)
{
gdk_draw_pixmap( widget->window,
widget->style->fg_gc[GTK_WIDGET_STATE(widget)],
pixmap,
event->area.x, event->area.y,
event->area.x, event->area.y,
event->area.width, event->area.height );
return FALSE;
}
gboolean
on_graphs_configure_event (GtkWidget *widget,
GdkEventConfigure *event,
gpointer user_data)
{
if (!gc) {
gc = gdk_gc_new(widget->window);
init_colors(widget);
}
if (pixmap)
gdk_pixmap_unref(pixmap);
pixmap = gdk_pixmap_new( widget->window,
widget->allocation.width,
widget->allocation.height,
-1 );
gdk_draw_rectangle( pixmap,
widget->style->white_gc,
TRUE, 0, 0,
widget->allocation.width,
widget->allocation.height );
repaintclear(widget);
return FALSE;
}
void repaintclear(GtkWidget *area2)
{
GdkColor *color;
color = &white;
gdk_gc_set_foreground(gc, color);
gdk_draw_rectangle(pixmap, gc, TRUE,0,0 , 400 ,400 );
color = &black;
gdk_gc_set_foreground(gc, color);
gdk_draw_rectangle(pixmap, gc, TRUE,0,200 , 400 ,2 );
color = &black;
gdk_gc_set_foreground(gc, color);
gdk_draw_rectangle(pixmap, gc, TRUE,0,0 ,2 ,400 );
gdk_draw_pixmap( area2->window,
area2->style->fg_gc[GTK_WIDGET_STATE(area2)],
pixmap, 0, 0, 0, 0,
area2->allocation.width, area2->allocation.height );
}
void trace(GtkWidget *area2, int i, int j)
{
GdkColor *color;
color = &red;
gdk_gc_set_foreground(gc, color);
gdk_draw_rectangle(pixmap, gc, TRUE,
i,j , 1,1 );
gdk_draw_pixmap( area2->window,
area2->style->fg_gc[GTK_WIDGET_STATE(area2)],
pixmap, 0, 0, 0, 0,
area2->allocation.width, area2->allocation.height );
}
Could someon tell me what's wrong ?
Thanks
Valery Avaux
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]