A press on a widget in a movable frameless window is not a window drag (headless).
A press on a widget in a movable frameless window is not a window drag (headless). A frameless window without N_GUI_WIN_FIXED_POSITION is dragged by its body. The press handler used to start that drag after handing the press to the widget under the pointer, so a press on a slider started both: the window then followed the pointer exactly, the slider's position inside its own window never changed, and the slider did not move at all. The same held for a scrollbar and for anything else that is dragged.
The rule now is that a press a widget took is not a window drag. A press on the empty body still is, and so is a press on a widget that does nothing with a press - here an image - so a window made mostly of pictures can still be moved.
#define ALLEGRO_UNSTABLE 1
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
if (!cond) {
} else {
}
}
static void on_slider(
int id,
double value,
void* data) {
(void)id;
(void)value;
(void)data;
}
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 i = 0;
for (i = 1; i <= 3; i++) {
}
}
ALLEGRO_BITMAP* pic;
int win, slider;
double before;
if (!al_init() || !al_init_font_addon()) {
return 1;
}
font = al_create_builtin_font();
return 1;
}
al_set_new_bitmap_flags(ALLEGRO_MEMORY_BITMAP);
pic = al_create_bitmap(16, 16);
if (!pic) {
return 1;
}
al_destroy_bitmap(pic);
return 1;
}
if (!w) {
al_destroy_bitmap(pic);
return 1;
}
expect_true(
"a drag on a slider leaves the window where it was",
w->
x == 0.0f && w->
y == 0.0f);
expect_true(
"a drag on the empty body moves the window", w->
x == 30.0f && w->
y == 0.0f);
expect_true(
"a drag on an image moves the window", w->
x == 60.0f);
al_destroy_bitmap(pic);
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 int slider_changes
How many times the slider's callback fired.
static void drag_right(N_GUI_CTX *gui, int x, int y, int step)
Press at (x, y), move right in three steps of step with the button held, and release where the pointe...
static void on_slider(int id, double value, void *data)
Slider callback: counts the changes it is told about.
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()
float x
position x on screen
float y
position y on screen
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.
#define N_GUI_IMAGE_FIT
scale to fit within bounds, keep aspect ratio
int n_gui_add_slider(N_GUI_CTX *ctx, int window_id, float x, float y, float w, float h, double min_val, double max_val, double initial, int mode, void(*on_change)(int, double, void *), void *user_data)
Add a slider widget.
#define N_GUI_SLIDER_VALUE
slider uses raw start/end values
int n_gui_process_event(N_GUI_CTX *ctx, ALLEGRO_EVENT event)
Process an allegro event through the GUI system.
double n_gui_slider_get_value(N_GUI_CTX *ctx, int widget_id)
get the current value of a slider widget
#define N_GUI_WIN_FRAMELESS
frameless window: no title bar drawn, drag via window body unless N_GUI_WIN_FIXED_POSITION is also se...
int n_gui_add_image(N_GUI_CTX *ctx, int window_id, float x, float y, float w, float h, ALLEGRO_BITMAP *bitmap, int scale_mode)
Add an image display widget.
N_GUI_WINDOW * n_gui_get_window(N_GUI_CTX *ctx, int window_id)
Get a window pointer by id.
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_slider_set_value(N_GUI_CTX *ctx, int widget_id, double value)
set the value of a slider widget
void n_gui_window_set_flags(N_GUI_CTX *ctx, int window_id, int flags)
Set feature flags on a window.
The top-level GUI context that holds all windows.
A pseudo window that contains widgets.
#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.