예제 #1
0
void 
undo_create_mask ( gint width, gint height, GdkBitmap **mask, GdkGC **gc_mask )
{
    GdkColor    color;
	gp_canvas   *cv	=	cv_get_canvas();
     
    *mask 		=	gdk_pixmap_new (NULL, width, height, 1 );
    *gc_mask	=	gdk_gc_new ( *mask );
    gdk_gc_set_line_attributes ( *gc_mask, cv->line_width, GDK_LINE_SOLID, 
                             	 GDK_CAP_ROUND, GDK_JOIN_ROUND );

    color.pixel = 0;
    gdk_gc_set_foreground (*gc_mask, &color);
    gdk_draw_rectangle (*mask, *gc_mask, TRUE, 0, 0, width, height);

    color.pixel = 1;
    gdk_gc_set_foreground (*gc_mask, &color);
    return;
}
예제 #2
0
파일: vpDisplayGTK.cpp 프로젝트: ricsp/visp
/*!
  Display a circle.
  \param center : Circle center position.
  \param radius : Circle radius.
  \param color : Circle color.
  \param fill : When set to true fill the circle.
  \param thickness : Thickness of the circle. This parameter is only useful 
  when \e fill is set to false.
*/
void vpDisplayGTK::displayCircle ( const vpImagePoint &center,
				   unsigned int radius,
				   const vpColor &color,
				   bool fill,
				   unsigned int thickness )
{
  if (displayHasBeenInitialized)
  {
    if ( thickness == 1 ) thickness = 0;

    if (color.id < vpColor::id_unknown)
      gdk_gc_set_foreground(gc, col[color.id]);
    else {
      gdkcolor.red   = 256 * color.R;
      gdkcolor.green = 256 * color.G;
      gdkcolor.blue  = 256 * color.B;
      gdk_colormap_alloc_color(colormap,&gdkcolor,FALSE,TRUE);
      gdk_gc_set_foreground(gc, &gdkcolor);     
    }

    gdk_gc_set_line_attributes(gc, (gint)thickness,
			       GDK_LINE_SOLID, GDK_CAP_BUTT,
			       GDK_JOIN_BEVEL) ;

    if (fill == false)
      gdk_draw_arc(background, gc, FALSE,
		   vpMath::round( center.get_u()-radius ), 
		   vpMath::round( center.get_v()-radius ),
		   (gint)(2*radius), (gint)(2*radius), 23040, 23040) ; /* 23040 = 360*64 */
    else
      gdk_draw_arc(background, gc, TRUE,
		   vpMath::round( center.get_u()-radius ), 
		   vpMath::round( center.get_v()-radius ),
		   (gint)(2*radius), (gint)(2*radius), 23040, 23040) ; /* 23040 = 360*64 */
  }
  else
  {
    vpERROR_TRACE("GTK not initialized " ) ;
    throw(vpDisplayException(vpDisplayException::notInitializedError,
                             "GTK not initialized")) ;
  }
}
예제 #3
0
파일: draw-gdk.c 프로젝트: rupin/test-gerbv
/*
 * Aperture macro primitive 1 (Circle)
 */
static void
gerbv_gdk_draw_prim1(GdkPixmap *pixmap, GdkGC *gc, double *p, 
		     double scale, gint x, gint y)
{
    const int exposure_idx = 0;
    const int diameter_idx = 1;
    const int x_offset_idx = 2;
    const int y_offset_idx = 3;
    const gint full_circle = 23360;
    GdkGC *local_gc = gdk_gc_new(pixmap);
    gint dia    = round(fabs(p[diameter_idx] * scale));
    gint real_x = x - dia / 2;
    gint real_y = y - dia / 2;
    GdkColor color;

    gdk_gc_copy(local_gc, gc);

    real_x += (int)(p[x_offset_idx] * (double)scale);
    real_y -= (int)(p[y_offset_idx] * (double)scale);

    /* Exposure */
    if (p[exposure_idx] == 0.0) {
	color.pixel = 0;
	gdk_gc_set_foreground(local_gc, &color);
    }

    gdk_gc_set_line_attributes(local_gc, 
			       1, /* outline always 1 pixels */
			       GDK_LINE_SOLID, 
			       GDK_CAP_BUTT, 
			       GDK_JOIN_MITER);

    /* 
     * A filled circle 
     */
    gdk_draw_arc(pixmap, local_gc, 1, real_x, real_y, dia, dia, 
		 0, full_circle);

    gdk_gc_unref(local_gc);

    return;
} /* gerbv_gdk_draw_prim1 */
예제 #4
0
static gint
draw_line (gint        n,
	   gint        startx,
	   gint        starty,
	   gint        pw,
	   gint        ph,
	   gdouble     cx1,
	   gdouble     cy1,
	   gdouble     cx2,
	   gdouble     cy2,
	   GimpVector3 a,
	   GimpVector3 b)
{
  gdouble x1, y1, x2, y2;
  gint    i = n;

  gimp_vector_3d_to_2d (startx, starty, pw, ph,
			&x1, &y1, &mapvals.viewpoint, &a);
  gimp_vector_3d_to_2d (startx, starty, pw, ph,
			&x2, &y2, &mapvals.viewpoint, &b);

  if (clip_line (&x1, &y1, &x2, &y2, cx1, cy1, cx2, cy2) == TRUE)
    {
      linetab[i].x1 = RINT (x1);
      linetab[i].y1 = RINT (y1);
      linetab[i].x2 = RINT (x2);
      linetab[i].y2 = RINT (y2);
      linetab[i].linewidth = 3;
      linetab[i].linestyle = GDK_LINE_SOLID;
      gdk_gc_set_line_attributes (gc,
				  linetab[i].linewidth,
				  linetab[i].linestyle,
				  GDK_CAP_NOT_LAST,
				  GDK_JOIN_MITER);
      gdk_draw_line (previewarea->window, gc,
		     linetab[i].x1, linetab[i].y1,
		     linetab[i].x2, linetab[i].y2);
      i++;
    }

  return i;
}
예제 #5
0
파일: gdl-dock.c 프로젝트: EQ4/samplecat
void
gdl_dock_xor_rect (GdlDock      *dock,
                   GdkRectangle *rect)
{
    GtkWidget *widget;
    gint8      dash_list [2];

    widget = GTK_WIDGET (dock);

    if (!dock->_priv->xor_gc) {
        if (GTK_WIDGET_REALIZED (widget)) {
            GdkGCValues values;

            values.function = GDK_INVERT;
            values.subwindow_mode = GDK_INCLUDE_INFERIORS;
            dock->_priv->xor_gc = gdk_gc_new_with_values 
                (widget->window, &values, GDK_GC_FUNCTION | GDK_GC_SUBWINDOW);
        } else 
            return;
    };

    gdk_gc_set_line_attributes (dock->_priv->xor_gc, 1,
                                GDK_LINE_ON_OFF_DASH,
                                GDK_CAP_NOT_LAST,
                                GDK_JOIN_BEVEL);
    
    dash_list [0] = 1;
    dash_list [1] = 1;
    
    gdk_gc_set_dashes (dock->_priv->xor_gc, 1, dash_list, 2);

    gdk_draw_rectangle (widget->window, dock->_priv->xor_gc, 0, 
                        rect->x, rect->y,
                        rect->width, rect->height);

    gdk_gc_set_dashes (dock->_priv->xor_gc, 0, dash_list, 2);

    gdk_draw_rectangle (widget->window, dock->_priv->xor_gc, 0, 
                        rect->x + 1, rect->y + 1,
                        rect->width - 2, rect->height - 2);
}
예제 #6
0
파일: gtkhid-gdk.c 프로젝트: thequux/pcb
void
ghid_set_line_cap (hidGC gc, EndCapStyle style)
{

    switch (style)
    {
    case Trace_Cap:
    case Round_Cap:
        gc->cap = GDK_CAP_ROUND;
        gc->join = GDK_JOIN_ROUND;
        break;
    case Square_Cap:
    case Beveled_Cap:
        gc->cap = GDK_CAP_PROJECTING;
        gc->join = GDK_JOIN_MITER;
        break;
    }
    if (gc->gc)
        gdk_gc_set_line_attributes (WHICH_GC (gc),
                                    Vz (gc->width), GDK_LINE_SOLID,
                                    (GdkCapStyle)gc->cap, (GdkJoinStyle)gc->join);
}
예제 #7
0
static void
cursor_paint(HosOrnament *self, HosCanvas *canvas)
{

  g_return_if_fail(HOS_IS_CURSOR(self));
  g_return_if_fail(HOS_IS_CANVAS(canvas));
  g_return_if_fail(GTK_WIDGET_DRAWABLE(canvas));

  HosCursor *cursor = HOS_CURSOR(self);
  GtkWidget *widget = GTK_WIDGET(canvas);
  GdkGC *gc = canvas->gc;

  gdouble pos = cursor_get_position(cursor);

  {
    GdkColor color = {0, 0xFFFF, 0xFFFF, 0xFFFF};
    gdk_gc_set_rgb_fg_color(gc, &color);
  }
  gdk_gc_set_line_attributes(gc,
			     1, /* width */
			     GDK_LINE_SOLID,
			     GDK_CAP_BUTT,
			     GDK_JOIN_MITER);

  if (cursor->orientation == HOS_VERTICAL)
    {
      canvas_world2view(canvas, &pos, NULL);
      gdk_draw_line(widget->window,
		    gc, pos, 0, pos, 1000000);
    }
  else
    {
      assert(cursor->orientation == HOS_HORIZONTAL);
      canvas_world2view(canvas, NULL, &pos);
      gdk_draw_line(widget->window,
		    gc, 0, pos, 1000000, pos);
    }
}
예제 #8
0
파일: vnr-crop.c 프로젝트: mcsf/Viewnior
static gboolean
drawable_expose_cb (GtkWidget *widget, GdkEventExpose *event, VnrCrop *crop)
{
    gdk_draw_pixbuf (GDK_DRAWABLE(widget->window), NULL, crop->preview_pixbuf,
                     0, 0, 0, 0, -1, -1, GDK_RGB_DITHER_NORMAL, 0, 0);

    crop->gc = gdk_gc_new(GDK_DRAWABLE(widget->window));
    gdk_gc_set_function (crop->gc, GDK_INVERT);
    gdk_gc_set_line_attributes (crop->gc,
                                2,
                                GDK_LINE_SOLID, GDK_CAP_BUTT, GDK_JOIN_MITER);

    if(crop->sub_width == -1)
    {
        crop->sub_x = 0;
        crop->sub_y = 0;
        crop->sub_width = crop->width;
        crop->sub_height = crop->height;
    }
    vnr_crop_clear_rectangle (crop);

    return FALSE;
}
예제 #9
0
static void 
set_linewidth (DiaRenderer *object, real linewidth)
{
  DiaGdkRenderer *renderer = DIA_GDK_RENDERER (object);

  if (renderer->highlight_color != NULL) {
    /* 6 pixels wide -> 3 pixels beyond normal obj */
    real border = dia_untransform_length(renderer->transform, 6);
    linewidth += border;
  } 

  /* 0 == hairline **/
  renderer->line_width =
    dia_transform_length(renderer->transform, linewidth);

  if (renderer->line_width<=0)
    renderer->line_width = 1; /* Minimum 1 pixel. */

  gdk_gc_set_line_attributes(renderer->gc,
			     renderer->line_width,
			     renderer->line_style,
			     renderer->cap_style,
			     renderer->join_style);
}
예제 #10
0
void
gthumb_draw_frame (int          image_x,
		   int          image_y,
		   int          image_w,
		   int          image_h,
		   GdkDrawable *drawable,
		   GdkColor    *frame_color)
{
	GdkGC    *gc;
	GdkColor  white;
	int       frame_width;

	gc = gdk_gc_new (drawable);

	gdk_color_parse ("#FFFFFF", &white);
	gdk_gc_set_rgb_fg_color (gc, &white);
	gdk_draw_rectangle (drawable,
			    gc,
			    TRUE,
			    image_x, image_y,
			    image_w, image_h);
	
	gdk_gc_set_rgb_fg_color (gc, frame_color); 
	gdk_gc_set_line_attributes (gc, FRAME_WIDTH, 0, 0, 0);

	frame_width = FRAME_WIDTH - 2;
	gdk_draw_rectangle (drawable,
			    gc,
			    FALSE,
			    image_x - frame_width, 
			    image_y - frame_width,
			    image_w + (frame_width * 2) - 1,
			    image_h + (frame_width * 2) - 1);

	g_object_unref (gc);
}
예제 #11
0
파일: render_gdk.c 프로젝트: AmiGanguli/dia
static void
set_size(DiaRenderer *object, gpointer window,
		      int width, int height)
{
  DiaGdkRenderer *renderer = DIA_GDK_RENDERER (object);

  if (renderer->pixmap != NULL)
    g_object_unref(renderer->pixmap);

  if (window)
    renderer->pixmap = gdk_pixmap_new(GDK_WINDOW(window),  width, height, -1);
  else /* the integrated UI insist to call us too early */
    renderer->pixmap = gdk_pixmap_new(NULL,  width, height, 24);

  if (renderer->gc == NULL) {
    renderer->gc = gdk_gc_new(renderer->pixmap);

    gdk_gc_set_line_attributes(renderer->gc,
			       renderer->line_width,
			       renderer->line_style,
			       renderer->cap_style,
			       renderer->join_style);
  }
}
예제 #12
0
/**
 * gwy_graph_label_draw_on_drawable:
 * @label: graph label
 * @drawable: the #GdkDrawable
 * @gc: Graphics context.
 *      It is modified by this function unpredictably.
 * @layout: pango layout
 * @x: x position where label is to be drawn
 * @y: y position where label is to be drawn
 * @width: width of the label
 * @height: hieght of the label
 *
 * draws a graph label on a drawable
 **/
void
gwy_graph_label_draw_on_drawable(GwyGraphLabel *label,
                                 GdkDrawable *drawable,
                                 GdkGC *gc,
                                 PangoLayout *layout,
                                 gint x, gint y,
                                 gint width, gint height)
{
    gint ypos, winheight, winwidth, winx, winy, frame_off;
    gint i, nc;
    GwyGraphCurveModel *curvemodel;
    GwyGraphModel *model;
    PangoRectangle rect;
    GdkColor fg = { 0, 0, 0, 0 };
    GdkColor color = { 0, 65535, 65535, 65535 };

    if (!label->graph_model)
        return;

    model = GWY_GRAPH_MODEL(label->graph_model);
    pango_layout_set_font_description(layout, label->font_desc);

    frame_off = model->label_frame_thickness/2;
    ypos = 5 + frame_off;

    gdk_gc_set_rgb_fg_color(gc, &color);
    gdk_draw_rectangle(drawable, gc, TRUE, x, y, width, height);
    gdk_gc_set_rgb_fg_color(gc, &fg);

    winx = x;
    winy = y;
    winwidth = width;
    winheight = height;

    nc = gwy_graph_model_get_n_curves(model);
    for (i = 0; i < nc; i++) {
        curvemodel = gwy_graph_model_get_curve(model, i);

        pango_layout_set_markup(layout, curvemodel->description->str,
                                curvemodel->description->len);
        pango_layout_get_pixel_extents(layout, NULL, &rect);

        if (model->label_reverse)
            gdk_draw_layout(drawable, gc,
                            winx + winwidth - rect.width - 25 - frame_off,
                            winy + ypos,
                            layout);
        else
            gdk_draw_layout(drawable, gc,
                            winx + 25 + frame_off,
                            winy + ypos,
                            layout);

        g_array_index(label->samplepos, gint, i) = ypos;

        if (curvemodel->mode == GWY_GRAPH_CURVE_LINE
            || curvemodel->mode == GWY_GRAPH_CURVE_LINE_POINTS) {
            if (model->label_reverse)
                gwy_graph_draw_line(drawable, gc,
                                    winx + winwidth - 20 - frame_off,
                                    winy + ypos + rect.height/2,
                                    winx + winwidth - 5,
                                    winy + ypos + rect.height/2,
                                    curvemodel->line_style,
                                    curvemodel->line_width,
                                    &(curvemodel->color));
            else
                gwy_graph_draw_line(drawable, gc,
                                    winx + 5 + frame_off,
                                    winy + ypos + rect.height/2,
                                    winx + 20 + frame_off,
                                    winy + ypos + rect.height/2,
                                    curvemodel->line_style,
                                    curvemodel->line_width,
                                    &(curvemodel->color));
        }
        if (curvemodel->mode == GWY_GRAPH_CURVE_POINTS
            || curvemodel->mode == GWY_GRAPH_CURVE_LINE_POINTS) {
            if (model->label_reverse)
                gwy_graph_draw_point(drawable, gc,
                                     winx + winwidth - 13 - frame_off,
                                     winy + ypos + rect.height/2,
                                     curvemodel->point_type,
                                     curvemodel->point_size,
                                     &(curvemodel->color));
            else
                gwy_graph_draw_point(drawable, gc,
                                     winx + 12 + frame_off,
                                     winy + ypos + rect.height/2,
                                     curvemodel->point_type,
                                     curvemodel->point_size,
                                     &(curvemodel->color));
        }
        gdk_gc_set_rgb_fg_color(gc, &fg);

        ypos += rect.height + 5;
    }

    if (model->label_frame_thickness > 0) {
        gdk_gc_set_line_attributes(gc, model->label_frame_thickness,
                                   GDK_LINE_SOLID, GDK_CAP_ROUND,
                                   GDK_JOIN_MITER);

        gdk_draw_line(drawable, gc,
                      winx + model->label_frame_thickness/2,
                      winy + model->label_frame_thickness/2,
                      winx + winwidth - model->label_frame_thickness/2 - 1,
                      winy + model->label_frame_thickness/2);
        gdk_draw_line(drawable, gc,
                      winx + model->label_frame_thickness/2,
                      winy + winheight - model->label_frame_thickness/2 - 1,
                      winx + winwidth - model->label_frame_thickness/2 - 1,
                      winy + winheight - model->label_frame_thickness/2 - 1);
        gdk_draw_line(drawable, gc,
                      winx + model->label_frame_thickness/2,
                      winy + model->label_frame_thickness/2,
                      winx + model->label_frame_thickness/2,
                      winy + winheight - model->label_frame_thickness/2 - 1);
        gdk_draw_line(drawable, gc,
                      winx + winwidth - model->label_frame_thickness/2 - 1,
                      winy + model->label_frame_thickness/2,
                      winx + winwidth - model->label_frame_thickness/2 - 1,
                      winy + winheight - model->label_frame_thickness/2 - 1);
    }
}
예제 #13
0
void _HYPlatformGraphicPane::_FillArc (_HYRect rectDesc, int s, int f)
{
	gdk_gc_set_line_attributes (theContext, rectDesc.width, GDK_LINE_SOLID, GDK_CAP_NOT_LAST, GDK_JOIN_MITER);
	gdk_draw_arc   (thePane, theContext, true, rectDesc.left, rectDesc.top, rectDesc.right-rectDesc.left+1, 
							 rectDesc.bottom-rectDesc.top+1, (90-s)*64, -64*f);	
}
예제 #14
0
void _HYPlatformGraphicPane::_DrawOval (_HYRect rectDesc)
{
	gdk_gc_set_line_attributes (theContext, rectDesc.width, GDK_LINE_SOLID, GDK_CAP_NOT_LAST, GDK_JOIN_MITER);
	gdk_draw_arc   (thePane, theContext, false, rectDesc.left, rectDesc.top, rectDesc.right-rectDesc.left+1, 
							 rectDesc.bottom-rectDesc.top+1, 0, 64*360);
}
예제 #15
0
void _HYPlatformGraphicPane::_FillRect (_HYRect rectDesc)
{
	gdk_gc_set_line_attributes (theContext, rectDesc.width, GDK_LINE_SOLID, GDK_CAP_NOT_LAST, GDK_JOIN_MITER);
	gdk_draw_rectangle		   (thePane, theContext, true, rectDesc.left, rectDesc.top, 
								rectDesc.right-rectDesc.left+1,rectDesc.bottom-rectDesc.top+1);
}
예제 #16
0
void _HYPlatformGraphicPane::_DrawHatchedLine (_HYRect lineDesc)
{
	gdk_gc_set_line_attributes (theContext, lineDesc.width, GDK_LINE_ON_OFF_DASH, GDK_CAP_NOT_LAST, GDK_JOIN_MITER);
	gdk_draw_line (thePane, theContext, lineDesc.left, lineDesc.top, lineDesc.right, lineDesc.bottom);
}
예제 #17
0
static void
draw_wireframe_sphere (gint startx,
		       gint starty,
		       gint pw,
		       gint ph)
{
  GimpVector3 p[2 * (WIRESIZE + 5)];
  gint        cnt, cnt2, n = 0;
  gdouble     x1, y1, x2, y2, twopifac, cx1, cy1, cx2, cy2;

  /* Compute wireframe points */
  /* ======================== */

  twopifac = (2.0 * G_PI) / WIRESIZE;

  for (cnt = 0; cnt < WIRESIZE; cnt++)
    {
      p[cnt].x = mapvals.radius * cos ((gdouble) cnt * twopifac);
      p[cnt].y = 0.0;
      p[cnt].z = mapvals.radius * sin ((gdouble) cnt * twopifac);
      gimp_vector3_rotate (&p[cnt],
			   gimp_deg_to_rad (mapvals.alpha),
			   gimp_deg_to_rad (mapvals.beta),
			   gimp_deg_to_rad (mapvals.gamma));
      gimp_vector3_add (&p[cnt], &p[cnt], &mapvals.position);
    }

  p[cnt] = p[0];

  for (cnt = WIRESIZE + 1; cnt < 2 * WIRESIZE + 1; cnt++)
    {
      p[cnt].x = mapvals.radius * cos ((gdouble) (cnt-(WIRESIZE+1))*twopifac);
      p[cnt].y = mapvals.radius * sin ((gdouble) (cnt-(WIRESIZE+1))*twopifac);
      p[cnt].z = 0.0;
      gimp_vector3_rotate (&p[cnt],
			   gimp_deg_to_rad (mapvals.alpha),
			   gimp_deg_to_rad (mapvals.beta),
			   gimp_deg_to_rad (mapvals.gamma));
      gimp_vector3_add (&p[cnt], &p[cnt], &mapvals.position);
    }

  p[cnt] = p[WIRESIZE+1];
  cnt++;
  cnt2 = cnt;

  /* Find rotated axis */
  /* ================= */

  gimp_vector3_set (&p[cnt], 0.0, -0.35, 0.0);
  gimp_vector3_rotate (&p[cnt],
		       gimp_deg_to_rad (mapvals.alpha),
		       gimp_deg_to_rad (mapvals.beta),
		       gimp_deg_to_rad (mapvals.gamma));
  p[cnt+1] = mapvals.position;

  gimp_vector3_set (&p[cnt+2], 0.0, 0.0, -0.35);
  gimp_vector3_rotate (&p[cnt+2],
		       gimp_deg_to_rad (mapvals.alpha),
		       gimp_deg_to_rad (mapvals.beta),
		       gimp_deg_to_rad (mapvals.gamma));
  p[cnt+3] = mapvals.position;

  p[cnt + 4] = p[cnt];
  gimp_vector3_mul (&p[cnt + 4], -1.0);
  p[cnt + 5] = p[cnt + 1];

  gimp_vector3_add (&p[cnt],     &p[cnt],     &mapvals.position);
  gimp_vector3_add (&p[cnt + 2], &p[cnt + 2], &mapvals.position);
  gimp_vector3_add (&p[cnt + 4], &p[cnt + 4], &mapvals.position);

  /* Draw the circles (equator and zero meridian) */
  /* ============================================ */

  cx1 = (gdouble) startx;
  cy1 = (gdouble) starty;
  cx2 = cx1 + (gdouble) pw;
  cy2 = cy1 + (gdouble) ph;

  for (cnt = 0; cnt < cnt2 - 1; cnt++)
    {
      if (p[cnt].z > mapvals.position.z && p[cnt + 1].z > mapvals.position.z)
        {
          gimp_vector_3d_to_2d (startx, starty, pw, ph,
				&x1, &y1, &mapvals.viewpoint, &p[cnt]);
          gimp_vector_3d_to_2d (startx, starty, pw, ph,
				&x2, &y2, &mapvals.viewpoint, &p[cnt + 1]);

          if (clip_line (&x1, &y1, &x2, &y2, cx1, cy1, cx2, cy2) == TRUE)
            {
              linetab[n].x1 = (gint) (x1 + 0.5);
              linetab[n].y1 = (gint) (y1 + 0.5);
              linetab[n].x2 = (gint) (x2 + 0.5);
              linetab[n].y2 = (gint) (y2 + 0.5);
              linetab[n].linewidth = 3;
              linetab[n].linestyle = GDK_LINE_SOLID;
              gdk_gc_set_line_attributes (gc,
					  linetab[n].linewidth,
					  linetab[n].linestyle,
					  GDK_CAP_NOT_LAST,
					  GDK_JOIN_MITER);
              gdk_draw_line (previewarea->window, gc,
			     linetab[n].x1, linetab[n].y1,
			     linetab[n].x2, linetab[n].y2);
              n++;
            }
        }
    }

  /* Draw the axis (pole to pole and center to zero meridian) */
  /* ======================================================== */

  for (cnt = 0; cnt < 3; cnt++)
    {
      gimp_vector_3d_to_2d (startx, starty, pw, ph,
			    &x1, &y1, &mapvals.viewpoint, &p[cnt2]);
      gimp_vector_3d_to_2d (startx, starty, pw, ph,
			    &x2, &y2, &mapvals.viewpoint, &p[cnt2 + 1]);

      if (clip_line (&x1, &y1, &x2, &y2, cx1, cy1, cx2, cy2) == TRUE)
        {
          linetab[n].x1 = RINT (x1);
          linetab[n].y1 = RINT (y1);
          linetab[n].x2 = RINT (x2);
          linetab[n].y2 = RINT (y2);

          if (p[cnt2].z < mapvals.position.z || p[cnt2+1].z < mapvals.position.z)
            {
              linetab[n].linewidth = 1;
              linetab[n].linestyle = GDK_LINE_DOUBLE_DASH;
            }
          else
            {
              linetab[n].linewidth = 3;
              linetab[n].linestyle = GDK_LINE_SOLID;
            }

          gdk_gc_set_line_attributes (gc,
				      linetab[n].linewidth,
				      linetab[n].linestyle,
				      GDK_CAP_NOT_LAST,
				      GDK_JOIN_MITER);
          gdk_draw_line (previewarea->window, gc,
			 linetab[n].x1, linetab[n].y1,
			 linetab[n].x2, linetab[n].y2);
          n++;
        }

      cnt2 += 2;
    }

  /* Mark end of lines */
  /* ================= */

  linetab[n].x1 = -1;
}
예제 #18
0
/*
 * Draw a grid over the map
 */
