Maps screen coordinates to tile/ROM data. More...
#include <coordinate_mapper.h>

Public Types | |
| using | RomOffsetCalculator = std::function<uint32_t(int tile_id)> |
| Callback type for custom ROM offset calculation. | |
Public Member Functions | |
| CoordinateMapper ()=default | |
| ~CoordinateMapper ()=default | |
| void | SetConfig (const CoordinateMapperConfig &config) |
| const CoordinateMapperConfig & | GetConfig () const |
| void | SetGeometry (const CanvasGeometry &geometry) |
| const CanvasGeometry & | GetGeometry () const |
| void | SetScale (float scale) |
| float | GetScale () const |
| void | SetCanvasId (const std::string &id) |
| const std::string & | GetCanvasId () const |
| ScreenToTileResult | ScreenToTile (float screen_x, float screen_y) const |
| Convert screen coordinates to tile information. | |
| TileHitInfo | CanvasToTile (float canvas_x, float canvas_y) const |
| Convert canvas-relative coordinates to tile information. | |
| ImVec2 | TileToCanvas (int tile_x, int tile_y) const |
| Convert tile coordinates to canvas position. | |
| ImVec2 | TileToScreen (int tile_x, int tile_y) const |
| Convert tile coordinates to screen position. | |
| int | GetTileId (float canvas_x, float canvas_y) const |
| Get tile ID from canvas position. | |
| int | GetTile16Index (float canvas_x, float canvas_y) const |
| Get tile16 index from canvas position. | |
| bool | IsInCanvasBounds (float screen_x, float screen_y) const |
| Check if screen coordinates are within canvas bounds. | |
| bool | IsValidTileCoord (int tile_x, int tile_y) const |
| Check if tile coordinates are valid. | |
| uint32_t | CalculateRomOffset (int tile_id, uint32_t base_offset=0) const |
| Calculate ROM offset for a given tile ID. | |
| void | SetRomOffsetCalculator (RomOffsetCalculator calculator) |
| Set a custom ROM offset calculator. | |
| int | CalculateLocalMapId (float content_x, float content_y) const |
| Calculate local map ID from content coordinates. | |
| std::vector< ScreenToTileResult > | ScreenToTileBatch (const std::vector< std::pair< float, float > > &positions) const |
| Convert multiple screen positions to tile info. | |
Private Member Functions | |
| ImVec2 | ApplyScrollOffset (float canvas_x, float canvas_y) const |
| ImVec2 | ApplyInverseScale (float x, float y) const |
| std::pair< int, int > | SnapToTileGrid (float x, float y) const |
Private Attributes | |
| CoordinateMapperConfig | config_ |
| CanvasGeometry | geometry_ |
| float | scale_ = 1.0f |
| std::string | canvas_id_ |
| RomOffsetCalculator | rom_offset_calculator_ |
Maps screen coordinates to tile/ROM data.
Provides comprehensive coordinate transformation for mapping user interactions (mouse clicks, touches) to underlying tile data in the ROM. Handles all necessary transformations including:
Usage:
Definition at line 113 of file coordinate_mapper.h.
| using yaze::gui::CoordinateMapper::RomOffsetCalculator = std::function<uint32_t(int tile_id)> |
Callback type for custom ROM offset calculation.
Definition at line 210 of file coordinate_mapper.h.
|
default |
|
default |
|
inline |
Definition at line 119 of file coordinate_mapper.h.
References config_.
|
inline |
Definition at line 120 of file coordinate_mapper.h.
References config_.
|
inline |
Definition at line 122 of file coordinate_mapper.h.
References geometry_.
|
inline |
Definition at line 123 of file coordinate_mapper.h.
References geometry_.
|
inline |
Definition at line 125 of file coordinate_mapper.h.
References scale_.
|
inline |
Definition at line 126 of file coordinate_mapper.h.
References scale_.
|
inline |
Definition at line 128 of file coordinate_mapper.h.
References canvas_id_.
|
inline |
Definition at line 129 of file coordinate_mapper.h.
References canvas_id_.
| ScreenToTileResult yaze::gui::CoordinateMapper::ScreenToTile | ( | float | screen_x, |
| float | screen_y ) const |
Convert screen coordinates to tile information.
| screen_x | Screen X coordinate (from ImGui mouse position) |
| screen_y | Screen Y coordinate (from ImGui mouse position) |
Definition at line 11 of file coordinate_mapper.cc.
References ApplyInverseScale(), ApplyScrollOffset(), yaze::gui::TileHitInfo::canvas_id, canvas_id_, yaze::gui::CanvasGeometry::canvas_p0, yaze::gui::ScreenToTileResult::canvas_x, yaze::gui::ScreenToTileResult::canvas_y, CanvasToTile(), yaze::gui::ScreenToTileResult::content_x, yaze::gui::ScreenToTileResult::content_y, geometry_, yaze::gui::ScreenToTileResult::in_canvas_bounds, IsInCanvasBounds(), yaze::gui::ScreenToTileResult::scaled_x, yaze::gui::ScreenToTileResult::scaled_y, yaze::gui::ScreenToTileResult::screen_x, yaze::gui::ScreenToTileResult::screen_y, and yaze::gui::ScreenToTileResult::tile_info.
Referenced by ScreenToTileBatch().

| TileHitInfo yaze::gui::CoordinateMapper::CanvasToTile | ( | float | canvas_x, |
| float | canvas_y ) const |
Convert canvas-relative coordinates to tile information.
| canvas_x | X position relative to canvas top-left |
| canvas_y | Y position relative to canvas top-left |
Definition at line 43 of file coordinate_mapper.cc.
References CalculateLocalMapId(), CalculateRomOffset(), config_, GetTile16Index(), GetTileId(), yaze::gui::TileHitInfo::is_valid, IsValidTileCoord(), yaze::gui::TileHitInfo::local_map_id, yaze::gui::CoordinateMapperConfig::local_map_size, yaze::gui::TileHitInfo::map_x, yaze::gui::TileHitInfo::map_y, yaze::gui::TileHitInfo::rom_offset, rom_offset_calculator_, SnapToTileGrid(), yaze::gui::TileHitInfo::tile16_index, yaze::gui::TileHitInfo::tile_id, yaze::gui::TileHitInfo::tile_origin_px, yaze::gui::CoordinateMapperConfig::tile_size, yaze::gui::TileHitInfo::tile_size_px, and yaze::gui::CoordinateMapperConfig::use_tile16.
Referenced by ScreenToTile().
| ImVec2 yaze::gui::CoordinateMapper::TileToCanvas | ( | int | tile_x, |
| int | tile_y ) const |
Convert tile coordinates to canvas position.
| tile_x | Tile X coordinate |
| tile_y | Tile Y coordinate |
Definition at line 87 of file coordinate_mapper.cc.
References config_, geometry_, scale_, yaze::gui::CanvasGeometry::scrolling, and yaze::gui::CoordinateMapperConfig::tile_size.
Referenced by TileToScreen().
| ImVec2 yaze::gui::CoordinateMapper::TileToScreen | ( | int | tile_x, |
| int | tile_y ) const |
Convert tile coordinates to screen position.
| tile_x | Tile X coordinate |
| tile_y | Tile Y coordinate |
Definition at line 93 of file coordinate_mapper.cc.
References yaze::gui::CanvasGeometry::canvas_p0, geometry_, and TileToCanvas().

| int yaze::gui::CoordinateMapper::GetTileId | ( | float | canvas_x, |
| float | canvas_y ) const |
Get tile ID from canvas position.
| canvas_x | Canvas-relative X position |
| canvas_y | Canvas-relative Y position |
Definition at line 99 of file coordinate_mapper.cc.
References config_, IsValidTileCoord(), yaze::gui::CoordinateMapperConfig::tile_size, and yaze::gui::CoordinateMapperConfig::tiles_per_row.
Referenced by CanvasToTile().

| int yaze::gui::CoordinateMapper::GetTile16Index | ( | float | canvas_x, |
| float | canvas_y ) const |
Get tile16 index from canvas position.
| canvas_x | Canvas-relative X position |
| canvas_y | Canvas-relative Y position |
Definition at line 114 of file coordinate_mapper.cc.
References config_, yaze::gui::CoordinateMapperConfig::tile_size, and yaze::gui::CoordinateMapperConfig::tiles_per_row.
Referenced by CanvasToTile().
| bool yaze::gui::CoordinateMapper::IsInCanvasBounds | ( | float | screen_x, |
| float | screen_y ) const |
Check if screen coordinates are within canvas bounds.
Definition at line 134 of file coordinate_mapper.cc.
References yaze::gui::CanvasGeometry::canvas_p0, yaze::gui::CanvasGeometry::canvas_p1, and geometry_.
Referenced by ScreenToTile().
| bool yaze::gui::CoordinateMapper::IsValidTileCoord | ( | int | tile_x, |
| int | tile_y ) const |
Check if tile coordinates are valid.
Definition at line 141 of file coordinate_mapper.cc.
References config_, yaze::gui::CoordinateMapperConfig::tiles_per_col, and yaze::gui::CoordinateMapperConfig::tiles_per_row.
Referenced by CanvasToTile(), and GetTileId().
| uint32_t yaze::gui::CoordinateMapper::CalculateRomOffset | ( | int | tile_id, |
| uint32_t | base_offset = 0 ) const |
Calculate ROM offset for a given tile ID.
| tile_id | The tile ID |
| base_offset | Base ROM offset for tile data |
Note: This is a simplified calculation. Actual ROM offsets depend on the specific data type (overworld, dungeon, sprites, etc.) and may need to be overridden or configured per-editor.
Definition at line 147 of file coordinate_mapper.cc.
References config_, and yaze::gui::CoordinateMapperConfig::use_tile16.
Referenced by CanvasToTile().
|
inline |
Set a custom ROM offset calculator.
Definition at line 215 of file coordinate_mapper.h.
References rom_offset_calculator_.
| int yaze::gui::CoordinateMapper::CalculateLocalMapId | ( | float | content_x, |
| float | content_y ) const |
Calculate local map ID from content coordinates.
| content_x | X coordinate in content space |
| content_y | Y coordinate in content space |
Definition at line 163 of file coordinate_mapper.cc.
References config_, and yaze::gui::CoordinateMapperConfig::local_map_size.
Referenced by CanvasToTile().
| std::vector< ScreenToTileResult > yaze::gui::CoordinateMapper::ScreenToTileBatch | ( | const std::vector< std::pair< float, float > > & | positions | ) | const |
Convert multiple screen positions to tile info.
| positions | Vector of (x, y) screen positions |
Definition at line 177 of file coordinate_mapper.cc.
References ScreenToTile().

|
private |
Definition at line 189 of file coordinate_mapper.cc.
References geometry_, and yaze::gui::CanvasGeometry::scrolling.
Referenced by ScreenToTile().
|
private |
Definition at line 195 of file coordinate_mapper.cc.
References scale_.
Referenced by ScreenToTile().
|
private |
Definition at line 202 of file coordinate_mapper.cc.
References config_, and yaze::gui::CoordinateMapperConfig::tile_size.
Referenced by CanvasToTile().
|
private |
Definition at line 249 of file coordinate_mapper.h.
Referenced by CalculateLocalMapId(), CalculateRomOffset(), CanvasToTile(), GetConfig(), GetTile16Index(), GetTileId(), IsValidTileCoord(), SetConfig(), SnapToTileGrid(), and TileToCanvas().
|
private |
Definition at line 250 of file coordinate_mapper.h.
Referenced by ApplyScrollOffset(), GetGeometry(), IsInCanvasBounds(), ScreenToTile(), SetGeometry(), TileToCanvas(), and TileToScreen().
|
private |
Definition at line 251 of file coordinate_mapper.h.
Referenced by ApplyInverseScale(), GetScale(), SetScale(), and TileToCanvas().
|
private |
Definition at line 252 of file coordinate_mapper.h.
Referenced by GetCanvasId(), ScreenToTile(), and SetCanvasId().
|
private |
Definition at line 253 of file coordinate_mapper.h.
Referenced by CanvasToTile(), and SetRomOffsetCalculator().