terom@27: terom@27: #include "tile.h" terom@27: #include "render_struct.h" terom@27: terom@27: #define MIN(a, b) ((a) < (b) ? (a) : (b)) terom@27: #define MAX(a, b) ((a) > (b) ? (a) : (b)) terom@27: terom@27: int render_set_tile (struct render *render_info, u_int32_t view_w, u_int32_t view_h, u_int32_t x, u_int32_t y, u_int16_t zoom) { terom@27: // figure out how many tiles will fit onto the view area terom@27: u_int16_t tiles = MIN( terom@27: MAX(view_w / TILE_WIDTH, 1), terom@27: MAX(view_h / TILE_HEIGHT, 1) terom@27: ) + 1; terom@27: terom@27: // have it be square terom@27: view_w = tiles * TILE_WIDTH; terom@27: view_h = tiles * TILE_HEIGHT; terom@27: terom@27: // the image width is fixed terom@27: render_info->img_w = TILE_WIDTH; terom@27: render_info->img_h = TILE_HEIGHT; terom@27: terom@27: // calcuate how wide each pixel is terom@27: double width_scale = REGION_W/(view_w << zoom); terom@27: double height_scale = REGION_H/(view_h << zoom); terom@27: terom@27: // calcuate the region terom@27: render_info->x1 = REGION_X1 + x * width_scale; terom@27: render_info->y1 = REGION_Y1 + y * height_scale; terom@27: render_info->x2 = render_info->x1 + TILE_WIDTH * width_scale; terom@27: render_info->y2 = render_info->y1 + TILE_HEIGHT * height_scale; terom@27: terom@27: // ok terom@27: return 0; terom@27: }