summaryrefslogtreecommitdiff
path: root/src/interface.c
diff options
context:
space:
mode:
authorjacksonmj <mj-pt@jacksonmj.co.uk>2012-04-29 23:34:07 (GMT)
committer jacksonmj <mj-pt@jacksonmj.co.uk>2012-04-29 23:39:12 (GMT)
commit8872e33b44ddc766e2c92fc843e2ee883247f473 (patch)
treef520b81af863eeb1bedbab36568604791ddd84b6 /src/interface.c
parent74979102b34980ce2a815ebf15985d356a73de3c (diff)
downloadpowder-8872e33b44ddc766e2c92fc843e2ee883247f473.zip
powder-8872e33b44ddc766e2c92fc843e2ee883247f473.tar.gz
Massive cleanup of sdl_scale, and fix moving a sign in the zoom window
Diffstat (limited to 'src/interface.c')
-rw-r--r--src/interface.c198
1 files changed, 86 insertions, 112 deletions
diff --git a/src/interface.c b/src/interface.c
index 7f7ec65..4824cb9 100644
--- a/src/interface.c
+++ b/src/interface.c
@@ -184,7 +184,7 @@ void add_sign_ui(pixel *vid_buf, int mx, int my)
while (!sdl_poll())
{
- b = SDL_GetMouseState(&mx, &my);
+ b = mouse_get_state(&mx, &my);
if (!b)
break;
}
@@ -205,9 +205,7 @@ void add_sign_ui(pixel *vid_buf, int mx, int my)
while (!sdl_poll())
{
bq = b;
- b = SDL_GetMouseState(&mx, &my);
- mx /= sdl_scale;
- my /= sdl_scale;
+ b = mouse_get_state(&mx, &my);
drawrect(vid_buf, x0, y0, 192, 80, 192, 192, 192, 255);
clearrect(vid_buf, x0, y0, 192, 80);
@@ -490,16 +488,14 @@ void ui_list_process(pixel * vid_buf, int mx, int my, int mb, ui_list *ed)
ystart = 5;
while (!sdl_poll())
{
- mb = SDL_GetMouseState(&mx, &my);
+ mb = mouse_get_state(&mx, &my);
if (!mb)
break;
}
while (!sdl_poll() && !selected)
{
- mb = SDL_GetMouseState(&mx, &my);
- mx /= sdl_scale;
- my /= sdl_scale;
+ mb = mouse_get_state(&mx, &my);
for(i = 0; i < ed->count; i++)
{
if(mx > ed->x && mx < ed->x+ed->w && my > (ystart + i*16) && my < (ystart + i * 16) + 16)
@@ -525,7 +521,7 @@ void ui_list_process(pixel * vid_buf, int mx, int my, int mb, ui_list *ed)
}
while (!sdl_poll())
{
- mb = SDL_GetMouseState(&mx, &my);
+ mb = mouse_get_state(&mx, &my);
if (!mb)
break;
}
@@ -923,7 +919,7 @@ void error_ui(pixel *vid_buf, int err, char *txt)
while (!sdl_poll())
{
- b = SDL_GetMouseState(&mx, &my);
+ b = mouse_get_state(&mx, &my);
if (!b)
break;
}
@@ -931,9 +927,7 @@ void error_ui(pixel *vid_buf, int err, char *txt)
while (!sdl_poll())
{
bq = b;
- b = SDL_GetMouseState(&mx, &my);
- mx /= sdl_scale;
- my /= sdl_scale;
+ b = mouse_get_state(&mx, &my);
clearrect(vid_buf, x0-2, y0-2, 244, 52+textheight);
drawrect(vid_buf, x0, y0, 240, 48+textheight, 192, 192, 192, 255);
@@ -959,7 +953,7 @@ void error_ui(pixel *vid_buf, int err, char *txt)
while (!sdl_poll())
{
- b = SDL_GetMouseState(&mx, &my);
+ b = mouse_get_state(&mx, &my);
if (!b)
break;
}
@@ -990,7 +984,7 @@ char *input_ui(pixel *vid_buf, char *title, char *prompt, char *text, char *shad
while (!sdl_poll())
{
- b = SDL_GetMouseState(&mx, &my);
+ b = mouse_get_state(&mx, &my);
if (!b)
break;
}
@@ -998,9 +992,7 @@ char *input_ui(pixel *vid_buf, char *title, char *prompt, char *text, char *shad
while (!sdl_poll())
{
bq = b;
- b = SDL_GetMouseState(&mx, &my);
- mx /= sdl_scale;
- my /= sdl_scale;
+ b = mouse_get_state(&mx, &my);
clearrect(vid_buf, x0-2, y0-2, xsize+4, ysize+4);
drawrect(vid_buf, x0, y0, xsize, ysize, 192, 192, 192, 255);
@@ -1028,7 +1020,7 @@ char *input_ui(pixel *vid_buf, char *title, char *prompt, char *text, char *shad
while (!sdl_poll())
{
- b = SDL_GetMouseState(&mx, &my);
+ b = mouse_get_state(&mx, &my);
if (!b)
break;
}
@@ -1081,7 +1073,7 @@ void prop_edit_ui(pixel *vid_buf, int x, int y)
while (!sdl_poll())
{
- b = SDL_GetMouseState(&mx, &my);
+ b = mouse_get_state(&mx, &my);
if (!b)
break;
}
@@ -1089,9 +1081,7 @@ void prop_edit_ui(pixel *vid_buf, int x, int y)
while (!sdl_poll())
{
bq = b;
- b = SDL_GetMouseState(&mx, &my);
- mx /= sdl_scale;
- my /= sdl_scale;
+ b = mouse_get_state(&mx, &my);
clearrect(vid_buf, x0-2, y0-2, xsize+4, ysize+4);
drawrect(vid_buf, x0, y0, xsize, ysize, 192, 192, 192, 255);
@@ -1223,7 +1213,7 @@ void prop_edit_ui(pixel *vid_buf, int x, int y)
exit:
while (!sdl_poll())
{
- b = SDL_GetMouseState(&mx, &my);
+ b = mouse_get_state(&mx, &my);
if (!b)
break;
}
@@ -1235,7 +1225,7 @@ void info_ui(pixel *vid_buf, char *top, char *txt)
while (!sdl_poll())
{
- b = SDL_GetMouseState(&mx, &my);
+ b = mouse_get_state(&mx, &my);
if (!b)
break;
}
@@ -1243,9 +1233,7 @@ void info_ui(pixel *vid_buf, char *top, char *txt)
while (!sdl_poll())
{
bq = b;
- b = SDL_GetMouseState(&mx, &my);
- mx /= sdl_scale;
- my /= sdl_scale;
+ b = mouse_get_state(&mx, &my);
clearrect(vid_buf, x0-2, y0-2, 244, 64);
drawrect(vid_buf, x0, y0, 240, 60, 192, 192, 192, 255);
@@ -1266,7 +1254,7 @@ void info_ui(pixel *vid_buf, char *top, char *txt)
while (!sdl_poll())
{
- b = SDL_GetMouseState(&mx, &my);
+ b = mouse_get_state(&mx, &my);
if (!b)
break;
}
@@ -1314,7 +1302,7 @@ void copytext_ui(pixel *vid_buf, char *top, char *txt, char *copytxt)
while (!sdl_poll())
{
- b = SDL_GetMouseState(&mx, &my);
+ b = mouse_get_state(&mx, &my);
if (!b)
break;
}
@@ -1322,9 +1310,7 @@ void copytext_ui(pixel *vid_buf, char *top, char *txt, char *copytxt)
while (!sdl_poll())
{
bq = b;
- b = SDL_GetMouseState(&mx, &my);
- mx /= sdl_scale;
- my /= sdl_scale;
+ b = mouse_get_state(&mx, &my);
clearrect(vid_buf, x0-2, y0-2, xsize+4, ysize+4);
drawrect(vid_buf, x0, y0, xsize, ysize, 192, 192, 192, 255);
@@ -1350,7 +1336,7 @@ void copytext_ui(pixel *vid_buf, char *top, char *txt, char *copytxt)
while (!sdl_poll())
{
- b = SDL_GetMouseState(&mx, &my);
+ b = mouse_get_state(&mx, &my);
if (!b)
break;
}
@@ -1369,7 +1355,7 @@ int confirm_ui(pixel *vid_buf, char *top, char *msg, char *btn)
while (!sdl_poll())
{
- b = SDL_GetMouseState(&mx, &my);
+ b = mouse_get_state(&mx, &my);
if (!b)
break;
}
@@ -1377,9 +1363,7 @@ int confirm_ui(pixel *vid_buf, char *top, char *msg, char *btn)
while (!sdl_poll())
{
bq = b;
- b = SDL_GetMouseState(&mx, &my);
- mx /= sdl_scale;
- my /= sdl_scale;
+ b = mouse_get_state(&mx, &my);
clearrect(vid_buf, x0-2, y0-2, 244, 52+textheight);
drawrect(vid_buf, x0, y0, 240, 48+textheight, 192, 192, 192, 255);
@@ -1412,7 +1396,7 @@ int confirm_ui(pixel *vid_buf, char *top, char *msg, char *btn)
while (!sdl_poll())
{
- b = SDL_GetMouseState(&mx, &my);
+ b = mouse_get_state(&mx, &my);
if (!b)
break;
}
@@ -1428,7 +1412,7 @@ void login_ui(pixel *vid_buf)
while (!sdl_poll())
{
- b = SDL_GetMouseState(&mx, &my);
+ b = mouse_get_state(&mx, &my);
if (!b)
break;
}
@@ -1458,9 +1442,7 @@ void login_ui(pixel *vid_buf)
while (!sdl_poll())
{
bq = b;
- b = SDL_GetMouseState(&mx, &my);
- mx /= sdl_scale;
- my /= sdl_scale;
+ b = mouse_get_state(&mx, &my);
drawrect(vid_buf, x0, y0, 192, 80, 192, 192, 192, 255);
clearrect(vid_buf, x0, y0, 192, 80);
@@ -1598,7 +1580,7 @@ int stamp_ui(pixel *vid_buf)
while (!sdl_poll())
{
- b = SDL_GetMouseState(&mx, &my);
+ b = mouse_get_state(&mx, &my);
if (!b)
break;
}
@@ -1606,9 +1588,7 @@ int stamp_ui(pixel *vid_buf)
while (!sdl_poll())
{
bq = b;
- b = SDL_GetMouseState(&mx, &my);
- mx /= sdl_scale;
- my /= sdl_scale;
+ b = mouse_get_state(&mx, &my);
clearrect(vid_buf, -1, -1, XRES+BARSIZE+1, YRES+MENUSIZE+1);
k = stamp_page*per_page;//0;
@@ -1723,7 +1703,7 @@ int stamp_ui(pixel *vid_buf)
while (!sdl_poll())
{
- b = SDL_GetMouseState(&mx, &my);
+ b = mouse_get_state(&mx, &my);
if (!b)
break;
}
@@ -1754,9 +1734,7 @@ void tag_list_ui(pixel *vid_buf)
while (!sdl_poll())
{
bq = b;
- b = SDL_GetMouseState(&mx, &my);
- mx /= sdl_scale;
- my /= sdl_scale;
+ b = mouse_get_state(&mx, &my);
op = tag = NULL;
@@ -1868,7 +1846,7 @@ void tag_list_ui(pixel *vid_buf)
}
while (!sdl_poll())
{
- b = SDL_GetMouseState(&mx, &my);
+ b = mouse_get_state(&mx, &my);
if (!b)
break;
}
@@ -1892,7 +1870,7 @@ int save_name_ui(pixel *vid_buf)
while (!sdl_poll())
{
- b = SDL_GetMouseState(&mx, &my);
+ b = mouse_get_state(&mx, &my);
if (!b)
break;
}
@@ -1942,9 +1920,7 @@ int save_name_ui(pixel *vid_buf)
while (!sdl_poll())
{
bq = b;
- b = SDL_GetMouseState(&mx, &my);
- mx /= sdl_scale;
- my /= sdl_scale;
+ b = mouse_get_state(&mx, &my);
drawrect(vid_buf, x0, y0, 420, 90+YRES/4, 192, 192, 192, 255);
clearrect(vid_buf, x0, y0, 420, 90+YRES/4);
@@ -2035,16 +2011,14 @@ void menu_ui(pixel *vid_buf, int i, int *sl, int *sr)
while (!sdl_poll())
{
- b = SDL_GetMouseState(&mx, &my);
+ b = mouse_get_state(&mx, &my);
if (!b)
break;
}
while (!sdl_poll())
{
bq = b;
- b = SDL_GetMouseState(&mx, &my);
- mx /= sdl_scale;
- my /= sdl_scale;
+ b = mouse_get_state(&mx, &my);
rows = ceil((float)msections[i].itemcount/16.0f);
height = (ceil((float)msections[i].itemcount/16.0f)*18);
width = restrict_flt(msections[i].itemcount*31, 0, 16*31);
@@ -2213,7 +2187,7 @@ void menu_ui(pixel *vid_buf, int i, int *sl, int *sr)
while (!sdl_poll())
{
- b = SDL_GetMouseState(&mx, &my);
+ b = mouse_get_state(&mx, &my);
if (!b)
break;
}
@@ -2225,8 +2199,6 @@ void menu_ui_v3(pixel *vid_buf, int i, int *sl, int *sr, int *su, int *dae, int
{
int h,x,y,n=0,height,width,sy,rows=0,xoff=0,fwidth;
SEC = SEC2;
- mx /= sdl_scale;
- my /= sdl_scale;
rows = ceil((float)msections[i].itemcount/16.0f);
height = (ceil((float)msections[i].itemcount/16.0f)*18);
width = restrict_flt(msections[i].itemcount*31, 0, 16*31);
@@ -2594,8 +2566,6 @@ int quickoptions_tooltip_y = 0;
void quickoptions_menu(pixel *vid_buf, int b, int bq, int x, int y)
{
int i = 0;
- x /= sdl_scale;
- y /= sdl_scale;
if(quickoptions_tooltip_fade && quickoptions_tooltip)
{
drawtext_outline(vid_buf, (XRES - 5) - textwidth(quickoptions_tooltip), quickoptions_tooltip_y, quickoptions_tooltip, 255, 255, 255, quickoptions_tooltip_fade*20, 0, 0, 0, quickoptions_tooltip_fade*15);
@@ -3088,7 +3058,7 @@ int search_ui(pixel *vid_buf)
while (!sdl_poll())
{
- b = SDL_GetMouseState(&mx, &my);
+ b = mouse_get_state(&mx, &my);
if (!b)
break;
}
@@ -3116,9 +3086,7 @@ int search_ui(pixel *vid_buf)
bq = b;
mxq = mx;
myq = my;
- b = SDL_GetMouseState(&mx, &my);
- mx /= sdl_scale;
- my /= sdl_scale;
+ b = mouse_get_state(&mx, &my);
if (mx!=mxq || my!=myq || sdl_wheel || b)
mmt = 0;
@@ -3800,7 +3768,7 @@ int report_ui(pixel* vid_buf, char *save_id)
fillrect(vid_buf, -1, -1, XRES+BARSIZE, YRES+MENUSIZE, 0, 0, 0, 192);
while (!sdl_poll())
{
- b = SDL_GetMouseState(&mx, &my);
+ b = mouse_get_state(&mx, &my);
if (!b)
break;
}
@@ -3811,9 +3779,7 @@ int report_ui(pixel* vid_buf, char *save_id)
drawrect(vid_buf, 205, 155, (XRES+BARSIZE-400)-10, (YRES+MENUSIZE-300)-28, 255, 255, 255, 170);
bq = b;
- b = SDL_GetMouseState(&mx, &my);
- mx /= sdl_scale;
- my /= sdl_scale;
+ b = mouse_get_state(&mx, &my);
drawrect(vid_buf, 200, (YRES+MENUSIZE-150)-18, 50, 18, 255, 255, 255, 255);
@@ -3899,7 +3865,7 @@ int open_ui(pixel *vid_buf, char *save_id, char *save_date)
while (!sdl_poll())
{
- b = SDL_GetMouseState(&mx, &my);
+ b = mouse_get_state(&mx, &my);
if (!b)
break;
}
@@ -3993,9 +3959,7 @@ int open_ui(pixel *vid_buf, char *save_id, char *save_date)
while (!sdl_poll())
{
bq = b;
- b = SDL_GetMouseState(&mx, &my);
- mx /= sdl_scale;
- my /= sdl_scale;
+ b = mouse_get_state(&mx, &my);
if (active && http_async_req_status(http))
{
@@ -4367,7 +4331,7 @@ int open_ui(pixel *vid_buf, char *save_id, char *save_date)
//Prevent those mouse clicks being passed down.
while (!sdl_poll())
{
- b = SDL_GetMouseState(&mx, &my);
+ b = mouse_get_state(&mx, &my);
if (!b)
break;
}
@@ -5200,9 +5164,7 @@ char *console_ui(pixel *vid_buf,char error[255],char console_more) {
}
while (!sdl_poll())
{
- b = SDL_GetMouseState(&mx, &my);
- mx /= sdl_scale;
- my /= sdl_scale;
+ b = mouse_get_state(&mx, &my);
ed.focus = 1;
memcpy(vid_buf,old_buf,(XRES+BARSIZE)*YRES*PIXELSIZE);
@@ -5403,9 +5365,7 @@ unsigned int decorations_ui(pixel *vid_buf,int *bsx,int *bsy, unsigned int saved
while (!sdl_poll())
{
bq = b;
- b = SDL_GetMouseState(&mx, &my);
- mx /= sdl_scale;
- my /= sdl_scale;
+ b = mouse_get_state(&mx, &my);
memcpy(vid_buf,old_buf,(XRES+BARSIZE)*(YRES+MENUSIZE)*PIXELSIZE);
render_parts(vid_buf);
@@ -5431,14 +5391,8 @@ unsigned int decorations_ui(pixel *vid_buf,int *bsx,int *bsy, unsigned int saved
box_G.x = XRES - 254 + 40;
box_B.x = XRES - 254 + 75;
}
- if (zoom_en && mx>=zoom_wx && my>=zoom_wy //change mouse position while it is in a zoom window
- && mx<(zoom_wx+ZFACTOR*ZSIZE)
- && my<(zoom_wy+ZFACTOR*ZSIZE))
- {
- mx = (((mx-zoom_wx)/ZFACTOR)+zoom_x);
- my = (((my-zoom_wy)/ZFACTOR)+zoom_y);
- }
-
+ mouse_coords_window_to_sim(&mx, &my, mx, my);//change mouse position while it is in a zoom window
+
drawrect(vid_buf, -1, -1, XRES+1, YRES+1, 220, 220, 220, 255);
drawrect(vid_buf, -1, -1, XRES+2, YRES+2, 70, 70, 70, 255);
drawtext(vid_buf, 2, 388, "Welcome to the decoration editor v.3 (by cracker64) \n\nClicking the current color on the window will move it to the other side. Right click is eraser. ", 255, 255, 255, 255);
@@ -6020,7 +5974,7 @@ int save_filename_ui(pixel *vid_buf)
while (!sdl_poll())
{
- b = SDL_GetMouseState(&mx, &my);
+ b = mouse_get_state(&mx, &my);
if (!b)
break;
}
@@ -6033,9 +5987,7 @@ int save_filename_ui(pixel *vid_buf)
while (!sdl_poll())
{
bq = b;
- b = SDL_GetMouseState(&mx, &my);
- mx /= sdl_scale;
- my /= sdl_scale;
+ b = mouse_get_state(&mx, &my);
clearrect(vid_buf, x0-2, y0-2, xsize+4, ysize+4);
drawrect(vid_buf, x0, y0, xsize, ysize, 192, 192, 192, 255);
@@ -6120,7 +6072,7 @@ int save_filename_ui(pixel *vid_buf)
savefin:
while (!sdl_poll())
{
- b = SDL_GetMouseState(&mx, &my);
+ b = mouse_get_state(&mx, &my);
if (!b)
break;
}
@@ -6165,7 +6117,7 @@ void catalogue_ui(pixel * vid_buf)
cssave = csave = saves;
while (!sdl_poll())
{
- b = SDL_GetMouseState(&mx, &my);
+ b = mouse_get_state(&mx, &my);
if (!b)
break;
}
@@ -6173,9 +6125,7 @@ void catalogue_ui(pixel * vid_buf)
fillrect(vid_buf, -1, -1, XRES+BARSIZE, YRES+MENUSIZE, 0, 0, 0, 192);
while (!sdl_poll())
{
- b = SDL_GetMouseState(&mx, &my);
- mx /= sdl_scale;
- my /= sdl_scale;
+ b = mouse_get_state(&mx, &my);
sprintf(savetext, "Found %d save%s", rescount, rescount==1?"":"s");
clearrect(vid_buf, x0-2, y0-2, xsize+4, ysize+4);
clearrect(vid_buf2, x0-2, y0-2, xsize+4, ysize+4);
@@ -6352,7 +6302,7 @@ void catalogue_ui(pixel * vid_buf)
openfin:
while (!sdl_poll())
{
- b = SDL_GetMouseState(&mx, &my);
+ b = mouse_get_state(&mx, &my);
if (!b)
break;
}
@@ -6511,7 +6461,7 @@ void render_ui(pixel * vid_buf, int xcoord, int ycoord, int orientation)
while (!sdl_poll())
{
- b = SDL_GetMouseState(&mx, &my);
+ b = mouse_get_state(&mx, &my);
if (!b)
break;
}
@@ -6519,9 +6469,7 @@ void render_ui(pixel * vid_buf, int xcoord, int ycoord, int orientation)
while (!sdl_poll())
{
bq = b;
- b = SDL_GetMouseState(&mx, &my);
- mx /= sdl_scale;
- my /= sdl_scale;
+ b = mouse_get_state(&mx, &my);
memcpy(vid_buf, o_vid_buf, ((YRES+MENUSIZE) * (XRES+BARSIZE)) * PIXELSIZE);
render_parts(vid_buf);
@@ -6676,7 +6624,7 @@ void render_ui(pixel * vid_buf, int xcoord, int ycoord, int orientation)
while (!sdl_poll())
{
- b = SDL_GetMouseState(&mx, &my);
+ b = mouse_get_state(&mx, &my);
if (!b)
break;
}
@@ -6753,7 +6701,7 @@ void simulation_ui(pixel * vid_buf)
while (!sdl_poll())
{
- b = SDL_GetMouseState(&mx, &my);
+ b = mouse_get_state(&mx, &my);
if (!b)
break;
}
@@ -6761,9 +6709,7 @@ void simulation_ui(pixel * vid_buf)
while (!sdl_poll())
{
bq = b;
- b = SDL_GetMouseState(&mx, &my);
- mx /= sdl_scale;
- my /= sdl_scale;
+ b = mouse_get_state(&mx, &my);
clearrect(vid_buf, x0-2, y0-2, xsize+4, ysize+4);
drawrect(vid_buf, x0, y0, xsize, ysize, 192, 192, 192, 255);
@@ -6856,8 +6802,36 @@ void simulation_ui(pixel * vid_buf)
while (!sdl_poll())
{
- b = SDL_GetMouseState(&mx, &my);
+ b = mouse_get_state(&mx, &my);
if (!b)
break;
}
}
+
+Uint8 mouse_get_state(int *x, int *y)
+{
+ //Wrapper around SDL_GetMouseState to divide by sdl_scale
+ Uint8 sdl_b;
+ int sdl_x, sdl_y;
+ sdl_b = SDL_GetMouseState(&sdl_x, &sdl_y);
+ *x = sdl_x/sdl_scale;
+ *y = sdl_y/sdl_scale;
+ return sdl_b;
+}
+
+void mouse_coords_window_to_sim(int *sim_x, int *sim_y, int window_x, int window_y)
+{
+ //Change mouse coords to take zoom window into account
+ if (zoom_en && window_x>=zoom_wx && window_y>=zoom_wy
+ && window_x<(zoom_wx+ZFACTOR*ZSIZE)
+ && window_y<(zoom_wy+ZFACTOR*ZSIZE))
+ {
+ *sim_x = (((window_x-zoom_wx)/ZFACTOR)+zoom_x);
+ *sim_y = (((window_y-zoom_wy)/ZFACTOR)+zoom_y);
+ }
+ else
+ {
+ *sim_x = window_x;
+ *sim_y = window_y;
+ }
+}