1#ifndef YAZE_APP_GUI_CANVAS_COORDINATE_MAPPER_H
2#define YAZE_APP_GUI_CANVAS_COORDINATE_MAPPER_H
11#include "imgui/imgui.h"
171 int GetTileId(
float canvas_x,
float canvas_y)
const;
237 const std::vector<std::pair<float, float>>& positions)
const;
262 float screen_x,
float screen_y,
263 float tile_size = 16.0f);
269 float tile_size,
int tiles_per_row);
274ImVec4
GetTileBounds(
int tile_x,
int tile_y,
float tile_size,
float scale);
Maps screen coordinates to tile/ROM data.
void SetRomOffsetCalculator(RomOffsetCalculator calculator)
Set a custom ROM offset calculator.
const CoordinateMapperConfig & GetConfig() const
bool IsInCanvasBounds(float screen_x, float screen_y) const
Check if screen coordinates are within canvas bounds.
int GetTileId(float canvas_x, float canvas_y) const
Get tile ID from canvas position.
void SetConfig(const CoordinateMapperConfig &config)
~CoordinateMapper()=default
std::pair< int, int > SnapToTileGrid(float x, float y) const
CoordinateMapper()=default
ImVec2 TileToScreen(int tile_x, int tile_y) const
Convert tile coordinates to screen position.
ImVec2 ApplyInverseScale(float x, float y) const
ScreenToTileResult ScreenToTile(float screen_x, float screen_y) const
Convert screen coordinates to tile information.
std::function< uint32_t(int tile_id)> RomOffsetCalculator
Callback type for custom ROM offset calculation.
std::vector< ScreenToTileResult > ScreenToTileBatch(const std::vector< std::pair< float, float > > &positions) const
Convert multiple screen positions to tile info.
void SetCanvasId(const std::string &id)
TileHitInfo CanvasToTile(float canvas_x, float canvas_y) const
Convert canvas-relative coordinates to tile information.
int GetTile16Index(float canvas_x, float canvas_y) const
Get tile16 index from canvas position.
void SetScale(float scale)
ImVec2 ApplyScrollOffset(float canvas_x, float canvas_y) const
int CalculateLocalMapId(float content_x, float content_y) const
Calculate local map ID from content coordinates.
void SetGeometry(const CanvasGeometry &geometry)
CoordinateMapperConfig config_
const std::string & GetCanvasId() const
bool IsValidTileCoord(int tile_x, int tile_y) const
Check if tile coordinates are valid.
RomOffsetCalculator rom_offset_calculator_
uint32_t CalculateRomOffset(int tile_id, uint32_t base_offset=0) const
Calculate ROM offset for a given tile ID.
const CanvasGeometry & GetGeometry() const
ImVec2 TileToCanvas(int tile_x, int tile_y) const
Convert tile coordinates to canvas position.
int CalculateTileIndex(float local_x, float local_y, float tile_size, int tiles_per_row)
Calculate tile index from local position and grid settings.
ImVec4 GetTileBounds(int tile_x, int tile_y, float tile_size, float scale)
Get tile bounds in canvas space.
TileHitInfo ScreenToTileQuick(const CanvasRuntime &runtime, float screen_x, float screen_y, float tile_size)
Quick screen-to-tile lookup using canvas runtime state.
Canvas geometry calculated per-frame.
Configuration for coordinate mapping.
bool use_tile16
Use 16x16 tile indexing.
int tiles_per_col
Number of tiles per column.
int local_map_size
Size of local map in pixels (512 for OW)
int tiles_per_row
Number of tiles per row in the map.
float tile_size
Size of tiles in pixels (8 or 16)
Screen coordinate mapping result.
float scaled_x
X after applying inverse scale.
TileHitInfo tile_info
Full tile information.
float scaled_y
Y after applying inverse scale.
float canvas_x
X position relative to canvas origin.
float canvas_y
Y position relative to canvas origin.
float content_y
Y in content space (with scroll)
float screen_x
Original screen X coordinate.
float screen_y
Original screen Y coordinate.
bool in_canvas_bounds
Whether point is within canvas.
float content_x
X in content space (with scroll)
Information about a tile at a specific screen location.
bool is_valid
Whether the hit is valid.
ImVec2 tile_origin_px
Top-left of tile in canvas space (pixels)
int palette_group
Palette group index.
uint32_t rom_offset
ROM offset for tile data.
std::string canvas_id
ID of the canvas that was hit.
int palette_index
Palette index within group.
int tile_id
8x8 tile ID (-1 if invalid)
int map_y
Tile Y coordinate in map space.
int tile16_index
16x16 tile index (-1 if invalid)
int local_map_id
Local map ID (for overworld)
int map_x
Tile X coordinate in map space.
ImVec2 tile_size_px
Size of the tile in pixels.