Exemplo n.º 1
0
static void
tangent_normal_line(int x, int y, float vx, float vy)
{
    int dx, dy, xl, yl, xr, yr;
    F_line	   *line;
 
    dx = round(vx);
    dy = round(vy);   

    xl = x - dx;
    yl = y - dy;
    xr = x + dx;
    yr = y + dy;

    if ((first_point = create_point()) == NULL) 
        return;
    cur_point = first_point;
    first_point->x = xl;
    first_point->y = yl;
    first_point->next = NULL;
    append_point(x, y, &cur_point);
    append_point(xr, yr, &cur_point);
    
    if ((line = create_line()) == NULL)
        return; /* an error occured */
    line->type = T_POLYLINE;
    line->style = cur_linestyle;
    line->thickness = cur_linewidth;
    line->pen_color = cur_pencolor;
    line->fill_color = cur_fillcolor;
    line->depth = cur_depth;
    line->pen_style = -1;
    line->join_style = cur_joinstyle;
    line->cap_style = cur_capstyle;
    line->fill_style = cur_fillstyle;
    line->style_val = cur_styleval * (cur_linewidth + 1) / 2;
    line->points = first_point;
		/* polyline; draw any arrows */
    if (autoforwardarrow_mode)
	line->for_arrow = forward_arrow();
    /* arrow will be drawn in draw_line below */
    if (autobackwardarrow_mode)
	line->back_arrow = backward_arrow();
    /* arrow will be drawn in draw_line below */
    draw_line(line, PAINT);	/* draw final */
    add_line(line);
    toggle_linemarker(line);
}
Exemplo n.º 2
0
void read_points_from_file(const char * file_name, AllPoints *all_points)
{
	FILE *fp;
	char buffer[BUFFER_SIZE];

	if ((fp = fopen(file_name, "r")) == NULL)
	{
		printf(" could not open input file %s\n", file_name);
		exit(-1);
	}

	while (fgets(buffer, BUFFER_SIZE, fp))
	{
		// read input point coordinates
		int x = 0;
		int y = 0;
		sscanf(buffer, "%d %d", &x, &y);
		append_point(all_points, x, y);
	}
	fclose(fp);

	if (all_points->number_of_points >= MAX_POINTS)
	{
		printf(" too many points in file\n", file_name);
		exit(-1);
	}
}
Exemplo n.º 3
0
void
get_intermediatepoint(int x, int y, int shift)
{
    /* in freehand mode call unconstrained_line explicitely to move the mouse */
    if (freehand_line) {
	unconstrained_line(x,y);
	/* pointer must move by at least freehand_resolution in any direction */
	if (abs(fix_x-cur_x) < appres.freehand_resolution &&
	   (abs(fix_y-cur_y) < appres.freehand_resolution))
		return;
    } else {
	/* otherwise call the (possibly) constrained movement procedure */
	(*canvas_locmove_proc) (x, y);
    }

    /* don't allow coincident consecutive points */
    if (fix_x == cur_x && fix_y == cur_y)
	return;

    num_point++;
    fix_x = cur_x;
    fix_y = cur_y;
    elastic_line();
    if (cur_cursor != null_cursor) {
	set_cursor(null_cursor);
    }
    if (shift && num_point > 2) {
	F_point	*p;

	num_point -= 2;
	p = prev_point(first_point, cur_point);
	p->next = NULL;
	/* erase the newest segment */
	pw_vector(canvas_win, fix_x, fix_y, cur_point->x, cur_point->y,
		  INV_PAINT, 1, RUBBER_LINE, 0.0, DEFAULT);
	/* and segment drawn before */
	pw_vector(canvas_win, p->x, p->y, cur_point->x, cur_point->y,
		  INV_PAINT, 1, RUBBER_LINE, 0.0, DEFAULT);
	/* and draw new elastic segment */
	pw_vector(canvas_win, fix_x, fix_y, p->x, p->y,
		  PAINT, 1, RUBBER_LINE, 0.0, DEFAULT);
	fix_x = p->x;
	fix_y = p->y;
	free_points(cur_point);
	cur_point = p;
    } else {
	append_point(fix_x, fix_y, &cur_point);
    }
    if (num_point == min_num_points - 1) {
	if (freehand_line)
	    set_mousefun("", "final point", "cancel", "del point", "", "");
	else
	    set_mousefun("next point", "final point", "cancel", "del point", "", "");
	draw_mousefun_canvas();
	canvas_middlebut_proc = (FCallBack)canvas_middlebut_save;
    }
}
Exemplo n.º 4
0
 virtual void move_to(P p) {
     if ( !current_loop.empty() ) {
         all_loops.push_back(current_loop);
         current_loop.clear();
     }
     std::cout << "pen UP \n";
     std::cout << "  move to " << p.x << " , " << p.y << "\n";
     std::cout << "pen DOWN \n";
     append_point(p);
 }
Exemplo n.º 5
0
 //virtual void line_comment(P c1, P c2, P to) {}
 virtual void line_to(P p) {
     std::cout << last_point.x << " , " << last_point.y << " lineto " << p.x << " , " << p.y << "\n";
     append_point(p);
 }
