⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gdkdrawable-win32.c

📁 linux下电话本所依赖的一些图形库
💻 C
📖 第 1 页 / 共 4 页
字号:
  generic_draw (drawable, gc,		GDK_GC_FOREGROUND | (filled ? 0 : LINE_ATTRIBUTES),		draw_arc, region, filled, x, y, width, height, angle1, angle2);  gdk_region_destroy (region);}static voiddraw_polygon (GdkGCWin32 *gcwin32,	      HDC         hdc,	      gint        x_offset,	      gint        y_offset,	      va_list     args){  gboolean filled;  POINT *pts;  HPEN old_pen;  gint npoints;  gint i;  filled = va_arg (args, gboolean);  pts = va_arg (args, POINT *);  npoints = va_arg (args, gint);  if (x_offset != 0 || y_offset != 0)    for (i = 0; i < npoints; i++)      {	pts[i].x -= x_offset;	pts[i].y -= y_offset;      }  if (filled)    {      old_pen = SelectObject (hdc, GetStockObject (NULL_PEN));      if (old_pen == NULL)	WIN32_GDI_FAILED ("SelectObject");      GDI_CALL (Polygon, (hdc, pts, npoints));      if (old_pen != NULL)	GDI_CALL (SelectObject, (hdc, old_pen));    }  else    GDI_CALL (Polyline, (hdc, pts, npoints));}static voidgdk_win32_draw_polygon (GdkDrawable *drawable,			GdkGC       *gc,			gboolean     filled,			GdkPoint    *points,			gint         npoints){  GdkRectangle bounds;  GdkRegion *region;  POINT *pts;  int i;  GDK_NOTE (MISC, g_print ("gdk_win32_draw_polygon: %s %d points\n",			   _gdk_win32_drawable_description (drawable),			   npoints));  if (npoints < 2)    return;  bounds.x = G_MAXINT;  bounds.y = G_MAXINT;  bounds.width = 0;  bounds.height = 0;  pts = g_new (POINT, npoints+1);  for (i = 0; i < npoints; i++)    {      bounds.x = MIN (bounds.x, points[i].x);      bounds.y = MIN (bounds.y, points[i].y);      pts[i].x = points[i].x;      pts[i].y = points[i].y;    }  for (i = 0; i < npoints; i++)    {      bounds.width = MAX (bounds.width, points[i].x - bounds.x);      bounds.height = MAX (bounds.height, points[i].y - bounds.y);    }  if (points[0].x != points[npoints-1].x ||      points[0].y != points[npoints-1].y)     {      pts[npoints].x = points[0].x;      pts[npoints].y = points[0].y;      npoints++;    }        region = widen_bounds (&bounds, GDK_GC_WIN32 (gc)->pen_width);  generic_draw (drawable, gc,		GDK_GC_FOREGROUND | (filled ? 0 : LINE_ATTRIBUTES),		draw_polygon, region, filled, pts, npoints);  gdk_region_destroy (region);  g_free (pts);}typedef struct{  gint x, y;  HDC hdc;} gdk_draw_text_arg;static voidgdk_draw_text_handler (GdkWin32SingleFont *singlefont,		       const wchar_t      *wcstr,		       int                 wclen,		       void               *arg){  HGDIOBJ oldfont;  SIZE size;  gdk_draw_text_arg *argp = (gdk_draw_text_arg *) arg;  if (!singlefont)    return;  if ((oldfont = SelectObject (argp->hdc, singlefont->hfont)) == NULL)    {      WIN32_GDI_FAILED ("SelectObject");      return;    }    if (!TextOutW (argp->hdc, argp->x, argp->y, wcstr, wclen))    WIN32_GDI_FAILED ("TextOutW");  GetTextExtentPoint32W (argp->hdc, wcstr, wclen, &size);  argp->x += size.cx;  SelectObject (argp->hdc, oldfont);}static voidgdk_win32_draw_text (GdkDrawable *drawable,		     GdkFont     *font,		     GdkGC       *gc,		     gint         x,		     gint         y,		     const gchar *text,		     gint         text_length){  const GdkGCValuesMask mask = GDK_GC_FOREGROUND|GDK_GC_FONT;  wchar_t *wcstr, wc;  glong wlen;  gdk_draw_text_arg arg;  if (text_length == 0)    return;  g_assert (font->type == GDK_FONT_FONT || font->type == GDK_FONT_FONTSET);  arg.x = x;  arg.y = y;  arg.hdc = gdk_win32_hdc_get (drawable, gc, mask);  GDK_NOTE (MISC, g_print ("gdk_win32_draw_text: %s (%d,%d) \"%.*s\" (len %d)\n",			   _gdk_win32_drawable_description (drawable),			   x, y,			   (text_length > 10 ? 10 : text_length),			   text, text_length));    if (text_length == 1)    {      /* For single characters, don't try to interpret as UTF-8. */      wc = (guchar) text[0];      _gdk_wchar_text_handle (font, &wc, 1, gdk_draw_text_handler, &arg);    }  else    {      wcstr = g_utf8_to_utf16 (text, text_length, NULL, &wlen, NULL);      _gdk_wchar_text_handle (font, wcstr, wlen, gdk_draw_text_handler, &arg);      g_free (wcstr);    }  gdk_win32_hdc_release (drawable, gc, mask);}static voidgdk_win32_draw_text_wc (GdkDrawable	 *drawable,			GdkFont          *font,			GdkGC		 *gc,			gint		  x,			gint		  y,			const GdkWChar *text,			gint		  text_length){  const GdkGCValuesMask mask = GDK_GC_FOREGROUND|GDK_GC_FONT;  gint i;  wchar_t *wcstr;  gdk_draw_text_arg arg;  if (text_length == 0)    return;  g_assert (font->type == GDK_FONT_FONT || font->type == GDK_FONT_FONTSET);  arg.x = x;  arg.y = y;  arg.hdc = gdk_win32_hdc_get (drawable, gc, mask);  GDK_NOTE (MISC, g_print ("gdk_win32_draw_text_wc: %s (%d,%d) len: %d\n",			   _gdk_win32_drawable_description (drawable),			   x, y, text_length));        if (sizeof (wchar_t) != sizeof (GdkWChar))    {      wcstr = g_new (wchar_t, text_length);      for (i = 0; i < text_length; i++)	wcstr[i] = text[i];    }  else    wcstr = (wchar_t *) text;  _gdk_wchar_text_handle (font, wcstr, text_length,			 gdk_draw_text_handler, &arg);  if (sizeof (wchar_t) != sizeof (GdkWChar))    g_free (wcstr);  gdk_win32_hdc_release (drawable, gc, mask);}static voidgdk_win32_draw_drawable (GdkDrawable *drawable,			 GdkGC       *gc,			 GdkPixmap   *src,			 gint         xsrc,			 gint         ysrc,			 gint         xdest,			 gint         ydest,			 gint         width,			 gint         height){  g_assert (GDK_IS_DRAWABLE_IMPL_WIN32 (drawable));  _gdk_win32_blit (FALSE, (GdkDrawableImplWin32 *) drawable,		   gc, src, xsrc, ysrc,		   xdest, ydest, width, height);}static voidgdk_win32_draw_points (GdkDrawable *drawable,		       GdkGC       *gc,		       GdkPoint    *points,		       gint         npoints){  HDC hdc;  HGDIOBJ old_pen;  int i;  hdc = gdk_win32_hdc_get (drawable, gc, GDK_GC_FOREGROUND);    GDK_NOTE (MISC, g_print ("gdk_win32_draw_points: %s %d points\n",			   _gdk_win32_drawable_description (drawable),			   npoints));  /* The X11 version uses XDrawPoint(), which doesn't use the fill   * mode, so don't use generic_draw. But we should use the current   * function, so we can't use SetPixel(). Draw single-pixel   * rectangles (sigh).   */  old_pen = SelectObject (hdc, GetStockObject (NULL_PEN));  for (i = 0; i < npoints; i++)    Rectangle (hdc, points[i].x, points[i].y,	       points[i].x + 2, points[i].y + 2);  SelectObject (hdc, old_pen);  gdk_win32_hdc_release (drawable, gc, GDK_GC_FOREGROUND);}static voiddraw_segments (GdkGCWin32 *gcwin32,	       HDC         hdc,	       gint        x_offset,	       gint        y_offset,	       va_list     args){  GdkSegment *segs;  gint nsegs;  gint i;  segs = va_arg (args, GdkSegment *);  nsegs = va_arg (args, gint);  if (x_offset != 0 || y_offset != 0)    {      /* must not modify in place, but could splice in the offset all below */      segs = g_memdup (segs, nsegs * sizeof (GdkSegment));      for (i = 0; i < nsegs; i++)        {          segs[i].x1 -= x_offset;          segs[i].y1 -= y_offset;          segs[i].x2 -= x_offset;          segs[i].y2 -= y_offset;        }    }  if (MUST_RENDER_DASHES_MANUALLY (gcwin32))    {      for (i = 0; i < nsegs; i++)	{	  if (segs[i].x1 == segs[i].x2)	    {	      int y1, y2;	      	      if (segs[i].y1 <= segs[i].y2)		y1 = segs[i].y1, y2 = segs[i].y2;	      else		y1 = segs[i].y2, y2 = segs[i].y1;	      	      render_line_vertical (gcwin32, segs[i].x1, y1, y2);	    }	  else if (segs[i].y1 == segs[i].y2)	    {	      int x1, x2;	      	      if (segs[i].x1 <= segs[i].x2)		x1 = segs[i].x1, x2 = segs[i].x2;	      else		x1 = segs[i].x2, x2 = segs[i].x1;	      	      render_line_horizontal (gcwin32, x1, x2, segs[i].y1);	    }	  else	    GDI_CALL (MoveToEx, (hdc, segs[i].x1, segs[i].y1, NULL)) &&	      GDI_CALL (LineTo, (hdc, segs[i].x2, segs[i].y2));	}    }  else    {      for (i = 0; i < nsegs; i++)	{	  const GdkSegment *ps = &segs[i];	  const int x1 = ps->x1, y1 = ps->y1;	  int x2 = ps->x2, y2 = ps->y2;	  GDK_NOTE (MISC, g_print (" +%d+%d..+%d+%d", x1, y1, x2, y2));	  GDI_CALL (MoveToEx, (hdc, x1, y1, NULL)) &&	    GDI_CALL (LineTo, (hdc, x2, y2));	}      GDK_NOTE (MISC, g_print ("\n"));    }  if (x_offset != 0 || y_offset != 0)    g_free (segs);}static voidgdk_win32_draw_segments (GdkDrawable *drawable,			 GdkGC       *gc,			 GdkSegment  *segs,			 gint         nsegs){  GdkRectangle bounds;  GdkRegion *region;  gint i;  GDK_NOTE (MISC, g_print ("gdk_win32_draw_segments: %s %d segs\n",			   _gdk_win32_drawable_description (drawable),			   nsegs));  bounds.x = G_MAXINT;  bounds.y = G_MAXINT;  bounds.width = 0;  bounds.height = 0;  for (i = 0; i < nsegs; i++)    {      bounds.x = MIN (bounds.x, segs[i].x1);      bounds.x = MIN (bounds.x, segs[i].x2);      bounds.y = MIN (bounds.y, segs[i].y1);      bounds.y = MIN (bounds.y, segs[i].y2);    }  for (i = 0; i < nsegs; i++)    {      bounds.width = MAX (bounds.width, segs[i].x1 - bounds.x);      bounds.width = MAX (bounds.width, segs[i].x2 - bounds.x);      bounds.height = MAX (bounds.height, segs[i].y1 - bounds.y);      bounds.height = MAX (bounds.height, segs[i].y2 - bounds.y);    }  region = widen_bounds (&bounds, GDK_GC_WIN32 (gc)->pen_width);  generic_draw (drawable, gc, GDK_GC_FOREGROUND | LINE_ATTRIBUTES,		draw_segments, region, segs, nsegs);  gdk_region_destroy (region);}static voiddraw_lines (GdkGCWin32 *gcwin32,	    HDC         hdc,	    gint        x_offset,	    gint        y_offset,	    va_list     args){  POINT *pts;  gint npoints;  gint i;  pts = va_arg (args, POINT *);  npoints = va_arg (args, gint);  if (x_offset != 0 || y_offset != 0)    for (i = 0; i < npoints; i++)      {	pts[i].x -= x_offset;	pts[i].y -= y_offset;      }    if (MUST_RENDER_DASHES_MANUALLY (gcwin32))    {      for (i = 0; i < npoints - 1; i++)        {	  if (pts[i].x == pts[i+1].x)	    {	      int y1, y2;	      if (pts[i].y > pts[i+1].y)	        y1 = pts[i+1].y, y2 = pts[i].y;	      else	        y1 = pts[i].y, y2 = pts[i+1].y;	      	      render_line_vertical (gcwin32, pts[i].x, y1, y2);	    }	  else if (pts[i].y == pts[i+1].y)	    {	      int x1, x2;	      if (pts[i].x > pts[i+1].x)	        x1 = pts[i+1].x, x2 = pts[i].x;	      else	        x1 = pts[i].x, x2 = pts[i+1].x;	      render_line_horizontal (gcwin32, x1, x2, pts[i].y);	    }	  else	    GDI_CALL (MoveToEx, (hdc, pts[i].x, pts[i].y, NULL)) &&	      GDI_CALL (LineTo, (hdc, pts[i+1].x, pts[i+1].y));	}    }  else    GDI_CALL (Polyline, (hdc, pts, npoints));}static voidgdk_win32_draw_lines (GdkDrawable *drawable,		      GdkGC       *gc,		      GdkPoint    *points,		      gint         npoints){  GdkRectangle bounds;  GdkRegion *region;  POINT *pts;  int i;  GDK_NOTE (MISC, g_print ("gdk_win32_draw_lines: %s %d points\n",			   _gdk_win32_drawable_description (drawable),			   npoints));  if (npoints < 2)    return;  bounds.x = G_MAXINT;  bounds.y = G_MAXINT;  bounds.width = 0;  bounds.height = 0;  pts = g_new (POINT, npoints);  for (i = 0; i < npoints; i++)    {      bounds.x = MIN (bounds.x, points[i].x);      bounds.y = MIN (bounds.y, points[i].y);      pts[i].x = points[i].x;      pts[i].y = points[i].y;    }  for (i = 0; i < npoints; i++)    {      bounds.width = MAX (bounds.width, points[i].x - bounds.x);      bounds.height = MAX (bounds.height, points[i].y - bounds.y);    }  region = widen_bounds (&bounds, GDK_GC_WIN32 (gc)->pen_width);  generic_draw (drawable, gc, GDK_GC_FOREGROUND | GDK_GC_BACKGROUND |			      LINE_ATTRIBUTES,		draw_lines, region, pts, npoints);  gdk_region_destroy (region);  g_free (pts);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -