18 w.
mb= 0; w.mx= 0; w.
my= 0;
39 if(mouse.state == SDL_PRESSED)
48 if(wheel.x != 0 || wheel.y != 0)
58 if(key.type == SDL_KEYDOWN)
61 w.
key= key.keysym.sym;
62 w.
mod= key.keysym.mod;
84 if(input.text[0] != 0)
99 bool overlap(
const Rect r,
const int x,
const int y )
101 return (x >= r.x && x < r.x + r.w && y >= r.y && y < r.y + r.h);
105 Rect place(
Widgets& w,
const int width,
const int height= 1 )
126 return place(w, (
int) strlen(text));
144 char tmp[4096] = { 0 };
147 va_start(args, format);
148 vsnprintf(tmp,
sizeof(tmp), format, args);
151 Rect r= place(w, tmp);
157 Rect r= place(w, (
int) strlen(text) +2);
160 if(w.
mb > 0 && overlap(r, w.mx, w.
my))
163 status= (status + 1) % 2;
167 sprintf(tmp,
"%c %s", (status != 0) ? 22 : 20, text);
175 Rect r= place(w, (
int) strlen(text) +2);
178 if(w.
mb > 0 && overlap(r, w.mx, w.
my))
185 sprintf(tmp,
"%c %s", (status == option) ? 4 : 3, text);
196 Rect r= place(w, (
int) strlen(tmp));
199 if(w.
mb > 0 && overlap(r, w.mx, w.
my))
201 if(overlap(r, w.mx, w.
my))
207 if(w.
key == SDLK_PAGEUP)
209 if(w.
key == SDLK_DOWN)
211 if(w.
key == SDLK_PAGEDOWN)
214 if(
value < value_min)
216 if(
value > value_max)
219 sprintf(tmp,
"%s: ",
label);
220 int l= (int) strlen(tmp);
223 sprintf(tmp,
"%4d",
value);
232 bool value(
Widgets& w,
const char *
label,
float&
value,
const float value_min,
const float value_max,
const float value_step )
237 Rect r= place(w, (
int) strlen(tmp));
240 if(w.
mb > 0 && overlap(r, w.mx, w.
my))
242 if(overlap(r, w.mx, w.
my))
248 if(w.
key == SDLK_PAGEUP)
250 if(w.
key == SDLK_DOWN)
252 if(w.
key == SDLK_PAGEDOWN)
255 if(
value < value_min)
257 if(
value > value_max)
260 sprintf(tmp,
"%s: ",
label);
261 int l= (int) strlen(tmp);
264 sprintf(tmp,
"%.6f",
value);
275 Rect r= place(w, 128, height);
277 if(overlap(r, w.mx, w.
my))
281 if(w.
key == SDLK_PAGEUP)
283 if(w.
key == SDLK_PAGEDOWN)
285 if(w.
key == SDLK_SPACE)
289 if(w.
key == SDLK_DOWN)
295 for(
int i= 0; text[i] != 0; i++)
306 for(
int i= 0; text[i] != 0; i++)
321 assert(text_size > 1);
322 int size=
std::min((
int) strlen(text), text_size -2);
323 Rect r= place(w, text_size -1);
329 if(overlap(r, w.mx, w.
my))
335 if(w.fx >= r.x + size)
340 change= (w.
focus > 0);
344 bool focus= overlap(r, w.fx, w.
fy);
345 if(focus && w.
key > 0)
348 assert(c < text_size -1);
350 if(w.
key == SDLK_BACKSPACE)
353 for(
int i= c -1; i >= 0 && i+1 < text_size; i++) text[i]= text[i+1];
355 else if(w.
key == SDLK_DELETE)
358 for(
int i= c; i+1 < text_size; i++) text[i]= text[i+1];
360 else if(w.
key == SDLK_LEFT)
364 else if(w.
key == SDLK_RIGHT)
368 else if(w.
key == SDLK_RETURN)
376 for(
int i= text_size -1; i > c; i--) text[i]= text[i -1];
379 if(size < text_size - 2)
387 if(w.fx >= r.x + size)
393 for(; text[i] != 0; i++) tmp[i]= text[i];
394 for(; i < text_size; i++) tmp[i]=
' ';
395 tmp[text_size -1]= 0;
void begin(Widgets &w)
debut de la description des elements de l'interface graphique.
void clear(Text &text)
efface le contenu de la console.
Widgets create_widgets()
cree une interface graphique. a detruire avec release_widgets( ).
void release_widgets(Widgets &w)
detruit l'interface graphique.
SDL_MouseButtonEvent button_event()
renvoie le dernier evenement. etat des boutons de la souris.
bool button(Widgets &w, const char *text, int &status)
void clear_button_event()
desactive l'evenement.
void label(Widgets &w, const char *format,...)
cree un texte. meme fonctionnement que printf().
SDL_TextInputEvent text_event()
renvoie le dernier evenement. saisie de texte.
bool value(Widgets &w, const char *label, int &value, const int value_min, const int value_max, const int value_step)
valeur editable par increment.
void clear_key_event()
desactive l'evenement.
SDL_KeyboardEvent key_event()
renvoie le dernier evenement. touche speciales.
void end_line(Widgets &widgets)
termine la description des elements de la ligne.
bool select(Widgets &w, const char *text, const int option, int &status)
bool edit(Widgets &w, int text_size, char *text)
void clear_text_event()
desactive l'evenement.
void clear_wheel_event()
desactive l'evenement.
void end(Widgets &w)
termine la description des elements de l'interface graphique.
Text create_text()
cree une console. a detruire avec release_text( ).
void print(Text &text, const int px, const int py, const char *message)
affiche un texte a la position x, y.
void draw(Widgets &w, const int width, const int height)
affiche les elements decrits entre begin() et end().
void text_area(Widgets &w, const int height, const char *text, int &begin_line)
void begin_line(Widgets &w)
place les prochains elements sur une nouvelle ligne.
void release_text(Text &text)
detruit une console.
SDL_MouseWheelEvent wheel_event()
renvoie le dernier evenement. etat de la molette de la souris / glisser sur le pad.
void print_background(Text &text, const int px, const int py, const int background, const char c)
affiche un caractere c sur un fond background.
void default_color(Widgets &w, const Color &color)
choisit une couleur par defaut pour le texte.
Point min(const Point &a, const Point &b)
renvoie la plus petite composante de chaque point. x, y, z= min(a.x, b.x), min(a.y,...
representation d'une couleur (rgba) transparente ou opaque.