changed examples to event-based updates

This commit is contained in:
vurtun 2016-01-02 13:35:16 +01:00
parent 599a64ed9e
commit 1f0004f274
3 changed files with 27 additions and 2 deletions

View File

@ -43,7 +43,7 @@
/* macros */
#define MAX_BUFFER 64
#define MAX_MEMORY (16 * 1024)
#define MAX_MEMORY (32 * 1024)
#define WINDOW_WIDTH 1200
#define WINDOW_HEIGHT 800
#define DTIME 40
@ -375,7 +375,7 @@ basic_demo(struct zr_context *ctx, struct icons *img)
if (image_active) {
struct zr_layout popup;
zr_popup_begin(ctx, &popup, ZR_POPUP_STATIC, "Image Popup", 0,
zr_rect(265, 0, 300, 220));
zr_rect(265, 0, 320, 220));
zr_layout_row_static(ctx, 82, 82, 3);
for (i = 0; i < 9; ++i) {
if (zr_button_image(ctx, zr_image_id(img->images[i]), ZR_BUTTON_DEFAULT)) {
@ -678,6 +678,7 @@ main(int argc, char *argv[])
unsigned int started;
unsigned int dt;
int i = 0;
int poll = 1;
/* GUI */
struct icons icons;
@ -760,9 +761,16 @@ main(int argc, char *argv[])
while (running) {
/* Input */
int ret;
SDL_Event evt;
started = SDL_GetTicks();
zr_input_begin(&ctx.input);
if (!poll) {
ret = SDL_WaitEvent(&evt);
poll = 1;
}
while (SDL_PollEvent(&evt)) {
if (evt.type == SDL_WINDOWEVENT &&
evt.window.event == SDL_WINDOWEVENT_RESIZED)
@ -796,6 +804,7 @@ main(int argc, char *argv[])
SDL_GetWindowSize(win, &width, &height);
draw(vg, &ctx, width, height);
SDL_GL_SwapWindow(win);
poll = (!((poll+1) & 4));
/* Timing */
dt = SDL_GetTicks() - started;

View File

@ -783,6 +783,7 @@ main(int argc, char *argv[])
NVGcontext *vg = NULL;
struct zr_context ctx;
void *memory;
int poll = 1;
int running = 1;
struct file_browser browser;
@ -830,6 +831,11 @@ main(int argc, char *argv[])
while (running) {
/* Input */
SDL_Event evt;
if (!poll) {
SDL_WaitEvent(&evt);
poll = 1;
}
zr_input_begin(&ctx.input);
while (SDL_PollEvent(&evt)) {
if (evt.type == SDL_WINDOWEVENT) resize(&evt);
@ -852,6 +858,7 @@ main(int argc, char *argv[])
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
draw(vg, &ctx, width, height);
SDL_GL_SwapWindow(win);
poll = (!((poll+1) & 4));
}
cleanup:

View File

@ -575,6 +575,7 @@ int
main(int argc, char *argv[])
{
/* Platform */
int poll = 1;
int x, y, width, height;
const char *font_path;
zr_size font_height;
@ -642,8 +643,15 @@ main(int argc, char *argv[])
while (running) {
/* Input */
int ret;
SDL_Event evt;
started = SDL_GetTicks();
if (!poll) {
ret = SDL_WaitEvent(&evt);
poll = 1;
}
zr_input_begin(&ctx.input);
while (SDL_PollEvent(&evt)) {
if (evt.type == SDL_WINDOWEVENT) resize(&evt);
@ -674,6 +682,7 @@ main(int argc, char *argv[])
SDL_GetWindowSize(win, &width, &height);
draw(vg, &ctx, width, height);
SDL_GL_SwapWindow(win);
poll = (!((poll+1) & 4));
/* Timing */
dt = SDL_GetTicks() - started;