void
draw_grid (GtkWidget * widget)
{
	int count;
	gdouble step, step_pow10;
	gdouble lat, lon;
	gdouble lat_ul, lon_ul;
	gdouble lat_ll, lon_ll;
	gdouble lat_ur, lon_ur;
	gdouble lat_lr, lon_lr;

	gdouble lat_min, lon_min;
	gdouble lat_max, lon_max;

	gchar precision[10];
	gint iteration_count =0;
	
	if ( mydebug >50 ) 
	    fprintf(stderr , "draw_grid()\n");


	// calculate the start and stop for lat/lon according to the displayed section
	calcxytopos (0, 0, &lat_ul, &lon_ul, current.zoom);
	calcxytopos (0, gui_status.mapview_y, &lat_ll, &lon_ll, current.zoom);
	calcxytopos (gui_status.mapview_x, 0, &lat_ur, &lon_ur, current.zoom);
	calcxytopos (gui_status.mapview_x, gui_status.mapview_y, &lat_lr, &lon_lr, current.zoom);

	// add more lines as the scale increases

	// Calculate distance between grid lines
	step = (gdouble) current.mapscale / 2000000.0 / current.zoom;

	/* round step to one sig. digit */
	step_pow10= floor( log10(step) );  // add -1 for 2 sig digits, -2 for 3, etc.

/* FIXME: use round(x) instead of floor(x+0.5) ??? */
//	step = pow(10, step_pow10) * round(step * pow(10, -1 * step_pow10));
	step = pow(10, step_pow10) * floor(0.5+ (step * pow(10, -1 * step_pow10)));

/* TODO: respect user's prefered DMS style; round and display accordingly:
	DDD.DDDDD, DDD MM.MMMM, DDD MM SS.SSSS

   TODO: round on "nice numbers":
	deg, min, sec: 30, 15, 10, 5, 2, 1
	decimal deg: .5, .25, .1, .05, 0.02, 0.1

     see SourceForge wish #2375742 for some sample GPL'd code to do that
       (from GRASS GIS's ps/ps.map/ps_fclrtbl.c#L162)
  */

	if (step != step || step == 0) {
	    fprintf(stderr, "?? draw_grid(): distance step is %f, "
			    "mapscale is 1:%ld\n", step, current.mapscale);
	    return;
	}

	do {
	    if (step >= 1)		g_snprintf (precision, sizeof (precision), "%%.0f");
	    else if (step >= .1)	g_snprintf (precision, sizeof (precision), "%%.1f");
	    else if (step >= .01)	g_snprintf (precision, sizeof (precision), "%%.2f");
	    else if (step >= .001)	g_snprintf (precision, sizeof (precision), "%%.3f");
	    else if (step >= .0001)	g_snprintf (precision, sizeof (precision), "%%.4f");
	    else           		g_snprintf (precision, sizeof (precision), "%%.5f");

	    if (current.mapscale / current.zoom < 50000000)
		{
		    lat_min = min (lat_ll, lat_ul) - step;
		    lat_max = max (lat_lr, lat_ur) + step;
		    lon_min = min (lon_ll, lon_ul) - step;
		    lon_max = max (lon_lr, lon_ur) + step;
		}
	    else
		{
		    lat_min = -90;
		    lat_max = 90;
		    lon_min = -180;
		    lon_max = 180;
		}
	    lat_min = floor (lat_min / step) * step;
	    lon_min = floor (lon_min / step) * step;

	    if ( mydebug > 20 )
		printf ("Draw Grid: (%.2f,%.2f) - (%.2f,%.2f) Step %f for Ef.Scale %ld Zoom %d\n",
			lat_min, lon_min, lat_max, lon_max, step,
			current.mapscale/current.zoom, current.zoom);
	    if ( mydebug > 40 )
		{
		    printf ("Draw Grid: (%.2f) Iterations for lat\n", (lat_max-lat_min)/step);
		    printf ("Draw Grid: (%.2f) Iterations for lon\n", (lon_max-lon_min)/step);
		}

	    // limit number of grid iterations to between 20 and 45 iterations
	    iteration_count = ((lat_max-lat_min)/step) * ((lon_max-lon_min)/step);
	    if ( iteration_count > 45 )
		step = step * 2;
	    else if ( iteration_count < 20 )
		step = step / 3.;

	} while ( iteration_count > 45 || iteration_count < 20 );


	// Loop over desired lat/lon  
	count = 0;
	for (lon = lon_min; lon <= lon_max; lon = lon + step)
	    {
		for (lat = lat_min; lat <= lat_max; lat = lat + step)
		    {
			gint posxdest11, posydest11;
			gint posxdest12, posydest12;
			gint posxdest21, posydest21;
			gint posxdest22, posydest22;
			gint posxdist, posydist;
			gchar str[200];

			count++;
			calcxy (&posxdest11, &posydest11, lon,        max(-90,lat)       , current.zoom);
			calcxy (&posxdest12, &posydest12, lon,        min( 90,lat + step), current.zoom);
			calcxy (&posxdest21, &posydest21, lon + step, max(-90,lat),        current.zoom);
			calcxy (&posxdest22, &posydest22, lon + step, min( 90,lat + step), current.zoom);

			if (((posxdest11 >= 0) && (posxdest11 < gui_status.mapview_x) &&
			     (posydest11 >= 0) && (posydest11 < gui_status.mapview_y))
			    ||
			    ((posxdest22 >= 0) && (posxdest22 < gui_status.mapview_x) &&
			     (posydest22 >= 0) && (posydest22 < gui_status.mapview_y))
			    ||
			    ((posxdest21 >= 0) && (posxdest21 < gui_status.mapview_x) &&
			     (posydest21 >= 0) && (posydest21 < gui_status.mapview_y))
			    ||
			    ((posxdest12 >= 0) && (posxdest12 < gui_status.mapview_x) &&
			     (posydest12 >= 0) && (posydest12 < gui_status.mapview_y)))
			    {
				// TODO: add linethickness 2 for Mayor Lines
				// Set Drawing Mode
				gdk_gc_set_function (kontext_map, GDK_XOR);
				gdk_gc_set_foreground (kontext_map, &colors.darkgrey);
				gdk_gc_set_line_attributes (kontext_map, 1, GDK_LINE_SOLID, 0, 0);

				gdk_draw_line (drawable, kontext_map, posxdest11,
					       posydest11, posxdest21,
					       posydest21);
				gdk_draw_line (drawable, kontext_map, posxdest11,
					       posydest11, posxdest12,
					       posydest12);
			    
				// Text lon
				g_snprintf (str, sizeof (str), precision, lon);

				posxdist = (posxdest12 - posxdest11) / 4;
				posydist = (posydest12 - posydest11) / 4;
				draw_grid_text (widget, 
						posxdest11 + posxdist,
						posydest11 + posydist, str);
				
				// Text lat
				g_snprintf (str, sizeof (str), precision, lat);
					    
				posxdist = (posxdest21 - posxdest11) / 4;
				posydist = (posydest21 - posydest11) / 4;
				draw_grid_text (widget, 
						posxdest11 + posxdist,
						posydest11 + posydist-5, str);
			    }
		    }
	    }
	if ( mydebug > 30 )
	    printf ("draw_grid loops: %d\n", count);
}
예제 #19
0
파일: vikviewport.c 프로젝트: gdt/viking
void vik_viewport_set_highlight_thickness ( VikViewport *vvp, gint thickness )
{
  // Otherwise same GDK_* attributes as in vik_viewport_new_gc
  gdk_gc_set_line_attributes ( vvp->highlight_gc, thickness, GDK_LINE_SOLID, GDK_CAP_ROUND, GDK_JOIN_ROUND );
}
예제 #20
0
void sarl_lattice_view_interp_draw_labels(
  SarlLatticeView *view, 
  GdkDrawable *dest, GdkGC *gc)
{
  GtkWidget         *widget = GTK_WIDGET(view);
  sarl_label_t      *label = 0;
  sarl_point_t      *p = 0;
  sarl_unsigned_int label_index;

  int               do_draw = 1;

  int scaled_line_width = (int)(view->p->label_line_width * view->p->scale);
  if ( scaled_line_width < 1 ) scaled_line_width = 1;
  
  gdk_gc_set_line_attributes(
    gc, scaled_line_width, GDK_LINE_SOLID, GDK_CAP_BUTT, GDK_JOIN_MITER);

  // draw the lines first

  SARL_ARRAY_FOR_EACH_INDEX(label_index, sarl_label_t, label, view->p->labels);
    p = sarl_diagram_get_concept_pos(view->p->diagram, label->concept);
    switch (label->kind) {
    case SARL_LABEL_OBJECT_KIND:
      do_draw = view->p->show_objects;
      if (label->bbox.top + (label->bbox.height/2) > 0) {
        gdk_gc_set_rgb_fg_color(gc, &view->line_good_color);
      }
      else {
        gdk_gc_set_rgb_fg_color(gc, &view->line_bad_color);
      };
      break;
    case SARL_LABEL_ATTRIBUTE_KIND:
      do_draw = view->p->show_attributes;
      if (label->bbox.top + (label->bbox.height/2) < 0) {
        gdk_gc_set_rgb_fg_color(gc, &view->line_good_color);
      }
      else {
        gdk_gc_set_rgb_fg_color(gc, &view->line_bad_color);
      };
      break;
    }
    if ( do_draw ) {
      gdk_draw_line(
        dest, gc, 
        TR_X(p->x), TR_Y(p->y), 
        TR_X(p->x + label->bbox.left + (label->bbox.width/2)), 
        TR_Y(p->y + label->bbox.top + (label->bbox.height/2))
      );
    }
  SARL_ARRAY_END;

  // next draw the labels themselves
  SARL_ARRAY_FOR_EACH_INDEX(label_index, sarl_label_t, label, view->p->labels);
    p = sarl_diagram_get_concept_pos(view->p->diagram, label->concept);
    switch (label->kind) {
    case SARL_LABEL_OBJECT_KIND:
      do_draw = view->p->show_objects;
      break;
    case SARL_LABEL_ATTRIBUTE_KIND:
      do_draw = view->p->show_attributes;
      break;
    }
    if ( do_draw ) {
      if ( label_index == view->hover_label ) {
        sarl_label_draw_background_with_scrollbar(
          view, dest, gc, label, p->x, p->y, &view->p->offset, view->p->scale
        );
      }
      else {
        sarl_label_draw_background(
          view, dest, gc, label, p->x, p->y, &view->p->offset, view->p->scale
        );
      };
      sarl_label_draw(
        widget, dest, gc, label, p->x, p->y, &view->p->offset, view->p->scale
      );
    }
  SARL_ARRAY_END;
};
예제 #21
0
파일: gui_util.c 프로젝트: bert/fped
void set_width(GdkGC *gc, int width)
{
	gdk_gc_set_line_attributes(gc, width < 1 ? 1 : width,
	    GDK_LINE_SOLID, GDK_CAP_ROUND, GDK_JOIN_ROUND);
}
예제 #22
0
void ZLGtkPaintContext::setColor(ZLColor color, LineStyle style) {
	::setColor(myTextGC, color);
	gdk_gc_set_line_attributes(myTextGC, 0, (style == SOLID_LINE) ? GDK_LINE_SOLID : GDK_LINE_ON_OFF_DASH, (GdkCapStyle)1, (GdkJoinStyle)1);
}
예제 #23
0
파일: histodrawing.c 프로젝트: adannis/lttv
/* Redraw the screen from the backing pixmap */
static gboolean
histo_expose_event( GtkWidget *widget, GdkEventExpose *event, gpointer user_data )
{
  histoDrawing_t *drawing = (histoDrawing_t*)user_data;

  HistoControlFlowData *histo_control_flow_data =
      (HistoControlFlowData*)g_object_get_data(
                G_OBJECT(widget),
                "histo_control_flow_data");
#if 0
  if(unlikely(drawing->gc == NULL)) {
    drawing->gc = gdk_gc_new(drawing->drawing_area->window);
    gdk_gc_copy(drawing->gc, drawing->drawing_area->style->black_gc);
  }
#endif //0
  TimeWindow time_window = 
      lttvwindow_get_time_window(histo_control_flow_data->tab);
  LttTime current_time = 
      lttvwindow_get_current_time(histo_control_flow_data->tab);

  guint cursor_x=0;

  LttTime window_end = time_window.end_time;


  /* update the screen from the pixmap buffer */
//added again for histogram:

  gdk_draw_pixmap(widget->window,
      widget->style->fg_gc[GTK_WIDGET_STATE (widget)],
      drawing->pixmap,
      event->area.x, event->area.y,
      event->area.x, event->area.y,
      event->area.width, event->area.height);
 //0

  drawing->height = drawing-> drawing_area ->allocation.height;

#if 0
  copy_pixmap_to_screen(histo_control_flow_data->process_list,
                        widget->window,
                        widget->style->fg_gc[GTK_WIDGET_STATE (widget)],
                        event->area.x, event->area.y,
                        event->area.width, event->area.height);
#endif //0


 /* //disabled for histogram
  copy_pixmap_to_screen(histo_control_flow_data->process_list,
                        widget->window,
                        drawing->gc,
                        event->area.x, event->area.y,
                        event->area.width, event->area.height);*/

  /* Erase the dotted lines left.. */
  if(widget->allocation.height > drawing->height)
  {
    gdk_draw_rectangle (widget->window,
      drawing->drawing_area->style->black_gc,
      TRUE,
      event->area.x, drawing->height,
      event->area.width,  // do not overlap
      widget->allocation.height - drawing->height);
  }
  if(ltt_time_compare(time_window.start_time, current_time) <= 0 &&
           ltt_time_compare(window_end, current_time) >= 0)
  {
    /* Draw the dotted lines */
    histo_convert_time_to_pixels(
          time_window,
          current_time,
          drawing->width,
          &cursor_x);

#if 0
    if(drawing->dotted_gc == NULL) {

      drawing->dotted_gc = gdk_gc_new(drawing->drawing_area->window);
      gdk_gc_copy(drawing->dotted_gc, widget->style->white_gc);
   
      gint8 dash_list[] = { 1, 2 };
      gdk_gc_set_line_attributes(drawing->dotted_gc,
                                 1,
                                 GDK_LINE_ON_OFF_DASH,
                                 GDK_CAP_BUTT,
                                 GDK_JOIN_MITER);
      gdk_gc_set_dashes(drawing->dotted_gc,
                        0,
                        dash_list,
                        2);
    }
#endif //0
    gint height_tot = MAX(widget->allocation.height, drawing->height);
    gdk_draw_line(widget->window,
                  drawing->dotted_gc,
                  cursor_x, 0,
                  cursor_x, height_tot);
  }
  
  return FALSE;
}
예제 #24
0
파일: histodrawing.c 프로젝트: adannis/lttv
histoDrawing_t *histo_drawing_construct(HistoControlFlowData *histo_control_flow_data)
{
  histoDrawing_t *drawing = g_new(histoDrawing_t, 1);
  
  drawing->histo_control_flow_data = histo_control_flow_data;

  drawing->vbox = gtk_vbox_new(FALSE, 1);

  
  drawing->ruler_hbox = gtk_hbox_new(FALSE, 1);
  drawing->ruler = gtk_drawing_area_new ();
  //gtk_widget_set_size_request(drawing->ruler, -1, 27);
  
  drawing->padding = gtk_drawing_area_new ();
  //gtk_widget_set_size_request(drawing->padding, -1, 27);
   
  gtk_box_pack_start(GTK_BOX(drawing->ruler_hbox), drawing->padding,FALSE, FALSE, 0);
  
  gtk_box_pack_end(GTK_BOX(drawing->ruler_hbox), drawing->ruler, 
                     TRUE, TRUE, 0);

  drawing->drawing_area = gtk_drawing_area_new ();
  
  drawing->gc = NULL;
  /* 
  ///at this time not necessary for histogram
  drawing->hbox = gtk_hbox_new(FALSE, 1);
 
  drawing->viewport = gtk_viewport_new(NULL, histo_control_flow_data->v_adjust);
  drawing->scrollbar = gtk_vscrollbar_new(histo_control_flow_data->v_adjust);
  gtk_box_pack_start(GTK_BOX(drawing->hbox), drawing->viewport, 
                     TRUE, TRUE, 0);
  gtk_box_pack_end(GTK_BOX(drawing->hbox), drawing->scrollbar, 
                     FALSE, FALSE, 0);
  gtk_container_add(GTK_CONTAINER(drawing->viewport),
                    drawing->drawing_area);*/

  //add vertical ruler:
  drawing->vruler_drawing_hbox = gtk_hbox_new(FALSE, 1);
  drawing-> vertical_ruler =gtk_drawing_area_new ();
  gtk_box_pack_start(GTK_BOX(drawing->vruler_drawing_hbox), drawing->vertical_ruler, 
                     	FALSE, FALSE, 0);
  gtk_box_pack_end(GTK_BOX(drawing->vruler_drawing_hbox), drawing->drawing_area,
                   	TRUE, TRUE, 1);
  gtk_widget_set_size_request(drawing->vertical_ruler, padding_width, -1);

  gtk_box_pack_start(GTK_BOX(drawing->vbox), drawing->ruler_hbox, 
                     	FALSE, FALSE, 1);
  gtk_box_pack_end(GTK_BOX(drawing->vbox), drawing->vruler_drawing_hbox/*drawing_area*/,
                   	TRUE, TRUE, 1);
  
  drawing->pango_layout =
    	gtk_widget_create_pango_layout(drawing->drawing_area, NULL);

  drawing->height = 1;
  drawing->width = 1;
  drawing->depth = 0;
  drawing->alloc_height = 1;
  drawing->alloc_width = 1;
  
  drawing->damage_begin = 0;
  drawing->damage_end = 0;
  drawing->horizontal_sel = -1;
  
  //gtk_widget_set_size_request(drawing->drawing_area->window, 50, 50);
  g_object_set_data_full(
      G_OBJECT(drawing->drawing_area),
      "histo_Link_drawing_Data",
      drawing,
      (GDestroyNotify)histo_drawing_destroy);

  g_object_set_data(
      G_OBJECT(drawing->ruler),
      "histo_drawing",
      drawing);

  g_object_set_data(
      G_OBJECT(drawing->vertical_ruler),
      "histo_drawing",
      drawing);

  //gtk_widget_modify_bg( drawing->drawing_area,
  //      GTK_STATE_NORMAL,
  //      &CF_Colors[BLACK]);
  
  //gdk_window_get_geometry(drawing->drawing_area->window,
  //    NULL, NULL,
  //    &(drawing->width),
  //    &(drawing->height),
  //    -1);
  
  //drawing->pixmap = gdk_pixmap_new(
  //    drawing->drawing_area->window,
  //    drawing->width,
  //    drawing->height,
  //    drawing->depth);
  
  drawing->pixmap = NULL;

//  drawing->pixmap = gdk_pixmap_new(drawing->drawing_area->window,
//        drawing->drawing_area->allocation.width,
//        drawing->drawing_area->allocation.height,
//        -1);

  g_signal_connect (G_OBJECT(drawing->drawing_area),
        "configure_event",
        G_CALLBACK (histo_configure_event),
        (gpointer)drawing);
 
  g_signal_connect (G_OBJECT(drawing->ruler),
        "expose_event",
        G_CALLBACK(histo_expose_ruler),
        (gpointer)drawing);

  gtk_widget_add_events(drawing->ruler, GDK_POINTER_MOTION_MASK);
  gtk_widget_add_events(drawing->vertical_ruler, GDK_POINTER_MOTION_MASK);

  g_signal_connect (G_OBJECT(drawing->ruler),
        "motion-notify-event",
        G_CALLBACK(histo_motion_notify_ruler),
        (gpointer)drawing);

 
  g_signal_connect (G_OBJECT(drawing->vertical_ruler),
        "expose_event",
        G_CALLBACK(histo_expose_vertical_ruler),
        (gpointer)drawing);

  g_signal_connect (G_OBJECT(drawing->vertical_ruler),
        "motion-notify-event",
        G_CALLBACK(histo_motion_notify_vertical_ruler),
        (gpointer)drawing);

/*//not necessary for historam. 
  g_signal_connect (G_OBJECT(drawing->drawing_area),
        "size-allocate",
        G_CALLBACK(scrollbar_size_allocate),
        (gpointer)drawing); */


  gtk_widget_set_size_request(drawing->padding, padding_width, -1);//use it for vertical ruler

  g_signal_connect (G_OBJECT(drawing->drawing_area),
        "expose_event",
        G_CALLBACK (histo_expose_event),
        (gpointer)drawing);

  g_signal_connect_after (G_OBJECT(drawing->drawing_area),
        "expose_event",
        G_CALLBACK (histo_after_expose_event),
        (gpointer)drawing);

  g_signal_connect (G_OBJECT(drawing->drawing_area),
        "button-press-event",
        G_CALLBACK (histo_button_press_event),
        (gpointer)drawing);
  
  gtk_widget_show(drawing->ruler);
  gtk_widget_show(drawing->padding);
  gtk_widget_show(drawing->ruler_hbox);
  gtk_widget_show(drawing->vertical_ruler);
  gtk_widget_show(drawing->vruler_drawing_hbox);
  gtk_widget_show(drawing->drawing_area);
  
 /// gtk_widget_show(drawing->viewport);
 /// gtk_widget_show(drawing->scrollbar);
 /// gtk_widget_show(drawing->hbox);

  /* Allocate the colors */
  GdkColormap* colormap = gdk_colormap_get_system();
  gboolean success[NUM_COLORS];
  gdk_colormap_alloc_colors(colormap, histo_drawing_colors, NUM_COLORS, FALSE,
                            TRUE, success);
  
  drawing->gc =
    gdk_gc_new(GDK_DRAWABLE(main_window_get_widget(histo_control_flow_data->tab)->window));
  drawing->dotted_gc =
    gdk_gc_new(GDK_DRAWABLE(main_window_get_widget(histo_control_flow_data->tab)->window));

  gdk_gc_copy(drawing->gc,
      main_window_get_widget(histo_control_flow_data->tab)->style->black_gc);
  gdk_gc_copy(drawing->dotted_gc,
      main_window_get_widget(histo_control_flow_data->tab)->style->white_gc);
  
  gint8 dash_list[] = { 1, 2 };
  gdk_gc_set_line_attributes(drawing->dotted_gc,
                             1,
                             GDK_LINE_ON_OFF_DASH,
                             GDK_CAP_BUTT,
                             GDK_JOIN_MITER);
  gdk_gc_set_dashes(drawing->dotted_gc,
                    0,
                    dash_list,
                    2);

  drawing->ruler_gc_butt = 
    gdk_gc_new(GDK_DRAWABLE(main_window_get_widget(histo_control_flow_data->tab)->window));
  gdk_gc_copy(drawing->ruler_gc_butt, 
      main_window_get_widget(histo_control_flow_data->tab)->style->black_gc);
  drawing->ruler_gc_round = 
    gdk_gc_new(GDK_DRAWABLE(main_window_get_widget(histo_control_flow_data->tab)->window));
  gdk_gc_copy(drawing->ruler_gc_round, 
      main_window_get_widget(histo_control_flow_data->tab)->style->black_gc);


  gdk_gc_set_line_attributes(drawing->ruler_gc_butt,
                               2,
                               GDK_LINE_SOLID,
                               GDK_CAP_BUTT,
                               GDK_JOIN_MITER);

  gdk_gc_set_line_attributes(drawing->ruler_gc_round,
                             2,
                             GDK_LINE_SOLID,
                             GDK_CAP_ROUND,
                             GDK_JOIN_ROUND);
 return drawing;
}
예제 #25
0
bool _HYSequencePane::_ProcessOSEvent (Ptr vEvent)
{
	static			bool	amScrolling = false,
							vertical;
					
	static			long   localPt_x,
						   localPt_y,	
						   originalStart,
						   originalSpan,
						   lastClick,
						   firstClick;


	if (_HYPlatformComponent::_ProcessOSEvent (vEvent)) 
		return true;	
		
	_HY_GTK_UI_Message *theMessage = (_HY_GTK_UI_Message*)vEvent;
	if (active) 
	{
		gdouble   xc, 
				  yc;

		if (gdk_event_get_coords (theMessage->theEvent,&xc,&yc))
		{
			switch (theMessage->theEvent->type)
			{
				case GDK_BUTTON_PRESS:
				case GDK_2BUTTON_PRESS:
					{
						GdkEventButton * bevent = (GdkEventButton*)theMessage->theEvent;
						
						long  globalPt_x = xc,
							  globalPt_y = yc;
							  
						localPt_x = globalPt_x-rel.left-parentWindow->allocation.x;
						localPt_y = globalPt_y-rel.top-parentWindow->allocation.y;
							  
						vertical = (localPt_x<headerWidth)&&(localPt_y>=(GetSlotHeight()+1));

						if (((GdkEventButton*)bevent)->button == 1)
						{
							if (vertical)
								ProcessVSelectionChange (localPt_x,localPt_y,bevent->state & GDK_SHIFT_MASK,bevent->state & GDK_CONTROL_MASK, false, bevent->type == GDK_2BUTTON_PRESS);
							else
								ProcessSelectionChange  (localPt_x,localPt_y,bevent->state & GDK_SHIFT_MASK,bevent->state & GDK_CONTROL_MASK);
						}
						else
						{
							if ((((GdkEventButton*)bevent)->button == 2 || ((GdkEventButton*)bevent)->button == 3 )&& (vertical&&vselection.lLength || !vertical &&selection.lLength))
							{
								ProcessContextualPopUp (globalPt_x, globalPt_y);
								return true;
							}
						}
					}
					break;
				case GDK_BUTTON_RELEASE:
				case GDK_LEAVE_NOTIFY:
				{
					if (amScrolling)
					{
						if (messageRecipient)
							((_HYTWindow*)messageRecipient)->trackMouseComponent = (Ptr)nil;
							
						/*gdk_pointer_ungrab (((GdkEventButton*)theMessage->theEvent)->time);*/
						
						if  (vertical)
						{
							_HYRect invalRectH = {parentWindow->allocation.x+rel.left,
												  parentWindow->allocation.y+rel.top+(GetSlotHeight()+1)+1,rel.left+headerWidth,rel.bottom-HY_SCROLLER_WIDTH};
							GdkRectangle irect = HYRect2GDKRect(invalRectH);
							irect.x+=parentWindow->allocation.x;
							irect.y+=parentWindow->allocation.y;
							gdk_window_invalidate_rect (parentWindow->window, &irect, false);
							if ( localPt_x<headerWidth && localPt_x>0 && lastClick>-2)
								MoveSpecies (firstClick+originalStart,lastClick+startRow);
						}
						amScrolling = false;
					}
					break;
				}
					
				case GDK_MOTION_NOTIFY:
				{
					GdkEventMotion * motEvent = (GdkEventMotion*)theMessage->theEvent;
					if (motEvent->state & GDK_BUTTON1_MASK)
					{
						if (amScrolling)
						{
							gint mousePt_x = motEvent->x - rel.left - parentWindow->allocation.x,
								 mousePt_y = motEvent->y - rel.top  - parentWindow->allocation.y;
								 
							if (vertical) // vertical scrolling
							{
								long  wHeight = rel.bottom-rel.top-HY_SCROLLER_WIDTH,
									  slotHeight = GetSlotHeight();

								if ( mousePt_y <  GetSlotHeight()+1 || localPt_y != mousePt_y || mousePt_y>wHeight )
								{
									localPt_x = mousePt_x;
									localPt_y = mousePt_y;
									
									if (mousePt_y>wHeight)
									{
										// scroll down
										if ((endRow<=speciesIndex.lLength)&&(vselection.lData[0]!=speciesIndex.lLength-1))
										{
											if (endRow-startRow<originalSpan) 
												break;
											startRow++;
											endRow++;
											_SetVScrollerPos(((double)MAX_CONTROL_VALUE*startRow)/
															 (speciesIndex.lLength-endRow+startRow+1));
											BuildPane();
											forceUpdateForScrolling = true;
											_MarkForUpdate();
											forceUpdateForScrolling = false;
											lastClick = -2;
										}
										break;
									}
									else
									{
										mousePt_y-=(GetSlotHeight()+1);
										if (mousePt_y<=slotHeight)
										{
											if (mousePt_y>=0)
											{
												if (mousePt_y<slotHeight/2)
													mousePt_y = -1;
												else
													mousePt_y = 0;
											}
											else
											{
												// scroll up
												if (startRow>0)
												{
													startRow--;
													endRow--;
													_SetVScrollerPos(((double)MAX_CONTROL_VALUE*startRow)/(speciesIndex.lLength-endRow+startRow+1));
													BuildPane();
													forceUpdateForScrolling = true;
													_MarkForUpdate();
													forceUpdateForScrolling = false;
													lastClick = -2;
												}
												break;
											}
										}
										else
											mousePt_y=(mousePt_y-(GetSlotHeight()+1))/slotHeight;
									}
										
									if ( mousePt_y<-1 || mousePt_y>= endRow-startRow ) 
										break;
										
									if (mousePt_y!=lastClick)
									{
										GdkDrawable * tempDr = GDK_DRAWABLE(parentWindow->window);
										GdkGC * tempGC = gdk_gc_new (tempDr);

										GdkColor black = HYColorToGDKColor((_HYColor){0,0,0});
										gdk_gc_set_foreground (theContext, &black);

										gdk_gc_set_function (tempGC, GDK_INVERT);
										gdk_gc_set_line_attributes (tempGC, 2, GDK_LINE_SOLID, GDK_CAP_BUTT, GDK_JOIN_MITER);
										if (lastClick>=-1)
										{
											lastClick = (GetSlotHeight()+1)+slotHeight*(lastClick+1)+rel.top+1;
											gdk_draw_line  (tempDr,tempGC,parentWindow->allocation.x+rel.left+1,parentWindow->allocation.y+lastClick,
																		  parentWindow->allocation.x+rel.left+headerWidth-1,parentWindow->allocation.y+lastClick);

										}
										
										lastClick = mousePt_y;
										
										if (lastClick+startRow != firstClick+originalStart)
										{
											mousePt_y = (GetSlotHeight()+1)+slotHeight*(lastClick+1)+rel.top+1;
											gdk_draw_line  (tempDr,tempGC,parentWindow->allocation.x+rel.left+1,parentWindow->allocation.y+mousePt_y,
																				parentWindow->allocation.x+rel.left+headerWidth-1,parentWindow->allocation.y+mousePt_y);
										}
										g_object_unref (tempGC);
									}
								}
								return true;
							}
							else // horizontal scrolling
							{
								long	rightWindowBound = _HYCanvas::GetMaxW()-HY_SCROLLER_WIDTH;
								guint32 serverTime = gdk_x11_get_server_time (parentWindow->window);
								if ( mousePt_x<headerWidth && startColumn>0 || localPt_x!=mousePt_x || mousePt_x> rightWindowBound)
								{
									forceUpdateForScrolling = true;
									if (mousePt_x<headerWidth && startColumn>0)
									{
										gint	  wx, wy;
										gdk_window_get_origin (parentWindow->window,&wx,&wy);
										wx += parentWindow->allocation.x+rel.left;
										wy += parentWindow->allocation.y+rel.top;
										do
										{
											guint32 serverTime2 = gdk_x11_get_server_time (parentWindow->window);
											if (serverTime2-serverTime < 100)
												ProcessSelectionChange (mousePt_x,mousePt_y,true,true,true);
											GdkModifierType keyDown;
											gdk_display_get_pointer (gdk_display_get_default(),NULL,&mousePt_x,&mousePt_y,&keyDown);
											mousePt_x -= wx;
											mousePt_y -= wy;
											serverTime = serverTime2;
											if ((keyDown & GDK_BUTTON1_MASK)==0)
												break;
												
											gtk_main_iteration_do(true);
										}
										while (mousePt_x<headerWidth && startColumn>0);
									}
									else
									{
										if (mousePt_x> rightWindowBound)
										{
											gint	  wx, wy;
											gdk_window_get_origin (parentWindow->window,&wx,&wy);
											wx += parentWindow->allocation.x;
											wy += parentWindow->allocation.y;
											do
											{
												guint32 serverTime2 = gdk_x11_get_server_time (parentWindow->window);
												if (serverTime2-serverTime < 100)
													ProcessSelectionChange (mousePt_x+HY_SCROLLER_WIDTH,mousePt_y,true,true,true);
												GdkModifierType keyDown;
												gdk_display_get_pointer (gdk_display_get_default(),NULL,&mousePt_x,&mousePt_y,&keyDown);
												mousePt_x -= wx;
												mousePt_y -= wy;
												serverTime = serverTime2;
												if ((keyDown & GDK_BUTTON1_MASK)==0)
													break;
													
												gtk_main_iteration_do(true);
											}
											while (mousePt_x> rightWindowBound && endColumn < columnStrings.lLength);
										}
										else
											if (serverTime-gdk_event_get_time(theMessage->theEvent) < 100)
												ProcessSelectionChange (mousePt_x,mousePt_y,true,true,true);	
									}
									
									forceUpdateForScrolling = false;
									localPt_x = mousePt_x;
									localPt_y = mousePt_y;
								}
								return true;
							}
						}					
						else
						{
							
							/*gdk_pointer_grab (parentWindow->window,false,
									  GDK_POINTER_MOTION_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK,
									  NULL, NULL, (((GdkEventMotion*)theMessage->theEvent))->time);*/
											  
							if (messageRecipient)
								((_HYTWindow*)messageRecipient)->trackMouseComponent = (Ptr)((_HYComponent*)this);

							amScrolling = true;
							originalStart = startRow,
							originalSpan  = endRow-startRow;
							lastClick = -2;
							firstClick = (localPt_y-(GetSlotHeight()+1))/GetSlotHeight();
							return true;
						}					
					}
					break;
				}
			}
		}
	}


	return false;
}
예제 #26
0
void _HYConsoleWindow::_PaintStatusBar(Ptr,bool force)
{
    if (GTK_WIDGET_MAPPED (theWindow)) {
        _Parameter      vL;
        checkParameter (VerbosityLevelString, vL, 0.0);

        if (vL<-0.5 && !force) {
            clock_t curMeasure = clock();
            _Parameter diff = 1.0/CLOCKS_PER_SEC*(curMeasure-lastMeasure);
            if (diff < -vL) {
                return;
            }
            lastMeasure = curMeasure;
        }

        if (!stripedFillGC) {
            SetUpStatusBarStuff (theWindow);
        }

        GdkRectangle wRC  = {0,0,theWindow->allocation.width,HY_SCROLLER_WIDTH},
                     w2RC;

        if (!_hyConsoleWindowGC) {
            _hyConsoleWindowGC   = gdk_gc_new     (theWindow->window);
            gdk_gc_set_tile (_hyConsoleWindowGC, stripedFill);
            gdk_gc_set_line_attributes(_hyConsoleWindowGC,1,GDK_LINE_SOLID,GDK_CAP_NOT_LAST,GDK_JOIN_MITER);
            _hyConsoleLayout = pango_layout_new (screenPContext);
            pango_layout_set_width (_hyConsoleLayout, -1);
            statusBarBold = pango_font_description_new ();
            statusBarNormal = pango_font_description_new ();
            _HYFont         consoleFont = {_HY_MONO_FONT,9,HY_FONT_PLAIN};
            HYFont2PangoFontDesc (consoleFont,statusBarNormal);
            consoleFont.style = HY_FONT_BOLD;
            HYFont2PangoFontDesc (consoleFont,statusBarBold);
        }

        GdkPixmap * offBitmap        = gdk_pixmap_new (theWindow->window, wRC.width, wRC.height,-1);

        if (offBitmap) {
            gdk_gc_set_fill         (_hyConsoleWindowGC,GDK_TILED);
            gdk_draw_rectangle      (offBitmap,_hyConsoleWindowGC,true,-1,-1,wRC.width+2,wRC.height+2);
            gdk_gc_set_fill         (_hyConsoleWindowGC,GDK_SOLID);
            gdk_gc_set_foreground   (_hyConsoleWindowGC,&_BLACKBRUSH_);
            gdk_draw_line(offBitmap,_hyConsoleWindowGC,0,0,wRC.width,0);

            pango_layout_set_font_description(_hyConsoleLayout,statusBarNormal);
            pango_layout_set_text(_hyConsoleLayout,fileName.getStr(),fileName.sLength);
            gdk_draw_layout(offBitmap,_hyConsoleWindowGC,33,wRC.height-13,_hyConsoleLayout);

            if (inputStatus == 1) {
                pango_layout_set_text(_hyConsoleLayout,cInput.getStr(),cInput.sLength);
            } else {
                pango_layout_set_text(_hyConsoleLayout,action.getStr(),action.sLength);
            }

            gdk_draw_layout(offBitmap,_hyConsoleWindowGC,193,wRC.height-13,_hyConsoleLayout);

            gdk_gc_set_foreground   (_hyConsoleWindowGC,&_DARKGREYBRUSH_);

            gdk_draw_rectangle      (offBitmap,_hyConsoleWindowGC,true,0,1,30,wRC.height-1);
            gdk_draw_rectangle      (offBitmap,_hyConsoleWindowGC,true,150,1,40,wRC.height-1);
            gdk_draw_rectangle      (offBitmap,_hyConsoleWindowGC,true,wRC.width-55,1,55,wRC.height-1);

            gdk_gc_set_foreground   (_hyConsoleWindowGC,&_WHITEBRUSH_);
            pango_layout_set_font_description(_hyConsoleLayout,statusBarBold);

            pango_layout_set_text(_hyConsoleLayout,cState.getStr(),cState.sLength);
            gdk_draw_layout(offBitmap,_hyConsoleWindowGC,3,wRC.height-13,_hyConsoleLayout);
            pango_layout_set_text(_hyConsoleLayout,cTask.getStr(),cTask.sLength);
            gdk_draw_layout(offBitmap,_hyConsoleWindowGC,151,wRC.height-13,_hyConsoleLayout);

            pango_layout_set_font_description(_hyConsoleLayout,statusBarNormal);

            pango_layout_set_text(_hyConsoleLayout,timer.getStr(),timer.sLength);
            gdk_draw_layout(offBitmap,_hyConsoleWindowGC,wRC.width-53,wRC.height-13,_hyConsoleLayout);

            if (percentDone>0 || percentDone == -HY_SL_DONE) {
                GdkColor blackBrush = HYColorToGDKColor((_HYColor) {
                    80,80,80
                }),
                orangeBrush = HYColorToGDKColor((_HYColor) {
                    255,153,102
                });

                gdk_gc_set_foreground   (_hyConsoleWindowGC,&orangeBrush);
                gdk_draw_rectangle      (offBitmap,_hyConsoleWindowGC,true,wRC.width-135,wRC.height-14,(percentDone>=0?percentDone:100.)*0.75,12);

                gdk_gc_set_foreground   (_hyConsoleWindowGC,&blackBrush);
                gdk_draw_rectangle      (offBitmap,_hyConsoleWindowGC,false,wRC.width-135,wRC.height-14,75,12);

                //gdk_gc_set_foreground (_hyConsoleWindowGC,&_WHITEBRUSH_);
                _String pLine;
                if (percentDone>=0) {
                    pLine = _String(percentDone)&"%";
                } else {
                    pLine = "DONE";
                }

                pango_layout_set_text(_hyConsoleLayout,pLine.getStr(),pLine.sLength);
                gdk_draw_layout(offBitmap,_hyConsoleWindowGC,wRC.width-107,wRC.height-13,_hyConsoleLayout);
            }
        }

        gdk_draw_drawable (theWindow->window, _hyConsoleWindowGC, offBitmap, 0, 0, theWindow->allocation.x, theWindow->allocation.y+theWindow->allocation.height-wRC.height, -1, -1);
        g_object_unref (offBitmap);
    }
}
예제 #27
0
파일: routes.c 프로젝트: Jalakas/gpsdrive
/* ****************************************************************************
 * draw lines showing the route
 */
void
draw_route (void)
{
	GdkSegment *route_seg;

	gint destpos_x, destpos_y, curpos_x, curpos_y;
	gint i, j;
	gint t = 0;
	gchar t_routept[5];
	GtkTreeIter iter_route;
	gdouble t_lon, t_lat;
	
	if (route.items < 1)
		return;

	i = (route.items + 5);
	route_seg = g_new0 (GdkSegment, i);

	if (local_config.use_database)
	{
	/* poi mode */	
		g_snprintf (t_routept, sizeof (t_routept), "%d",
			(route.pointer));
		gtk_tree_model_get_iter_from_string
			(GTK_TREE_MODEL (route_list_tree),
			&iter_route, t_routept);

		calcxy (&curpos_x, &curpos_y,
			coords.current_lon, coords.current_lat, current.zoom);
		(route_seg)->x1 = curpos_x;
		(route_seg)->y1 = curpos_y;

		do
		{
			gtk_tree_model_get
				(GTK_TREE_MODEL (route_list_tree), &iter_route,
				ROUTE_LON, &t_lon, ROUTE_LAT, &t_lat, -1);
			if (t != 0)
			{
				(route_seg + t)->x1 = (route_seg + t - 1)->x2;
				(route_seg + t)->y1 = (route_seg + t - 1)->y2;
			}
			calcxy (&destpos_x, &destpos_y, t_lon, t_lat,
				current.zoom);
			(route_seg + t)->x2 = destpos_x;
			(route_seg + t)->y2 = destpos_y;
			t++;
		}
		while (gtk_tree_model_iter_next (GTK_TREE_MODEL
			(route_list_tree), &iter_route));
	}
	else
	{
	/* waypoints mode */
		/* start beginning with actual route.pointer */
		for (j = route.pointer; j < route.items; j++)
		{
			/* start drawing with current_pos */
			if (j == route.pointer)
			{
				calcxy (&curpos_x, &curpos_y,
					coords.current_lon,
					coords.current_lat, current.zoom);
				(route_seg + t)->x1 = curpos_x;
				(route_seg + t)->y1 = curpos_y;
			}
			else
			{
				(route_seg + t)->x1 = (route_seg + t - 1)->x2;
				(route_seg + t)->y1 = (route_seg + t - 1)->y2;
			}
			calcxy (&destpos_x, &destpos_y, (routelist +
				j)->lon, (routelist + j)->lat, current.zoom);
			(route_seg + t)->x2 = destpos_x;
			(route_seg + t)->y2 = destpos_y;
			t++;
		}
	}

	gdk_gc_set_foreground (kontext_map, &colors.route);
	gdk_gc_set_background (kontext_map, &colors.white);
	gdk_gc_set_line_attributes (kontext_map, 4, GDK_LINE_ON_OFF_DASH, 0, 0);

	gdk_gc_set_dashes (kontext_map, 0, (gpointer) linestyles[local_config.style_route], 4);
	gdk_gc_set_function (kontext_map, GDK_COPY);
	gdk_draw_segments (drawable, kontext_map, (GdkSegment *) route_seg, t);
	g_free (route_seg);
}
예제 #28
0
static void
gnc_header_draw (GnomeCanvasItem *item, GdkDrawable *drawable,
                 int x, int y, int width, int height)
{
    GncHeader *header = GNC_HEADER(item);
    SheetBlockStyle *style = header->style;
    Table *table = header->sheet->table;
    VirtualLocation virt_loc;
    VirtualCell *vcell;
    CellDimensions *cd;
    GdkColor *bg_color;
    int xpaint, ypaint;
    const char *text;
    CellBlock *cb;
    guint32 argb, color_type;
    int i, j;
    int w, h;
    PangoLayout *layout;

    virt_loc.vcell_loc.virt_row = 0;
    virt_loc.vcell_loc.virt_col = 0;
    virt_loc.phys_row_offset = 0;
    virt_loc.phys_col_offset = 0;

    if (header->sheet->use_theme_colors)
    {
        color_type = gnc_table_get_gtkrc_bg_color (table, virt_loc,
                     NULL);
        bg_color = get_gtkrc_color(header->sheet, color_type);
    }
    else
    {
        argb = gnc_table_get_bg_color (table, virt_loc, NULL);
        bg_color = gnucash_color_argb_to_gdk (argb);
    }

    h = style->dimensions->height;
    h *= header->num_phys_rows;
    h /= header->style->nrows;

    gdk_gc_set_foreground (header->gc, bg_color);

    gdk_draw_rectangle (drawable, header->gc, TRUE, 0, 0,
                        style->dimensions->width, h);

    gdk_gc_set_line_attributes (header->gc, 1, GDK_LINE_SOLID, GDK_CAP_NOT_LAST, GDK_JOIN_MITER);
    gdk_gc_set_foreground (header->gc, &gn_black);

    gdk_draw_rectangle (drawable, header->gc, FALSE, -x, -y,
                        style->dimensions->width, h);

    gdk_draw_line (drawable, header->gc, 0, h + 1,
                   style->dimensions->width, h + 1);

    gdk_gc_set_line_attributes (header->gc, 1, GDK_LINE_SOLID, GDK_CAP_NOT_LAST, GDK_JOIN_MITER);
    gdk_gc_set_background (header->gc, &gn_white);
    gdk_gc_set_foreground (header->gc, &gn_black);
    /*font = gnucash_register_font;*/

    vcell = gnc_table_get_virtual_cell
            (table, table->current_cursor_loc.vcell_loc);
    cb = vcell ? vcell->cellblock : NULL;

    ypaint = -y;
    h = 0;

    for (i = 0; i < style->nrows; i++)
    {
        xpaint = -x;
        virt_loc.phys_row_offset = i;

        /* TODO: This routine is duplicated in several places.
           Can we abstract at least the cell drawing routine?
           That way we'll be sure everything is drawn
           consistently, and cut down on maintenance issues. */

        for (j = 0; j < style->ncols; j++)
        {
            /*                        gint x_offset, y_offset;*/
            GdkRectangle rect;
            BasicCell *cell;

            virt_loc.phys_col_offset = j;

            cd = gnucash_style_get_cell_dimensions (style, i, j);

            if (header->in_resize && (j == header->resize_col))
                w = header->resize_col_width;
            else
                w = cd->pixel_width;

            cell = gnc_cellblock_get_cell (cb, i, j);
            if (!cell || !cell->cell_name)
            {
                xpaint += w;
                continue;
            }

            h = cd->pixel_height;

            gdk_draw_rectangle (drawable, header->gc, FALSE,
                                xpaint, ypaint, w, h);

            virt_loc.vcell_loc =
                table->current_cursor_loc.vcell_loc;
            text = gnc_table_get_label (table, virt_loc);
            if (!text)
                text = "";

            layout = gtk_widget_create_pango_layout (GTK_WIDGET (header->sheet), text);

            /*y_offset = ((h / 2) +
                                    (((font->ascent + font->descent) / 2) -
                                     font->descent));
                        y_offset++;*/

            switch (gnc_table_get_align (table, virt_loc))
            {
            default:
            case CELL_ALIGN_LEFT:
                pango_layout_set_alignment (layout, PANGO_ALIGN_LEFT);
                break;

            case CELL_ALIGN_RIGHT:
                pango_layout_set_alignment (layout, PANGO_ALIGN_RIGHT);
                break;

            case CELL_ALIGN_CENTER:
                pango_layout_set_alignment (layout, PANGO_ALIGN_CENTER);
                break;
            }

            rect.x = xpaint + CELL_HPADDING;
            rect.y = ypaint + 1;
            rect.width = MAX (0, w - (2 * CELL_HPADDING));
            rect.height = h - 2;

            gdk_gc_set_clip_rectangle (header->gc, &rect);

            gdk_draw_layout (drawable,
                             header->gc,
                             xpaint + CELL_HPADDING,
                             ypaint + 1,
                             layout);

            g_object_unref (layout);

            gdk_gc_set_clip_rectangle (header->gc, NULL);

            xpaint += w;
        }

        ypaint += h;
    }
}
예제 #29
0
static void setgattr(Gwidget_t * widget, Ggattr_t * ap)
{
    GdkGCValues gcv;
    GdkColor c;
    int color, width, mode, style, pati;
    double intens;

    if (!(ap->flags & G_GATTRCOLOR))
	ap->color = WCU->defgattr.color;
    if (!(ap->flags & G_GATTRWIDTH))
	ap->width = WCU->defgattr.width;
    if (!(ap->flags & G_GATTRMODE))
	ap->mode = WCU->defgattr.mode;
    if (!(ap->flags & G_GATTRFILL))
	ap->fill = WCU->defgattr.fill;
    if (!(ap->flags & G_GATTRSTYLE))
	ap->style = WCU->defgattr.style;
    color = ap->color;

    if (color >= G_MAXCOLORS || !(WCU->colors[color].inuse))
	color = 1;

    if (color != WCU->gattr.color) {

	WCU->gattr.color = color;
	/*if (ap->mode == GDK_XOR) {
	   gdk_gc_set_foreground (GC, widget->w->style->white_gc);
	   }
	   else {
	 */
	gdk_gc_set_foreground(GC, &WCU->colors[WCU->gattr.color].color);
	/* } */

/*	    if (Gdepth == 1) {
	        cp = &WCU->colors[color].color;
	        intens = (0.3 * cp->blue + 0.59 * cp->red +
	                        0.11 * cp->green) / 65535.0;
	        pati = (intens <= 0.0625) ? 16 :
	                    -16.0 * (log (intens) / 2.7725887222);
	        XSetTile (Gdisplay, GC, WCU->grays[pati]);
            }
*/
    }
    mode = ap->mode;
    if (mode != WCU->gattr.mode) {
	WCU->gattr.mode = mode;
/*	    XSetFunction (Gdisplay, GC, WCU->gattr.mode);
	    if (mode == GDK_XOR)
            	gdk_gc_set_foreground (GC, &WCU->colors[0].color);
            else
*/
	gdk_gc_set_foreground(GC, &WCU->colors[WCU->gattr.color].color);
    }
    width = ap->width;
    if (width != WCU->gattr.width) {
	gdk_gc_set_line_attributes(GC, width, GDK_LINE_SOLID,
				   GDK_CAP_NOT_LAST, GDK_JOIN_BEVEL);
    }

    WCU->gattr.fill = ap->fill;
    style = ap->style;
    if (style != WCU->gattr.style) {
	WCU->gattr.style = style;
	if (style == G_SOLID) {
	    gdk_gc_set_line_attributes(GC, width, GDK_LINE_SOLID,
				       GDK_CAP_NOT_LAST, GDK_JOIN_BEVEL);
	} else {
	    gdk_gc_set_dashes(GC, 0, gstyles[style], 2);
	    gdk_gc_set_line_attributes(GC, width, GDK_LINE_ON_OFF_DASH,
				       GDK_CAP_NOT_LAST, GDK_JOIN_BEVEL);
	}
    }
}
예제 #30
0
static void
draw_wireframe_plane (gint startx,
		      gint starty,
		      gint pw,
		      gint ph)
{
  GimpVector3 v1, v2, a, b, c, d, dir1, dir2;
  gint        cnt, n = 0;
  gdouble     x1, y1, x2, y2, cx1, cy1, cx2, cy2, fac;

  /* Find rotated box corners */
  /* ======================== */

  gimp_vector3_set (&v1, 0.5, 0.0, 0.0);
  gimp_vector3_set (&v2, 0.0, 0.5, 0.0);

  gimp_vector3_rotate (&v1,
		       gimp_deg_to_rad (mapvals.alpha),
		       gimp_deg_to_rad (mapvals.beta),
		       gimp_deg_to_rad (mapvals.gamma));

  gimp_vector3_rotate (&v2,
		       gimp_deg_to_rad (mapvals.alpha),
		       gimp_deg_to_rad (mapvals.beta),
		       gimp_deg_to_rad (mapvals.gamma));

  dir1 = v1; gimp_vector3_normalize (&dir1);
  dir2 = v2; gimp_vector3_normalize (&dir2);

  fac = 1.0 / (gdouble) WIRESIZE;

  gimp_vector3_mul (&dir1, fac);
  gimp_vector3_mul (&dir2, fac);

  gimp_vector3_add (&a, &mapvals.position, &v1);
  gimp_vector3_sub (&b, &a, &v2);
  gimp_vector3_add (&a, &a, &v2);
  gimp_vector3_sub (&d, &mapvals.position, &v1);
  gimp_vector3_sub (&d, &d, &v2);

  c = b;

  cx1 = (gdouble) startx;
  cy1 = (gdouble) starty;
  cx2 = cx1 + (gdouble) pw;
  cy2 = cy1 + (gdouble) ph;

  for (cnt = 0; cnt <= WIRESIZE; cnt++)
    {
      gimp_vector_3d_to_2d (startx, starty, pw, ph,
			    &x1, &y1, &mapvals.viewpoint, &a);
      gimp_vector_3d_to_2d (startx, starty, pw, ph,
			    &x2, &y2, &mapvals.viewpoint, &b);

      if (clip_line (&x1, &y1, &x2, &y2, cx1, cy1, cx2, cy2) == TRUE)
        {
          linetab[n].x1 = RINT (x1);
          linetab[n].y1 = RINT (y1);
          linetab[n].x2 = RINT (x2);
          linetab[n].y2 = RINT (y2);
          linetab[n].linewidth = 1;
          linetab[n].linestyle = GDK_LINE_SOLID;
          gdk_gc_set_line_attributes (gc,
				      linetab[n].linewidth,
				      linetab[n].linestyle,
				      GDK_CAP_NOT_LAST,
				      GDK_JOIN_MITER);
          gdk_draw_line (previewarea->window, gc,
			 linetab[n].x1, linetab[n].y1,
			 linetab[n].x2, linetab[n].y2);
          n++;
        }

      gimp_vector_3d_to_2d (startx, starty, pw, ph,
			    &x1, &y1, &mapvals.viewpoint, &c);
      gimp_vector_3d_to_2d (startx, starty, pw, ph,
			    &x2, &y2, &mapvals.viewpoint, &d);

      if (clip_line (&x1, &y1, &x2, &y2, cx1, cy1, cx2, cy2) == TRUE)
        {
          linetab[n].x1 = RINT (x1);
          linetab[n].y1 = RINT (y1);
          linetab[n].x2 = RINT (x2);
          linetab[n].y2 = RINT (y2);
          linetab[n].linewidth = 1;
          linetab[n].linestyle = GDK_LINE_SOLID;
          gdk_gc_set_line_attributes (gc,
				      linetab[n].linewidth,
				      linetab[n].linestyle,
				      GDK_CAP_NOT_LAST,
				      GDK_JOIN_MITER);
          gdk_draw_line (previewarea->window, gc,
			 linetab[n].x1, linetab[n].y1,
			 linetab[n].x2, linetab[n].y2);
          n++;
        }

      gimp_vector3_sub (&a, &a, &dir1);
      gimp_vector3_sub (&b, &b, &dir1);
      gimp_vector3_add (&c, &c, &dir2);
      gimp_vector3_add (&d, &d, &dir2);
    }

  /* Mark end of lines */
  /* ================= */

  linetab[n].x1 = -1;
}