summaryrefslogtreecommitdiff
path: root/meme/gui.c
diff options
context:
space:
mode:
authorWerner Almesberger <werner@almesberger.net>2014-09-13 16:01:39 (GMT)
committerWerner Almesberger <werner@almesberger.net>2014-09-13 16:01:39 (GMT)
commit079480506feafde34833f5768834f4aee490cb7e (patch)
tree5094272677abf36efda9f870086f4e3e5dcd7548 /meme/gui.c
parentc89544e48b120d2808b55ec2840bbe5f9b41f67f (diff)
downloadmisc-079480506feafde34833f5768834f4aee490cb7e.zip
misc-079480506feafde34833f5768834f4aee490cb7e.tar.gz
misc-079480506feafde34833f5768834f4aee490cb7e.tar.bz2
meme/gui.c (XRES, YRES): use variables for current resolution
Diffstat (limited to 'meme/gui.c')
-rw-r--r--meme/gui.c46
1 files changed, 25 insertions, 21 deletions
diff --git a/meme/gui.c b/meme/gui.c
index bc36211..c5f6e61 100644
--- a/meme/gui.c
+++ b/meme/gui.c
@@ -44,6 +44,7 @@
static int x_orig, y_orig;
+static Sint16 xres, yres;
static int x_min, x_max, y_min, y_max, z_min, z_max;
static int zoom;
static bool show_grid = 0;
@@ -56,25 +57,25 @@ static const struct vertex *cursor;
static inline int x_model2screen(int x)
{
- return ((x-x_orig) >> zoom)+(XRES >> 1);
+ return ((x-x_orig) >> zoom)+(xres >> 1);
}
static inline int y_model2screen(int y)
{
- return ((y-y_orig) >> zoom)+(YRES >> 1);
+ return ((y-y_orig) >> zoom)+(yres >> 1);
}
static inline int x_screen2model(int x)
{
- return ((x - (XRES >> 1)) << zoom)+x_orig;
+ return ((x - (xres >> 1)) << zoom)+x_orig;
}
static inline int y_screen2model(int y)
{
- return ((y - (YRES >> 1)) << zoom)+y_orig;
+ return ((y - (yres >> 1)) << zoom)+y_orig;
}
@@ -91,14 +92,14 @@ static int coord(int x, int y, Sint16 *res_x, Sint16 *res_y)
*res_x = x;
*res_y = y;
- return x >= 0 && x < XRES && y >= 0 && y < YRES;
+ return x >= 0 && x < xres && y >= 0 && y < yres;
}
static inline int xz_z_model2screen(int z)
{
/* center at cursor in lower 1/4 of screen */
- return YRES-(YRES >> 3) - ((z-cursor->z) >> zoom);
+ return yres-(yres >> 3) - ((z-cursor->z) >> zoom);
}
@@ -115,14 +116,14 @@ static int coord_xz(int x, int y, Sint16 *res_x, Sint16 *res_y)
*res_x = x;
*res_y = y;
- return x >= 0 && x < XRES && y >= 0 && y < YRES;
+ return x >= 0 && x < xres && y >= 0 && y < yres;
}
static inline int yz_z_model2screen(int z)
{
/* center at cursor in right 1/4 of screen */
- return XRES-(XRES >> 3) - ((z-cursor->z) >> zoom);
+ return xres-(xres >> 3) - ((z-cursor->z) >> zoom);
}
@@ -139,7 +140,7 @@ static int coord_yz(int x, int y, Sint16 *res_x, Sint16 *res_y)
*res_x = x;
*res_y = y;
- return x >= 0 && x < XRES && y >= 0 && y < YRES;
+ return x >= 0 && x < xres && y >= 0 && y < yres;
}
@@ -234,10 +235,10 @@ static void change(SDL_Surface *s, int x, int y, int w, int h)
h += y;
y = 0;
}
- if (x+w >= XRES)
- w = XRES-x-1;
- if (y+h >= YRES)
- h = YRES-y-1;
+ if (x+w >= xres)
+ w = xres-x-1;
+ if (y+h >= yres)
+ h = yres-y-1;
/*
* @@@ this seems weird. do we really have no direct way to create
@@ -325,11 +326,11 @@ static void show_cursor(SDL_Surface *s, const struct vertex *v)
int y = y_model2screen(v->y);
change(s, x-CURSOR_R, y-CURSOR_R, 2*CURSOR_R+1, 2*CURSOR_R+1);
- change(s, 0, y, XRES-1, 1);
- change(s, x, 0, 1, YRES-1);
+ change(s, 0, y, xres-1, 1);
+ change(s, x, 0, 1, yres-1);
SDL_LockSurface(s);
- aalineColor(s, 0, y, XRES-1, y, CURSOR_RGBA);
- aalineColor(s, x, 0, x, YRES-1, CURSOR_RGBA);
+ aalineColor(s, 0, y, xres-1, y, CURSOR_RGBA);
+ aalineColor(s, x, 0, x, yres-1, CURSOR_RGBA);
filledCircleColor(s, x, y, CURSOR_R, CURSOR_RGBA);
SDL_UnlockSurface(s);
}
@@ -351,7 +352,7 @@ static void show_xz_profile(SDL_Surface *s)
xz = plane_xz(cursor->y, &n);
a = coord_xz(xz[0].x, xz[0].y, &xa, &ya);
- change(s, 0, YRES - (YRES >> 2)-1, XRES, YRES >> 2);
+ change(s, 0, yres - (yres >> 2)-1, xres, yres >> 2);
SDL_LockSurface(s);
for (i = 1; i < n; i++) {
b = coord_xz(xz[i].x, xz[i].y, &xb, &yb);
@@ -361,7 +362,7 @@ static void show_xz_profile(SDL_Surface *s)
ya = yb;
a = b;
}
- aalineColor(s, 0, YRES - (YRES >> 3), XRES-1, YRES - (YRES >> 3), PROFILE_RGBA);
+ aalineColor(s, 0, yres - (yres >> 3), xres-1, yres - (yres >> 3), PROFILE_RGBA);
SDL_UnlockSurface(s);
free(xz);
@@ -381,7 +382,7 @@ static void show_yz_profile(SDL_Surface *s)
yz = plane_yz(cursor->x, &n);
a = coord_yz(yz[0].x, yz[0].y, &xa, &ya);
- change(s, XRES - (XRES >> 2)-1, 0, XRES >> 2, YRES);
+ change(s, xres - (xres >> 2)-1, 0, xres >> 2, yres);
SDL_LockSurface(s);
for (i = 1; i < n; i++) {
b = coord_yz(yz[i].x, yz[i].y, &xb, &yb);
@@ -391,7 +392,7 @@ static void show_yz_profile(SDL_Surface *s)
ya = yb;
a = b;
}
- aalineColor(s, XRES - (XRES >> 3), 0, XRES - (XRES >> 3), YRES-1, PROFILE_RGBA);
+ aalineColor(s, xres - (xres >> 3), 0, xres - (xres >> 3), yres-1, PROFILE_RGBA);
SDL_UnlockSurface(s);
free(yz);
@@ -819,6 +820,9 @@ void gui(void)
exit(1);
}
+ xres = surf->w;
+ yres = surf->h;
+
extrema();
x_orig = (x_min+x_max) >> 1;
y_orig = (y_min+y_max) >> 1;