liberscribble/include/scbstrokes.h File Reference

#include "scbstroke.h"

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  _ScbStrokes

Typedefs

typedef struct _ScbStrokes ScbStrokes
typedef ScbStrokesScbStrokesPtr

Functions

gboolean scb_strokes_new (ScbStrokesPtr ptr)
void scb_strokes_free (ScbStrokesPtr strokes)
void scb_strokes_empty (ScbStrokesPtr strokes)
void scb_strokes_detach (ScbStrokesPtr strokes)
int scb_strokes_get_count (const ScbStrokesPtr strokes)
void scb_strokes_add_stroke (ScbStrokesPtr strokes, ScbStrokePtr stroke)
void scb_strokes_add_strokes (ScbStrokesPtr dst, const ScbStrokesPtr src)
ScbStrokePtr scb_strokes_detach_stroke (ScbStrokesPtr strokes, ScbStrokePtr stroke)
ScbStrokesPtr scb_strokes_point_hit_test (ScbStrokesPtr strokes, ScbDevPointPtr point, const ScbHitTestCtxPtr ctx)
ScbStrokesPtr scb_strokes_line_hit_test (ScbStrokesPtr strokes, ScbDevPointPtr point1, ScbDevPointPtr point2, const ScbHitTestCtxPtr ctx)
void scb_strokes_erase_fast_draw (ScbStrokesPtr strokes)
gboolean scb_strokes_save (ScbStrokesPtr strokes, ScbXmlPtr ptr)
gboolean scb_strokes_load (ScbStrokesPtr strokes, ScbXmlPtr ptr)
void scb_strokes_dump (ScbStrokesPtr strokes)


Typedef Documentation

typedef struct _ScbStrokes ScbStrokes

Copyright (C) 2005-2008 iRex Technologies B.V. All rights reserved.

Definition at line 36 of file scbstrokes.h.


Function Documentation

void scb_strokes_add_stroke ( ScbStrokesPtr  strokes,
ScbStrokePtr  stroke 
)

Definition at line 112 of file scbstrokes.c.

00114 {
00115     SCB_RET_IF(NULL == strokes || NULL == stroke, "Invalid storkes or stroke pointer!");
00116     g_list_append(strokes->strokes, stroke);
00117 }

void scb_strokes_add_strokes ( ScbStrokesPtr  dst,
const ScbStrokesPtr  src 
)

Definition at line 119 of file scbstrokes.c.

00121 {
00122     SCB_RET_IF(NULL == dst || NULL == src, "Invalid pointer(s)!");
00123     g_list_concat(dst->strokes, src->strokes);
00124 }

void scb_strokes_detach ( ScbStrokesPtr  strokes  ) 

Definition at line 100 of file scbstrokes.c.

00101 {
00102     if (strokes)
00103     {
00104         g_list_free(strokes->strokes);
00105         strokes->strokes = NULL;
00106     }
00107     // NULL strokes pointer is not an error here. 
00108 }

ScbStrokePtr scb_strokes_detach_stroke ( ScbStrokesPtr  strokes,
ScbStrokePtr  stroke 
)

Definition at line 129 of file scbstrokes.c.

00131 {
00132     SCB_RET_NULL_IF(NULL == strokes || NULL == stroke, "Invalid pointer!");
00133     g_list_remove(strokes->strokes, stroke);                   
00134     return stroke;
00135 }

void scb_strokes_dump ( ScbStrokesPtr  strokes  ) 

Definition at line 292 of file scbstrokes.c.

00293 {
00294     if (strokes)
00295     {
00296         g_list_foreach(strokes->strokes, _stroke_dump, 0);
00297     }
00298 }

Here is the call graph for this function:

void scb_strokes_empty ( ScbStrokesPtr  strokes  ) 

Definition at line 72 of file scbstrokes.c.

00073 {
00074     SCB_RET_IF(NULL == strokes, "Attempt to release NULL pointer!");
00075         
00076     g_list_foreach(strokes->strokes, _stroke_release, NULL);
00077     // free and allocate again? I can not find list release function
00078     // maybe we always free the first element unti list is empty
00079     g_list_free(strokes->strokes);
00080     strokes->strokes = g_list_alloc();
00081 }

Here is the call graph for this function:

void scb_strokes_erase_fast_draw ( ScbStrokesPtr  strokes  ) 

Definition at line 208 of file scbstrokes.c.

00209 {
00210     if (NULL == strokes)
00211     {
00212         return;
00213     }
00214 
00215     GList *ptr = g_list_first(strokes->strokes);
00216     ScbStrokePtr stroke = NULL;
00217     while (ptr)
00218     {
00219         stroke = ptr->data;
00220         if (stroke)
00221         {
00222             ScbDevColor old = stroke->style.color;
00223             // use reverse color
00224             stroke->style.color = SCB_DEV_COLOR_WHITE;
00225             scb_stroke_fast_draw(stroke);
00226             stroke->style.color = old;
00227         }
00228         ptr = g_list_next(ptr);
00229     }
00230 }

Here is the call graph for this function:

void scb_strokes_free ( ScbStrokesPtr  strokes  ) 

Definition at line 59 of file scbstrokes.c.

00060 {
00061     SCB_RET_IF(NULL == strokes, "Attempt to release NULL pointer!");
00062         
00063     // release all stroke
00064     g_list_foreach(strokes->strokes, _stroke_release, NULL);
00065 
00066     // now the pointers are wild pointers
00067     g_list_free(strokes->strokes);
00068     strokes->strokes = NULL;
00069 }

Here is the call graph for this function:

