summaryrefslogtreecommitdiff
path: root/meme
diff options
context:
space:
mode:
authorWerner Almesberger <werner@almesberger.net>2014-09-12 01:11:10 -0300
committerWerner Almesberger <werner@almesberger.net>2014-09-12 01:11:10 -0300
commit32276ccb0791869c2b8eb8584a025a8fdcb910ae (patch)
tree9578f2bd57cd56106f1955557d3548f0d1665ca2 /meme
parent80fd84c94a958b18c7d55e1e725040232c457680 (diff)
downloadmisc-32276ccb0791869c2b8eb8584a025a8fdcb910ae.tar.gz
misc-32276ccb0791869c2b8eb8584a025a8fdcb910ae.tar.bz2
misc-32276ccb0791869c2b8eb8584a025a8fdcb910ae.zip
meme/gui.c (coord): move coordinate transform to separate functions; simplify
We don't pass width and height anymore. Maybe later.
Diffstat (limited to 'meme')
-rw-r--r--meme/gui.c40
1 files changed, 24 insertions, 16 deletions
diff --git a/meme/gui.c b/meme/gui.c
index 9ff1d7b..d648dfa 100644
--- a/meme/gui.c
+++ b/meme/gui.c
@@ -33,6 +33,18 @@ static bool show_grid = 1;
/* ----- Coordinate transform ---------------------------------------------- */
+static inline int x_model2screen(int x)
+{
+ return ((x-x_orig) >> zoom)+(XRES >> 1);
+}
+
+
+static inline int y_model2screen(int y)
+{
+ return ((y-y_orig) >> zoom)+(YRES >> 1);
+}
+
+
static inline int x_screen2model(int x)
{
return ((x - (XRES >> 1)) << zoom)+x_orig;
@@ -45,14 +57,10 @@ static inline int y_screen2model(int y)
}
-static int coord(int w, int h, int x, int y,
- Sint16 *res_x, Sint16 *res_y)
+static int coord(int x, int y, Sint16 *res_x, Sint16 *res_y)
{
- int xc = w >> 1;
- int yc = h >> 1;
-
- x = ((x-x_orig) >> zoom)+xc;
- y = ((y-y_orig) >> zoom)+yc;
+ x = x_model2screen(x);
+ y = y_model2screen(y);
if (x < -32768 || x > 32767)
return -1;
@@ -69,7 +77,7 @@ static int coord(int w, int h, int x, int y,
/* ----- Draw the mesh ----------------------------------------------------- */
-static void surface_draw(SDL_Surface *s, int w, int h)
+static void surface_draw(SDL_Surface *s)
{
const struct facet *f;
Sint16 xa, ya, xb, yb, xc, yc;
@@ -78,13 +86,13 @@ static void surface_draw(SDL_Surface *s, int w, int h)
Uint32 col;
for (f = facets; f; f = f->next) {
- a = coord(w, h, f->v[0]->x, f->v[0]->y, &xa, &ya);
+ a = coord(f->v[0]->x, f->v[0]->y, &xa, &ya);
if (a < 0)
continue;
- b = coord(w, h, f->v[1]->x, f->v[1]->y, &xb, &yb);
+ b = coord(f->v[1]->x, f->v[1]->y, &xb, &yb);
if (b < 0)
continue;
- c = coord(w, h, f->v[2]->x, f->v[2]->y, &xc, &yc);
+ c = coord(f->v[2]->x, f->v[2]->y, &xc, &yc);
if (c < 0)
continue;
if (!(a || b || c))
@@ -98,17 +106,17 @@ static void surface_draw(SDL_Surface *s, int w, int h)
}
-static void edges_draw(SDL_Surface *s, int w, int h)
+static void edges_draw(SDL_Surface *s)
{
const struct edge *e;
Sint16 xa, ya, xb, yb;
int a, b;
for (e = edges; e; e = e->next) {
- a = coord(w, h, e->a->x, e->a->y, &xa, &ya);
+ a = coord(e->a->x, e->a->y, &xa, &ya);
if (a < 0)
continue;
- b = coord(w, h, e->b->x, e->b->y, &xb, &yb);
+ b = coord(e->b->x, e->b->y, &xb, &yb);
if (b < 0)
continue;
if (!(a || b))
@@ -121,9 +129,9 @@ static void edges_draw(SDL_Surface *s, int w, int h)
static void draw(SDL_Surface *s)
{
SDL_FillRect(s, NULL, SDL_MapRGB(s->format, 0xff, 0xff, 0xff));
- surface_draw(s, XRES, YRES);
+ surface_draw(s);
if (show_grid)
- edges_draw(s, XRES, YRES);
+ edges_draw(s);
}