00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 #include <stdlib.h>
00036 #include <gtk/gtk.h>
00037
00038 #include "ink_draw.h"
00039 #include "ScribbleLog.h"
00040 #include "ScribbleUtils.h"
00041
00042
00043 static GdkDrawable *pCurrDrawable=NULL;
00044 static GdkGC *pCurrGDKGC=NULL;
00045
00046 int ink_setDrawable(GdkDrawable *pDrawable)
00047 {
00048
00049 if(pCurrDrawable==pDrawable) return 0;
00050
00051 pCurrDrawable=pDrawable;
00052
00053 if(pCurrGDKGC)
00054 g_object_unref(pCurrGDKGC);
00055
00056 pCurrGDKGC=gdk_gc_new(pDrawable);
00057 if(NULL==pCurrGDKGC)
00058 {
00059 SB_INKERRPRINTF("error when create GDKGC\n");
00060 return -1;
00061 }
00062 SB_INKPRINTF("create gdk gc successfully\n");
00063 return 0;
00064 }
00065
00066 static int iLastPenSize=-1;
00067
00068 gboolean setPenSizeAtrr(int iPenSize)
00069 {
00070 if(iLastPenSize != iPenSize)
00071 {
00072 gdk_gc_set_line_attributes(pCurrGDKGC,
00073 iPenSize,
00074 GDK_LINE_SOLID,
00075 GDK_CAP_PROJECTING,
00076 GDK_JOIN_MITER);
00077 iLastPenSize=iPenSize;
00078 }
00079 return TRUE;
00080 }
00081
00082 static int iLastHwColor=-1;
00083
00084 gboolean setPenColorAttr(GdkColor* pGdkColor)
00085 {
00086 HW_COLOR iColor=Util_HWCOLORFromGdkColor(pGdkColor);
00087 if(iLastHwColor != iColor)
00088 {
00089 gdk_gc_set_rgb_fg_color(pCurrGDKGC,pGdkColor);
00090 iLastHwColor=iColor;
00091 }
00092 return TRUE;
00093 }
00094
00095 void ink_draw_line (int x0, int y0, int x1, int y1)
00096 {
00097 GdkPoint points[2];
00098 points[0].x=(gint)x0;
00099 points[0].y=(gint)y0;
00100 points[1].x=(gint)x1;
00101 points[1].y=(gint)y1;
00102 gdk_draw_lines(pCurrDrawable,pCurrGDKGC,points,2);
00103 }
00104
00105
00106 void draw_ink (PtrInk ink)
00107 {
00108 int nStrokes;
00109 PtrStroke stroke = NULL;
00110 if (ink == NULL)
00111 return;
00112
00113 stroke = ink->firstStroke;
00114 nStrokes = get_num_of_strokes (ink);
00115 SB_INKPRINTF("nStrokes=%d\n", nStrokes);
00116 if (stroke == NULL || nStrokes <= 0)
00117 {
00118 return;
00119 }
00120
00121 while (stroke)
00122 {
00123 draw_stroke (stroke);
00124 stroke = stroke->nextStroke;
00125 }
00126 }
00127
00128
00129 void draw_stroke (PtrStroke stroke)
00130 {
00131 PtrInkPoint point = NULL;
00132 int nPoints;
00133 if (stroke == NULL)
00134 return;
00135
00136 point = stroke->firstPoint;
00137 nPoints = get_num_of_points (stroke);
00138 if (point == NULL || nPoints <= 0)
00139 return;
00140
00141
00142 setPenSizeAtrr(stroke->iPenSize);
00143
00144 setPenColorAttr(&stroke->gdkColor);
00145
00146 SB_INKPRINTF("(nPoints=%d)\n", nPoints);
00147
00148 if ( 1==nPoints )
00149 {
00150 ink_draw_line(point->x, point->y,point->x, point->y);
00151 return;
00152 }
00153
00154 while (point->nextPoint)
00155 {
00156 ink_draw_line(point->x, point->y,
00157 point->nextPoint->x,point->nextPoint->y);
00158 point = point->nextPoint;
00159 }
00160 }