25# include "config_auto.h"
28#ifndef GRAPHICS_DISABLED
38static int rgb[3] = {255, 255, 255};
42 explicit SVPaint(
const char *server_name);
50 void PopupHandler(
const SVEvent *sv_event);
51 void MenuBarHandler(
const SVEvent *sv_event);
52 void ClickHandler(
const SVEvent *sv_event);
53 void SelectionHandler(
const SVEvent *sv_event);
68 bool has_start_point_;
79 root->AddChild(
"G", 2,
"255",
"Green Color Value?");
80 root->AddChild(
"B", 3,
"255",
"Blue Color Value?");
85SVMenuNode *SVPaint::BuildMenuBar() {
86 auto *root =
new SVMenuNode();
89 SVMenuNode *click = root->AddChild(
"Clicking");
90 SVMenuNode *drag = root->AddChild(
"Dragging");
93 click->AddChild(
"Point to Point Drawing",
95 click->AddChild(
"Point Drawing", 2);
96 click->AddChild(
"Text Drawing", 3);
97 drag->AddChild(
"Line Drawing", 4);
98 drag->AddChild(
"Rectangle Drawing", 5);
99 drag->AddChild(
"Ellipse Drawing", 6);
105void SVPaint::PopupHandler(
const SVEvent *sv_event) {
108 rgb[sv_event->command_id - 1] = atoi(sv_event->parameter);
109 window_->
Pen(rgb[0], rgb[1], rgb[2]);
115void SVPaint::MenuBarHandler(
const SVEvent *sv_event) {
116 if ((sv_event->command_id > 0) && (sv_event->command_id < 4)) {
117 click_mode_ = sv_event->command_id;
118 has_start_point_ =
false;
120 drag_mode_ = sv_event->command_id;
127void SVPaint::ClickHandler(
const SVEvent *sv_event) {
128 switch (click_mode_) {
130 if (has_start_point_) {
131 window_->
DrawTo(sv_event->x, sv_event->y);
133 has_start_point_ =
true;
134 window_->
SetCursor(sv_event->x, sv_event->y);
138 window_->
Line(sv_event->x, sv_event->y, sv_event->x, sv_event->y);
144 window_->
Text(sv_event->x, sv_event->y,
p);
153void SVPaint::SelectionHandler(
const SVEvent *sv_event) {
154 switch (drag_mode_) {
157 window_->
Line(sv_event->x, sv_event->y, sv_event->x - sv_event->x_size,
158 sv_event->y - sv_event->y_size);
161 window_->
Rectangle(sv_event->x, sv_event->y, sv_event->x - sv_event->x_size,
162 sv_event->y - sv_event->y_size);
165 window_->
Ellipse(sv_event->x - sv_event->x_size, sv_event->y - sv_event->y_size,
166 sv_event->x_size, sv_event->y_size);
175 ClickHandler(sv_event);
177 SelectionHandler(sv_event);
179 MenuBarHandler(sv_event);
181 PopupHandler(sv_event);
189 window_ =
new ScrollView(
"ScrollView Paint Example",
203 has_start_point_ =
false;
241int main(
int argc,
char **argv) {
242 const char *server_name;
244 server_name = argv[1];
246 server_name =
"localhost";
int main(int argc, char **argv)
SVPaint(const char *server_name)
void Notify(const SVEvent *sv_event) override
void Line(int x1, int y1, int x2, int y2)
char * ShowInputDialog(const char *msg)
std::unique_ptr< SVEvent > AwaitEvent(SVEventType type)
void Text(int x, int y, const char *mystring)
void SetVisible(bool visible)
void AddEventHandler(SVEventHandler *listener)
Add an Event Listener to this ScrollView Window.
void Rectangle(int x1, int y1, int x2, int y2)
void SetCursor(int x, int y)
void Ellipse(int x, int y, int width, int height)
void DrawTo(int x, int y)
void BuildMenu(ScrollView *sv, bool menu_bar=true)