mirror of
https://github.com/arabine/open-story-teller.git
synced 2025-12-06 17:09:06 +01:00
fix build story editor v2
This commit is contained in:
parent
5da2ba2e56
commit
cb63b37f86
18 changed files with 9476 additions and 18 deletions
6
.gitignore
vendored
6
.gitignore
vendored
|
|
@ -53,3 +53,9 @@ software/.vscode/.cortex-debug.peripherals.state.json
|
||||||
story-editor/build
|
story-editor/build
|
||||||
|
|
||||||
build-story-editor-v2-System_Qt5_15_8-Debug/
|
build-story-editor-v2-System_Qt5_15_8-Debug/
|
||||||
|
|
||||||
|
story-editor-v2/src/CMakeSettings.json
|
||||||
|
|
||||||
|
story-editor-v2/imgui.ini
|
||||||
|
|
||||||
|
story-editor-v2/src/.vscode/
|
||||||
|
|
|
||||||
BIN
docs/images/proto1_board.png
Normal file
BIN
docs/images/proto1_board.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 195 KiB |
|
|
@ -80,11 +80,11 @@ set(SRCS
|
||||||
|
|
||||||
src/main.cpp
|
src/main.cpp
|
||||||
src/window_base.h
|
src/window_base.h
|
||||||
src/ConsoleWindow.cpp
|
src/console_window.cpp
|
||||||
src/ConsoleWindow.h
|
src/console_window.h
|
||||||
|
|
||||||
src/ImageWindow.cpp
|
src/emulator_window.cpp
|
||||||
src/ImageWindow.h
|
src/emulator_window.h
|
||||||
|
|
||||||
src/main_window.cpp
|
src/main_window.cpp
|
||||||
src/main_window.h
|
src/main_window.h
|
||||||
|
|
@ -101,11 +101,11 @@ set(SRCS
|
||||||
src/resources_window.cpp
|
src/resources_window.cpp
|
||||||
src/resources_window.h
|
src/resources_window.h
|
||||||
|
|
||||||
src/Gui.h
|
src/gui.h
|
||||||
src/Gui.cpp
|
src/gui.cpp
|
||||||
|
|
||||||
src/CodeEditor.cpp
|
src/code_editor.cpp
|
||||||
src/CodeEditor.h
|
src/code_editor.h
|
||||||
|
|
||||||
libs/ImGuiColorTextEdit/TextEditor.cpp
|
libs/ImGuiColorTextEdit/TextEditor.cpp
|
||||||
libs/ImGuiColorTextEdit/TextEditor.h
|
libs/ImGuiColorTextEdit/TextEditor.h
|
||||||
|
|
|
||||||
1006
story-editor-v2/src/IconsFontAwesome5_c.h
Normal file
1006
story-editor-v2/src/IconsFontAwesome5_c.h
Normal file
File diff suppressed because it is too large
Load diff
7378
story-editor-v2/src/IconsMaterialDesignIcons.h
Normal file
7378
story-editor-v2/src/IconsMaterialDesignIcons.h
Normal file
File diff suppressed because it is too large
Load diff
108
story-editor-v2/src/code_editor.cpp
Normal file
108
story-editor-v2/src/code_editor.cpp
Normal file
|
|
@ -0,0 +1,108 @@
|
||||||
|
#include "code_editor.h"
|
||||||
|
|
||||||
|
#include <fstream>
|
||||||
|
|
||||||
|
CodeEditor::CodeEditor()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void CodeEditor::Initialize()
|
||||||
|
{
|
||||||
|
// error markers
|
||||||
|
TextEditor::ErrorMarkers markers;
|
||||||
|
markers.insert(std::make_pair<int, std::string>(6, "Example error here:\nInclude file not found: \"TextEditor.h\""));
|
||||||
|
markers.insert(std::make_pair<int, std::string>(41, "Another example error"));
|
||||||
|
mEditor.SetErrorMarkers(markers);
|
||||||
|
|
||||||
|
// "breakpoint" markers
|
||||||
|
//TextEditor::Breakpoints bpts;
|
||||||
|
//bpts.insert(24);
|
||||||
|
//bpts.insert(47);
|
||||||
|
//editor.SetBreakpoints(bpts);
|
||||||
|
|
||||||
|
mFileToEdit = "test/test_zebra7500.js";
|
||||||
|
|
||||||
|
{
|
||||||
|
std::ifstream t(mFileToEdit);
|
||||||
|
if (t.good())
|
||||||
|
{
|
||||||
|
std::string str((std::istreambuf_iterator<char>(t)), std::istreambuf_iterator<char>());
|
||||||
|
mEditor.SetText(str);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void CodeEditor::Draw(const char* title, bool* p_open)
|
||||||
|
{
|
||||||
|
if (!IsVisible())
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto cpos = mEditor.GetCursorPosition();
|
||||||
|
ImGui::Begin(title, p_open, ImGuiWindowFlags_HorizontalScrollbar | ImGuiWindowFlags_MenuBar);
|
||||||
|
ImGui::SetWindowSize(ImVec2(800, 600), ImGuiCond_FirstUseEver);
|
||||||
|
if (ImGui::BeginMenuBar())
|
||||||
|
{
|
||||||
|
if (ImGui::BeginMenu("File"))
|
||||||
|
{
|
||||||
|
if (ImGui::MenuItem("Save"))
|
||||||
|
{
|
||||||
|
auto textToSave = mEditor.GetText();
|
||||||
|
/// save text....
|
||||||
|
}
|
||||||
|
ImGui::EndMenu();
|
||||||
|
}
|
||||||
|
if (ImGui::BeginMenu("Edit"))
|
||||||
|
{
|
||||||
|
bool ro = mEditor.IsReadOnly();
|
||||||
|
if (ImGui::MenuItem("Read-only mode", nullptr, &ro))
|
||||||
|
mEditor.SetReadOnly(ro);
|
||||||
|
ImGui::Separator();
|
||||||
|
|
||||||
|
if (ImGui::MenuItem("Undo", "ALT-Backspace", nullptr, !ro && mEditor.CanUndo()))
|
||||||
|
mEditor.Undo();
|
||||||
|
if (ImGui::MenuItem("Redo", "Ctrl-Y", nullptr, !ro && mEditor.CanRedo()))
|
||||||
|
mEditor.Redo();
|
||||||
|
|
||||||
|
ImGui::Separator();
|
||||||
|
|
||||||
|
if (ImGui::MenuItem("Copy", "Ctrl-C", nullptr, mEditor.HasSelection()))
|
||||||
|
mEditor.Copy();
|
||||||
|
if (ImGui::MenuItem("Cut", "Ctrl-X", nullptr, !ro && mEditor.HasSelection()))
|
||||||
|
mEditor.Cut();
|
||||||
|
if (ImGui::MenuItem("Delete", "Del", nullptr, !ro && mEditor.HasSelection()))
|
||||||
|
mEditor.Delete();
|
||||||
|
if (ImGui::MenuItem("Paste", "Ctrl-V", nullptr, !ro && ImGui::GetClipboardText() != nullptr))
|
||||||
|
mEditor.Paste();
|
||||||
|
|
||||||
|
ImGui::Separator();
|
||||||
|
|
||||||
|
if (ImGui::MenuItem("Select all", nullptr, nullptr))
|
||||||
|
mEditor.SetSelection(TextEditor::Coordinates(), TextEditor::Coordinates(mEditor.GetTotalLines(), 0));
|
||||||
|
|
||||||
|
ImGui::EndMenu();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ImGui::BeginMenu("View"))
|
||||||
|
{
|
||||||
|
if (ImGui::MenuItem("Dark palette"))
|
||||||
|
mEditor.SetPalette(TextEditor::GetDarkPalette());
|
||||||
|
if (ImGui::MenuItem("Light palette"))
|
||||||
|
mEditor.SetPalette(TextEditor::GetLightPalette());
|
||||||
|
if (ImGui::MenuItem("Retro blue palette"))
|
||||||
|
mEditor.SetPalette(TextEditor::GetRetroBluePalette());
|
||||||
|
ImGui::EndMenu();
|
||||||
|
}
|
||||||
|
ImGui::EndMenuBar();
|
||||||
|
}
|
||||||
|
|
||||||
|
ImGui::Text("%6d/%-6d %6d lines | %s | %s | %s | %s", cpos.mLine + 1, cpos.mColumn + 1, mEditor.GetTotalLines(),
|
||||||
|
mEditor.IsOverwrite() ? "Ovr" : "Ins",
|
||||||
|
mEditor.CanUndo() ? "*" : " ",
|
||||||
|
mEditor.GetLanguageDefinition().mName.c_str(), mFileToEdit.c_str());
|
||||||
|
|
||||||
|
mEditor.Render("TextEditor");
|
||||||
|
ImGui::End();
|
||||||
|
}
|
||||||
17
story-editor-v2/src/code_editor.h
Normal file
17
story-editor-v2/src/code_editor.h
Normal file
|
|
@ -0,0 +1,17 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "TextEditor.h"
|
||||||
|
#include "window_base.h"
|
||||||
|
|
||||||
|
class CodeEditor : public WindowBase
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
CodeEditor();
|
||||||
|
|
||||||
|
void Draw(const char *title, bool *p_open);
|
||||||
|
|
||||||
|
void Initialize();
|
||||||
|
private:
|
||||||
|
TextEditor mEditor;
|
||||||
|
std::string mFileToEdit;
|
||||||
|
};
|
||||||
329
story-editor-v2/src/console_window.cpp
Normal file
329
story-editor-v2/src/console_window.cpp
Normal file
|
|
@ -0,0 +1,329 @@
|
||||||
|
#include "console_window.h"
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
|
||||||
|
ConsoleWindow::ConsoleWindow()
|
||||||
|
{
|
||||||
|
ClearLog();
|
||||||
|
memset(InputBuf, 0, sizeof(InputBuf));
|
||||||
|
HistoryPos = -1;
|
||||||
|
|
||||||
|
// "CLASSIFY" is here to provide the test case where "C"+[tab] completes to "CL" and display multiple matches.
|
||||||
|
Commands.push_back("HELP");
|
||||||
|
Commands.push_back("HISTORY");
|
||||||
|
Commands.push_back("CLEAR");
|
||||||
|
Commands.push_back("CLASSIFY");
|
||||||
|
AutoScroll = true;
|
||||||
|
ScrollToBottom = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
ConsoleWindow::~ConsoleWindow()
|
||||||
|
{
|
||||||
|
ClearLog();
|
||||||
|
for (int i = 0; i < History.Size; i++)
|
||||||
|
free(History[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ConsoleWindow::ClearLog()
|
||||||
|
{
|
||||||
|
std::scoped_lock<std::mutex> mutex(mLogMutex);
|
||||||
|
Items.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ConsoleWindow::Draw(const char *title, bool *p_open)
|
||||||
|
{
|
||||||
|
ImGui::SetNextWindowSize(ImVec2(520, 600), ImGuiCond_FirstUseEver);
|
||||||
|
if (!ImGui::Begin(title, p_open))
|
||||||
|
{
|
||||||
|
ImGui::End();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// As a specific feature guaranteed by the library, after calling Begin() the last Item represent the title bar.
|
||||||
|
// So e.g. IsItemHovered() will return true when hovering the title bar.
|
||||||
|
// Here we create a context menu only available from the title bar.
|
||||||
|
if (ImGui::BeginPopupContextItem())
|
||||||
|
{
|
||||||
|
if (ImGui::MenuItem("Close Console"))
|
||||||
|
*p_open = false;
|
||||||
|
ImGui::EndPopup();
|
||||||
|
}
|
||||||
|
|
||||||
|
ImGui::TextWrapped("Console view");
|
||||||
|
// ImGui::TextWrapped("Enter 'HELP' for help.");
|
||||||
|
|
||||||
|
// TODO: display items starting from the bottom
|
||||||
|
|
||||||
|
// if (ImGui::SmallButton("Add Debug Text")) { AddLog("%d some text", Items.Size); AddLog("some more text"); AddLog("display very important message here!"); }
|
||||||
|
// ImGui::SameLine();
|
||||||
|
// if (ImGui::SmallButton("Add Debug Error")) { AddLog("[error] something went wrong"); }
|
||||||
|
// ImGui::SameLine();
|
||||||
|
if (ImGui::SmallButton("Clear")) { ClearLog(); }
|
||||||
|
ImGui::SameLine();
|
||||||
|
bool copy_to_clipboard = ImGui::SmallButton("Copy");
|
||||||
|
//static float t = 0.0f; if (ImGui::GetTime() - t > 0.02f) { t = ImGui::GetTime(); AddLog("Spam %f", t); }
|
||||||
|
|
||||||
|
// ImGui::Separator();
|
||||||
|
|
||||||
|
// // Options menu
|
||||||
|
// if (ImGui::BeginPopup("Options"))
|
||||||
|
// {
|
||||||
|
// ImGui::Checkbox("Auto-scroll", &AutoScroll);
|
||||||
|
// ImGui::EndPopup();
|
||||||
|
// }
|
||||||
|
|
||||||
|
// // Options, Filter
|
||||||
|
// if (ImGui::Button("Options"))
|
||||||
|
// ImGui::OpenPopup("Options");
|
||||||
|
// ImGui::SameLine();
|
||||||
|
// Filter.Draw("Filter (\"incl,-excl\") (\"error\")", 180);
|
||||||
|
ImGui::Separator();
|
||||||
|
|
||||||
|
// Reserve enough left-over height for 1 separator + 1 input text
|
||||||
|
const float footer_height_to_reserve = ImGui::GetStyle().ItemSpacing.y + ImGui::GetFrameHeightWithSpacing();
|
||||||
|
ImGui::BeginChild("ScrollingRegion", ImVec2(0, -footer_height_to_reserve), false, ImGuiWindowFlags_HorizontalScrollbar);
|
||||||
|
if (ImGui::BeginPopupContextWindow())
|
||||||
|
{
|
||||||
|
if (ImGui::Selectable("Clear")) ClearLog();
|
||||||
|
ImGui::EndPopup();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Display every line as a separate entry so we can change their color or add custom widgets.
|
||||||
|
// If you only want raw text you can use ImGui::TextUnformatted(log.begin(), log.end());
|
||||||
|
// NB- if you have thousands of entries this approach may be too inefficient and may require user-side clipping
|
||||||
|
// to only process visible items. The clipper will automatically measure the height of your first item and then
|
||||||
|
// "seek" to display only items in the visible area.
|
||||||
|
// To use the clipper we can replace your standard loop:
|
||||||
|
// for (int i = 0; i < Items.Size; i++)
|
||||||
|
// With:
|
||||||
|
// ImGuiListClipper clipper;
|
||||||
|
// clipper.Begin(Items.Size);
|
||||||
|
// while (clipper.Step())
|
||||||
|
// for (int i = clipper.DisplayStart; i < clipper.DisplayEnd; i++)
|
||||||
|
// - That your items are evenly spaced (same height)
|
||||||
|
// - That you have cheap random access to your elements (you can access them given their index,
|
||||||
|
// without processing all the ones before)
|
||||||
|
// You cannot this code as-is if a filter is active because it breaks the 'cheap random-access' property.
|
||||||
|
// We would need random-access on the post-filtered list.
|
||||||
|
// A typical application wanting coarse clipping and filtering may want to pre-compute an array of indices
|
||||||
|
// or offsets of items that passed the filtering test, recomputing this array when user changes the filter,
|
||||||
|
// and appending newly elements as they are inserted. This is left as a task to the user until we can manage
|
||||||
|
// to improve this example code!
|
||||||
|
// If your items are of variable height:
|
||||||
|
// - Split them into same height items would be simpler and facilitate random-seeking into your list.
|
||||||
|
// - Consider using manual call to IsRectVisible() and skipping extraneous decoration from your items.
|
||||||
|
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(4, 1)); // Tighten spacing
|
||||||
|
if (copy_to_clipboard)
|
||||||
|
ImGui::LogToClipboard();
|
||||||
|
|
||||||
|
ImGuiListClipper clipper;
|
||||||
|
std::scoped_lock<std::mutex> mutex(mLogMutex);
|
||||||
|
clipper.Begin(Items.size());
|
||||||
|
while (clipper.Step())
|
||||||
|
{
|
||||||
|
for (int i = clipper.DisplayStart; i < clipper.DisplayEnd; i++)
|
||||||
|
{
|
||||||
|
ImGui::TextUnformatted(Items[i].c_str());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
for (int i = 0; i < Items.Size; i++)
|
||||||
|
{
|
||||||
|
const char* item = Items[i];
|
||||||
|
if (!Filter.PassFilter(item))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
// Normally you would store more information in your item than just a string.
|
||||||
|
// (e.g. make Items[] an array of structure, store color/type etc.)
|
||||||
|
ImVec4 color;
|
||||||
|
bool has_color = false;
|
||||||
|
if (strstr(item, "[error]")) { color = ImVec4(1.0f, 0.4f, 0.4f, 1.0f); has_color = true; }
|
||||||
|
else if (strncmp(item, "# ", 2) == 0) { color = ImVec4(1.0f, 0.8f, 0.6f, 1.0f); has_color = true; }
|
||||||
|
if (has_color)
|
||||||
|
ImGui::PushStyleColor(ImGuiCol_Text, color);
|
||||||
|
ImGui::TextUnformatted(item);
|
||||||
|
if (has_color)
|
||||||
|
ImGui::PopStyleColor();
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
if (copy_to_clipboard)
|
||||||
|
ImGui::LogFinish();
|
||||||
|
|
||||||
|
if (ScrollToBottom || (AutoScroll && ImGui::GetScrollY() >= ImGui::GetScrollMaxY()))
|
||||||
|
ImGui::SetScrollHereY(1.0f);
|
||||||
|
ScrollToBottom = false;
|
||||||
|
|
||||||
|
ImGui::PopStyleVar();
|
||||||
|
ImGui::EndChild();
|
||||||
|
ImGui::Separator();
|
||||||
|
/*
|
||||||
|
// Command-line
|
||||||
|
bool reclaim_focus = false;
|
||||||
|
ImGuiInputTextFlags input_text_flags = ImGuiInputTextFlags_EnterReturnsTrue | ImGuiInputTextFlags_CallbackCompletion | ImGuiInputTextFlags_CallbackHistory;
|
||||||
|
if (ImGui::InputText("Input", InputBuf, IM_ARRAYSIZE(InputBuf), input_text_flags, &TextEditCallbackStub, (void*)this))
|
||||||
|
{
|
||||||
|
char* s = InputBuf;
|
||||||
|
Strtrim(s);
|
||||||
|
if (s[0])
|
||||||
|
ExecCommand(s);
|
||||||
|
strcpy(s, "");
|
||||||
|
reclaim_focus = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Auto-focus on window apparition
|
||||||
|
ImGui::SetItemDefaultFocus();
|
||||||
|
if (reclaim_focus)
|
||||||
|
ImGui::SetKeyboardFocusHere(-1); // Auto focus previous widget
|
||||||
|
*/
|
||||||
|
ImGui::End();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ConsoleWindow::ExecCommand(const char *command_line)
|
||||||
|
{
|
||||||
|
AddLog("# %s\n", command_line);
|
||||||
|
|
||||||
|
// Insert into history. First find match and delete it so it can be pushed to the back.
|
||||||
|
// This isn't trying to be smart or optimal.
|
||||||
|
HistoryPos = -1;
|
||||||
|
for (int i = History.Size - 1; i >= 0; i--)
|
||||||
|
if (Stricmp(History[i], command_line) == 0)
|
||||||
|
{
|
||||||
|
free(History[i]);
|
||||||
|
History.erase(History.begin() + i);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
History.push_back(Strdup(command_line));
|
||||||
|
|
||||||
|
// Process command
|
||||||
|
if (Stricmp(command_line, "CLEAR") == 0)
|
||||||
|
{
|
||||||
|
ClearLog();
|
||||||
|
}
|
||||||
|
else if (Stricmp(command_line, "HELP") == 0)
|
||||||
|
{
|
||||||
|
AddLog("Commands:");
|
||||||
|
for (int i = 0; i < Commands.Size; i++)
|
||||||
|
AddLog("- %s", Commands[i]);
|
||||||
|
}
|
||||||
|
else if (Stricmp(command_line, "HISTORY") == 0)
|
||||||
|
{
|
||||||
|
int first = History.Size - 10;
|
||||||
|
for (int i = first > 0 ? first : 0; i < History.Size; i++)
|
||||||
|
AddLog("%3d: %s\n", i, History[i]);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
AddLog("Unknown command: '%s'\n", command_line);
|
||||||
|
}
|
||||||
|
|
||||||
|
// On command input, we scroll to bottom even if AutoScroll==false
|
||||||
|
ScrollToBottom = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
int ConsoleWindow::TextEditCallbackStub(ImGuiInputTextCallbackData *data)
|
||||||
|
{
|
||||||
|
ConsoleWindow* console = (ConsoleWindow*)data->UserData;
|
||||||
|
return console->TextEditCallback(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
int ConsoleWindow::TextEditCallback(ImGuiInputTextCallbackData *data)
|
||||||
|
{
|
||||||
|
//AddLog("cursor: %d, selection: %d-%d", data->CursorPos, data->SelectionStart, data->SelectionEnd);
|
||||||
|
switch (data->EventFlag)
|
||||||
|
{
|
||||||
|
case ImGuiInputTextFlags_CallbackCompletion:
|
||||||
|
{
|
||||||
|
// Example of TEXT COMPLETION
|
||||||
|
|
||||||
|
// Locate beginning of current word
|
||||||
|
const char* word_end = data->Buf + data->CursorPos;
|
||||||
|
const char* word_start = word_end;
|
||||||
|
while (word_start > data->Buf)
|
||||||
|
{
|
||||||
|
const char c = word_start[-1];
|
||||||
|
if (c == ' ' || c == '\t' || c == ',' || c == ';')
|
||||||
|
break;
|
||||||
|
word_start--;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Build a list of candidates
|
||||||
|
ImVector<const char*> candidates;
|
||||||
|
for (int i = 0; i < Commands.Size; i++)
|
||||||
|
if (Strnicmp(Commands[i], word_start, (int)(word_end - word_start)) == 0)
|
||||||
|
candidates.push_back(Commands[i]);
|
||||||
|
|
||||||
|
if (candidates.Size == 0)
|
||||||
|
{
|
||||||
|
// No match
|
||||||
|
AddLog("No match for \"%.*s\"!\n", (int)(word_end - word_start), word_start);
|
||||||
|
}
|
||||||
|
else if (candidates.Size == 1)
|
||||||
|
{
|
||||||
|
// Single match. Delete the beginning of the word and replace it entirely so we've got nice casing.
|
||||||
|
data->DeleteChars((int)(word_start - data->Buf), (int)(word_end - word_start));
|
||||||
|
data->InsertChars(data->CursorPos, candidates[0]);
|
||||||
|
data->InsertChars(data->CursorPos, " ");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Multiple matches. Complete as much as we can..
|
||||||
|
// So inputing "C"+Tab will complete to "CL" then display "CLEAR" and "CLASSIFY" as matches.
|
||||||
|
int match_len = (int)(word_end - word_start);
|
||||||
|
for (;;)
|
||||||
|
{
|
||||||
|
int c = 0;
|
||||||
|
bool all_candidates_matches = true;
|
||||||
|
for (int i = 0; i < candidates.Size && all_candidates_matches; i++)
|
||||||
|
if (i == 0)
|
||||||
|
c = toupper(candidates[i][match_len]);
|
||||||
|
else if (c == 0 || c != toupper(candidates[i][match_len]))
|
||||||
|
all_candidates_matches = false;
|
||||||
|
if (!all_candidates_matches)
|
||||||
|
break;
|
||||||
|
match_len++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (match_len > 0)
|
||||||
|
{
|
||||||
|
data->DeleteChars((int)(word_start - data->Buf), (int)(word_end - word_start));
|
||||||
|
data->InsertChars(data->CursorPos, candidates[0], candidates[0] + match_len);
|
||||||
|
}
|
||||||
|
|
||||||
|
// List matches
|
||||||
|
AddLog("Possible matches:\n");
|
||||||
|
for (int i = 0; i < candidates.Size; i++)
|
||||||
|
AddLog("- %s\n", candidates[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case ImGuiInputTextFlags_CallbackHistory:
|
||||||
|
{
|
||||||
|
// Example of HISTORY
|
||||||
|
const int prev_history_pos = HistoryPos;
|
||||||
|
if (data->EventKey == ImGuiKey_UpArrow)
|
||||||
|
{
|
||||||
|
if (HistoryPos == -1)
|
||||||
|
HistoryPos = History.Size - 1;
|
||||||
|
else if (HistoryPos > 0)
|
||||||
|
HistoryPos--;
|
||||||
|
}
|
||||||
|
else if (data->EventKey == ImGuiKey_DownArrow)
|
||||||
|
{
|
||||||
|
if (HistoryPos != -1)
|
||||||
|
if (++HistoryPos >= History.Size)
|
||||||
|
HistoryPos = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// A better implementation would preserve the data on the current input line along with cursor position.
|
||||||
|
if (prev_history_pos != HistoryPos)
|
||||||
|
{
|
||||||
|
const char* history_str = (HistoryPos >= 0) ? History[HistoryPos] : "";
|
||||||
|
data->DeleteChars(0, data->BufTextLen);
|
||||||
|
data->InsertChars(0, history_str);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
68
story-editor-v2/src/console_window.h
Normal file
68
story-editor-v2/src/console_window.h
Normal file
|
|
@ -0,0 +1,68 @@
|
||||||
|
#ifndef CONSOLEWINDOW_H
|
||||||
|
#define CONSOLEWINDOW_H
|
||||||
|
|
||||||
|
#include "gui.h"
|
||||||
|
#include <string>
|
||||||
|
#include <mutex>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
|
||||||
|
// Demonstrate creating a simple console window, with scrolling, filtering, completion and history.
|
||||||
|
// For the console example, we are using a more C++ like approach of declaring a class to hold both data and functions.
|
||||||
|
struct ConsoleWindow
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
ConsoleWindow();
|
||||||
|
~ConsoleWindow();
|
||||||
|
|
||||||
|
// Portable helpers
|
||||||
|
static int Stricmp(const char* s1, const char* s2) { int d; while ((d = toupper(*s2) - toupper(*s1)) == 0 && *s1) { s1++; s2++; } return d; }
|
||||||
|
static int Strnicmp(const char* s1, const char* s2, int n) { int d = 0; while (n > 0 && (d = toupper(*s2) - toupper(*s1)) == 0 && *s1) { s1++; s2++; n--; } return d; }
|
||||||
|
static char* Strdup(const char* s) { IM_ASSERT(s); size_t len = strlen(s) + 1; void* buf = malloc(len); IM_ASSERT(buf); return (char*)memcpy(buf, (const void*)s, len); }
|
||||||
|
static void Strtrim(char* s) { char* str_end = s + strlen(s); while (str_end > s && str_end[-1] == ' ') str_end--; *str_end = 0; }
|
||||||
|
|
||||||
|
void ClearLog();
|
||||||
|
|
||||||
|
void AddMessage(const std::string &message) { AddLog("%s", message.c_str()); }
|
||||||
|
|
||||||
|
void Draw(const char* title, bool* p_open);
|
||||||
|
|
||||||
|
void ExecCommand(const char* command_line);
|
||||||
|
|
||||||
|
// In C++11 you'd be better off using lambdas for this sort of forwarding callbacks
|
||||||
|
static int TextEditCallbackStub(ImGuiInputTextCallbackData* data);
|
||||||
|
|
||||||
|
int TextEditCallback(ImGuiInputTextCallbackData* data);
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
void AddLog(const char* fmt, ...) IM_FMTARGS(2)
|
||||||
|
{
|
||||||
|
// FIXME-OPT
|
||||||
|
char buf[1024];
|
||||||
|
va_list args;
|
||||||
|
va_start(args, fmt);
|
||||||
|
vsnprintf(buf, IM_ARRAYSIZE(buf), fmt, args);
|
||||||
|
buf[IM_ARRAYSIZE(buf)-1] = 0;
|
||||||
|
va_end(args);
|
||||||
|
std::scoped_lock<std::mutex> mutex(mLogMutex);
|
||||||
|
Items.push_back(Strdup(buf));
|
||||||
|
if (Items.size() > 100)
|
||||||
|
{
|
||||||
|
Items.erase(Items.begin());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
std::mutex mLogMutex;
|
||||||
|
char InputBuf[256];
|
||||||
|
std::vector<std::string> Items;
|
||||||
|
ImVector<const char*> Commands;
|
||||||
|
ImVector<char*> History;
|
||||||
|
int HistoryPos; // -1: new line, 0..History.Size-1 browsing history.
|
||||||
|
ImGuiTextFilter Filter;
|
||||||
|
bool AutoScroll;
|
||||||
|
bool ScrollToBottom;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // CONSOLEWINDOW_H
|
||||||
37
story-editor-v2/src/emulator_window.cpp
Normal file
37
story-editor-v2/src/emulator_window.cpp
Normal file
|
|
@ -0,0 +1,37 @@
|
||||||
|
#include "emulator_window.h"
|
||||||
|
#include "gui.h"
|
||||||
|
|
||||||
|
EmulatorWindow::EmulatorWindow()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void EmulatorWindow::Initialize() {
|
||||||
|
|
||||||
|
int my_image_width = 0;
|
||||||
|
int my_image_height = 0;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void EmulatorWindow::Draw(const char *title, bool *p_open)
|
||||||
|
{
|
||||||
|
if (!IsVisible())
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ImGui::SetNextWindowSize(ImVec2(626, 744), ImGuiCond_FirstUseEver);
|
||||||
|
if (!ImGui::Begin(title, p_open))
|
||||||
|
{
|
||||||
|
ImGui::End();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ImGui::Image((void*)(intptr_t)my_image_texture, ImVec2(313, 367));
|
||||||
|
|
||||||
|
float sz = ImGui::GetTextLineHeight();
|
||||||
|
ImVec2 p = ImGui::GetCursorScreenPos();
|
||||||
|
ImGui::GetWindowDrawList()->AddRectFilled(p, ImVec2(p.x + sz, p.y + sz), ImGui::GetColorU32(ImVec4(1.0, 1.0, 1.0, 1.0)));
|
||||||
|
|
||||||
|
ImGui::End();
|
||||||
|
}
|
||||||
16
story-editor-v2/src/emulator_window.h
Normal file
16
story-editor-v2/src/emulator_window.h
Normal file
|
|
@ -0,0 +1,16 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "window_base.h"
|
||||||
|
|
||||||
|
class EmulatorWindow : public WindowBase
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
EmulatorWindow();
|
||||||
|
|
||||||
|
void Initialize();
|
||||||
|
void Draw(const char* title, bool* p_open);
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
440
story-editor-v2/src/gui.cpp
Normal file
440
story-editor-v2/src/gui.cpp
Normal file
|
|
@ -0,0 +1,440 @@
|
||||||
|
|
||||||
|
/*
|
||||||
|
Define the NOMINMAX symbol at the top of your source, before you include any headers.
|
||||||
|
Visual C++ defines min and max as macros somewhere in windows.h, and they interfere with
|
||||||
|
your use of the corresponding standard functions.
|
||||||
|
*/
|
||||||
|
#define NOMINMAX
|
||||||
|
#include "gui.h"
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
|
||||||
|
#include "imgui_impl_sdl3.h"
|
||||||
|
#include "imgui_impl_sdlrenderer3.h"
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <SDL3/SDL.h>
|
||||||
|
#if defined(IMGUI_IMPL_OPENGL_ES2)
|
||||||
|
#include <SDL3/SDL_opengles2.h>
|
||||||
|
#else
|
||||||
|
#include <SDL3/SDL_opengl.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "IconsMaterialDesignIcons.h"
|
||||||
|
#include "IconsFontAwesome5_c.h"
|
||||||
|
|
||||||
|
static void glfw_error_callback(int error, const char* description)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "GLFW Error %d: %s\n", error, description);
|
||||||
|
}
|
||||||
|
|
||||||
|
static SDL_Window* window{nullptr};
|
||||||
|
static SDL_Renderer* renderer{nullptr};
|
||||||
|
|
||||||
|
|
||||||
|
#include "stb_image.h"
|
||||||
|
|
||||||
|
|
||||||
|
// Simple helper function to load an image into a OpenGL texture with common settings
|
||||||
|
bool LoadTextureFromFile(const char* filename, Gui::Image &img)
|
||||||
|
{
|
||||||
|
int channels;
|
||||||
|
unsigned char* data = stbi_load(filename, &img.w, &img.h, &channels, 0);
|
||||||
|
|
||||||
|
if (data == nullptr) {
|
||||||
|
fprintf(stderr, "Failed to load image: %s\n", stbi_failure_reason());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
SDL_Surface* surface = SDL_CreateSurfaceFrom((void*)data, img.w, img.h, 4 * img.w, SDL_PIXELFORMAT_RGBA8888);
|
||||||
|
|
||||||
|
if (surface == nullptr) {
|
||||||
|
fprintf(stderr, "Failed to create SDL surface: %s\n", SDL_GetError());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
img.texture = SDL_CreateTextureFromSurface(renderer, surface);
|
||||||
|
|
||||||
|
if (img.texture == nullptr) {
|
||||||
|
fprintf(stderr, "Failed to create SDL texture: %s\n", SDL_GetError());
|
||||||
|
}
|
||||||
|
|
||||||
|
SDL_DestroySurface(surface);
|
||||||
|
stbi_image_free(data);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
#define MANOLAB_VERSION "1.0"
|
||||||
|
|
||||||
|
Gui::Gui()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool Gui::Initialize()
|
||||||
|
{
|
||||||
|
// Setup SDL
|
||||||
|
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_GAMEPAD) != 0)
|
||||||
|
{
|
||||||
|
printf("Error: SDL_Init(): %s\n", SDL_GetError());
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Enable native IME.
|
||||||
|
SDL_SetHint(SDL_HINT_IME_SHOW_UI, "1");
|
||||||
|
|
||||||
|
// Create window with SDL_Renderer graphics context
|
||||||
|
SDL_WindowFlags window_flags = (SDL_WindowFlags)(SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE | SDL_WINDOW_HIDDEN);
|
||||||
|
window = SDL_CreateWindow("Dear ImGui SDL3+SDL_Renderer example", 1280, 720, window_flags);
|
||||||
|
if (window == nullptr)
|
||||||
|
{
|
||||||
|
printf("Error: SDL_CreateWindow(): %s\n", SDL_GetError());
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
renderer = SDL_CreateRenderer(window, NULL, SDL_RENDERER_PRESENTVSYNC | SDL_RENDERER_ACCELERATED);
|
||||||
|
if (renderer == nullptr)
|
||||||
|
{
|
||||||
|
SDL_Log("Error: SDL_CreateRenderer(): %s\n", SDL_GetError());
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
SDL_SetWindowPosition(window, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED);
|
||||||
|
SDL_ShowWindow(window);
|
||||||
|
|
||||||
|
|
||||||
|
// Setup Dear ImGui context
|
||||||
|
IMGUI_CHECKVERSION();
|
||||||
|
ImGui::CreateContext();
|
||||||
|
ImGuiIO& io = ImGui::GetIO(); (void)io;
|
||||||
|
io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; // Enable Keyboard Controls
|
||||||
|
io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad; // Enable Gamepad Controls
|
||||||
|
io.ConfigFlags |= ImGuiConfigFlags_DockingEnable;
|
||||||
|
|
||||||
|
|
||||||
|
io.Fonts->AddFontFromFileTTF( "fonts/roboto.ttf", 20);
|
||||||
|
|
||||||
|
{
|
||||||
|
ImFontConfig config;
|
||||||
|
config.MergeMode = true; // ATTENTION, MERGE AVEC LA FONT PRECEDENTE !!
|
||||||
|
// config.GlyphMinAdvanceX = 20.0f; // Use if you want to make the icon monospaced
|
||||||
|
// config.GlyphOffset.y += 1.0;
|
||||||
|
static const ImWchar icon_ranges[] = { ICON_MIN_FA, ICON_MAX_FA, 0 };
|
||||||
|
io.Fonts->AddFontFromFileTTF("fonts/fa-solid-900.ttf", 16.0f, &config, icon_ranges);
|
||||||
|
|
||||||
|
io.Fonts->Build();
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
ImFontConfig config;
|
||||||
|
config.MergeMode = true; // ATTENTION, MERGE AVEC LA FONT PRECEDENTE !!
|
||||||
|
|
||||||
|
static const ImWchar icon_ranges_mdi[] = { ICON_MIN_MDI, ICON_MAX_MDI, 0 };
|
||||||
|
io.Fonts->AddFontFromFileTTF("fonts/materialdesignicons-webfont.ttf", 16.0f, &config, icon_ranges_mdi);
|
||||||
|
|
||||||
|
io.Fonts->Build();
|
||||||
|
}
|
||||||
|
// Setup Dear ImGui style
|
||||||
|
ImGui::StyleColorsDark();
|
||||||
|
//ImGui::StyleColorsLight();
|
||||||
|
|
||||||
|
// Setup Platform/Renderer backends
|
||||||
|
ImGui_ImplSDL3_InitForSDLRenderer(window, renderer);
|
||||||
|
ImGui_ImplSDLRenderer3_Init(renderer);
|
||||||
|
|
||||||
|
// Load Fonts
|
||||||
|
// - If no fonts are loaded, dear imgui will use the default font. You can also load multiple fonts and use ImGui::PushFont()/PopFont() to select them.
|
||||||
|
// - AddFontFromFileTTF() will return the ImFont* so you can store it if you need to select the font among multiple.
|
||||||
|
// - If the file cannot be loaded, the function will return a nullptr. Please handle those errors in your application (e.g. use an assertion, or display an error and quit).
|
||||||
|
// - The fonts will be rasterized at a given size (w/ oversampling) and stored into a texture when calling ImFontAtlas::Build()/GetTexDataAsXXXX(), which ImGui_ImplXXXX_NewFrame below will call.
|
||||||
|
// - Use '#define IMGUI_ENABLE_FREETYPE' in your imconfig file to use Freetype for higher quality font rendering.
|
||||||
|
// - Read 'docs/FONTS.md' for more instructions and details.
|
||||||
|
// - Remember that in C/C++ if you want to include a backslash \ in a string literal you need to write a double backslash \\ !
|
||||||
|
// - Our Emscripten build process allows embedding fonts to be accessible at runtime from the "fonts/" folder. See Makefile.emscripten for details.
|
||||||
|
//io.Fonts->AddFontDefault();
|
||||||
|
//io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\segoeui.ttf", 18.0f);
|
||||||
|
//io.Fonts->AddFontFromFileTTF("../../misc/fonts/DroidSans.ttf", 16.0f);
|
||||||
|
//io.Fonts->AddFontFromFileTTF("../../misc/fonts/Roboto-Medium.ttf", 16.0f);
|
||||||
|
//io.Fonts->AddFontFromFileTTF("../../misc/fonts/Cousine-Regular.ttf", 15.0f);
|
||||||
|
//ImFont* font = io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\ArialUni.ttf", 18.0f, nullptr, io.Fonts->GetGlyphRangesJapanese());
|
||||||
|
//IM_ASSERT(font != nullptr);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool Gui::PollEvent()
|
||||||
|
{
|
||||||
|
bool done = false;
|
||||||
|
SDL_Event event;
|
||||||
|
while (SDL_PollEvent(&event))
|
||||||
|
{
|
||||||
|
ImGui_ImplSDL3_ProcessEvent(&event);
|
||||||
|
if (event.type == SDL_EVENT_QUIT)
|
||||||
|
done = true;
|
||||||
|
if (event.type == SDL_EVENT_WINDOW_CLOSE_REQUESTED && event.window.windowID == SDL_GetWindowID(window))
|
||||||
|
done = true;
|
||||||
|
}
|
||||||
|
return done;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void Gui::StartFrame()
|
||||||
|
{
|
||||||
|
// Start the Dear ImGui frame
|
||||||
|
ImGui_ImplSDLRenderer3_NewFrame();
|
||||||
|
ImGui_ImplSDL3_NewFrame();
|
||||||
|
ImGui::NewFrame();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Gui::EndFrame()
|
||||||
|
{
|
||||||
|
static ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f);
|
||||||
|
// Rendering
|
||||||
|
// Rendering
|
||||||
|
ImGui::Render();
|
||||||
|
//SDL_RenderSetScale(renderer, io.DisplayFramebufferScale.x, io.DisplayFramebufferScale.y);
|
||||||
|
SDL_SetRenderDrawColor(renderer, (Uint8)(clear_color.x * 255), (Uint8)(clear_color.y * 255), (Uint8)(clear_color.z * 255), (Uint8)(clear_color.w * 255));
|
||||||
|
SDL_RenderClear(renderer);
|
||||||
|
ImGui_ImplSDLRenderer3_RenderDrawData(ImGui::GetDrawData());
|
||||||
|
SDL_RenderPresent(renderer);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Gui::Destroy()
|
||||||
|
{
|
||||||
|
// Cleanup
|
||||||
|
ImGui_ImplSDLRenderer3_Shutdown();
|
||||||
|
ImGui_ImplSDL3_Shutdown();
|
||||||
|
ImGui::DestroyContext();
|
||||||
|
|
||||||
|
SDL_DestroyRenderer(renderer);
|
||||||
|
SDL_DestroyWindow(window);
|
||||||
|
SDL_Quit();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Gui::LoadRawImage(const std::string &filename, Image &image)
|
||||||
|
{
|
||||||
|
bool success = true;
|
||||||
|
|
||||||
|
LoadTextureFromFile(filename.c_str(), image);
|
||||||
|
|
||||||
|
return success;
|
||||||
|
}
|
||||||
|
|
||||||
|
Gui::Size Gui::GetWindowSize()
|
||||||
|
{
|
||||||
|
Size s;
|
||||||
|
SDL_GetWindowSize(window, &s.w, &s.h);
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Gui::ApplyTheme()
|
||||||
|
{
|
||||||
|
ImVec4* colors = ImGui::GetStyle().Colors;
|
||||||
|
ImGuiStyle & style = ImGui::GetStyle();
|
||||||
|
|
||||||
|
|
||||||
|
colors[ImGuiCol_Text] = ImVec4(1.00f, 1.00f, 1.00f, 1.00f);
|
||||||
|
colors[ImGuiCol_TextDisabled] = ImVec4(0.50f, 0.50f, 0.50f, 1.00f);
|
||||||
|
colors[ImGuiCol_WindowBg] = ImVec4(0.06f, 0.06f, 0.06f, 0.94f);
|
||||||
|
colors[ImGuiCol_ChildBg] = ImVec4(0.00f, 0.00f, 0.00f, 0.00f);
|
||||||
|
colors[ImGuiCol_PopupBg] = ImVec4(0.08f, 0.08f, 0.08f, 0.94f);
|
||||||
|
colors[ImGuiCol_Border] = ImVec4(0.43f, 0.43f, 0.50f, 0.50f);
|
||||||
|
colors[ImGuiCol_BorderShadow] = ImVec4(0.00f, 0.00f, 0.00f, 0.00f);
|
||||||
|
colors[ImGuiCol_FrameBg] = ImVec4(0.44f, 0.44f, 0.44f, 0.60f);
|
||||||
|
colors[ImGuiCol_FrameBgHovered] = ImVec4(0.57f, 0.57f, 0.57f, 0.70f);
|
||||||
|
colors[ImGuiCol_FrameBgActive] = ImVec4(0.76f, 0.76f, 0.76f, 0.80f);
|
||||||
|
colors[ImGuiCol_TitleBg] = ImVec4(0.04f, 0.04f, 0.04f, 1.00f);
|
||||||
|
colors[ImGuiCol_TitleBgActive] = ImVec4(0.16f, 0.16f, 0.16f, 1.00f);
|
||||||
|
colors[ImGuiCol_TitleBgCollapsed] = ImVec4(0.00f, 0.00f, 0.00f, 0.60f);
|
||||||
|
colors[ImGuiCol_MenuBarBg] = ImVec4(0.14f, 0.14f, 0.14f, 1.00f);
|
||||||
|
colors[ImGuiCol_ScrollbarBg] = ImVec4(0.02f, 0.02f, 0.02f, 0.53f);
|
||||||
|
colors[ImGuiCol_ScrollbarGrab] = ImVec4(0.31f, 0.31f, 0.31f, 1.00f);
|
||||||
|
colors[ImGuiCol_ScrollbarGrabHovered] = ImVec4(0.41f, 0.41f, 0.41f, 1.00f);
|
||||||
|
colors[ImGuiCol_ScrollbarGrabActive] = ImVec4(0.51f, 0.51f, 0.51f, 1.00f);
|
||||||
|
colors[ImGuiCol_CheckMark] = ImVec4(0.13f, 0.75f, 0.55f, 0.80f);
|
||||||
|
colors[ImGuiCol_SliderGrab] = ImVec4(0.13f, 0.75f, 0.75f, 0.80f);
|
||||||
|
colors[ImGuiCol_SliderGrabActive] = ImVec4(0.13f, 0.75f, 1.00f, 0.80f);
|
||||||
|
colors[ImGuiCol_Button] = ImVec4(0.13f, 0.75f, 0.55f, 0.40f);
|
||||||
|
colors[ImGuiCol_ButtonHovered] = ImVec4(0.13f, 0.75f, 0.75f, 0.60f);
|
||||||
|
colors[ImGuiCol_ButtonActive] = ImVec4(0.13f, 0.75f, 1.00f, 0.80f);
|
||||||
|
colors[ImGuiCol_Header] = ImVec4(0.13f, 0.75f, 0.55f, 0.40f);
|
||||||
|
colors[ImGuiCol_HeaderHovered] = ImVec4(0.13f, 0.75f, 0.75f, 0.60f);
|
||||||
|
colors[ImGuiCol_HeaderActive] = ImVec4(0.13f, 0.75f, 1.00f, 0.80f);
|
||||||
|
colors[ImGuiCol_Separator] = ImVec4(0.13f, 0.75f, 0.55f, 0.40f);
|
||||||
|
colors[ImGuiCol_SeparatorHovered] = ImVec4(0.13f, 0.75f, 0.75f, 0.60f);
|
||||||
|
colors[ImGuiCol_SeparatorActive] = ImVec4(0.13f, 0.75f, 1.00f, 0.80f);
|
||||||
|
colors[ImGuiCol_ResizeGrip] = ImVec4(0.13f, 0.75f, 0.55f, 0.40f);
|
||||||
|
colors[ImGuiCol_ResizeGripHovered] = ImVec4(0.13f, 0.75f, 0.75f, 0.60f);
|
||||||
|
colors[ImGuiCol_ResizeGripActive] = ImVec4(0.13f, 0.75f, 1.00f, 0.80f);
|
||||||
|
colors[ImGuiCol_Tab] = ImVec4(0.13f, 0.75f, 0.55f, 0.80f);
|
||||||
|
colors[ImGuiCol_TabHovered] = ImVec4(0.13f, 0.75f, 0.75f, 0.80f);
|
||||||
|
colors[ImGuiCol_TabActive] = ImVec4(0.13f, 0.75f, 1.00f, 0.80f);
|
||||||
|
colors[ImGuiCol_TabUnfocused] = ImVec4(0.18f, 0.18f, 0.18f, 1.00f);
|
||||||
|
colors[ImGuiCol_TabUnfocusedActive] = ImVec4(0.36f, 0.36f, 0.36f, 0.54f);
|
||||||
|
colors[ImGuiCol_PlotLines] = ImVec4(0.61f, 0.61f, 0.61f, 1.00f);
|
||||||
|
colors[ImGuiCol_PlotLinesHovered] = ImVec4(1.00f, 0.43f, 0.35f, 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] = ImVec4(0.19f, 0.19f, 0.20f, 1.00f);
|
||||||
|
colors[ImGuiCol_TableBorderStrong] = ImVec4(0.31f, 0.31f, 0.35f, 1.00f);
|
||||||
|
colors[ImGuiCol_TableBorderLight] = ImVec4(0.23f, 0.23f, 0.25f, 1.00f);
|
||||||
|
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.26f, 0.59f, 0.98f, 0.35f);
|
||||||
|
colors[ImGuiCol_DragDropTarget] = ImVec4(1.00f, 1.00f, 0.00f, 0.90f);
|
||||||
|
colors[ImGuiCol_NavHighlight] = ImVec4(0.26f, 0.59f, 0.98f, 1.00f);
|
||||||
|
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.80f, 0.80f, 0.80f, 0.35f);
|
||||||
|
|
||||||
|
|
||||||
|
style.ChildRounding = 4.0f;
|
||||||
|
style.FrameBorderSize = 1.0f;
|
||||||
|
style.FrameRounding = 2.0f;
|
||||||
|
style.GrabMinSize = 7.0f;
|
||||||
|
style.PopupRounding = 2.0f;
|
||||||
|
style.ScrollbarRounding = 12.0f;
|
||||||
|
style.ScrollbarSize = 13.0f;
|
||||||
|
style.TabBorderSize = 1.0f;
|
||||||
|
style.TabRounding = 0.0f;
|
||||||
|
style.WindowRounding = 4.0f;
|
||||||
|
|
||||||
|
/*
|
||||||
|
/// 0 = FLAT APPEARENCE
|
||||||
|
/// 1 = MORE "3D" LOOK
|
||||||
|
int is3D = 1;
|
||||||
|
|
||||||
|
colors[ImGuiCol_Text] = ImVec4(1.00f, 1.00f, 1.00f, 1.00f);
|
||||||
|
colors[ImGuiCol_TextDisabled] = ImVec4(0.40f, 0.40f, 0.40f, 1.00f);
|
||||||
|
colors[ImGuiCol_ChildBg] = ImVec4(0.25f, 0.25f, 0.25f, 1.00f);
|
||||||
|
colors[ImGuiCol_WindowBg] = ImVec4(0.25f, 0.25f, 0.25f, 1.00f);
|
||||||
|
colors[ImGuiCol_PopupBg] = ImVec4(0.25f, 0.25f, 0.25f, 1.00f);
|
||||||
|
colors[ImGuiCol_Border] = ImVec4(0.12f, 0.12f, 0.12f, 0.71f);
|
||||||
|
colors[ImGuiCol_BorderShadow] = ImVec4(1.00f, 1.00f, 1.00f, 0.06f);
|
||||||
|
colors[ImGuiCol_FrameBg] = ImVec4(0.42f, 0.42f, 0.42f, 0.54f);
|
||||||
|
colors[ImGuiCol_FrameBgHovered] = ImVec4(0.42f, 0.42f, 0.42f, 0.40f);
|
||||||
|
colors[ImGuiCol_FrameBgActive] = ImVec4(0.56f, 0.56f, 0.56f, 0.67f);
|
||||||
|
colors[ImGuiCol_TitleBg] = ImVec4(0.19f, 0.19f, 0.19f, 1.00f);
|
||||||
|
colors[ImGuiCol_TitleBgActive] = ImVec4(0.22f, 0.22f, 0.22f, 1.00f);
|
||||||
|
colors[ImGuiCol_TitleBgCollapsed] = ImVec4(0.17f, 0.17f, 0.17f, 0.90f);
|
||||||
|
colors[ImGuiCol_MenuBarBg] = ImVec4(0.335f, 0.335f, 0.335f, 1.000f);
|
||||||
|
colors[ImGuiCol_ScrollbarBg] = ImVec4(0.24f, 0.24f, 0.24f, 0.53f);
|
||||||
|
colors[ImGuiCol_ScrollbarGrab] = ImVec4(0.41f, 0.41f, 0.41f, 1.00f);
|
||||||
|
colors[ImGuiCol_ScrollbarGrabHovered] = ImVec4(0.52f, 0.52f, 0.52f, 1.00f);
|
||||||
|
colors[ImGuiCol_ScrollbarGrabActive] = ImVec4(0.76f, 0.76f, 0.76f, 1.00f);
|
||||||
|
colors[ImGuiCol_CheckMark] = ImVec4(0.65f, 0.65f, 0.65f, 1.00f);
|
||||||
|
colors[ImGuiCol_SliderGrab] = ImVec4(0.52f, 0.52f, 0.52f, 1.00f);
|
||||||
|
colors[ImGuiCol_SliderGrabActive] = ImVec4(0.64f, 0.64f, 0.64f, 1.00f);
|
||||||
|
colors[ImGuiCol_Button] = ImVec4(0.54f, 0.54f, 0.54f, 0.35f);
|
||||||
|
colors[ImGuiCol_ButtonHovered] = ImVec4(0.52f, 0.52f, 0.52f, 0.59f);
|
||||||
|
colors[ImGuiCol_ButtonActive] = ImVec4(0.76f, 0.76f, 0.76f, 1.00f);
|
||||||
|
colors[ImGuiCol_Header] = ImVec4(0.38f, 0.38f, 0.38f, 1.00f);
|
||||||
|
colors[ImGuiCol_HeaderHovered] = ImVec4(0.47f, 0.47f, 0.47f, 1.00f);
|
||||||
|
colors[ImGuiCol_HeaderActive] = ImVec4(0.76f, 0.76f, 0.76f, 0.77f);
|
||||||
|
colors[ImGuiCol_Separator] = ImVec4(0.000f, 0.000f, 0.000f, 0.137f);
|
||||||
|
colors[ImGuiCol_SeparatorHovered] = ImVec4(0.700f, 0.671f, 0.600f, 0.290f);
|
||||||
|
colors[ImGuiCol_SeparatorActive] = ImVec4(0.702f, 0.671f, 0.600f, 0.674f);
|
||||||
|
colors[ImGuiCol_ResizeGrip] = ImVec4(0.26f, 0.59f, 0.98f, 0.25f);
|
||||||
|
colors[ImGuiCol_ResizeGripHovered] = ImVec4(0.26f, 0.59f, 0.98f, 0.67f);
|
||||||
|
colors[ImGuiCol_ResizeGripActive] = ImVec4(0.26f, 0.59f, 0.98f, 0.95f);
|
||||||
|
colors[ImGuiCol_PlotLines] = ImVec4(0.61f, 0.61f, 0.61f, 1.00f);
|
||||||
|
colors[ImGuiCol_PlotLinesHovered] = ImVec4(1.00f, 0.43f, 0.35f, 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_TextSelectedBg] = ImVec4(0.73f, 0.73f, 0.73f, 0.35f);
|
||||||
|
colors[ImGuiCol_ModalWindowDimBg] = ImVec4(0.80f, 0.80f, 0.80f, 0.35f);
|
||||||
|
colors[ImGuiCol_DragDropTarget] = ImVec4(1.00f, 1.00f, 0.00f, 0.90f);
|
||||||
|
colors[ImGuiCol_NavHighlight] = ImVec4(0.26f, 0.59f, 0.98f, 1.00f);
|
||||||
|
colors[ImGuiCol_NavWindowingHighlight] = ImVec4(1.00f, 1.00f, 1.00f, 0.70f);
|
||||||
|
colors[ImGuiCol_NavWindowingDimBg] = ImVec4(0.80f, 0.80f, 0.80f, 0.20f);
|
||||||
|
|
||||||
|
style.PopupRounding = 3;
|
||||||
|
|
||||||
|
style.WindowPadding = ImVec2(4, 4);
|
||||||
|
style.FramePadding = ImVec2(6, 4);
|
||||||
|
style.ItemSpacing = ImVec2(6, 2);
|
||||||
|
|
||||||
|
style.ScrollbarSize = 18;
|
||||||
|
|
||||||
|
style.WindowBorderSize = 1;
|
||||||
|
style.ChildBorderSize = 1;
|
||||||
|
style.PopupBorderSize = 1;
|
||||||
|
style.FrameBorderSize = is3D;
|
||||||
|
|
||||||
|
style.WindowRounding = 3;
|
||||||
|
style.ChildRounding = 3;
|
||||||
|
style.FrameRounding = 3;
|
||||||
|
style.ScrollbarRounding = 2;
|
||||||
|
style.GrabRounding = 3;
|
||||||
|
|
||||||
|
|
||||||
|
style.TabBorderSize = is3D;
|
||||||
|
style.TabRounding = 3;
|
||||||
|
|
||||||
|
colors[ImGuiCol_DockingEmptyBg] = ImVec4(0.38f, 0.38f, 0.38f, 1.00f);
|
||||||
|
colors[ImGuiCol_Tab] = ImVec4(0.25f, 0.25f, 0.25f, 1.00f);
|
||||||
|
colors[ImGuiCol_TabHovered] = ImVec4(0.40f, 0.40f, 0.40f, 1.00f);
|
||||||
|
colors[ImGuiCol_TabActive] = ImVec4(0.33f, 0.33f, 0.33f, 1.00f);
|
||||||
|
colors[ImGuiCol_TabUnfocused] = ImVec4(0.25f, 0.25f, 0.25f, 1.00f);
|
||||||
|
colors[ImGuiCol_TabUnfocusedActive] = ImVec4(0.33f, 0.33f, 0.33f, 1.00f);
|
||||||
|
colors[ImGuiCol_DockingPreview] = ImVec4(0.85f, 0.85f, 0.85f, 0.28f);
|
||||||
|
|
||||||
|
if (ImGui::GetIO().ConfigFlags & ImGuiConfigFlags_ViewportsEnable)
|
||||||
|
{
|
||||||
|
style.WindowRounding = 0.0f;
|
||||||
|
style.Colors[ImGuiCol_WindowBg].w = 1.0f;
|
||||||
|
}
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#include "imgui_internal.h"
|
||||||
|
namespace ImGui {
|
||||||
|
void LoadingIndicatorCircle(const char* label, const float indicator_radius,
|
||||||
|
const ImVec4& main_color, const ImVec4& backdrop_color,
|
||||||
|
const int circle_count, const float speed) {
|
||||||
|
ImGuiWindow* window = GetCurrentWindow();
|
||||||
|
if (window->SkipItems) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ImGuiContext& g = *GImGui;
|
||||||
|
const ImGuiID id = window->GetID(label);
|
||||||
|
|
||||||
|
const ImVec2 pos = window->DC.CursorPos;
|
||||||
|
const float circle_radius = indicator_radius / 10.0f;
|
||||||
|
const ImRect bb(pos, ImVec2(pos.x + indicator_radius * 2.0f,
|
||||||
|
pos.y + indicator_radius * 2.0f));
|
||||||
|
ItemSize(bb, GetStyle().FramePadding.y);
|
||||||
|
if (!ItemAdd(bb, id)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const float t = g.Time;
|
||||||
|
const auto degree_offset = 2.0f * IM_PI / circle_count;
|
||||||
|
for (int i = 0; i < circle_count; ++i) {
|
||||||
|
const auto x = indicator_radius * std::sin(degree_offset * i);
|
||||||
|
const auto y = indicator_radius * std::cos(degree_offset * i);
|
||||||
|
const auto growth = std::max(0.0f, std::sin(t * speed - i * degree_offset));
|
||||||
|
ImVec4 color;
|
||||||
|
color.x = main_color.x * growth + backdrop_color.x * (1.0f - growth);
|
||||||
|
color.y = main_color.y * growth + backdrop_color.y * (1.0f - growth);
|
||||||
|
color.z = main_color.z * growth + backdrop_color.z * (1.0f - growth);
|
||||||
|
color.w = 1.0f;
|
||||||
|
window->DrawList->AddCircleFilled(ImVec2(pos.x + indicator_radius + x,
|
||||||
|
pos.y + indicator_radius - y),
|
||||||
|
circle_radius + growth * circle_radius,
|
||||||
|
GetColorU32(color));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} // namespace ImGui
|
||||||
|
|
||||||
|
Gui::Image::Image()
|
||||||
|
{
|
||||||
|
texture = nullptr;
|
||||||
|
w = 0;
|
||||||
|
h = 0;
|
||||||
|
}
|
||||||
53
story-editor-v2/src/gui.h
Normal file
53
story-editor-v2/src/gui.h
Normal file
|
|
@ -0,0 +1,53 @@
|
||||||
|
#ifndef GUI_H
|
||||||
|
#define GUI_H
|
||||||
|
|
||||||
|
#define IMGUI_DEFINE_MATH_OPERATORS
|
||||||
|
#include "imgui.h"
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
class Gui
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
Gui();
|
||||||
|
|
||||||
|
struct Texture;
|
||||||
|
|
||||||
|
struct Image {
|
||||||
|
void *texture; // Platform specific
|
||||||
|
int w;
|
||||||
|
int h;
|
||||||
|
|
||||||
|
bool valid() const {
|
||||||
|
return (w && h);
|
||||||
|
}
|
||||||
|
|
||||||
|
Image();
|
||||||
|
};
|
||||||
|
|
||||||
|
struct Size {
|
||||||
|
int w;
|
||||||
|
int h;
|
||||||
|
};
|
||||||
|
|
||||||
|
void ApplyTheme();
|
||||||
|
bool Initialize();
|
||||||
|
bool PollEvent();
|
||||||
|
void StartFrame();
|
||||||
|
void EndFrame();
|
||||||
|
void Destroy();
|
||||||
|
|
||||||
|
static bool LoadRawImage(const std::string &filename, Image &image);
|
||||||
|
static Size GetWindowSize();
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
namespace ImGui {
|
||||||
|
void LoadingIndicatorCircle(const char* label, const float indicator_radius,
|
||||||
|
const ImVec4& main_color, const ImVec4& backdrop_color,
|
||||||
|
const int circle_count, const float speed);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // GUI_H
|
||||||
|
|
@ -98,7 +98,7 @@ void MainWindow::Initialize()
|
||||||
// gui.ApplyTheme();
|
// gui.ApplyTheme();
|
||||||
|
|
||||||
editor.Initialize();
|
editor.Initialize();
|
||||||
imgWindow.Initialize();
|
m_emulatorWindow.Initialize();
|
||||||
m_nodeEditorWindow.Initialize();
|
m_nodeEditorWindow.Initialize();
|
||||||
|
|
||||||
LoadParams();
|
LoadParams();
|
||||||
|
|
@ -245,7 +245,7 @@ void MainWindow::Loop()
|
||||||
SetupMainMenuBar();
|
SetupMainMenuBar();
|
||||||
|
|
||||||
console.Draw("Console", nullptr);
|
console.Draw("Console", nullptr);
|
||||||
imgWindow.Draw("ImageWindow", nullptr);
|
m_emulatorWindow.Draw("Emulator", nullptr);
|
||||||
editor.Draw("Code Editor", nullptr);
|
editor.Draw("Code Editor", nullptr);
|
||||||
|
|
||||||
m_resourcesWindow.Draw("Resources", nullptr);
|
m_resourcesWindow.Draw("Resources", nullptr);
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,11 @@
|
||||||
#ifndef MAINWINDOW_H
|
#ifndef MAINWINDOW_H
|
||||||
#define MAINWINDOW_H
|
#define MAINWINDOW_H
|
||||||
|
|
||||||
#include "Gui.h"
|
#include "gui.h"
|
||||||
#include "ConsoleWindow.h"
|
#include "console_window.h"
|
||||||
#include "CodeEditor.h"
|
#include "code_editor.h"
|
||||||
|
|
||||||
#include "ImageWindow.h"
|
#include "emulator_window.h"
|
||||||
#include "resources_window.h"
|
#include "resources_window.h"
|
||||||
#include "node_editor_window.h"
|
#include "node_editor_window.h"
|
||||||
|
|
||||||
|
|
@ -94,7 +94,7 @@ private:
|
||||||
|
|
||||||
|
|
||||||
Gui gui;
|
Gui gui;
|
||||||
ImageWindow imgWindow;
|
EmulatorWindow m_emulatorWindow;
|
||||||
ConsoleWindow console;
|
ConsoleWindow console;
|
||||||
CodeEditor editor;
|
CodeEditor editor;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
#include <set>
|
#include <set>
|
||||||
|
|
||||||
#include "base_node.h"
|
#include "base_node.h"
|
||||||
#include "Gui.h"
|
#include "gui.h"
|
||||||
#include <imgui_node_editor.h>
|
#include <imgui_node_editor.h>
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@
|
||||||
#include "IconsFontAwesome5_c.h"
|
#include "IconsFontAwesome5_c.h"
|
||||||
|
|
||||||
#include "media_node.h"
|
#include "media_node.h"
|
||||||
#include "Gui.h"
|
#include "gui.h"
|
||||||
|
|
||||||
|
|
||||||
NodeEditorWindow::NodeEditorWindow()
|
NodeEditorWindow::NodeEditorWindow()
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
#define MEDIA_CONVERTER_H
|
#define MEDIA_CONVERTER_H
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <cstdint>
|
||||||
class MediaConverter
|
class MediaConverter
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue