/*
 * This callback is invoked whenever the user moves the mouse
 * over the drawing area.
 */
static void
view_motion_notify_cb (GtkWidget *drawing_area, GdkEventMotion *event,
		       view_data_t *view_data)
{
	embeddable_data_t *embeddable_data = view_data->embeddable_data;

	/*
	 * If the mouse button is depressed, we update the internal
	 * representation of the image.  Then we update all the views.
	 */

	if (! (event->state & GDK_BUTTON1_MASK))
		return;

	/*
	 * First, update the internal representation of the image.  We
	 * store the image data internally in an off-screen GdkPixmap.
	 * This is just for the convenience of being able to use gdk
	 * routines to draw into it.  We could just as easily store
	 * this data in our own image buffer, or as a list of strokes
	 * which could be replayed, or whatever.
	 *
	 * We do the drawing using the view's graphics context.  This
	 * is because each view could have a different current drawing
	 * mode (pen color, style, etc).  In general, all views for a
	 * given embeddable are supposed to be identical, but they can
	 * differ in some small ways, such as the undo history and
	 * current editing mode.
	 */
	if (view_data->last_x != -1 && view_data->last_y != -1) {
		gdk_draw_line (embeddable_data->pixmap,
			       view_data->gc,
			       view_data->last_x, view_data->last_y,
			       (gint) event->x, (gint) event->y);
	}

	view_data->last_x = (gint) event->x;
	view_data->last_y = (gint) event->y;
		
	/*
	 * Now reflect this change to the image data in all the views.
	 */
	embeddable_update_all_views (embeddable_data);
}
Beispiel #2
0
static void
record_stroke_segment(GtkWidget *widget)
{
	gint x, y;
	struct gstroke_metrics *metrics;
	GdkDeviceManager *devmgr;
	GdkDevice *dev;

	g_return_if_fail(widget != NULL);

	devmgr = gdk_display_get_device_manager(gtk_widget_get_display(widget));
	dev = gdk_device_manager_get_client_pointer(devmgr);
	gdk_window_get_device_position(gtk_widget_get_window(widget),
		dev, &x, &y, NULL);

	if (last_mouse_position.invalid)
		last_mouse_position.invalid = FALSE;
	else if (gstroke_draw_strokes()) {
#if 1
		XDrawLine(gstroke_disp, gstroke_window, gstroke_gc,
			last_mouse_position.last_point.x,
			last_mouse_position.last_point.y, x, y);
		/* XFlush (gstroke_disp); */
#else
		/* FIXME: this does not work. It will only work if we create
		 * a corresponding GDK window for stroke_window and draw on
		 * that... */
		gdk_draw_line(gtk_widget_get_window(widget),
			widget->style->fg_gc[GTK_STATE_NORMAL],
			last_mouse_position.last_point.x,
			last_mouse_position.last_point.y, x, y);
#endif
	}

	if (last_mouse_position.last_point.x != x ||
		last_mouse_position.last_point.y != y)
	{
		last_mouse_position.last_point.x = x;
		last_mouse_position.last_point.y = y;
		metrics = g_object_get_data(G_OBJECT(widget), GSTROKE_METRICS);
		_gstroke_record (x, y, metrics);
	}
}
Beispiel #3
0
static void 
pad_area_init (PadArea *area)
{
  GList *tmp_list;
  int index = 1;
  
  guint16 width = area->widget->allocation.width;
  guint16 height = area->widget->allocation.height;

  gdk_draw_rectangle (area->pixmap, 
		      area->widget->style->white_gc, TRUE,
		      0, 0, width, height);

  tmp_list = area->strokes;
  while (tmp_list)
    {
      GdkPoint *cur, *old;
      GList *stroke_list = tmp_list->data;

      old = NULL;

      if (area->annotate)
	pad_area_annotate_stroke (area, stroke_list, index);

      while (stroke_list)
	{
	  cur = (GdkPoint *)stroke_list->data;
	  if (old)
	    gdk_draw_line (area->pixmap, 
			   area->widget->style->black_gc,
			   old->x, old->y, cur->x, cur->y);

	  old = cur;
	  stroke_list = stroke_list->next;
	}
      
      tmp_list = tmp_list->next;
      index++;
    }

  gtk_widget_queue_draw (area->widget);
  
}
Beispiel #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;
}
Beispiel #5
0
/*
 * DrawScreen
 *
 * This does a lot of work.  It draws the background and 
 * all the units, as well as the radar.  This routine is 
 * essentially the main loop that gets called by the 
 * timer every update frequency.
 */
void DrawScreen (GdkPixmap *pixmap, GtkWidget *drawing_area)
{
    /* --- Move player based on keys pressed --- */
    HandleKeysPressed ();

    /* --- Get the screen width --- */
    nScreenWidth = drawing_area->allocation.width;

    /* --- Figure out the offset of the player --- */
    CalculateAdjustments (drawing_area);

    /* --- clear pixmap (background image) --- */
    gdk_draw_rectangle (pixmap,
              drawing_area->style->black_gc,
              TRUE,
              0, 0,
              drawing_area->allocation.width,
              drawing_area->allocation.height);

    /* --- Draw top border and radar screen --- */
    gdk_draw_line (pixmap, drawing_area->style->white_gc, 
                   0, RADAR_HEIGHT, 
                   drawing_area->allocation.width, 
                   RADAR_HEIGHT);

    /* --- Oh those high peaks --- */
    DrawMountains (pixmap, drawing_area, 
                   drawing_area->allocation.height - 65,
                   drawing_area->allocation.height - BOTTOM_HEIGHT);
 
    /* --- Draw the characters --- */
    DrawAllUnits (pixmap, drawing_area); 

    /* --- Draw the units on the radar --- */
    DrawRadar (pixmap, drawing_area);

    /* --- Look for collisions --- */
    CollisionCheck ();

    /* --- Clean up those that got destroyed --- */
    FreeDestroyedUnits ();
}
Beispiel #6
0
/**
 * Draw replay records from start(?) up to some point.
 * Order is important!
 */
static void replay_draw_lines()
{
	int i, start_idx, end_idx, inc;

	if (replay_records == NULL || last_draw_idx == -1)
		return;

	map_draw_back_layers(g_view.pixmap);

	if (direction_forward) {
		start_idx = 0;
		end_idx = last_draw_idx;
		inc = 1;
	} else {
		start_idx = total_records - 1;
		end_idx = last_draw_idx;
		inc = -1;
	}

	trackpoint_t *rec, *last_rec = NULL;

	for (i=start_idx; direction_forward? i<=end_idx : i>=end_idx; i+=inc) {
		rec = &(replay_records[i]);
		point_t p = {(rec->pixel.x - g_view.fglayer.tl_pixel.x),
				(rec->pixel.y - g_view.fglayer.tl_pixel.y)};

		if (last_rec) {
			if (rec->inview || last_rec->inview) {
				gdk_draw_line(g_view.pixmap, g_context.track_gc,
					last_point.x, last_point.y, p.x, p.y);
			}
		}

		last_point = p;
		last_rec = rec;
	}

	gdk_draw_drawable (g_view.da->window, g_context.track_gc, g_view.pixmap,
		g_view.fglayer.visible.x, g_view.fglayer.visible.y,
		g_view.fglayer.visible.x, g_view.fglayer.visible.y,
		g_view.fglayer.visible.width, g_view.fglayer.visible.height);
}
/* Utility to actually draw the line for an intron. Clips it if necessary, maintaining the same
 * angle for the line */
static void drawIntronLine(DrawData *data, const gint x1, const gint y1, const gint x2, const gint y2, GdkRectangle *clipRect)
{
    /* Only draw anything if at least part of the line is within range. We are only ever called with
     * y values that are in range so don't bother checking them. */
    const gint xMax = clipRect->x + clipRect->width;

    if (x1 <= xMax && x2 >= clipRect->x)
    {
        int xStart = x1;
        int xEnd = x2;
        int yStart = y1;
        int yEnd = y2;

        /* Clip the start/end x values if out of range */
        if (xStart < clipRect->x)
        {
            const int origWidth = abs(xEnd - xStart);

            xStart = clipRect->x;

            const int newWidth = abs(xEnd - xStart);
            const int newHeight = roundNearest((double)(yEnd - yStart) * (double)newWidth / (double)origWidth); /* negative if yend < ystart */

            yStart = yEnd - newHeight;
        }

        if (xEnd > xMax)
        {
            const int origWidth = abs(xEnd - xStart);

            xEnd = xMax;

            const int newWidth = abs(xEnd - xStart);
            const int newHeight = roundNearest((double)(yEnd - yStart) * (double)newWidth / (double)origWidth);

            yEnd = yStart + newHeight;
        }

        gdk_draw_line(data->drawable, data->gc, xStart, yStart, xEnd, yEnd);
    }
}
Beispiel #8
0
static void 
draw_line (DiaRenderer *object, Point *start, Point *end, Color *line_color)
{
  DiaGdkRenderer *renderer = DIA_GDK_RENDERER (object);

  GdkGC *gc = renderer->gc;
  GdkColor color;
  int x1,y1,x2,y2;

  if (line_color->alpha == 0.0)
    return;

  dia_transform_coords(renderer->transform, start->x, start->y, &x1, &y1);
  dia_transform_coords(renderer->transform, end->x, end->y, &x2, &y2);
  
  renderer_color_convert(renderer, line_color, &color);
  gdk_gc_set_foreground(gc, &color);
  
  gdk_draw_line(renderer->pixmap, gc,
		x1, y1,	x2, y2);
}
Beispiel #9
0
/*!
  Display a dashed line from image point \e ip1 to image point \e ip2.
  \param ip1,ip2 : Initial and final image points.
  \param color : Line color.
  \param thickness : Line thickness.
*/
void vpDisplayGTK::displayDotLine ( const vpImagePoint &ip1, 
				    const vpImagePoint &ip2,
				    const vpColor &color, 
				    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_ON_OFF_DASH, GDK_CAP_BUTT,
                               GDK_JOIN_BEVEL) ;
    gdk_draw_line(background, gc,
		  vpMath::round( ip1.get_u() ),
		  vpMath::round( ip1.get_v() ),
		  vpMath::round( ip2.get_u() ),
		  vpMath::round( ip2.get_v() ) );
    gdk_gc_set_line_attributes(gc, 0,
                               GDK_LINE_SOLID, GDK_CAP_BUTT,
                               GDK_JOIN_BEVEL) ;
  }
  else
  {
    vpERROR_TRACE("GTK not initialized " ) ;
    throw(vpDisplayException(vpDisplayException::notInitializedError,
                             "GTK not initialized")) ;
  }
}
static void
sample_display_draw_data (GdkDrawable *win,
			  const SampleDisplay *s,
			  int color,
			  int x,
			  int width)
{
    gint16 c, d;
    GdkGC *gc;
    const int sh = s->height;

    if(width == 0)
	return;

    g_return_if_fail(x >= 0);
    g_return_if_fail(x + width <= s->width);

    gdk_draw_rectangle(win, color ? s->fg_gc : s->bg_gc,
		       TRUE, x, 0, width, s->height);

    if(s->display_zero_line) {
	gdk_draw_line(win, s->zeroline_gc, x, s->height / 2, x + width - 1, s->height / 2);
    }

    gc = color ? s->bg_gc : s->fg_gc;

    if(s->datatype == 16) {
	c = ((gint16*)s->data)[OFFSET_RANGE(s->datalen, XPOS_TO_OFFSET(x - 1))];
	
	while(width >= 0) {
	    d = ((gint16*)s->data)[OFFSET_RANGE(s->datalen, XPOS_TO_OFFSET(x))];
	    gdk_draw_line(win, gc,
			  x - 1, ((32768 - c) * sh) >> 16,
			  x,     ((32768 - d) * sh) >> 16);
	    c = d;
	    x++;
	    width--;
	}
    } else {
gboolean on_darea_expose ()
{
	


	GdkGC *gc = gdk_gc_new(GDK_DRAWABLE(widget->window));
 GdkColor color;
 gdk_color_parse("RED", &color); 
 gdk_gc_set_foreground(gc, &color);
 
 	a+=10;
 	b+=10;
printf("ok");
	gdk_draw_line((widget->window), gc, a, a,b,b);
	
	return TRUE;
 
 
	
	
	//gtk_timeout_add(100, (GtkFunction)draw_line(widget, gc, a, b), NULL);

}
Beispiel #12
0
int GCline(Gwidget_t * widget, Gpoint_t gp1, Gpoint_t gp2, Ggattr_t * ap)
{
    PIXpoint_t pp1, pp2;
    Grect_t gr;

    if (gp1.x < gp2.x)
	gr.o.x = gp1.x, gr.c.x = gp2.x;
    else
	gr.o.x = gp2.x, gr.c.x = gp1.x;
    if (gp1.y < gp2.y)
	gr.o.y = gp1.y, gr.c.y = gp2.y;
    else
	gr.o.y = gp2.y, gr.c.y = gp1.y;

/*	if(!ISVISIBLE(gr))
		return 1;
*/

    pp1 = pdrawtopix(widget, gp1), pp2 = pdrawtopix(widget, gp2);
    setgattr(widget, ap);
    gdk_draw_line(widget->w->window, GC, pp1.x, pp1.y, pp2.x, pp2.y);
    return 0;
}
Beispiel #13
0
void draw_horiz_specgram()
{
	active_drawing_area = height-(2*border);
	gdk_threads_enter();
	if (display_markers)
	{
                update_freq_markers();
                clear_display = FALSE;
                display_markers = FALSE;
	}
	gdk_window_copy_area(main_pixmap,gc,
			0,border,
			main_pixmap,
			tape_scroll,border,
			width-horiz_spec_start,
			active_drawing_area);

	reducer(low_freq, high_freq, active_drawing_area);

	for (i=0; i < active_drawing_area; i++)
	{
		lvl=(gint)pip_arr[i]*4;
		if (lvl > (MAXBANDS-1))
			lvl=(MAXBANDS-1);
		gdk_gc_set_foreground(gc,&colortab[16][lvl]);

		gdk_draw_line(main_pixmap,gc,
				width-horiz_spec_start-tape_scroll, 
				active_drawing_area-i+border,
				width-horiz_spec_start,
				active_drawing_area-i+border);
	}

	gdk_window_clear(main_display->window);

	gdk_threads_leave();
}
Beispiel #14
0
Datei: gtkfb.c Projekt: sgh/aos
void ugui_line(int x1, int y1, int x2, int y2, unsigned int color) {
	int dx,dy;
	GdkColormap *cmap;
	GdkColor acolor;
// 	GdkRectangle rect = {
// 		.x = 0,
// 		.y = 0,
// 		.width = 100,
// 		.height = 100,
// 	};

	x1 += bound_x1;
	x2 += bound_x1;
	y1 += bound_y1;
	y2 += bound_y1;

	gdk_threads_enter();
	
	cmap = gdk_colormap_get_system();
	
  acolor.red   = ((color >> 16) & 0xFF) * 0x101;
  acolor.green = ((color >>  8) & 0xFF) * 0x101;
  acolor.blue  = ((color >>  0) & 0xFF) * 0x101;

  if (!gdk_color_alloc(cmap, &acolor)) {
    g_error("couldn't allocate color");
		exit(1);
  }
	
	gdk_gc_set_rgb_fg_color(drawing_area->style->fg_gc[GTK_WIDGET_STATE (drawing_area)], &acolor );

	for (dx = 0; dx<SCALE; dx++)
	for (dy = 0; dy<SCALE; dy++)
		gdk_draw_line(pixmap, drawing_area->style->fg_gc[GTK_WIDGET_STATE (drawing_area)], x1*SCALE+dx, y1*SCALE+dy, x2*SCALE+dx, y2*SCALE+dy);

	gdk_threads_leave();
}
Beispiel #15
0
static void _draw_label_and_line(LoadGraph * lg, gint position, gint value)
{
    gchar *tmp;

    /* draw lines */
    if (position > 0)
	gdk_draw_line(GDK_DRAWABLE(lg->buf), lg->grid, 0, position,
		      lg->width, position);
    else
	position = -1 * position;

    /* draw label */
    tmp =
	g_strdup_printf("<span size=\"x-small\">%d%s</span>", value,
			lg->suffix);

    pango_layout_set_markup(lg->layout, tmp, -1);
    pango_layout_set_width(lg->layout,
			   lg->area->allocation.width * PANGO_SCALE);
    gdk_draw_layout(GDK_DRAWABLE(lg->buf), lg->trace, 2, position,
		    lg->layout);

    g_free(tmp);
}
Beispiel #16
0
/**
 * gimp_canvas_draw_cursor:
 * @canvas: the #GimpCanvas widget to draw on.
 * @x: x coordinate
 * @y: y coordinate
 *
 * Draws a plus-shaped black and white cursor, centered at the point
 * @x, @y.
 **/
void
gimp_canvas_draw_cursor (GimpCanvas *canvas,
                         gint        x,
                         gint        y)
{
  GtkWidget *widget = GTK_WIDGET (canvas);

  if (! (gimp_canvas_ensure_style (canvas, GIMP_CANVAS_STYLE_BLACK) &&
         gimp_canvas_ensure_style (canvas, GIMP_CANVAS_STYLE_WHITE)) )
    return;

  gdk_draw_line (widget->window, canvas->gc[GIMP_CANVAS_STYLE_WHITE],
                 x - 7, y - 1, x + 7, y - 1);
  gdk_draw_line (widget->window, canvas->gc[GIMP_CANVAS_STYLE_BLACK],
                 x - 7, y,     x + 7, y    );
  gdk_draw_line (widget->window, canvas->gc[GIMP_CANVAS_STYLE_WHITE],
                 x - 7, y + 1, x + 7, y + 1);
  gdk_draw_line (widget->window, canvas->gc[GIMP_CANVAS_STYLE_WHITE],
                 x - 1, y - 7, x - 1, y + 7);
  gdk_draw_line (widget->window, canvas->gc[GIMP_CANVAS_STYLE_BLACK],
                 x,     y - 7, x,     y + 7);
  gdk_draw_line (widget->window, canvas->gc[GIMP_CANVAS_STYLE_WHITE],
                 x + 1, y - 7, x + 1, y + 7);
}
Beispiel #17
0
void draw_spike_3d()
{
	extern gfloat det_axis_angle;
	gdk_threads_enter();
	gdk_window_copy_area(main_pixmap,gc,
			0,0,
			main_pixmap,
			xdet_scroll,
			zdet_scroll,
			width-xdet_scroll,
			height-zdet_scroll);
	if (xdet_scroll > 0)
	{
		gdk_draw_rectangle(main_pixmap,
				main_display->style->black_gc,
				TRUE, width-xdet_scroll,0,
				xdet_scroll,height);
	}
	else
	{
		gdk_draw_rectangle(main_pixmap,
				main_display->style->black_gc,
				TRUE, 0,0,
				abs(xdet_scroll),height);
	}

	if (zdet_scroll > 0)
	{
		gdk_draw_rectangle(main_pixmap,
				main_display->style->black_gc,
				TRUE, 0,height-zdet_scroll,
				width,zdet_scroll);
	}
	else
	{
		gdk_draw_rectangle(main_pixmap,
				main_display->style->black_gc,
				TRUE, 0,0,
				width,abs(zdet_scroll));
	}
	gdk_threads_leave();

	/* in pixels */
	x_draw_width = width - abs(xdet_scroll)-2*border;
	y_draw_height = height - abs(zdet_scroll)-2*border;

	/* in pixels */
	x_offset = (width-x_draw_width)/2;
	y_offset = (height-y_draw_height)/2;


	det_axis_angle_deg = det_axis_angle*90/M_PI_2;
	if (det_axis_angle_deg < 0.0)
		det_axis_angle_deg += 360.0;

	dir_angle_rad = (float)atan2((float)zdet_scroll,-(float)xdet_scroll);
	dir_angle_deg = dir_angle_rad*90/M_PI_2;
	if (dir_angle_deg < 0.0)
		dir_angle_deg += 360.0;


	if (spiketilt == FALSE)
	{
		x_tilt=0.0;
		y_tilt=0.0;
	}
	else
	{
		/* Perspecitve Tilting algorithm.  Probably severely flawed
		 * but it displays nicely..  
		 * 
		 * Note to self.  Learn how to use Trig properly... :)
		 */ 
		if ((dir_angle_deg >= 315.0) || (dir_angle_deg < 45.0))
		{
			//printf("Quad 4<->1\n");
			x_tilt = sin(dir_angle_rad);
			y_tilt = cos(dir_angle_rad);
		}
		else if ((dir_angle_deg >= 45.0) && (dir_angle_deg < 135.0))
		{
			//printf("Quad 1<->2\n");
			x_tilt = cos(dir_angle_rad);
			y_tilt = sin(dir_angle_rad);
		}
		else if ((dir_angle_deg >= 135.0) && (dir_angle_deg < 225.0))
		{
			//printf("Quad 2<->3\n");
			x_tilt = -sin(dir_angle_rad);
			y_tilt = -cos(dir_angle_rad);
		}
		else if  ((dir_angle_deg >= 225.0) && (dir_angle_deg < 315.0))
		{
			//printf("Quad 3<->4\n");
			x_tilt = -cos(dir_angle_rad);
			y_tilt = -sin(dir_angle_rad);
		}
	}

	x_axis_tilt = sin(det_axis_angle);
	y_axis_tilt = cos(det_axis_angle);

	x_tilt_weight = cos(det_axis_angle);
	y_tilt_weight = 0.0;
	x_axis_weight = 1.0;
	y_axis_weight = 1.0;

/*
	// Debugging Code....  

	printf("axis angle in deg is %f\n",det_axis_angle_deg);
	printf("direction angle in deg is %f\n",dir_angle_deg);
	printf("\nx_tilt %f, y_tilt %f\n",x_tilt,y_tilt);
	printf("x_tilt_weight %f, y_tilt_weight %f\n",x_tilt_weight,y_tilt_weight);
	printf("Scroll Tilt components (%f,%f)\n",x_tilt*x_tilt_weight,y_tilt*y_tilt_weight);
	printf("x_axis_tilt %f, y_axis_tilt %f\n",x_axis_tilt,y_axis_tilt);
	printf("x_axis_weight %f, y_axis_weight %f\n",x_axis_weight,y_axis_weight);
	printf("Perspective Tilt components (%f,%f)\n\n",x_axis_tilt*x_axis_weight,y_axis_tilt*y_axis_weight);
	
*/

	/* in pixels */
	start_x = width-((x_draw_width)*(1.0-xdet_end))-x_offset;
	end_x = width-((x_draw_width)*(1.0-xdet_start))-x_offset;
	start_y = height-((y_draw_height)*(1.0-ydet_end))-y_offset;
	end_y = height-((y_draw_height)*(1.0-ydet_start))-y_offset;

	/* in pixels */
	start_x = width-((x_draw_width)*(1.0-xdet_end))-x_offset;
	end_x = width-((x_draw_width)*(1.0-xdet_start))-x_offset;
	start_y = height-((y_draw_height)*(1.0-ydet_end))-y_offset;
	end_y = height-((y_draw_height)*(1.0-ydet_start))-y_offset;
	/* end_x - start_x is X screen space in pixels 
	 * the idea is to reduce the number of gdk_draw_lines to 
	 * the number in axis_length, instead of nsamp/2. which saves drawing 
	 * over the same location on the screen and wasting time.
	 * I guess when combining pips together we should AVG them. What
	 * other way might be better? (suggestions welcome...)
	 */

	/* disp_val[] is a malloc'd array storing pip values for ALL pips, 
	 * (1/2 NSAMP). pip_arr[] is malloc'd array that is length 
	 * "axis_length"and contains anti-aliased reduction of 
	 * disp[val] using linear interpolation to combine/average 
	 * multiple pip values into one viewable spike. Should be 
	 * fully scaling with best results of having bins_per_pip 
	 * being a multiple of nsamp/2.
	 */
	axis_length = (gint)sqrt(((end_x-start_x)*(end_x-start_x))+((end_y-start_y)*(end_y-start_y)));
	loc_bins_per_pip = ((float)nsamp/2.0)/(fabs(axis_length));

	reducer(low_freq, high_freq, axis_length);
	gdk_threads_enter();

	/* Do this here instead of in the loop  axis_length number of times..
	 * cpu savings... :)
	 */
	x_amplitude = (x_tilt*x_tilt_weight)+(x_axis_tilt*x_axis_weight);
	y_amplitude = (y_tilt*y_tilt_weight)+(y_axis_tilt*y_axis_weight);

	for( i=0; i < axis_length; i++ )
	{
		pt[0].x=width-(((i*x_draw_width)*(1-xdet_start))/axis_length)\
				-((((axis_length-i)*x_draw_width)*(1-xdet_end))\
				/(axis_length))-x_offset;
		pt[0].y=height-(((i*loc_bins_per_pip)*y_draw_height*ydet_start)\
				/(nsamp/2))-((((nsamp/2)-(i*loc_bins_per_pip))\
				*y_draw_height*ydet_end)/(nsamp/2))\
				-y_offset;
		pt[1].x=pt[0].x -(gint)pip_arr[i]*x_amplitude;
		pt[1].y=pt[0].y -(gint)pip_arr[i]*y_amplitude; \
		lvl=abs((gint)pip_arr[i]*4);
		if (lvl > (MAXBANDS-1))
			lvl=(MAXBANDS-1);
		else if (lvl <= 0)
			lvl = 0;

		gdk_gc_set_foreground(gc,&colortab[16][lvl]);

		gdk_draw_line(main_pixmap,gc,\
				pt[0].x,\
				pt[0].y,\
				pt[1].x,\
				pt[1].y);
	}
	gdk_window_clear(main_display->window);

	gdk_threads_leave();
}
void GtkPaintContext::drawLine(int x0, int y0, int x1, int y1) {
	gdk_draw_line(myPixmap, myTextGC,
								x0 + leftMargin(), y0 + topMargin(),
								x1 + leftMargin(), y1 + topMargin());
}
Beispiel #19
0
/*
 * DisplayOtherUnits
 *
 * Display all the units on the screen. First, we need 
 * to move each of the units to their new positions. 
 * Some of this is done in the AI module. 
 * 
 */
void DisplayOtherUnits (GdkPixmap *pixmap, GtkWidget *drawing_area)
{
    typUnit *unit;
    typUnit *unitHit;
    GList *node;
    int xPos;
    int xPosEnd;
    typSprite *sprite;

    /* --- Each unit in the list --- */
    for (node = unitList; node; node = node->next) {
 
        /* --- Get the unit --- */
        unit = (typUnit *) node->data;

        /*  
         * --- Run the AI module on it to move it --- 
         */
        AIModule (unit);

        /* 
         * If the unit was destroyed by the AI, 
         * don't draw the unit.
         */
        if (unit->bDestroy) {
            continue;
        }

        /* 
         * If there's no sprite for the unit, 
         * we can't draw it now, can we?
         */
        sprite = GetSprite (unit);
        if (sprite == NULL) continue;
 
        /* --- Where on the screen is it going? --- */
        xPos = UnitScreenX (unit);

        /* --- Make sure unit doesn't go out of bounds --- */
        AdjustSpriteHeight (unit);

        /* --- Finally draw unit --- */
        DisplaySprite (drawing_area, sprite, 
                   (int) (xPos - sprite[0].width / 2), 
                   (int) (unit->y - sprite[0].height / 2));
    }

    /* 
     * --- once everyone is painted, fire the lasers.
     */

    for (node = unitList; node; node = node->next) {

        unit = (typUnit *) node->data;

        /* --- If this is a laser --- */
        if (unit->type == LASER) {
 
            /* --- Get starting and ending positions --- */
            xPos = ScreenX ((int) unit->x);
            xPosEnd = xPos + LASER_LENGTH * unit->direction;

            /* --- See if anything was hit --- */
            unitHit = AnyoneBetween ((int) xPos, (int) unit->y, 
                                     (int) xPosEnd, (int) unit->y);
            if (unitHit) {

                /* --- Something was hit --- */

                /* --- Laser shot only goes this far --- */
                xPosEnd = UnitScreenX (unitHit);

                /* --- Destroy the unit --- */
                unitHit->bDestroy = TRUE;
                unit->bDestroy = TRUE;

                /* --- Special effects of destruction --- */
                AddExplosion (unitHit);
            }

            /* --- Draw the laser --- */
            gdk_draw_line (pixmap, penWhite,
                           xPos, unit->y, 
                           xPosEnd,
                           unit->y);
            
            /* --- Get real coordinates of laser --- */
            unit->x = GameX (xPosEnd);

            /* --- If laser has gone too far... --- */
            if (DistanceBetween (unit, hero) > nScreenWidth / 2) {

                /* --- destroy it --- */
                unit->bDestroy = TRUE;
            }
        }
    }
}
Beispiel #20
0
void dessiner_pdv(pdv* pt_pdv_current, file_opener* donnees)
{
    GdkDrawable* cartew=donnees->carte->window;
            if(pt_pdv_current->affichage==1) // Vérifie si le plan de vol doit être affiché
            {
            position* loc_avion=malloc(sizeof(position));
//            Position_avion(donnees,pt_pdv_current,loc_avion);
            get_position_avion(loc_avion,pt_pdv_current,donnees->temps);
            loc_avion->y=conversion_lat(loc_avion->y,donnees)*donnees->ycarte;
            loc_avion->x=conversion_longitude(loc_avion->x,donnees)*donnees->xcarte;

        //  On change la couleur du tracé pour le carré et le nom de l'avion
            couleur(donnees->gc,donnees->c,donnees->couleur_avion);
            gdk_draw_rectangle(cartew,donnees->gc,TRUE,loc_avion->x-2,loc_avion->y-2,5,5);
            gdk_draw_string(cartew,donnees->font,donnees->gc,loc_avion->x+3,loc_avion->y-2,pt_pdv_current->nom);
            couleur(donnees->gc,donnees->c,10);


            int x1=-9,x2=0,y1=0,y2=0; // Variables de stockage des coordonnées pour les points de passage

            pt_pass * pt_pass_current = pt_pdv_current->pass_debut;

                if(x1==-9 && pt_pass_current->ptsuiv!=NULL) // Cas du premier point
                {

                    if(pt_pass_current->type_point==0) // Si le point est un aérodrome
                    {
                        aerodrome * pass_aerodrome = pt_pass_current->point;
                        //printf("\n AERODROME 1 \n");
                        x1=conversion_longitude(pass_aerodrome->longitude,donnees)* donnees->xcarte;
                        y1=conversion_lat(pass_aerodrome->latitude,donnees)* donnees->ycarte;

                        // Affichage de l'aérodrome
                        pass_aerodrome->affichage=1;
                        dessiner_aerodromes(pass_aerodrome,donnees);
                    }

                    if(pt_pass_current->type_point==1) // Si le point est une balise
                    {
                        balise * pass_balise = pt_pass_current->point;
                       // printf("\n BALISE 1 \n");
                        x1=conversion_longitude(pass_balise->longitude,donnees)* donnees->xcarte;
                        y1=conversion_lat(pass_balise->latitude,donnees)* donnees->ycarte;

                        // Affichage de la balise
                        pass_balise->affichage=1;
                        dessiner_balise(pass_balise,donnees);
                    }

                    if(pt_pass_current->type_point==2) // Si le point est une ptgpx
                    {
                        ptgpx * pass = pt_pass_current->point;
                       // printf("\n BALISE 1 \n");
                        x1=conversion_longitude(pass->longitude,donnees)* donnees->xcarte;
                        y1=conversion_lat(pass->latitude,donnees)* donnees->ycarte;

                        // Affichage de la balise
                        //gdk_draw_string(carte,font,gc, x1 + 2,y1 + 7, pass_balise->nom);
                        gdk_draw_point(cartew,donnees->gc, x1,y1);
                    }

                pt_pass_current = pt_pass_current->ptsuiv;

                }


                while(pt_pass_current->ptsuiv!=NULL) // Parcours de tous les autres points de passage
                {


                    if(pt_pass_current->type_point==0) // Si le point est un aérodrome
                    {
                    aerodrome * pass_aerodrome = pt_pass_current->point;
                   // printf("\n AERODROME \n");
                    x2=conversion_longitude(pass_aerodrome->longitude,donnees)* donnees->xcarte;
                    y2=conversion_lat(pass_aerodrome->latitude,donnees)* donnees->ycarte;

                    // Affichage de l'aerodrome
                    pass_aerodrome->affichage=1;
                    dessiner_aerodromes(pass_aerodrome,donnees);
                    }

                    if(pt_pass_current->type_point==1) // Si le point est une balise
                    {
                    balise * pass_balise = pt_pass_current->point;
                  //  printf("\n BALISE \n");

                    x2=conversion_longitude(pass_balise->longitude,donnees)* donnees->xcarte;
                    y2=conversion_lat(pass_balise->latitude,donnees)* donnees->ycarte;

                    // Affichage de la balise
                    pass_balise->affichage=1;
                    dessiner_balise(pass_balise,donnees);
                    }

                    if(pt_pass_current->type_point==2) // Si le point est un ptgpx
                    {
                    ptgpx * pass = pt_pass_current->point;

                    x2=conversion_longitude(pass->longitude,donnees)* donnees->xcarte;
                    y2=conversion_lat(pass->latitude,donnees)* donnees->ycarte;

                    // Affichage de la balise
                    int x=conversion_longitude(pass->longitude,donnees)* donnees->xcarte;
                    int y=conversion_lat(pass->latitude,donnees)* donnees->ycarte;
                    //gdk_draw_string(carte,font,gc, x + 2,y + 7, pass_balise->nom);
                    gdk_draw_point(cartew,donnees->gc, x,y);
                    }



//                  Une couleur différente par avion
                    couleur(donnees->gc,donnees->c,donnees->couleur_avion);

//                  Trace la ligne et remet la couleur normalement.
                    gdk_draw_line(cartew, donnees->gc, x1,y1,x2,y2);
                    couleur(donnees->gc,donnees->c,10);

                    // Le point 2 devient le point 1
                    x1=x2;
                    y1=y2;
                    pt_pass_current = pt_pass_current->ptsuiv;

                }

            free(loc_avion);
            }
}
Beispiel #21
0
void dessiner(file_opener *donnees)
{
    GdkDrawable* cartew=donnees->carte->window;
    donnees->gc = gdk_gc_new (cartew);
    // On initialise la police et la couleur
    donnees->font=gdk_font_load("6x9");//6x9 - 10x20
int j;
char text[5];

couleur(donnees->gc,donnees->c,-2);
// On trace les parallèles
for(j=35;j<=60;j+=5)
{
sprintf(text,"%d",j);
gdk_draw_line(cartew,donnees->gc,0,conversion_lat(j,donnees)*donnees->ycarte,donnees->xcarte*3,conversion_lat(j,donnees)*donnees->ycarte);
gdk_draw_string(cartew,donnees->font,donnees->gc,3,conversion_lat(j,donnees)*donnees->ycarte-5,text);
}

// Puis les méridiens
for(j=-15;j<=20;j+=5)
{
sprintf(text,"%d",j);
gdk_draw_line(cartew,donnees->gc,conversion_longitude(j,donnees)*donnees->xcarte,0,conversion_longitude(j,donnees)*donnees->xcarte,donnees->ycarte*3);
gdk_draw_string(cartew,donnees->font,donnees->gc,conversion_longitude(j,donnees)*donnees->xcarte+5,8,text);
}
couleur(donnees->gc,donnees->c,10);

 /* ----------------------------------  CONTOUR FRANCE -------------------------------------- */


    {
        double x1,x2,y1,y2;
        // On ouvre le fichier contenant les points
        FILE *f = fopen("contour_france.csv", "rb");
        //printf("f=%p\n", f);
        if(f)
        {
            char buffer[1024];

            while(fgets(buffer, sizeof(buffer), f))
            {
            //  On charge et on converti les points.
                sscanf(buffer, "%lf;%lf", &x1, &y1);
                x1 = conversion_longitude(x1, donnees);
                y1 = conversion_lat(y1, donnees);
                while(fgets(buffer, sizeof(buffer), f))
                {
                //  Si la ligne est "BREAK" on empeche de tracer la ligne afin de retirer les traits entre les iles
                    if(!strcmp(buffer, "BREAK\n"))
                    {
                        break;
                    }

                    sscanf(buffer, "%lf;%lf", &x2, &y2);
                    x2=conversion_longitude(x2, donnees);
                    y2=conversion_lat(y2, donnees);
                    gdk_draw_line(cartew, donnees->gc, x1*donnees->xcarte,y1*donnees->ycarte,x2*donnees->xcarte,y2*donnees->ycarte);
                    x1=x2;
                    y1=y2;
                }
            }
            fclose(f);
        }
    }

 // ----------------------------------  AERODROMES --------------------------------------
// Si des aérodromes sont chargé on commence l'affichage
   if(donnees->debutaero!=NULL)
    {

        aerodrome* pt_aero=donnees->debutaero;
        // Boucle pour parcourir tous les aérodromes
        while(pt_aero->ptsuiv!=NULL)
        {
            dessiner_aerodromes(pt_aero,donnees);
            pt_aero = pt_aero->ptsuiv;
        }
    }

 // ----------------------------------  BALISES --------------------------------------
// La structure est semblable à celle des aérodromes
    if(donnees->debutbalises!=NULL)
    {
        balise* pt_balise=donnees->debutbalises;

        while(pt_balise->ptsuiv!=NULL)
        {
            dessiner_balise(pt_balise,donnees);
            pt_balise = pt_balise->ptsuiv;
        }
    }




 // ----------------------------------  PLAN DE VOL --------------------------------------
// On initialise la couleur à 0 pour donner une couleur à chaque plan de vol
donnees->couleur_avion=0;

    if(donnees->debutpdv!=NULL) // Rentre si un plan de vol est chargé
    {
    pdv * pt_pdv_current=donnees->debutpdv;

        while(pt_pdv_current!=NULL) // Parcours tous les plans de vol
        {
            dessiner_pdv(pt_pdv_current,donnees);
            pt_pdv_current=pt_pdv_current->ptsuiv;
            donnees->couleur_avion+=1;
        }
    }

/* ------------------------------------ CONFLITS  ---------------------------------------- */

// Si il y a des conflits
    if(donnees->deb_conflits!=NULL)
    {
    // On passe en couleur rouge
    couleur(donnees->gc,donnees->c,-3);
    conflit* conflit_current = donnees->deb_conflits;
    // Variable d'affichage si reste nul à la fin de la boucle pas de conflit
    int conflit_affiche = 0;
    //  On parcours les conflits
        while(conflit_current->ptsuiv != NULL)
        {
        pdv* avion1 = conflit_current->pdv1;
        pdv* avion2 = conflit_current->pdv2;

            // On se situe entre le temps de début et de fin de conflit
            if(donnees->temps > conflit_current->temps_deb && donnees->temps < conflit_current->temps_fin)
            {
                position c0; // position au temps t
                if(avion1->affichage && avion2->affichage) // Les deux avions sont affichés
                {
                // Conflits affiché conflit_affiche est différent de 0
                    conflit_affiche++;

                //  On met un gros carré rouge sur la position de l'avion
                    get_position_avion(&c0,avion1,donnees->temps);
                    gdk_draw_rectangle(cartew,donnees->gc,TRUE,conversion_longitude(c0.x,donnees)*donnees->xcarte-3,conversion_lat(c0.y,donnees)*donnees->ycarte-3,7,7);

                    get_position_avion(&c0,avion2,donnees->temps);
                    gdk_draw_rectangle(cartew,donnees->gc,TRUE,conversion_longitude(c0.x,donnees)*donnees->xcarte-3,conversion_lat(c0.y,donnees)*donnees->ycarte-3,7,7);

                //  On change le label de conflit
                    char *markup;
                    markup = g_markup_printf_escaped ("<span foreground=\"#A00000\">%s</span>", "Conflit.");
                    gtk_label_set_markup (GTK_LABEL (donnees->Msg_conflit), markup);
                    g_free (markup);
                }
            }
        conflit_current = conflit_current->ptsuiv;
        }
// Si aucun conflit n'est affiché on passe au label pas de conflit
    if(conflit_affiche==0)
    {
        char *markup;
        markup = g_markup_printf_escaped ("<span foreground=\"#00A000\">%s</span>", "Pas de conflit\n actuellement.");
        gtk_label_set_markup (GTK_LABEL (donnees->Msg_conflit), markup);
        g_free (markup);
    }
    // On remet en noir
    couleur(donnees->gc,donnees->c,10);
    }
    gdk_font_unref(donnees->font);
    g_object_unref (donnees->gc);
}
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;
}
Beispiel #23
0
bool wxMask::Create( const wxBitmap& bitmap,
                     const wxColour& colour )
{
    if (m_bitmap)
    {
        gdk_bitmap_unref( m_bitmap );
        m_bitmap = (GdkBitmap*) NULL;
    }

    wxImage image = bitmap.ConvertToImage();
    if (!image.Ok()) return FALSE;

    m_bitmap = gdk_pixmap_new( wxGetRootWindow()->window, image.GetWidth(), image.GetHeight(), 1 );
    GdkGC *gc = gdk_gc_new( m_bitmap );

    GdkColor color;
    color.red = 65000;
    color.green = 65000;
    color.blue = 65000;
    color.pixel = 1;
    gdk_gc_set_foreground( gc, &color );
    gdk_gc_set_fill( gc, GDK_SOLID );
    gdk_draw_rectangle( m_bitmap, gc, TRUE, 0, 0, image.GetWidth(), image.GetHeight() );

    unsigned char *data = image.GetData();
    int index = 0;

    unsigned char red = colour.Red();
    unsigned char green = colour.Green();
    unsigned char blue = colour.Blue();

    GdkVisual *visual = wxTheApp->GetGdkVisual();

    int bpp = visual->depth;
    if ((bpp == 16) && (visual->red_mask != 0xf800))
        bpp = 15;
    if (bpp == 15)
    {
        red = red & 0xf8;
        green = green & 0xf8;
        blue = blue & 0xf8;
    }
    else if (bpp == 16)
    {
        red = red & 0xf8;
        green = green & 0xfc;
        blue = blue & 0xf8;
    }
    else if (bpp == 12)
    {
        red = red & 0xf0;
        green = green & 0xf0;
        blue = blue & 0xf0;
    }

    color.red = 0;
    color.green = 0;
    color.blue = 0;
    color.pixel = 0;
    gdk_gc_set_foreground( gc, &color );

    for (int j = 0; j < image.GetHeight(); j++)
    {
        int start_x = -1;
        int i;
        for (i = 0; i < image.GetWidth(); i++)
        {
            if ((data[index] == red) &&
                (data[index+1] == green) &&
                (data[index+2] == blue))
            {
                if (start_x == -1)
                start_x = i;
            }
            else
            {
                if (start_x != -1)
                {
                    gdk_draw_line( m_bitmap, gc, start_x, j, i-1, j );
                    start_x = -1;
                }
            }
            index += 3;
        }
        if (start_x != -1)
            gdk_draw_line( m_bitmap, gc, start_x, j, i, j );
    }

    gdk_gc_unref( gc );

    return TRUE;
}
Beispiel #24
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);
}
Beispiel #25
0
GdkRectangle tandrawpiece (GtkWidget *widget,GdkPixmap *pixmap,
			   tanpiecepos *piecepos,
			   double zoom, tanremplis remplis){

  GdkPoint pnt[PNTNBRMAX+1];
  int i,pntnbr,ix,iy,ixmax=-20000,ixmin=20000,iymax=-20000,iymin=20000;
  GdkRectangle update_rect;
  GdkGC *gc;
  double gris,rx,ry;

  pntnbr=tanplacepiece(piecepos,pnt,zoom);

  for(i=0; i<pntnbr; i++){
    ix=pnt[i].x;
    iy=pnt[i].y;
    if (ix<ixmin)
      ixmin=ix;
    if (ix>ixmax)
      ixmax=ix;
    if (iy<iymin)
      iymin=iy;
    if (iy>iymax)
      iymax=iy;
  }

  update_rect.x=ixmin;
  update_rect.y=iymin;
  update_rect.width=ixmax-ixmin+1;
  update_rect.height=iymax-iymin+1;

  switch (remplis){
  case TAN_PETITEHLP:
    gc=tabgc[GCPETITEHLP];
    break;
  case TAN_PIECENOR:
    gc=tabgc[GCPIECENOR];
    gdk_gc_set_ts_origin (gc,pnt[pntnbr].x,pnt[pntnbr].y);
    break;
  case TAN_PIECEHI:
    gc=tabgc[GCPIECEHI];
    gdk_gc_set_ts_origin (gc,pnt[pntnbr].x,pnt[pntnbr].y);
    break;
  default:
    gc=widget->style->white_gc;
    break;
  }

  gdk_draw_polygon (pixmap,
		    gc,
		    TRUE,
		    pnt,
		    pntnbr);

  if ( remplis==TAN_PIECENOR || remplis==TAN_PIECEHI ){
    pnt[pntnbr]=pnt[0];                 /* ecrase le point du centre */
    for (i=0; i<pntnbr; i++){
      rx=pnt[i+1].x-pnt[i].x;
      ry=pnt[i].y-pnt[i+1].y;
      gris=(ry+rx)*0.35355339/sqrt(rx*rx+ry*ry);
      if (piecepos->flipped)
	gris=-gris;
      gris=gris+0.5;
      gdk_draw_line (pixmap,
		     tabgc[(int)(gris*(GRISNBR))],
		     pnt[i].x,pnt[i].y,pnt[i+1].x,pnt[i+1].y);
    }
  }
  return(update_rect);

}
Beispiel #26
0
/* Smith.c: Routines for plotting Smith charts */
void gtk_graph_smith_plot_axes(GtkGraph *graph)
{
gint i ;
gint x, y, w, h;
gfloat ri[] = {0.2, 0.5, 1.0, 2.0, 5.0}, rxl[]={0.20, 0.5, 1, 2, 5}, coeff1, r, store, arc_angle;
gfloat yend, xend; // The x and y co-ordinates of the end of the reactance lines
gchar label[10];
gint text_width, text_height;
gint xpos = 0, ypos = 0;		// X and Y co-ordinate locations of radial labels

PangoFontDescription *fontdesc = NULL;
PangoLayout *layout = NULL;

g_return_if_fail (graph != NULL);
g_return_if_fail (GTK_IS_GRAPH (graph));
g_return_if_fail (GTK_WIDGET_REALIZED (graph));
g_return_if_fail (graph->graph_type == SMITH);

fontdesc = pango_font_description_from_string("Sans 10");
layout = gtk_widget_create_pango_layout(GTK_WIDGET(graph), NULL);
pango_layout_set_font_description(layout, fontdesc);

/* Plot the concentric grid */

centre_x = user_origin_x + user_width / 2;
centre_y = user_origin_y + user_width / 2;
gdk_draw_arc(buffer, Gridcontext, FALSE, centre_x - graph->dependant->scale_factor, centre_y - graph->dependant->scale_factor, 2.0 * graph->dependant->scale_factor, 2.0 * graph->dependant->scale_factor, 0, 23040);

for (i = 0 ; i < 5 ; i++)
	{
/* Draw the circles of Constant Resistance */
	coeff1 = ri[i] / (1.0+ri[i]);
	r = 1.0 / (ri[i] + 1.0);
	x = centre_x + (gint)((coeff1 - r) * graph->dependant->scale_factor);
	y = centre_y - (gint) (r * graph->dependant->scale_factor);
	w = 2.0 * r * graph->dependant->scale_factor;
	h = 2.0 * r * graph->dependant->scale_factor;
	gdk_draw_arc(buffer, Gridcontext, FALSE, x, y, w, h, 0, 23039);
		
	g_snprintf(label, 10, "%.0f", ri[i] * graph->smith_Z0);
    pango_layout_set_text(layout, label, -1);
    pango_layout_get_pixel_size(layout, &text_width, &text_height);
	xpos = x - text_width / 2;
	ypos = centre_y ;
	gdk_draw_layout(buffer, BandWcontext, xpos, ypos, layout);

/* Draw the circles of Constant Reactance */

	r = 1.0 / rxl[i];
	x = centre_x + (gint) ((1 - r) * graph->dependant->scale_factor);
	w = 2.0 * r * graph->dependant->scale_factor;
	h = 2.0 * r * graph->dependant->scale_factor;

/* Now Label the Constant Reactance curves */
	g_snprintf(label, 10, "+j%0.f", rxl[i]*graph->smith_Z0);
    pango_layout_set_text(layout, label, -1);
    pango_layout_get_pixel_size(layout, &text_width, &text_height);
	store = 2.0 * r/(r*r + 1);
	yend = store * (gfloat)(graph->dependant->scale_factor);
	xend = sqrt(1 - store*store) * (gfloat)(graph->dependant->scale_factor);
	
	switch(i)
		{
		case 0:
		case 1:
			g_snprintf(label, 10, "+j%0.f", rxl[i]*graph->smith_Z0);
			pango_layout_set_text(layout, label, -1);
			pango_layout_get_pixel_size(layout, &text_width, &text_height);
			ypos = centre_y - (gint)yend;
			xpos = centre_x - (gint)xend;
			gdk_draw_layout(buffer, BandWcontext, xpos - text_width, ypos - text_height, layout);
			g_snprintf(label, 10, "-j%0.f", rxl[i]*graph->smith_Z0);
			pango_layout_set_text(layout, label, -1);
			ypos = centre_y + (gint)yend;
			gdk_draw_layout(buffer, BandWcontext, xpos - text_width, ypos, layout);
			arc_angle = atan((gfloat)(centre_x + graph->dependant->scale_factor - xpos)/(gfloat)((centre_y + r * graph->dependant->scale_factor)-ypos)) *180.0 / 3.141592654;
			gdk_draw_arc(buffer, Gridcontext, FALSE, x, centre_y, w, h, 5760, (gint)(arc_angle * 64.0)); // Capacitive Circles
			gdk_draw_arc(buffer, Gridcontext, FALSE, x, centre_y - (gint) ((2 *r) * graph->dependant->scale_factor), w, h, 17280 - (gint) (arc_angle*64.0), (gint) (arc_angle*64.0));	// Inductive Circles
			break;
		case 2:
			g_snprintf(label, 10, "+j%0.f", rxl[i]*graph->smith_Z0);
			pango_layout_set_text(layout, label, -1);
			pango_layout_get_pixel_size(layout, &text_width, &text_height);
			ypos = centre_y - (gint)yend;
			xpos = centre_x - (gint)xend;
			gdk_draw_layout(buffer, BandWcontext, xpos - text_width/2, ypos - text_height, layout);
			g_snprintf(label, 10, "-j%0.f", rxl[i]*graph->smith_Z0);
			pango_layout_set_text(layout, label, -1);
			ypos = centre_y + yend;
			gdk_draw_layout(buffer, BandWcontext, xpos - text_width/2, ypos, layout);
			arc_angle = atan((gfloat)(centre_x + graph->dependant->scale_factor - xpos)/(gfloat)(ypos - (centre_y + r * graph->dependant->scale_factor))) *180.0 / 3.141592654;
			gdk_draw_arc(buffer, Gridcontext, FALSE, x, centre_y, w, h, 5760, (gint) (arc_angle*64.0)); // Capacitive Circles
			gdk_draw_arc(buffer, Gridcontext, FALSE, x, centre_y - (gint) ((2 *r) * graph->dependant->scale_factor), w, h, 17280 - (gint) (arc_angle*64.0), (gint) (arc_angle*64.0));	// Inductive Circles
			break;
		case 3:
		case 4:
			g_snprintf(label, 10, "+j%0.f", rxl[i]*graph->smith_Z0);
			pango_layout_set_text(layout, label, -1);
			pango_layout_get_pixel_size(layout, &text_width, &text_height);
			ypos = centre_y - (gint)yend;
			xpos = centre_x + (gint)xend;
			gdk_draw_layout(buffer, BandWcontext, xpos, ypos - text_height, layout);
			g_snprintf(label, 10, "-j%0.f", rxl[i]*graph->smith_Z0);
			pango_layout_set_text(layout, label, -1);
			ypos = centre_y + (gint)yend;
			gdk_draw_layout(buffer, BandWcontext, xpos, ypos, layout);
			arc_angle = atan((gfloat)(centre_x + graph->dependant->scale_factor - xpos)/(gfloat)(ypos - (centre_y + r * graph->dependant->scale_factor))) *180.0 / 3.141592654;
			gdk_draw_arc(buffer, Gridcontext, FALSE, x, centre_y, w, h, 5760, 11520 - (gint) (arc_angle*64.0)); // Capacitive Circles
			gdk_draw_arc(buffer, Gridcontext, FALSE, x, centre_y - (gint) ((2 *r) * graph->dependant->scale_factor), w, h, 5760 + (gint) (arc_angle*64.0), 11520 - (gint) (arc_angle*64.0));	// Inductive Circles
			break;
		}
	}
	
/* Draw the Real Axis */	
gdk_draw_line(buffer, Gridcontext, centre_x - user_width/2, centre_y, centre_x + user_width/2, centre_y);	
g_snprintf(label, 10, "+inf");
pango_layout_set_text(layout, label, -1);
pango_layout_get_pixel_size(layout, &text_width, &text_height);
xpos = centre_x + user_width/2.0 - text_width/2 ;
ypos = centre_y ;
gdk_draw_layout(buffer, BandWcontext, xpos, ypos, layout);
	
pango_font_description_free(fontdesc);
g_object_unref(layout);	
}
Beispiel #27
0
static void
gtk_databox_marker_real_draw (GtkDataboxGraph *graph,
                             GtkDataboxCanvas *canvas)
{
   GtkDataboxMarker *marker = GTK_DATABOX_MARKER (graph);
   GdkPoint points [3];
   gfloat *X;
   gfloat *Y;
   gint len;
   gint16 x;
   gint16 y;
   GtkDataboxCoord coord;
   gint size;
   gint i;
 
   g_return_if_fail (GTK_DATABOX_IS_MARKER (marker));
   g_return_if_fail (canvas);
   g_return_if_fail (canvas->pixmap);
   g_return_if_fail (canvas->context);

   if (!graph->gc) 
      gtk_databox_graph_create_gc (graph, canvas);

   len = gtk_databox_xyc_graph_get_length (GTK_DATABOX_XYC_GRAPH (graph));
   X = gtk_databox_xyc_graph_get_X (GTK_DATABOX_XYC_GRAPH (graph));
   Y = gtk_databox_xyc_graph_get_Y (GTK_DATABOX_XYC_GRAPH (graph));
   size = gtk_databox_graph_get_size (graph);

   for (i = 0; i < len; ++i)
   {
      x = (gint16) ((X[i] - canvas->top_left_visible.x) 
            * canvas->translation_factor.x);
      y = (gint16) ((Y[i] - canvas->top_left_visible.y) 
            * canvas->translation_factor.y);
      
      switch (marker->priv->type)
      {
         case GTK_DATABOX_MARKER_TRIANGLE:
            switch (marker->priv->marker_info[i].position) 
            {
               case GTK_DATABOX_MARKER_C:
                  coord.x = x;
                  coord.y = y;
                  y = y - size / 2;
                  points[0].x = x;
                  points[0].y = y;
                  points[1].x = x - size / 2;
                  points[1].y = y + size;
                  points[2].x = x + size / 2;
                  points[2].y = y + size;
                  break;
               case GTK_DATABOX_MARKER_N:
                  coord.x = x;
                  coord.y = y - 2 - size / 2;
                  y = y - 2;
                  points[0].x = x;
                  points[0].y = y;
                  points[1].x = x - size / 2;
                  points[1].y = y - size;
                  points[2].x = x + size / 2;
                  points[2].y = y - size;
                  break;
               case GTK_DATABOX_MARKER_E:
                  coord.x = x + 2 + size / 2;
                  coord.y = y;
                  x = x + 2;
                  points[0].x = x;
                  points[0].y = y;
                  points[1].x = x + size;
                  points[1].y = y + size / 2;
                  points[2].x = x + size;
                  points[2].y = y - size / 2;
                  break;
               case GTK_DATABOX_MARKER_S:
                  coord.x = x;
                  coord.y = y + 2 + size / 2;
                  y = y + 2;
                  points[0].x = x;
                  points[0].y = y;
                  points[1].x = x - size / 2;
                  points[1].y = y + size;
                  points[2].x = x + size / 2;
                  points[2].y = y + size;
                  break;
               case GTK_DATABOX_MARKER_W:
                  coord.x = x - 2 - size / 2;
                  coord.y = y;
                  x = x - 2;
                  points[0].x = x;
                  points[0].y = y;
                  points[1].x = x - size;
                  points[1].y = y + size / 2;
                  points[2].x = x - size;
                  points[2].y = y - size / 2;
                  break;
            }
            gdk_draw_polygon (canvas->pixmap, graph->gc, 
                              TRUE, points, 3);
            break;
            /* End of GTK_DATABOX_MARKER_TRIANGLE */
         case GTK_DATABOX_MARKER_SOLID_LINE:
         case GTK_DATABOX_MARKER_DASHED_LINE:
            switch (marker->priv->marker_info[i].position) 
            {
               case GTK_DATABOX_MARKER_C:
                  coord.x = x;
                  coord.y = y;
                  points[0].x = x;
                  points[0].y = 0;
                  points[1].x = x;
                  points[1].y = canvas->height;
                  break;
               case GTK_DATABOX_MARKER_N:
                  coord.x = x;
                  points[0].x = x;
                  points[0].y = 0;
                  points[1].x = x;
                  points[1].y = canvas->height;
                  break;
               case GTK_DATABOX_MARKER_E:
                  coord.y = y;
                  points[0].x = 0;
                  points[0].y = y;
                  points[1].x = canvas->width;
                  points[1].y = y;
                  break;
               case GTK_DATABOX_MARKER_S:
                  coord.x = x;
                  points[0].x = x;
                  points[0].y = 0;
                  points[1].x = x;
                  points[1].y = canvas->height;
                  break;
               case GTK_DATABOX_MARKER_W:
                  coord.y = y;
                  points[0].x = 0;
                  points[0].y = y;
                  points[1].x = canvas->width;
                  points[1].y = y;
                  break;
            }

            gdk_draw_line (canvas->pixmap, graph->gc,
                           points[0].x, points[0].y,
                           points[1].x, points[1].y);
            break;
            /* End of GTK_DATABOX_MARKER_LINE */

         case GTK_DATABOX_MARKER_NONE:
         default:
            coord.x = x;
            coord.y = y;
            break;
      }

      if (marker->priv->marker_info[i].text)
      {
         if (!marker->priv->marker_info[i].label)
         {
            marker->priv->marker_info[i].label = 
               pango_layout_new (canvas->context);
            pango_layout_set_text (marker->priv->marker_info[i].label, 
                                   marker->priv->marker_info[i].text, 
                                   -1);
         }

         if (marker->priv->type == GTK_DATABOX_MARKER_SOLID_LINE
               || marker->priv->type == GTK_DATABOX_MARKER_DASHED_LINE)
         {
            gint width;
            gint height;
            pango_layout_get_pixel_size (marker->priv->marker_info[i].label, 
                                         &width, &height);

            width = (width + 1) / 2 + 2;
            height = (height + 1) / 2 + 2;
            size = 0;

            switch (marker->priv->marker_info[i].position)
            {
               case GTK_DATABOX_MARKER_C:
               break;
               case GTK_DATABOX_MARKER_N:
                  coord.y = height;
               break;
               case GTK_DATABOX_MARKER_E:
                  coord.x = canvas->width - width;
               break;
               case GTK_DATABOX_MARKER_S:
                  coord.y = canvas->height - height;
               break;
               case GTK_DATABOX_MARKER_W:
                  coord.x = width;
               break;
            }
         }
         
         gtk_databox_label_write_at (canvas->pixmap, 
                                    marker->priv->marker_info[i].label, 
                                    marker->priv->label_gc, coord,
                                    marker->priv->marker_info[i].label_position,
                                    (size + 1) / 2 + 2,
                                    marker->priv->marker_info[i].boxed);
      }
   }
      
   return;
}
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);
}
Beispiel #29
0
/** Draw a TextLine object.
 * @param object The renderer object to use for transform and output
 * @param text_line The TextLine to render, including font and height.
 * @param pos The position to render it at.
 * @param color The color to render it with.
 */
static void 
draw_text_line (DiaRenderer *object, TextLine *text_line,
		Point *pos, Alignment alignment, Color *color)
{
  DiaGdkRenderer *renderer = DIA_GDK_RENDERER (object);
  GdkColor gdkcolor;
  int x,y;
  Point start_pos;
  PangoLayout* layout = NULL;
  const gchar *text = text_line_get_string(text_line);
  int height_pixels;
  real font_height = text_line_get_height(text_line);
  real scale = dia_transform_length(renderer->transform, 1.0);

  if (text == NULL || *text == '\0') return; /* Don't render empty strings. */

  point_copy(&start_pos,pos);

  renderer_color_convert(renderer, color, &gdkcolor);
 
  height_pixels = dia_transform_length(renderer->transform, font_height);
  if (height_pixels < 2) { /* "Greeking" instead of making tiny font */
    int width_pixels = dia_transform_length(renderer->transform,
					    text_line_get_width(text_line));
    gdk_gc_set_foreground(renderer->gc, &gdkcolor);
    gdk_gc_set_dashes(renderer->gc, 0, (gint8*)"\1\2", 2);
    dia_transform_coords(renderer->transform, start_pos.x, start_pos.y, &x, &y);
    gdk_draw_line(renderer->pixmap, renderer->gc, x, y, x + width_pixels, y);
    return;
  } else {
    start_pos.y -= text_line_get_ascent(text_line);
    start_pos.x -= text_line_get_alignment_adjustment (text_line, alignment);
  
    dia_transform_coords(renderer->transform, 
			 start_pos.x, start_pos.y, &x, &y);

    layout = dia_font_build_layout(text, text_line->font,
				   dia_transform_length(renderer->transform, text_line->height)/20.0);
#if defined(PANGO_VERSION_ENCODE)
#  if (PANGO_VERSION >= PANGO_VERSION_ENCODE(1,16,0))
    /* I'd say the former Pango API was broken, i.e. leaky */
#    define HAVE_pango_layout_get_line_readonly
#   endif
#endif
    text_line_adjust_layout_line (text_line, 
#if defined(HAVE_pango_layout_get_line_readonly)
                                  pango_layout_get_line_readonly(layout, 0),
#else
                                  pango_layout_get_line(layout, 0),
#endif
				  scale/20.0);

    if (renderer->highlight_color != NULL) {
      draw_highlighted_string(renderer, layout, x, y, &gdkcolor);
    } else {
#if defined HAVE_FREETYPE
      {
	FT_Bitmap ftbitmap;
	int width, height;
	GdkPixbuf *rgba = NULL;
	
	width = dia_transform_length(renderer->transform,
				     text_line_get_width(text_line));
	height = dia_transform_length(renderer->transform, 
				      text_line_get_height(text_line));
	
	if (width > 0) {
	  int stride;
	  guchar* pixels;
	  int i,j;
	  guint8 *graybitmap;

	  initialize_ft_bitmap(&ftbitmap, width, height);
	  pango_ft2_render_layout(&ftbitmap, layout, 0, 0);
	  
	  graybitmap = ftbitmap.buffer;
	  
	  rgba = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, width, height);
	  stride = gdk_pixbuf_get_rowstride(rgba);
	  pixels = gdk_pixbuf_get_pixels(rgba);
	  for (i = 0; i < height; i++) {
	    for (j = 0; j < width; j++) {
	      pixels[i*stride+j*4] = gdkcolor.red>>8;
	      pixels[i*stride+j*4+1] = gdkcolor.green>>8;
	      pixels[i*stride+j*4+2] = gdkcolor.blue>>8;
	      pixels[i*stride+j*4+3] = graybitmap[i*ftbitmap.pitch+j];
	    }
	  }
	  g_free(graybitmap);

	  gdk_draw_pixbuf(renderer->pixmap, renderer->gc, rgba, 0, 0, x, y, width, height, GDK_RGB_DITHER_NONE, 0, 0);

	  g_object_unref(G_OBJECT(rgba));
	}
      }
#else
      gdk_gc_set_foreground(renderer->gc, &gdkcolor);
	
      gdk_draw_layout(renderer->pixmap, renderer->gc, x, y, layout);
#endif
    } /* !higlight_color */
    g_object_unref(G_OBJECT(layout));
  } /* !greeking */
Beispiel #30
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);
    }
}