int
main (int argc, char *argv[])
{
    App *app;

    app = (App *) g_new (App, 1);

    gtk_init (&argc, &argv);

    app_init (app);

    GET_UI_ELEMENT (GtkWidget, mainwindow);
    GET_UI_ELEMENT (GtkWidget, layout1);

    g_signal_connect (G_OBJECT (layout1), "draw",
                      G_CALLBACK (layout_draw_cb), app);

    make_button ("eventbox1", app);
    make_button ("eventbox2", app);

    gtk_widget_show_all (mainwindow);

    gtk_main ();

    return 0;
}
Exemple #2
0
void
app_init (App * app)
{
  GError *err = NULL;
    
  app->definitions = gtk_builder_new ();
    
  gtk_builder_add_from_file (app->definitions,
			     UI_DEFINITIONS_FILE, &err);
    
  if (err != NULL) {
    g_printerr
      ("Error while loading app definitions file: %s\n",
       err->message);
    g_error_free (err);
    gtk_main_quit ();
  }
    
  gtk_builder_connect_signals (app->definitions, app);
  
  app_init_colors (app);

  app->filename = NULL;
  
  app->display_level = FALSE;
  app->display_weight = FALSE;




   GtkCellRenderer *renderer=gtk_cell_renderer_text_new();
  GET_UI_ELEMENT(GtkComboBox, combobox_from);  
        gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(combobox_from),renderer,FALSE);
        gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(combobox_from),renderer,
				       "text",0,
				       NULL);
        gtk_combo_box_set_active(GTK_COMBO_BOX(combobox_from),0);

  GET_UI_ELEMENT(GtkComboBox, combobox_to);  
        gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(combobox_to),renderer,FALSE);
        gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(combobox_to),renderer,
				       "text",0,
				       NULL);
        gtk_combo_box_set_active(GTK_COMBO_BOX(combobox_to),0);

	
  //init non graphical units
  app->p_graph = malloc(sizeof(graph));

  app->p_matrix = malloc(sizeof(matrix));
  app->p_matrix->i_size = 3;
  matrix_malloc(app->p_matrix);
  matrix_zero(app->p_matrix);
  
  //construct the graph from the matrix
  init_all(app->p_graph, app->p_matrix);
  
}
static gboolean
motion_notify_event (GtkWidget * widget,
                     GdkEventMotion * event, App * app)
{

    gint x, y;
    gboolean ret;
    GtkAdjustment *hadjustment, *vadjustment;
    gfloat hval, vval;

    GET_UI_ELEMENT (GtkWidget, scrolledwindow2);
    GET_UI_ELEMENT (GtkWidget, layout1);

    gtk_widget_translate_coordinates (widget, layout1,
                                      event->x, event->y, &x,
                                      &y);

    x -= offsetx;
    y -= offsety;

    // make sure the potential coordinates x,y:
    //   1) will not push any part of the widget outside of its parent container
    //   2) is a multiple of Sensitivity

    x = RoundToNearestMultiple (Max (Min (x, maxx), 0),
                                Sensitivity);
    y = RoundToNearestMultiple (Max (Min (y, maxy), 0),
                                Sensitivity);

    if (x != px || y != py) {
        g_object_get (scrolledwindow2, "hadjustment",
                      &hadjustment, "vadjustment",
                      &vadjustment, NULL);

        hval = gtk_adjustment_get_value (hadjustment);
        vval = gtk_adjustment_get_value (vadjustment);

        x += hval;
        y += vval;

        px = x;
        py = y;

        gtk_layout_move (GTK_LAYOUT (layout1), widget, x, y);
    }

    gtk_widget_queue_draw (layout1);

    return TRUE;
}
Exemple #4
0
void
app_init_colors (App * app)
{
  app->background_color = g_new0 (GdkRGBA, 1);
  app->strokes_color = g_new0 (GdkRGBA, 1);
  
  //fetch system colors
  GET_UI_ELEMENT (GtkWidget, window1);
  GtkStyleContext *context;
  context = gtk_widget_get_style_context (window1);

  gtk_style_context_get_background_color(context,
					 GTK_STATE_FLAG_NORMAL,
					 app->background_color);

  gtk_style_context_get_color(context,
			      GTK_STATE_FLAG_NORMAL,
			      app->strokes_color);
}