Esempio n. 1
0
static void
create_demo_table (GooCanvasItemModel *root,
		   gdouble        x,
		   gdouble        y,
		   gdouble        width,
		   gdouble        height)
{
  GooCanvasItemModel *table, *square, *circle, *triangle;
  GooCanvasItem *item;

  table = goo_canvas_table_model_new (root,
				      "row-spacing", 4.0,
				      "column-spacing", 4.0,
				      "width", width,
				      "height", height,
				      NULL);
  goo_canvas_item_model_translate (table, x, y);

  square = goo_canvas_rect_model_new (table, 0.0, 0.0, 50.0, 50.0,
				      "fill-color", "red",
				      NULL);
  goo_canvas_item_model_set_child_properties (table, square,
					      "row", 0,
					      "column", 0,
					      "x-shrink", TRUE,
					      NULL);
  item = goo_canvas_get_item (canvas, square);
  g_object_set_data (G_OBJECT (item), "id", "Red square");
  g_signal_connect (item, "button_press_event",
		    G_CALLBACK (on_button_press), NULL);

  circle = goo_canvas_ellipse_model_new (table, 0.0, 0.0, 25.0, 25.0,
					 "fill-color", "blue",
					 NULL);
  goo_canvas_item_model_set_child_properties (table, circle,
					      "row", 0,
					      "column", 1,
					      "x-shrink", TRUE,
					      NULL);
  item = goo_canvas_get_item (canvas, circle);
  g_object_set_data (G_OBJECT (item), "id", "Blue circle");
  g_signal_connect (item, "button_press_event",
		    G_CALLBACK (on_button_press), NULL);

  triangle = goo_canvas_polyline_model_new (table, TRUE, 3,
					    25.0, 0.0, 0.0, 50.0, 50.0, 50.0,
					    "fill-color", "yellow",
					    NULL);
  goo_canvas_item_model_set_child_properties (table, triangle,
					      "row", 0,
					      "column", 2,
					      "x-shrink", TRUE,
					      NULL);
  item = goo_canvas_get_item (canvas, triangle);
  g_object_set_data (G_OBJECT (item), "id", "Yellow triangle");
  g_signal_connect (item, "button_press_event",
		    G_CALLBACK (on_button_press), NULL);
}
Esempio n. 2
0
static GooCanvasItemModel*
create_model (GdkPixbuf *pixbuf)
{
  GooCanvasItemModel *root;
  GooCanvasItemModel *item;
  GooCanvasItemModel* child;

  root = goo_canvas_group_model_new (NULL, NULL);

  /* Test clipping of GooCanvasGroup: We put the rectangle and the ellipse into
   * a group with width=200 and height=200. */
  item = goo_canvas_group_model_new (root, "x", 50.0, "y", 350.0, "width", 200.0, "height", 200.0, NULL);
  /*goo_canvas_item_model_rotate(item, 45.0, 150.0, 450.0);*/

  child = goo_canvas_rect_model_new (item, 0.0, 0.0, 100, 100, "fill-color", "blue", NULL);
  g_object_set_data (G_OBJECT (child), "setup-dnd-signals", "TRUE");
  goo_canvas_item_model_rotate(child, 45.0, 50.0, 50.0);

  child = goo_canvas_ellipse_model_new (item, 150, 00, 50, 50, "fill-color", "red", NULL);
  g_object_set_data (G_OBJECT (child), "setup-dnd-signals", "TRUE");

  item = goo_canvas_polyline_model_new (root, FALSE, 5.0, 250.0, 350.0, 275.0, 400.0, 300.0, 350.0, 325.0, 400.0, 350.0, 350.0, "stroke-color", "cyan", "line-width", 5.0, NULL);
  g_object_set_data (G_OBJECT (item), "setup-dnd-signals", "TRUE");

  item = goo_canvas_path_model_new (root, "M20,500 C20,450 100,450 100,500", "stroke-color", "green", "line-width", 5.0, NULL);
  g_object_set_data (G_OBJECT (item), "setup-dnd-signals", "TRUE");

  item = goo_canvas_image_model_new (root, pixbuf, 150, 450, /*"fill-color", "yellow", */NULL);
  g_object_unref (pixbuf);
  g_object_set_data (G_OBJECT (item), "setup-dnd-signals", "TRUE");

  item = goo_canvas_text_model_new (root, "Hello, World!", 250, 450, -1, GOO_CANVAS_ANCHOR_NW, "fill-color", "magenta", "wrap", PANGO_WRAP_WORD_CHAR, NULL);
  g_object_set_data (G_OBJECT (item), "setup-dnd-signals", "TRUE");

  item = goo_canvas_table_model_new (root, "horz-grid-line-width", 2.0, "vert-grid-line-width", 2.0, "row-spacing", 2.0, "column-spacing", 2.0, NULL);
  goo_canvas_item_model_translate (item, 10.0, 10.0);
  g_object_set_data (G_OBJECT (item), "setup-dnd-signals", "TRUE");

  child = goo_canvas_rect_model_new (item, 10.0, 10.0, 50.0, 50.0, "fill-color", "blue", "x", 10.0, "y", 25.0, NULL);
  g_object_set_data (G_OBJECT (child), "setup-dnd-signals", "TRUE");
  goo_canvas_item_model_set_child_properties (item, child, "column", 0, "row", 0, "columns", 1, "rows", 1, NULL);
  /*goo_canvas_item_model_translate (child, 10.0, 10.0);*/

  child = goo_canvas_rect_model_new (item, 0.0, 0.0, 50.0, 50.0, "fill-color", "red", NULL);
  g_object_set_data (G_OBJECT (child), "setup-dnd-signals", "TRUE");
  goo_canvas_item_model_set_child_properties (item, child, "column", 1, "row", 0, "columns", 1, "rows", 1, NULL);

  child = goo_canvas_rect_model_new (item, 0.0, 0.0, 50.0, 50.0, "fill-color", "green", NULL);
  g_object_set_data (G_OBJECT (child), "setup-dnd-signals", "TRUE");
  goo_canvas_item_model_set_child_properties(item, child, "column", 0, "row", 1, "columns", 1, "rows", 1, NULL);

  child = goo_canvas_rect_model_new (item, 0.0, 0.0, 50.0, 50.0, "fill-color", "yellow", NULL);
  g_object_set_data (G_OBJECT (child), "setup-dnd-signals", "TRUE");
  goo_canvas_item_model_set_child_properties (item, child, "column", 1, "row", 1, "columns", 1, "rows", 1, NULL);

  return root;
}
Esempio n. 3
0
static void
create_dimension (GtkWidget *canvas,
		  GooCanvasItemModel *root,
		  char *arrow_name,
		  char *text_name,
		  GooCanvasAnchorType anchor)
{
	GooCanvasItemModel *item;

	item = goo_canvas_polyline_model_new (root, FALSE, 0,
					      "fill_color", "black",
					      "start-arrow", TRUE,
					      "end-arrow", TRUE,
					      NULL);
	g_object_set_data (G_OBJECT (canvas), arrow_name, item);

	item = goo_canvas_text_model_new (root, NULL, 0, 0, -1, anchor,
					  "fill_color", "black",
					  "font", "Sans 12",
					  NULL);
	g_object_set_data (G_OBJECT (canvas), text_name, item);
}
Esempio n. 4
0
GtkWidget *
create_canvas_arrowhead (void)
{
	GtkWidget *vbox;
	GtkWidget *w;
	GtkWidget *frame;
	GtkWidget *canvas;
	GooCanvasItemModel *root, *item;

	vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 4);
	gtk_container_set_border_width (GTK_CONTAINER (vbox), 4);
	gtk_widget_show (vbox);

	w = gtk_label_new ("This demo allows you to edit arrowhead shapes.  Drag the little boxes\n"
			   "to change the shape of the line and its arrowhead.  You can see the\n"
			   "arrows at their normal scale on the right hand side of the window.");
	gtk_box_pack_start (GTK_BOX (vbox), w, FALSE, FALSE, 0);
	gtk_widget_show (w);

	w = gtk_alignment_new (0.5, 0.5, 0.0, 0.0);
	gtk_box_pack_start (GTK_BOX (vbox), w, TRUE, TRUE, 0);
	gtk_widget_show (w);

	frame = gtk_frame_new (NULL);
	gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_IN);
	gtk_container_add (GTK_CONTAINER (w), frame);
	gtk_widget_show (frame);

	canvas = goo_canvas_new ();

	g_signal_connect (canvas, "item_created",
			  G_CALLBACK (on_item_created), NULL);

	root = goo_canvas_group_model_new (NULL, NULL);
	goo_canvas_set_root_item_model (GOO_CANVAS (canvas), root);
	g_object_unref (root);

	gtk_widget_set_size_request (canvas, 500, 350);
	goo_canvas_set_bounds (GOO_CANVAS (canvas), 0, 0, 500, 350);
	gtk_container_add (GTK_CONTAINER (frame), canvas);
	gtk_widget_show (canvas);


	g_object_set_data (G_OBJECT (canvas), "width",
			   GINT_TO_POINTER (DEFAULT_WIDTH));
	g_object_set_data (G_OBJECT (canvas), "shape_a",
			   GINT_TO_POINTER (DEFAULT_SHAPE_A));
	g_object_set_data (G_OBJECT (canvas), "shape_b",
			   GINT_TO_POINTER (DEFAULT_SHAPE_B));
	g_object_set_data (G_OBJECT (canvas), "shape_c",
			   GINT_TO_POINTER (DEFAULT_SHAPE_C));

	/* Big arrow */

	item = goo_canvas_polyline_model_new_line (root,
						   LEFT, MIDDLE, RIGHT, MIDDLE,
						   "stroke_color", "mediumseagreen",
						   "end-arrow", TRUE,
						   NULL);
	g_object_set_data (G_OBJECT (canvas), "big_arrow", item);

	/* Arrow outline */

	item = goo_canvas_polyline_model_new (root, TRUE, 0,
					      "stroke_color", "black",
					      "line-width", 2.0,
					      "line-cap", CAIRO_LINE_CAP_ROUND,
					      "line-join", CAIRO_LINE_JOIN_ROUND,
					      NULL);
	g_object_set_data (G_OBJECT (canvas), "outline", item);

	/* Drag boxes */

	create_drag_box (canvas, root, "width_drag_box");
	create_drag_box (canvas, root, "shape_a_drag_box");
	create_drag_box (canvas, root, "shape_b_c_drag_box");

	/* Dimensions */

	create_dimension (canvas, root, "width_arrow", "width_text", GOO_CANVAS_ANCHOR_E);
	create_dimension (canvas, root, "shape_a_arrow", "shape_a_text", GOO_CANVAS_ANCHOR_N);
	create_dimension (canvas, root, "shape_b_arrow", "shape_b_text", GOO_CANVAS_ANCHOR_N);
	create_dimension (canvas, root, "shape_c_arrow", "shape_c_text", GOO_CANVAS_ANCHOR_W);

	/* Info */

	create_info (canvas, root, "width_info", LEFT, 260);
	create_info (canvas, root, "shape_a_info", LEFT, 280);
	create_info (canvas, root, "shape_b_info", LEFT, 300);
	create_info (canvas, root, "shape_c_info", LEFT, 320);

	/* Division line */

	goo_canvas_polyline_model_new_line (root, RIGHT + 50, 0, RIGHT + 50, 1000,
					    "fill_color", "black",
					    "line-width", 2.0,
					    NULL);

	/* Sample arrows */

	create_sample_arrow (canvas, root, "sample_1",
			     RIGHT + 100, 30, RIGHT + 100, MIDDLE - 30);
	create_sample_arrow (canvas, root, "sample_2",
			     RIGHT + 70, MIDDLE, RIGHT + 130, MIDDLE);
	create_sample_arrow (canvas, root, "sample_3",
			     RIGHT + 70, MIDDLE + 30, RIGHT + 130, MIDDLE + 120);

	/* Done! */
	
	set_arrow_shape (GOO_CANVAS (canvas));
	return vbox;
}
/** \brief Create polylines. */
static void
create_polylines (GtkSatMap *satmap, sat_t *sat, qth_t *qth, sat_map_obj_t *obj)
{
     ssp_t              *ssp,*buff;     /* map coordinates */
     double             lastx,lasty;
     GSList             *points = NULL;
     GooCanvasItemModel *root;
     GooCanvasItemModel *line;
     GooCanvasPoints    *gpoints;
     guint              start;
     guint              i,j,n,num_points;
     guint32            col;

     (void) sat; /* prevent unused parameter compiler warning */
     (void) qth; /* prevent unused parameter compiler warning */

     /* initialise parameters */
     lastx = -50.0;
     lasty = -50.0;
     start = 0;
     num_points = 0;
     n = g_slist_length (obj->track_data.latlon);
     col = mod_cfg_get_int (satmap->cfgdata,
                                 MOD_CFG_MAP_SECTION,
                                 MOD_CFG_MAP_TRACK_COL,
                                 SAT_CFG_INT_MAP_TRACK_COL);

     /* loop over each SSP */
     for (i = 0; i < n; i++) {

          buff = (ssp_t *) g_slist_nth_data (obj->track_data.latlon, i);
          ssp = g_try_new (ssp_t, 1);
          gtk_sat_map_lonlat_to_xy (satmap, buff->lon, buff->lat, &ssp->lon, &ssp->lat);

          /* if this is the first point, just add it to the list */
          if (i == start) {
               points = g_slist_prepend (points, ssp);
               lastx = ssp->lon;
               lasty = ssp->lat;
          }

          else {

               /* if SSP is on the other side of the map */
               if (ssp_wrap_detected (satmap, lastx, ssp->lon)) {

                    points = g_slist_reverse (points);
                    num_points = g_slist_length (points);

                    /* we need at least 2 points to draw a line */
                    if (num_points > 1) {

                         /* convert SSPs to GooCanvasPoints */
                         gpoints = goo_canvas_points_new (num_points);
                         for (j = 0; j < num_points; j++) {
                              buff = (ssp_t *) g_slist_nth_data (points, j);
                              gpoints->coords[2*j] = buff->lon;
                              gpoints->coords[2*j+1] = buff->lat;
                         }

                         /* create a new polyline using the current set of points */
                         root = goo_canvas_get_root_item_model (GOO_CANVAS (satmap->canvas));

                         line = goo_canvas_polyline_model_new (root, FALSE, 0,
                                                                        "points", gpoints,
                                                                        "line-width", 1.0,
                                                                        "stroke-color-rgba", col,
                                                                        "line-cap", CAIRO_LINE_CAP_SQUARE,
                                                                        "line-join", CAIRO_LINE_JOIN_MITER,
                                                                        NULL);
                         goo_canvas_points_unref (gpoints);
                         goo_canvas_item_model_lower (line, obj->marker);
                         
                         /* store line in sat object */
                         obj->track_data.lines = g_slist_append (obj->track_data.lines, line);

                    }

                    /* reset parameters and continue with a new set */
                    g_slist_foreach (points, free_ssp, NULL);
                    g_slist_free (points);
                    points = NULL;
                    start = i;
                    lastx = ssp->lon;
                    lasty = ssp->lat;
                    num_points = 0;

                    /* Add current SSP to the new list */
                    points = g_slist_prepend (points, ssp);
                    lastx = ssp->lon;
                    lasty = ssp->lat;

               }

               /* else if this SSP is separable from the previous */
               else if ((fabs (lastx - ssp->lon) > 1.0 ) || (fabs(lasty - ssp->lat)>1.0)){

                    /* add SSP to list */
                    points = g_slist_prepend (points, ssp);
                    lastx = ssp->lon;
                    lasty = ssp->lon;

               }

               /* else if  do nothing */

          }
     }

     /* create (last) line if we have at least two points */
     points = g_slist_reverse (points);
     num_points = g_slist_length (points);

     if (num_points > 1) {

          /* convert SSPs to GooCanvasPoints */
          gpoints = goo_canvas_points_new (num_points);
          for (j = 0; j < num_points; j++) {
               buff = (ssp_t *) g_slist_nth_data (points, j);
               gpoints->coords[2*j] = buff->lon;
               gpoints->coords[2*j+1] = buff->lat;
          }

          /* create a new polyline using the current set of points */
          root = goo_canvas_get_root_item_model (GOO_CANVAS (satmap->canvas));

          line = goo_canvas_polyline_model_new (root, FALSE, 0,
                                                         "points", gpoints,
                                                         "line-width", 1.0,
                                                         "stroke-color-rgba", col,
                                                         "line-cap", CAIRO_LINE_CAP_SQUARE,
                                                         "line-join", CAIRO_LINE_JOIN_MITER,
                                                         NULL);
          goo_canvas_points_unref (gpoints);
          goo_canvas_item_model_lower (line, obj->marker);

          /* store line in sat object */
          obj->track_data.lines = g_slist_append (obj->track_data.lines, line);

          /* reset parameters and continue with a new set */
          g_slist_foreach (points, free_ssp, NULL);
          g_slist_free (points);

     }
}
/** \brief Manage toggling of Ground Track.
 *  \param item The menu item that was toggled.
 *  \param data Pointer to the GtkPolarView structure.
 *
 */
