Ejemplo n.º 1
0
void
ghack_map_cliparound(GtkWidget *win, int x, int y, gpointer data)
{
    int map_width, map_height;
    int to_x, to_y;
    int cur_x, cur_y;
    int width, height, half_width, half_height;

    x *= ghack_glyph_width() * ghack_map.zoom;
    y *= ghack_glyph_height() * ghack_map.zoom;
    map_width = COLNO * ghack_glyph_width() * ghack_map.zoom;
    map_height = ROWNO * ghack_glyph_height() * ghack_map.zoom;

    gdk_window_get_size(GTK_LAYOUT(ghack_map.canvas)->bin_window, &width,
                        &height);
    gnome_canvas_get_scroll_offsets(ghack_map.canvas, &cur_x, &cur_y);

    half_width = width * 0.5;
    half_height = height * 0.5;

    if (((x - cur_x) < (width * 0.25)) || ((x - cur_x) > (width * 0.75))) {
        to_x = ((x - half_width) > 0) ? x - half_width : 0;
        to_x = ((x + half_width) > map_width) ? map_width - 2 * half_width
               : to_x;
    } else {
        to_x = cur_x;
    }

    if (((y - cur_y) < (height * 0.25)) || ((y - cur_y) > (height * 0.75))) {
        to_y = ((y - half_height) > 0) ? y - half_height : 0;
        to_y = ((y + half_height) > map_height) ? map_height - 2 * half_height
               : to_y;
    } else {
        to_y = cur_y;
    }

    if (to_x != cur_x || to_y != cur_y)
        gnome_canvas_scroll_to(ghack_map.canvas, to_x, to_y);
    // gnome_canvas_update_now ( ghack_map.canvas);
}
Ejemplo n.º 2
0
gboolean
starchart_event_pointer_motion         (GtkWidget       *widget,
                                        GdkEventMotion  *event,
                                        gpointer         user_data)
{
  gint x, y;
  gint16 vpx, vpy;
  gdouble wx, wy;
  static guint interleave;
  static gint pointer_x = 0, pointer_y = 0;
  static gboolean panning = FALSE;
  
  /* First get canvas coords */
  x = (gint) event->x;
  y = (gint) event->y;

  /* If we are dragging the starchart to pan... */
  if((event->state & (GDK_BUTTON1_MASK)) == (GDK_BUTTON1_MASK)) {
    gint offset_x, offset_y;

    /* Check if extra panels are closed, panning is deactivated when open */
    if (!gwp_game_state_get_extra_panel_open(game_state)) {
      
      /* Set drag cursor */
      if(!panning) {
	starchart_set_pan_cursor();
	panning = TRUE;
      }

      /* Do panning */       
      if((interleave++ % MOUSE_INTERLEAVE) == 0) {
	gnome_canvas_get_scroll_offsets(starchart_get_canvas(), 
					&offset_x, 
					&offset_y);
	starchart_scroll_to(offset_x + (pointer_x - x) * (MOUSE_INTERLEAVE+1), 
			    offset_y + (pointer_y - y) * (MOUSE_INTERLEAVE+1));
      }
    } 
  }
  /* If not panning... */
  else {

    /* Reset cursor */
    if(panning) {
      starchart_set_default_cursor();
      panning = FALSE;
    }

    /* Translate coords to World system */
    gnome_canvas_c2w(GNOME_CANVAS(widget), x, y, &wx, &wy);
    
    /* Assign VP coords to game state*/
    vp_coord_w2v (wx, wy, &vpx, &vpy);
    g_object_set (game_state,
		  "x-coord", vpx,
		  "y-coord", vpy,
		  NULL);

    /* Update coord indicator */
    starchart_update_coord_panel(widget, wx, wy);

    /* Distance calculation stuff */
    /*    starchart_update_distance_calc (wx, wy);*/
  }

  pointer_x = (gint) event->x;
  pointer_y = (gint) event->y;

  return FALSE;
}
Ejemplo n.º 3
0
// paste xournal native data
void clipboard_paste_from_xournal(GtkSelectionData *sel_data)
{
  unsigned char *p;
  int nitems, npts, i, len;
  struct Item *item;
  double hoffset, voffset, cx, cy;
  double *pf;
  int sx, sy, wx, wy;
  
  reset_selection();
  
  ui.selection = g_new(struct Selection, 1);
  p = sel_data->data + sizeof(int);
  g_memmove(&nitems, p, sizeof(int)); p+= sizeof(int);
  ui.selection->type = ITEM_SELECTRECT;
  ui.selection->layer = ui.cur_layer;
  g_memmove(&ui.selection->bbox, p, sizeof(struct BBox)); p+= sizeof(struct BBox);
  ui.selection->items = NULL;
  
  // find by how much we translate the pasted selection
  gnome_canvas_get_scroll_offsets(canvas, &sx, &sy);
  gdk_window_get_geometry(GTK_WIDGET(canvas)->window, NULL, NULL, &wx, &wy, NULL);
  gnome_canvas_window_to_world(canvas, sx + wx/2, sy + wy/2, &cx, &cy);
  cx -= ui.cur_page->hoffset;
  cy -= ui.cur_page->voffset;
  if (cx + (ui.selection->bbox.right-ui.selection->bbox.left)/2 > ui.cur_page->width)
    cx = ui.cur_page->width - (ui.selection->bbox.right-ui.selection->bbox.left)/2;
  if (cx - (ui.selection->bbox.right-ui.selection->bbox.left)/2 < 0)
    cx = (ui.selection->bbox.right-ui.selection->bbox.left)/2;
  if (cy + (ui.selection->bbox.bottom-ui.selection->bbox.top)/2 > ui.cur_page->height)
    cy = ui.cur_page->height - (ui.selection->bbox.bottom-ui.selection->bbox.top)/2;
  if (cy - (ui.selection->bbox.bottom-ui.selection->bbox.top)/2 < 0)
    cy = (ui.selection->bbox.bottom-ui.selection->bbox.top)/2;
  hoffset = cx - (ui.selection->bbox.right+ui.selection->bbox.left)/2;
  voffset = cy - (ui.selection->bbox.top+ui.selection->bbox.bottom)/2;
  ui.selection->bbox.left += hoffset;
  ui.selection->bbox.right += hoffset;
  ui.selection->bbox.top += voffset;
  ui.selection->bbox.bottom += voffset;

  ui.selection->canvas_item = gnome_canvas_item_new(ui.cur_layer->group,
      gnome_canvas_rect_get_type(), "width-pixels", 1,
      "outline-color-rgba", 0x000000ff,
      "fill-color-rgba", 0x80808040,
      "x1", ui.selection->bbox.left, "x2", ui.selection->bbox.right, 
      "y1", ui.selection->bbox.top, "y2", ui.selection->bbox.bottom, NULL);
  make_dashed(ui.selection->canvas_item);

  while (nitems-- > 0) {
    item = g_new(struct Item, 1);
    ui.selection->items = g_list_append(ui.selection->items, item);
    ui.cur_layer->items = g_list_append(ui.cur_layer->items, item);
    ui.cur_layer->nitems++;
    g_memmove(&item->type, p, sizeof(int)); p+= sizeof(int);
    if (item->type == ITEM_STROKE) {
      g_memmove(&item->brush, p, sizeof(struct Brush)); p+= sizeof(struct Brush);
      g_memmove(&npts, p, sizeof(int)); p+= sizeof(int);
      item->path = gnome_canvas_points_new(npts);
      pf = (double *)p;
      for (i=0; i<npts; i++) {
        item->path->coords[2*i] = pf[2*i] + hoffset;
        item->path->coords[2*i+1] = pf[2*i+1] + voffset;
      }
      p+= 2*item->path->num_points*sizeof(double);
      if (item->brush.variable_width) {
        item->widths = g_memdup(p, (item->path->num_points-1)*sizeof(double));
        p+= (item->path->num_points-1)*sizeof(double);
      }
      else item->widths = NULL;
      update_item_bbox(item);
      make_canvas_item_one(ui.cur_layer->group, item);
    }
    if (item->type == ITEM_TEXT) {
      g_memmove(&item->brush, p, sizeof(struct Brush)); p+= sizeof(struct Brush);
      g_memmove(&item->bbox.left, p, sizeof(double)); p+= sizeof(double);
      g_memmove(&item->bbox.top, p, sizeof(double)); p+= sizeof(double);
      item->bbox.left += hoffset;
      item->bbox.top += voffset;
      g_memmove(&len, p, sizeof(int)); p+= sizeof(int);
      item->text = g_malloc(len+1);
      g_memmove(item->text, p, len+1); p+= len+1;
      g_memmove(&len, p, sizeof(int)); p+= sizeof(int);
      item->font_name = g_malloc(len+1);
      g_memmove(item->font_name, p, len+1); p+= len+1;
      g_memmove(&item->font_size, p, sizeof(double)); p+= sizeof(double);
      make_canvas_item_one(ui.cur_layer->group, item);
    }
    if (item->type == ITEM_IMAGE) {
      item->canvas_item = NULL;
      item->image_png = NULL;
      item->image_png_len = 0;
      g_memmove(&item->bbox, p, sizeof(struct BBox)); p+= sizeof(struct BBox);
      item->bbox.left += hoffset;
      item->bbox.right += hoffset;
      item->bbox.top += voffset;
      item->bbox.bottom += voffset;
      g_memmove(&item->image_png_len, p, sizeof(gsize)); p+= sizeof(gsize);
      if (item->image_png_len > 0) {
        item->image_png = g_memdup(p, item->image_png_len);
        item->image = pixbuf_from_buffer(item->image_png, item->image_png_len);
        p+= item->image_png_len;
      } else {
        item->image = NULL;
      }
      make_canvas_item_one(ui.cur_layer->group, item);
    }
  }

  prepare_new_undo();
  undo->type = ITEM_PASTE;
  undo->layer = ui.cur_layer;
  undo->itemlist = g_list_copy(ui.selection->items);  
  
  gtk_selection_data_free(sel_data);
  update_copy_paste_enabled();
  update_color_menu();
  update_thickness_buttons();
  update_color_buttons();
  update_font_button();  
  update_cursor(); // FIXME: can't know if pointer is within selection!
}