Double click reporting (headless).
Double click reporting (headless). The toolkit routes presses to widgets and knows which widget each one landed on, which is everything a double click needs, and it did not report one. Every program wanting the gesture kept its own clock and its own last-widget, and got the radius test right or, more often, left it out and then wondered why a double click fired in the middle of a drag.
#define ALLEGRO_UNSTABLE 1
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
if (!cond) {
} else {
}
}
ALLEGRO_EVENT ev;
memset(&ev, 0, sizeof(ev));
ev.type = (
unsigned int)
type;
ev.mouse.x = x;
ev.mouse.y = y;
ev.mouse.button = 1;
return ev;
}
}
int got;
return got;
}
int win, a, b;
if (!al_init() || !al_init_font_addon()) {
return 1;
}
font = al_create_builtin_font();
return 1;
}
return 1;
}
expect_true(
"a third press is not another double click",
expect_true(
"a press on another widget is not a double click",
expect_true(
"two presses too far apart are not a double click",
expect_true(
"but a couple of pixels of hand movement still counts",
expect_true(
"a radius of zero refuses one pixel of movement",
return 1;
}
return 0;
}
static void expect_true(const char *label, int cond)
static ALLEGRO_EVENT mouse_event(int type, int x, int y, int dz)
Build a left-button mouse event at (x, y).
static void click_at(N_GUI_CTX *gui, int x, int y)
Move to (x, y) and click there.
static int click_and_report(N_GUI_CTX *gui, int x, int y)
Press the primary button at (x, y) and report the double click.
static void type(N_GUI_CTX *gui, const char *s)
Type a whole string into whatever has focus.
FONT * font
the default 8x8 font, valid after allegro_init()
void n_gui_set_display_size(N_GUI_CTX *ctx, float w, float h)
set the display (viewport) size so global scrollbars can be computed.
int n_gui_process_event(N_GUI_CTX *ctx, ALLEGRO_EVENT event)
Process an allegro event through the GUI system.
#define N_GUI_WIN_FRAMELESS
frameless window: no title bar drawn, drag via window body unless N_GUI_WIN_FIXED_POSITION is also se...
void n_gui_set_double_click_time(N_GUI_CTX *ctx, double seconds)
set how long after a press a second one still counts as a double click
int n_gui_double_clicked_widget(const N_GUI_CTX *ctx)
id of the widget the primary press just processed double clicked
void n_gui_set_double_click_radius(N_GUI_CTX *ctx, int pixels)
set how far the pointer may move between the two presses
int n_gui_add_window(N_GUI_CTX *ctx, const char *title, float x, float y, float w, float h)
Add a new pseudo-window to the context.
N_GUI_CTX * n_gui_new_ctx(ALLEGRO_FONT *default_font)
Create a new GUI context.
void n_gui_destroy_ctx(N_GUI_CTX **ctx)
Destroy a GUI context and all its windows/widgets.
void n_gui_open_window(N_GUI_CTX *ctx, int window_id)
Open (show) a window.
void n_gui_window_set_flags(N_GUI_CTX *ctx, int window_id, int flags)
Set feature flags on a window.
int n_gui_was_double_click(const N_GUI_CTX *ctx, int widget_id)
whether the press just processed double clicked this widget
#define N_GUI_SHAPE_RECT
rectangle shape (default)
int n_gui_add_button(N_GUI_CTX *ctx, int window_id, const char *label, float x, float y, float w, float h, int shape, void(*on_click)(int, void *), void *user_data)
Add a button widget to a window.
The top-level GUI context that holds all windows.
#define n_log(__LEVEL__,...)
Logging function wrapper to get line and func.
#define LOG_ERR
error conditions
void set_log_level(const int log_level)
Set the global log level value ( static int LOG_LEVEL ).
#define LOG_NOTICE
normal but significant condition
#define LOG_INFO
informational
Common headers and low-level functions & define.
GUI system: buttons, sliders, text areas, checkboxes, scrollbars, dropdown menus, windows.