yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
canvas_utils.h
Go to the documentation of this file.
1#ifndef YAZE_APP_GUI_CANVAS_UTILS_H
2#define YAZE_APP_GUI_CANVAS_UTILS_H
3
4#include <string>
5#include <vector>
7#include "app/rom.h"
8#include "imgui/imgui.h"
9
10namespace yaze {
11namespace gui {
12
17 bool enable_grid = true;
18 bool enable_hex_labels = false;
21 bool is_draggable = false;
22 bool auto_resize = false;
23 bool clamp_rect_to_local_maps = true; // NEW: Prevent rectangle wrap across 512x512 boundaries
24 float grid_step = 32.0f;
25 float global_scale = 1.0f;
26 ImVec2 canvas_size = ImVec2(0, 0);
27 ImVec2 content_size = ImVec2(0, 0); // Size of actual content (bitmap, etc.)
28 bool custom_canvas_size = false;
29};
30
35 std::vector<ImVec2> selected_tiles;
36 std::vector<ImVec2> selected_points;
37 ImVec2 selected_tile_pos = ImVec2(-1, -1);
38 bool select_rect_active = false;
39
40 void Clear() {
41 selected_tiles.clear();
42 selected_points.clear();
43 selected_tile_pos = ImVec2(-1, -1);
44 select_rect_active = false;
45 }
46};
47
52 std::vector<gfx::SnesPalette> rom_palette_groups;
53 std::vector<std::string> palette_group_names;
55 bool palettes_loaded = false;
58
59 void Clear() {
60 rom_palette_groups.clear();
61 palette_group_names.clear();
63 palettes_loaded = false;
66 }
67};
68
73 std::string label;
74 std::string shortcut;
75 std::function<void()> callback;
76 std::function<bool()> enabled_condition = []() { return true; };
77 std::vector<CanvasContextMenuItem> subitems;
78};
79
83namespace CanvasUtils {
84
85// Core utility functions
86ImVec2 AlignToGrid(ImVec2 pos, float grid_step);
87float CalculateEffectiveScale(ImVec2 canvas_size, ImVec2 content_size, float global_scale);
88int GetTileIdFromPosition(ImVec2 mouse_pos, float tile_size, float scale, int tiles_per_row);
89
90// Palette management utilities
91bool LoadROMPaletteGroups(Rom* rom, CanvasPaletteManager& palette_manager);
92bool ApplyPaletteGroup(gfx::IRenderer* renderer, gfx::Bitmap* bitmap, const CanvasPaletteManager& palette_manager,
93 int group_index, int palette_index);
94
95// Drawing utility functions (moved from Canvas class)
96void DrawCanvasRect(ImDrawList* draw_list, ImVec2 canvas_p0, ImVec2 scrolling,
97 int x, int y, int w, int h, ImVec4 color, float global_scale);
98void DrawCanvasText(ImDrawList* draw_list, ImVec2 canvas_p0, ImVec2 scrolling,
99 const std::string& text, int x, int y, float global_scale);
100void DrawCanvasOutline(ImDrawList* draw_list, ImVec2 canvas_p0, ImVec2 scrolling,
101 int x, int y, int w, int h, uint32_t color = IM_COL32(255, 255, 255, 200));
102void DrawCanvasOutlineWithColor(ImDrawList* draw_list, ImVec2 canvas_p0, ImVec2 scrolling,
103 int x, int y, int w, int h, ImVec4 color);
104
105// Grid utility functions
106void DrawCanvasGridLines(ImDrawList* draw_list, ImVec2 canvas_p0, ImVec2 canvas_p1,
107 ImVec2 scrolling, float grid_step, float global_scale);
108void DrawCustomHighlight(ImDrawList* draw_list, ImVec2 canvas_p0, ImVec2 scrolling,
109 int highlight_tile_id, float grid_step);
110void DrawHexTileLabels(ImDrawList* draw_list, ImVec2 canvas_p0, ImVec2 scrolling,
111 ImVec2 canvas_sz, float grid_step, float global_scale);
112
113// Layout and interaction utilities
114ImVec2 CalculateCanvasSize(ImVec2 content_region, ImVec2 custom_size, bool use_custom);
115ImVec2 CalculateScaledCanvasSize(ImVec2 canvas_size, float global_scale);
116bool IsPointInCanvas(ImVec2 point, ImVec2 canvas_p0, ImVec2 canvas_p1);
117
118// Size reporting for ImGui table integration
119ImVec2 CalculateMinimumCanvasSize(ImVec2 content_size, float global_scale, float padding = 4.0f);
120ImVec2 CalculatePreferredCanvasSize(ImVec2 content_size, float global_scale, float min_scale = 1.0f);
121void ReserveCanvasSpace(ImVec2 canvas_size, const std::string& label = "");
122void SetNextCanvasSize(ImVec2 size, bool auto_resize = false);
123
124// High-level canvas operations
135
136// Composite drawing operations
137void DrawCanvasGrid(const CanvasRenderContext& ctx, int highlight_tile_id = -1);
138void DrawCanvasOverlay(const CanvasRenderContext& ctx, const ImVector<ImVec2>& points,
139 const ImVector<ImVec2>& selected_points);
140void DrawCanvasLabels(const CanvasRenderContext& ctx, const ImVector<ImVector<std::string>>& labels,
141 int current_labels, int tile_id_offset);
142
143} // namespace CanvasUtils
144
145} // namespace gui
146} // namespace yaze
147
148#endif // YAZE_APP_GUI_CANVAS_UTILS_H
The Rom class is used to load, save, and modify Rom data.
Definition rom.h:71
Represents a bitmap image optimized for SNES ROM hacking.
Definition bitmap.h:66
Defines an abstract interface for all rendering operations.
Definition irenderer.h:35
Represents a palette of colors for the Super Nintendo Entertainment System (SNES).
void ReserveCanvasSpace(ImVec2 canvas_size, const std::string &label)
void SetNextCanvasSize(ImVec2 size, bool auto_resize)
void DrawCanvasRect(ImDrawList *draw_list, ImVec2 canvas_p0, ImVec2 scrolling, int x, int y, int w, int h, ImVec4 color, float global_scale)
void DrawCanvasLabels(const CanvasRenderContext &ctx, const ImVector< ImVector< std::string > > &labels, int current_labels, int tile_id_offset)
bool IsPointInCanvas(ImVec2 point, ImVec2 canvas_p0, ImVec2 canvas_p1)
void DrawCanvasOverlay(const CanvasRenderContext &ctx, const ImVector< ImVec2 > &points, const ImVector< ImVec2 > &selected_points)
ImVec2 CalculateCanvasSize(ImVec2 content_region, ImVec2 custom_size, bool use_custom)
bool LoadROMPaletteGroups(Rom *rom, CanvasPaletteManager &palette_manager)
ImVec2 CalculateMinimumCanvasSize(ImVec2 content_size, float global_scale, float padding)
bool ApplyPaletteGroup(gfx::IRenderer *renderer, gfx::Bitmap *bitmap, const CanvasPaletteManager &palette_manager, int group_index, int palette_index)
float CalculateEffectiveScale(ImVec2 canvas_size, ImVec2 content_size, float global_scale)
void DrawCanvasOutline(ImDrawList *draw_list, ImVec2 canvas_p0, ImVec2 scrolling, int x, int y, int w, int h, uint32_t color)
int GetTileIdFromPosition(ImVec2 mouse_pos, float tile_size, float scale, int tiles_per_row)
void DrawCanvasOutlineWithColor(ImDrawList *draw_list, ImVec2 canvas_p0, ImVec2 scrolling, int x, int y, int w, int h, ImVec4 color)
void DrawCanvasGrid(const CanvasRenderContext &ctx, int highlight_tile_id)
ImVec2 CalculatePreferredCanvasSize(ImVec2 content_size, float global_scale, float min_scale)
void DrawCanvasText(ImDrawList *draw_list, ImVec2 canvas_p0, ImVec2 scrolling, const std::string &text, int x, int y, float global_scale)
ImVec2 CalculateScaledCanvasSize(ImVec2 canvas_size, float global_scale)
void DrawCustomHighlight(ImDrawList *draw_list, ImVec2 canvas_p0, ImVec2 scrolling, int highlight_tile_id, float grid_step)
void DrawCanvasGridLines(ImDrawList *draw_list, ImVec2 canvas_p0, ImVec2 canvas_p1, ImVec2 scrolling, float grid_step, float global_scale)
ImVec2 AlignToGrid(ImVec2 pos, float grid_step)
void DrawHexTileLabels(ImDrawList *draw_list, ImVec2 canvas_p0, ImVec2 scrolling, ImVec2 canvas_sz, float grid_step, float global_scale)
Main namespace for the application.
Configuration for canvas display and interaction.
Context menu item configuration.
std::function< void()> callback
std::function< bool()> enabled_condition
std::vector< CanvasContextMenuItem > subitems
Palette management state for canvas.
std::vector< gfx::SnesPalette > rom_palette_groups
gfx::SnesPalette original_palette
std::vector< std::string > palette_group_names
Selection state for canvas interactions.
std::vector< ImVec2 > selected_tiles
std::vector< ImVec2 > selected_points