
Untitled
By: a guest on
May 18th, 2012 | syntax:
None | size: 1.05 KB | hits: 13 | expires: Never
Knowing Which Button Was pressed! GTK
GtkWidget *board[x][y];
g_signal_connect(G_OBJECT(board[][]), "clicked",///I want to know what [][] they pressed, how could I verify/check this?
G_CALLBACK(board_button_pressed), NULL);
...
typedef struct _identifier{
int x;
int y;
}identifier;
static void button_clicked_cb(GtkButton *button, gpointer data)
{
(void)button; /*To get rid of compiler warning*/
identifier *id = data;
printf("n id = %d, %dn", id->x, id->y);
return;
}
....
identifier id[x*y]; /* Size of x*y of the board*/
unsigned int counter = 0;
for (i = 0; i < x; i++)
{
for (j = 0; j < y; j++)
{
id[counter].x = i;
id[counter].y = j;
board[i][j] = gtk_button_new ();
g_signal_connect(board[i][j], "clicked", G_CALLBACK(button_clicked_cb), &id[counter]);
counter++;
}
}