Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 18th, 2012  |  syntax: None  |  size: 1.05 KB  |  hits: 13  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Knowing Which Button Was pressed! GTK
  2. GtkWidget *board[x][y];
  3.        
  4. g_signal_connect(G_OBJECT(board[][]), "clicked",///I want to know what [][] they pressed, how could I verify/check this?  
  5.        G_CALLBACK(board_button_pressed), NULL);
  6.        
  7. ...
  8.  
  9. typedef struct _identifier{
  10.     int x;
  11.     int y;
  12. }identifier;
  13.  
  14. static void button_clicked_cb(GtkButton *button, gpointer data)
  15. {
  16.     (void)button; /*To get rid of compiler warning*/
  17.     identifier *id = data;
  18.     printf("n id = %d, %dn", id->x, id->y);
  19.     return;
  20. }
  21. ....
  22.     identifier id[x*y]; /* Size of x*y of the board*/
  23.     unsigned int counter = 0;
  24.     for (i = 0; i < x; i++)
  25.     {
  26.         for (j = 0; j < y; j++)
  27.         {
  28.             id[counter].x = i;
  29.             id[counter].y = j;
  30.             board[i][j] = gtk_button_new ();
  31.             g_signal_connect(board[i][j], "clicked", G_CALLBACK(button_clicked_cb), &id[counter]);
  32.             counter++;
  33.         }                                                                                                                                                    
  34.     }