static void
        track_toggled (GtkCheckMenuItem *item, gpointer data)
{
    GtkPolarView       *pv = GTK_POLAR_VIEW (data);
    sat_obj_t          *obj = NULL;
    sat_t              *sat;
    qth_t              *qth;
    gint               idx,i;
    GooCanvasItemModel *root;
    pass_detail_t      *detail;
    guint              num;
    GooCanvasPoints    *points;
    gfloat             x,y;
    guint32            col;
    guint              tres,ttidx;


    /* get satellite object */
    obj = SAT_OBJ(g_object_get_data (G_OBJECT (item), "obj"));
    sat = SAT(g_object_get_data (G_OBJECT (item), "sat"));
    qth = (qth_t *)(g_object_get_data (G_OBJECT (item), "qth"));

    if (obj == NULL) {
        sat_log_log (SAT_LOG_LEVEL_BUG,
                     _("%s:%d: Failed to get satellite object."),
                     __FILE__, __LINE__);
        return;
    }

    /* toggle flag */
    obj->showtrack = !obj->showtrack;
    gtk_check_menu_item_set_active (item, obj->showtrack);

    root = goo_canvas_get_root_item_model (GOO_CANVAS (pv->canvas));

    if (obj->showtrack) {
        /* add sky track */

        /* create points */
        num = g_slist_length (obj->pass->details);
        if (num == 0) {
            sat_log_log (SAT_LOG_LEVEL_BUG,
                         _("%s:%d: Pass has no details."),
                         __FILE__, __LINE__);
            return;
        }

        /* time resolution for time ticks; we need
                   3 additional points to AOS and LOS ticks.
                */
        tres = (num-2) / (TRACK_TICK_NUM-1);

        points = goo_canvas_points_new (num);

        /* first point should be (aos_az,0.0) */
        azel_to_xy (pv, obj->pass->aos_az, 0.0, &x, &y);
        points->coords[0] = (double) x;
        points->coords[1] = (double) y;
        obj->trtick[0] = create_time_tick (pv, obj->pass->aos, x, y);

        ttidx = 1;

        for (i = 1; i < num-1; i++) {
            detail = PASS_DETAIL(g_slist_nth_data (obj->pass->details, i));
            if (detail->el >=0.0)
                azel_to_xy (pv, detail->az, detail->el, &x, &y);
            points->coords[2*i] = (double) x;
            points->coords[2*i+1] = (double) y;

            if (!(i % tres)) {
                /* create a time tick */
                if (ttidx<TRACK_TICK_NUM)
                    obj->trtick[ttidx] = create_time_tick (pv, detail->time, x, y);
                ttidx++;
            }
        }

        /* last point should be (los_az, 0.0)  */
        azel_to_xy (pv, obj->pass->los_az, 0.0, &x, &y);
        points->coords[2*(num-1)] = (double) x;
        points->coords[2*(num-1)+1] = (double) y;

        /* create poly-line */
        col = mod_cfg_get_int (pv->cfgdata,
                               MOD_CFG_POLAR_SECTION,
                               MOD_CFG_POLAR_TRACK_COL,
                               SAT_CFG_INT_POLAR_TRACK_COL);

        obj->track = goo_canvas_polyline_model_new (root, FALSE, 0,
                                                    "points", points,
                                                    "line-width", 1.0,
                                                    "stroke-color-rgba", col,
                                                    "line-cap", CAIRO_LINE_CAP_SQUARE,
                                                    "line-join", CAIRO_LINE_JOIN_MITER,
                                                    NULL);
        goo_canvas_points_unref (points);

        /* put track on the bottom of the sack */
        goo_canvas_item_model_lower (obj->track, NULL);

    }
    else {
        /* delete sky track */
        idx = goo_canvas_item_model_find_child (root, obj->track);

        if (idx != -1) {
            goo_canvas_item_model_remove_child (root, idx);
        }

        for (i = 0; i < TRACK_TICK_NUM; i++) {
            idx = goo_canvas_item_model_find_child (root, obj->trtick[i]);

            if (idx != -1) {
                goo_canvas_item_model_remove_child (root, idx);
            }
        }
    }

}