tesseract  4.0.0-beta.1-59-g2cc4
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 362 of file scrollview.cpp.

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

◆ 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 265 of file scrollview.cpp.

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

◆ 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 257 of file scrollview.cpp.

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

◆ 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 250 of file scrollview.cpp.

252  {
253  Initialize(name, x_pos, y_pos, x_size, y_size, x_canvas_size, y_canvas_size,
254  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 417 of file scrollview.cpp.

417  {
418  event_handler_ = listener;
419 }

◆ AddMessage()

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

Definition at line 566 of file scrollview.cpp.

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

◆ AddMessageBox()

void ScrollView::AddMessageBox ( )

Definition at line 583 of file scrollview.cpp.

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

◆ AlwaysOnTop()

void ScrollView::AlwaysOnTop ( bool  b)

Definition at line 560 of file scrollview.cpp.

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

◆ 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 448 of file scrollview.cpp.

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

◆ AwaitEventAnyWindow()

SVEvent * ScrollView::AwaitEventAnyWindow ( )

Definition at line 469 of file scrollview.cpp.

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

◆ Brush() [1/3]

void ScrollView::Brush ( Color  color)

Definition at line 731 of file scrollview.cpp.

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

◆ Brush() [2/3]

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

Definition at line 630 of file scrollview.cpp.

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

◆ Brush() [3/3]

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

Definition at line 635 of file scrollview.cpp.

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

◆ Clear()

void ScrollView::Clear ( )

Definition at line 594 of file scrollview.cpp.

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

◆ DrawTo()

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

Definition at line 530 of file scrollview.cpp.

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

◆ Ellipse()

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

Definition at line 614 of file scrollview.cpp.

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

◆ Exit()

void ScrollView::Exit ( )
static

Definition at line 588 of file scrollview.cpp.

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

◆ 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 771 of file scrollview.cpp.

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

◆ Image() [2/2]

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

Definition at line 662 of file scrollview.cpp.

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

◆ Line()

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

Definition at line 537 of file scrollview.cpp.

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

◆ MenuItem() [1/3]

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

Definition at line 685 of file scrollview.cpp.

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

◆ MenuItem() [2/3]

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

Definition at line 679 of file scrollview.cpp.

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

◆ MenuItem() [3/3]

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

Definition at line 669 of file scrollview.cpp.

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

◆ Pen() [1/3]

void ScrollView::Pen ( Color  color)

Definition at line 725 of file scrollview.cpp.

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

◆ Pen() [2/3]

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

Definition at line 620 of file scrollview.cpp.

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

◆ Pen() [3/3]

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

Definition at line 625 of file scrollview.cpp.

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

◆ PopupItem() [1/2]

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

Definition at line 691 of file scrollview.cpp.

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

◆ PopupItem() [2/2]

void ScrollView::PopupItem ( const char *  parent,
const char *  name,
int  cmdEvent,
const char *  value,
const char *  desc 
)

Definition at line 697 of file scrollview.cpp.

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

◆ Rectangle()

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

Definition at line 605 of file scrollview.cpp.

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

◆ SendMsg()

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

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

Definition at line 394 of file scrollview.cpp.

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

◆ 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 412 of file scrollview.cpp.

412  {
413  stream_->Send(msg);
414 }
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 524 of file scrollview.cpp.

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

◆ SetVisible()

void ScrollView::SetVisible ( bool  visible)

Definition at line 554 of file scrollview.cpp.

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

◆ ShowInputDialog()

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

Definition at line 739 of file scrollview.cpp.

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

◆ ShowYesNoDialog()

int ScrollView::ShowYesNoDialog ( const char *  msg)

Definition at line 751 of file scrollview.cpp.

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

◆ Stroke()

void ScrollView::Stroke ( float  width)

Definition at line 599 of file scrollview.cpp.

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

◆ Text()

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

Definition at line 657 of file scrollview.cpp.

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

◆ TextAttributes()

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

Definition at line 640 of file scrollview.cpp.

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

◆ TranslateYCoordinate()

int ScrollView::TranslateYCoordinate ( int  y)

Definition at line 833 of file scrollview.cpp.

833  {
834  if (!y_axis_is_reversed_) { return y;
835  } else { return y_size_ - y; }
836 }

◆ Update()

void ScrollView::Update ( )
static

Definition at line 714 of file scrollview.cpp.

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

◆ UpdateWindow()

void ScrollView::UpdateWindow ( )

Definition at line 709 of file scrollview.cpp.

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

◆ ZoomToRectangle()

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

Definition at line 763 of file scrollview.cpp.

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

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