#include <scribble_manager.h>
Public Member Functions | |
ScribbleMgr (void) | |
~ScribbleMgr (void) | |
bool | open (const char *doc_path) |
void | close (bool bSave=true) |
void | save () |
Save scribble document directly. | |
ScbDocPtr | get_erscribble_doc () |
Retrieve raw scribble document pointer. | |
void | clear_page (const ScbPageId &pageId) |
void | on_scribble_begin (const ScbPageId &pageId, ScribbleGC &sgc, const int absoluteX, const int absoluteY, const int offsetX, const int offsetY, const int pageX, const int pageY) |
Scribble stylus press event handler. This function will draw the new added scribbles both on e-ink screen and on gdk window. | |
void | on_scribble_move (const ScbPageId &pageId, ScribbleGC &sgc, const int absoluteX, const int absoluteY, const int offsetX, const int offsetY, const int pageX, const int pageY) |
Scribble stylus move event handler. This function will draw the new added scribbles both on e-ink screen and on gdk window. | |
void | on_scribble_end (const ScbPageId &pageId, ScribbleGC &sgc, const int absoluteX, const int absoluteY, const int offsetX, const int offsetY, const int pageX, const int pageY) |
Scribble stylus release event handler. This function will draw the new added scribbles both on e-ink screen and on gdk window. | |
void | on_erase_begin (const ScbPageId &pageId, ScribbleGC &sgc, const int absoluteX, const int absoluteY, const int offsetX, const int offsetY, const int pageX, const int pageY) |
Scribble stylus erase press event handler. This function will draw the strokes to be removed both on e-ink screen and on gdk window with color different from normal strokes. | |
void | on_erase_move (const ScbPageId &pageId, ScribbleGC &sgc, const int absoluteX, const int absoluteY, const int offsetX, const int offsetY, const int pageX, const int pageY) |
Scribble stylus erase move event handler. This function will draw the strokes to be removed both on e-ink screen and on gdk window with color different from normal strokes. | |
void | on_erase_end (const ScbPageId &pageId, ScribbleGC &sgc, const int absoluteX, const int absoluteY, const int offsetX, const int offsetY, const int pageX, const int pageY) |
Scribble stylus erase release event handler. This function will draw the strokes to be removed both on e-ink screen and on gdk window with color different from normal strokes. | |
bool | is_active () const |
Is the scribble manager active? | |
void | draw_scribble_page (const ScbPageId &pageId, ScribbleGC &sgc, const int pageX, const int pageY) |
Draw strokes belong to the specified page. | |
void | generate_page_id (ScbPageId &pid, const std::string &anchor, const int pos) |
Generate page id from anchor. | |
Static Public Member Functions | |
static void | copy_page_id (ScbPageId &dst, const ScbPageId &src) |
Duplicate page id. | |
static void | clear_page_id (ScbPageId &pageId) |
Clear page id. | |
static bool | is_page_id_empty (const ScbPageId &pageId) |
Check page id is empty. | |
static bool | cmp_page_id (const ScbPageId &src, const ScbPageId &dst) |
Compare two anchor objects. |
Scribble manager.
Definition at line 127 of file scribble_manager.h.
test::ScribbleMgr::ScribbleMgr | ( | void | ) |
Definition at line 44 of file scribble_manager.cpp.
References erscribble_init().
00045 : doc(0) 00046 , page(0) 00047 , stroke(0) 00048 , last_absolute_point() 00049 , last_page_point() 00050 , last_page_position() 00051 , dirty_pages() 00052 { 00053 erscribble_init(); 00054 }
test::ScribbleMgr::~ScribbleMgr | ( | void | ) |
Definition at line 56 of file scribble_manager.cpp.
References erscribble_uninit().
00057 { 00058 erscribble_uninit(); 00059 }
void test::ScribbleMgr::clear_page | ( | const ScbPageId & | pageId | ) |
Definition at line 509 of file scribble_manager.cpp.
References erscribble_doc_get_page(), and erscribble_page_clear_strokes().
00510 { 00511 ScbPagePtr page; 00512 page = erscribble_doc_get_page(doc, (const ScbPageIdPtr)(&pageId)); 00513 if (page == 0) 00514 { 00515 printf("no page to erase\n"); 00516 return; 00517 } 00518 erscribble_page_clear_strokes(page); 00519 }
void test::ScribbleMgr::clear_page_id | ( | ScbPageId & | pageId | ) | [static] |
Clear page id.
Definition at line 154 of file scribble_manager.cpp.
References erscribble_page_reset_id().
00155 { 00156 erscribble_page_reset_id(&pageId); 00157 }
void test::ScribbleMgr::close | ( | bool | bSave = true |
) |
Close scribble document. This function will check the scribble data is dirty or not. bSave Whether or not to save current scribble data into persistent document.
Definition at line 88 of file scribble_manager.cpp.
References erscribble_doc_free(), and save().
Referenced by open().
00089 { 00090 // TODO. need save the data of current page 00091 if (bSave) 00092 { 00093 save(); 00094 } 00095 00096 erscribble_doc_free(doc); 00097 doc = 0; 00098 memset(&path, 0, sizeof(path)); 00099 page = 0; 00100 stroke = 0; 00101 }
Compare two anchor objects.
Definition at line 164 of file scribble_manager.cpp.
References ERSCRIBBLE_MAX_PAGEID_LEN, and _ScbPageId::id.
Referenced by on_erase_move(), and on_scribble_move().
00165 { 00166 return 0 == strncmp(src.id, dst.id, ERSCRIBBLE_MAX_PAGEID_LEN); 00167 }
Duplicate page id.
Definition at line 149 of file scribble_manager.cpp.
References erscribble_page_copy_id().
Referenced by on_erase_begin(), and on_erase_move().
00150 { 00151 erscribble_page_copy_id(&dst, (const ScbPageIdPtr)(&src)); 00152 }
void test::ScribbleMgr::draw_scribble_page | ( | const ScbPageId & | pageId, | |
ScribbleGC & | sgc, | |||
const int | pageX, | |||
const int | pageY | |||
) |
Draw strokes belong to the specified page.
pageId | The page id provided by caller. | |
sgc | The scribble graphics context. | |
pageX | The page screen coordinate x. | |
pageY | The page screen coordinate y. | |
page_width | width of the page, useful when in landscape mode | |
page_height | height of the page, useful when in landscape mode |
Definition at line 567 of file scribble_manager.cpp.
References erscribble_doc_get_page(), _ScbPageId::id, and test::ScribbleGC::rotation.
00571 { 00572 00573 // page from page id 00574 ScbPagePtr ptr = erscribble_doc_get_page(doc, (const ScbPageIdPtr)(&pageId)); 00575 if (ptr == 0) 00576 { 00577 printf("page %s not found!", pageId.id); 00578 return; 00579 } 00580 00581 if (sgc.rotation == 270) 00582 { 00583 draw_scribble_page_landscape(ptr, sgc, pageX, pageY); 00584 } 00585 else 00586 { 00587 draw_scribble_page_portrait(ptr, sgc, pageX, pageY); 00588 } 00589 }
void test::ScribbleMgr::generate_page_id | ( | ScbPageId & | pid, | |
const std::string & | anchor, | |||
const int | pos | |||
) |
Generate page id from anchor.
TODO: This function should be provided by caller now.
pid | The erscribble page id which will store the result. | |
anchor | The input anchor. | |
pos | The page number |
Removed should be provded by caller. Should compare PLUGIN_MAX_ANCHOR_LENGTH and erscribble_MAX_PAGEID_LEN. erscribble_MAX_PAGEID_LEN 256 PLUGIN_MAX_ANCHOR_LENGTH 1024. It may cause some problem when anchors' first 256 bytes are equal. Quite impossible.
Definition at line 144 of file scribble_manager.cpp.
References erscribble_page_set_id().
00145 { 00146 erscribble_page_set_id(&pid, pos, anchor.c_str(), -1); 00147 }
ScbDocPtr test::ScribbleMgr::get_erscribble_doc | ( | ) | [inline] |
Retrieve raw scribble document pointer.
Definition at line 150 of file scribble_manager.h.
bool test::ScribbleMgr::is_active | ( | ) | const [inline] |
Is the scribble manager active?
Definition at line 275 of file scribble_manager.h.
bool test::ScribbleMgr::is_page_id_empty | ( | const ScbPageId & | pageId | ) | [static] |
Check page id is empty.
Definition at line 159 of file scribble_manager.cpp.
References _ScbPageId::id.
Referenced by on_erase_begin(), on_erase_end(), on_erase_move(), on_scribble_begin(), on_scribble_end(), and on_scribble_move().
00160 { 00161 return pageId.id[0] == '\0'; 00162 }
void test::ScribbleMgr::on_erase_begin | ( | const ScbPageId & | pageId, | |
ScribbleGC & | sgc, | |||
const int | absoluteX, | |||
const int | absoluteY, | |||
const int | offsetX, | |||
const int | offsetY, | |||
const int | pageX, | |||
const int | pageY | |||
) |
Scribble stylus erase press event handler. This function will draw the strokes to be removed both on e-ink screen and on gdk window with color different from normal strokes.
When erasing, no need to check whether or not go into another page.
pageId | The page id provided by caller. | |
sgc | The scribble graphics context. | |
absoluteX | The point screen coordinate x. | |
absoluteY | The point screen coordinate y. | |
offsetX | The x offset value within the page. | |
offsetY | The y offset value within the page. | |
pageX | The x offset of the page display position. | |
pageY | The y offset of the page display position. |
Definition at line 413 of file scribble_manager.cpp.
References copy_page_id(), erscribble_doc_get_page(), erscribble_page_erase_hit_test(), erscribble_page_erase_init(), erscribble_strokes_free(), is_page_id_empty(), _ScbDevPoint::point, test::ScribbleGC::realZoom, test::ScribbleGC::rotation, _ScbPoint::x, _ScbPoint::y, and _ScbPageEraseCtx::zoom.
00421 { 00422 if (is_page_id_empty(pageId)) 00423 { 00424 return; 00425 } 00426 00427 // prepare for erasing. 00428 erscribble_page_erase_init(&erase_context); 00429 page = erscribble_doc_get_page(doc, (const ScbPageIdPtr)(&pageId)); 00430 if (page == 0) 00431 { 00432 return; 00433 } 00434 00435 // record 00436 copy_page_id(last_page_id, pageId); 00437 00438 ScbDevPoint point; 00439 point.point.x = offsetX, point.point.y = offsetY; 00440 erase_context.zoom = sgc.realZoom; 00441 ScbStrokesPtr strokes = erscribble_page_erase_hit_test(page, &point, &erase_context); 00442 if (strokes) 00443 { 00444 printf("Erase strokes!"); 00445 00446 // draw and free 00447 if (sgc.rotation == 270) 00448 { 00449 draw_erased_strokes_landscape(strokes, sgc, pageX, pageY); 00450 } 00451 else 00452 { 00453 draw_erased_strokes_portrait(strokes, sgc, pageX, pageY); 00454 } 00455 00456 // free 00457 erscribble_strokes_free(strokes); 00458 } 00459 }
void test::ScribbleMgr::on_erase_end | ( | const ScbPageId & | pageId, | |
ScribbleGC & | sgc, | |||
const int | absoluteX, | |||
const int | absoluteY, | |||
const int | offsetX, | |||
const int | offsetY, | |||
const int | pageX, | |||
const int | pageY | |||
) |
Scribble stylus erase release event handler. This function will draw the strokes to be removed both on e-ink screen and on gdk window with color different from normal strokes.
pageId | The page id provided by caller. | |
sgc | The scribble graphics context. | |
absoluteX | The point screen coordinate x. | |
absoluteY | The point screen coordinate y. | |
offsetX | The x offset value within the page. | |
offsetY | The y offset value within the page. | |
pageX | The x offset of the page display position. | |
pageY | The y offset of the page display position. |
Definition at line 521 of file scribble_manager.cpp.
References erscribble_page_erase_hit_test(), erscribble_strokes_free(), is_page_id_empty(), _ScbDevPoint::point, test::ScribbleGC::rotation, _ScbPoint::x, and _ScbPoint::y.
00529 { 00530 if (is_page_id_empty(pageId) || page == 0) 00531 { 00532 return; 00533 } 00534 00535 ScbDevPoint point; 00536 point.point.x = offsetX; 00537 point.point.y = offsetY; 00538 ScbStrokesPtr strokes = erscribble_page_erase_hit_test(page, &point, &erase_context); 00539 00540 if (!is_page_dirty(page)) 00541 { 00542 // add page into dirty list 00543 set_page_dirty(page); 00544 } 00545 00546 // reset 00547 page = 0; 00548 if (strokes) 00549 { 00550 printf("Erase strokes!"); 00551 if (sgc.rotation == 270) 00552 { 00553 draw_erased_strokes_landscape(strokes, sgc, pageX, pageY); 00554 } 00555 else 00556 { 00557 draw_erased_strokes_portrait(strokes, sgc, pageX, pageY); 00558 } 00559 00560 // draw and free 00561 erscribble_strokes_free(strokes); 00562 } 00563 }
void test::ScribbleMgr::on_erase_move | ( | const ScbPageId & | pageId, | |
ScribbleGC & | sgc, | |||
const int | absoluteX, | |||
const int | absoluteY, | |||
const int | offsetX, | |||
const int | offsetY, | |||
const int | pageX, | |||
const int | pageY | |||
) |
Scribble stylus erase move event handler. This function will draw the strokes to be removed both on e-ink screen and on gdk window with color different from normal strokes.
pageId | The page id provided by caller. | |
sgc | The scribble graphics context. | |
absoluteX | The point screen coordinate x. | |
absoluteY | The point screen coordinate y. | |
offsetX | The x offset value within the page. | |
offsetY | The y offset value within the page. | |
pageX | The x offset of the page display position. | |
pageY | The y offset of the page display position. |
Definition at line 461 of file scribble_manager.cpp.
References cmp_page_id(), copy_page_id(), erscribble_doc_get_page(), erscribble_page_erase_hit_test(), erscribble_page_erase_init(), erscribble_strokes_free(), is_page_id_empty(), _ScbDevPoint::point, test::ScribbleGC::realZoom, test::ScribbleGC::rotation, _ScbPoint::x, _ScbPoint::y, and _ScbPageEraseCtx::zoom.
00469 { 00470 if (is_page_id_empty(pageId)) 00471 { 00472 return; 00473 } 00474 00475 if (!cmp_page_id(last_page_id, pageId)) 00476 { 00477 copy_page_id(last_page_id, pageId); 00478 erscribble_page_erase_init(&erase_context); 00479 erase_context.zoom = sgc.realZoom; 00480 } 00481 00482 page = erscribble_doc_get_page(doc, (const ScbPageIdPtr)(&pageId)); 00483 if (page == 0) 00484 { 00485 return; 00486 } 00487 00488 ScbDevPoint point; 00489 point.point.x = offsetX; point.point.y = offsetY; 00490 00491 ScbStrokesPtr strokes = erscribble_page_erase_hit_test(page, &point, &erase_context); 00492 if (strokes) 00493 { 00494 printf("Erase strokes!"); 00495 if (sgc.rotation == 270) 00496 { 00497 draw_erased_strokes_landscape(strokes, sgc, pageX, pageY); 00498 } 00499 else 00500 { 00501 draw_erased_strokes_portrait(strokes, sgc, pageX, pageY); 00502 } 00503 00504 // free 00505 erscribble_strokes_free(strokes); 00506 } 00507 }
void test::ScribbleMgr::on_scribble_begin | ( | const ScbPageId & | pageId, | |
ScribbleGC & | sgc, | |||
const int | absoluteX, | |||
const int | absoluteY, | |||
const int | offsetX, | |||
const int | offsetY, | |||
const int | pageX, | |||
const int | pageY | |||
) |
Scribble stylus press event handler. This function will draw the new added scribbles both on e-ink screen and on gdk window.
pageId | The page id provided by caller. | |
sgc | The scribble graphics context. | |
absoluteX | The point screen coordinate x. | |
absoluteY | The point screen coordinate y. | |
offsetX | The x offset value within the page. | |
offsetY | The y offset value within the page. | |
pageX | The x offset of the page display position. | |
pageY | The y offset of the page display position. |
Definition at line 304 of file scribble_manager.cpp.
References _ScbPageId::id, is_page_id_empty(), test::Point::x, and test::Point::y.
00312 { 00313 printf("PageId %s page %p stroke %p!", pageId.id, page, stroke); 00314 if (!is_page_id_empty(pageId)) 00315 { 00316 if (page && stroke) 00317 { 00318 add_point(pageId, sgc, absoluteX, absoluteY, offsetX, offsetY); 00319 } 00320 else if (page == 0 && stroke == 0) 00321 { 00322 begin_stroke(pageId, sgc, absoluteX, absoluteY, offsetX, offsetY); 00323 } 00324 00325 // record the last point 00326 last_absolute_point.x = absoluteX; 00327 last_absolute_point.y = absoluteY; 00328 last_page_point.x = offsetX; 00329 last_page_point.y = offsetY; 00330 last_page_position.x = pageX; 00331 last_page_position.y = pageY; 00332 } 00333 }
void test::ScribbleMgr::on_scribble_end | ( | const ScbPageId & | pageId, | |
ScribbleGC & | sgc, | |||
const int | absoluteX, | |||
const int | absoluteY, | |||
const int | offsetX, | |||
const int | offsetY, | |||
const int | pageX, | |||
const int | pageY | |||
) |
Scribble stylus release event handler. This function will draw the new added scribbles both on e-ink screen and on gdk window.
pageId | The page id provided by caller. | |
sgc | The scribble graphics context. | |
absoluteX | The point screen coordinate x. | |
absoluteY | The point screen coordinate y. | |
offsetX | The x offset value within the page. | |
offsetY | The y offset value within the page. | |
pageX | The x offset of the page display position. | |
pageY | The y offset of the page display position. |
Definition at line 390 of file scribble_manager.cpp.
References is_page_id_empty(), test::Point::x, and test::Point::y.
00398 { 00399 if (!is_page_id_empty(pageId) && stroke && doc && page) 00400 { 00401 end_stroke(pageId, sgc, absoluteX, absoluteY, offsetX, offsetY, pageX, pageY); 00402 // record the last point 00403 last_absolute_point.x = absoluteX; 00404 last_absolute_point.y = absoluteY; 00405 last_page_point.x = offsetX; 00406 last_page_point.y = offsetY; 00407 last_page_position.x = pageX; 00408 last_page_position.y = pageY; 00409 } 00410 }
void test::ScribbleMgr::on_scribble_move | ( | const ScbPageId & | pageId, | |
ScribbleGC & | sgc, | |||
const int | absoluteX, | |||
const int | absoluteY, | |||
const int | offsetX, | |||
const int | offsetY, | |||
const int | pageX, | |||
const int | pageY | |||
) |
Scribble stylus move event handler. This function will draw the new added scribbles both on e-ink screen and on gdk window.
Should consider following situations:
pageId | The page id provided by caller. | |
sgc | The scribble graphics context. | |
absoluteX | The point screen coordinate x. | |
absoluteY | The point screen coordinate y. | |
offsetX | The x offset value within the page. | |
offsetY | The y offset value within the page. | |
pageX | The x offset of the page display position. | |
pageY | The y offset of the page display position. |
Definition at line 339 of file scribble_manager.cpp.
References cmp_page_id(), is_page_id_empty(), test::Point::x, and test::Point::y.
00347 { 00348 // out of page, end stroke now. 00349 if (is_page_id_empty(pageId) && stroke && page) 00350 { 00351 // end without adding it 00352 end_stroke(sgc, absoluteX, absoluteY, pageX, pageY); 00353 return; 00354 } 00355 00356 bool ret = false; 00357 // re-enter page bound 00358 if (!ret && !is_page_id_empty(pageId) && stroke == 0 && page == 0) 00359 { 00360 begin_stroke(pageId, sgc, absoluteX, absoluteY, offsetX, offsetY); 00361 ret = true; 00362 } 00363 00364 // from one page to the other, should use old pagex and pagey 00365 if (!ret && !is_page_id_empty(last_page_id) && 00366 !is_page_id_empty(pageId) && 00367 !cmp_page_id(pageId, last_page_id) && stroke && page) 00368 { 00369 end_stroke(last_page_id, sgc, last_absolute_point.x, last_absolute_point.y 00370 , last_page_point.x, last_page_point.y, last_page_position.x, last_page_position.y); 00371 begin_stroke(pageId, sgc, absoluteX, absoluteY, offsetX, offsetY); 00372 ret = true; 00373 } 00374 00375 // scribble mode 00376 if (!ret && stroke) 00377 { 00378 add_point(pageId, sgc, absoluteX, absoluteY, offsetX, offsetY); 00379 // record the last point 00380 last_absolute_point.x = absoluteX; 00381 last_absolute_point.y = absoluteY; 00382 last_page_point.x = offsetX; 00383 last_page_point.y = offsetY; 00384 last_page_position.x = pageX; 00385 last_page_position.y = pageY; 00386 ret = true; 00387 } 00388 }
bool test::ScribbleMgr::open | ( | const char * | doc_path | ) |
Open scribble document.
path | The document absolute path. |
Definition at line 61 of file scribble_manager.cpp.
References close(), erscribble_doc_new(), erscribble_doc_open(), and ERSCRIBBLE_MAX_PATH.
00062 { 00063 close(); 00064 00065 // check 00066 if (doc_path == 0) 00067 { 00068 printf("Invalid path name pointer!\n"); 00069 return false; 00070 } 00071 00072 // keep the path name. 00073 strncpy(path.document_path, doc_path, ERSCRIBBLE_MAX_PATH); 00074 00075 // open file 00076 doc = erscribble_doc_open(&path); 00077 00078 // if there is no scribble data stored in the data base 00079 // create a new scribble document 00080 if (doc == 0) 00081 { 00082 doc = erscribble_doc_new(&path); 00083 } 00084 00085 return (doc != 0); 00086 }
void test::ScribbleMgr::save | ( | ) |
Save scribble document directly.
Definition at line 123 of file scribble_manager.cpp.
References erscribble_doc_save_page().
Referenced by close().
00124 { 00125 if (doc) 00126 { 00127 DirtyPagesIter idx = dirty_pages.begin(); 00128 for (; idx != dirty_pages.end(); ++idx) 00129 { 00130 ScbPagePtr ptr = *idx; 00131 erscribble_doc_save_page(doc, ptr); 00132 } 00133 // clear all dirty pages 00134 dirty_pages.clear(); 00135 } 00136 }