tesseract  4.00.00dev
ScrollView Class Reference

#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. More...
 
 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_. More...
 
 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. More...
 
void AddEventHandler (SVEventHandler *listener)
 Add an Event Listener to this ScrollView Window. More...
 
SVEventAwaitEvent (SVEventType type)
 
SVEventAwaitEventAnyWindow ()
 
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. More...
 
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)
 

Detailed Description

Definition at line 102 of file scrollview.h.

Member Enumeration Documentation

◆ Color

Enumerator
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 

Definition at line 105 of file scrollview.h.

105  {
106  NONE,
107  BLACK,
108  WHITE,
109  RED,
110  YELLOW,
111  GREEN,
112  CYAN,
113  BLUE,
114  MAGENTA,
115  AQUAMARINE,
117  LIGHT_BLUE,
118  MEDIUM_BLUE,
120  NAVY_BLUE,
121  SKY_BLUE,
122  SLATE_BLUE,
123  STEEL_BLUE,
124  CORAL,
125  BROWN,
126  SANDY_BROWN,
127  GOLD,
128  GOLDENROD,
129  DARK_GREEN,
131  FOREST_GREEN,
132  LIME_GREEN,
133  PALE_GREEN,
134  YELLOW_GREEN,
135  LIGHT_GREY,
137  DIM_GREY,
138  GREY,
139  KHAKI,
140  MAROON,
141  ORANGE,
142  ORCHID,
143  PINK,
144  PLUM,
145  INDIAN_RED,
146  ORANGE_RED,
147  VIOLET_RED,
148  SALMON,
149  TAN,
150  TURQUOISE,
152  VIOLET,
153  WHEAT,
154  GREEN_YELLOW // Make sure this one is last.
155 };

Constructor & Destructor Documentation

◆ ~ScrollView()

ScrollView::~ScrollView ( )

Definition at line 363 of file scrollview.cpp.

363  {
364  #ifndef GRAPHICS_DISABLED
365  svmap_mu->Lock();
366  if (svmap[window_id_] != NULL) {
367  svmap_mu->Unlock();
368  // So the event handling thread can quit.
369  SendMsg("destroy()");
370 
372  delete sve;
373  svmap_mu->Lock();
374  svmap[window_id_] = NULL;
375  svmap_mu->Unlock();
376  // The event handler thread for this window *must* receive the
377  // destroy event and set its pointer to this to NULL before we allow
378  // the destructor to exit.
379  while (!event_handler_ended_)
380  Update();
381  } else {
382  svmap_mu->Unlock();
383  }
384  delete mutex_;
385  delete semaphore_;
386  delete points_;
387  for (int i = 0; i < SVET_COUNT; i++) {
388  delete event_table_[i];
389  }
390  #endif // GRAPHICS_DISABLED
391 }
void Unlock()
Unlocks on a mutex.
Definition: svutil.cpp:78
void SendMsg(const char *msg,...)
Send a message to the server, attaching the window id.
Definition: scrollview.cpp:395
static void Update()
Definition: scrollview.cpp:715
void Lock()
Locks on a mutex.
Definition: svutil.cpp:70
SVEvent * AwaitEvent(SVEventType type)
Definition: scrollview.cpp:449

◆ ScrollView() [1/3]

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.

267  {
268  Initialize(name, x_pos, y_pos, x_size, y_size, x_canvas_size, y_canvas_size,
269  false, "localhost");
270 }

◆ ScrollView() [2/3]

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.

260  {
261  Initialize(name, x_pos, y_pos, x_size, y_size, x_canvas_size, y_canvas_size,
262  y_axis_reversed, "localhost");
263 }

◆ ScrollView() [3/3]

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.

253  {
254  Initialize(name, x_pos, y_pos, x_size, y_size, x_canvas_size, y_canvas_size,
255  y_axis_reversed, server_name);}

Member Function Documentation

◆ AddEventHandler()

void ScrollView::AddEventHandler ( SVEventHandler listener)

Add an Event Listener to this ScrollView Window.

Definition at line 418 of file scrollview.cpp.

418  {
419  event_handler_ = listener;
420 }

◆ AddMessage()

void ScrollView::AddMessage ( const char *  format,
  ... 
)

Definition at line 567 of file scrollview.cpp.

567  {
568  va_list args;
569  char message[kMaxMsgSize];
570  char form[kMaxMsgSize];
571 
572  va_start(args, format); // variable list
573  vsnprintf(message, kMaxMsgSize, format, args);
574  va_end(args);
575 
576  snprintf(form, kMaxMsgSize, "w%u:%s", window_id_, message);
577 
578  char* esc = AddEscapeChars(form);
579  SendMsg("addMessage(\"%s\")", esc);
580  delete[] esc;
581 }
void SendMsg(const char *msg,...)
Send a message to the server, attaching the window id.
Definition: scrollview.cpp:395
const int kMaxMsgSize
Definition: scrollview.cpp:46

◆ AddMessageBox()

void ScrollView::AddMessageBox ( )

Definition at line 584 of file scrollview.cpp.

584  {
585  SendMsg("addMessageBox()");
586 }
void SendMsg(const char *msg,...)
Send a message to the server, attaching the window id.
Definition: scrollview.cpp:395

◆ AlwaysOnTop()

void ScrollView::AlwaysOnTop ( bool  b)

Definition at line 561 of file scrollview.cpp.

561  {
562  if (b) { SendMsg("setAlwaysOnTop(true)");
563  } else { SendMsg("setAlwaysOnTop(false)"); }
564 }
void SendMsg(const char *msg,...)
Send a message to the server, attaching the window id.
Definition: scrollview.cpp:395

◆ AwaitEvent()

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.

449  {
450  // Initialize the waiting semaphore.
451  SVSemaphore* sem = new SVSemaphore();
452  std::pair<ScrollView*, SVEventType> ea(this, type);
453  waiting_for_events_mu->Lock();
454  waiting_for_events[ea] = std::pair<SVSemaphore*, SVEvent*> (sem, (SVEvent*)0);
455  waiting_for_events_mu->Unlock();
456  // Wait on it, but first flush.
457  stream_->Flush();
458  sem->Wait();
459  // Process the event we got woken up for (its in waiting_for_events pair).
460  waiting_for_events_mu->Lock();
461  SVEvent* ret = waiting_for_events[ea].second;
462  waiting_for_events.erase(ea);
463  delete sem;
464  waiting_for_events_mu->Unlock();
465  return ret;
466 }
void Unlock()
Unlocks on a mutex.
Definition: svutil.cpp:78
void Flush()
Flush the buffer.
Definition: svutil.cpp:217
void Wait()
Wait on a semaphore.
Definition: svutil.cpp:199
void Lock()
Locks on a mutex.
Definition: svutil.cpp:70

◆ AwaitEventAnyWindow()

SVEvent * ScrollView::AwaitEventAnyWindow ( )

Definition at line 470 of file scrollview.cpp.

470  {
471  // Initialize the waiting semaphore.
472  SVSemaphore* sem = new SVSemaphore();
473  std::pair<ScrollView*, SVEventType> ea((ScrollView*)0, SVET_ANY);
474  waiting_for_events_mu->Lock();
475  waiting_for_events[ea] = std::pair<SVSemaphore*, SVEvent*> (sem, (SVEvent*)0);
476  waiting_for_events_mu->Unlock();
477  // Wait on it.
478  stream_->Flush();
479  sem->Wait();
480  // Process the event we got woken up for (its in waiting_for_events pair).
481  waiting_for_events_mu->Lock();
482  SVEvent* ret = waiting_for_events[ea].second;
483  waiting_for_events.erase(ea);
484  waiting_for_events_mu->Unlock();
485  return ret;
486 }
void Unlock()
Unlocks on a mutex.
Definition: svutil.cpp:78
void Flush()
Flush the buffer.
Definition: svutil.cpp:217
void Wait()
Wait on a semaphore.
Definition: svutil.cpp:199
void Lock()
Locks on a mutex.
Definition: svutil.cpp:70

◆ Brush() [1/3]

void ScrollView::Brush ( Color  color)

Definition at line 732 of file scrollview.cpp.

732  {
733  Brush(table_colors[color][0],
734  table_colors[color][1],
735  table_colors[color][2],
736  table_colors[color][3]);
737 }
void Brush(Color color)
Definition: scrollview.cpp:732
int table_colors[ScrollView::GREEN_YELLOW+1][4]
Definition: scrollview.cpp:189

◆ Brush() [2/3]

void ScrollView::Brush ( int  red,
int  green,
int  blue 
)

Definition at line 631 of file scrollview.cpp.

