yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
tile8_source_interaction.h
Go to the documentation of this file.
1#ifndef YAZE_APP_EDITOR_OVERWORLD_TILE8_SOURCE_INTERACTION_H
2#define YAZE_APP_EDITOR_OVERWORLD_TILE8_SOURCE_INTERACTION_H
3
4namespace yaze {
5namespace editor {
6
7inline bool ComputeTile8UsageHighlight(bool source_hovered,
8 bool right_mouse_down) {
9 return source_hovered && right_mouse_down;
10}
11
12inline int ComputeTile8IndexFromCanvasMouse(float mouse_x, float mouse_y,
13 int source_bitmap_width_px,
14 int max_tile_count,
15 float display_scale) {
16 if (source_bitmap_width_px <= 0 || max_tile_count <= 0 ||
17 display_scale <= 0) {
18 return -1;
19 }
20 if (mouse_x < 0.0f || mouse_y < 0.0f) {
21 return -1;
22 }
23
24 const int tile_x = static_cast<int>(mouse_x / (8.0f * display_scale));
25 const int tile_y = static_cast<int>(mouse_y / (8.0f * display_scale));
26 if (tile_x < 0 || tile_y < 0) {
27 return -1;
28 }
29
30 const int tiles_per_row = source_bitmap_width_px / 8;
31 if (tiles_per_row <= 0) {
32 return -1;
33 }
34
35 const int tile8_id = tile_x + (tile_y * tiles_per_row);
36 if (tile8_id < 0 || tile8_id >= max_tile_count) {
37 return -1;
38 }
39 return tile8_id;
40}
41
42} // namespace editor
43} // namespace yaze
44
45#endif // YAZE_APP_EDITOR_OVERWORLD_TILE8_SOURCE_INTERACTION_H
bool ComputeTile8UsageHighlight(bool source_hovered, bool right_mouse_down)
int ComputeTile8IndexFromCanvasMouse(float mouse_x, float mouse_y, int source_bitmap_width_px, int max_tile_count, float display_scale)