notepad::GCtx Class Reference

#include <notepad_utils.h>

Public Member Functions

 GCtx ()
 ~GCtx ()
void set_color (const ScbDevColor c)
void set_line_attributes (const int width)
 Change the X11 gc to use new line attributes. Currently, only change the width. Always use LineSolid.
void draw_line (GdkImage *image, const int x1, const int y1, const int x2, const int y2)
 Draw line on image by using current line color, line width and line style.
void draw_line (GdkImage *image, const ScbPoint &p1, const ScbPoint &p2)
void draw_brush (GdkImage *image, const int x, const int y)
void draw_points (GdkImage *image, const GdkPoint *shape, const int npoints_in_shape)

Data Fields

GdkGC * gc
 X11 graphics context.
np_rotation rotation
 rotation
int width
 width, max y when in landscape, max x otherwise
int height
 height, max x when in landscape, max y otherwise
int margin
 border

Detailed Description

Definition at line 67 of file notepad_utils.h.


Constructor & Destructor Documentation

notepad::GCtx::GCtx (  )  [inline]

Definition at line 80 of file notepad_utils.h.

00081                 : size(0)
00082                 , gc(0)
00083                 , rotation(NP_PORTRAIT)
00084                 , width(0)
00085                 , height(0)
00086                 , margin(0)
00087             {
00088             }

notepad::GCtx::~GCtx (  )  [inline]

Definition at line 90 of file notepad_utils.h.

References gc.

00091             {
00092                 if (gc) { g_object_unref(gc); gc = 0; } 
00093             }


Member Function Documentation

void notepad::GCtx::draw_brush ( GdkImage *  image,
const int  x,
const int  y 
)

Definition at line 170 of file notepad_utils.cpp.

References draw_points().

Referenced by draw_line().

00171     {
00172         g_assert(image != 0);
00173         // draw a brush of size: this->size
00174         // at coordinate (x,y)
00175         gint npoints_in_shape = 0;
00176 
00177         // portrait only for now
00178         GdkPoint brush1[1]  = { {x,  y  } };
00179         GdkPoint brush2[4]  = { 
00180                                 {x-1,y  } , {x  ,y  } , 
00181                                 {x-1,y+1} , {x  ,y+1} 
00182                               };
00183 
00184         GdkPoint brush3[5]  = { 
00185                                             {x  ,y-1} , 
00186                                 {x-1,y  } , {x  ,y  } , {x+1,y  } , 
00187                                             {x  ,y+1} 
00188                               };
00189 
00190         GdkPoint brush4[12] = { 
00191                                             {x-1,y-1} , {x  ,y-1} , 
00192                                 {x-2,y  } , {x-1,y  } , {x  ,y  } , {x+1,y  }, 
00193                                 {x-2,y+1} , {x-1,y+1} , {x  ,y+1} , {x+1,y+1}, 
00194                                             {x-1,y+2} , {x  ,y+2} 
00195                               };
00196 
00197         GdkPoint brush5[13] = { 
00198                                                         {x  ,y-2} , 
00199                                             {x-1,y-1} , {x  ,y-1} , {x+1,y-1} , 
00200                                 {x-2,y  } , {x-1,y  } , {x  ,y  } , {x+1,y  } , {x+2,y} ,
00201                                             {x-1,y+1} , {x  ,y+1} , {x+1,y+1} ,       
00202                                                         {x  ,y+2} 
00203                               };
00204 
00205         GdkPoint* shape = NULL;
00206 
00207         switch(size)
00208         {
00209             case 1:
00210                 npoints_in_shape = 1;
00211                 shape = brush1;
00212                 break;
00213             case 2:
00214                 npoints_in_shape = 4;
00215                 shape = brush2;
00216                 break;
00217             case 3:
00218                 npoints_in_shape = 5;
00219                 shape = brush3;
00220                 break;
00221             case 4:
00222                 npoints_in_shape = 12;
00223                 shape = brush4;
00224                 break;
00225             case 5:
00226                 npoints_in_shape = 13;
00227                 shape = brush5;
00228                 break;
00229             default:
00230                 npoints_in_shape = 13;
00231                 break;
00232 
00233         }
00234         draw_points(image, shape, npoints_in_shape);
00235     }

Here is the call graph for this function:

Here is the caller graph for this function:

void notepad::GCtx::draw_line ( GdkImage *  image,
const ScbPoint p1,
const ScbPoint p2 
) [inline]

Definition at line 121 of file notepad_utils.h.

References draw_line(), _ScbPoint::x, and _ScbPoint::y.

00122             {
00123                 draw_line(image, p1.x, p1.y, p2.x, p2.y);
00124             }

Here is the call graph for this function:

void notepad::GCtx::draw_line ( GdkImage *  image,
const int  x1,
const int  y1,
const int  x2,
const int  y2 
)

Draw line on image by using current line color, line width and line style.

Definition at line 63 of file notepad_utils.cpp.

References draw_brush(), test::swap(), notepad::Point::x, and notepad::Point::y.

Referenced by draw_line().