631  {
632  SendMsg("brush(%d,%d,%d)", red, green, blue);
633 }
void SendMsg(const char *msg,...)
Send a message to the server, attaching the window id.
Definition: scrollview.cpp:395

◆ Brush() [3/3]

void ScrollView::Brush ( int  red,
int  green,
int  blue,
int  alpha 
)

Definition at line 636 of file scrollview.cpp.

636  {
637  SendMsg("brush(%d,%d,%d,%d)", red, green, blue, alpha);
638 }
void SendMsg(const char *msg,...)
Send a message to the server, attaching the window id.
Definition: scrollview.cpp:395

◆ Clear()

void ScrollView::Clear ( )

Definition at line 595 of file scrollview.cpp.

595  {
596  SendMsg("clear()");
597 }
void SendMsg(const char *msg,...)
Send a message to the server, attaching the window id.
Definition: scrollview.cpp:395

◆ DrawTo()

void ScrollView::DrawTo ( int  x,
int  y 
)

Definition at line 531 of file scrollview.cpp.

531  {
532  points_->xcoords.push_back(x);
533  points_->ycoords.push_back(TranslateYCoordinate(y));
534  points_->empty = false;
535 }
int TranslateYCoordinate(int y)
Definition: scrollview.cpp:836
std::vector< int > xcoords
Definition: scrollview.cpp:55
std::vector< int > ycoords
Definition: scrollview.cpp:56

◆ Ellipse()

void ScrollView::Ellipse ( int  x,
int  y,
int  width,
int  height 
)

Definition at line 615 of file scrollview.cpp.

615  {
616  SendMsg("drawEllipse(%d,%d,%u,%u)",
617  x1, TranslateYCoordinate(y1), width, height);
618 }
int TranslateYCoordinate(int y)
Definition: scrollview.cpp:836
void SendMsg(const char *msg,...)
Send a message to the server, attaching the window id.
Definition: scrollview.cpp:395

◆ Exit()

void ScrollView::Exit ( )
static

Definition at line 589 of file scrollview.cpp.

589  {
590  SendRawMessage("svmain:exit()");
591  exit(0);
592 }
static void SendRawMessage(const char *msg)
Definition: scrollview.cpp:413

◆ GetId()

int ScrollView::GetId ( )
inline

Definition at line 197 of file scrollview.h.

197 { return window_id_; }

◆ GetName()

const char* ScrollView::GetName ( )
inline

Definition at line 194 of file scrollview.h.

194 { return window_name_; }

◆ Image() [1/2]

void ScrollView::Image ( struct Pix *  image,
int  x_pos,
int  y_pos 
)

Definition at line 773 of file scrollview.cpp.

773  {
774  l_uint8* data;
775  size_t size;
776  pixWriteMem(&data, &size, image, IFF_PNG);
777  int base64_len = (size + 2) / 3 * 4;
778  y_pos = TranslateYCoordinate(y_pos);
779  SendMsg("readImage(%d,%d,%d)", x_pos, y_pos, base64_len);
780  // Base64 encode the data.
781  const char kBase64Table[64] = {
782  'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
783  'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P',
784  'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X',
785  'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f',
786  'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',
787  'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
788  'w', 'x', 'y', 'z', '0', '1', '2', '3',
789  '4', '5', '6', '7', '8', '9', '+', '/',
790  };
791  char* base64 = new char[base64_len + 1];
792  memset(base64, '=', base64_len);
793  base64[base64_len] = '\0';
794  int remainder = 0;
795  int bits_left = 0;
796  int code_len = 0;
797  for (size_t i = 0; i < size; ++i) {
798  int code = (data[i] >> (bits_left + 2)) | remainder;
799  base64[code_len++] = kBase64Table[code & 63];
800  bits_left += 2;
801  remainder = data[i] << (6 - bits_left);
802  if (bits_left == 6) {
803  base64[code_len++] = kBase64Table[remainder & 63];
804  bits_left = 0;
805  remainder = 0;
806  }
807  }
808  if (bits_left > 0)
809  base64[code_len++] = kBase64Table[remainder & 63];
810  SendRawMessage(base64);
811  delete [] base64;
812  free(data);
813 }
voidpf void uLong size
Definition: ioapi.h:39
int TranslateYCoordinate(int y)
Definition: scrollview.cpp:836
static void SendRawMessage(const char *msg)
Definition: scrollview.cpp:413
void SendMsg(const char *msg,...)
Send a message to the server, attaching the window id.
Definition: scrollview.cpp:395

