* Determine the tile relative to the base tile of the smallmap, and the pixel position at * that tile for a point in the smallmap. * @param px Horizontal coordinate of the pixel. * @param py Vertical coordinate of the pixel. * @param[out] sub Pixel position at the tile (0..3). * @param add_sub Add current #subscroll to the position. * @return Tile being displayed at the gi
| 1146 | * @note The #subscroll offset is already accounted for. |
| 1147 | */ |
| 1148 | Point PixelToTile(int px, int py, int *sub, bool add_sub = true) const |
| 1149 | { |
| 1150 | if (add_sub) px += this->subscroll; // Total horizontal offset. |
| 1151 | |
| 1152 | /* For each two rows down, add a x and a y tile, and |
| 1153 | * For each four pixels to the right, move a tile to the right. */ |
| 1154 | Point pt = {((py >> 1) - (px >> 2)) * this->zoom, ((py >> 1) + (px >> 2)) * this->zoom}; |
| 1155 | px &= 3; |
| 1156 | |
| 1157 | if (py & 1) { // Odd number of rows, handle the 2 pixel shift. |
| 1158 | if (px < 2) { |
| 1159 | pt.x += this->zoom; |
| 1160 | px += 2; |
| 1161 | } else { |
| 1162 | pt.y += this->zoom; |
| 1163 | px -= 2; |
| 1164 | } |
| 1165 | } |
| 1166 | |
| 1167 | *sub = px; |
| 1168 | return pt; |
| 1169 | } |
| 1170 | |
| 1171 | /** |
| 1172 | * Compute base parameters of the smallmap such that tile (\a tx, \a ty) starts at pixel (\a x, \a y). |
no outgoing calls
no test coverage detected