X11 -> SDL2 + beginning of last abstraction layer
This commit is contained in:
parent
6f82dbf69c
commit
5c2ffcae38
318
gui.h
318
gui.h
@ -34,64 +34,22 @@ struct gui_vec2 {gui_float x,y;};
|
||||
struct gui_rect {gui_float x,y,w,h;};
|
||||
struct gui_key {gui_int down, clicked;};
|
||||
|
||||
enum gui_error {
|
||||
GUI_OK = 0x00,
|
||||
GUI_ERROR_NOMEM = 0x01,
|
||||
GUI_ERROR_INVAL = 0x02,
|
||||
GUI_ERROR_INVOP = 0x04
|
||||
struct gui_font_glyph {
|
||||
gui_ulong code;
|
||||
gui_float xadvance;
|
||||
gui_short width, height;
|
||||
gui_float xoff, yoff;
|
||||
struct gui_texCoord uv[2];
|
||||
};
|
||||
|
||||
struct gui_memory {
|
||||
void *memory;
|
||||
gui_size vertex_size;
|
||||
gui_size command_size;
|
||||
gui_size clip_size;
|
||||
};
|
||||
|
||||
struct gui_memory_status {
|
||||
gui_size vertexes_allocated;
|
||||
gui_size vertexes_needed;
|
||||
gui_size commands_allocated;
|
||||
gui_size commands_needed;
|
||||
gui_size clips_allocated;
|
||||
gui_size clips_needed;
|
||||
gui_size allocated;
|
||||
gui_size needed;
|
||||
};
|
||||
|
||||
struct gui_vertex {
|
||||
struct gui_vec2 pos;
|
||||
struct gui_texCoord uv;
|
||||
struct gui_color color;
|
||||
};
|
||||
|
||||
struct gui_draw_command {
|
||||
gui_size vertex_count;
|
||||
struct gui_rect clip_rect;
|
||||
struct gui_font {
|
||||
gui_float height;
|
||||
gui_float scale;
|
||||
gui_texture texture;
|
||||
};
|
||||
|
||||
struct gui_draw_buffer {
|
||||
struct gui_vertex *vertexes;
|
||||
gui_size vertex_capacity;
|
||||
gui_size vertex_size;
|
||||
gui_size vertex_needed;
|
||||
struct gui_draw_command *commands;
|
||||
gui_size command_capacity;
|
||||
gui_size command_size;
|
||||
gui_size command_needed;
|
||||
struct gui_rect *clips;
|
||||
gui_size clip_capacity;
|
||||
gui_size clip_size;
|
||||
gui_size clip_needed;
|
||||
};
|
||||
|
||||
struct gui_draw_call_list {
|
||||
void *memory;
|
||||
struct gui_vertex *vertexes;
|
||||
gui_size vertex_size;
|
||||
struct gui_draw_command *commands;
|
||||
gui_size command_size;
|
||||
struct gui_vec2 tex_size;
|
||||
gui_long glyph_count;
|
||||
struct gui_font_glyph *glyphes;
|
||||
const struct gui_font_glyph *fallback;
|
||||
};
|
||||
|
||||
enum gui_keys {
|
||||
@ -117,22 +75,71 @@ struct gui_input {
|
||||
struct gui_vec2 mouse_clicked_pos;
|
||||
};
|
||||
|
||||
struct gui_font_glyph {
|
||||
gui_ulong code;
|
||||
gui_float xadvance;
|
||||
gui_short width, height;
|
||||
gui_float xoff, yoff;
|
||||
struct gui_texCoord uv[2];
|
||||
enum gui_error {
|
||||
GUI_OK = 0x00,
|
||||
GUI_ERROR_NOMEM = 0x01,
|
||||
GUI_ERROR_INVAL = 0x02,
|
||||
GUI_ERROR_INVOP = 0x04
|
||||
};
|
||||
|
||||
struct gui_font {
|
||||
gui_float height;
|
||||
gui_float scale;
|
||||
struct gui_vertex {
|
||||
struct gui_vec2 pos;
|
||||
struct gui_texCoord uv;
|
||||
struct gui_color color;
|
||||
};
|
||||
|
||||
struct gui_draw_command {
|
||||
gui_size vertex_count;
|
||||
struct gui_rect clip_rect;
|
||||
gui_texture texture;
|
||||
struct gui_vec2 tex_size;
|
||||
gui_long glyph_count;
|
||||
struct gui_font_glyph *glyphes;
|
||||
const struct gui_font_glyph *fallback;
|
||||
};
|
||||
|
||||
struct gui_memory {
|
||||
void *memory;
|
||||
gui_size size;
|
||||
gui_size max_panels;
|
||||
gui_float vertex_percentage;
|
||||
gui_float command_percentage;
|
||||
gui_float clip_percentage;
|
||||
};
|
||||
|
||||
struct gui_memory_status {
|
||||
gui_size vertexes_allocated;
|
||||
gui_size vertexes_needed;
|
||||
gui_size commands_allocated;
|
||||
gui_size commands_needed;
|
||||
gui_size clips_allocated;
|
||||
gui_size clips_needed;
|
||||
gui_size allocated;
|
||||
gui_size needed;
|
||||
};
|
||||
|
||||
struct gui_draw_buffer {
|
||||
struct gui_vertex *vertexes;
|
||||
gui_size vertex_capacity;
|
||||
gui_size vertex_size;
|
||||
gui_size vertex_needed;
|
||||
struct gui_draw_command *commands;
|
||||
gui_size command_capacity;
|
||||
gui_size command_size;
|
||||
gui_size command_needed;
|
||||
struct gui_rect *clips;
|
||||
gui_size clip_capacity;
|
||||
gui_size clip_size;
|
||||
gui_size clip_needed;
|
||||
};
|
||||
|
||||
struct gui_draw_call_list {
|
||||
void *memory;
|
||||
struct gui_vertex *vertexes;
|
||||
gui_size vertex_size;
|
||||
struct gui_draw_command *commands;
|
||||
gui_size command_size;
|
||||
};
|
||||
|
||||
struct gui_output {
|
||||
struct gui_draw_call_list **list;
|
||||
gui_size list_size;
|
||||
};
|
||||
|
||||
struct gui_text {
|
||||
@ -269,7 +276,7 @@ struct gui_histo {
|
||||
struct gui_color highlight;
|
||||
};
|
||||
|
||||
enum gui_colors {
|
||||
enum gui_panel_colors {
|
||||
GUI_COLOR_TEXT,
|
||||
GUI_COLOR_PANEL,
|
||||
GUI_COLOR_BORDER,
|
||||
@ -326,6 +333,12 @@ enum gui_panel_flags {
|
||||
GUI_PANEL_HIDDEN = 0x40
|
||||
};
|
||||
|
||||
enum gui_win_flags {
|
||||
GUI_PANEL_SCALEABLE = 0x01,
|
||||
GUI_PANEL_MOVEABLE = 0x02,
|
||||
GUI_PANEL_OVERLAPPING = 0x03
|
||||
};
|
||||
|
||||
struct gui_panel {
|
||||
gui_flags flags;
|
||||
gui_float x, y;
|
||||
@ -352,88 +365,99 @@ void gui_input_char(struct gui_input *in, gui_glyph glyph);
|
||||
void gui_input_end(struct gui_input *in);
|
||||
|
||||
/* Output */
|
||||
void gui_begin(struct gui_draw_buffer *buf, const struct gui_memory *memory);
|
||||
void gui_end(struct gui_draw_buffer *buf, struct gui_draw_call_list *calls,
|
||||
struct gui_memory_status* status);
|
||||
void gui_output_begin(struct gui_draw_buffer *buf, const struct gui_memory *memory);
|
||||
void gui_output_end(struct gui_draw_buffer *buf, struct gui_draw_call_list *calls,
|
||||
struct gui_memory_status* status);
|
||||
|
||||
/* Widgets */
|
||||
void gui_text(struct gui_draw_buffer *buf, const struct gui_text *text,
|
||||
const struct gui_font *font);
|
||||
gui_size gui_text_wrap(struct gui_draw_buffer *buf, const struct gui_text *text,
|
||||
const struct gui_font *font);
|
||||
void gui_image(struct gui_draw_buffer *buf, const struct gui_image *image);
|
||||
gui_bool gui_button_text(struct gui_draw_buffer *buf, const struct gui_button *button,
|
||||
const char *text, gui_size len, const struct gui_font *font,
|
||||
const struct gui_input *in);
|
||||
gui_bool gui_button_triangle(struct gui_draw_buffer *buffer, struct gui_button* button,
|
||||
enum gui_heading heading, const struct gui_input *in);
|
||||
gui_bool gui_button_image(struct gui_draw_buffer *buffer, struct gui_button* button,
|
||||
gui_texture tex, struct gui_texCoord from, struct gui_texCoord to,
|
||||
const struct gui_input *in);
|
||||
gui_bool gui_toggle(struct gui_draw_buffer *buf, const struct gui_toggle *toggle,
|
||||
const struct gui_font *font, const struct gui_input *in);
|
||||
gui_float gui_slider(struct gui_draw_buffer *buf, const struct gui_slider *slider,
|
||||
const struct gui_input *in);
|
||||
gui_float gui_slider_vertical(struct gui_draw_buffer *buf,
|
||||
const struct gui_slider *slider, const struct gui_input *in);
|
||||
gui_size gui_progress(struct gui_draw_buffer *buf, const struct gui_progress *prog,
|
||||
const struct gui_input *in);
|
||||
gui_size gui_progress_vertical(struct gui_draw_buffer *buf, const struct gui_progress *prog,
|
||||
const struct gui_input *in);
|
||||
gui_bool gui_input(struct gui_draw_buffer *buf, gui_char *buffer, gui_size *length,
|
||||
const struct gui_input_field *input,
|
||||
const struct gui_font *font, const struct gui_input *in);
|
||||
gui_float gui_scroll(struct gui_draw_buffer *buf, const struct gui_scroll *scroll,
|
||||
const struct gui_input *in);
|
||||
gui_int gui_histo(struct gui_draw_buffer *buf, const struct gui_histo *histo,
|
||||
const struct gui_input *in);
|
||||
gui_int gui_plot(struct gui_draw_buffer *buf, const struct gui_plot *plot,
|
||||
const struct gui_input *in);
|
||||
void gui_widget_text(struct gui_draw_buffer*, const struct gui_text*,
|
||||
const struct gui_font*);
|
||||
gui_size gui_widget_text_wrap(struct gui_draw_buffer*, const struct gui_text*,
|
||||
const struct gui_font*);
|
||||
void gui_widget_image(struct gui_draw_buffer*, const struct gui_image*);
|
||||
gui_bool gui_widget_button_text(struct gui_draw_buffer*, const struct gui_button*,
|
||||
const char *text, gui_size len, const struct gui_font*,
|
||||
const struct gui_input*);
|
||||
gui_bool gui_widget_button_triangle(struct gui_draw_buffer*, struct gui_button*,
|
||||
enum gui_heading, const struct gui_input*);
|
||||
gui_bool gui_widget_button_image(struct gui_draw_buffer*, struct gui_button*,
|
||||
gui_texture, struct gui_texCoord from, struct gui_texCoord to,
|
||||
const struct gui_input*);
|
||||
gui_bool gui_widget_toggle(struct gui_draw_buffer*, const struct gui_toggle*,
|
||||
const struct gui_font*, const struct gui_input*);
|
||||
gui_float gui_widget_slider(struct gui_draw_buffer*, const struct gui_slider*,
|
||||
const struct gui_input*);
|
||||
gui_float gui_widget_slider_vertical(struct gui_draw_buffer*,
|
||||
const struct gui_slider*, const struct gui_input*);
|
||||
gui_size gui_widget_progress(struct gui_draw_buffer*, const struct gui_progress*,
|
||||
const struct gui_input*);
|
||||
gui_size gui_widget_progress_vertical(struct gui_draw_buffer *buf,
|
||||
const struct gui_progress*, const struct gui_input*);
|
||||
gui_bool gui_widget_input(struct gui_draw_buffer*, gui_char*, gui_size*,
|
||||
const struct gui_input_field*, const struct gui_font*,
|
||||
const struct gui_input*);
|
||||
gui_float gui_widget_scroll(struct gui_draw_buffer*, const struct gui_scroll*,
|
||||
const struct gui_input*);
|
||||
gui_int gui_widget_histo(struct gui_draw_buffer*, const struct gui_histo*,
|
||||
const struct gui_input*);
|
||||
gui_int gui_widget_plot(struct gui_draw_buffer*, const struct gui_plot*,
|
||||
const struct gui_input*);
|
||||
|
||||
/* Panel */
|
||||
void gui_default_config(struct gui_config *config);
|
||||
void gui_panel_init(struct gui_panel *panel, const struct gui_config *config,
|
||||
const struct gui_font *font, const struct gui_input *input);
|
||||
gui_bool gui_panel_begin(struct gui_panel *panel, struct gui_draw_buffer *buffer,
|
||||
const char *text, gui_float x, gui_float y, gui_float w,
|
||||
gui_float h, gui_flags flags);
|
||||
void gui_panel_layout(struct gui_panel *panel, gui_float height, gui_size cols);
|
||||
void gui_panel_seperator(struct gui_panel *panel, gui_size cols);
|
||||
void gui_panel_text(struct gui_panel *panel, const char *str, gui_size len);
|
||||
gui_bool gui_panel_check(struct gui_panel *p, const char *s, gui_size l, gui_bool a);
|
||||
gui_bool gui_panel_option(struct gui_panel *p, const char *s, gui_size l, gui_bool a);
|
||||
gui_bool gui_panel_button_text(struct gui_panel *panel, const char *str, gui_size len,
|
||||
enum gui_button_behavior behavior);
|
||||
gui_bool gui_panel_button_color(struct gui_panel *panel, const struct gui_color color,
|
||||
enum gui_button_behavior behavior);
|
||||
gui_bool gui_panel_button_triangle(struct gui_panel *panel, enum gui_heading heading,
|
||||
enum gui_button_behavior behavior);
|
||||
gui_bool gui_panel_button_image(struct gui_panel *panel, gui_texture tex,
|
||||
struct gui_texCoord from, struct gui_texCoord to,
|
||||
enum gui_button_behavior behavior);
|
||||
gui_bool gui_panel_button_toggle(struct gui_panel *panel, const char *str, gui_size len,
|
||||
gui_bool value);
|
||||
gui_float gui_panel_slider(struct gui_panel *panel, gui_float min, gui_float val,
|
||||
gui_float max, gui_float step, enum gui_direction d);
|
||||
gui_size gui_panel_progress(struct gui_panel *panel, gui_size cur, gui_size max,
|
||||
gui_bool modifyable, enum gui_direction d);
|
||||
gui_bool gui_panel_input(struct gui_panel *panel, gui_char *buffer, gui_size *len,
|
||||
gui_size max, enum gui_input_filter filter, gui_bool active);
|
||||
gui_size gui_panel_command(struct gui_panel *panel, gui_char *buffer, gui_size *length,
|
||||
gui_size max, gui_bool *active);
|
||||
gui_bool gui_panel_spinner(struct gui_panel *panel, gui_int min, gui_int *value,
|
||||
gui_int max, gui_int step, gui_bool active);
|
||||
gui_size gui_panel_selector(struct gui_panel *panel, const char *items[],
|
||||
gui_size item_count, gui_size item_current);
|
||||
gui_int gui_panel_plot(struct gui_panel *panel, const gui_float *values,
|
||||
gui_size value_count);
|
||||
gui_int gui_panel_histo(struct gui_panel *panel, const gui_float *values,
|
||||
gui_size value_count);
|
||||
gui_float gui_panel_list(struct gui_panel *panel, gui_bool *selected, const char *items[],
|
||||
gui_size item_count, gui_float offset, gui_float item_height);
|
||||
void gui_default_config(struct gui_config*);
|
||||
void gui_panel_init(struct gui_panel*, const struct gui_config*,
|
||||
const struct gui_font*);
|
||||
gui_bool gui_panel_begin(struct gui_panel*, struct gui_draw_buffer*,
|
||||
const struct gui_input*, const char*,
|
||||
gui_float x, gui_float y, gui_float w, gui_float h, gui_flags);
|
||||
void gui_panel_layout(struct gui_panel*, gui_float height, gui_size cols);
|
||||
void gui_panel_seperator(struct gui_panel*, gui_size cols);
|
||||
void gui_panel_text(struct gui_panel*, const char *str, gui_size len);
|
||||
gui_bool gui_panel_check(struct gui_panel*, const char*, gui_size, gui_bool active);
|
||||
gui_bool gui_panel_option(struct gui_panel*, const char*, gui_size, gui_bool active);
|
||||
gui_bool gui_panel_button_text(struct gui_panel*, const char*, gui_size,
|
||||
enum gui_button_behavior);
|
||||
gui_bool gui_panel_button_color(struct gui_panel*, const struct gui_color,
|
||||
enum gui_button_behavior);
|
||||
gui_bool gui_panel_button_triangle(struct gui_panel*, enum gui_heading,
|
||||
enum gui_button_behavior);
|
||||
gui_bool gui_panel_button_image(struct gui_panel*, gui_texture,
|
||||
struct gui_texCoord from, struct gui_texCoord to,
|
||||
enum gui_button_behavior);
|
||||
gui_bool gui_panel_button_toggle(struct gui_panel*, const char*, gui_size,
|
||||
gui_bool value);
|
||||
gui_float gui_panel_slider(struct gui_panel*, gui_float min, gui_float val,
|
||||
gui_float max, gui_float step, enum gui_direction);
|
||||
gui_size gui_panel_progress(struct gui_panel*, gui_size cur, gui_size max,
|
||||
gui_bool modifyable, enum gui_direction);
|
||||
gui_bool gui_panel_input(struct gui_panel*, gui_char *buffer, gui_size *len,
|
||||
gui_size max, enum gui_input_filter, gui_bool active);
|
||||
gui_size gui_panel_command(struct gui_panel*, gui_char *buffer, gui_size *length,
|
||||
gui_size max, gui_bool *active);
|
||||
gui_bool gui_panel_spinner(struct gui_panel*, gui_int min, gui_int *value,
|
||||
gui_int max, gui_int step, gui_bool active);
|
||||
gui_size gui_panel_selector(struct gui_panel*, const char *items[],
|
||||
gui_size item_count, gui_size item_current);
|
||||
gui_int gui_panel_plot(struct gui_panel*, const gui_float *values,
|
||||
gui_size value_count);
|
||||
gui_int gui_panel_histo(struct gui_panel*, const gui_float *values,
|
||||
gui_size value_count);
|
||||
gui_float gui_panel_list(struct gui_panel*, gui_bool *selected, const char *items[],
|
||||
gui_size item_count, gui_float offset, gui_float item_height);
|
||||
void gui_panel_frame_begin(struct gui_panel *panel, struct gui_panel *tab, const char *title);
|
||||
void gui_panel_frame_end(struct gui_panel *tab);
|
||||
void gui_panel_hook(struct gui_panel *panel, struct gui_panel *tab);
|
||||
gui_uint gui_panel_end(struct gui_panel *panel);
|
||||
void gui_panel_frame_end(struct gui_panel*);
|
||||
gui_uint gui_panel_end(struct gui_panel*);
|
||||
|
||||
/* Context */
|
||||
struct gui_context;
|
||||
struct gui_context *gui_new(const struct gui_memory*, const struct gui_input*);
|
||||
void gui_begin(struct gui_context*, gui_float width, gui_float height);
|
||||
void gui_end(struct gui_context*, struct gui_output*, struct gui_memory_status*);
|
||||
struct gui_panel *gui_panel_new(struct gui_context*,
|
||||
gui_float x, gui_float y, gui_float w, gui_float h, gui_flags,
|
||||
const struct gui_config* , const struct gui_font*);
|
||||
void gui_panel_del(struct gui_context*, struct gui_panel*);
|
||||
gui_bool gui_begin_panel(struct gui_context*, struct gui_panel*, const char *title, gui_flags flags);
|
||||
void gui_end_panel(struct gui_context*, struct gui_panel*, struct gui_memory_status*);
|
||||
|
||||
#endif
|
||||
|
438
opengl.c
438
opengl.c
@ -6,102 +6,35 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdarg.h>
|
||||
#include <limits.h>
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
#include <memory.h>
|
||||
#include <assert.h>
|
||||
#include <time.h>
|
||||
#include <errno.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/select.h>
|
||||
#include <sys/time.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <X11/Xlib.h>
|
||||
#include <X11/Xutil.h>
|
||||
#include <GL/gl.h>
|
||||
#include <GL/glx.h>
|
||||
#include <GL/glu.h>
|
||||
#include <SDL2/SDL.h>
|
||||
|
||||
#include "gui.h"
|
||||
|
||||
/* ---- TODO ------
|
||||
* - Font loading
|
||||
* - X11 -> SDL
|
||||
*/
|
||||
|
||||
/* macros */
|
||||
#define WIN_WIDTH 800
|
||||
#define WIN_HEIGHT 600
|
||||
#define DTIME 33
|
||||
#define MAX_BUFFER (64 * 1024)
|
||||
#define INPUT_MAX 64
|
||||
#define MAX_BUFFER (256 * 1024)
|
||||
#define MAX_PANELS 4
|
||||
|
||||
#define LEN(a)(sizeof(a)/sizeof(a)[0])
|
||||
#define UNUSED(a)((void)(a))
|
||||
|
||||
/* types */
|
||||
struct XWindow {
|
||||
Window root;
|
||||
Display *dpy;
|
||||
XVisualInfo *vi;
|
||||
Colormap cmap;
|
||||
XSetWindowAttributes swa;
|
||||
XWindowAttributes gwa;
|
||||
Window win;
|
||||
GLXContext glc;
|
||||
gui_bool running;
|
||||
};
|
||||
|
||||
struct GUI {
|
||||
struct XWindow *win;
|
||||
struct gui_memory main;
|
||||
struct gui_memory combo;
|
||||
struct gui_memory_status status;
|
||||
struct gui_draw_buffer out;
|
||||
struct gui_draw_call_list draw_list;
|
||||
struct gui_input in;
|
||||
struct gui_font *font;
|
||||
struct gui_config config;
|
||||
struct gui_panel panel;
|
||||
struct gui_panel tab;
|
||||
gui_bool selection[6];
|
||||
gui_float seloff;
|
||||
|
||||
/* State */
|
||||
gui_char input_text[INPUT_MAX];
|
||||
gui_char cmd_input[INPUT_MAX];
|
||||
gui_size input_len;
|
||||
gui_size cmd_len;
|
||||
gui_bool typing;
|
||||
gui_float slider;
|
||||
gui_size prog;
|
||||
gui_size vprog;
|
||||
gui_size vprog2;
|
||||
gui_size vprog3;
|
||||
gui_int spinner;
|
||||
gui_bool check;
|
||||
gui_bool option;
|
||||
gui_bool spinning;
|
||||
gui_size submit;
|
||||
gui_bool submitting;
|
||||
gui_size select;
|
||||
};
|
||||
|
||||
/* functions */
|
||||
static void die(const char*,...);
|
||||
static void* xcalloc(size_t nmemb, size_t size);
|
||||
static long timestamp(void);
|
||||
static void sleep_for(long ms);
|
||||
static char* ldfile(const char*, int, size_t*);
|
||||
static char* ldfile(const char*, size_t*);
|
||||
|
||||
static void kpress(struct GUI*, XEvent*);
|
||||
static void bpress(struct GUI*, XEvent*);
|
||||
static void brelease(struct GUI*, XEvent*);
|
||||
static void bmotion(struct GUI*, XEvent*);
|
||||
static void resize(struct GUI*, XEvent*);
|
||||
static void kpress(struct gui_input*, SDL_Event*);
|
||||
static void bpress(struct gui_input*, SDL_Event*);
|
||||
static void brelease(struct gui_input*, SDL_Event*);
|
||||
static void bmotion(struct gui_input*, SDL_Event*);
|
||||
static GLuint ldbmp(gui_byte*, uint32_t*, uint32_t*);
|
||||
|
||||
/* gobals */
|
||||
@ -112,135 +45,99 @@ die(const char *fmt, ...)
|
||||
va_start(ap, fmt);
|
||||
vfprintf(stderr, fmt, ap);
|
||||
va_end(ap);
|
||||
exit(EXIT_FAILURE);
|
||||
SDL_Quit();
|
||||
exit(1);
|
||||
}
|
||||
|
||||
static void*
|
||||
xcalloc(size_t nmemb, size_t size)
|
||||
{
|
||||
void *p = calloc(nmemb, size);
|
||||
if (!p)
|
||||
die("out of memory\n");
|
||||
if (!p) die("out of memory\n");
|
||||
return p;
|
||||
}
|
||||
|
||||
static long
|
||||
timestamp(void)
|
||||
static void
|
||||
kpress(struct gui_input *in, SDL_Event* e)
|
||||
{
|
||||
struct timeval tv;
|
||||
if (gettimeofday(&tv, NULL) < 0) return 0;
|
||||
return (long)((long)tv.tv_sec * 1000 + (long)tv.tv_usec/1000);
|
||||
SDL_Keycode code = e->key.keysym.sym;
|
||||
if (code == SDLK_LCTRL || code == SDLK_RCTRL)
|
||||
gui_input_key(in, GUI_KEY_CTRL, gui_true);
|
||||
else if (code == SDLK_LSHIFT || code == SDLK_RSHIFT)
|
||||
gui_input_key(in, GUI_KEY_SHIFT, gui_true);
|
||||
else if (code == SDLK_DELETE)
|
||||
gui_input_key(in, GUI_KEY_DEL, gui_true);
|
||||
else if (code == SDLK_RETURN)
|
||||
gui_input_key(in, GUI_KEY_ENTER, gui_true);
|
||||
else if (code == SDLK_SPACE)
|
||||
gui_input_key(in, GUI_KEY_SPACE, gui_true);
|
||||
else if (code == SDLK_BACKSPACE)
|
||||
gui_input_key(in, GUI_KEY_BACKSPACE, gui_true);
|
||||
}
|
||||
|
||||
static void
|
||||
sleep_for(long t)
|
||||
krelease(struct gui_input *in, SDL_Event* e)
|
||||
{
|
||||
const time_t sec = (int)(t/1000);
|
||||
const long ms = t - (sec * 1000);
|
||||
struct timespec req;
|
||||
req.tv_sec = sec;
|
||||
req.tv_nsec = ms * 1000000L;
|
||||
while(-1 == nanosleep(&req, &req));
|
||||
SDL_Keycode code = e->key.keysym.sym;
|
||||
if (code == SDLK_LCTRL || code == SDLK_RCTRL)
|
||||
gui_input_key(in, GUI_KEY_CTRL, gui_false);
|
||||
else if (code == SDLK_LSHIFT || code == SDLK_RSHIFT)
|
||||
gui_input_key(in, GUI_KEY_SHIFT, gui_false);
|
||||
else if (code == SDLK_DELETE)
|
||||
gui_input_key(in, GUI_KEY_DEL, gui_false);
|
||||
else if (code == SDLK_RETURN)
|
||||
gui_input_key(in, GUI_KEY_ENTER, gui_false);
|
||||
else if (code == SDLK_SPACE)
|
||||
gui_input_key(in, GUI_KEY_SPACE, gui_false);
|
||||
else if (code == SDLK_BACKSPACE)
|
||||
gui_input_key(in, GUI_KEY_BACKSPACE, gui_false);
|
||||
}
|
||||
|
||||
static void
|
||||
kpress(struct GUI *gui, XEvent* e)
|
||||
bpress(struct gui_input *in, SDL_Event *evt)
|
||||
{
|
||||
int ret;
|
||||
struct XWindow *xw = gui->win;
|
||||
KeySym *keysym = XGetKeyboardMapping(xw->dpy, (KeyCode)e->xkey.keycode, 1, &ret);
|
||||
if (*keysym == XK_Shift_L || *keysym == XK_Shift_R)
|
||||
gui_input_key(&gui->in, GUI_KEY_SHIFT, gui_true);
|
||||
else if (*keysym == XK_Control_L || *keysym == XK_Control_L)
|
||||
gui_input_key(&gui->in, GUI_KEY_CTRL, gui_true);
|
||||
else if (*keysym == XK_Delete)
|
||||
gui_input_key(&gui->in, GUI_KEY_DEL, gui_true);
|
||||
else if (*keysym == XK_Return)
|
||||
gui_input_key(&gui->in, GUI_KEY_ENTER, gui_true);
|
||||
else if (*keysym == XK_space)
|
||||
gui_input_key(&gui->in, GUI_KEY_SPACE, gui_true);
|
||||
else if (*keysym == XK_BackSpace)
|
||||
gui_input_key(&gui->in, GUI_KEY_BACKSPACE, gui_true);
|
||||
else if ((*keysym >= 'a' && *keysym <= 'z') ||
|
||||
(*keysym >= '0' && *keysym <= '9'))
|
||||
gui_input_char(&gui->in, (unsigned char*)keysym);
|
||||
XFree(keysym);
|
||||
const int x = evt->button.x;
|
||||
const int y = evt->button.y;
|
||||
if (evt->button.button == SDL_BUTTON_LEFT)
|
||||
gui_input_button(in, x, y, gui_true);
|
||||
}
|
||||
|
||||
static void
|
||||
krelease(struct GUI *gui, XEvent* e)
|
||||
brelease(struct gui_input *in, SDL_Event *evt)
|
||||
{
|
||||
int ret;
|
||||
struct XWindow *xw = gui->win;
|
||||
KeySym *keysym = XGetKeyboardMapping(xw->dpy, (KeyCode)e->xkey.keycode, 1, &ret);
|
||||
if (*keysym == XK_Shift_L || *keysym == XK_Shift_R)
|
||||
gui_input_key(&gui->in, GUI_KEY_SHIFT, gui_false);
|
||||
else if (*keysym == XK_Control_L || *keysym == XK_Control_L)
|
||||
gui_input_key(&gui->in, GUI_KEY_CTRL, gui_false);
|
||||
else if (*keysym == XK_Delete)
|
||||
gui_input_key(&gui->in, GUI_KEY_DEL, gui_false);
|
||||
else if (*keysym == XK_Return)
|
||||
gui_input_key(&gui->in, GUI_KEY_ENTER, gui_false);
|
||||
else if (*keysym == XK_space)
|
||||
gui_input_key(&gui->in, GUI_KEY_SPACE, gui_false);
|
||||
else if (*keysym == XK_BackSpace)
|
||||
gui_input_key(&gui->in, GUI_KEY_BACKSPACE, gui_false);
|
||||
XFree(keysym);
|
||||
const int x = evt->button.x;
|
||||
const int y = evt->button.y;
|
||||
if (evt->button.button == SDL_BUTTON_LEFT)
|
||||
gui_input_button(in, x, y, gui_false);
|
||||
}
|
||||
|
||||
static void
|
||||
bpress(struct GUI *gui, XEvent *evt)
|
||||
bmotion(struct gui_input *in, SDL_Event *evt)
|
||||
{
|
||||
const int x = evt->xbutton.x;
|
||||
const int y = evt->xbutton.y;
|
||||
if (evt->xbutton.button == Button1)
|
||||
gui_input_button(&gui->in, x, y, gui_true);
|
||||
const gui_int x = evt->motion.x;
|
||||
const gui_int y = evt->motion.y;
|
||||
gui_input_motion(in, x, y);
|
||||
}
|
||||
|
||||
static void
|
||||
brelease(struct GUI *con, XEvent *evt)
|
||||
resize(SDL_Event* evt)
|
||||
{
|
||||
const int x = evt->xbutton.x;
|
||||
const int y = evt->xbutton.y;
|
||||
UNUSED(evt);
|
||||
if (evt->xbutton.button == Button1)
|
||||
gui_input_button(&con->in, x, y, gui_false);
|
||||
}
|
||||
|
||||
static void
|
||||
bmotion(struct GUI *gui, XEvent *evt)
|
||||
{
|
||||
const gui_int x = evt->xbutton.x;
|
||||
const gui_int y = evt->xbutton.y;
|
||||
UNUSED(evt);
|
||||
gui_input_motion(&gui->in, x, y);
|
||||
}
|
||||
|
||||
static void
|
||||
resize(struct GUI *con, XEvent* evt)
|
||||
{
|
||||
struct XWindow *xw = con->win;
|
||||
UNUSED(evt);
|
||||
XGetWindowAttributes(xw->dpy, xw->win, &xw->gwa);
|
||||
glViewport(0, 0, xw->gwa.width, xw->gwa.height);
|
||||
if (evt->window.event == SDL_WINDOWEVENT_RESIZED)
|
||||
glViewport(0, 0, evt->window.data1, evt->window.data2);
|
||||
}
|
||||
|
||||
static char*
|
||||
ldfile(const char* path, int flags, size_t* siz)
|
||||
ldfile(const char* path, size_t* siz)
|
||||
{
|
||||
char *buf;
|
||||
int fd = open(path, flags);
|
||||
struct stat status;
|
||||
if (fd == -1)
|
||||
die("Failed to open file: %s (%s)\n",
|
||||
path, strerror(errno));
|
||||
if (fstat(fd, &status) < 0)
|
||||
die("Failed to call fstat: %s",strerror(errno));
|
||||
*siz = (size_t)status.st_size;
|
||||
FILE *fd = fopen(path, "rb");
|
||||
if (!fd) die("Failed to open file: %s\n");
|
||||
fseek(fd, 0, SEEK_END);
|
||||
*siz = (size_t)ftell(fd);
|
||||
fseek(fd, 0, SEEK_SET);
|
||||
buf = xcalloc(*siz, 1);
|
||||
if (read(fd, buf, *siz) < 0)
|
||||
die("Failed to call read: %s",strerror(errno));
|
||||
close(fd);
|
||||
fread(buf, *siz, 1, fd);
|
||||
fclose(fd);
|
||||
return buf;
|
||||
}
|
||||
|
||||
@ -253,7 +150,6 @@ ldbmp(gui_byte *data, uint32_t *width, uint32_t *height)
|
||||
gui_byte *target;
|
||||
gui_byte *writer;
|
||||
gui_byte *reader;
|
||||
size_t mem;
|
||||
uint32_t ioff;
|
||||
uint32_t j;
|
||||
int32_t i;
|
||||
@ -272,8 +168,7 @@ ldbmp(gui_byte *data, uint32_t *width, uint32_t *height)
|
||||
|
||||
data = data + ioff;
|
||||
reader = data;
|
||||
mem = *width * *height * 4;
|
||||
target = xcalloc(mem, 1);
|
||||
target = xcalloc(*width * *height * 4, 1);
|
||||
for (i = (int32_t)*height-1; i >= 0; i--) {
|
||||
writer = target + (i * (int32_t)*width * 4);
|
||||
for (j = 0; j < *width; j++) {
|
||||
@ -302,14 +197,14 @@ ldbmp(gui_byte *data, uint32_t *width, uint32_t *height)
|
||||
static struct gui_font*
|
||||
ldfont(const char *name, unsigned char height)
|
||||
{
|
||||
gui_texture tex;
|
||||
size_t mem;
|
||||
size_t size;
|
||||
size_t i = 0;
|
||||
gui_byte *iter;
|
||||
gui_texture tex;
|
||||
short max_height = 0;
|
||||
struct gui_font *font;
|
||||
uint32_t img_width, img_height;
|
||||
short max_height = 0;
|
||||
size_t i = 0;
|
||||
size_t mem;
|
||||
gui_byte *iter;
|
||||
struct gui_font_glyph *glyphes;
|
||||
|
||||
uint16_t num;
|
||||
@ -317,7 +212,7 @@ ldfont(const char *name, unsigned char height)
|
||||
uint16_t tex_width;
|
||||
uint16_t tex_height;
|
||||
|
||||
gui_byte *buffer = (gui_byte*)ldfile(name, O_RDONLY, &size);
|
||||
gui_byte *buffer = (gui_byte*)ldfile(name, &size);
|
||||
memcpy(&num, buffer, sizeof(uint16_t));
|
||||
memcpy(&indexes, &buffer[0x02], sizeof(uint16_t));
|
||||
memcpy(&tex_width, &buffer[0x04], sizeof(uint16_t));
|
||||
@ -339,7 +234,6 @@ ldfont(const char *name, unsigned char height)
|
||||
memcpy(&yoff, &iter[14], sizeof(float));
|
||||
memcpy(&xadv, &iter[18], sizeof(float));
|
||||
|
||||
assert(id <= indexes);
|
||||
glyphes[id].code = id;
|
||||
glyphes[id].width = (short)w;
|
||||
glyphes[id].height = (short)h;
|
||||
@ -377,7 +271,7 @@ delfont(struct gui_font *font)
|
||||
}
|
||||
|
||||
static void
|
||||
draw(int width, int height, const struct gui_draw_call_list **list, gui_size count)
|
||||
draw(int width, int height, struct gui_draw_call_list **list, gui_size count)
|
||||
{
|
||||
gui_size i = 0;
|
||||
gui_size n = 0;
|
||||
@ -419,11 +313,11 @@ draw(int width, int height, const struct gui_draw_call_list **list, gui_size cou
|
||||
int x,y,w,h;
|
||||
cmd = &list[n]->commands[i];
|
||||
x = (int)cmd->clip_rect.x;
|
||||
y = height - (int)(cmd->clip_rect.y + cmd->clip_rect.h);
|
||||
w = (int)cmd->clip_rect.w;
|
||||
h = (int)cmd->clip_rect.h;
|
||||
y = height - (int)(cmd->clip_rect.y + cmd->clip_rect.h);
|
||||
glScissor(x, y, w, h);
|
||||
glBindTexture(GL_TEXTURE_2D, (GLuint)(unsigned long)cmd->texture.gl);
|
||||
glBindTexture(GL_TEXTURE_2D, (GLuint)cmd->texture.gl);
|
||||
glDrawArrays(GL_TRIANGLES, offset, (GLsizei)cmd->vertex_count);
|
||||
offset += (GLint)cmd->vertex_count;
|
||||
}
|
||||
@ -442,135 +336,103 @@ draw(int width, int height, const struct gui_draw_call_list **list, gui_size cou
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
struct XWindow xw;
|
||||
struct GUI gui;
|
||||
long dt, started;
|
||||
const struct gui_draw_call_list *list;
|
||||
static const gui_float values[] = {10.0f, 12.5f, 18.0f, 15.0f, 25.0f, 30.0f};
|
||||
static GLint att[] = {GLX_RGBA, GLX_DEPTH_SIZE,24, GLX_DOUBLEBUFFER, None};
|
||||
static const char *sel[] = {"item0", "item1", "item2", "item3", "item4", "item5"};
|
||||
static const char *select[] = {"Fist", "Pistol", "Shotgun", "Railgun", "BFG"};
|
||||
int width, height;
|
||||
uint32_t dt, started;
|
||||
gui_bool running;
|
||||
SDL_Window *win;
|
||||
SDL_GLContext glContext;
|
||||
|
||||
struct gui_context *ctx;
|
||||
struct gui_font *font;
|
||||
struct gui_panel *panel;
|
||||
struct gui_panel *subpanel;
|
||||
struct gui_config config;
|
||||
struct gui_memory memory;
|
||||
struct gui_input input;
|
||||
struct gui_output output;
|
||||
gui_int id;
|
||||
|
||||
/* Window */
|
||||
UNUSED(argc); UNUSED(argv);
|
||||
memset(&xw, 0, sizeof xw);
|
||||
memset(&gui, 0, sizeof gui);
|
||||
xw.dpy = XOpenDisplay(NULL);
|
||||
if (!xw.dpy) die("XOpenDisplay failed\n");
|
||||
xw.root = DefaultRootWindow(xw.dpy);
|
||||
xw.vi = glXChooseVisual(xw.dpy, 0, att);
|
||||
if (!xw.vi) die("Failed to find appropriate visual\n");
|
||||
xw.cmap = XCreateColormap(xw.dpy,xw.root,xw.vi->visual,AllocNone);
|
||||
xw.swa.colormap = xw.cmap;
|
||||
xw.swa.event_mask =
|
||||
ExposureMask | KeyPressMask |KeyReleaseMask | ButtonPress |
|
||||
ButtonReleaseMask | ButtonMotionMask | PointerMotionMask |
|
||||
Button1MotionMask | Button2MotionMask | Button3MotionMask;
|
||||
xw.win = XCreateWindow(
|
||||
xw.dpy, xw.root, 0, 0,WIN_WIDTH,WIN_HEIGHT, 0,
|
||||
xw.vi->depth, InputOutput, xw.vi->visual,
|
||||
CWColormap | CWEventMask, &xw.swa);
|
||||
XGetWindowAttributes(xw.dpy, xw.win, &xw.gwa);
|
||||
XStoreName(xw.dpy, xw.win, "Demo");
|
||||
XMapWindow(xw.dpy, xw.win);
|
||||
XFlush(xw.dpy);
|
||||
XSync(xw.dpy, False);
|
||||
|
||||
/* OpenGL */
|
||||
xw.glc = glXCreateContext(xw.dpy, xw.vi, NULL, GL_TRUE);
|
||||
glXMakeCurrent(xw.dpy, xw.win, xw.glc);
|
||||
|
||||
gui.win = &xw;
|
||||
gui.option = 0;
|
||||
gui.select = 0;
|
||||
gui.prog = 60;
|
||||
gui.vprog = 70;
|
||||
gui.vprog2 = 30;
|
||||
gui.vprog3 = 50;
|
||||
gui.spinner = 100;
|
||||
gui.slider = 5.0f;
|
||||
if (SDL_Init(SDL_INIT_VIDEO) < 0)
|
||||
die("[SDL] unabled to initialize\n");
|
||||
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
|
||||
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);
|
||||
win = SDL_CreateWindow("clone",
|
||||
0, 0, WIN_WIDTH, WIN_HEIGHT, SDL_WINDOW_OPENGL|SDL_WINDOW_SHOWN);
|
||||
if (!win) die("[SDL] unable to create window\n");
|
||||
glContext = SDL_GL_CreateContext(win);
|
||||
glViewport(0, 0, WIN_WIDTH, WIN_HEIGHT);
|
||||
|
||||
/* GUI */
|
||||
gui.font = ldfont("mono.sdf", 16);
|
||||
gui.main.memory = xcalloc(MAX_BUFFER, 1);
|
||||
gui.main.clip_size = MAX_BUFFER / 32;
|
||||
gui.main.command_size = MAX_BUFFER / 6;
|
||||
gui.main.vertex_size = MAX_BUFFER - gui.main.clip_size - gui.main.command_size;
|
||||
gui_default_config(&gui.config);
|
||||
gui_panel_init(&gui.panel, &gui.config, gui.font, &gui.in);
|
||||
gui.config.colors[GUI_COLOR_TEXT].r = 255;
|
||||
gui.config.colors[GUI_COLOR_TEXT].g = 255;
|
||||
gui.config.colors[GUI_COLOR_TEXT].b = 255;
|
||||
gui.config.colors[GUI_COLOR_TEXT].a = 255;
|
||||
memset(&input, 0, sizeof(input));
|
||||
memory.max_panels = MAX_PANELS;
|
||||
memory.memory = xcalloc(MAX_BUFFER , 1);
|
||||
memory.size = MAX_BUFFER;
|
||||
memory.vertex_percentage = 0.80f;
|
||||
memory.command_percentage = 0.19f;
|
||||
memory.clip_percentage = 0.01f;
|
||||
|
||||
xw.running = 1;
|
||||
while (xw.running) {
|
||||
XEvent ev;
|
||||
started = timestamp();
|
||||
gui_input_begin(&gui.in);
|
||||
while (XCheckWindowEvent(xw.dpy, xw.win, xw.swa.event_mask, &ev)) {
|
||||
if (ev.type == Expose||ev.type == ConfigureNotify) resize(&gui, &ev);
|
||||
else if (ev.type == MotionNotify) bmotion(&gui, &ev);
|
||||
else if (ev.type == ButtonPress) bpress(&gui, &ev);
|
||||
else if (ev.type == ButtonRelease) brelease(&gui, &ev);
|
||||
else if (ev.type == KeyPress) kpress(&gui, &ev);
|
||||
else if (ev.type == KeyRelease) krelease(&gui, &ev);
|
||||
ctx = gui_new(&memory, &input);
|
||||
gui_default_config(&config);
|
||||
config.colors[GUI_COLOR_TEXT].r = 255;
|
||||
config.colors[GUI_COLOR_TEXT].g = 255;
|
||||
config.colors[GUI_COLOR_TEXT].b = 255;
|
||||
config.colors[GUI_COLOR_TEXT].a = 255;
|
||||
font = ldfont("mono.sdf", 16);
|
||||
|
||||
panel = gui_panel_new(ctx, 20, 20, 200, 200, 0, &config, font);
|
||||
subpanel = gui_panel_new(ctx, 300, 20, 200, 200, 0, &config, font);
|
||||
|
||||
running = 1;
|
||||
while (running) {
|
||||
SDL_Event ev;
|
||||
started = SDL_GetTicks();
|
||||
gui_input_begin(&input);
|
||||
while (SDL_PollEvent(&ev)) {
|
||||
if (ev.type == SDL_WINDOWEVENT) resize(&ev);
|
||||
else if (ev.type == SDL_MOUSEMOTION) bmotion(&input, &ev);
|
||||
else if (ev.type == SDL_MOUSEBUTTONDOWN) bpress(&input, &ev);
|
||||
else if (ev.type == SDL_MOUSEBUTTONUP) brelease(&input, &ev);
|
||||
else if (ev.type == SDL_KEYDOWN) kpress( &input, &ev);
|
||||
else if (ev.type == SDL_KEYUP) krelease(&input, &ev);
|
||||
}
|
||||
gui_input_end(&gui.in);
|
||||
gui_input_end(&input);
|
||||
|
||||
/* ------------------------- GUI --------------------------*/
|
||||
gui_begin(&gui.out, &gui.main);
|
||||
xw.running = gui_panel_begin(&gui.panel, &gui.out, "Demo", 20, 20, 200, 400,
|
||||
SDL_GetWindowSize(win, &width, &height);
|
||||
gui_begin(ctx, (gui_float)width, (gui_float)height);
|
||||
running = gui_begin_panel(ctx, panel, "Demo",
|
||||
GUI_PANEL_HEADER|GUI_PANEL_CLOSEABLE|GUI_PANEL_MINIMIZABLE|GUI_PANEL_SCROLLBAR);
|
||||
gui_panel_layout(&gui.panel, 30, 1);
|
||||
if (gui_panel_button_text(&gui.panel, "button", 6, GUI_BUTTON_SWITCH))
|
||||
gui_panel_layout(panel, 30, 1);
|
||||
if (gui_panel_button_text(panel, "button", 6, GUI_BUTTON_SWITCH))
|
||||
fprintf(stdout, "button pressed!\n");
|
||||
gui.slider = gui_panel_slider(&gui.panel, 0.0f, gui.slider, 10.0f, 1.0f, GUI_HORIZONTAL);
|
||||
gui.prog = gui_panel_progress(&gui.panel, gui.prog, 100, gui_true, GUI_HORIZONTAL);
|
||||
gui.check = gui_panel_check(&gui.panel, "advanced", 8, gui.check);
|
||||
gui_panel_layout(&gui.panel, 30, 2);
|
||||
if (gui_panel_option(&gui.panel, "easy", 4, gui.option == 0)) gui.option = 0;
|
||||
if (gui_panel_option(&gui.panel, "hard", 4, gui.option == 1)) gui.option = 1;
|
||||
gui_panel_layout(&gui.panel, 30, 1);
|
||||
gui.typing = gui_panel_input(&gui.panel, gui.input_text, &gui.input_len, INPUT_MAX,
|
||||
GUI_INPUT_DEFAULT, gui.typing);
|
||||
gui.submit = gui_panel_command(&gui.panel, gui.cmd_input, &gui.cmd_len, INPUT_MAX,
|
||||
&gui.submitting);
|
||||
gui.spinning = gui_panel_spinner(&gui.panel, 0, &gui.spinner, 250, 10, gui.spinning);
|
||||
gui.select = gui_panel_selector(&gui.panel, select, LEN(select), gui.select);
|
||||
gui_panel_layout(&gui.panel, 100, 3);
|
||||
gui.vprog = gui_panel_progress(&gui.panel, gui.vprog, 100, gui_true, GUI_VERTICAL);
|
||||
gui.vprog2 = gui_panel_progress(&gui.panel, gui.vprog2, 100, gui_true, GUI_VERTICAL);
|
||||
gui.vprog3 = gui_panel_progress(&gui.panel, gui.vprog3, 100, gui_true, GUI_VERTICAL);
|
||||
gui_panel_layout(&gui.panel, 100, 1);
|
||||
gui.seloff = gui_panel_list(&gui.panel, gui.selection, sel, LEN(sel), gui.seloff, 30);
|
||||
gui_panel_histo(&gui.panel, values, LEN(values));
|
||||
gui_panel_plot(&gui.panel, values, LEN(values));
|
||||
gui_panel_end(&gui.panel);
|
||||
gui_end(&gui.out, &gui.draw_list, &gui.status);
|
||||
gui_end_panel(ctx, panel, NULL);
|
||||
|
||||
gui_begin_panel(ctx, subpanel, "Subdemo", GUI_PANEL_HEADER|GUI_PANEL_SCROLLBAR);
|
||||
gui_panel_layout(panel, 30, 1);
|
||||
if (gui_panel_button_text(subpanel, "button", 6, GUI_BUTTON_SWITCH))
|
||||
fprintf(stdout, "subbutton pressed!\n");
|
||||
gui_end_panel(ctx, subpanel, NULL);
|
||||
gui_end(ctx, &output, NULL);
|
||||
/* ---------------------------------------------------------*/
|
||||
|
||||
/* Draw */
|
||||
glClearColor(120.0f/255.0f, 120.0f/255.0f, 120.0f/255.0f, 120.0f/255.0f);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
list = &gui.draw_list;
|
||||
draw(xw.gwa.width, xw.gwa.height, &list, 1);
|
||||
glXSwapBuffers(xw.dpy, xw.win);
|
||||
draw(width, height, output.list, output.list_size);
|
||||
SDL_GL_SwapWindow(win);
|
||||
|
||||
/* Timing */
|
||||
dt = timestamp() - started;
|
||||
dt = SDL_GetTicks() - started;
|
||||
if (dt < DTIME)
|
||||
sleep_for(DTIME - dt);
|
||||
SDL_Delay(DTIME - dt);
|
||||
}
|
||||
|
||||
/* Cleanup */
|
||||
free(gui.main.memory);
|
||||
delfont(gui.font);
|
||||
XFree(xw.vi);
|
||||
glXMakeCurrent(xw.dpy, None, NULL);
|
||||
glXDestroyContext(xw.dpy, xw.glc);
|
||||
XDestroyWindow(xw.dpy, xw.win);
|
||||
XCloseDisplay(xw.dpy);
|
||||
free(memory.memory);
|
||||
delfont(font);
|
||||
SDL_Quit();
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user