コード例 #1
0
ファイル: handle_ops.c プロジェクト: UIKit0/dia
void
handle_draw(Handle *handle, DDisplay *ddisp)
{
  gboolean some_selected;
  int x,y;
  DiaRenderer *renderer = ddisp->renderer;
  DiaInteractiveRendererInterface *irenderer =
    DIA_GET_INTERACTIVE_RENDERER_INTERFACE (ddisp->renderer);
  const Color *color;

  ddisplay_transform_coords(ddisp, handle->pos.x, handle->pos.y, &x, &y);
  /* change handle color to reflect different behaviour for multiple selected */
  /* this code relies on the fact that only selected objects get their handles drawn */
  some_selected = g_list_length (ddisp->diagram->data->selected) > 1;

  if  (handle->connected_to != NULL) {
    color = &handle_color_connected[handle->type + (some_selected ? NUM_HANDLE_TYPES : 0)];
  } else {
    color = &handle_color[handle->type + (some_selected ? NUM_HANDLE_TYPES : 0)];
  }

  DIA_RENDERER_GET_CLASS(renderer)->set_linewidth(renderer, 0.0);
  DIA_RENDERER_GET_CLASS(renderer)->set_linestyle(renderer, LINESTYLE_SOLID);
  DIA_RENDERER_GET_CLASS(renderer)->set_linejoin(renderer, LINEJOIN_MITER);
  DIA_RENDERER_GET_CLASS(renderer)->set_fillstyle(renderer, FILLSTYLE_SOLID);
  

  irenderer->fill_pixel_rect(renderer,
			     x - HANDLE_SIZE/2 + 1,
			     y - HANDLE_SIZE/2 + 1,
			     HANDLE_SIZE-2, HANDLE_SIZE-2,
			     /* it does not change the color, but does not reflect taht in the signature */
			     (Color *)color);
  
  irenderer->draw_pixel_rect(renderer,
			     x - HANDLE_SIZE/2,
			     y - HANDLE_SIZE/2,
			     HANDLE_SIZE-1, HANDLE_SIZE-1,
			     &color_black);

    
  
  if (handle->connect_type != HANDLE_NONCONNECTABLE) {
    irenderer->draw_pixel_line
                         (renderer,
			  x - HANDLE_SIZE/2, y - HANDLE_SIZE/2,
			  x + HANDLE_SIZE/2, y + HANDLE_SIZE/2,
			  &color_black);
    irenderer->draw_pixel_line
                         (renderer,
			  x - HANDLE_SIZE/2, y + HANDLE_SIZE/2,
			  x + HANDLE_SIZE/2, y - HANDLE_SIZE/2,
			  &color_black);
  }
}
コード例 #2
0
/*
 * Wrapper functions using the above
 */