◆ Image() [2/2]

void ScrollView::Image ( const char *  image,
int  x_pos,
int  y_pos 
)

Definition at line 663 of file scrollview.cpp.

663  {
664  SendMsg("openImage('%s')", image);
665  SendMsg("drawImage('%s',%d,%d)",
666  image, x_pos, TranslateYCoordinate(y_pos));
667 }
int TranslateYCoordinate(int y)
Definition: scrollview.cpp:836
void SendMsg(const char *msg,...)
Send a message to the server, attaching the window id.
Definition: scrollview.cpp:395

◆ Line()

void ScrollView::Line ( int  x1,
int  y1,
int  x2,
int  y2 
)

Definition at line 538 of file scrollview.cpp.

538  {
539  if (!points_->xcoords.empty() && x1 == points_->xcoords.back() &&
540  TranslateYCoordinate(y1) == points_->ycoords.back()) {
541  // We are already at x1, y1, so just draw to x2, y2.
542  DrawTo(x2, y2);
543  } else if (!points_->xcoords.empty() && x2 == points_->xcoords.back() &&
544  TranslateYCoordinate(y2) == points_->ycoords.back()) {
545  // We are already at x2, y2, so just draw to x1, y1.
546  DrawTo(x1, y1);
547  } else {
548  // This is a new line.
549  SetCursor(x1, y1);
550  DrawTo(x2, y2);
551  }
552 }
int TranslateYCoordinate(int y)
Definition: scrollview.cpp:836
void SetCursor(int x, int y)
Definition: scrollview.cpp:525
std::vector< int > xcoords
Definition: scrollview.cpp:55
std::vector< int > ycoords
Definition: scrollview.cpp:56
void DrawTo(int x, int y)
Definition: scrollview.cpp:531

◆ MenuItem() [1/3]

void ScrollView::MenuItem ( const char *  parent,
const char *  name 
)

Definition at line 686 of file scrollview.cpp.

686  {
687  if (parent == NULL) { parent = ""; }
688  SendMsg("addMenuBarItem('%s','%s')", parent, name);
689 }
void SendMsg(const char *msg,...)
Send a message to the server, attaching the window id.
Definition: scrollview.cpp:395

◆ MenuItem() [2/3]

void ScrollView::MenuItem ( const char *  parent,
const char *  name,
int  cmdEvent 
)

Definition at line 680 of file scrollview.cpp.

680  {
681  if (parent == NULL) { parent = ""; }
682  SendMsg("addMenuBarItem('%s','%s',%d)", parent, name, cmdEvent);
683 }
void SendMsg(const char *msg,...)
Send a message to the server, attaching the window id.
Definition: scrollview.cpp:395

◆ MenuItem() [3/3]

void ScrollView::MenuItem ( const char *  parent,
const char *  name,
int  cmdEvent,
bool  flagged 
)

Definition at line 670 of file scrollview.cpp.

671  {
672  if (parent == NULL) { parent = ""; }
673  if (flag) { SendMsg("addMenuBarItem('%s','%s',%d,true)",
674  parent, name, cmdEvent);
675  } else { SendMsg("addMenuBarItem('%s','%s',%d,false)",
676  parent, name, cmdEvent); }
677 }
void SendMsg(const char *msg,...)
Send a message to the server, attaching the window id.
Definition: scrollview.cpp:395

◆ Pen() [1/3]

void ScrollView::Pen ( Color  color)

Definition at line 726 of file scrollview.cpp.

726  {
727  Pen(table_colors[color][0], table_colors[color][1],
728  table_colors[color][2], table_colors[color][3]);
729 }
int table_colors[ScrollView::GREEN_YELLOW+1][4]
Definition: scrollview.cpp:189
void Pen(Color color)
Definition: scrollview.cpp:726

◆ Pen() [2/3]

void ScrollView::Pen ( int  red,
int  green,
int  blue 
)

Definition at line 621 of file scrollview.cpp.

621  {
622  SendMsg("pen(%d,%d,%d)", red, green, blue);
623 }
void SendMsg(const char *msg,...)
Send a message to the server, attaching the window id.
Definition: scrollview.cpp:395

◆ Pen() [3/3]

void ScrollView::Pen ( int  red,
int  green,
int  blue,
int  alpha 
)

