yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
canvas_types.h
Go to the documentation of this file.
1#ifndef YAZE_APP_GUI_CANVAS_CANVAS_TYPES_H
2#define YAZE_APP_GUI_CANVAS_CANVAS_TYPES_H
3
4// POD and option structs for the canvas subsystem.
5
6#include <cstdint>
7#include <optional>
8
9#include "imgui/imgui.h"
10
11namespace yaze {
12namespace gui {
13
14enum class CanvasType { kTile, kBlock, kMap };
15enum class CanvasMode { kPaint, kSelect };
17
18// Describes the role this canvas plays: what it's for, distinct from
19// CanvasMode which describes the input behavior the user is currently
20// performing. A canvas can have CanvasMode::kSelect while being either a
21// kSelectionSource (picker) or a kEditableScratchpad (rect-select-then-edit).
22//
23// Editors set this once at Init/Begin time. Canvas reads it for cursor and
24// hover-hint defaults; it does not gate operations.
25enum class CanvasRole : uint8_t {
26 kPreviewOnly, // Read-only display (gfx-group sheet thumbnail).
27 kSelectionSource, // Read-only tile/region picker source.
28 kEditableScratchpad, // User-editable target (default).
29 kCompositeOutput, // Post-render composite output.
30};
31
32// True when the canvas's underlying bitmap is owned by the editor and may be
33// mutated through it. False for kPreviewOnly/kSelectionSource canvases whose
34// bitmap is a shared view (gfx-group sheets, sprite atlas thumbnails) where
35// destructive operations like Reformat/SetPalette would corrupt every other
36// view of the same data. The context menu uses this to suppress
37// "Pixel Format" and "Edit Palette" entries on read-only canvases.
39 return role == CanvasRole::kEditableScratchpad ||
41}
42
44 ImDrawList* draw_list = nullptr;
45 ImVec2 canvas_p0 = ImVec2(0, 0);
46 ImVec2 canvas_sz = ImVec2(0, 0);
47 ImVec2 scrolling = ImVec2(0, 0);
48 ImVec2 mouse_pos_local = ImVec2(0, 0);
49 bool hovered = false;
50 float grid_step = 16.0f;
51 float scale = 1.0f;
52 ImVec2 content_size = ImVec2(0, 0);
53};
54
56 ImVec2 canvas_size = ImVec2(0, 0);
57 // Optional fixed viewport in screen pixels. The content still uses
58 // canvas_size/global_scale, but zooming cannot enlarge the host item.
59 std::optional<ImVec2> viewport_size;
60 bool draw_context_menu = true;
61 bool draw_grid = true;
62 std::optional<float> grid_step;
63 bool draw_overlay = true;
64 bool render_popups = true;
65 bool use_child_window = false;
66 bool show_scrollbar = false;
67};
68
70 ImVec2 canvas_size = ImVec2(0, 0);
71 ImVec2 dest_pos = ImVec2(0, 0);
72 ImVec2 dest_size = ImVec2(0, 0);
73 ImVec2 src_pos = ImVec2(0, 0);
74 ImVec2 src_size = ImVec2(0, 0);
75 float scale = 1.0f;
76 int alpha = 255;
77 bool draw_context_menu = false;
78 bool draw_grid = true;
79 std::optional<float> grid_step;
80 bool draw_overlay = true;
81 bool render_popups = true;
82 bool ensure_texture = false;
85};
86
87struct TileHit {
88 int tile_index = -1;
89 ImVec2 tile_origin = ImVec2(0, 0);
90 ImVec2 tile_size = ImVec2(0, 0);
91};
92
94 ImVec2 dest_pos = ImVec2(0, 0);
95 ImVec2 dest_size = ImVec2(0, 0);
96 ImVec2 src_pos = ImVec2(0, 0);
97 ImVec2 src_size = ImVec2(0, 0);
98 float scale = 1.0f;
99 int alpha = 255;
100 bool ensure_texture = true;
101};
102
104 ImVec2 canvas_size = ImVec2(0, 0);
105 float grid_step = 16.0f;
106 bool show_grid = true;
107 bool show_overlay = true;
108 bool render_popups = true;
109 bool ensure_texture = true;
112};
113
115 ImVec2 canvas_size = ImVec2(0, 0);
116 ImVec2 dest_pos = ImVec2(0, 0);
117 ImVec2 dest_size = ImVec2(0, 0);
118 float grid_step = 0.0f;
119 bool render_popups = false;
120 bool ensure_texture = true;
121};
122
124 float scale = 1.0f;
125 ImVec2 scroll = ImVec2(0, 0);
126};
127
128} // namespace gui
129} // namespace yaze
130
131#endif // YAZE_APP_GUI_CANVAS_CANVAS_TYPES_H
constexpr bool RoleAllowsBitmapMutation(CanvasRole role)
std::optional< float > grid_step
std::optional< ImVec2 > viewport_size
std::optional< float > grid_step