diff --git a/src/gl.c b/src/gl.c index f449db7..4107a19 100644 --- a/src/gl.c +++ b/src/gl.c @@ -233,6 +233,7 @@ void heliGLSetCommonState(const HeliGLCommonState *state) { glGetIntegerv(GL_MATRIX_MODE, (int*)&mode); glMatrixMode(GL_MODELVIEW); if (!loadTransform) glPushMatrix(); + glLoadIdentity(); const int clipCount = (int)(sizeof(state->clipPlanes)/sizeof(*state->clipPlanes)); for(int i = 0; i < clipCount; ++i) { if (state->clipPlanes[i].enabled) glEnable(GL_CLIP_PLANE0+i); diff --git a/src/helianthus.h b/src/helianthus.h index 25af633..39efaf2 100644 --- a/src/helianthus.h +++ b/src/helianthus.h @@ -18,7 +18,7 @@ extern "C" { #include "helianthus/sprite.h" #include "helianthus/group.h" - + #ifdef __cplusplus } #endif diff --git a/src/nuklear-heli.c b/src/nuklear-heli.c index 512599e..0c24fdc 100644 --- a/src/nuklear-heli.c +++ b/src/nuklear-heli.c @@ -1,4 +1,5 @@ +#include #include #include "drawing.h" @@ -55,6 +56,10 @@ nk_bool nk_heli_init(nk_heli *n, double fontSize) { n->font.width = &nk_heli_text_width; if (!nk_init_default(&n->context, &n->font)) return 0; + n->cliprect[0] = INT_MIN; + n->cliprect[1] = INT_MIN; + n->cliprect[2] = INT_MAX; + n->cliprect[3] = INT_MAX; struct nk_context *c = &n->context; c->clip.paste = &nk_heli_clipboard_paste; c->clip.copy = &nk_heli_clipboard_copy; @@ -74,6 +79,14 @@ struct nk_image nk_heli_image(Animation anim, int width, int height) { } +void nk_heli_cliprect(nk_heli *n, int x, int y, int w, int h) { + n->cliprect[0] = x; + n->cliprect[1] = y; + n->cliprect[2] = x + w; + n->cliprect[3] = y + h; +} + + void nk_heli_input_ex(nk_heli *n, unsigned int flags) { static const struct { enum nk_buttons nk; @@ -215,7 +228,11 @@ void nk_heli_draw(nk_heli *n) { switch (cmd->type) { case NK_COMMAND_SCISSOR: { const struct nk_command_scissor *s = (const struct nk_command_scissor*)cmd; - cliprect(s->x, s->y, s->w, s->h); + int x0 = s->x > n->cliprect[0] ? s->x : n->cliprect[0]; + int y0 = s->y > n->cliprect[1] ? s->y : n->cliprect[1]; + int x1 = s->x + s->w < n->cliprect[2] ? s->x + s->w : n->cliprect[2]; + int y1 = s->y + s->h < n->cliprect[3] ? s->y + s->h : n->cliprect[3]; + cliprect(x0, y0, x1 - x0, y1 - y0); } break; case NK_COMMAND_LINE: { const struct nk_command_line *l = (const struct nk_command_line *)cmd; diff --git a/src/nuklear-heli.h b/src/nuklear-heli.h index e8ca017..7cb0fb3 100644 --- a/src/nuklear-heli.h +++ b/src/nuklear-heli.h @@ -44,6 +44,7 @@ enum { typedef struct { struct nk_context context; struct nk_user_font font; + int cliprect[4]; int keys[NK_KEY_MAX]; int buttons[NK_BUTTON_MAX]; } nk_heli; @@ -56,6 +57,7 @@ struct nk_color nk_color_from_heli(unsigned int c); nk_bool nk_heli_init(nk_heli *n, double fontSize); void nk_heli_deinit(nk_heli *n); struct nk_image nk_heli_image(Animation anim, int width, int height); +void nk_heli_cliprect(nk_heli *n, int x, int y, int w, int h); void nk_heli_input_ex(nk_heli *n, unsigned int flags); void nk_heli_input(nk_heli *n); void nk_heli_draw(nk_heli *n); diff --git a/src/windowui.c b/src/windowui.c index ba872fe..0faa94c 100644 --- a/src/windowui.c +++ b/src/windowui.c @@ -138,6 +138,7 @@ static void paste(HeliDialog *dialog) { static void draw(HeliDialog *dialog) { saveState(); + resetState(); const double time = SDL_GetTicks()*1e-3;