summaryrefslogtreecommitdiff
path: root/test/penpal.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'test/penpal.cxx')
-rw-r--r--test/penpal.cxx93
1 files changed, 54 insertions, 39 deletions
diff --git a/test/penpal.cxx b/test/penpal.cxx
index eec1307bb..1b0373abb 100644
--- a/test/penpal.cxx
+++ b/test/penpal.cxx
@@ -15,7 +15,7 @@
//
// The Penpal test app is here to test pen/stylus/tablet event distribution
-// in the Fl::Pen driver. Our main window has three canvases for drawing.
+// in the Fl_Pen driver. Our main window has three canvases for drawing.
// The first canvas is a child of the main window. The second canvas is
// inside a group. The third canvas is a subwindow inside the main window.
// A second application window is itself yet another canvas.
@@ -23,8 +23,8 @@
// We can test if the events are delivered to the right receiver, if the
// mouse and pen offsets are correct. The pen implementation also reacts
// to pen pressure and angles. If handle() returns 1 when receiving
-// Fl::Pen::ENTER, the event handler should not send any mouse events until
-// Fl::Pen::LEAVE.
+// FL_PEN_ENTER, the event handler should not send any mouse events until
+// FL_PEN_LEAVE.
#include <FL/Fl.H>
#include <FL/Fl_Window.H>
@@ -34,6 +34,7 @@
#include <FL/fl_draw.H>
#include <FL/fl_message.H>
#include <FL/names.h>
+#include <FL/core/pen_events.H>
extern Fl_Menu_Item app_menu[];
extern int popup_app_menu();
@@ -79,24 +80,24 @@ int CanvasInterface::cv_handle(int event)
switch (event)
{
// Event handling for pen events:
- case Fl::Pen::ENTER: // Return 1 to receive all pen events and suppress mouse events
+ case FL_PEN_ENTER: // Return 1 to receive all pen events and suppress mouse events
// Pen entered the widget area.
color_++;
if (color_ > 6) color_ = 1;
/* fall through */
- case Fl::Pen::HOVER:
+ case FL_PEN_HOVER:
// Pen move over the surface without touching it.
overlay_ = PEN_HOVER;
ov_x_ = Fl::event_x();
ov_y_ = Fl::event_y();
widget_->redraw();
return 1;
- case Fl::Pen::TOUCH:
+ case FL_PEN_TOUCH:
// Pen tip or eraser just touched the surface.
- if (Fl::event_state(FL_CTRL) || Fl::Pen::event_state(Fl::Pen::State::BUTTON0))
+ if (Fl::event_state(FL_CTRL) || Fl_Pen_event_state_check(FL_PEN_STATE_BUTTON0))
return popup_app_menu();
/* fall through */
- case Fl::Pen::DRAW:
+ case FL_PEN_DRAW:
// Pen is dragged over the surface, or hovers with a button pressed.
overlay_ = PEN_DRAW;
ov_x_ = Fl::event_x();
@@ -104,10 +105,10 @@ int CanvasInterface::cv_handle(int event)
cv_pen_paint();
widget_->redraw();
return 1;
- case Fl::Pen::LIFT:
+ case FL_PEN_LIFT:
// Pen was just lifted from the surface and is now hovering
return 1;
- case Fl::Pen::LEAVE:
+ case FL_PEN_LEAVE:
// The pen left the drawing area.
overlay_ = NONE;
widget_->redraw();
@@ -164,7 +165,7 @@ void CanvasInterface::cv_draw()
// Preset values for overlay
int r = 10;
if (overlay_ == PEN_DRAW)
- r = static_cast<int>(32.0 * Fl::Pen::event_pressure());
+ r = (int)(32.0 * Fl_Pen_event_pressure());
fl_color(FL_BLACK);
switch (overlay_) {
case NONE: break;
@@ -180,8 +181,8 @@ void CanvasInterface::cv_draw()
/* fall through */
case DRAW:
fl_arc(ov_x_-r, ov_y_-r, 2*r, 2*r, 0, 360);
- fl_arc(ov_x_-r/2-40*Fl::Pen::event_tilt_x(),
- ov_y_-r/2-40*Fl::Pen::event_tilt_y(), r, r, 0, 360);
+ fl_arc(ov_x_-r/2-(int)(40*Fl_Pen_event_tilt_x()),
+ ov_y_-r/2-(int)(40*Fl_Pen_event_tilt_y()), r, r, 0, 360);
break;
}
}
@@ -205,9 +206,10 @@ void CanvasInterface::cv_paint() {
void CanvasInterface::cv_pen_paint() {
if (!offscreen_)
return;
- int r = static_cast<int>(32.0 * (Fl::Pen::event_pressure()*Fl::Pen::event_pressure()));
+ double p = Fl_Pen_event_pressure();
+ int r = (int)(32.0 * (p * p));
int dx = in_window_ ? 0 : widget_->x(), dy = in_window_ ? 0 : widget_->y();
- Fl_Color cc = Fl::Pen::event_state(Fl::Pen::State::ERASER_DOWN) ? FL_WHITE : color_;
+ Fl_Color cc = Fl_Pen_event_state_check(FL_PEN_STATE_ERASER_DOWN) ? FL_WHITE : color_;
fl_begin_offscreen(offscreen_);
fl_draw_circle(Fl::event_x()-dx-r, Fl::event_y()-dy-r, 2*r, cc);
fl_end_offscreen();
@@ -246,26 +248,37 @@ public:
void draw() { return cv_draw(); }
};
+// Menu callbacks (replacing lambdas)
+static void menu_modal_cb(Fl_Widget*, void*) {
+ fl_message("None of the canvas areas should receive\n"
+ "pen events while this window is open.");
+}
+
+static void menu_nonmodal_cb(Fl_Widget*, void*) {
+ Fl_Window *w = new Fl_Window(400, 32, "Toolbox");
+ w->set_non_modal();
+ w->show();
+}
+
+static void menu_unsubscribe_cb(Fl_Widget*, void*) {
+ if (cv1) Fl_Pen_unsubscribe(cv1);
+}
+
+static void menu_resubscribe_cb(Fl_Widget*, void*) {
+ if (cv1) Fl_Pen_subscribe(cv1);
+}
+
+static void menu_delete_cb(Fl_Widget*, void*) {
+ if (cv1) { cv1->top_window()->redraw(); delete cv1; cv1 = 0; }
+}
+
// A popup menu with a few test tasks.
Fl_Menu_Item app_menu[] = {
- { "with modal window", 0, [](Fl_Widget*, void*) {
- fl_message("None of the canvas areas should receive\n"
- "pen events while this window is open.");
- } },
- { "with non-modal window", 0, [](Fl_Widget*, void*) {
- Fl_Window *w = new Fl_Window(400, 32, "Toolbox");
- w->set_non_modal();
- w->show();
- } },
- { "unsubscribe middle canvas", 0, [](Fl_Widget*, void*) {
- if (cv1) Fl::Pen::unsubscribe(cv1);
- } },
- { "resubscribe middle canvas", 0, [](Fl_Widget*, void*) {
- if (cv1) Fl::Pen::subscribe(cv1);
- } },
- { "delete middle canvas", 0, [](Fl_Widget*, void*) {
- if (cv1) { cv1->top_window()->redraw(); delete cv1; cv1 = 0; }
- } },
+ { "with modal window", 0, menu_modal_cb },
+ { "with non-modal window", 0, menu_nonmodal_cb },
+ { "unsubscribe middle canvas", 0, menu_unsubscribe_cb },
+ { "resubscribe middle canvas", 0, menu_resubscribe_cb },
+ { "delete middle canvas", 0, menu_delete_cb },
{ 0 }
};
@@ -292,7 +305,8 @@ int main(int argc, char **argv)
// The second canvas is inside a group
Fl_Group *cv1_group = new Fl_Group(215, 5, 210, 210);
cv1_group->box(FL_FRAME_BOX);
- CanvasWidget *canvas_widget_1 = cv1 = new CanvasWidget(220, 10, 200, 200, "CV1");
+ CanvasWidget *canvas_widget_1 = new CanvasWidget(220, 10, 200, 200, "CV1");
+ cv1 = canvas_widget_1;
cv1_group->end();
// The third canvas is a window inside a window, so we can verify
@@ -303,13 +317,14 @@ int main(int argc, char **argv)
window->end();
// A fourth canvas is a top level window by itself.
- CanvasWindow *cv_window = cvwin = new CanvasWindow(100, 380, 200, 200, "Canvas Window");
+ CanvasWindow *cv_window = new CanvasWindow(100, 380, 200, 200, "Canvas Window");
+ cvwin = cv_window;
// All canvases subscribe to pen events.
- Fl::Pen::subscribe(canvas_widget_0);
- Fl::Pen::subscribe(canvas_widget_1);
- Fl::Pen::subscribe(canvas_widget_2);
- Fl::Pen::subscribe(cv_window);
+ Fl_Pen_subscribe(canvas_widget_0);
+ Fl_Pen_subscribe(canvas_widget_1);
+ Fl_Pen_subscribe(canvas_widget_2);
+ Fl_Pen_subscribe(cv_window);
window->show(argc, argv);
canvas_widget_2->show();