int scb_strokes_get_count ( const ScbStrokesPtr  strokes  ) 

Definition at line 84 of file scbstrokes.c.

00085 {
00086     SCB_RET_INT_IF(NULL == strokes, SCB_INVALID_COUNT, "Invalid strokes pointer!");
00087     
00088     // here, the list contains a empty item, so we need to decrease one
00089     int len = g_list_length(strokes->strokes);
00090     if (len > 0)
00091     {
00092         return len - 1;
00093     }
00094     return SCB_INVALID_COUNT;
00095 }

ScbStrokesPtr scb_strokes_line_hit_test ( ScbStrokesPtr  strokes,
ScbDevPointPtr  point1,
ScbDevPointPtr  point2,
const ScbHitTestCtxPtr  ctx 
)

Definition at line 174 of file scbstrokes.c.

00178 {
00179     SCB_RET_NULL_IF(NULL == strokes, "Invalid strokes list pointer!");
00180         
00181     ScbStrokesPtr result = NULL;
00182     ScbStrokePtr stroke  = NULL;
00183     GList* ptr = g_list_first(strokes->strokes);
00184     while(ptr)
00185     {
00186         stroke = ptr->data;
00187         if (stroke && scb_stroke_line_hit_test(stroke, point1, point2, ctx))
00188         {
00189             SCB_TRACE("line hit");
00190             if (NULL == result)
00191             {
00192                 result = g_new0(ScbStrokes, 1);
00193                 if (!scb_strokes_new(result))
00194                 {
00195                     return NULL;
00196                 }
00197             }
00198             // move from one list to the other
00199             scb_strokes_add_stroke(result, stroke);
00200             scb_strokes_detach_stroke(strokes, stroke);
00201         }
00202         ptr = g_list_next(ptr);   
00203     }
00204     return result;
00205 }

Here is the call graph for this function:

gboolean scb_strokes_load ( ScbStrokesPtr  strokes,
ScbXmlPtr  ptr 
)

Definition at line 262 of file scbstrokes.c.

00263 {
00264     // check
00265     SCB_RET_FALSE_IF(NULL == strokes || NULL == ptr, "Invalid strokes or xml pointer!");
00266         
00267     // the strokes here, should be clear. maybe memory leak if open and reload
00268     // the caller should check it
00269     scb_strokes_empty(strokes);
00270     ScbXmlPtr self = scb_xml_clone(ptr);
00271     strncat(self->xPath, "/strokes", SCB_MAX_XML_PATH);
00272     self->index = 1;
00273         
00274     while(1)
00275     {
00276         ScbStrokePtr stroke = scb_stroke_new();
00277         if (scb_stroke_load(stroke, self))
00278         {
00279             scb_strokes_add_stroke(strokes, stroke);
00280             ++self->index;
00281         }
00282         else
00283         {
00284             scb_stroke_free(stroke);
00285             break;
00286         }
00287     }
00288     return TRUE;
00289 }

Here is the call graph for this function:

gboolean scb_strokes_new ( ScbStrokesPtr  ptr  ) 

Definition at line 49 of file scbstrokes.c.

00050 {
00051     SCB_RET_FALSE_IF(NULL == ptr, "Invalid pointer!");
00052     ptr->strokes = g_list_alloc();
00053     SCB_RET_FALSE_IF(NULL == ptr->strokes, "Could not allocate memory for list!");
00054     return TRUE;
00055 }

ScbStrokesPtr scb_strokes_point_hit_test ( ScbStrokesPtr  strokes,
ScbDevPointPtr  point,
const ScbHitTestCtxPtr  ctx 
)

Definition at line 140 of file scbstrokes.c.

00143 {
00144     SCB_RET_NULL_IF(NULL == strokes, "Invalid strokes list pointer!");
00145         
00146     ScbStrokesPtr result = NULL;
00147     ScbStrokePtr stroke  = NULL;
00148     GList* ptr = g_list_first(strokes->strokes);
00149     while(ptr)
00150     {
00151         stroke = (ScbStrokePtr)ptr->data;
00152         if (stroke && scb_stroke_point_hit_test(stroke, point, ctx))
00153         {
00154             SCB_TRACE("point hit");
00155             if (NULL == result)
00156             {
00157                 result = g_new0(ScbStrokes, 1);
00158                 if (! scb_strokes_new(result))
00159                 {
00160                     return NULL;
00161                 }
00162             }
00163             // move from one stroke list to the other
00164             scb_strokes_add_stroke(result, stroke);
00165             scb_strokes_detach_stroke(strokes, stroke);
00166         }
00167         ptr = g_list_next(ptr);   
00168     }
00169     return result;
00170 }

Here is the call graph for this function:

gboolean scb_strokes_save ( ScbStrokesPtr  strokes,
ScbXmlPtr  ptr 
)

Definition at line 246 of file scbstrokes.c.

00247 {
00248     // check
00249     SCB_RET_FALSE_IF(NULL == strokes || NULL == ptr, "Invalid strokes or xml pointer!");
00250         
00251     // construct xPath
00252     ScbXmlPtr self = scb_xml_clone(ptr);
00253     ermXmlNewString(&self->handle, self->xPath, "strokes", "");
00254     strncat(self->xPath, "/strokes", SCB_MAX_XML_PATH);
00255     self->index = 1;
00256     g_list_foreach(strokes->strokes, _stroke_save, self);
00257     scb_xml_free(self);
00258     return TRUE;
00259 }

Here is the call graph for this function:


Generated on Sun Dec 14 17:15:05 2008 by  doxygen 1.5.6