tesseract  4.0.0-1-g2a2b
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 361 of file scrollview.cpp.

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

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

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

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

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

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

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

416  {
417  event_handler_ = listener;
418 }

◆ AddMessage()

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

Definition at line 563 of file scrollview.cpp.

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

◆ AddMessageBox()

void ScrollView::AddMessageBox ( )

Definition at line 580 of file scrollview.cpp.

580  {
581  SendMsg("addMessageBox()");
582 }
void SendMsg(const char *msg,...)
Send a message to the server, attaching the window id.
Definition: scrollview.cpp:393

◆ AlwaysOnTop()

void ScrollView::AlwaysOnTop ( bool  b)

Definition at line 557 of file scrollview.cpp.

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

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

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

◆ AwaitEventAnyWindow()

SVEvent * ScrollView::AwaitEventAnyWindow ( )

Definition at line 466 of file scrollview.cpp.

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

◆ Brush() [1/3]

void ScrollView::Brush ( Color  color)

Definition at line 728 of file scrollview.cpp.

728  {
729  Brush(table_colors[color][0],
730  table_colors[color][1],
731  table_colors[color][2],
732  table_colors[color][3]);
733 }
void Brush(Color color)
Definition: scrollview.cpp:728

◆ Brush() [2/3]

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

Definition at line 627 of file scrollview.cpp.

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

◆ Brush() [3/3]

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

Definition at line 632 of file scrollview.cpp.

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

◆ Clear()

void ScrollView::Clear ( )

Definition at line 591 of file scrollview.cpp.

591  {
592  SendMsg("clear()");
593 }
void SendMsg(const char *msg,...)
Send a message to the server, attaching the window id.
Definition: scrollview.cpp:393

◆ DrawTo()

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

Definition at line 527 of file scrollview.cpp.

527  {
528  points_->xcoords.push_back(x);
529  points_->ycoords.push_back(TranslateYCoordinate(y));
530  points_->empty = false;
531 }
int TranslateYCoordinate(int y)
Definition: scrollview.cpp:830
std::vector< int > ycoords
Definition: scrollview.cpp:50
std::vector< int > xcoords
Definition: scrollview.cpp:49

◆ Ellipse()

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

Definition at line 611 of file scrollview.cpp.

611  {
612  SendMsg("drawEllipse(%d,%d,%u,%u)",
613  x1, TranslateYCoordinate(y1), width, height);
614 }
int TranslateYCoordinate(int y)
Definition: scrollview.cpp:830
void SendMsg(const char *msg,...)
Send a message to the server, attaching the window id.
Definition: scrollview.cpp:393

◆ Exit()

void ScrollView::Exit ( )
static

Definition at line 585 of file scrollview.cpp.

585  {
586  SendRawMessage("svmain:exit()");
587  exit(0);
588 }
static void SendRawMessage(const char *msg)
Definition: scrollview.cpp:411

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

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

◆ Image() [2/2]

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

Definition at line 659 of file scrollview.cpp.

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

◆ Line()

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

Definition at line 534 of file scrollview.cpp.

534  {
535  if (!points_->xcoords.empty() && x1 == points_->xcoords.back() &&
536  TranslateYCoordinate(y1) == points_->ycoords.back()) {
537  // We are already at x1, y1, so just draw to x2, y2.
538  DrawTo(x2, y2);
539  } else if (!points_->xcoords.empty() && x2 == points_->xcoords.back() &&
540  TranslateYCoordinate(y2) == points_->ycoords.back()) {
541  // We are already at x2, y2, so just draw to x1, y1.
542  DrawTo(x1, y1);
543  } else {
544  // This is a new line.
545  SetCursor(x1, y1);
546  DrawTo(x2, y2);
547  }
548 }
void DrawTo(int x, int y)
Definition: scrollview.cpp:527
int TranslateYCoordinate(int y)
Definition: scrollview.cpp:830
void SetCursor(int x, int y)
Definition: scrollview.cpp:521
std::vector< int > ycoords
Definition: scrollview.cpp:50
std::vector< int > xcoords
Definition: scrollview.cpp:49

◆ MenuItem() [1/3]

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

Definition at line 682 of file scrollview.cpp.

682  {
683  if (parent == nullptr) { parent = ""; }
684  SendMsg("addMenuBarItem('%s','%s')", parent, name);
685 }
void SendMsg(const char *msg,...)
Send a message to the server, attaching the window id.
Definition: scrollview.cpp:393

◆ MenuItem() [2/3]

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

Definition at line 676 of file scrollview.cpp.

676  {
677  if (parent == nullptr) { parent = ""; }
678  SendMsg("addMenuBarItem('%s','%s',%d)", parent, name, cmdEvent);
679 }
void SendMsg(const char *msg,...)
Send a message to the server, attaching the window id.
Definition: scrollview.cpp:393

◆ MenuItem() [3/3]

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

Definition at line 666 of file scrollview.cpp.

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

◆ Pen() [1/3]

void ScrollView::Pen ( Color  color)

Definition at line 722 of file scrollview.cpp.

722  {
723  Pen(table_colors[color][0], table_colors[color][1],
724  table_colors[color][2], table_colors[color][3]);
725 }
void Pen(Color color)
Definition: scrollview.cpp:722

◆ Pen() [2/3]

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

Definition at line 617 of file scrollview.cpp.

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

◆ Pen() [3/3]

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

Definition at line 622 of file scrollview.cpp.

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

◆ PopupItem() [1/2]

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

Definition at line 688 of file scrollview.cpp.

688  {
689  if (parent == nullptr) { parent = ""; }
690  SendMsg("addPopupMenuItem('%s','%s')", parent, name);
691 }
void SendMsg(const char *msg,...)
Send a message to the server, attaching the window id.
Definition: scrollview.cpp:393

◆ PopupItem() [2/2]

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

Definition at line 694 of file scrollview.cpp.

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

◆ Rectangle()

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

Definition at line 602 of file scrollview.cpp.

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

◆ SendMsg()

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

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

Definition at line 393 of file scrollview.cpp.

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

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

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

◆ SetCursor()

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

Definition at line 521 of file scrollview.cpp.

521  {
522  SendPolygon();
523  DrawTo(x, y);
524 }
void DrawTo(int x, int y)
Definition: scrollview.cpp:527

◆ SetVisible()

void ScrollView::SetVisible ( bool  visible)

Definition at line 551 of file scrollview.cpp.

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

◆ ShowInputDialog()

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

Definition at line 736 of file scrollview.cpp.

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

◆ ShowYesNoDialog()

int ScrollView::ShowYesNoDialog ( const char *  msg)

Definition at line 748 of file scrollview.cpp.

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

◆ Stroke()

void ScrollView::Stroke ( float  width)

Definition at line 596 of file scrollview.cpp.

596  {
597  SendMsg("setStrokeWidth(%f)", width);
598 }
void SendMsg(const char *msg,...)
Send a message to the server, attaching the window id.
Definition: scrollview.cpp:393

◆ Text()

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

Definition at line 654 of file scrollview.cpp.

654  {
655  SendMsg("drawText(%d,%d,'%s')", x, TranslateYCoordinate(y), mystring);
656 }
int TranslateYCoordinate(int y)
Definition: scrollview.cpp:830
void SendMsg(const char *msg,...)
Send a message to the server, attaching the window id.
Definition: scrollview.cpp:393

◆ TextAttributes()

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

Definition at line 637 of file scrollview.cpp.

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

◆ TranslateYCoordinate()

int ScrollView::TranslateYCoordinate ( int  y)

Definition at line 830 of file scrollview.cpp.

830  {
831  if (!y_axis_is_reversed_) { return y;
832  } else { return y_size_ - y; }
833 }

◆ Update()

void ScrollView::Update ( )
static

Definition at line 711 of file scrollview.cpp.

711  {
712  svmap_mu->Lock();
713  for (std::map<int, ScrollView*>::iterator iter = svmap.begin();
714  iter != svmap.end(); ++iter) {
715  if (iter->second != nullptr)
716  iter->second->UpdateWindow();
717  }
718  svmap_mu->Unlock();
719 }
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 706 of file scrollview.cpp.

706  {
707  SendMsg("update()");
708 }
void SendMsg(const char *msg,...)
Send a message to the server, attaching the window id.
Definition: scrollview.cpp:393

◆ ZoomToRectangle()

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

Definition at line 760 of file scrollview.cpp.

760  {
761  y1 = TranslateYCoordinate(y1);
762  y2 = TranslateYCoordinate(y2);
763  SendMsg("zoomRectangle(%d,%d,%d,%d)",
764  std::min(x1, x2), std::min(y1, y2), std::max(x1, x2), std::max(y1, y2));
765 }
int TranslateYCoordinate(int y)
Definition: scrollview.cpp:830
void SendMsg(const char *msg,...)
Send a message to the server, attaching the window id.
Definition: scrollview.cpp:393

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