equal
deleted
inserted
replaced
|
1 |
|
2 #include "tile.h" |
|
3 #include "render_struct.h" |
|
4 |
|
5 #define MIN(a, b) ((a) < (b) ? (a) : (b)) |
|
6 #define MAX(a, b) ((a) > (b) ? (a) : (b)) |
|
7 |
|
8 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) { |
|
9 // figure out how many tiles will fit onto the view area |
|
10 u_int16_t tiles = MIN( |
|
11 MAX(view_w / TILE_WIDTH, 1), |
|
12 MAX(view_h / TILE_HEIGHT, 1) |
|
13 ) + 1; |
|
14 |
|
15 // have it be square |
|
16 view_w = tiles * TILE_WIDTH; |
|
17 view_h = tiles * TILE_HEIGHT; |
|
18 |
|
19 // the image width is fixed |
|
20 render_info->img_w = TILE_WIDTH; |
|
21 render_info->img_h = TILE_HEIGHT; |
|
22 |
|
23 // calcuate how wide each pixel is |
|
24 double width_scale = REGION_W/(view_w << zoom); |
|
25 double height_scale = REGION_H/(view_h << zoom); |
|
26 |
|
27 // calcuate the region |
|
28 render_info->x1 = REGION_X1 + x * width_scale; |
|
29 render_info->y1 = REGION_Y1 + y * height_scale; |
|
30 render_info->x2 = render_info->x1 + TILE_WIDTH * width_scale; |
|
31 render_info->y2 = render_info->y1 + TILE_HEIGHT * height_scale; |
|
32 |
|
33 // ok |
|
34 return 0; |
|
35 } |