int
main (int argc,
    char *argv[])
{
  GtkWidget *window;
  GtkWidget *widget, *vbox, *bbox, *button, *viewport, *image;
  ChamplainView *view;
  ChamplainMarkerLayer *layer;
  ClutterActor *scale;
  ChamplainLicense *license_actor;

  if (gtk_clutter_init (&argc, &argv) != CLUTTER_INIT_SUCCESS)
    return 1;

  /* create the main, top level, window */
  window = gtk_window_new (GTK_WINDOW_TOPLEVEL);

  /* give the window a 10px wide border */
  gtk_container_set_border_width (GTK_CONTAINER (window), 10);

  /* give it the title */
  gtk_window_set_title (GTK_WINDOW (window), "libchamplain Gtk+ demo");

  /* Connect the destroy event of the window with our on_destroy function
   * When the window is about to be destroyed we get a notificaiton and
   * stop the main GTK loop
   */
  g_signal_connect (G_OBJECT (window), "destroy", G_CALLBACK (on_destroy),
      NULL);

  vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 10);

  widget = gtk_champlain_embed_new ();
  view = gtk_champlain_embed_get_view (GTK_CHAMPLAIN_EMBED (widget));
  clutter_actor_set_reactive (CLUTTER_ACTOR (view), TRUE);
  g_signal_connect (view, "button-release-event", G_CALLBACK (mouse_click_cb), view);


  g_object_set (G_OBJECT (view),
      "kinetic-mode", TRUE,
      "zoom-level", 5,
      NULL);

  g_object_set_data (G_OBJECT (view), "window", window);
      
  scale = champlain_scale_new ();
  champlain_scale_connect_view (CHAMPLAIN_SCALE (scale), view);
  
  /* align to the bottom left */
  clutter_actor_set_x_expand (scale, TRUE);
  clutter_actor_set_y_expand (scale, TRUE);
  clutter_actor_set_x_align (scale, CLUTTER_ACTOR_ALIGN_START);
  clutter_actor_set_y_align (scale, CLUTTER_ACTOR_ALIGN_END);
  clutter_actor_add_child (CLUTTER_ACTOR (view), scale);
  
  license_actor = champlain_view_get_license_actor (view);
  champlain_license_set_extra_text (license_actor, "Don't eat cereals with orange juice\nIt tastes bad");
  
  champlain_view_center_on (CHAMPLAIN_VIEW (view), 45.466, -73.75);

  layer = create_marker_layer (view, &path);
  champlain_view_add_layer (view, CHAMPLAIN_LAYER (path));
  champlain_view_add_layer (view, CHAMPLAIN_LAYER (layer));
  
  path_layer = champlain_path_layer_new ();
  /* Cheap approx of Highway 10 */
  append_point (path_layer, 45.4095, -73.3197);
  append_point (path_layer, 45.4104, -73.2846);
  append_point (path_layer, 45.4178, -73.2239);
  append_point (path_layer, 45.4176, -73.2181);
  append_point (path_layer, 45.4151, -73.2126);
  append_point (path_layer, 45.4016, -73.1926);
  append_point (path_layer, 45.3994, -73.1877);
  append_point (path_layer, 45.4000, -73.1815);
  append_point (path_layer, 45.4151, -73.1218);
  champlain_view_add_layer (view, CHAMPLAIN_LAYER (path_layer));

  gtk_widget_set_size_request (widget, 640, 481);

  bbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 10);
  button = gtk_button_new ();
  image = gtk_image_new_from_icon_name ("zoom-in", GTK_ICON_SIZE_BUTTON);
  gtk_button_set_image (GTK_BUTTON (button), image);
  gtk_button_set_label (GTK_BUTTON (button), "Zoom In");
  g_signal_connect (button, "clicked", G_CALLBACK (zoom_in), view);
  gtk_container_add (GTK_CONTAINER (bbox), button);

  button = gtk_button_new ();
  image = gtk_image_new_from_icon_name ("zoom-out", GTK_ICON_SIZE_BUTTON);
  gtk_button_set_image (GTK_BUTTON (button), image);
  gtk_button_set_label (GTK_BUTTON (button), "Zoom Out");
  g_signal_connect (button, "clicked", G_CALLBACK (zoom_out), view);
  gtk_container_add (GTK_CONTAINER (bbox), button);

  button = gtk_toggle_button_new_with_label ("Markers");
  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), TRUE);
  g_signal_connect (button, "toggled", G_CALLBACK (toggle_layer), layer);
  gtk_container_add (GTK_CONTAINER (bbox), button);

  button = gtk_toggle_button_new_with_label ("Toggle wrap");
  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button),
                                champlain_view_get_horizontal_wrap (view));
  g_signal_connect (button, "toggled", G_CALLBACK (toggle_wrap), view);
  gtk_container_add (GTK_CONTAINER (bbox), button);

  button = gtk_combo_box_new ();
  build_combo_box (GTK_COMBO_BOX (button));
  gtk_combo_box_set_active (GTK_COMBO_BOX (button), 0);
  g_signal_connect (button, "changed", G_CALLBACK (map_source_changed), view);
  gtk_container_add (GTK_CONTAINER (bbox), button);

  button = gtk_spin_button_new_with_range (0, 20, 1);
  gtk_spin_button_set_value (GTK_SPIN_BUTTON (button),
      champlain_view_get_zoom_level (view));
  g_signal_connect (button, "changed", G_CALLBACK (zoom_changed), view);
  g_signal_connect (view, "notify::zoom-level", G_CALLBACK (map_zoom_changed),
      button);
  gtk_container_add (GTK_CONTAINER (bbox), button);

  button = gtk_button_new ();
  image = gtk_image_new_from_icon_name ("list-add", GTK_ICON_SIZE_BUTTON);
  gtk_button_set_image (GTK_BUTTON (button), image);
  g_signal_connect (button, "clicked", G_CALLBACK (add_clicked), view);
  gtk_container_add (GTK_CONTAINER (bbox), button);

  button = gtk_button_new ();
  image = gtk_image_new_from_icon_name ("camera-photo-symbolic", GTK_ICON_SIZE_BUTTON);
  gtk_button_set_image (GTK_BUTTON (button), image);
  g_signal_connect (button, "clicked", G_CALLBACK (export_png), view);
  gtk_container_add (GTK_CONTAINER (bbox), button);

  button = gtk_image_new ();
  gtk_widget_set_size_request (button, 22, -1);
  g_signal_connect (view, "notify::state", G_CALLBACK (view_state_changed),
      button);
  gtk_box_pack_end (GTK_BOX (bbox), button, FALSE, FALSE, 0);

  viewport = gtk_frame_new (NULL);
  gtk_container_add (GTK_CONTAINER (viewport), widget);

  gtk_box_pack_start (GTK_BOX (vbox), bbox, FALSE, FALSE, 0);
  gtk_container_add (GTK_CONTAINER (vbox), viewport);

  /* and insert it into the main window  */
  gtk_container_add (GTK_CONTAINER (window), vbox);

  /* make sure that everything, window and label, are visible */
  gtk_widget_show_all (window);
  /* start the main loop */
  gtk_main ();

  return 0;
}
Exemplo n.º 7
0
void
create_lineobject(int x, int y)
{
    F_line	   *line;
    F_compound	   *comp;
    int		    dot;

    if (num_point == 0) {
	if ((first_point = create_point()) == NULL) {
	    line_drawing_selected();
	    draw_mousefun_canvas();
	    return;
	}
	cur_point = first_point;
	first_point->x = fix_x = cur_x = x;
	first_point->y = fix_y = cur_y = y;
	first_point->next = NULL;
	num_point++;
    } else if (x != fix_x || y != fix_y) {
	get_intermediatepoint(x, y, 0);
    }
    /* dimension line must have 2 different points */
    if (dimension_line && first_point->x == x && first_point->y == y)
	return;

    dot = (num_point == 1);
    elastic_line();
    /* erase any length info if appres.showlengths is true */
    erase_lengths();
    if ((line = create_line()) == NULL) {
	line_drawing_selected();
	draw_mousefun_canvas();
	return;
    }
    line->type = T_POLYLINE;
    line->style = cur_linestyle;
    line->thickness = cur_linewidth;
    line->pen_color = cur_pencolor;
    line->fill_color = cur_fillcolor;
    line->depth = cur_depth;
    line->pen_style = -1;
    line->join_style = cur_joinstyle;
    line->cap_style = cur_capstyle;
    line->fill_style = cur_fillstyle;
    line->style_val = cur_styleval * (cur_linewidth + 1) / 2;
    line->points = first_point;
    if (!dot) {
	if (cur_mode == F_POLYGON) {	/* close off polygon */
	    line->type = T_POLYGON;
	    num_point++;
	    append_point(first_point->x, first_point->y, &cur_point);
	    elastic_line();
	    fix_x = first_point->x;
	    fix_y = first_point->y;
	    elastic_line();	/* fix last elastic line */
	} else {		/* polyline; draw any arrows */
	    if (autoforwardarrow_mode && !dimension_line)
		line->for_arrow = forward_arrow();
	    /* arrow will be drawn in draw_line below */
	    if (autobackwardarrow_mode && !dimension_line)
		line->back_arrow = backward_arrow();
	    /* arrow will be drawn in draw_line below */
	}
	cur_x = fix_x;
	cur_y = fix_y;
	elastic_moveline(first_point);	/* erase temporary outline */
    }
    if (dimension_line) {
	comp = create_dimension_line(line, True);
	reset_action_on(); /* this signals redisplay_curobj() not to refresh */
	/* draw it and anything on top of it */
	redisplay_compound(comp);
    } else {
	add_line(line);
	reset_action_on(); /* this signals redisplay_curobj() not to refresh */
	/* draw it and anything on top of it */
	redisplay_line(line);
    }
    line_drawing_selected();
    if (!edit_remember_dimline_mode)
	draw_mousefun_canvas();
}