예제 #1
0
static gboolean button_pressed (GtkWidget *widget, GdkEventButton *event, gpointer data)
  {
  QCADDesignObject *obj = NULL ;
  double xWorld = real_to_world_x (event->x), yWorld = real_to_world_y (event->y) ;

  if (1 != event->button) return FALSE ;

#ifdef DESIGNER
  world_to_grid_pt (&xWorld, &yWorld) ;
#endif /* def DESIGNER */

//  fprintf (stderr, "QCADRectangleElectrode::button_pressed:Calling qcad_rectangle_electrode_new\n") ;
  obj = QCAD_DESIGN_OBJECT (qcad_object_new_from_object (qcad_object_get_default (QCAD_TYPE_RECTANGLE_ELECTRODE))) ;
//  fprintf (stderr, "QCADRectangleElectrode::button_pressed:Calling qcad_design_object_move\n") ;
  qcad_design_object_move_to (obj, xWorld, yWorld) ;

#ifdef DESIGNER
  if (NULL != drop_function)
    if ((*drop_function) (obj))
      return FALSE ;
#endif /* def DESIGNER */

  g_object_unref (obj) ;

  return FALSE ;
  }
예제 #2
0
static void draw (QCADDesignObject *obj, GdkDrawable *dst, GdkFunction rop)
  {
  GdkGC *gc = NULL ;
  GdkRectangle rcReal ;
  QCADRuler *ruler = QCAD_RULER (obj) ;
  double
    dCurrentGrad = 0 ;
  int iPowerOfTen = 0 ;
  int idx = -1 ;
  gboolean bVertical = (QCAD_RULER_ORIENTATION_EAST == ruler->orientation || QCAD_RULER_ORIENTATION_WEST == ruler->orientation) ;
  QCADLabel *lblGrad = NULL ;

  world_to_real_rect (&(ruler->ruler_bounding_box), &rcReal) ;

  gc = gdk_gc_new (dst) ;
  gdk_gc_set_function (gc, rop) ;
  gdk_gc_set_foreground (gc, &(obj->clr)) ;

  // Graduation lines should be at least MIN_GRADATION_DISTANCE_PIXELS pixels apart
  iPowerOfTen =
    (int)ceil (log10 (bVertical
      ? real_to_world_cy (MIN_GRADATION_DISTANCE_PIXELS)
      : real_to_world_cx (MIN_GRADATION_DISTANCE_PIXELS))) ;

  ruler->icLabelsVisible = 0 ;

  if (bVertical)
    {
    int xBeg = 0, xEnd = 0, xMid = 0, yReal = 0.0 ;
    double xBegWorld, xEndWorld, xMidWorld, yWorld ;

    if (QCAD_RULER_ORIENTATION_WEST == ruler->orientation)
      {
      xBeg = world_to_real_x (xBegWorld = ruler->ruler_bounding_box.xWorld),
      xEnd = world_to_real_x (xEndWorld = ruler->ruler_bounding_box.xWorld + ruler->ruler_bounding_box.cxWorld) ;
      }
    else
      {
      xBeg = world_to_real_x (xBegWorld = ruler->ruler_bounding_box.xWorld + ruler->ruler_bounding_box.cxWorld),
      xEnd = world_to_real_x (xEndWorld = ruler->ruler_bounding_box.xWorld) ;
      }
    xMid = world_to_real_x (xMidWorld = ruler->ruler_bounding_box.xWorld + ruler->ruler_bounding_box.cxWorld / 2.0) ;

    for (dCurrentGrad = 0 ; dCurrentGrad < ruler->ruler_bounding_box.cyWorld ; dCurrentGrad += pow (10, iPowerOfTen))
      {
      idx++ ;
      idx %= 10 ;
      yReal = world_to_real_y (yWorld = ruler->ruler_bounding_box.yWorld + dCurrentGrad) ;
      gdk_draw_line (dst, gc, xBeg, yReal, (0 == idx ? xEnd : xMid), yReal) ;

      if (0 == idx)
        {
        lblGrad = get_label_from_array (ruler->labels, (ruler->icLabelsVisible)++, dCurrentGrad, &(obj->clr)) ;
        qcad_label_shrinkwrap (lblGrad) ;
        qcad_design_object_move_to (QCAD_DESIGN_OBJECT (lblGrad), xEndWorld, yWorld) ;
        qcad_design_object_draw (QCAD_DESIGN_OBJECT (lblGrad), dst, rop) ;
        }
      }
    gdk_draw_line (dst, gc, xBeg, rcReal.y, xBeg, rcReal.y + rcReal.height) ;

    lblGrad = get_label_from_array (ruler->labels, (ruler->icLabelsVisible)++, ruler->ruler_bounding_box.cyWorld, &(obj->clr)) ;
    qcad_label_shrinkwrap (lblGrad) ;
    qcad_design_object_move_to (QCAD_DESIGN_OBJECT (lblGrad), xBegWorld, ruler->ruler_bounding_box.yWorld + ruler->ruler_bounding_box.cyWorld) ;
    qcad_design_object_draw (QCAD_DESIGN_OBJECT (lblGrad), dst, rop) ;
    }
  else
    {
    int yBeg = 0, yEnd = 0, yMid = 0, xReal = 0.0 ;
    double yBegWorld, yEndWorld, yMidWorld, xWorld ;

    if (QCAD_RULER_ORIENTATION_NORTH == ruler->orientation)
      {
      yBeg = world_to_real_y (yBegWorld = ruler->ruler_bounding_box.yWorld),
      yEnd = world_to_real_y (yEndWorld = ruler->ruler_bounding_box.yWorld + ruler->ruler_bounding_box.cyWorld) ;
      }
    else
      {
      yBeg = world_to_real_y (yBegWorld = ruler->ruler_bounding_box.yWorld + ruler->ruler_bounding_box.cyWorld),
      yEnd = world_to_real_y (yEndWorld = ruler->ruler_bounding_box.yWorld) ;
      }
    yMid = world_to_real_y (yMidWorld = ruler->ruler_bounding_box.yWorld + ruler->ruler_bounding_box.cyWorld / 2.0) ;

    for (dCurrentGrad = 0 ; dCurrentGrad < ruler->ruler_bounding_box.cxWorld ; dCurrentGrad += pow (10, iPowerOfTen))
      {
      idx++ ;
      idx %= 10 ;
      xReal = world_to_real_x (xWorld = ruler->ruler_bounding_box.xWorld + dCurrentGrad) ;
      gdk_draw_line (dst, gc, xReal, yBeg, xReal, (0 == idx ? yEnd : yMid)) ;

      if (0 == idx)
        {
        lblGrad = get_label_from_array (ruler->labels, (ruler->icLabelsVisible)++, dCurrentGrad, &(obj->clr)) ;
        qcad_label_shrinkwrap (lblGrad) ;
        qcad_design_object_move_to (QCAD_DESIGN_OBJECT (lblGrad), xWorld, yEndWorld) ;
        qcad_design_object_draw (QCAD_DESIGN_OBJECT (lblGrad), dst, rop) ;
        }
      }
    gdk_draw_line (dst, gc, rcReal.x, yBeg, rcReal.x + rcReal.width, yBeg) ;

    lblGrad = get_label_from_array (ruler->labels, (ruler->icLabelsVisible)++, ruler->ruler_bounding_box.cxWorld, &(obj->clr)) ;
    qcad_label_shrinkwrap (lblGrad) ;
    qcad_design_object_move_to (QCAD_DESIGN_OBJECT (lblGrad), ruler->ruler_bounding_box.xWorld + ruler->ruler_bounding_box.cxWorld, yBegWorld) ;
    qcad_design_object_draw (QCAD_DESIGN_OBJECT (lblGrad), dst, rop) ;
    }

  g_object_unref (gc) ;
  }