Definition at line 626 of file scrollview.cpp.

626  {
627  SendMsg("pen(%d,%d,%d,%d)", red, green, blue, alpha);
628 }
void SendMsg(const char *msg,...)
Send a message to the server, attaching the window id.
Definition: scrollview.cpp:395

◆ PopupItem() [1/2]

void ScrollView::PopupItem ( const char *  parent,
const char *  name 
)

Definition at line 692 of file scrollview.cpp.

692  {
693  if (parent == NULL) { parent = ""; }
694  SendMsg("addPopupMenuItem('%s','%s')", parent, name);
695 }
void SendMsg(const char *msg,...)
Send a message to the server, attaching the window id.
Definition: scrollview.cpp:395

◆ PopupItem() [2/2]

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.

699  {
700  if (parent == NULL) { parent = ""; }
701  char* esc = AddEscapeChars(value);
702  char* esc2 = AddEscapeChars(desc);
703  SendMsg("addPopupMenuItem('%s','%s',%d,'%s','%s')", parent, name,
704  cmdEvent, esc, esc2);
705  delete[] esc;
706  delete[] esc2;
707 }
void SendMsg(const char *msg,...)
Send a message to the server, attaching the window id.
Definition: scrollview.cpp:395

◆ Rectangle()

void ScrollView::Rectangle ( int  x1,
int  y1,
int  x2,
int  y2 
)

Definition at line 606 of file scrollview.cpp.

606  {
607  if (x1 == x2 && y1 == y2)
608  return; // Scrollviewer locks up.
609  SendMsg("drawRectangle(%d,%d,%d,%d)",
610  x1, TranslateYCoordinate(y1), x2, TranslateYCoordinate(y2));
611 }
int TranslateYCoordinate(int y)
Definition: scrollview.cpp:836
void SendMsg(const char *msg,...)
Send a message to the server, attaching the window id.
Definition: scrollview.cpp:395

◆ SendMsg()

void ScrollView::SendMsg ( const char *  msg,
  ... 
)

Send a message to the server, attaching the window id.

Definition at line 395 of file scrollview.cpp.

395  {
396  if (!points_->empty)
397  SendPolygon();
398  va_list args;
399  char message[kMaxMsgSize];
400 
401  va_start(args, format); // variable list
402  vsnprintf(message, kMaxMsgSize, format, args);
403  va_end(args);
404 
405  char form[kMaxMsgSize];
406  snprintf(form, kMaxMsgSize, "w%u:%s\n", window_id_, message);
407 
408  stream_->Send(form);
409 }
void Send(const char *msg)
Put a message in the messagebuffer to the server and try to send it.
Definition: svutil.cpp:210
const int kMaxMsgSize
Definition: scrollview.cpp:46

◆ SendRawMessage()

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.

413  {
414  stream_->Send(msg);
415 }
void Send(const char *msg)
Put a message in the messagebuffer to the server and try to send it.
Definition: svutil.cpp:210

◆ SetCursor()

void ScrollView::SetCursor ( int  x,
int  y 
)

Definition at line 525 of file scrollview.cpp.

525  {
526  SendPolygon();
527  DrawTo(x, y);
528 }
void DrawTo(int x, int y)
Definition: scrollview.cpp:531

◆ SetVisible()

void ScrollView::SetVisible ( bool  visible)

Definition at line 555 of file scrollview.cpp.

555  {
556  if (visible) { SendMsg("setVisible(true)");
557  } else { SendMsg("setVisible(false)"); }
558 }
void SendMsg(const char *msg,...)
Send a message to the server, attaching the window id.
Definition: scrollview.cpp:395

◆ ShowInputDialog()

char * ScrollView::ShowInputDialog ( const char *  msg)

Definition at line 740 of file scrollview.cpp.

740  {
741  SendMsg("showInputDialog(\"%s\")", msg);
742  SVEvent* ev;
743  // wait till an input event (all others are thrown away)
744  ev = AwaitEvent(SVET_INPUT);
745  char* p = new char[strlen(ev->parameter) + 1];
746  strncpy(p, ev->parameter, strlen(ev->parameter));
747  p[strlen(ev->parameter)] = '\0';
748  delete ev;
749  return p;
750 }
char * parameter
Definition: scrollview.h:71
void SendMsg(const char *msg,...)
Send a message to the server, attaching the window id.
Definition: scrollview.cpp:395
SVEvent * AwaitEvent(SVEventType type)
Definition: scrollview.cpp:449

