Popout PaletteEditor, general housekeeping
This commit is contained in:
222
src/app/gui/canvas.cc
Normal file
222
src/app/gui/canvas.cc
Normal file
@@ -0,0 +1,222 @@
|
||||
#include "canvas.h"
|
||||
|
||||
#include <imgui/imgui.h>
|
||||
|
||||
#include <cmath>
|
||||
#include <string>
|
||||
|
||||
#include "app/gfx/bitmap.h"
|
||||
#include "app/rom.h"
|
||||
|
||||
namespace yaze {
|
||||
namespace gui {
|
||||
|
||||
// Background for the Canvas represents region without any content drawn to it,
|
||||
// but can be controlled by the user.
|
||||
void Canvas::DrawBackground(ImVec2 canvas_size) {
|
||||
canvas_p0_ = ImGui::GetCursorScreenPos();
|
||||
if (!custom_canvas_size_) canvas_sz_ = ImGui::GetContentRegionAvail();
|
||||
if (canvas_size.x != 0) canvas_sz_ = canvas_size;
|
||||
canvas_p1_ = ImVec2(canvas_p0_.x + canvas_sz_.x, canvas_p0_.y + canvas_sz_.y);
|
||||
draw_list_ = ImGui::GetWindowDrawList(); // Draw border and background color
|
||||
draw_list_->AddRectFilled(canvas_p0_, canvas_p1_, IM_COL32(32, 32, 32, 255));
|
||||
draw_list_->AddRect(canvas_p0_, canvas_p1_, IM_COL32(255, 255, 255, 255));
|
||||
}
|
||||
|
||||
// Context Menu refers to what happens when the right mouse button is pressed
|
||||
// This routine also handles the scrolling for the canvas.
|
||||
void Canvas::DrawContextMenu() {
|
||||
// This will catch our interactions
|
||||
const ImGuiIO &io = ImGui::GetIO();
|
||||
ImGui::InvisibleButton(
|
||||
"canvas", canvas_sz_,
|
||||
ImGuiButtonFlags_MouseButtonLeft | ImGuiButtonFlags_MouseButtonRight);
|
||||
const bool is_active = ImGui::IsItemActive(); // Held
|
||||
const ImVec2 origin(canvas_p0_.x + scrolling_.x,
|
||||
canvas_p0_.y + scrolling_.y); // Lock scrolled origin
|
||||
const ImVec2 mouse_pos_in_canvas(io.MousePos.x - origin.x,
|
||||
io.MousePos.y - origin.y);
|
||||
|
||||
// Pan (we use a zero mouse threshold when there's no context menu)
|
||||
if (const float mouse_threshold_for_pan = enable_context_menu_ ? -1.0f : 0.0f;
|
||||
is_active &&
|
||||
ImGui::IsMouseDragging(ImGuiMouseButton_Right, mouse_threshold_for_pan)) {
|
||||
scrolling_.x += io.MouseDelta.x;
|
||||
scrolling_.y += io.MouseDelta.y;
|
||||
}
|
||||
|
||||
// Context menu (under default mouse threshold)
|
||||
if (ImVec2 drag_delta = ImGui::GetMouseDragDelta(ImGuiMouseButton_Right);
|
||||
enable_context_menu_ && drag_delta.x == 0.0f && drag_delta.y == 0.0f)
|
||||
ImGui::OpenPopupOnItemClick("context", ImGuiPopupFlags_MouseButtonRight);
|
||||
|
||||
// Contents of the Context Menu
|
||||
if (ImGui::BeginPopup("context")) {
|
||||
ImGui::MenuItem("Show Grid", nullptr, &enable_grid_);
|
||||
if (ImGui::MenuItem("Reset Position", nullptr, false)) {
|
||||
scrolling_.x = 0;
|
||||
scrolling_.y = 0;
|
||||
}
|
||||
|
||||
if (ImGui::MenuItem("Remove all", nullptr, false, points_.Size > 0)) {
|
||||
points_.clear();
|
||||
}
|
||||
ImGui::EndPopup();
|
||||
}
|
||||
}
|
||||
|
||||
// Tile painter shows a preview of the currently selected tile
|
||||
// and allows the user to left click to paint the tile or right
|
||||
// click to select a new tile to paint with.
|
||||
bool Canvas::DrawTilePainter(const Bitmap &bitmap, int size) {
|
||||
const ImGuiIO &io = ImGui::GetIO();
|
||||
const bool is_hovered = ImGui::IsItemHovered(); // Hovered
|
||||
const ImVec2 origin(canvas_p0_.x + scrolling_.x,
|
||||
canvas_p0_.y + scrolling_.y); // Lock scrolled origin
|
||||
const ImVec2 mouse_pos_in_canvas(io.MousePos.x - origin.x,
|
||||
io.MousePos.y - origin.y);
|
||||
|
||||
if (is_hovered) {
|
||||
// Reset the previous tile hover
|
||||
if (!points_.empty()) {
|
||||
points_.clear();
|
||||
}
|
||||
|
||||
// Calculate the coordinates of the mouse
|
||||
ImVec2 draw_tile_outline_pos;
|
||||
draw_tile_outline_pos.x =
|
||||
std::floor((double)mouse_pos_in_canvas.x / size) * size;
|
||||
draw_tile_outline_pos.y =
|
||||
std::floor((double)mouse_pos_in_canvas.y / size) * size;
|
||||
|
||||
auto draw_tile_outline_pos_end =
|
||||
ImVec2(draw_tile_outline_pos.x + size, draw_tile_outline_pos.y + size);
|
||||
points_.push_back(draw_tile_outline_pos);
|
||||
points_.push_back(draw_tile_outline_pos_end);
|
||||
|
||||
if (bitmap.IsActive()) {
|
||||
draw_list_->AddImage(
|
||||
(void *)bitmap.GetTexture(),
|
||||
ImVec2(origin.x + draw_tile_outline_pos.x,
|
||||
origin.y + draw_tile_outline_pos.y),
|
||||
ImVec2(origin.x + draw_tile_outline_pos.x + bitmap.GetWidth(),
|
||||
origin.y + draw_tile_outline_pos.y + bitmap.GetHeight()));
|
||||
}
|
||||
|
||||
if (ImGui::IsMouseClicked(ImGuiMouseButton_Left)) {
|
||||
// Draw the currently selected tile on the overworld here
|
||||
// Save the coordinates of the selected tile.
|
||||
drawn_tile_pos_ = mouse_pos_in_canvas;
|
||||
return true;
|
||||
}
|
||||
|
||||
} else {
|
||||
// Erase the hover when the mouse is not in the canvas window.
|
||||
points_.clear();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// Dictates which tile is currently selected based on what the user clicks
|
||||
// in the canvas window. Represented and split apart into a grid of tiles.
|
||||
void Canvas::DrawTileSelector(int size) {
|
||||
const ImGuiIO &io = ImGui::GetIO();
|
||||
const bool is_hovered = ImGui::IsItemHovered(); // Hovered
|
||||
const ImVec2 origin(canvas_p0_.x + scrolling_.x,
|
||||
canvas_p0_.y + scrolling_.y); // Lock scrolled origin
|
||||
const ImVec2 mouse_pos_in_canvas(io.MousePos.x - origin.x,
|
||||
io.MousePos.y - origin.y);
|
||||
|
||||
if (is_hovered && ImGui::IsMouseClicked(ImGuiMouseButton_Left)) {
|
||||
if (!points_.empty()) {
|
||||
points_.clear();
|
||||
}
|
||||
ImVec2 draw_tile_outline_pos;
|
||||
draw_tile_outline_pos.x =
|
||||
std::floor((double)mouse_pos_in_canvas.x / size) * size;
|
||||
draw_tile_outline_pos.y =
|
||||
std::floor((double)mouse_pos_in_canvas.y / size) * size;
|
||||
|
||||
points_.push_back(draw_tile_outline_pos);
|
||||
points_.push_back(
|
||||
ImVec2(draw_tile_outline_pos.x + size, draw_tile_outline_pos.y + size));
|
||||
}
|
||||
}
|
||||
|
||||
// Draws the contents of the Bitmap image to the Canvas
|
||||
void Canvas::DrawBitmap(const Bitmap &bitmap, int border_offset, bool ready) {
|
||||
if (ready) {
|
||||
draw_list_->AddImage(
|
||||
(void *)bitmap.GetTexture(),
|
||||
ImVec2(canvas_p0_.x + border_offset, canvas_p0_.y + border_offset),
|
||||
ImVec2(canvas_p0_.x + (bitmap.GetWidth() * 2),
|
||||
canvas_p0_.y + (bitmap.GetHeight() * 2)));
|
||||
}
|
||||
}
|
||||
|
||||
void Canvas::DrawBitmap(const Bitmap &bitmap, int x_offset, int y_offset) {
|
||||
draw_list_->AddImage(
|
||||
(void *)bitmap.GetTexture(),
|
||||
ImVec2(canvas_p0_.x + x_offset + scrolling_.x,
|
||||
canvas_p0_.y + y_offset + scrolling_.y),
|
||||
ImVec2(canvas_p0_.x + x_offset + scrolling_.x + (bitmap.GetWidth()),
|
||||
canvas_p0_.y + y_offset + scrolling_.y + (bitmap.GetHeight())));
|
||||
}
|
||||
|
||||
void Canvas::DrawOutline(int x, int y, int w, int h) {
|
||||
ImVec2 origin(canvas_p0_.x + scrolling_.x + x,
|
||||
canvas_p0_.y + scrolling_.y + y);
|
||||
ImVec2 size(canvas_p0_.x + scrolling_.x + x + w,
|
||||
canvas_p0_.y + scrolling_.y + y + h);
|
||||
draw_list_->AddRect(origin, size, IM_COL32(255, 255, 255, 255));
|
||||
}
|
||||
|
||||
// Canvas Wrapper for a Rectangle
|
||||
void Canvas::DrawRect(int x, int y, int w, int h, ImVec4 color) {
|
||||
ImVec2 origin(canvas_p0_.x + scrolling_.x + x,
|
||||
canvas_p0_.y + scrolling_.y + y);
|
||||
ImVec2 size(canvas_p0_.x + scrolling_.x + x + w,
|
||||
canvas_p0_.y + scrolling_.y + y + h);
|
||||
draw_list_->AddRectFilled(origin, size,
|
||||
IM_COL32(color.x, color.y, color.z, color.w));
|
||||
}
|
||||
|
||||
// Canvas Wrapper for Text
|
||||
void Canvas::DrawText(std::string text, int x, int y) {
|
||||
draw_list_->AddText(
|
||||
ImVec2(canvas_p0_.x + scrolling_.x + x, canvas_p0_.y + scrolling_.y + y),
|
||||
IM_COL32(255, 255, 255, 255), text.data());
|
||||
}
|
||||
|
||||
void Canvas::DrawGrid(float grid_step) {
|
||||
// Draw grid + all lines in the canvas
|
||||
draw_list_->PushClipRect(canvas_p0_, canvas_p1_, true);
|
||||
if (enable_grid_) {
|
||||
for (float x = fmodf(scrolling_.x, grid_step); x < canvas_sz_.x;
|
||||
x += grid_step)
|
||||
draw_list_->AddLine(ImVec2(canvas_p0_.x + x, canvas_p0_.y),
|
||||
ImVec2(canvas_p0_.x + x, canvas_p1_.y),
|
||||
IM_COL32(200, 200, 200, 40));
|
||||
for (float y = fmodf(scrolling_.y, grid_step); y < canvas_sz_.y;
|
||||
y += grid_step)
|
||||
draw_list_->AddLine(ImVec2(canvas_p0_.x, canvas_p0_.y + y),
|
||||
ImVec2(canvas_p1_.x, canvas_p0_.y + y),
|
||||
IM_COL32(200, 200, 200, 40));
|
||||
}
|
||||
}
|
||||
|
||||
void Canvas::DrawOverlay() {
|
||||
const ImVec2 origin(canvas_p0_.x + scrolling_.x,
|
||||
canvas_p0_.y + scrolling_.y); // Lock scrolled origin
|
||||
for (int n = 0; n < points_.Size; n += 2) {
|
||||
draw_list_->AddRect(
|
||||
ImVec2(origin.x + points_[n].x, origin.y + points_[n].y),
|
||||
ImVec2(origin.x + points_[n + 1].x, origin.y + points_[n + 1].y),
|
||||
IM_COL32(255, 255, 255, 255), 1.0f);
|
||||
}
|
||||
|
||||
draw_list_->PopClipRect();
|
||||
}
|
||||
|
||||
} // namespace gui
|
||||
} // namespace yaze
|
||||
72
src/app/gui/canvas.h
Normal file
72
src/app/gui/canvas.h
Normal file
@@ -0,0 +1,72 @@
|
||||
#ifndef YAZE_GUI_CANVAS_H
|
||||
#define YAZE_GUI_CANVAS_H
|
||||
|
||||
#include <imgui/imgui.h>
|
||||
|
||||
#include <cmath>
|
||||
#include <string>
|
||||
|
||||
#include "app/gfx/bitmap.h"
|
||||
#include "app/rom.h"
|
||||
|
||||
namespace yaze {
|
||||
namespace gui {
|
||||
|
||||
using app::gfx::Bitmap;
|
||||
|
||||
class Canvas {
|
||||
public:
|
||||
Canvas() = default;
|
||||
explicit Canvas(ImVec2 canvas_size)
|
||||
: custom_canvas_size_(true), canvas_sz_(canvas_size) {}
|
||||
|
||||
void DrawBackground(ImVec2 canvas_size = ImVec2(0, 0));
|
||||
void DrawContextMenu();
|
||||
|
||||
bool DrawTilePainter(const Bitmap& bitmap, int size);
|
||||
void DrawTileSelector(int size);
|
||||
|
||||
void DrawBitmap(const Bitmap& bitmap, int border_offset = 0,
|
||||
bool ready = true);
|
||||
void DrawBitmap(const Bitmap& bitmap, int x_offset, int y_offset);
|
||||
void DrawOutline(int x, int y, int w, int h);
|
||||
void DrawRect(int x, int y, int w, int h, ImVec4 color);
|
||||
void DrawText(std::string text, int x, int y);
|
||||
void DrawGrid(float grid_step = 64.0f);
|
||||
void DrawOverlay(); // last
|
||||
|
||||
auto Points() const { return points_; }
|
||||
auto GetDrawList() const { return draw_list_; }
|
||||
auto GetZeroPoint() const { return canvas_p0_; }
|
||||
auto GetCurrentDrawnTilePosition() const { return drawn_tile_pos_; }
|
||||
auto GetCanvasSize() const { return canvas_sz_; }
|
||||
void SetCanvasSize(ImVec2 canvas_size) {
|
||||
canvas_sz_ = canvas_size;
|
||||
custom_canvas_size_ = true;
|
||||
}
|
||||
|
||||
private:
|
||||
bool enable_grid_ = true;
|
||||
bool enable_context_menu_ = true;
|
||||
bool custom_canvas_size_ = false;
|
||||
bool is_hovered_ = false;
|
||||
|
||||
ImDrawList* draw_list_;
|
||||
ImVector<ImVec2> points_;
|
||||
ImVec2 scrolling_;
|
||||
ImVec2 canvas_sz_;
|
||||
ImVec2 canvas_p0_;
|
||||
ImVec2 canvas_p1_;
|
||||
ImVec2 mouse_pos_in_canvas_;
|
||||
ImVec2 drawn_tile_pos_;
|
||||
|
||||
std::vector<app::gfx::Bitmap> changed_tiles_;
|
||||
app::gfx::Bitmap current_tile_;
|
||||
|
||||
std::string title_;
|
||||
};
|
||||
|
||||
} // namespace gui
|
||||
} // namespace yaze
|
||||
|
||||
#endif
|
||||
84
src/app/gui/color.cc
Normal file
84
src/app/gui/color.cc
Normal file
@@ -0,0 +1,84 @@
|
||||
#include "color.h"
|
||||
|
||||
#include <imgui/imgui.h>
|
||||
|
||||
#include <cmath>
|
||||
#include <string>
|
||||
|
||||
#include "app/gfx/bitmap.h"
|
||||
#include "app/gfx/snes_palette.h"
|
||||
|
||||
namespace yaze {
|
||||
namespace gui {
|
||||
void DisplayPalette(app::gfx::SNESPalette& palette, bool loaded) {
|
||||
static ImVec4 color = ImVec4(0, 0, 0, 255.f);
|
||||
ImGuiColorEditFlags misc_flags = ImGuiColorEditFlags_AlphaPreview |
|
||||
ImGuiColorEditFlags_NoDragDrop |
|
||||
ImGuiColorEditFlags_NoOptions;
|
||||
|
||||
// Generate a default palette. The palette will persist and can be edited.
|
||||
static bool init = false;
|
||||
static ImVec4 saved_palette[32] = {};
|
||||
if (loaded && !init) {
|
||||
for (int n = 0; n < palette.size_; n++) {
|
||||
saved_palette[n].x = palette.GetColor(n).rgb.x / 255;
|
||||
saved_palette[n].y = palette.GetColor(n).rgb.y / 255;
|
||||
saved_palette[n].z = palette.GetColor(n).rgb.z / 255;
|
||||
saved_palette[n].w = 255; // Alpha
|
||||
}
|
||||
init = true;
|
||||
}
|
||||
|
||||
static ImVec4 backup_color;
|
||||
ImGui::Text("Current ==>");
|
||||
ImGui::SameLine();
|
||||
ImGui::Text("Previous");
|
||||
|
||||
ImGui::ColorButton(
|
||||
"##current", color,
|
||||
ImGuiColorEditFlags_NoPicker | ImGuiColorEditFlags_AlphaPreviewHalf,
|
||||
ImVec2(60, 40));
|
||||
ImGui::SameLine();
|
||||
|
||||
if (ImGui::ColorButton(
|
||||
"##previous", backup_color,
|
||||
ImGuiColorEditFlags_NoPicker | ImGuiColorEditFlags_AlphaPreviewHalf,
|
||||
ImVec2(60, 40)))
|
||||
color = backup_color;
|
||||
ImGui::Separator();
|
||||
|
||||
ImGui::BeginGroup(); // Lock X position
|
||||
ImGui::Text("Palette");
|
||||
for (int n = 0; n < IM_ARRAYSIZE(saved_palette); n++) {
|
||||
ImGui::PushID(n);
|
||||
if ((n % 4) != 0) ImGui::SameLine(0.0f, ImGui::GetStyle().ItemSpacing.y);
|
||||
|
||||
ImGuiColorEditFlags palette_button_flags = ImGuiColorEditFlags_NoAlpha |
|
||||
ImGuiColorEditFlags_NoPicker |
|
||||
ImGuiColorEditFlags_NoTooltip;
|
||||
if (ImGui::ColorButton("##palette", saved_palette[n], palette_button_flags,
|
||||
ImVec2(20, 20)))
|
||||
color = ImVec4(saved_palette[n].x, saved_palette[n].y, saved_palette[n].z,
|
||||
color.w); // Preserve alpha!
|
||||
|
||||
if (ImGui::BeginDragDropTarget()) {
|
||||
if (const ImGuiPayload* payload =
|
||||
ImGui::AcceptDragDropPayload(IMGUI_PAYLOAD_TYPE_COLOR_3F))
|
||||
memcpy((float*)&saved_palette[n], payload->Data, sizeof(float) * 3);
|
||||
if (const ImGuiPayload* payload =
|
||||
ImGui::AcceptDragDropPayload(IMGUI_PAYLOAD_TYPE_COLOR_4F))
|
||||
memcpy((float*)&saved_palette[n], payload->Data, sizeof(float) * 4);
|
||||
ImGui::EndDragDropTarget();
|
||||
}
|
||||
|
||||
ImGui::PopID();
|
||||
}
|
||||
ImGui::EndGroup();
|
||||
ImGui::SameLine();
|
||||
|
||||
ImGui::ColorPicker4("##picker", (float*)&color,
|
||||
misc_flags | ImGuiColorEditFlags_NoSidePreview |
|
||||
ImGuiColorEditFlags_NoSmallPreview);
|
||||
}
|
||||
} // namespace gui
|
||||
} // namespace yaze
|
||||
20
src/app/gui/color.h
Normal file
20
src/app/gui/color.h
Normal file
@@ -0,0 +1,20 @@
|
||||
#ifndef YAZE_GUI_COLOR_H
|
||||
#define YAZE_GUI_COLOR_H
|
||||
|
||||
#include <imgui/imgui.h>
|
||||
|
||||
#include <cmath>
|
||||
#include <string>
|
||||
|
||||
#include "app/gfx/bitmap.h"
|
||||
#include "app/gfx/snes_palette.h"
|
||||
|
||||
namespace yaze {
|
||||
namespace gui {
|
||||
|
||||
void DisplayPalette(app::gfx::SNESPalette& palette, bool loaded);
|
||||
|
||||
} // namespace gui
|
||||
} // namespace yaze
|
||||
|
||||
#endif
|
||||
2192
src/app/gui/icons.h
Normal file
2192
src/app/gui/icons.h
Normal file
File diff suppressed because it is too large
Load Diff
70
src/app/gui/input.cc
Normal file
70
src/app/gui/input.cc
Normal file
@@ -0,0 +1,70 @@
|
||||
#include "input.h"
|
||||
|
||||
#include <imgui/imgui.h>
|
||||
#include <imgui/imgui_internal.h>
|
||||
|
||||
#include "absl/strings/string_view.h"
|
||||
|
||||
namespace yaze {
|
||||
namespace gui {
|
||||
|
||||
const int kStepOneHex = 0x01;
|
||||
const int kStepFastHex = 0x0F;
|
||||
|
||||
bool InputHex(const char* label, int* data) {
|
||||
return ImGui::InputScalar(label, ImGuiDataType_U64, data, &kStepOneHex,
|
||||
&kStepFastHex, "%06X",
|
||||
ImGuiInputTextFlags_CharsHexadecimal);
|
||||
}
|
||||
|
||||
bool InputHexShort(const char* label, int* data) {
|
||||
return ImGui::InputScalar(label, ImGuiDataType_U32, data, &kStepOneHex,
|
||||
&kStepFastHex, "%06X",
|
||||
ImGuiInputTextFlags_CharsHexadecimal);
|
||||
}
|
||||
|
||||
void ItemLabel(absl::string_view title, ItemLabelFlags flags) {
|
||||
ImGuiWindow* window = ImGui::GetCurrentWindow();
|
||||
const ImVec2 lineStart = ImGui::GetCursorScreenPos();
|
||||
const ImGuiStyle& style = ImGui::GetStyle();
|
||||
float fullWidth = ImGui::GetContentRegionAvail().x;
|
||||
float itemWidth = ImGui::CalcItemWidth() + style.ItemSpacing.x;
|
||||
ImVec2 textSize = ImGui::CalcTextSize(title.begin(), title.end());
|
||||
ImRect textRect;
|
||||
textRect.Min = ImGui::GetCursorScreenPos();
|
||||
if (flags & ItemLabelFlag::Right) textRect.Min.x = textRect.Min.x + itemWidth;
|
||||
textRect.Max = textRect.Min;
|
||||
textRect.Max.x += fullWidth - itemWidth;
|
||||
textRect.Max.y += textSize.y;
|
||||
|
||||
ImGui::SetCursorScreenPos(textRect.Min);
|
||||
|
||||
ImGui::AlignTextToFramePadding();
|
||||
// Adjust text rect manually because we render it directly into a drawlist
|
||||
// instead of using public functions.
|
||||
textRect.Min.y += window->DC.CurrLineTextBaseOffset;
|
||||
textRect.Max.y += window->DC.CurrLineTextBaseOffset;
|
||||
|
||||
ImGui::ItemSize(textRect);
|
||||
if (ImGui::ItemAdd(
|
||||
textRect, window->GetID(title.data(), title.data() + title.size()))) {
|
||||
ImGui::RenderTextEllipsis(
|
||||
ImGui::GetWindowDrawList(), textRect.Min, textRect.Max, textRect.Max.x,
|
||||
textRect.Max.x, title.data(), title.data() + title.size(), &textSize);
|
||||
|
||||
if (textRect.GetWidth() < textSize.x && ImGui::IsItemHovered())
|
||||
ImGui::SetTooltip("%.*s", (int)title.size(), title.data());
|
||||
}
|
||||
if (flags & ItemLabelFlag::Left) {
|
||||
ImVec2 result;
|
||||
auto other = ImVec2{0, textSize.y + window->DC.CurrLineTextBaseOffset};
|
||||
result.x = textRect.Max.x - other.x;
|
||||
result.y = textRect.Max.y - other.y;
|
||||
ImGui::SetCursorScreenPos(result);
|
||||
ImGui::SameLine();
|
||||
} else if (flags & ItemLabelFlag::Right)
|
||||
ImGui::SetCursorScreenPos(lineStart);
|
||||
}
|
||||
|
||||
} // namespace gui
|
||||
} // namespace yaze
|
||||
29
src/app/gui/input.h
Normal file
29
src/app/gui/input.h
Normal file
@@ -0,0 +1,29 @@
|
||||
#ifndef YAZE_APP_CORE_INPUT_H
|
||||
#define YAZE_APP_CORE_INPUT_H
|
||||
|
||||
#include <imgui/imgui.h>
|
||||
#include <imgui/imgui_internal.h>
|
||||
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
|
||||
#include "absl/strings/string_view.h"
|
||||
|
||||
namespace yaze {
|
||||
namespace gui {
|
||||
|
||||
IMGUI_API bool InputHex(const char* label, int* data);
|
||||
IMGUI_API bool InputHexShort(const char* label, int* data);
|
||||
|
||||
using ItemLabelFlags = enum ItemLabelFlag {
|
||||
Left = 1u << 0u,
|
||||
Right = 1u << 1u,
|
||||
Default = Left,
|
||||
};
|
||||
|
||||
IMGUI_API void ItemLabel(absl::string_view title, ItemLabelFlags flags);
|
||||
|
||||
} // namespace gui
|
||||
} // namespace yaze
|
||||
|
||||
#endif
|
||||
108
src/app/gui/style.cc
Normal file
108
src/app/gui/style.cc
Normal file
@@ -0,0 +1,108 @@
|
||||
#include "style.h"
|
||||
|
||||
#include "imgui/imgui.h"
|
||||
#include "imgui/imgui_internal.h"
|
||||
|
||||
namespace yaze {
|
||||
namespace gui {
|
||||
|
||||
void ColorsYaze() {
|
||||
ImGuiStyle *style = &ImGui::GetStyle();
|
||||
ImVec4 *colors = style->Colors;
|
||||
|
||||
style->WindowPadding = ImVec2(10.f, 10.f);
|
||||
style->FramePadding = ImVec2(10.f, 3.f);
|
||||
style->CellPadding = ImVec2(4.f, 5.f);
|
||||
style->ItemSpacing = ImVec2(10.f, 5.f);
|
||||
style->ItemInnerSpacing = ImVec2(5.f, 5.f);
|
||||
style->TouchExtraPadding = ImVec2(0.f, 0.f);
|
||||
style->IndentSpacing = 20.f;
|
||||
style->ScrollbarSize = 14.f;
|
||||
style->GrabMinSize = 15.f;
|
||||
|
||||
style->WindowBorderSize = 0.f;
|
||||
style->ChildBorderSize = 1.f;
|
||||
style->PopupBorderSize = 1.f;
|
||||
style->FrameBorderSize = 0.f;
|
||||
style->TabBorderSize = 0.f;
|
||||
|
||||
style->WindowRounding = 0.f;
|
||||
style->ChildRounding = 0.f;
|
||||
style->FrameRounding = 5.f;
|
||||
style->PopupRounding = 0.f;
|
||||
style->ScrollbarRounding = 5.f;
|
||||
|
||||
auto alttpDarkGreen = ImVec4(0.18f, 0.26f, 0.18f, 1.0f);
|
||||
auto alttpMidGreen = ImVec4(0.28f, 0.36f, 0.28f, 1.0f);
|
||||
auto allttpLightGreen = ImVec4(0.36f, 0.45f, 0.36f, 1.0f);
|
||||
auto allttpLightestGreen = ImVec4(0.49f, 0.57f, 0.49f, 1.0f);
|
||||
|
||||
colors[ImGuiCol_MenuBarBg] = alttpDarkGreen;
|
||||
colors[ImGuiCol_TitleBg] = alttpMidGreen;
|
||||
|
||||
colors[ImGuiCol_Header] = alttpDarkGreen;
|
||||
colors[ImGuiCol_HeaderHovered] = allttpLightGreen;
|
||||
colors[ImGuiCol_HeaderActive] = alttpMidGreen;
|
||||
|
||||
colors[ImGuiCol_TitleBgActive] = alttpDarkGreen;
|
||||
colors[ImGuiCol_TitleBgCollapsed] = alttpMidGreen;
|
||||
|
||||
colors[ImGuiCol_Tab] = alttpDarkGreen;
|
||||
colors[ImGuiCol_TabHovered] = alttpMidGreen;
|
||||
colors[ImGuiCol_TabActive] = ImVec4(0.347f, 0.466f, 0.347f, 1.000f);
|
||||
|
||||
colors[ImGuiCol_Button] = alttpMidGreen;
|
||||
colors[ImGuiCol_ButtonHovered] = allttpLightestGreen;
|
||||
colors[ImGuiCol_ButtonActive] = allttpLightGreen;
|
||||
|
||||
colors[ImGuiCol_ScrollbarBg] = ImVec4(0.36f, 0.45f, 0.36f, 0.60f);
|
||||
colors[ImGuiCol_ScrollbarGrab] = ImVec4(0.36f, 0.45f, 0.36f, 0.30f);
|
||||
colors[ImGuiCol_ScrollbarGrabHovered] = ImVec4(0.36f, 0.45f, 0.36f, 0.40f);
|
||||
colors[ImGuiCol_ScrollbarGrabActive] = ImVec4(0.36f, 0.45f, 0.36f, 0.60f);
|
||||
|
||||
colors[ImGuiCol_Text] = ImVec4(0.90f, 0.90f, 0.90f, 1.00f);
|
||||
colors[ImGuiCol_TextDisabled] = ImVec4(0.60f, 0.60f, 0.60f, 1.00f);
|
||||
colors[ImGuiCol_WindowBg] = ImVec4(0.00f, 0.00f, 0.00f, 0.85f);
|
||||
colors[ImGuiCol_ChildBg] = ImVec4(0.00f, 0.00f, 0.00f, 0.00f);
|
||||
colors[ImGuiCol_PopupBg] = ImVec4(0.11f, 0.11f, 0.14f, 0.92f);
|
||||
colors[ImGuiCol_Border] = allttpLightGreen;
|
||||
colors[ImGuiCol_BorderShadow] = ImVec4(0.00f, 0.00f, 0.00f, 0.00f);
|
||||
|
||||
colors[ImGuiCol_FrameBg] = ImVec4(0.43f, 0.43f, 0.43f, 0.39f);
|
||||
colors[ImGuiCol_FrameBgHovered] = ImVec4(0.28f, 0.36f, 0.28f, 0.40f);
|
||||
colors[ImGuiCol_FrameBgActive] = ImVec4(0.28f, 0.36f, 0.28f, 0.69f);
|
||||
|
||||
colors[ImGuiCol_CheckMark] = ImVec4(0.90f, 0.90f, 0.90f, 0.50f);
|
||||
colors[ImGuiCol_SliderGrab] = ImVec4(1.00f, 1.00f, 1.00f, 0.30f);
|
||||
colors[ImGuiCol_SliderGrabActive] = ImVec4(0.36f, 0.45f, 0.36f, 0.60f);
|
||||
|
||||
colors[ImGuiCol_Separator] = ImVec4(0.50f, 0.50f, 0.50f, 0.60f);
|
||||
colors[ImGuiCol_SeparatorHovered] = ImVec4(0.60f, 0.60f, 0.70f, 1.00f);
|
||||
colors[ImGuiCol_SeparatorActive] = ImVec4(0.70f, 0.70f, 0.90f, 1.00f);
|
||||
colors[ImGuiCol_ResizeGrip] = ImVec4(1.00f, 1.00f, 1.00f, 0.10f);
|
||||
colors[ImGuiCol_ResizeGripHovered] = ImVec4(0.78f, 0.82f, 1.00f, 0.60f);
|
||||
colors[ImGuiCol_ResizeGripActive] = ImVec4(0.78f, 0.82f, 1.00f, 0.90f);
|
||||
|
||||
colors[ImGuiCol_TabUnfocused] =
|
||||
ImLerp(colors[ImGuiCol_Tab], colors[ImGuiCol_TitleBg], 0.80f);
|
||||
colors[ImGuiCol_TabUnfocusedActive] =
|
||||
ImLerp(colors[ImGuiCol_TabActive], colors[ImGuiCol_TitleBg], 0.40f);
|
||||
colors[ImGuiCol_PlotLines] = ImVec4(1.00f, 1.00f, 1.00f, 1.00f);
|
||||
colors[ImGuiCol_PlotLinesHovered] = ImVec4(0.90f, 0.70f, 0.00f, 1.00f);
|
||||
colors[ImGuiCol_PlotHistogram] = ImVec4(0.90f, 0.70f, 0.00f, 1.00f);
|
||||
colors[ImGuiCol_PlotHistogramHovered] = ImVec4(1.00f, 0.60f, 0.00f, 1.00f);
|
||||
colors[ImGuiCol_TableHeaderBg] = alttpDarkGreen;
|
||||
colors[ImGuiCol_TableBorderStrong] = alttpMidGreen;
|
||||
colors[ImGuiCol_TableBorderLight] =
|
||||
ImVec4(0.26f, 0.26f, 0.28f, 1.00f); // Prefer using Alpha=1.0 here
|
||||
colors[ImGuiCol_TableRowBg] = ImVec4(0.00f, 0.00f, 0.00f, 0.00f);
|
||||
colors[ImGuiCol_TableRowBgAlt] = ImVec4(1.00f, 1.00f, 1.00f, 0.07f);
|
||||
colors[ImGuiCol_TextSelectedBg] = ImVec4(0.00f, 0.00f, 1.00f, 0.35f);
|
||||
colors[ImGuiCol_DragDropTarget] = ImVec4(1.00f, 1.00f, 0.00f, 0.90f);
|
||||
colors[ImGuiCol_NavHighlight] = colors[ImGuiCol_HeaderHovered];
|
||||
colors[ImGuiCol_NavWindowingHighlight] = ImVec4(1.00f, 1.00f, 1.00f, 0.70f);
|
||||
colors[ImGuiCol_NavWindowingDimBg] = ImVec4(0.80f, 0.80f, 0.80f, 0.20f);
|
||||
colors[ImGuiCol_ModalWindowDimBg] = ImVec4(0.20f, 0.20f, 0.20f, 0.35f);
|
||||
}
|
||||
} // namespace gui
|
||||
} // namespace yaze
|
||||
15
src/app/gui/style.h
Normal file
15
src/app/gui/style.h
Normal file
@@ -0,0 +1,15 @@
|
||||
#ifndef YAZE_APP_CORE_STYLE_H
|
||||
#define YAZE_APP_CORE_STYLE_H
|
||||
|
||||
#include <imgui/imgui.h>
|
||||
#include <imgui/imgui_internal.h>
|
||||
|
||||
namespace yaze {
|
||||
namespace gui {
|
||||
|
||||
void ColorsYaze();
|
||||
|
||||
} // namespace gui
|
||||
} // namespace yaze
|
||||
|
||||
#endif
|
||||
68
src/app/gui/widgets.cc
Normal file
68
src/app/gui/widgets.cc
Normal file
@@ -0,0 +1,68 @@
|
||||
#include "widgets.h"
|
||||
|
||||
#include <ImGuiColorTextEdit/TextEditor.h>
|
||||
|
||||
#include "absl/status/status.h"
|
||||
#include "app/core/constants.h"
|
||||
|
||||
namespace yaze {
|
||||
namespace gui {
|
||||
namespace widgets {
|
||||
|
||||
TextEditor::LanguageDefinition GetAssemblyLanguageDef() {
|
||||
TextEditor::LanguageDefinition language_65816;
|
||||
for (auto &k : app::core::kKeywords) language_65816.mKeywords.emplace(k);
|
||||
|
||||
for (auto &k : app::core::kIdentifiers) {
|
||||
TextEditor::Identifier id;
|
||||
id.mDeclaration = "Built-in function";
|
||||
language_65816.mIdentifiers.insert(std::make_pair(std::string(k), id));
|
||||
}
|
||||
|
||||
language_65816.mTokenRegexStrings.push_back(
|
||||
std::make_pair<std::string, TextEditor::PaletteIndex>(
|
||||
"[ \\t]*#[ \\t]*[a-zA-Z_]+", TextEditor::PaletteIndex::Preprocessor));
|
||||
language_65816.mTokenRegexStrings.push_back(
|
||||
std::make_pair<std::string, TextEditor::PaletteIndex>(
|
||||
"L?\\\"(\\\\.|[^\\\"])*\\\"", TextEditor::PaletteIndex::String));
|
||||
language_65816.mTokenRegexStrings.push_back(
|
||||
std::make_pair<std::string, TextEditor::PaletteIndex>(
|
||||
"\\'\\\\?[^\\']\\'", TextEditor::PaletteIndex::CharLiteral));
|
||||
language_65816.mTokenRegexStrings.push_back(
|
||||
std::make_pair<std::string, TextEditor::PaletteIndex>(
|
||||
"[+-]?([0-9]+([.][0-9]*)?|[.][0-9]+)([eE][+-]?[0-9]+)?[fF]?",
|
||||
TextEditor::PaletteIndex::Number));
|
||||
language_65816.mTokenRegexStrings.push_back(
|
||||
std::make_pair<std::string, TextEditor::PaletteIndex>(
|
||||
"[+-]?[0-9]+[Uu]?[lL]?[lL]?", TextEditor::PaletteIndex::Number));
|
||||
language_65816.mTokenRegexStrings.push_back(
|
||||
std::make_pair<std::string, TextEditor::PaletteIndex>(
|
||||
"0[0-7]+[Uu]?[lL]?[lL]?", TextEditor::PaletteIndex::Number));
|
||||
language_65816.mTokenRegexStrings.push_back(
|
||||
std::make_pair<std::string, TextEditor::PaletteIndex>(
|
||||
"0[xX][0-9a-fA-F]+[uU]?[lL]?[lL]?",
|
||||
TextEditor::PaletteIndex::Number));
|
||||
language_65816.mTokenRegexStrings.push_back(
|
||||
std::make_pair<std::string, TextEditor::PaletteIndex>(
|
||||
"[a-zA-Z_][a-zA-Z0-9_]*", TextEditor::PaletteIndex::Identifier));
|
||||
language_65816.mTokenRegexStrings.push_back(
|
||||
std::make_pair<std::string, TextEditor::PaletteIndex>(
|
||||
"[\\[\\]\\{\\}\\!\\%\\^\\&\\*\\(\\)\\-\\+\\=\\~\\|\\<\\>\\?\\/"
|
||||
"\\;\\,\\.]",
|
||||
TextEditor::PaletteIndex::Punctuation));
|
||||
|
||||
language_65816.mCommentStart = "/*";
|
||||
language_65816.mCommentEnd = "*/";
|
||||
language_65816.mSingleLineComment = ";";
|
||||
|
||||
language_65816.mCaseSensitive = false;
|
||||
language_65816.mAutoIndentation = true;
|
||||
|
||||
language_65816.mName = "65816";
|
||||
|
||||
return language_65816;
|
||||
}
|
||||
|
||||
} // namespace widgets
|
||||
} // namespace gui
|
||||
} // namespace yaze
|
||||
19
src/app/gui/widgets.h
Normal file
19
src/app/gui/widgets.h
Normal file
@@ -0,0 +1,19 @@
|
||||
#ifndef YAZE_GUI_WIDGETS_H
|
||||
#define YAZE_GUI_WIDGETS_H
|
||||
|
||||
#include <ImGuiColorTextEdit/TextEditor.h>
|
||||
|
||||
#include "absl/status/status.h"
|
||||
#include "app/core/constants.h"
|
||||
|
||||
namespace yaze {
|
||||
namespace gui {
|
||||
namespace widgets {
|
||||
|
||||
TextEditor::LanguageDefinition GetAssemblyLanguageDef();
|
||||
|
||||
} // namespace widgets
|
||||
} // namespace gui
|
||||
} // namespace yaze
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user