Fix y-axis mapping incorrect for images

This commit is contained in:
Kovid Goyal 2017-10-04 19:34:34 +05:30
parent e9bc64205e
commit 46bb482e96
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 11 additions and 11 deletions

View File

@ -575,17 +575,17 @@ grman_update_layers(GraphicsManager *self, unsigned int scrolled_by, float scree
Image *img; ImageRef *ref;
ImageRect r;
float screen_width = dx * num_cols, screen_height = dy * num_rows;
float screen_bottom = screen_top + screen_height;
float screen_bottom = screen_top - screen_height;
float screen_width_px = num_cols * global_state.cell_width;
float screen_height_px = num_rows * global_state.cell_height;
// Iterate over all visible refs and create render data
self->count = 0;
for (i = 0; i < self->image_count; i++) { img = self->images + i; for (j = 0; j < img->refcnt; j++) { ref = img->refs + j;
r.top = screen_top + (scrolled_by + ref->start_row) * dy + dy * (float)ref->cell_y_offset / (float)global_state.cell_height;
if (ref->num_rows) r.bottom = screen_top + (scrolled_by + ref->start_row + ref->num_rows) * dy;
else r.bottom = r.top + screen_height * (float)ref->src_height / screen_height_px;
if (r.top > screen_bottom || r.bottom < screen_top) continue; // not visible
r.top = screen_top - (scrolled_by + ref->start_row) * dy - dy * (float)ref->cell_y_offset / (float)global_state.cell_height;
if (ref->num_rows) r.bottom = screen_top - (scrolled_by + ref->start_row + ref->num_rows) * dy;
else r.bottom = r.top - screen_height * (float)ref->src_height / screen_height_px;
if (r.top < screen_bottom || r.bottom > screen_top) continue; // not visible
r.left = screen_left + ref->start_column * dx + dx * (float)ref->cell_x_offset / (float) global_state.cell_width;
if (ref->num_cols) r.right = screen_left + (ref->start_column + ref->num_cols) * dx;

View File

@ -175,8 +175,8 @@ class TestGraphics(BaseTest):
cmd = 'a=p,i=%d,%s' % (iid, put_cmd(**kw))
send_command(screen, cmd)
def layers(screen, scrolled_by=0, xstart=0, ystart=0):
dx, dy = (2 - xstart) / s.columns, (2 - ystart) / s.lines
def layers(screen, scrolled_by=0, xstart=-1, ystart=1):
dx, dy = 2 / s.columns, 2 / s.lines
return screen.grman.update_layers(scrolled_by, xstart, ystart, dx, dy, screen.columns, screen.lines)
def rect_eq(r, left, top, right, bottom):
@ -190,16 +190,16 @@ class TestGraphics(BaseTest):
l = layers(s)
self.ae(len(l), 1)
rect_eq(l[0]['src_rect'], 0, 0, 1, 1)
rect_eq(l[0]['dest_rect'], 0, 0, dx, dy)
rect_eq(l[0]['dest_rect'], -1, 1, -1 + dx, 1 - dy)
self.ae(l[0]['group_count'], 1)
self.ae(s.cursor.x, 1), self.ae(s.cursor.y, 0)
put_ref(s, iid, num_cols=s.columns, x_off=2, y_off=1, width=3, height=5, cell_x_off=3, cell_y_off=1, z=-1)
l = layers(s)
self.ae(len(l), 2)
rect_eq(l[0]['src_rect'], 2 / 10, 1 / 20, (2 + 3) / 10, (1 + 5)/20)
left, top = dx + 3 * dx / cw, 1 * dy / ch
rect_eq(l[0]['dest_rect'], left, top, (1 + s.columns) * dx, top + dy * 5 / ch)
left, top = -1 + dx + 3 * dx / cw, 1 - 1 * dy / ch
rect_eq(l[0]['dest_rect'], left, top, -1 + (1 + s.columns) * dx, top - dy * 5 / ch)
rect_eq(l[1]['src_rect'], 0, 0, 1, 1)
rect_eq(l[1]['dest_rect'], 0, 0, dx, dy)
rect_eq(l[1]['dest_rect'], -1, 1, -1 + dx, 1 - dy)
self.ae(l[0]['group_count'], 1), self.ae(l[1]['group_count'], 1)
self.ae(s.cursor.x, 0), self.ae(s.cursor.y, 1)