yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
sheet_browser_panel.cc
Go to the documentation of this file.
2
3#include <cstdlib>
4#include <cstring>
5
6#include "absl/strings/str_format.h"
10#include "imgui/imgui.h"
11
12namespace yaze {
13namespace editor {
14
16 // Initialize with sensible defaults
17 thumbnail_scale_ = 2.0f;
18 columns_ = 2;
19}
20
21void SheetBrowserPanel::Draw(bool* p_open) {
22 // EditorPanel interface - delegate to existing Update() logic
24 ImGui::Separator();
26 ImGui::Separator();
28}
29
32 ImGui::Separator();
34 ImGui::Separator();
36 return absl::OkStatus();
37}
38
40 ImGui::Text("Search:");
41 ImGui::SameLine();
42 ImGui::SetNextItemWidth(80);
43 if (ImGui::InputText("##SheetSearch", search_buffer_, sizeof(search_buffer_),
44 ImGuiInputTextFlags_CharsHexadecimal)) {
45 // Parse hex input for sheet number
46 if (strlen(search_buffer_) > 0) {
47 int value = static_cast<int>(strtol(search_buffer_, nullptr, 16));
48 if (value >= 0 && value <= 222) {
49 state_->SelectSheet(static_cast<uint16_t>(value));
50 }
51 }
52 }
53 HOVER_HINT("Enter hex sheet number (00-DE)");
54
55 ImGui::SameLine();
56 ImGui::SetNextItemWidth(60);
57 ImGui::DragInt("##FilterMin", &filter_min_, 1.0f, 0, 222, "%02X");
58 ImGui::SameLine();
59 ImGui::Text("-");
60 ImGui::SameLine();
61 ImGui::SetNextItemWidth(60);
62 ImGui::DragInt("##FilterMax", &filter_max_, 1.0f, 0, 222, "%02X");
63
64 ImGui::SameLine();
65 ImGui::Checkbox("Modified", &show_only_modified_);
66 HOVER_HINT("Show only modified sheets");
67}
68
70 if (ImGui::Button(ICON_MD_SELECT_ALL " Select All")) {
71 for (int i = filter_min_; i <= filter_max_; i++) {
72 state_->selected_sheets.insert(static_cast<uint16_t>(i));
73 }
74 }
75 ImGui::SameLine();
76 if (ImGui::Button(ICON_MD_DESELECT " Clear")) {
77 state_->selected_sheets.clear();
78 }
79
80 if (!state_->selected_sheets.empty()) {
81 ImGui::SameLine();
82 ImGui::Text("(%zu selected)", state_->selected_sheets.size());
83 }
84
85 // Thumbnail size slider
86 ImGui::SameLine();
87 ImGui::SetNextItemWidth(100);
88 ImGui::SliderFloat("##Scale", &thumbnail_scale_, 1.0f, 4.0f, "%.1fx");
89}
90
92 ImGui::BeginChild("##SheetGridChild", ImVec2(0, 0), true,
93 ImGuiWindowFlags_AlwaysVerticalScrollbar);
94
95 auto& sheets = gfx::Arena::Get().gfx_sheets();
96
97 // Calculate thumbnail size
98 const float thumb_width = 128 * thumbnail_scale_;
99 const float thumb_height = 32 * thumbnail_scale_;
100 const float padding = 4.0f;
101
102 // Calculate columns based on available width
103 float available_width = ImGui::GetContentRegionAvail().x;
104 columns_ = std::max(1, static_cast<int>(available_width / (thumb_width + padding * 2)));
105
106 int col = 0;
107 for (int i = filter_min_; i <= filter_max_ && i < zelda3::kNumGfxSheets; i++) {
108 // Filter by modification state if enabled
110 state_->modified_sheets.find(static_cast<uint16_t>(i)) ==
111 state_->modified_sheets.end()) {
112 continue;
113 }
114
115 if (col > 0) {
116 ImGui::SameLine();
117 }
118
119 ImGui::PushID(i);
120 DrawSheetThumbnail(i, sheets[i]);
121 ImGui::PopID();
122
123 col++;
124 if (col >= columns_) {
125 col = 0;
126 }
127 }
128
129 ImGui::EndChild();
130}
131
133 const float thumb_width = 128 * thumbnail_scale_;
134 const float thumb_height = 32 * thumbnail_scale_;
135
136 bool is_selected = state_->current_sheet_id == static_cast<uint16_t>(sheet_id);
137 bool is_multi_selected =
138 state_->selected_sheets.count(static_cast<uint16_t>(sheet_id)) > 0;
139 bool is_modified =
140 state_->modified_sheets.count(static_cast<uint16_t>(sheet_id)) > 0;
141
142 // Selection highlight
143 if (is_selected) {
144 ImGui::PushStyleColor(ImGuiCol_ChildBg, ImVec4(0.3f, 0.5f, 0.8f, 0.3f));
145 } else if (is_multi_selected) {
146 ImGui::PushStyleColor(ImGuiCol_ChildBg, ImVec4(0.5f, 0.5f, 0.2f, 0.3f));
147 }
148
149 ImGui::BeginChild(absl::StrFormat("##Sheet%02X", sheet_id).c_str(),
150 ImVec2(thumb_width + 8, thumb_height + 24), true,
151 ImGuiWindowFlags_NoScrollbar);
152
153 gui::BitmapPreviewOptions preview_opts;
154 preview_opts.canvas_size = ImVec2(thumb_width + 1, thumb_height + 1);
155 preview_opts.dest_pos = ImVec2(2, 2);
156 preview_opts.dest_size = ImVec2(thumb_width - 2, thumb_height - 2);
157 preview_opts.grid_step = 8.0f * thumbnail_scale_;
158 preview_opts.draw_context_menu = false;
159 preview_opts.ensure_texture = true;
160
161 gui::CanvasFrameOptions frame_opts;
162 frame_opts.canvas_size = preview_opts.canvas_size;
163 frame_opts.draw_context_menu = preview_opts.draw_context_menu;
164 frame_opts.draw_grid = preview_opts.draw_grid;
165 frame_opts.grid_step = preview_opts.grid_step;
166 frame_opts.draw_overlay = preview_opts.draw_overlay;
167 frame_opts.render_popups = preview_opts.render_popups;
168
169 {
170 auto rt = gui::BeginCanvas(thumbnail_canvas_, frame_opts);
171 gui::DrawBitmapPreview(rt, bitmap, preview_opts);
172
173 // Sheet label with modification indicator
174 std::string label = absl::StrFormat("%02X", sheet_id);
175 if (is_modified) {
176 label += "*";
177 }
178
179 // Draw label with background
180 ImVec2 text_pos = ImGui::GetCursorScreenPos();
181 ImVec2 text_size = ImGui::CalcTextSize(label.c_str());
183 ImVec2(2, 2), ImVec2(text_size.x + 4, text_size.y + 2),
184 is_modified ? IM_COL32(180, 100, 0, 200) : IM_COL32(0, 100, 0, 180));
185
186 thumbnail_canvas_.AddTextAt(ImVec2(4, 2), label,
187 is_modified ? IM_COL32(255, 200, 100, 255)
188 : IM_COL32(150, 255, 150, 255));
189 gui::EndCanvas(thumbnail_canvas_, rt, frame_opts);
190 }
191
192 // Click handling
193 if (ImGui::IsItemClicked(ImGuiMouseButton_Left)) {
194 if (ImGui::GetIO().KeyCtrl) {
195 // Ctrl+click for multi-select
196 if (is_multi_selected) {
197 state_->selected_sheets.erase(static_cast<uint16_t>(sheet_id));
198 } else {
199 state_->selected_sheets.insert(static_cast<uint16_t>(sheet_id));
200 }
201 } else {
202 // Normal click to select
203 state_->SelectSheet(static_cast<uint16_t>(sheet_id));
204 }
205 }
206
207 // Double-click to open in new tab
208 if (ImGui::IsItemHovered() && ImGui::IsMouseDoubleClicked(ImGuiMouseButton_Left)) {
209 state_->open_sheets.insert(static_cast<uint16_t>(sheet_id));
210 }
211
212 ImGui::EndChild();
213
214 if (is_selected || is_multi_selected) {
215 ImGui::PopStyleColor();
216 }
217
218 // Tooltip with sheet info
219 if (ImGui::IsItemHovered()) {
220 ImGui::BeginTooltip();
221 ImGui::Text("Sheet: 0x%02X (%d)", sheet_id, sheet_id);
222 if (bitmap.is_active()) {
223 ImGui::Text("Size: %dx%d", bitmap.width(), bitmap.height());
224 ImGui::Text("Depth: %d bpp", bitmap.depth());
225 } else {
226 ImGui::Text("(Inactive)");
227 }
228 if (is_modified) {
229 ImGui::TextColored(ImVec4(1.0f, 0.6f, 0.2f, 1.0f), "Modified");
230 }
231 ImGui::EndTooltip();
232 }
233}
234
235} // namespace editor
236} // namespace yaze
void SelectSheet(uint16_t sheet_id)
Select a sheet for editing.
void DrawBatchOperations()
Draw batch operation buttons.
void Draw(bool *p_open) override
Draw the sheet browser UI.
void DrawSearchBar()
Draw the search/filter bar.
void Initialize()
Initialize the panel.
void DrawSheetThumbnail(int sheet_id, gfx::Bitmap &bitmap)
Draw a single sheet thumbnail.
void DrawSheetGrid()
Draw the sheet grid view.
absl::Status Update()
Legacy Update method for backward compatibility.
std::array< gfx::Bitmap, 223 > & gfx_sheets()
Get reference to all graphics sheets.
Definition arena.h:101
static Arena & Get()
Definition arena.cc:19
Represents a bitmap image optimized for SNES ROM hacking.
Definition bitmap.h:67
bool is_active() const
Definition bitmap.h:384
int height() const
Definition bitmap.h:374
int width() const
Definition bitmap.h:373
int depth() const
Definition bitmap.h:375
void AddTextAt(ImVec2 local_pos, const std::string &text, uint32_t color)
Definition canvas.cc:2425
void AddRectFilledAt(ImVec2 local_top_left, ImVec2 size, uint32_t color)
Definition canvas.cc:2416
#define ICON_MD_SELECT_ALL
Definition icons.h:1680
#define ICON_MD_DESELECT
Definition icons.h:540
#define HOVER_HINT(string)
Definition macro.h:24
void EndCanvas(Canvas &canvas)
Definition canvas.cc:1509
void DrawBitmapPreview(const CanvasRuntime &rt, gfx::Bitmap &bitmap, const BitmapPreviewOptions &options)
Definition canvas.cc:2135
void BeginCanvas(Canvas &canvas, ImVec2 child_size)
Definition canvas.cc:1486
constexpr uint32_t kNumGfxSheets
Definition game_data.h:25
std::optional< float > grid_step
Definition canvas.h:90
std::optional< float > grid_step
Definition canvas.h:70