summaryrefslogtreecommitdiff
path: root/meme
diff options
context:
space:
mode:
authorWerner Almesberger <werner@almesberger.net>2014-09-12 00:39:14 -0300
committerWerner Almesberger <werner@almesberger.net>2014-09-12 00:39:14 -0300
commit1c6b75e49abd8cb77d28935f07d25de162bd46be (patch)
tree2188f6a11977244c717b18c1be10bfa316c4eab1 /meme
parent6def231e45616899c67bf3294fba9d16bac2bf73 (diff)
downloadmisc-1c6b75e49abd8cb77d28935f07d25de162bd46be.tar.gz
misc-1c6b75e49abd8cb77d28935f07d25de162bd46be.tar.bz2
misc-1c6b75e49abd8cb77d28935f07d25de162bd46be.zip
meme/gui.c: don't draw off-screen items
This greatly improves responsiveness at high zoom levels.
Diffstat (limited to 'meme')
-rw-r--r--meme/gui.c35
1 files changed, 23 insertions, 12 deletions
diff --git a/meme/gui.c b/meme/gui.c
index f126760..b78a3ff 100644
--- a/meme/gui.c
+++ b/meme/gui.c
@@ -30,7 +30,7 @@ static int zoom;
static bool show_grid = 1;
-static bool coord(int w, int h, int x, int y,
+static int coord(int w, int h, int x, int y,
Sint16 *res_x, Sint16 *res_y)
{
int xc = w >> 1;
@@ -40,14 +40,14 @@ static bool coord(int w, int h, int x, int y,
y = ((y-y_orig) >> zoom)+yc;
if (x < -32768 || x > 32767)
- return 0;
+ return -1;
if (y < -32768 || y > 32767)
- return 0;
+ return -1;
*res_x = x;
*res_y = y;
- return 1;
+ return x >= 0 && x < XRES && y >= 0 && y < YRES;
}
@@ -55,21 +55,27 @@ static void surface_draw(SDL_Surface *s, int w, int h)
{
const struct facet *f;
Sint16 xa, ya, xb, yb, xc, yc;
+ int a, b, c;
int z3;
- Uint32 c;
+ Uint32 col;
for (f = facets; f; f = f->next) {
- if (!coord(w, h, f->v[0]->x, f->v[0]->y, &xa, &ya))
+ a = coord(w, h, f->v[0]->x, f->v[0]->y, &xa, &ya);
+ if (a < 0)
continue;
- if (!coord(w, h, f->v[1]->x, f->v[1]->y, &xb, &yb))
+ b = coord(w, h, f->v[1]->x, f->v[1]->y, &xb, &yb);
+ if (b < 0)
continue;
- if (!coord(w, h, f->v[2]->x, f->v[2]->y, &xc, &yc))
+ c = coord(w, h, f->v[2]->x, f->v[2]->y, &xc, &yc);
+ if (c < 0)
+ continue;
+ if (!(a || b || c))
continue;
z3 = f->v[0]->z + f->v[1]->z + f->v[2]->z - z_min*3;
- c = z3*0x90/3/(z_max-z_min)*0x1010100 + 0x606060ff;
+ col = z3*0x90/3/(z_max-z_min)*0x1010100 + 0x606060ff;
- filledTrigonColor(s, xa, ya, xb, yb, xc, yc, c);
+ filledTrigonColor(s, xa, ya, xb, yb, xc, yc, col);
}
}
@@ -78,11 +84,16 @@ static void edges_draw(SDL_Surface *s, int w, int h)
{
const struct edge *e;
Sint16 xa, ya, xb, yb;
+ int a, b;
for (e = edges; e; e = e->next) {
- if (!coord(w, h, e->a->x, e->a->y, &xa, &ya))
+ a = coord(w, h, e->a->x, e->a->y, &xa, &ya);
+ if (a < 0)
+ continue;
+ b = coord(w, h, e->b->x, e->b->y, &xb, &yb);
+ if (b < 0)
continue;
- if (!coord(w, h, e->b->x, e->b->y, &xb, &yb))
+ if (!(a || b))
continue;
aalineColor(s, xa, ya, xb, yb, 0x000000ff);
}