Make fast scroll code easier to read

This commit is contained in:
Chris Young 2013-02-03 18:50:16 +00:00
parent 871a8e7cba
commit ccaeced4bf
1 changed files with 38 additions and 28 deletions

View File

@ -1050,6 +1050,28 @@ void ami_update_quals(struct gui_window_2 *gwin)
}
}
bool ami_spacebox_to_ns_coords(struct gui_window_2 *gwin, int *x, int *y,
int space_x, int space_y)
{
int xs, ys;
int ns_x = space_x;
int ns_y = space_y;
ns_x /= gwin->bw->scale;
ns_y /= gwin->bw->scale;
ami_get_hscroll_pos(gwin, (ULONG *)&xs);
ami_get_vscroll_pos(gwin, (ULONG *)&ys);
ns_x += xs;
ns_y += ys;
*x = ns_x;
*y = ns_y;
return true;
}
bool ami_mouse_to_ns_coords(struct gui_window_2 *gwin, int *x, int *y,
int mouse_x, int mouse_y)
{
@ -1069,19 +1091,7 @@ bool ami_mouse_to_ns_coords(struct gui_window_2 *gwin, int *x, int *y,
if((ns_x < 0) || (ns_x > bbox->Width) || (ns_y < 0) || (ns_y > bbox->Height))
return false;
ns_x /= gwin->bw->scale;
ns_y /= gwin->bw->scale;
ami_get_hscroll_pos(gwin, (ULONG *)&xs);
ami_get_vscroll_pos(gwin, (ULONG *)&ys);
ns_x += xs;
ns_y += ys;
*x = ns_x;
*y = ns_y;
return true;
return ami_spacebox_to_ns_coords(gwin, x, y, ns_x, ns_y);
}
void ami_gui_scroll_internal(struct gui_window_2 *gwin, int xs, int ys)
@ -3832,10 +3842,13 @@ void ami_do_redraw(struct gui_window_2 *gwin)
gwin->redraw_scroll = false;
if(gwin->new_content) gwin->redraw_scroll = false;
// if(gwin->bw->scale != 1.0) gwin->redraw_scroll = false;
}
if(gwin->redraw_scroll)
{
int x0, y0, x1, y1;
gwin->bw->window->c_h_temp = gwin->bw->window->c_h;
gui_window_remove_caret(gwin->bw->window);
@ -3846,31 +3859,28 @@ void ami_do_redraw(struct gui_window_2 *gwin)
if(vcurrent>oldv) /* Going down */
{
ami_do_redraw_limits(gwin->bw->window, gwin->bw, true,
hcurrent, (oldv + height) / gwin->bw->scale - 1,
(hcurrent + width) / gwin->bw->scale,
(vcurrent + height) / gwin->bw->scale + 1);
ami_spacebox_to_ns_coords(gwin, &x0, &y0, 0, height - (vcurrent - oldv));
ami_spacebox_to_ns_coords(gwin, &x1, &y1, width, height);
ami_do_redraw_limits(gwin->bw->window, gwin->bw, true, x0, y0, x1, y1);
}
else if(vcurrent<oldv) /* Going up */
{
ami_do_redraw_limits(gwin->bw->window, gwin->bw, true,
hcurrent, vcurrent,
hcurrent + (width / gwin->bw->scale),
oldv);
ami_spacebox_to_ns_coords(gwin, &x0, &y0, 0, 0);
ami_spacebox_to_ns_coords(gwin, &x1, &y1, width, oldv - vcurrent);
ami_do_redraw_limits(gwin->bw->window, gwin->bw, true, x0, y0, x1, y1);
}
if(hcurrent>oldh) /* Going right */
{
ami_do_redraw_limits(gwin->bw->window, gwin->bw, true,
(width / gwin->bw->scale) + oldh , vcurrent,
hcurrent + (width / gwin->bw->scale),
vcurrent + (height / gwin->bw->scale));
ami_spacebox_to_ns_coords(gwin, &x0, &y0, width - (hcurrent - oldh), 0);
ami_spacebox_to_ns_coords(gwin, &x1, &y1, width, height);
ami_do_redraw_limits(gwin->bw->window, gwin->bw, true, x0, y0, x1, y1);
}
else if(hcurrent<oldh) /* Going left */
{
ami_do_redraw_limits(gwin->bw->window, gwin->bw, true,
hcurrent, vcurrent,
oldh, vcurrent + (height / gwin->bw->scale));
ami_spacebox_to_ns_coords(gwin, &x0, &y0, 0, 0);
ami_spacebox_to_ns_coords(gwin, &x1, &y1, oldh - hcurrent, height);
ami_do_redraw_limits(gwin->bw->window, gwin->bw, true, x0, y0, x1, y1);
}
}
else