◆ ShowYesNoDialog()

int ScrollView::ShowYesNoDialog ( const char *  msg)

Definition at line 753 of file scrollview.cpp.

753  {
754  SendMsg("showYesNoDialog(\"%s\")", msg);
755  SVEvent* ev;
756  // Wait till an input event (all others are thrown away)
757  ev = AwaitEvent(SVET_INPUT);
758  int a = ev->parameter[0];
759  delete ev;
760  return a;
761 }
char * parameter
Definition: scrollview.h:71
void SendMsg(const char *msg,...)
Send a message to the server, attaching the window id.
Definition: scrollview.cpp:395
SVEvent * AwaitEvent(SVEventType type)
Definition: scrollview.cpp:449

◆ Stroke()

void ScrollView::Stroke ( float  width)

Definition at line 600 of file scrollview.cpp.

600  {
601  SendMsg("setStrokeWidth(%f)", width);
602 }
void SendMsg(const char *msg,...)
Send a message to the server, attaching the window id.
Definition: scrollview.cpp:395

◆ Text()

void ScrollView::Text ( int  x,
int  y,
const char *  mystring 
)

Definition at line 658 of file scrollview.cpp.

658  {
659  SendMsg("drawText(%d,%d,'%s')", x, TranslateYCoordinate(y), mystring);
660 }
int TranslateYCoordinate(int y)
Definition: scrollview.cpp:836
void SendMsg(const char *msg,...)
Send a message to the server, attaching the window id.
Definition: scrollview.cpp:395

◆ TextAttributes()

void ScrollView::TextAttributes ( const char *  font,
int  pixel_size,
bool  bold,
bool  italic,
bool  underlined 
)

Definition at line 641 of file scrollview.cpp.

642  {
643  const char* b;
644  const char* i;
645  const char* u;
646 
647  if (bold) { b = "true";
648  } else { b = "false"; }
649  if (italic) { i = "true";
650  } else { i = "false"; }
651  if (underlined) { u = "true";
652  } else { u = "false"; }
653  SendMsg("textAttributes('%s',%u,%s,%s,%s)", font, pixel_size,
654  b, i, u);
655 }
double u[max]
void SendMsg(const char *msg,...)
Send a message to the server, attaching the window id.
Definition: scrollview.cpp:395

◆ TranslateYCoordinate()

int ScrollView::TranslateYCoordinate ( int  y)

Definition at line 836 of file scrollview.cpp.

836  {
837  if (!y_axis_is_reversed_) { return y;
838  } else { return y_size_ - y; }
839 }

◆ Update()

void ScrollView::Update ( )
static

Definition at line 715 of file scrollview.cpp.

715  {
716  svmap_mu->Lock();
717  for (std::map<int, ScrollView*>::iterator iter = svmap.begin();
718  iter != svmap.end(); ++iter) {
719  if (iter->second != NULL)
720  iter->second->UpdateWindow();
721  }
722  svmap_mu->Unlock();
723 }
void Unlock()
Unlocks on a mutex.
Definition: svutil.cpp:78
void Lock()
Locks on a mutex.
Definition: svutil.cpp:70

◆ UpdateWindow()

void ScrollView::UpdateWindow ( )

Definition at line 710 of file scrollview.cpp.

710  {
711  SendMsg("update()");
712 }
void SendMsg(const char *msg,...)
Send a message to the server, attaching the window id.
Definition: scrollview.cpp:395

◆ ZoomToRectangle()

void ScrollView::ZoomToRectangle ( int  x1,
int  y1,
int  x2,
int  y2 
)

Definition at line 765 of file scrollview.cpp.

765  {
766  y1 = TranslateYCoordinate(y1);
767  y2 = TranslateYCoordinate(y2);
768  SendMsg("zoomRectangle(%d,%d,%d,%d)",
769  MIN(x1, x2), MIN(y1, y2), MAX(x1, x2), MAX(y1, y2));
770 }
int TranslateYCoordinate(int y)
Definition: scrollview.cpp:836
void SendMsg(const char *msg,...)
Send a message to the server, attaching the window id.
Definition: scrollview.cpp:395
#define MAX(x, y)
Definition: ndminx.h:24
#define MIN(x, y)
Definition: ndminx.h:28

The documentation for this class was generated from the following files: