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
4#include <algorithm>
5
7
8namespace yaze {
9namespace editor {
10
11inline bool ComputeTile8UsageHighlight(bool source_hovered,
12 bool right_mouse_down) {
13 return source_hovered && right_mouse_down;
14}
15
16inline int ComputeTile8IndexFromCanvasMouse(float mouse_x, float mouse_y,
17 int source_bitmap_width_px,
18 int max_tile_count,
19 float display_scale) {
20 if (source_bitmap_width_px <= 0 || max_tile_count <= 0 ||
21 display_scale <= 0) {
22 return -1;
23 }
24 if (mouse_x < 0.0f || mouse_y < 0.0f) {
25 return -1;
26 }
27
28 const int tile_x = static_cast<int>(mouse_x / (8.0f * display_scale));
29 const int tile_y = static_cast<int>(mouse_y / (8.0f * display_scale));
30 if (tile_x < 0 || tile_y < 0) {
31 return -1;
32 }
33
34 const int tiles_per_row = source_bitmap_width_px / 8;
35 if (tiles_per_row <= 0) {
36 return -1;
37 }
38
39 const int tile8_id = tile_x + (tile_y * tiles_per_row);
40 if (tile8_id < 0 || tile8_id >= max_tile_count) {
41 return -1;
42 }
43 return tile8_id;
44}
45
46inline float ComputeTile8SourceDisplayScale(float available_width_px,
47 int source_bitmap_width_px,
48 float min_scale = 1.0f,
49 float max_scale = 4.0f) {
50 if (source_bitmap_width_px <= 0 || available_width_px <= 0.0f ||
51 min_scale <= 0.0f || max_scale < min_scale) {
52 return min_scale;
53 }
54
55 constexpr float kAbsoluteMinimumReadableScale = 0.35f;
57 available_width_px, source_bitmap_width_px, 1,
59 std::min(min_scale, kAbsoluteMinimumReadableScale), max_scale)
61}
62
63inline float ComputeTile8SourcePanelHeight(float available_height_px,
64 int source_bitmap_height_px,
65 float display_scale,
66 float preferred_height_px = 0.0f,
67 float min_height_px = 220.0f,
68 float max_height_px = 520.0f) {
69 if (min_height_px <= 0.0f) {
70 min_height_px = 1.0f;
71 }
72 max_height_px = std::max(min_height_px, max_height_px);
73
74 constexpr float kVerticalChromeAllowance = 18.0f;
75 const float sheet_height =
76 source_bitmap_height_px > 0 && display_scale > 0.0f
77 ? (static_cast<float>(source_bitmap_height_px) * display_scale) +
78 kVerticalChromeAllowance
79 : max_height_px;
80
81 float target_height =
82 preferred_height_px > 0.0f ? preferred_height_px : sheet_height;
83 target_height = std::clamp(target_height, min_height_px, max_height_px);
84
85 if (available_height_px <= 0.0f) {
86 return target_height;
87 }
88
89 const float clamped_max_height =
90 std::min(max_height_px, std::max(1.0f, available_height_px));
91 const float clamped_min_height = std::min(min_height_px, clamped_max_height);
92 return std::clamp(target_height, clamped_min_height, clamped_max_height);
93}
94
95} // namespace editor
96} // namespace yaze
97
98#endif // YAZE_APP_EDITOR_OVERWORLD_TILE8_SOURCE_INTERACTION_H
float ComputeTile8SourcePanelHeight(float available_height_px, int source_bitmap_height_px, float display_scale, float preferred_height_px=0.0f, float min_height_px=220.0f, float max_height_px=520.0f)
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)
float ComputeTile8SourceDisplayScale(float available_width_px, int source_bitmap_width_px, float min_scale=1.0f, float max_scale=4.0f)
AdaptiveSheetLayout ResolveAdaptiveSheetLayout(float available_width, int source_width, int source_height, AdaptiveSheetScaleMode mode=AdaptiveSheetScaleMode::kFit, float min_scale=0.35f, float max_scale=4.0f, float horizontal_chrome=24.0f)