#include <strings.h>#include "FileManager.h"#include "FileMgr_page.h"#include "ink.h"#include "ink_draw.h"#include "ink_intersect.h"#include "ScribbleCore.h"#include "ScribbleLog.h"#include "ScribbleIPC.h"#include "erbusy.h"#include "ScribbleUtils.h"#include "ScribbleSaveThread.h"Go to the source code of this file.
Functions | |
| void | genNewCurrentStroke (PScribbleCoreCtx pScribbleCoreCtx) |
| void | initScribbleCoreCtx (PScribbleCoreCtx pScribbleCoreCtx) |
| void | destroyScribbleCoreCtx (PScribbleCoreCtx pScribbleCoreCtx) |
| void | core_process_points (PScribbleUICtx pScribbleUICtx) |
| void | core_flush_delstroke_onscreen (PScribbleUICtx pScribbleUICtx) |
| int | core_addpoint2buf (PointsBuf *ppointsBuf, int x, int y, int iPenSize, unsigned char iHwColor, unsigned char iPenDown) |
| void | core_add_point (PScribbleUICtx pScribbleUICtx, int x, int y) |
| void | core_eraseStrokes (PScribbleUICtx pScribbleUICtx, GdkPoint *pCurPoint) |
| void | core_eraseInterSectLines (PScribbleUICtx pScribbleUICtx, GdkPoint *pCurPoint) |
| int | core_loadInk (PScribbleUICtx pScribbleUICtx) |
| void | drawInitBgPixMap2CurrPixMap (PScribbleUICtx pScribbleUICtx) |
| int | loadPageAndResultImg (PScribbleUICtx pScribbleUICtx) |
| int | savePageAndResultImg (PScribbleUICtx pScribbleUICtx, gboolean bAppQuit) |
| void | flushPixMap (PScribbleUICtx pScribbleUICtx) |
| int | core_redrawBgAndStrks (PScribbleUICtx pScribbleUICtx) |
| void core_add_point | ( | PScribbleUICtx | pScribbleUICtx, | |
| int | x, | |||
| int | y | |||
| ) |
Definition at line 173 of file ScribbleCore.c.
00174 { 00175 PScribbleCoreCtx pScribbleCoreCtx=&pScribbleUICtx->scribbleCoreCtx; 00176 PointsBuf *ppointsBuf=&pScribbleCoreCtx->pointsBuf; 00177 //add point to pixelbuffer 00178 core_addpoint2buf(ppointsBuf,x,y, 00179 getPenSize(),getPenColor(),pScribbleUICtx->pen_down); 00180 00181 //add points to current stroke 00182 PtrInkPoint pPoint=construct_point (); 00183 pPoint->x=x; 00184 pPoint->y=y; 00185 PtrStroke pStroke=pScribbleCoreCtx->pCurrStroke; 00186 ink_add_point(pStroke, pPoint); 00187 if(!pScribbleUICtx->pen_down) //finish a stroke 00188 { 00189 /* 00190 SB_LOGPRINTF("__add stroke to ink__\nrange=[(%d,%d),(%d,%d)]\n", 00191 pStroke->min_x, pStroke->min_y, 00192 pStroke->max_x, pStroke->max_y ); 00193 */ 00194 00195 //set the pensize for stroke. 00196 pStroke->iPenSize=getPenSize(); 00197 //set pen color 00198 Util_GdkColorFromHWCOLOR(&pStroke->gdkColor,getPenColor()); 00199 ink_add_stroke(pScribbleCoreCtx->pink,pStroke); 00200 //also, draw this new stroke in pixmap 00201 draw_stroke(pStroke); 00202 //sometimes, such as power status update, it invoke displayMgrClient 00203 //which maybe lead to image lost. 00204 flushPixMap(pScribbleUICtx); 00205 genNewCurrentStroke(pScribbleCoreCtx); 00206 //SB_LOGPRINTF("__end add stroke__\n"); 00207 } 00208 pScribbleCoreCtx->bNeedSave=TRUE;//need save 00209 }

| int core_addpoint2buf | ( | PointsBuf * | ppointsBuf, | |
| int | x, | |||
| int | y, | |||
| int | iPenSize, | |||
| unsigned char | iHwColor, | |||
| unsigned char | iPenDown | |||
| ) |
Definition at line 155 of file ScribbleCore.c.
00158 { 00159 unsigned int count=ppointsBuf->count; 00160 if ( count < PIXELBUFSIZE) 00161 { 00162 ppointsBuf->points [count].x = x;//temp measure 00163 ppointsBuf->points [count].y = y; 00164 ppointsBuf->points [count].size = iPenSize; 00165 ppointsBuf->points [count].color = iHwColor; 00166 ppointsBuf->points [count].pen_down = iPenDown; 00167 ppointsBuf->count++; 00168 } 00169 return ppointsBuf->count; 00170 }
| void core_eraseInterSectLines | ( | PScribbleUICtx | pScribbleUICtx, | |
| GdkPoint * | pCurPoint | |||
| ) |
Definition at line 222 of file ScribbleCore.c.
00223 { 00224 PScribbleCoreCtx pScribbleCoreCtx=&pScribbleUICtx->scribbleCoreCtx; 00225 delInterSectLines(pScribbleCoreCtx->pink, 00226 &pScribbleUICtx->lastPoint, 00227 pCurPoint); 00228 }

| void core_eraseStrokes | ( | PScribbleUICtx | pScribbleUICtx, | |
| GdkPoint * | pCurPoint | |||
| ) |
Definition at line 211 of file ScribbleCore.c.
00212 { 00213 PScribbleCoreCtx pScribbleCoreCtx=&pScribbleUICtx->scribbleCoreCtx; 00214 delStrokesByLine(pScribbleCoreCtx->pink, 00215 &pScribbleUICtx->lastPoint, 00216 pCurPoint, 00217 pScribbleCoreCtx->pDelInk); 00218 00219 }

| void core_flush_delstroke_onscreen | ( | PScribbleUICtx | pScribbleUICtx | ) |
Definition at line 111 of file ScribbleCore.c.
00112 { 00113 00114 PScribbleCoreCtx pScribbleCoreCtx=&pScribbleUICtx->scribbleCoreCtx; 00115 PtrInk pDelInk=pScribbleCoreCtx->pDelInk; 00116 if( NULL==pDelInk || 0==pDelInk->nStrokes) return; 00117 00118 SB_LOGPRINTF("deleted strokes=%d\n",pDelInk->nStrokes); 00119 pScribbleCoreCtx->bNeedSave=TRUE; 00120 PtrStroke pCurStroke=pDelInk->firstStroke; 00121 while(pCurStroke) 00122 { 00123 int iPenDown=TRUE; 00124 PtrInkPoint pCurPoint=pCurStroke->firstPoint; 00125 while(pCurPoint) 00126 { 00127 if( NULL==pCurPoint->nextPoint) 00128 {//last stroke 00129 iPenDown=False; 00130 } 00131 int iCurrPointNum=core_addpoint2buf( 00132 &pScribbleUICtx->scribbleCoreCtx.pointsBuf, 00133 pCurPoint->x, 00134 pCurPoint->y, 00135 pCurStroke->iPenSize, 00136 COLOR_WHITE,iPenDown); 00137 00138 if( PIXELBUFSIZE==iCurrPointNum ) 00139 { 00140 core_process_points(pScribbleUICtx);//flush screen 00141 } 00142 pCurPoint=pCurPoint->nextPoint; 00143 } 00144 pCurStroke=pCurStroke->nextStroke; 00145 } 00146 core_process_points ( pScribbleUICtx );//last time flush 00147 //empty the deleted ink 00148 destroy_ink(pScribbleCoreCtx->pDelInk); 00149 //reconstruct the deleted ink file. 00150 pScribbleCoreCtx->pDelInk=construct_ink(); 00151 }

| int core_loadInk | ( | PScribbleUICtx | pScribbleUICtx | ) |
Definition at line 231 of file ScribbleCore.c.
00232 { 00233 PScribbleCoreCtx pScribbleCoreCtx=&pScribbleUICtx->scribbleCoreCtx; 00234 destroyScribbleCoreCtx(pScribbleCoreCtx); 00235 initScribbleCoreCtx(pScribbleCoreCtx); 00236 //load the ink for current page. 00237 SB_TIMEDISPLAY("load ink file\n"); 00238 pScribbleCoreCtx->pink=fm_loadCurrInk(&pScribbleUICtx->fileManager); 00239 if( NULL == pScribbleCoreCtx->pink) 00240 { 00241 SB_ERRORPRINTF("load ink error\n"); 00242 return -1; 00243 } 00244 SB_TIMEDISPLAY("load ink succsessful(strokes=%d)\n", 00245 pScribbleCoreCtx->pink->nStrokes); 00246 return 0; 00247 }

| void core_process_points | ( | PScribbleUICtx | pScribbleUICtx | ) |
Definition at line 82 of file ScribbleCore.c.
00083 { 00084 //SB_LOGPRINTF("__start__\n"); 00085 PointsBuf *pPointsBuf=&pScribbleUICtx->scribbleCoreCtx.pointsBuf; 00086 00087 if (pPointsBuf->count > 0) 00088 { 00089 //SB_LOGPRINTF("SCRIBLE: Sending %d points\n", pPointsBuf->count); 00090 /* 00091 int i; 00092 printf("=====================\n"); 00093 for(i=0;i<pPointsBuf->count;i++) 00094 { 00095 printf("[%d,%d,%d,%d,%d]\n", 00096 pPointsBuf->points [i].x , 00097 pPointsBuf->points [i].y, 00098 pPointsBuf->points [i].size, 00099 pPointsBuf->points [i].color, 00100 pPointsBuf->points [i].pen_down); 00101 } 00102 printf("=====================\n"); 00103 */ 00104 ioctl (pScribbleUICtx->fbdev,FBIO_DRAWPIXELS,pPointsBuf); 00105 pPointsBuf->count = 0; 00106 } 00107 //SB_LOGPRINTF("__end__\n"); 00108 }
| int core_redrawBgAndStrks | ( | PScribbleUICtx | pScribbleUICtx | ) |
Definition at line 410 of file ScribbleCore.c.
00411 { 00412 //init backup to current pixmap,current will be overwrite. 00413 SB_TIMEDISPLAY("start"); 00414 drawInitBgPixMap2CurrPixMap(pScribbleUICtx); 00415 draw_ink(pScribbleUICtx->scribbleCoreCtx.pink); 00416 //flush it to screen immediatly. 00417 flushPixMap(pScribbleUICtx); 00418 SB_TIMEDISPLAY("end"); 00419 return 0; 00420 }

| void destroyScribbleCoreCtx | ( | PScribbleCoreCtx | pScribbleCoreCtx | ) |
Definition at line 68 of file ScribbleCore.c.
00069 { 00070 if(pScribbleCoreCtx->pDelInk) 00071 { 00072 destroy_ink(pScribbleCoreCtx->pDelInk); 00073 pScribbleCoreCtx->pDelInk=NULL; 00074 } 00075 if(pScribbleCoreCtx->pCurrStroke) 00076 { 00077 destroy_stroke(pScribbleCoreCtx->pCurrStroke); 00078 pScribbleCoreCtx->pCurrStroke=NULL; 00079 } 00080 }

| void drawInitBgPixMap2CurrPixMap | ( | PScribbleUICtx | pScribbleUICtx | ) |
Definition at line 249 of file ScribbleCore.c.
00250 { 00251 //draw the backup pixmap to pix map 00252 GtkWidget* widget=pScribbleUICtx->drawing_area; 00253 00254 gdk_draw_drawable(pScribbleUICtx->pixmap, 00255 widget->style->fg_gc[GTK_WIDGET_STATE(widget)], 00256 pScribbleUICtx->initBgPixMap, 00257 0,0,0,0,-1,-1); 00258 }
| void flushPixMap | ( | PScribbleUICtx | pScribbleUICtx | ) |
Definition at line 400 of file ScribbleCore.c.
00401 { 00402 GtkWidget* w=pScribbleUICtx->drawing_area; 00403 gdk_draw_drawable(w->window, 00404 w->style->fg_gc[GTK_WIDGET_STATE(w)], 00405 pScribbleUICtx->pixmap, 00406 0,0,0,0,-1,-1); 00407 }
| void genNewCurrentStroke | ( | PScribbleCoreCtx | pScribbleCoreCtx | ) |
Copyright (C) 2005-2008 iRex Technologies B.V. All rights reserved.
Definition at line 53 of file ScribbleCore.c.
00054 { 00055 pScribbleCoreCtx->pCurrStroke=construct_stroke(); 00056 }

| void initScribbleCoreCtx | ( | PScribbleCoreCtx | pScribbleCoreCtx | ) |
Copyright (C) 2005-2008 iRex Technologies B.V. All rights reserved.
Definition at line 58 of file ScribbleCore.c.
00059 { 00060 pScribbleCoreCtx->pointsBuf.count=0; 00061 pScribbleCoreCtx->pink=NULL; 00062 pScribbleCoreCtx->pDelInk=construct_ink(); 00063 genNewCurrentStroke(pScribbleCoreCtx); 00064 pScribbleCoreCtx->bNeedSave=FALSE; 00065 }

| int loadPageAndResultImg | ( | PScribbleUICtx | pScribbleUICtx | ) |
Definition at line 262 of file ScribbleCore.c.
00263 { 00264 SB_LOGPRINTF("__start__\n"); 00265 //load/construct ink firstly 00266 if( 0!=core_loadInk(pScribbleUICtx) ) return -1; 00267 00268 //need draw strokes?eg:result img lost), always true currently. 00269 gboolean bNeedDrawInk=TRUE; 00270 PFileManager pFM=&pScribbleUICtx->fileManager; 00271 00272 const char* sCurrImgFile=getCurrImgFileName(pFM); 00273 if( NULL==pScribbleUICtx->sLastTmplImg 00274 || 0!=strcasecmp(sCurrImgFile,pScribbleUICtx->sLastTmplImg) ) 00275 { 00276 GdkPixbuf *pbuf=NULL; 00277 SB_TIMEDISPLAY("load image..start\n"); 00278 00279 char sAbsPath[MAX_FILENAME]; 00280 sCurrImgFile=getAbsPathFromCurrScrib 00281 (sAbsPath,sizeof(sAbsPath),sCurrImgFile,pFM); 00282 00283 //we creat the background pixmap,and then keep it as initial 00284 GtkWidget* widget=pScribbleUICtx->drawing_area; 00285 int width=widget->allocation.width; 00286 int height=widget->allocation.height; 00287 //need load the new image as background. 00288 // notes: pbuf is always smaller than (width,height) 00289 if( 0!= util_loadImage_bysize(&pbuf,sCurrImgFile,width,height)) 00290 { 00291 SB_ERRORPRINTF("load image\n(%s) error\n",sCurrImgFile); 00292 if(pbuf) g_object_unref(pbuf); 00293 return -1; 00294 } 00295 pScribbleUICtx->sLastTmplImg=sCurrImgFile; 00296 00297 if(pScribbleUICtx->initBgPixMap) 00298 { 00299 g_object_unref(pScribbleUICtx->initBgPixMap); 00300 } 00301 pScribbleUICtx->initBgPixMap=gdk_pixmap_new(widget->window,width,height,-1); 00302 // clear the background to be white 00303 gdk_draw_rectangle (pScribbleUICtx->initBgPixMap, widget->style->white_gc, TRUE, 00304 0, 0, width, height); 00305 // center the pixbuf, (width >= w) && (height >= h) 00306 int xPos, yPos, w, h; 00307 w = gdk_pixbuf_get_width(pbuf); 00308 h = gdk_pixbuf_get_height(pbuf); 00309 xPos = (width - w) / 2; 00310 yPos = (height - h) / 2; 00311 //draw the picture to back,use the background widget width, 00312 //previously, we use -1 as the original size of pixbuf. 00313 gdk_draw_pixbuf(pScribbleUICtx->initBgPixMap, NULL, pbuf, 00314 0, 0, xPos, yPos,-1,-1, 00315 GDK_RGB_DITHER_NONE, 0, 0); 00316 00317 if(pbuf) g_object_unref(pbuf);//no need any more. 00318 00319 SB_TIMEDISPLAY("load image success\n(%s)\n",sCurrImgFile); 00320 } 00321 drawInitBgPixMap2CurrPixMap(pScribbleUICtx); 00322 SB_TIMEDISPLAY("after draw bgPixMap\n"); 00323 if(bNeedDrawInk) 00324 { 00325 draw_ink(pScribbleUICtx->scribbleCoreCtx.pink); 00326 } 00327 SB_TIMEDISPLAY("after draw ink\n"); 00328 pScribbleUICtx->scribbleCoreCtx.bNeedSave=FALSE; 00329 SB_LOGPRINTF("__end_\n"); 00330 return 0; 00331 }

| int savePageAndResultImg | ( | PScribbleUICtx | pScribbleUICtx, | |
| gboolean | bAppQuit | |||
| ) |
Definition at line 335 of file ScribbleCore.c.
00336 { 00337 PScribbleCoreCtx pScribbleCoreCtx=&pScribbleUICtx->scribbleCoreCtx; 00338 if(!pScribbleCoreCtx->bNeedSave && !bAppQuit) 00339 { 00340 SB_LOGPRINTF("__saved or no modification!__\n"); 00341 return 0; 00342 } 00343 00344 SB_TIMEDISPLAY("__saving__\n"); 00345 erbusy_blink(); 00346 00347 PFileManager pFM=&pScribbleUICtx->fileManager; 00348 gboolean bNeedSaveBgPic=FALSE; 00349 if( pScribbleCoreCtx->bNeedSave ) 00350 { 00351 //delete empty ink file,anyway, we need not create dir. 00352 if( NULL==pScribbleCoreCtx->pink 00353 || 0==pScribbleCoreCtx->pink->nStrokes) 00354 { 00355 //delete the strokes in .irx 00356 fm_deleteOnePage(pFM,getCurrScribPage(pFM) ); 00357 //delete related result files 00358 deleteRelatedFiles(pFM,getCurrScribPage(pFM) ); 00359 } 00360 else 00361 { 00362 //if directory hirachy do not created,creat it. 00363 if( 0!=createDirHirachy(pFM) ) 00364 { 00365 SB_ERRORPRINTF("error when create dir hirachy\n"); 00366 erbusy_off(); 00367 return -1; 00368 } 00369 SB_TIMEDISPLAY("create dir successful\n"); 00370 bNeedSaveBgPic=TRUE; 00371 } 00372 } 00373 00374 //ahead the save action,let contenlister had time to refresh correctly. 00375 if(bAppQuit || bNeedSaveBgPic) 00376 { 00377 //save the filemanager settings and manifest 00378 fm_saveFileManager(pFM); 00379 } 00380 if (bNeedSaveBgPic) 00381 { 00382 //notify the save thread to save 00383 notifySave(pScribbleUICtx); 00384 setCurrentPageDirty(pFM,TRUE); 00385 fm_saveCurrPage(pFM);//save curr page to irx 00386 } 00387 //save ink files 00388 if (bAppQuit || bNeedSaveBgPic) 00389 { 00390 fm_saveIrexInk(pFM, bAppQuit); 00391 } 00392 00393 pScribbleCoreCtx->bNeedSave=FALSE; 00394 SB_TIMEDISPLAY("__saved done__\n"); 00395 00396 return 0; 00397 }

1.5.6