Tesseract
3.02
|
#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 (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. | |
~ScrollView () | |
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 107 of file scrollview.h.
enum ScrollView::Color |
Definition at line 110 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. };
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 265 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 257 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 250 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);}
ScrollView::~ScrollView | ( | ) |
Definition at line 361 of file scrollview.cpp.
{ 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_; }
void ScrollView::AddEventHandler | ( | SVEventHandler * | listener | ) |
Add an Event Listener to this ScrollView Window.
Definition at line 410 of file scrollview.cpp.
{ event_handler_ = listener; }
void ScrollView::AddMessage | ( | const char * | format, |
... | |||
) |
Definition at line 559 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 576 of file scrollview.cpp.
{ SendMsg("addMessageBox()"); }
void ScrollView::AlwaysOnTop | ( | bool | b | ) |
Definition at line 553 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 441 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; }
SVEvent * ScrollView::AwaitEventAnyWindow | ( | ) |
Definition at line 462 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 724 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 623 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 628 of file scrollview.cpp.
{ SendMsg("brush(%d,%d,%d,%d)", red, green, blue, alpha); }
void ScrollView::Clear | ( | ) |
Definition at line 587 of file scrollview.cpp.
{ SendMsg("clear()"); }
void ScrollView::DrawTo | ( | int | x, |
int | y | ||
) |
Definition at line 523 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 607 of file scrollview.cpp.
{ SendMsg("drawEllipse(%d,%d,%u,%u)", x1, TranslateYCoordinate(y1), width, height); }
void ScrollView::Exit | ( | ) | [static] |
Definition at line 581 of file scrollview.cpp.
{ SendRawMessage("svmain:exit()"); exit(0); }
int ScrollView::GetId | ( | ) | [inline] |
Definition at line 202 of file scrollview.h.
{ return window_id_; }
const char* ScrollView::GetName | ( | ) | [inline] |
Definition at line 199 of file scrollview.h.
{ return window_name_; }
void ScrollView::Image | ( | struct Pix * | image, |
int | x_pos, | ||
int | y_pos | ||
) |
Definition at line 765 of file scrollview.cpp.
{ int width = image->w; int height = image->h; l_uint32 bpp = image->d; ++image_index_; // PIX* do not have a unique identifier/name associated, so name them "lept". SendMsg("createImage('lept%d',%d,%d,%d)", image_index_, width, height, bpp); if (bpp == 32) { Transfer32bppImage(image); } else if (bpp == 8) { TransferGrayImage(image); } else if (bpp == 1) { TransferBinaryImage(image); } // PIX* do not have a unique identifier/name associated, so name them "lept". SendMsg("drawImage('lept%d',%d,%d)", image_index_, x_pos, y_pos); }
void ScrollView::Image | ( | const char * | image, |
int | x_pos, | ||
int | y_pos | ||
) |
Definition at line 655 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 530 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 678 of file scrollview.cpp.
void ScrollView::MenuItem | ( | const char * | parent, |
const char * | name, | ||
int | cmdEvent | ||
) |
Definition at line 672 of file scrollview.cpp.
void ScrollView::MenuItem | ( | const char * | parent, |
const char * | name, | ||
int | cmdEvent, | ||
bool | flagged | ||
) |
Definition at line 662 of file scrollview.cpp.
void ScrollView::Pen | ( | Color | color | ) |
Definition at line 718 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 613 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 618 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 684 of file scrollview.cpp.
void ScrollView::PopupItem | ( | const char * | parent, |
const char * | name, | ||
int | cmdEvent, | ||
const char * | value, | ||
const char * | desc | ||
) |
Definition at line 690 of file scrollview.cpp.
void ScrollView::Rectangle | ( | int | x1, |
int | y1, | ||
int | x2, | ||
int | y2 | ||
) |
Definition at line 598 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 387 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 405 of file scrollview.cpp.
{ stream_->Send(msg); }
void ScrollView::SetCursor | ( | int | x, |
int | y | ||
) |
Definition at line 517 of file scrollview.cpp.
{ SendPolygon(); DrawTo(x, y); }
void ScrollView::SetVisible | ( | bool | visible | ) |
Definition at line 547 of file scrollview.cpp.
char * ScrollView::ShowInputDialog | ( | const char * | msg | ) |
Definition at line 732 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 745 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 592 of file scrollview.cpp.
{ SendMsg("setStrokeWidth(%f)", width); }
void ScrollView::Text | ( | int | x, |
int | y, | ||
const char * | mystring | ||
) |
Definition at line 650 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 633 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 860 of file scrollview.cpp.
{ if (!y_axis_is_reversed_) { return y; } else { return y_size_ - y; } }
void ScrollView::Update | ( | ) | [static] |
Definition at line 707 of file scrollview.cpp.
void ScrollView::UpdateWindow | ( | ) |
Definition at line 702 of file scrollview.cpp.
{ SendMsg("update()"); }
void ScrollView::ZoomToRectangle | ( | int | x1, |
int | y1, | ||
int | x2, | ||
int | y2 | ||
) |
Definition at line 757 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)); }