yaze 0.2.0
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
style.cc
Go to the documentation of this file.
1#include "style.h"
2
3#include "imgui/imgui.h"
4#include "imgui/imgui_internal.h"
5
6namespace yaze {
7namespace app {
8namespace gui {
9
10// TODO: Add more display settings to popup windows.
11void BeginWindowWithDisplaySettings(const char *id, bool *active,
12 const ImVec2 &size,
13 ImGuiWindowFlags flags) {
14 ImGuiStyle *ref = &ImGui::GetStyle();
15 static float childBgOpacity = 0.75f;
16 auto color = ref->Colors[ImGuiCol_WindowBg];
17
18 ImGui::PushStyleColor(ImGuiCol_WindowBg, color);
19 ImGui::PushStyleColor(ImGuiCol_ChildBg, color);
20 ImGui::PushStyleColor(ImGuiCol_Border, color);
21
22 ImGui::Begin(id, active, flags | ImGuiWindowFlags_MenuBar);
23 ImGui::BeginMenuBar();
24 if (ImGui::BeginMenu("Display Settings")) {
25 ImGui::SliderFloat("Child Background Opacity", &childBgOpacity, 0.0f, 1.0f);
26 ImGui::EndMenu();
27 }
28 ImGui::EndMenuBar();
29}
30
32 ImGui::End();
33 ImGui::PopStyleColor(3);
34}
35
36void BeginPadding(int i) {
37 ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(i, i));
38 ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(i, i));
39}
41
43 ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(0, 0));
44 ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0, 0));
45}
46void EndNoPadding() { ImGui::PopStyleVar(2); }
47
48void BeginChildWithScrollbar(const char *str_id) {
49 ImGui::BeginChild(str_id, ImGui::GetContentRegionAvail(), true,
50 ImGuiWindowFlags_AlwaysVerticalScrollbar);
51}
52
54 ImGuiID child_id = ImGui::GetID((void *)(intptr_t)id);
55 ImGui::BeginChild(child_id, ImGui::GetContentRegionAvail(), true,
56 ImGuiWindowFlags_AlwaysVerticalScrollbar |
57 ImGuiWindowFlags_AlwaysHorizontalScrollbar);
58}
59
60void DrawDisplaySettings(ImGuiStyle *ref) {
61 // You can pass in a reference ImGuiStyle structure to compare to, revert to
62 // and save to (without a reference style pointer, we will use one compared
63 // locally as a reference)
64 ImGuiStyle &style = ImGui::GetStyle();
65 static ImGuiStyle ref_saved_style;
66
67 // Default to using internal storage as reference
68 static bool init = true;
69 if (init && ref == NULL)
70 ref_saved_style = style;
71 init = false;
72 if (ref == NULL)
73 ref = &ref_saved_style;
74
75 ImGui::PushItemWidth(ImGui::GetWindowWidth() * 0.50f);
76
77 if (ImGui::ShowStyleSelector("Colors##Selector"))
78 ref_saved_style = style;
79 ImGui::ShowFontSelector("Fonts##Selector");
80
81 // Simplified Settings (expose floating-pointer border sizes as boolean
82 // representing 0.0f or 1.0f)
83 if (ImGui::SliderFloat("FrameRounding", &style.FrameRounding, 0.0f, 12.0f,
84 "%.0f"))
85 style.GrabRounding = style.FrameRounding; // Make GrabRounding always the
86 // same value as FrameRounding
87 {
88 bool border = (style.WindowBorderSize > 0.0f);
89 if (ImGui::Checkbox("WindowBorder", &border)) {
90 style.WindowBorderSize = border ? 1.0f : 0.0f;
91 }
92 }
93 ImGui::SameLine();
94 {
95 bool border = (style.FrameBorderSize > 0.0f);
96 if (ImGui::Checkbox("FrameBorder", &border)) {
97 style.FrameBorderSize = border ? 1.0f : 0.0f;
98 }
99 }
100 ImGui::SameLine();
101 {
102 bool border = (style.PopupBorderSize > 0.0f);
103 if (ImGui::Checkbox("PopupBorder", &border)) {
104 style.PopupBorderSize = border ? 1.0f : 0.0f;
105 }
106 }
107
108 // Save/Revert button
109 if (ImGui::Button("Save Ref"))
110 *ref = ref_saved_style = style;
111 ImGui::SameLine();
112 if (ImGui::Button("Revert Ref"))
113 style = *ref;
114 ImGui::SameLine();
115
116 ImGui::Separator();
117
118 if (ImGui::BeginTabBar("##tabs", ImGuiTabBarFlags_None)) {
119 if (ImGui::BeginTabItem("Sizes")) {
120 ImGui::SeparatorText("Main");
121 ImGui::SliderFloat2("WindowPadding", (float *)&style.WindowPadding, 0.0f,
122 20.0f, "%.0f");
123 ImGui::SliderFloat2("FramePadding", (float *)&style.FramePadding, 0.0f,
124 20.0f, "%.0f");
125 ImGui::SliderFloat2("ItemSpacing", (float *)&style.ItemSpacing, 0.0f,
126 20.0f, "%.0f");
127 ImGui::SliderFloat2("ItemInnerSpacing", (float *)&style.ItemInnerSpacing,
128 0.0f, 20.0f, "%.0f");
129 ImGui::SliderFloat2("TouchExtraPadding",
130 (float *)&style.TouchExtraPadding, 0.0f, 10.0f,
131 "%.0f");
132 ImGui::SliderFloat("IndentSpacing", &style.IndentSpacing, 0.0f, 30.0f,
133 "%.0f");
134 ImGui::SliderFloat("ScrollbarSize", &style.ScrollbarSize, 1.0f, 20.0f,
135 "%.0f");
136 ImGui::SliderFloat("GrabMinSize", &style.GrabMinSize, 1.0f, 20.0f,
137 "%.0f");
138
139 ImGui::SeparatorText("Borders");
140 ImGui::SliderFloat("WindowBorderSize", &style.WindowBorderSize, 0.0f,
141 1.0f, "%.0f");
142 ImGui::SliderFloat("ChildBorderSize", &style.ChildBorderSize, 0.0f, 1.0f,
143 "%.0f");
144 ImGui::SliderFloat("PopupBorderSize", &style.PopupBorderSize, 0.0f, 1.0f,
145 "%.0f");
146 ImGui::SliderFloat("FrameBorderSize", &style.FrameBorderSize, 0.0f, 1.0f,
147 "%.0f");
148 ImGui::SliderFloat("TabBorderSize", &style.TabBorderSize, 0.0f, 1.0f,
149 "%.0f");
150 ImGui::SliderFloat("TabBarBorderSize", &style.TabBarBorderSize, 0.0f,
151 2.0f, "%.0f");
152
153 ImGui::SeparatorText("Rounding");
154 ImGui::SliderFloat("WindowRounding", &style.WindowRounding, 0.0f, 12.0f,
155 "%.0f");
156 ImGui::SliderFloat("ChildRounding", &style.ChildRounding, 0.0f, 12.0f,
157 "%.0f");
158 ImGui::SliderFloat("FrameRounding", &style.FrameRounding, 0.0f, 12.0f,
159 "%.0f");
160 ImGui::SliderFloat("PopupRounding", &style.PopupRounding, 0.0f, 12.0f,
161 "%.0f");
162 ImGui::SliderFloat("ScrollbarRounding", &style.ScrollbarRounding, 0.0f,
163 12.0f, "%.0f");
164 ImGui::SliderFloat("GrabRounding", &style.GrabRounding, 0.0f, 12.0f,
165 "%.0f");
166 ImGui::SliderFloat("TabRounding", &style.TabRounding, 0.0f, 12.0f,
167 "%.0f");
168
169 ImGui::SeparatorText("Tables");
170 ImGui::SliderFloat2("CellPadding", (float *)&style.CellPadding, 0.0f,
171 20.0f, "%.0f");
172 ImGui::SliderAngle("TableAngledHeadersAngle",
173 &style.TableAngledHeadersAngle, -50.0f, +50.0f);
174
175 ImGui::SeparatorText("Widgets");
176 ImGui::SliderFloat2("WindowTitleAlign", (float *)&style.WindowTitleAlign,
177 0.0f, 1.0f, "%.2f");
178 ImGui::Combo("ColorButtonPosition", (int *)&style.ColorButtonPosition,
179 "Left\0Right\0");
180 ImGui::SliderFloat2("ButtonTextAlign", (float *)&style.ButtonTextAlign,
181 0.0f, 1.0f, "%.2f");
182 ImGui::SameLine();
183
184 ImGui::SliderFloat2("SelectableTextAlign",
185 (float *)&style.SelectableTextAlign, 0.0f, 1.0f,
186 "%.2f");
187 ImGui::SameLine();
188
189 ImGui::SliderFloat("SeparatorTextBorderSize",
190 &style.SeparatorTextBorderSize, 0.0f, 10.0f, "%.0f");
191 ImGui::SliderFloat2("SeparatorTextAlign",
192 (float *)&style.SeparatorTextAlign, 0.0f, 1.0f,
193 "%.2f");
194 ImGui::SliderFloat2("SeparatorTextPadding",
195 (float *)&style.SeparatorTextPadding, 0.0f, 40.0f,
196 "%.0f");
197 ImGui::SliderFloat("LogSliderDeadzone", &style.LogSliderDeadzone, 0.0f,
198 12.0f, "%.0f");
199
200 ImGui::SeparatorText("Tooltips");
201 for (int n = 0; n < 2; n++)
202 if (ImGui::TreeNodeEx(n == 0 ? "HoverFlagsForTooltipMouse"
203 : "HoverFlagsForTooltipNav")) {
204 ImGuiHoveredFlags *p = (n == 0) ? &style.HoverFlagsForTooltipMouse
205 : &style.HoverFlagsForTooltipNav;
206 ImGui::CheckboxFlags("ImGuiHoveredFlags_DelayNone", p,
207 ImGuiHoveredFlags_DelayNone);
208 ImGui::CheckboxFlags("ImGuiHoveredFlags_DelayShort", p,
209 ImGuiHoveredFlags_DelayShort);
210 ImGui::CheckboxFlags("ImGuiHoveredFlags_DelayNormal", p,
211 ImGuiHoveredFlags_DelayNormal);
212 ImGui::CheckboxFlags("ImGuiHoveredFlags_Stationary", p,
213 ImGuiHoveredFlags_Stationary);
214 ImGui::CheckboxFlags("ImGuiHoveredFlags_NoSharedDelay", p,
215 ImGuiHoveredFlags_NoSharedDelay);
216 ImGui::TreePop();
217 }
218
219 ImGui::SeparatorText("Misc");
220 ImGui::SliderFloat2("DisplaySafeAreaPadding",
221 (float *)&style.DisplaySafeAreaPadding, 0.0f, 30.0f,
222 "%.0f");
223 ImGui::SameLine();
224
225 ImGui::EndTabItem();
226 }
227
228 if (ImGui::BeginTabItem("Colors")) {
229 static int output_dest = 0;
230 static bool output_only_modified = true;
231 if (ImGui::Button("Export")) {
232 if (output_dest == 0)
233 ImGui::LogToClipboard();
234 else
235 ImGui::LogToTTY();
236 ImGui::LogText("ImVec4* colors = ImGui::GetStyle().Colors;" IM_NEWLINE);
237 for (int i = 0; i < ImGuiCol_COUNT; i++) {
238 const ImVec4 &col = style.Colors[i];
239 const char *name = ImGui::GetStyleColorName(i);
240 if (!output_only_modified ||
241 memcmp(&col, &ref->Colors[i], sizeof(ImVec4)) != 0)
242 ImGui::LogText(
243 "colors[ImGuiCol_%s]%*s= ImVec4(%.2ff, %.2ff, %.2ff, "
244 "%.2ff);" IM_NEWLINE,
245 name, 23 - (int)strlen(name), "", col.x, col.y, col.z, col.w);
246 }
247 ImGui::LogFinish();
248 }
249 ImGui::SameLine();
250 ImGui::SetNextItemWidth(120);
251 ImGui::Combo("##output_type", &output_dest, "To Clipboard\0To TTY\0");
252 ImGui::SameLine();
253 ImGui::Checkbox("Only Modified Colors", &output_only_modified);
254
255 static ImGuiTextFilter filter;
256 filter.Draw("Filter colors", ImGui::GetFontSize() * 16);
257
258 static ImGuiColorEditFlags alpha_flags = 0;
259 if (ImGui::RadioButton("Opaque",
260 alpha_flags == ImGuiColorEditFlags_None)) {
261 alpha_flags = ImGuiColorEditFlags_None;
262 }
263 ImGui::SameLine();
264 if (ImGui::RadioButton("Alpha",
265 alpha_flags == ImGuiColorEditFlags_AlphaPreview)) {
266 alpha_flags = ImGuiColorEditFlags_AlphaPreview;
267 }
268 ImGui::SameLine();
269 if (ImGui::RadioButton(
270 "Both", alpha_flags == ImGuiColorEditFlags_AlphaPreviewHalf)) {
271 alpha_flags = ImGuiColorEditFlags_AlphaPreviewHalf;
272 }
273 ImGui::SameLine();
274
275 ImGui::SetNextWindowSizeConstraints(
276 ImVec2(0.0f, ImGui::GetTextLineHeightWithSpacing() * 10),
277 ImVec2(FLT_MAX, FLT_MAX));
278 ImGui::BeginChild("##colors", ImVec2(0, 0), ImGuiChildFlags_Border,
279 ImGuiWindowFlags_AlwaysVerticalScrollbar |
280 ImGuiWindowFlags_AlwaysHorizontalScrollbar |
281 ImGuiWindowFlags_NavFlattened);
282 ImGui::PushItemWidth(ImGui::GetFontSize() * -12);
283 for (int i = 0; i < ImGuiCol_COUNT; i++) {
284 const char *name = ImGui::GetStyleColorName(i);
285 if (!filter.PassFilter(name))
286 continue;
287 ImGui::PushID(i);
288 ImGui::ColorEdit4("##color", (float *)&style.Colors[i],
289 ImGuiColorEditFlags_AlphaBar | alpha_flags);
290 if (memcmp(&style.Colors[i], &ref->Colors[i], sizeof(ImVec4)) != 0) {
291 // Tips: in a real user application, you may want to merge and use
292 // an icon font into the main font, so instead of "Save"/"Revert"
293 // you'd use icons! Read the FAQ and docs/FONTS.md about using icon
294 // fonts. It's really easy and super convenient!
295 ImGui::SameLine(0.0f, style.ItemInnerSpacing.x);
296 if (ImGui::Button("Save")) {
297 ref->Colors[i] = style.Colors[i];
298 }
299 ImGui::SameLine(0.0f, style.ItemInnerSpacing.x);
300 if (ImGui::Button("Revert")) {
301 style.Colors[i] = ref->Colors[i];
302 }
303 }
304 ImGui::SameLine(0.0f, style.ItemInnerSpacing.x);
305 ImGui::TextUnformatted(name);
306 ImGui::PopID();
307 }
308 ImGui::PopItemWidth();
309 ImGui::EndChild();
310
311 ImGui::EndTabItem();
312 }
313
314 if (ImGui::BeginTabItem("Fonts")) {
315 ImGuiIO &io = ImGui::GetIO();
316 ImFontAtlas *atlas = io.Fonts;
317 ImGui::ShowFontAtlas(atlas);
318
319 // Post-baking font scaling. Note that this is NOT the nice way of
320 // scaling fonts, read below. (we enforce hard clamping manually as by
321 // default DragFloat/SliderFloat allows CTRL+Click text to get out of
322 // bounds).
323 const float MIN_SCALE = 0.3f;
324 const float MAX_SCALE = 2.0f;
325
326 static float window_scale = 1.0f;
327 ImGui::PushItemWidth(ImGui::GetFontSize() * 8);
328 if (ImGui::DragFloat(
329 "window scale", &window_scale, 0.005f, MIN_SCALE, MAX_SCALE,
330 "%.2f",
331 ImGuiSliderFlags_AlwaysClamp)) // Scale only this window
332 ImGui::SetWindowFontScale(window_scale);
333 ImGui::DragFloat("global scale", &io.FontGlobalScale, 0.005f, MIN_SCALE,
334 MAX_SCALE, "%.2f",
335 ImGuiSliderFlags_AlwaysClamp); // Scale everything
336 ImGui::PopItemWidth();
337
338 ImGui::EndTabItem();
339 }
340
341 if (ImGui::BeginTabItem("Rendering")) {
342 ImGui::Checkbox("Anti-aliased lines", &style.AntiAliasedLines);
343 ImGui::SameLine();
344
345 ImGui::Checkbox("Anti-aliased lines use texture",
346 &style.AntiAliasedLinesUseTex);
347 ImGui::SameLine();
348
349 ImGui::Checkbox("Anti-aliased fill", &style.AntiAliasedFill);
350 ImGui::PushItemWidth(ImGui::GetFontSize() * 8);
351 ImGui::DragFloat("Curve Tessellation Tolerance",
352 &style.CurveTessellationTol, 0.02f, 0.10f, 10.0f,
353 "%.2f");
354 if (style.CurveTessellationTol < 0.10f)
355 style.CurveTessellationTol = 0.10f;
356
357 // When editing the "Circle Segment Max Error" value, draw a preview of
358 // its effect on auto-tessellated circles.
359 ImGui::DragFloat("Circle Tessellation Max Error",
360 &style.CircleTessellationMaxError, 0.005f, 0.10f, 5.0f,
361 "%.2f", ImGuiSliderFlags_AlwaysClamp);
362 const bool show_samples = ImGui::IsItemActive();
363 if (show_samples)
364 ImGui::SetNextWindowPos(ImGui::GetCursorScreenPos());
365 if (show_samples && ImGui::BeginTooltip()) {
366 ImGui::TextUnformatted("(R = radius, N = number of segments)");
367 ImGui::Spacing();
368 ImDrawList *draw_list = ImGui::GetWindowDrawList();
369 const float min_widget_width = ImGui::CalcTextSize("N: MMM\nR: MMM").x;
370 for (int n = 0; n < 8; n++) {
371 const float RAD_MIN = 5.0f;
372 const float RAD_MAX = 70.0f;
373 const float rad =
374 RAD_MIN + (RAD_MAX - RAD_MIN) * (float)n / (8.0f - 1.0f);
375
376 ImGui::BeginGroup();
377
378 ImGui::Text("R: %.f\nN: %d", rad,
379 draw_list->_CalcCircleAutoSegmentCount(rad));
380
381 const float canvas_width = std::max(min_widget_width, rad * 2.0f);
382 const float offset_x = floorf(canvas_width * 0.5f);
383 const float offset_y = floorf(RAD_MAX);
384
385 const ImVec2 p1 = ImGui::GetCursorScreenPos();
386 draw_list->AddCircle(ImVec2(p1.x + offset_x, p1.y + offset_y), rad,
387 ImGui::GetColorU32(ImGuiCol_Text));
388 ImGui::Dummy(ImVec2(canvas_width, RAD_MAX * 2));
389
390 /*
391 const ImVec2 p2 = ImGui::GetCursorScreenPos();
392 draw_list->AddCircleFilled(ImVec2(p2.x + offset_x, p2.y + offset_y),
393 rad, ImGui::GetColorU32(ImGuiCol_Text));
394 ImGui::Dummy(ImVec2(canvas_width, RAD_MAX * 2));
395 */
396
397 ImGui::EndGroup();
398 ImGui::SameLine();
399 }
400 ImGui::EndTooltip();
401 }
402 ImGui::SameLine();
403
404 ImGui::DragFloat("Global Alpha", &style.Alpha, 0.005f, 0.20f, 1.0f,
405 "%.2f"); // Not exposing zero here so user doesn't
406 // "lose" the UI (zero alpha clips all
407 // widgets). But application code could have a
408 // toggle to switch between zero and non-zero.
409 ImGui::DragFloat("Disabled Alpha", &style.DisabledAlpha, 0.005f, 0.0f,
410 1.0f, "%.2f");
411 ImGui::SameLine();
412
413 ImGui::PopItemWidth();
414
415 ImGui::EndTabItem();
416 }
417
418 ImGui::EndTabBar();
419 }
420
421 ImGui::PopItemWidth();
422}
423
424void TextWithSeparators(const absl::string_view &text) {
425 ImGui::Separator();
426 ImGui::Text("%s", text.data());
427 ImGui::Separator();
428}
429
430// TODO: Make the ColorsYaze style into a configuration file.
432 ImGuiStyle *style = &ImGui::GetStyle();
433 ImVec4 *colors = style->Colors;
434
435 style->WindowPadding = ImVec2(10.f, 10.f);
436 style->FramePadding = ImVec2(10.f, 2.f);
437 style->CellPadding = ImVec2(4.f, 5.f);
438 style->ItemSpacing = ImVec2(10.f, 5.f);
439 style->ItemInnerSpacing = ImVec2(5.f, 5.f);
440 style->TouchExtraPadding = ImVec2(0.f, 0.f);
441 style->IndentSpacing = 20.f;
442 style->ScrollbarSize = 14.f;
443 style->GrabMinSize = 15.f;
444
445 style->WindowBorderSize = 0.f;
446 style->ChildBorderSize = 1.f;
447 style->PopupBorderSize = 1.f;
448 style->FrameBorderSize = 0.f;
449 style->TabBorderSize = 0.f;
450
451 style->WindowRounding = 0.f;
452 style->ChildRounding = 0.f;
453 style->FrameRounding = 5.f;
454 style->PopupRounding = 0.f;
455 style->ScrollbarRounding = 5.f;
456
457 auto alttpDarkGreen = ImVec4(0.18f, 0.26f, 0.18f, 1.0f);
458 auto alttpMidGreen = ImVec4(0.28f, 0.36f, 0.28f, 1.0f);
459 auto allttpLightGreen = ImVec4(0.36f, 0.45f, 0.36f, 1.0f);
460 auto allttpLightestGreen = ImVec4(0.49f, 0.57f, 0.49f, 1.0f);
461
462 colors[ImGuiCol_MenuBarBg] = alttpDarkGreen;
463 colors[ImGuiCol_TitleBg] = alttpMidGreen;
464
465 colors[ImGuiCol_Header] = alttpDarkGreen;
466 colors[ImGuiCol_HeaderHovered] = allttpLightGreen;
467 colors[ImGuiCol_HeaderActive] = alttpMidGreen;
468
469 colors[ImGuiCol_TitleBgActive] = alttpDarkGreen;
470 colors[ImGuiCol_TitleBgCollapsed] = alttpMidGreen;
471
472 colors[ImGuiCol_Tab] = alttpDarkGreen;
473 colors[ImGuiCol_TabHovered] = alttpMidGreen;
474 colors[ImGuiCol_TabActive] = ImVec4(0.347f, 0.466f, 0.347f, 1.000f);
475
476 colors[ImGuiCol_Button] = alttpMidGreen;
477 colors[ImGuiCol_ButtonHovered] = allttpLightestGreen;
478 colors[ImGuiCol_ButtonActive] = allttpLightGreen;
479
480 colors[ImGuiCol_ScrollbarBg] = ImVec4(0.36f, 0.45f, 0.36f, 0.60f);
481 colors[ImGuiCol_ScrollbarGrab] = ImVec4(0.36f, 0.45f, 0.36f, 0.30f);
482 colors[ImGuiCol_ScrollbarGrabHovered] = ImVec4(0.36f, 0.45f, 0.36f, 0.40f);
483 colors[ImGuiCol_ScrollbarGrabActive] = ImVec4(0.36f, 0.45f, 0.36f, 0.60f);
484
485 colors[ImGuiCol_Text] = ImVec4(0.90f, 0.90f, 0.90f, 1.00f);
486 colors[ImGuiCol_TextDisabled] = ImVec4(0.60f, 0.60f, 0.60f, 1.00f);
487 colors[ImGuiCol_WindowBg] = ImVec4(0.00f, 0.00f, 0.00f, 0.85f);
488 colors[ImGuiCol_ChildBg] = ImVec4(0.00f, 0.00f, 0.00f, 0.00f);
489 colors[ImGuiCol_PopupBg] = ImVec4(0.11f, 0.11f, 0.14f, 0.92f);
490 colors[ImGuiCol_Border] = allttpLightGreen;
491 colors[ImGuiCol_BorderShadow] = ImVec4(0.00f, 0.00f, 0.00f, 0.00f);
492
493 colors[ImGuiCol_FrameBg] = ImVec4(0.43f, 0.43f, 0.43f, 0.39f);
494 colors[ImGuiCol_FrameBgHovered] = ImVec4(0.28f, 0.36f, 0.28f, 0.40f);
495 colors[ImGuiCol_FrameBgActive] = ImVec4(0.28f, 0.36f, 0.28f, 0.69f);
496
497 colors[ImGuiCol_CheckMark] = ImVec4(0.90f, 0.90f, 0.90f, 0.50f);
498 colors[ImGuiCol_SliderGrab] = ImVec4(1.00f, 1.00f, 1.00f, 0.30f);
499 colors[ImGuiCol_SliderGrabActive] = ImVec4(0.36f, 0.45f, 0.36f, 0.60f);
500
501 colors[ImGuiCol_Separator] = ImVec4(0.50f, 0.50f, 0.50f, 0.60f);
502 colors[ImGuiCol_SeparatorHovered] = ImVec4(0.60f, 0.60f, 0.70f, 1.00f);
503 colors[ImGuiCol_SeparatorActive] = ImVec4(0.70f, 0.70f, 0.90f, 1.00f);
504 colors[ImGuiCol_ResizeGrip] = ImVec4(1.00f, 1.00f, 1.00f, 0.10f);
505 colors[ImGuiCol_ResizeGripHovered] = ImVec4(0.78f, 0.82f, 1.00f, 0.60f);
506 colors[ImGuiCol_ResizeGripActive] = ImVec4(0.78f, 0.82f, 1.00f, 0.90f);
507
508 colors[ImGuiCol_TabUnfocused] =
509 ImLerp(colors[ImGuiCol_Tab], colors[ImGuiCol_TitleBg], 0.80f);
510 colors[ImGuiCol_TabUnfocusedActive] =
511 ImLerp(colors[ImGuiCol_TabActive], colors[ImGuiCol_TitleBg], 0.40f);
512 colors[ImGuiCol_PlotLines] = ImVec4(1.00f, 1.00f, 1.00f, 1.00f);
513 colors[ImGuiCol_PlotLinesHovered] = ImVec4(0.90f, 0.70f, 0.00f, 1.00f);
514 colors[ImGuiCol_PlotHistogram] = ImVec4(0.90f, 0.70f, 0.00f, 1.00f);
515 colors[ImGuiCol_PlotHistogramHovered] = ImVec4(1.00f, 0.60f, 0.00f, 1.00f);
516 colors[ImGuiCol_TableHeaderBg] = alttpDarkGreen;
517 colors[ImGuiCol_TableBorderStrong] = alttpMidGreen;
518 colors[ImGuiCol_TableBorderLight] =
519 ImVec4(0.26f, 0.26f, 0.28f, 1.00f); // Prefer using Alpha=1.0 here
520 colors[ImGuiCol_TableRowBg] = ImVec4(0.00f, 0.00f, 0.00f, 0.00f);
521 colors[ImGuiCol_TableRowBgAlt] = ImVec4(1.00f, 1.00f, 1.00f, 0.07f);
522 colors[ImGuiCol_TextSelectedBg] = ImVec4(0.00f, 0.00f, 1.00f, 0.35f);
523 colors[ImGuiCol_DragDropTarget] = ImVec4(1.00f, 1.00f, 0.00f, 0.90f);
524 colors[ImGuiCol_NavHighlight] = colors[ImGuiCol_HeaderHovered];
525 colors[ImGuiCol_NavWindowingHighlight] = ImVec4(1.00f, 1.00f, 1.00f, 0.70f);
526 colors[ImGuiCol_NavWindowingDimBg] = ImVec4(0.80f, 0.80f, 0.80f, 0.20f);
527 colors[ImGuiCol_ModalWindowDimBg] = ImVec4(0.20f, 0.20f, 0.20f, 0.35f);
528}
529
530void DrawBitmapViewer(const std::vector<gfx::Bitmap> &bitmaps, float scale,
531 int &current_bitmap_id) {
532 if (bitmaps.empty()) {
533 ImGui::Text("No bitmaps available.");
534 return;
535 }
536
537 // Display the current bitmap index and total count.
538 ImGui::Text("Viewing Bitmap %d / %zu", current_bitmap_id + 1, bitmaps.size());
539
540 // Buttons to navigate through bitmaps.
541 if (ImGui::Button("<- Prev")) {
542 if (current_bitmap_id > 0) {
543 --current_bitmap_id;
544 }
545 }
546 ImGui::SameLine();
547 if (ImGui::Button("Next ->")) {
548 if (current_bitmap_id < bitmaps.size() - 1) {
549 ++current_bitmap_id;
550 }
551 }
552
553 // Display the current bitmap.
554 const gfx::Bitmap &current_bitmap = bitmaps[current_bitmap_id];
555 // Assuming Bitmap has a function to get its texture ID, and width and
556 // height.
557 ImTextureID tex_id = (ImTextureID)(intptr_t)current_bitmap.texture();
558 ImVec2 size(current_bitmap.width() * scale, current_bitmap.height() * scale);
559 // ImGui::Image(tex_id, size);
560
561 // Scroll if the image is larger than the display area.
562 if (ImGui::BeginChild("BitmapScrollArea", ImVec2(0, 0), false,
563 ImGuiWindowFlags_HorizontalScrollbar)) {
564 ImGui::Image(tex_id, size);
565 ImGui::EndChild();
566 }
567}
568
569// ============================================================================
570// 65816 LanguageDefinition
571// ============================================================================
572
573static const char *const kKeywords[] = {
574 "ADC", "AND", "ASL", "BCC", "BCS", "BEQ", "BIT", "BMI", "BNE",
575 "BPL", "BRA", "BRL", "BVC", "BVS", "CLC", "CLD", "CLI", "CLV",
576 "CMP", "CPX", "CPY", "DEC", "DEX", "DEY", "EOR", "INC", "INX",
577 "INY", "JMP", "JSR", "JSL", "LDA", "LDX", "LDY", "LSR", "MVN",
578 "NOP", "ORA", "PEA", "PER", "PHA", "PHB", "PHD", "PHP", "PHX",
579 "PHY", "PLA", "PLB", "PLD", "PLP", "PLX", "PLY", "REP", "ROL",
580 "ROR", "RTI", "RTL", "RTS", "SBC", "SEC", "SEI", "SEP", "STA",
581 "STP", "STX", "STY", "STZ", "TAX", "TAY", "TCD", "TCS", "TDC",
582 "TRB", "TSB", "TSC", "TSX", "TXA", "TXS", "TXY", "TYA", "TYX",
583 "WAI", "WDM", "XBA", "XCE", "ORG", "LOROM", "HIROM", "NAMESPACE", "DB"};
584
585static const char *const kIdentifiers[] = {
586 "abort", "abs", "acos", "asin", "atan", "atexit",
587 "atof", "atoi", "atol", "ceil", "clock", "cosh",
588 "ctime", "div", "exit", "fabs", "floor", "fmod",
589 "getchar", "getenv", "isalnum", "isalpha", "isdigit", "isgraph",
590 "ispunct", "isspace", "isupper", "kbhit", "log10", "log2",
591 "log", "memcmp", "modf", "pow", "putchar", "putenv",
592 "puts", "rand", "remove", "rename", "sinh", "sqrt",
593 "srand", "strcat", "strcmp", "strerror", "time", "tolower",
594 "toupper"};
595
596TextEditor::LanguageDefinition GetAssemblyLanguageDef() {
597 TextEditor::LanguageDefinition language_65816;
598 for (auto &k : kKeywords)
599 language_65816.mKeywords.emplace(k);
600
601 for (auto &k : kIdentifiers) {
602 TextEditor::Identifier id;
603 id.mDeclaration = "Built-in function";
604 language_65816.mIdentifiers.insert(std::make_pair(std::string(k), id));
605 }
606
607 language_65816.mTokenRegexStrings.push_back(
608 std::make_pair<std::string, TextEditor::PaletteIndex>(
609 "[ \\t]*#[ \\t]*[a-zA-Z_]+", TextEditor::PaletteIndex::Preprocessor));
610 language_65816.mTokenRegexStrings.push_back(
611 std::make_pair<std::string, TextEditor::PaletteIndex>(
612 "L?\\\"(\\\\.|[^\\\"])*\\\"", TextEditor::PaletteIndex::String));
613 language_65816.mTokenRegexStrings.push_back(
614 std::make_pair<std::string, TextEditor::PaletteIndex>(
615 "\\'\\\\?[^\\']\\'", TextEditor::PaletteIndex::CharLiteral));
616 language_65816.mTokenRegexStrings.push_back(
617 std::make_pair<std::string, TextEditor::PaletteIndex>(
618 "[+-]?([0-9]+([.][0-9]*)?|[.][0-9]+)([eE][+-]?[0-9]+)?[fF]?",
619 TextEditor::PaletteIndex::Number));
620 language_65816.mTokenRegexStrings.push_back(
621 std::make_pair<std::string, TextEditor::PaletteIndex>(
622 "[+-]?[0-9]+[Uu]?[lL]?[lL]?", TextEditor::PaletteIndex::Number));
623 language_65816.mTokenRegexStrings.push_back(
624 std::make_pair<std::string, TextEditor::PaletteIndex>(
625 "0[0-7]+[Uu]?[lL]?[lL]?", TextEditor::PaletteIndex::Number));
626 language_65816.mTokenRegexStrings.push_back(
627 std::make_pair<std::string, TextEditor::PaletteIndex>(
628 "0[xX][0-9a-fA-F]+[uU]?[lL]?[lL]?",
629 TextEditor::PaletteIndex::Number));
630 language_65816.mTokenRegexStrings.push_back(
631 std::make_pair<std::string, TextEditor::PaletteIndex>(
632 "[a-zA-Z_][a-zA-Z0-9_]*", TextEditor::PaletteIndex::Identifier));
633 language_65816.mTokenRegexStrings.push_back(
634 std::make_pair<std::string, TextEditor::PaletteIndex>(
635 "[\\[\\]\\{\\}\\!\\%\\^\\&\\*\\(\\)\\-\\+\\=\\~\\|\\<\\>\\?\\/"
636 "\\;\\,\\.]",
637 TextEditor::PaletteIndex::Punctuation));
638
639 language_65816.mCommentStart = "/*";
640 language_65816.mCommentEnd = "*/";
641 language_65816.mSingleLineComment = ";";
642
643 language_65816.mCaseSensitive = false;
644 language_65816.mAutoIndentation = true;
645
646 language_65816.mName = "65816";
647
648 return language_65816;
649}
650
651} // namespace gui
652} // namespace app
653} // namespace yaze
Represents a bitmap image.
Definition bitmap.h:67
auto texture() const
Definition bitmap.h:186
int height() const
Definition bitmap.h:173
int width() const
Definition bitmap.h:172
void DrawDisplaySettings(ImGuiStyle *ref)
Definition style.cc:60
TextEditor::LanguageDefinition GetAssemblyLanguageDef()
Definition style.cc:596
void EndPadding()
Definition style.cc:40
void BeginChildWithScrollbar(const char *str_id)
Definition style.cc:48
void BeginPadding(int i)
Definition style.cc:36
void BeginWindowWithDisplaySettings(const char *id, bool *active, const ImVec2 &size, ImGuiWindowFlags flags)
Definition style.cc:11
void BeginChildBothScrollbars(int id)
Definition style.cc:53
void ColorsYaze()
Definition style.cc:431
void EndNoPadding()
Definition style.cc:46
void DrawBitmapViewer(const std::vector< gfx::Bitmap > &bitmaps, float scale, int &current_bitmap_id)
Definition style.cc:530
void TextWithSeparators(const absl::string_view &text)
Definition style.cc:424
void BeginNoPadding()
Definition style.cc:42
void EndWindowWithDisplaySettings()
Definition style.cc:31
Definition common.cc:22