-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
237 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[submodule "demo/zep"] | ||
path = demo/zep | ||
url = https://github.com/cmaughan/zep |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
cd build | ||
cmake --build . --config Debug | ||
cd .. |
1 change: 1 addition & 0 deletions
1
source/cmake/config_app.h.cmake → demo/cmake/config_app.h.cmake
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
#cmakedefine APPLICATION_NAME "${APPLICATION_NAME}" | ||
#cmakedefine APPLICATION_VERSION "${APPLICATION_VERSION}" | ||
#cmakedefine APP_ROOT "${APP_ROOT}" | ||
#cmakedefine ZEP_SINGLE_HEADER "${ZEP_SINGLE_HEADER}" | ||
|
||
|
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#pragma once | ||
|
||
#include <zep.h> | ||
|
||
// Helpers to create zep editor | ||
Zep::ZepEditor& zep_get_editor(); | ||
void zep_init(const Zep::NVec2f& pixelScale); | ||
void zep_update(); | ||
void zep_show(const Zep::NVec2i& displaySize); | ||
void zep_destroy(); | ||
void zep_load(const Zep::ZepPath& file); |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,150 @@ | ||
|
||
#if ZEP_SINGLE_HEADER == 1 | ||
#define ZEP_SINGLE_HEADER_BUILD | ||
#endif | ||
|
||
#include "editor.h" | ||
#include <functional> | ||
#include <filesystem> | ||
#include "config_app.h" | ||
|
||
namespace fs = std::filesystem; | ||
|
||
using namespace Zep; | ||
|
||
using cmdFunc = std::function<void(const std::vector<std::string>&)>; | ||
class ZepCmd : public ZepExCommand | ||
{ | ||
public: | ||
ZepCmd(ZepEditor& editor, const std::string name, cmdFunc fn) | ||
: ZepExCommand(editor) | ||
, m_name(name) | ||
, m_func(fn) | ||
{ | ||
} | ||
|
||
virtual void Run(const std::vector<std::string>& args) override | ||
{ | ||
m_func(args); | ||
} | ||
|
||
virtual const char* ExCommandName() const override | ||
{ | ||
return m_name.c_str(); | ||
} | ||
|
||
private: | ||
std::string m_name; | ||
cmdFunc m_func; | ||
}; | ||
|
||
struct ZepWrapper : public Zep::IZepComponent | ||
{ | ||
ZepWrapper(const fs::path& root_path, const Zep::NVec2f& pixelScale, std::function<void(std::shared_ptr<Zep::ZepMessage>)> fnCommandCB) | ||
: zepEditor(Zep::ZepPath(root_path.string()), pixelScale) | ||
, Callback(fnCommandCB) | ||
{ | ||
zepEditor.RegisterCallback(this); | ||
|
||
} | ||
|
||
virtual Zep::ZepEditor& GetEditor() const override | ||
{ | ||
return (Zep::ZepEditor&)zepEditor; | ||
} | ||
|
||
virtual void Notify(std::shared_ptr<Zep::ZepMessage> message) override | ||
{ | ||
Callback(message); | ||
|
||
return; | ||
} | ||
|
||
virtual void HandleInput() | ||
{ | ||
zepEditor.HandleInput(); | ||
} | ||
|
||
Zep::ZepEditor_ImGui zepEditor; | ||
std::function<void(std::shared_ptr<Zep::ZepMessage>)> Callback; | ||
}; | ||
|
||
std::shared_ptr<ZepWrapper> spZep; | ||
|
||
void zep_init(const Zep::NVec2f& pixelScale) | ||
{ | ||
// Initialize the editor and watch for changes | ||
spZep = std::make_shared<ZepWrapper>(APP_ROOT, Zep::NVec2f(pixelScale.x, pixelScale.y), [](std::shared_ptr<ZepMessage> spMessage) -> void { | ||
}); | ||
|
||
auto& display = spZep->GetEditor().GetDisplay(); | ||
auto pImFont = ImGui::GetIO().Fonts[0].Fonts[0]; | ||
auto pixelHeight = pImFont->FontSize; | ||
display.SetFont(ZepTextType::UI, std::make_shared<ZepFont_ImGui>(display, pImFont, int(pixelHeight))); | ||
display.SetFont(ZepTextType::Text, std::make_shared<ZepFont_ImGui>(display, pImFont, int(pixelHeight))); | ||
display.SetFont(ZepTextType::Heading1, std::make_shared<ZepFont_ImGui>(display, pImFont, int(pixelHeight * 1.5))); | ||
display.SetFont(ZepTextType::Heading2, std::make_shared<ZepFont_ImGui>(display, pImFont, int(pixelHeight * 1.25))); | ||
display.SetFont(ZepTextType::Heading3, std::make_shared<ZepFont_ImGui>(display, pImFont, int(pixelHeight * 1.125))); | ||
} | ||
|
||
void zep_update() | ||
{ | ||
if (spZep) | ||
{ | ||
spZep->GetEditor().RefreshRequired(); | ||
} | ||
} | ||
|
||
void zep_destroy() | ||
{ | ||
spZep.reset(); | ||
} | ||
|
||
ZepEditor& zep_get_editor() | ||
{ | ||
return spZep->GetEditor(); | ||
} | ||
|
||
void zep_load(const Zep::ZepPath& file) | ||
{ | ||
auto pBuffer = zep_get_editor().InitWithFileOrDir(file); | ||
} | ||
|
||
void zep_show(const Zep::NVec2i& displaySize) | ||
{ | ||
bool show = true; | ||
ImGui::SetNextWindowSize(ImVec2(displaySize.x, displaySize.y), ImGuiCond_FirstUseEver); | ||
if (!ImGui::Begin("Zep", &show, ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_MenuBar)) | ||
{ | ||
ImGui::End(); | ||
return; | ||
} | ||
|
||
auto min = ImGui::GetCursorScreenPos(); | ||
auto max = ImGui::GetContentRegionAvail(); | ||
if (max.x <= 0) | ||
max.x = 1; | ||
if (max.y <= 0) | ||
max.y = 1; | ||
ImGui::InvisibleButton("ZepContainer", max); | ||
|
||
// Fill the window | ||
max.x = min.x + max.x; | ||
max.y = min.y + max.y; | ||
|
||
spZep->zepEditor.SetDisplayRegion(Zep::NVec2f(min.x, min.y), Zep::NVec2f(max.x, max.y)); | ||
spZep->zepEditor.Display(); | ||
bool zep_focused = ImGui::IsWindowFocused(); | ||
if (zep_focused) | ||
{ | ||
spZep->zepEditor.HandleInput(); | ||
} | ||
|
||
// TODO: A Better solution for this; I think the audio graph is creating a new window and stealing focus | ||
static int focus_count = 0; | ||
if (focus_count++ < 2) | ||
{ | ||
ImGui::SetWindowFocus(); | ||
} | ||
ImGui::End(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
[editor] | ||
|
||
# Vertical Scroller: 0 = off, 1 = on if necessary, 2 = on always | ||
show_scrollbar = 0 | ||
|
||
# Style: normal, or minimal for a live-coding style of editor | ||
style = "normal" | ||
show_line_numbers = true | ||
show_indicator_region = true | ||
autohide_command_region = false | ||
cursor_line_solid = true | ||
short_tab_names = false | ||
|
||
line_margin_top = 1 | ||
line_margin_bottom = 1 | ||
widget_margin_top = 5 | ||
widget_margin_bottom = 5 | ||
|
||
background_fade_time = 20 | ||
background_fade_wait = 5 |