void 
dia_renderer_set_size (DiaRenderer* renderer, gpointer window, 
                       int width, int height)
{
  DiaInteractiveRendererInterface *irenderer =
    DIA_GET_INTERACTIVE_RENDERER_INTERFACE (renderer);

  g_return_if_fail (irenderer != NULL);
  g_return_if_fail (irenderer->set_size != NULL);

  irenderer->set_size (renderer, window, width, height);
}
コード例 #3
0
void
pagebreak_draw(DDisplay *ddisp, Rectangle *update)
{
  DiaRenderer *renderer = ddisp->renderer;
  DiaInteractiveRendererInterface *irenderer;

  int width = dia_renderer_get_width_pixels(ddisp->renderer);
  int height = dia_renderer_get_height_pixels(ddisp->renderer);
  
  irenderer = DIA_GET_INTERACTIVE_RENDERER_INTERFACE (renderer);
  if (prefs.pagebreak.visible) {
    Diagram *dia = ddisp->diagram;
    real origx = 0, origy = 0, pos;
    real pwidth = dia->data->paper.width;
    real pheight = dia->data->paper.height;
    int x,y;

    DIA_RENDERER_GET_CLASS(renderer)->set_linewidth(renderer, 0.0);
    if (prefs.pagebreak.solid)
      DIA_RENDERER_GET_CLASS(renderer)->set_linestyle(renderer, LINESTYLE_SOLID, 0.0);
    else
      DIA_RENDERER_GET_CLASS(renderer)->set_linestyle(renderer, LINESTYLE_DOTTED,
						      ddisplay_untransform_length(ddisp, 31));

    if (dia->data->paper.fitto) {
      origx = dia->data->extents.left;
      origy = dia->data->extents.top;
    }

    /* vertical lines ... */
    pos = origx + ceil((update->left - origx) / pwidth) * pwidth;
    while (pos <= update->right) {
      ddisplay_transform_coords(ddisp, pos,0,&x,&y);
      irenderer->draw_pixel_line(renderer,
                                 x, 0, x, height,
				 &dia->pagebreak_color);
      pos += pwidth;
    }
    /* Horizontal lines: */
    pos = origy + ceil((update->top - origy) / pheight) * pheight;
    while (pos <= update->bottom) {
      ddisplay_transform_coords(ddisp, 0,pos,&x,&y);
      irenderer->draw_pixel_line(renderer,
				 0, y, width, y,
				 &dia->pagebreak_color);
      pos += pheight;
    }
  }
}
コード例 #4
0
static void
grid_draw_horizontal_lines(DDisplay *ddisp, Rectangle *update, real length) 
{
  int x, y;
  real pos;
  int height, width;
  guint major_lines = ddisp->diagram->grid.major_lines;
  DiaRenderer *renderer = ddisp->renderer;
  DiaInteractiveRendererInterface *irenderer;
  int major_count = 0;

  irenderer = DIA_GET_INTERACTIVE_RENDERER_INTERFACE (renderer);

  pos = ceil( update->top / length ) * length;
  ddisplay_transform_coords(ddisp, update->left, pos, &x, &y);
  ddisplay_transform_coords(ddisp, update->right, update->bottom, &width, &height);

  /*
    Explanatory note from Lawrence Withers ([email protected]):
    Think about it in terms of the maths and the modulo arithmetic; we
    have a number P such that P < 0, and we want to find a number Q
    such that Q >= 0, but (P % major_count) == (Q % major_count). To
    do this, we say Q = P - (P * major_count), which is guaranteed to
    give a correct answer if major_count > 0 (since the addition of
    anf multiple of major_count won't alter the modulo).
  */

  if (major_lines) {
    major_count = ROUND (pos/length);
    if(major_count < 0) major_count -= major_lines * major_count;
    major_count %= major_lines;
  }

  while (y < height) {
    if (major_lines) {
      if (major_count == 0)
	DIA_RENDERER_GET_CLASS(renderer)->set_linestyle(renderer, LINESTYLE_SOLID, 0.0);
      else
	DIA_RENDERER_GET_CLASS(renderer)->set_linestyle(renderer, LINESTYLE_DOTTED,
							ddisplay_untransform_length(ddisp, 31));
      major_count = (major_count+1)%major_lines;
    }
    irenderer->draw_pixel_line(renderer, x, y, width, y,
			       &ddisp->diagram->grid.colour);
    pos += length;
    ddisplay_transform_coords(ddisp, update->left, pos, &x, &y);
  }
}
コード例 #5
0
ファイル: display.c プロジェクト: chebizarro/dia
static void
ddisplay_obj_render(DiaObject *obj, DiaRenderer *renderer,
		    int active_layer,
		    gpointer data)
{
  DDisplay *ddisp = (DDisplay *)data;
  DiaInteractiveRendererInterface *irenderer =
    DIA_GET_INTERACTIVE_RENDERER_INTERFACE (renderer);
  DiaHighlightType hltype = data_object_get_highlight(DIA_DIAGRAM_DATA(ddisp->diagram), obj);

  if (hltype != DIA_HIGHLIGHT_NONE && irenderer->draw_object_highlighted != NULL)
    irenderer->draw_object_highlighted(renderer, obj, hltype);
  else /* maybe the renderer does not support highlighting */
    DIA_RENDERER_GET_CLASS(renderer)->draw_object(renderer, obj, NULL);

  if (ddisp->show_cx_pts && 
      obj->parent_layer != NULL && obj->parent_layer->connectable) {
    object_draw_connectionpoints(obj, ddisp);
  }
}
コード例 #6
0
static void
grid_draw_vertical_lines(DDisplay *ddisp, Rectangle *update, real length) 
{
  int x = 0, y = 0;
  real pos;
  int height, width;
  guint major_lines = ddisp->diagram->grid.major_lines;
  DiaRenderer *renderer = ddisp->renderer;
  DiaInteractiveRendererInterface *irenderer;
  int major_count = 0;

  irenderer = DIA_GET_INTERACTIVE_RENDERER_INTERFACE (renderer);

  pos = ceil( update->left / length ) * length;
  ddisplay_transform_coords(ddisp, update->right, update->bottom, &width, &height);

  if (major_lines) {
    major_count = ROUND (pos/length);
    if(major_count < 0) major_count -= major_lines * major_count;
    major_count %= major_lines;
  }

  while (x < width) {
    ddisplay_transform_coords(ddisp, pos, update->top, &x, &y);
    if (major_lines) {
      if (major_count == 0)
	DIA_RENDERER_GET_CLASS(renderer)->set_linestyle(renderer, LINESTYLE_SOLID, 0.0);
      else
	DIA_RENDERER_GET_CLASS(renderer)->set_linestyle(renderer, LINESTYLE_DOTTED,
							ddisplay_untransform_length(ddisp, 31));
      major_count = (major_count+1)%major_lines;
    }
    irenderer->draw_pixel_line(renderer, x, y, x, height,
			       &ddisp->diagram->grid.colour);
    pos += length;
  }
}
コード例 #7
0
static void
grid_draw_hex(DDisplay *ddisp, Rectangle *update, real length)
{
  real horiz_pos, vert_pos;
  int to_x, to_y, x, y;
  DiaRenderer *renderer = ddisp->renderer;
  DiaInteractiveRendererInterface *irenderer;

  irenderer = DIA_GET_INTERACTIVE_RENDERER_INTERFACE (renderer);

  /* First horizontal lines: */
  vert_pos = ceil( update->top / (length * sqrt(3)) ) * length * sqrt(3);
  while (vert_pos <= update->bottom) {
    horiz_pos = ceil( (update->left) / (3 * length) ) * length * 3 - length * 2.5;
    while (horiz_pos <= update->right) {
      ddisplay_transform_coords(ddisp, horiz_pos, vert_pos, &x, &y);
      ddisplay_transform_coords(ddisp, horiz_pos + length, vert_pos, &to_x, &y);
	  
      irenderer->draw_pixel_line(renderer,
				 x, y, to_x, y,
				 &ddisp->diagram->grid.colour);
      horiz_pos += 3 * length;
    }
	
    vert_pos += sqrt(3) * length;
  }

  /*  Second horizontal lines: */
  vert_pos = ceil( update->top / (length * sqrt(3)) ) * length * sqrt(3) - 0.5 * sqrt(3) * length;
  while (vert_pos <= update->bottom) {
    horiz_pos = ceil( (update->left) / (3 * length) ) * length * 3 - length;
    while (horiz_pos <= update->right) {
      ddisplay_transform_coords(ddisp, horiz_pos, vert_pos, &x, &y);
      ddisplay_transform_coords(ddisp, horiz_pos+length, vert_pos, &to_x, &y);
	  
      irenderer->draw_pixel_line(renderer,
				 x, y, to_x, y,
				 &ddisp->diagram->grid.colour);
      horiz_pos += 3 * length;
    }
	
    vert_pos += sqrt(3) * length;
  }

  /* First \'s and /'s */
  vert_pos = ceil( update->top / (length * sqrt(3)) ) * length * sqrt(3) - length * sqrt(3);
  while (vert_pos <= update->bottom) {
    horiz_pos = ceil( (update->left) / (3 * length) ) * length * 3 - length * 2.5;
    while (horiz_pos <= update->right) {
      ddisplay_transform_coords(ddisp, horiz_pos + length, vert_pos, &x, &y);
      ddisplay_transform_coords(ddisp, horiz_pos + 1.5 * length, vert_pos + length * sqrt(3) * 0.5, &to_x, &to_y);
	  
      irenderer->draw_pixel_line(renderer,
				 x, y, to_x, to_y,
				 &ddisp->diagram->grid.colour);

      ddisplay_transform_coords(ddisp, horiz_pos, vert_pos, &x, &y);
      ddisplay_transform_coords(ddisp, horiz_pos - 0.5 * length, vert_pos + length * sqrt(3) * 0.5, &to_x, &to_y);
	  
      irenderer->draw_pixel_line(renderer,
				 x, y, to_x, to_y,
				 &ddisp->diagram->grid.colour);
      horiz_pos += 3 * length;
    }
	
    vert_pos += sqrt(3) * length;
  }

  /*  Second \'s and /'s */
  vert_pos = ceil( update->top / (length * sqrt(3)) ) * length * sqrt(3) - 0.5 * sqrt(3) * length;
  while (vert_pos <= update->bottom) {
    horiz_pos = ceil( (update->left) / (3 * length) ) * length * 3 - length;
    while (horiz_pos <= update->right) {
      ddisplay_transform_coords(ddisp, horiz_pos, vert_pos, &x, &y);
      ddisplay_transform_coords(ddisp, horiz_pos - 0.5 * length, vert_pos + 0.5 * sqrt(3) * length, &to_x, &to_y);
	  
      irenderer->draw_pixel_line(renderer,
				 x, y, to_x, to_y,
				 &ddisp->diagram->grid.colour);

      ddisplay_transform_coords(ddisp, horiz_pos + length, vert_pos, &x, &y);
      ddisplay_transform_coords(ddisp, horiz_pos + 1.5 * length, vert_pos + 0.5 * sqrt(3) * length, &to_x, &to_y);
	  
      irenderer->draw_pixel_line(renderer,
				 x, y, to_x, to_y,
				 &ddisp->diagram->grid.colour);
      horiz_pos += 3 * length;
    }

    vert_pos += sqrt(3) * length;
  }

}
コード例 #8
0
ファイル: display.c プロジェクト: chebizarro/dia
void
ddisplay_render_pixmap(DDisplay *ddisp, Rectangle *update)
{
  GList *list;
  DiaObject *obj;
  int i;
  DiaInteractiveRendererInterface *renderer;
#ifdef TRACES
  GTimer *timer;
#endif
  
  if (ddisp->renderer==NULL) {
    printf("ERROR! Renderer was NULL!!\n");
    return;
  }

  renderer = DIA_GET_INTERACTIVE_RENDERER_INTERFACE (ddisp->renderer);

  /* Erase background */
  g_return_if_fail (renderer->fill_pixel_rect != NULL);
  DIA_RENDERER_GET_CLASS(ddisp->renderer)->begin_render(ddisp->renderer, update);
  if (update) {
    int x0, y0, x1, y1;

    ddisplay_transform_coords (ddisp, update->left, update->top, &x0, &y0);
    ddisplay_transform_coords (ddisp, update->right, update->bottom, &x1, &y1);
    renderer->fill_pixel_rect (ddisp->renderer,
			       x0, y0, x1-x0, y1-y0,
			       &ddisp->diagram->data->bg_color);
  } else
    renderer->fill_pixel_rect (ddisp->renderer,
			       0, 0,
		               dia_renderer_get_width_pixels (ddisp->renderer),
			       dia_renderer_get_height_pixels (ddisp->renderer),
			       &ddisp->diagram->data->bg_color);

  /* Draw grid */
  grid_draw(ddisp, update);
  pagebreak_draw(ddisp, update);

#ifdef TRACES
  timer = g_timer_new();
#endif
  data_render(ddisp->diagram->data, ddisp->renderer, update,
	      ddisplay_obj_render, (gpointer) ddisp);
#ifdef TRACES
  g_print ("data_render(%g%%) took %g seconds\n", ddisp->zoom_factor * 5.0, g_timer_elapsed (timer, NULL));
  g_timer_destroy (timer);
#endif
  /* Draw handles for all selected objects */
  list = ddisp->diagram->data->selected;
  while (list!=NULL) {
    obj = (DiaObject *) list->data;

    for (i=0;i<obj->num_handles;i++) {
       handle_draw(obj->handles[i], ddisp);
     }
    list = g_list_next(list);
  }
  DIA_RENDERER_GET_CLASS(ddisp->renderer)->end_render(ddisp->renderer);
}
コード例 #9
0
ファイル: display.c プロジェクト: chebizarro/dia
static gboolean
ddisplay_update_handler(DDisplay *ddisp)
{
  GSList *l;
  IRectangle *ir;
  Rectangle *r, totrect;
  DiaInteractiveRendererInterface *renderer;

  g_return_val_if_fail (ddisp->renderer != NULL, FALSE);

  /* Renders updates to pixmap + copies display_areas to canvas(screen) */
  renderer = DIA_GET_INTERACTIVE_RENDERER_INTERFACE (ddisp->renderer);

  /* Only update if update_areas exist */
  l = ddisp->update_areas;
  if (l != NULL)
  {
    totrect = *(Rectangle *) l->data;
  
    g_return_val_if_fail (   renderer->clip_region_clear != NULL
                          && renderer->clip_region_add_rect != NULL, FALSE);

    renderer->clip_region_clear (ddisp->renderer);

    while(l!=NULL) {
      r = (Rectangle *) l->data;

      rectangle_union(&totrect, r);
      renderer->clip_region_add_rect (ddisp->renderer, r);
      
      l = g_slist_next(l);
    }
    /* Free update_areas list: */
    ddisplay_free_update_areas(ddisp);

    totrect.left -= 0.1;
    totrect.right += 0.1;
    totrect.top -= 0.1;
    totrect.bottom += 0.1;
    
    ddisplay_render_pixmap(ddisp, &totrect);
  }

  l = ddisp->display_areas;
  while(l!=NULL) {
    ir = (IRectangle *) l->data;

    g_return_val_if_fail (renderer->copy_to_window, FALSE);
    renderer->copy_to_window(ddisp->renderer, 
                             gtk_widget_get_window(ddisp->canvas),
                             ir->left, ir->top,
                             ir->right - ir->left, ir->bottom - ir->top);
    
    l = g_slist_next(l);
  }

  ddisplay_free_display_areas(ddisp);

  ddisp->update_id = 0;

  return FALSE;
}