A slider's default, put back by a double click (headless).
A slider's default, put back by a double click (headless). "Double click a slider to reset it" is a convention every editor has, and every host implemented it again for each slider it remembered, from n_gui_double_clicked_widget(), and forgot a few. n_gui_slider_set_default() gives the slider its default once; the double click then sets it, calls on_change as a drag would, and ends the drag the second press began, so a pointer that moves before the release does not drag the handle away again.
#define ALLEGRO_UNSTABLE 1
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
if (!cond) {
} else {
}
}
static void on_change(
int widget_id,
double value,
void* user_data) {
(void)widget_id;
(void)user_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 win, with, without;
double def = 0.0, at_click = 0.0;
if (!al_init() || !al_init_font_addon()) {
return 1;
}
font = al_create_builtin_font();
return 1;
}
return 1;
}
with =
n_gui_add_slider(
gui, win, 0.0f, 0.0f, 300.0f, 30.0f, 0.0, 100.0, 50.0,
N_GUI_SLIDER_VALUE,
on_change, NULL);
without =
n_gui_add_slider(
gui, win, 0.0f, 60.0f, 300.0f, 30.0f, 0.0, 100.0, 50.0,
N_GUI_SLIDER_VALUE,
on_change, NULL);
return 1;
}
return 0;
}
static void expect_true(const char *label, int cond)
static int changes
how many times the picker called back, and with what
static void on_change(const float rgba[4], void *user_data)
the picker's callback
static void press_at(N_GUI_CTX *gui, float x, float y)
add a value only when it is not in the list yet, the way a filter built from data does,...
static ALLEGRO_EVENT mouse_event(int type, int x, int y, int dz)
Build a left-button mouse event at (x, y).
static double last_value
how many times the picker called back, and with what
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_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_slider_get_default(N_GUI_CTX *ctx, int widget_id, double *value)
read a slider's default
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_slider_set_default(N_GUI_CTX *ctx, int widget_id, double value)
give a slider the value a double click on it puts back
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.
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.