00064     {
00065         g_assert(image != 0);
00066 
00067         Point p1(x1, y1);
00068         Point p2(x2, y2);
00069 
00070         // draw the end point
00071         draw_brush(image, p2.x, p2.y);
00072 
00073         bool is_steep = abs(p2.y - p1.y) > abs(p2.x - p1.x);
00074         if (is_steep)
00075         {
00076             std::swap(p1.x, p1.y);
00077             std::swap(p2.x, p2.y);
00078         }
00079 
00080         // setup line draw
00081         int deltax   = abs(p2.x - p1.x);
00082         int deltaerr = abs(p2.y - p1.y);
00083         int error = 0;
00084         int x = p1.x;
00085         int y = p1.y;
00086 
00087         // setup step increment
00088         int xstep = (p1.x < p2.x) ? 1 : -1;
00089         int ystep = (p1.y < p2.y) ? 1 : -1;
00090 
00091         if (is_steep)
00092         {
00093             // draw swapped line
00094             for (int numpix = 0; numpix < deltax; numpix++)
00095             {
00096                 x += xstep;
00097                 error += deltaerr;
00098 
00099                 if (2 * error > deltax) 
00100                 {
00101                     y += ystep;
00102                     error -= deltax;
00103                 }
00104 
00105                 draw_brush(image, y, x);
00106             }
00107         }
00108         else
00109         {
00110             // draw normal line
00111             for (int numpix = 0; numpix < deltax; numpix++)
00112             {
00113                 x += xstep;
00114                 error += deltaerr;
00115 
00116                 if (2 * error > deltax) 
00117                 {
00118                     y += ystep;
00119                     error -= deltax;
00120                 }
00121 
00122                 draw_brush(image, x, y);
00123             }
00124         }
00125 
00126     }

Here is the call graph for this function:

Here is the caller graph for this function:

void notepad::GCtx::draw_points ( GdkImage *  image,
const GdkPoint *  shape,
const int  npoints_in_shape 
)

Definition at line 237 of file notepad_utils.cpp.

References margin.

Referenced by draw_brush().

00238     {
00239         g_assert(image != 0);
00240         g_assert(shape != 0);
00241         g_assert(npoints_in_shape > 0);
00242 
00243 #if MACHINE_IS_DR1000S || MACHINE_IS_DR1000SW
00244         gint w = image->width;
00245 #endif
00246 #if MACHINE_IS_DR800S || MACHINE_IS_DR800SG || MACHINE_IS_DR800SW
00247         gint w = image->width - margin;
00248 #endif
00249         gint h = image->height;
00250 
00251         for (int i = 0; i < npoints_in_shape; i++)
00252         {
00253             // filter part of brush out of region
00254             if (  (shape[i].x > margin && shape[i].x < w) 
00255                && (shape[i].y > margin && shape[i].y < h) )
00256             {
00257                 gdk_image_put_pixel(image, shape[i].x, shape[i].y, color);
00258             }
00259         }
00260     }

Here is the caller graph for this function:

void notepad::GCtx::set_color ( const ScbDevColor  c  ) 

Definition at line 38 of file notepad_utils.cpp.

References ERSCRIBBLE_DEV_COLOR_BLACK, ERSCRIBBLE_DEV_COLOR_DARK_GRAY, ERSCRIBBLE_DEV_COLOR_LIGHT_GRAY, ERSCRIBBLE_DEV_COLOR_UNKNOWN, and ERSCRIBBLE_DEV_COLOR_WHITE.

00039     {
00040         // assume 8 bit depth: 0x00 00 00 .. 0xFF FF FF
00041         switch (scribblecolor)
00042         {
00043             case ERSCRIBBLE_DEV_COLOR_WHITE:
00044                 color = 0xFFFFFF;
00045                 break;
00046             case ERSCRIBBLE_DEV_COLOR_LIGHT_GRAY:
00047                 color = 0xAAAAAA;
00048                 break;
00049             case ERSCRIBBLE_DEV_COLOR_DARK_GRAY:
00050                 color = 0x888888; // or 55
00051                 break;
00052             case ERSCRIBBLE_DEV_COLOR_BLACK:
00053                 color = 0x000000;
00054                 break;
00055             case ERSCRIBBLE_DEV_COLOR_UNKNOWN:
00056             default:
00057                 color = 0x000000;
00058                 break;
00059         }
00060     }

void notepad::GCtx::set_line_attributes ( const int  width  )  [inline]

Change the X11 gc to use new line attributes. Currently, only change the width. Always use LineSolid.

Definition at line 106 of file notepad_utils.h.

References gc.

00107             {
00108                 this->size = width ;
00109 
00110                 gdk_gc_set_line_attributes(gc
00111                         , this->size
00112                         , GDK_LINE_SOLID
00113                         , GDK_CAP_PROJECTING
00114                         , GDK_JOIN_MITER);
00115             }


Field Documentation

height, max x when in landscape, max y otherwise

Definition at line 77 of file notepad_utils.h.

Referenced by notepad::CNotepadWindow::save(), and notepad::CNotepadWindow::set_rotation().

rotation

Definition at line 75 of file notepad_utils.h.

Referenced by notepad::CNotepadWindow::set_rotation().

width, max y when in landscape, max x otherwise

Definition at line 76 of file notepad_utils.h.

Referenced by notepad::CNotepadWindow::save(), and notepad::CNotepadWindow::set_rotation().


The documentation for this class was generated from the following files:
Generated by  doxygen 1.6.2-20100208