tesseract
3.03
|
#include <scrollview.h>
Public Types | |
enum | Color { NONE, BLACK, WHITE, RED, YELLOW, GREEN, CYAN, BLUE, MAGENTA, AQUAMARINE, DARK_SLATE_BLUE, LIGHT_BLUE, MEDIUM_BLUE, MIDNIGHT_BLUE, NAVY_BLUE, SKY_BLUE, SLATE_BLUE, STEEL_BLUE, CORAL, BROWN, SANDY_BROWN, GOLD, GOLDENROD, DARK_GREEN, DARK_OLIVE_GREEN, FOREST_GREEN, LIME_GREEN, PALE_GREEN, YELLOW_GREEN, LIGHT_GREY, DARK_SLATE_GREY, DIM_GREY, GREY, KHAKI, MAROON, ORANGE, ORCHID, PINK, PLUM, INDIAN_RED, ORANGE_RED, VIOLET_RED, SALMON, TAN, TURQUOISE, DARK_TURQUOISE, VIOLET, WHEAT, GREEN_YELLOW } |
Public Member Functions | |
~ScrollView () | |
ScrollView (const char *name, int x_pos, int y_pos, int x_size, int y_size, int x_canvas_size, int y_canvas_size) | |
Calls Initialize with default argument for server_name_ & y_axis_reversed. | |
ScrollView (const char *name, int x_pos, int y_pos, int x_size, int y_size, int x_canvas_size, int y_canvas_size, bool y_axis_reversed) | |
Calls Initialize with default argument for server_name_. | |
ScrollView (const char *name, int x_pos, int y_pos, int x_size, int y_size, int x_canvas_size, int y_canvas_size, bool y_axis_reversed, const char *server_name) | |
Calls Initialize with all arguments given. | |
void | AddEventHandler (SVEventHandler *listener) |
Add an Event Listener to this ScrollView Window. | |
SVEvent * | AwaitEvent (SVEventType type) |
SVEvent * | AwaitEventAnyWindow () |
const char * | GetName () |
int | GetId () |
void | Image (struct Pix *image, int x_pos, int y_pos) |
void | UpdateWindow () |
void | Clear () |
void | Pen (Color color) |
void | Pen (int red, int green, int blue) |
void | Pen (int red, int green, int blue, int alpha) |
void | Brush (Color color) |
void | Brush (int red, int green, int blue) |
void | Brush (int red, int green, int blue, int alpha) |
void | TextAttributes (const char *font, int pixel_size, bool bold, bool italic, bool underlined) |
void | Line (int x1, int y1, int x2, int y2) |
void | Stroke (float width) |
void | Rectangle (int x1, int y1, int x2, int y2) |
void | Ellipse (int x, int y, int width, int height) |
void | Text (int x, int y, const char *mystring) |
void | Image (const char *image, int x_pos, int y_pos) |
void | SetCursor (int x, int y) |
void | DrawTo (int x, int y) |
void | SetVisible (bool visible) |
void | AlwaysOnTop (bool b) |
int | ShowYesNoDialog (const char *msg) |
char * | ShowInputDialog (const char *msg) |
void | AddMessageBox () |
void | AddMessage (const char *format,...) |
void | ZoomToRectangle (int x1, int y1, int x2, int y2) |
void | SendMsg (const char *msg,...) |
Send a message to the server, attaching the window id. | |
void | MenuItem (const char *parent, const char *name) |
void | MenuItem (const char *parent, const char *name, int cmdEvent) |
void | MenuItem (const char *parent, const char *name, int cmdEvent, bool flagged) |
void | PopupItem (const char *parent, const char *name) |
void | PopupItem (const char *parent, const char *name, int cmdEvent, const char *value, const char *desc) |
int | TranslateYCoordinate (int y) |
Static Public Member Functions | |
static void | Update () |
static void | Exit () |
static void | SendRawMessage (const char *msg) |
Definition at line 102 of file scrollview.h.
enum ScrollView::Color |
Definition at line 105 of file scrollview.h.
{ NONE, BLACK, WHITE, RED, YELLOW, GREEN, CYAN, BLUE, MAGENTA, AQUAMARINE, DARK_SLATE_BLUE, LIGHT_BLUE, MEDIUM_BLUE, MIDNIGHT_BLUE, NAVY_BLUE, SKY_BLUE, SLATE_BLUE, STEEL_BLUE, CORAL, BROWN, SANDY_BROWN, GOLD, GOLDENROD, DARK_GREEN, DARK_OLIVE_GREEN, FOREST_GREEN, LIME_GREEN, PALE_GREEN, YELLOW_GREEN, LIGHT_GREY, DARK_SLATE_GREY, DIM_GREY, GREY, KHAKI, MAROON, ORANGE, ORCHID, PINK, PLUM, INDIAN_RED, ORANGE_RED, VIOLET_RED, SALMON, TAN, TURQUOISE, DARK_TURQUOISE, VIOLET, WHEAT, GREEN_YELLOW // Make sure this one is last. };
Definition at line 363 of file scrollview.cpp.
{ #ifndef GRAPHICS_DISABLED svmap_mu->Lock(); if (svmap[window_id_] != NULL) { svmap_mu->Unlock(); // So the event handling thread can quit. SendMsg("destroy()"); SVEvent* sve = AwaitEvent(SVET_DESTROY); delete sve; svmap_mu->Lock(); svmap[window_id_] = NULL; svmap_mu->Unlock(); // The event handler thread for this window *must* receive the // destroy event and set its pointer to this to NULL before we allow // the destructor to exit. while (!event_handler_ended_) Update(); } else { svmap_mu->Unlock(); } delete mutex_; delete semaphore_; delete points_; for (int i = 0; i < SVET_COUNT; i++) { delete event_table_[i]; } #endif // GRAPHICS_DISABLED }
ScrollView::ScrollView | ( | const char * | name, |
int | x_pos, | ||
int | y_pos, | ||
int | x_size, | ||
int | y_size, | ||
int | x_canvas_size, | ||
int | y_canvas_size | ||
) |
Calls Initialize with default argument for server_name_ & y_axis_reversed.
Definition at line 266 of file scrollview.cpp.
{ Initialize(name, x_pos, y_pos, x_size, y_size, x_canvas_size, y_canvas_size, false, "localhost"); }
ScrollView::ScrollView | ( | const char * | name, |
int | x_pos, | ||
int | y_pos, | ||
int | x_size, | ||
int | y_size, | ||
int | x_canvas_size, | ||
int | y_canvas_size, | ||
bool | y_axis_reversed | ||
) |
Calls Initialize with default argument for server_name_.
Definition at line 258 of file scrollview.cpp.
{
Initialize(name, x_pos, y_pos, x_size, y_size, x_canvas_size, y_canvas_size,
y_axis_reversed, "localhost");
}
ScrollView::ScrollView | ( | const char * | name, |
int | x_pos, | ||
int | y_pos, | ||
int | x_size, | ||
int | y_size, | ||
int | x_canvas_size, | ||
int | y_canvas_size, | ||
bool | y_axis_reversed, | ||
const char * | server_name | ||
) |
Calls Initialize with all arguments given.
Definition at line 251 of file scrollview.cpp.
{ Initialize(name, x_pos, y_pos, x_size, y_size, x_canvas_size, y_canvas_size, y_axis_reversed, server_name);}
void ScrollView::AddEventHandler | ( | SVEventHandler * | listener | ) |
Add an Event Listener to this ScrollView Window.
Definition at line 418 of file scrollview.cpp.
{ event_handler_ = listener; }
void ScrollView::AddMessage | ( | const char * | format, |
... | |||
) |
Definition at line 567 of file scrollview.cpp.
{ va_list args; char message[kMaxMsgSize]; char form[kMaxMsgSize]; va_start(args, format); // variable list vsnprintf(message, kMaxMsgSize, format, args); va_end(args); snprintf(form, kMaxMsgSize, "w%u:%s", window_id_, message); char* esc = AddEscapeChars(form); SendMsg("addMessage(\"%s\")", esc); delete[] esc; }
void ScrollView::AddMessageBox | ( | ) |
Definition at line 584 of file scrollview.cpp.
{ SendMsg("addMessageBox()"); }
void ScrollView::AlwaysOnTop | ( | bool | b | ) |
Definition at line 561 of file scrollview.cpp.
SVEvent * ScrollView::AwaitEvent | ( | SVEventType | type | ) |
Block until an event of the given type is received. Note: The calling function is responsible for deleting the returned SVEvent afterwards!
Definition at line 449 of file scrollview.cpp.
{ // Initialize the waiting semaphore. SVSemaphore* sem = new SVSemaphore(); std::pair<ScrollView*, SVEventType> ea(this, type); waiting_for_events_mu->Lock(); waiting_for_events[ea] = std::pair<SVSemaphore*, SVEvent*> (sem, (SVEvent*)0); waiting_for_events_mu->Unlock(); // Wait on it, but first flush. stream_->Flush(); sem->Wait(); // Process the event we got woken up for (its in waiting_for_events pair). waiting_for_events_mu->Lock(); SVEvent* ret = waiting_for_events[ea].second; waiting_for_events.erase(ea); delete sem; waiting_for_events_mu->Unlock(); return ret; }
Definition at line 470 of file scrollview.cpp.
{ // Initialize the waiting semaphore. SVSemaphore* sem = new SVSemaphore(); std::pair<ScrollView*, SVEventType> ea((ScrollView*)0, SVET_ANY); waiting_for_events_mu->Lock(); waiting_for_events[ea] = std::pair<SVSemaphore*, SVEvent*> (sem, (SVEvent*)0); waiting_for_events_mu->Unlock(); // Wait on it. stream_->Flush(); sem->Wait(); // Process the event we got woken up for (its in waiting_for_events pair). waiting_for_events_mu->Lock(); SVEvent* ret = waiting_for_events[ea].second; waiting_for_events.erase(ea); waiting_for_events_mu->Unlock(); return ret; }
void ScrollView::Brush | ( | Color | color | ) |
Definition at line 732 of file scrollview.cpp.
{ Brush(table_colors[color][0], table_colors[color][1], table_colors[color][2], table_colors[color][3]); }
void ScrollView::Brush | ( | int | red, |
int | green, | ||
int | blue | ||
) |
Definition at line 631 of file scrollview.cpp.
{ SendMsg("brush(%d,%d,%d)", red, green, blue); }
void ScrollView::Brush | ( | int | red, |
int | green, | ||
int | blue, | ||
int | alpha | ||
) |
Definition at line 636 of file scrollview.cpp.
{ SendMsg("brush(%d,%d,%d,%d)", red, green, blue, alpha); }
void ScrollView::Clear | ( | ) |
Definition at line 595 of file scrollview.cpp.
{ SendMsg("clear()"); }
void ScrollView::DrawTo | ( | int | x, |
int | y | ||
) |
Definition at line 531 of file scrollview.cpp.
{ points_->xcoords.push_back(x); points_->ycoords.push_back(TranslateYCoordinate(y)); points_->empty = false; }
void ScrollView::Ellipse | ( | int | x, |
int | y, | ||
int | width, | ||
int | height | ||
) |
Definition at line 615 of file scrollview.cpp.
{ SendMsg("drawEllipse(%d,%d,%u,%u)", x1, TranslateYCoordinate(y1), width, height); }
void ScrollView::Exit | ( | ) | [static] |
Definition at line 589 of file scrollview.cpp.
{ SendRawMessage("svmain:exit()"); exit(0); }
int ScrollView::GetId | ( | ) | [inline] |
Definition at line 197 of file scrollview.h.
{ return window_id_; }
const char* ScrollView::GetName | ( | ) | [inline] |
Definition at line 194 of file scrollview.h.
{ return window_name_; }
void ScrollView::Image | ( | struct Pix * | image, |
int | x_pos, | ||
int | y_pos | ||
) |
Definition at line 773 of file scrollview.cpp.
{ l_uint8* data; size_t size; pixWriteMem(&data, &size, image, IFF_PNG); int base64_len = (size + 2) / 3 * 4; SendMsg("readImage(%d,%d,%d)", x_pos, y_pos, base64_len); // Base64 encode the data. const char kBase64Table[64] = { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '/', }; char* base64 = new char[base64_len + 1]; memset(base64, '=', base64_len); base64[base64_len] = '\0'; int remainder = 0; int bits_left = 0; int code_len = 0; for (int i = 0; i < size; ++i) { int code = (data[i] >> (bits_left + 2)) | remainder; base64[code_len++] = kBase64Table[code & 63]; bits_left += 2; remainder = data[i] << (6 - bits_left); if (bits_left == 6) { base64[code_len++] = kBase64Table[remainder & 63]; bits_left = 0; remainder = 0; } } if (bits_left > 0) base64[code_len++] = kBase64Table[remainder & 63]; SendRawMessage(base64); delete [] base64; free(data); }
void ScrollView::Image | ( | const char * | image, |
int | x_pos, | ||
int | y_pos | ||
) |
Definition at line 663 of file scrollview.cpp.
{ SendMsg("openImage('%s')", image); SendMsg("drawImage('%s',%d,%d)", image, x_pos, TranslateYCoordinate(y_pos)); }
void ScrollView::Line | ( | int | x1, |
int | y1, | ||
int | x2, | ||
int | y2 | ||
) |
Definition at line 538 of file scrollview.cpp.
{ if (!points_->xcoords.empty() && x1 == points_->xcoords.back() && TranslateYCoordinate(y1) == points_->ycoords.back()) { // We are already at x1, y1, so just draw to x2, y2. DrawTo(x2, y2); } else if (!points_->xcoords.empty() && x2 == points_->xcoords.back() && TranslateYCoordinate(y2) == points_->ycoords.back()) { // We are already at x2, y2, so just draw to x1, y1. DrawTo(x1, y1); } else { // This is a new line. SetCursor(x1, y1); DrawTo(x2, y2); } }
void ScrollView::MenuItem | ( | const char * | parent, |
const char * | name | ||
) |
Definition at line 686 of file scrollview.cpp.
{ if (parent == NULL) { parent = ""; } SendMsg("addMenuBarItem('%s','%s')", parent, name); }
void ScrollView::MenuItem | ( | const char * | parent, |
const char * | name, | ||
int | cmdEvent | ||
) |
Definition at line 680 of file scrollview.cpp.
{ if (parent == NULL) { parent = ""; } SendMsg("addMenuBarItem('%s','%s',%d)", parent, name, cmdEvent); }
void ScrollView::MenuItem | ( | const char * | parent, |
const char * | name, | ||
int | cmdEvent, | ||
bool | flagged | ||
) |
Definition at line 670 of file scrollview.cpp.
void ScrollView::Pen | ( | Color | color | ) |
Definition at line 726 of file scrollview.cpp.
{ Pen(table_colors[color][0], table_colors[color][1], table_colors[color][2], table_colors[color][3]); }
void ScrollView::Pen | ( | int | red, |
int | green, | ||
int | blue | ||
) |
Definition at line 621 of file scrollview.cpp.
{ SendMsg("pen(%d,%d,%d)", red, green, blue); }
void ScrollView::Pen | ( | int | red, |
int | green, | ||
int | blue, | ||
int | alpha | ||
) |
Definition at line 626 of file scrollview.cpp.
{ SendMsg("pen(%d,%d,%d,%d)", red, green, blue, alpha); }
void ScrollView::PopupItem | ( | const char * | parent, |
const char * | name | ||
) |
Definition at line 692 of file scrollview.cpp.
{ if (parent == NULL) { parent = ""; } SendMsg("addPopupMenuItem('%s','%s')", parent, name); }
void ScrollView::PopupItem | ( | const char * | parent, |
const char * | name, | ||
int | cmdEvent, | ||
const char * | value, | ||
const char * | desc | ||
) |
Definition at line 698 of file scrollview.cpp.
{ if (parent == NULL) { parent = ""; } char* esc = AddEscapeChars(value); char* esc2 = AddEscapeChars(desc); SendMsg("addPopupMenuItem('%s','%s',%d,'%s','%s')", parent, name, cmdEvent, esc, esc2); delete[] esc; delete[] esc2; }
void ScrollView::Rectangle | ( | int | x1, |
int | y1, | ||
int | x2, | ||
int | y2 | ||
) |
Definition at line 606 of file scrollview.cpp.
{ if (x1 == x2 && y1 == y2) return; // Scrollviewer locks up. SendMsg("drawRectangle(%d,%d,%d,%d)", x1, TranslateYCoordinate(y1), x2, TranslateYCoordinate(y2)); }
void ScrollView::SendMsg | ( | const char * | msg, |
... | |||
) |
Send a message to the server, attaching the window id.
Definition at line 395 of file scrollview.cpp.
{ if (!points_->empty) SendPolygon(); va_list args; char message[kMaxMsgSize]; va_start(args, format); // variable list vsnprintf(message, kMaxMsgSize, format, args); va_end(args); char form[kMaxMsgSize]; snprintf(form, kMaxMsgSize, "w%u:%s\n", window_id_, message); stream_->Send(form); }
void ScrollView::SendRawMessage | ( | const char * | msg | ) | [static] |
Send a message to the server without a window id. Used for global events like exit().
Definition at line 413 of file scrollview.cpp.
{ stream_->Send(msg); }
void ScrollView::SetCursor | ( | int | x, |
int | y | ||
) |
Definition at line 525 of file scrollview.cpp.
{ SendPolygon(); DrawTo(x, y); }
void ScrollView::SetVisible | ( | bool | visible | ) |
Definition at line 555 of file scrollview.cpp.
char * ScrollView::ShowInputDialog | ( | const char * | msg | ) |
Definition at line 740 of file scrollview.cpp.
{ SendMsg("showInputDialog(\"%s\")", msg); SVEvent* ev; // wait till an input event (all others are thrown away) ev = AwaitEvent(SVET_INPUT); char* p = new char[strlen(ev->parameter) + 1]; strncpy(p, ev->parameter, strlen(ev->parameter)); p[strlen(ev->parameter)] = '\0'; delete ev; return p; }
int ScrollView::ShowYesNoDialog | ( | const char * | msg | ) |
Definition at line 753 of file scrollview.cpp.
{ SendMsg("showYesNoDialog(\"%s\")", msg); SVEvent* ev; // Wait till an input event (all others are thrown away) ev = AwaitEvent(SVET_INPUT); int a = ev->parameter[0]; delete ev; return a; }
void ScrollView::Stroke | ( | float | width | ) |
Definition at line 600 of file scrollview.cpp.
{ SendMsg("setStrokeWidth(%f)", width); }
void ScrollView::Text | ( | int | x, |
int | y, | ||
const char * | mystring | ||
) |
Definition at line 658 of file scrollview.cpp.
{ SendMsg("drawText(%d,%d,'%s')", x, TranslateYCoordinate(y), mystring); }
void ScrollView::TextAttributes | ( | const char * | font, |
int | pixel_size, | ||
bool | bold, | ||
bool | italic, | ||
bool | underlined | ||
) |
Definition at line 641 of file scrollview.cpp.
{ const char* b; const char* i; const char* u; if (bold) { b = "true"; } else { b = "false"; } if (italic) { i = "true"; } else { i = "false"; } if (underlined) { u = "true"; } else { u = "false"; } SendMsg("textAttributes('%s',%u,%s,%s,%s)", font, pixel_size, b, i, u); }
int ScrollView::TranslateYCoordinate | ( | int | y | ) |
Definition at line 835 of file scrollview.cpp.
{ if (!y_axis_is_reversed_) { return y; } else { return y_size_ - y; } }
void ScrollView::Update | ( | ) | [static] |
Definition at line 715 of file scrollview.cpp.
void ScrollView::UpdateWindow | ( | ) |
Definition at line 710 of file scrollview.cpp.
{ SendMsg("update()"); }
void ScrollView::ZoomToRectangle | ( | int | x1, |
int | y1, | ||
int | x2, | ||
int | y2 | ||
) |
Definition at line 765 of file scrollview.cpp.
{ y1 = TranslateYCoordinate(y1); y2 = TranslateYCoordinate(y2); SendMsg("zoomRectangle(%d,%d,%d,%d)", MIN(x1, x2), MIN(y1, y2), MAX(x1, x2), MAX(y1, y2)); }