Revert "gui encapsulation WIP"

This reverts commit d8db3e0564.
This commit is contained in:
Mikulas Florek 2015-12-23 19:15:50 +01:00
parent 3f9aeaa9e7
commit 8d22472e26
23 changed files with 517 additions and 918 deletions

View file

@ -20,9 +20,9 @@
#include "engine/iplugin.h"
#include "engine/plugin_manager.h"
#include "file_system_watcher.h"
#include "gui_interface.h"
#include "lua_script/lua_script_manager.h"
#include "metadata.h"
#include "ocornut-imgui/imgui.h"
#include "platform_interface.h"
#include "renderer/material.h"
#include "renderer/model.h"
@ -97,7 +97,6 @@ AssetBrowser::AssetBrowser(Lumix::WorldEditor& editor, Metadata& metadata)
, m_changed_files_mutex(false)
, m_history(editor.getAllocator())
, m_playing_clip(nullptr)
, m_gui(nullptr)
{
m_filter[0] = '\0';
m_current_type = 0;
@ -177,14 +176,14 @@ void AssetBrowser::update()
Lumix::Path path_obj;
{
Lumix::MT::SpinLock lock(m_changed_files_mutex);
path_obj = m_changed_files.back();
m_changed_files.pop();
is_empty = m_changed_files.empty();
}
const char* path = path_obj.c_str();
Lumix::uint32 resource_type = getResourceType(path);
if (resource_type == 0) continue;
@ -207,12 +206,6 @@ void AssetBrowser::update()
}
void AssetBrowser::setGUIInterface(GUIInterface& gui)
{
m_gui = &gui;
}
void AssetBrowser::onGUI()
{
if (m_wanted_resource.isValid())
@ -223,9 +216,9 @@ void AssetBrowser::onGUI()
if (!m_is_opened) return;
if (!m_gui->begin("AssetBrowser", &m_is_opened))
if (!ImGui::Begin("AssetBrowser", &m_is_opened))
{
m_gui->end();
ImGui::End();
return;
}
@ -235,13 +228,13 @@ void AssetBrowser::onGUI()
ImGui::SetWindowFocus();
}
if (m_gui->button("Refresh")) findResources();
m_gui->sameLine();
m_gui->checkbox("Autoreload", &m_autoreload_changed_resource);
if (ImGui::Button("Refresh")) findResources();
ImGui::SameLine();
ImGui::Checkbox("Autoreload", &m_autoreload_changed_resource);
const char* items = "Material\0Model\0Shader\0Texture\0Universe\0Lua Script\0Audio\0";
ImGui::Combo("Type", &m_current_type, items);
m_gui->inputText("Filter", m_filter, sizeof(m_filter));
ImGui::InputText("Filter", m_filter, sizeof(m_filter));
ImGui::ListBoxHeader("Resources");
auto& resources = m_resources[m_current_type];
@ -258,7 +251,7 @@ void AssetBrowser::onGUI()
}
ImGui::ListBoxFooter();
onGUIResource();
m_gui->end();
ImGui::End();
}
@ -329,29 +322,29 @@ bool AssetBrowser::resourceInput(const char* label, const char* str_id, char* bu
ImGui::PushItemWidth(item_w - ImGui::CalcTextSize("...View").x - style.FramePadding.x * 4 -
style.ItemSpacing.x * 2);
if (m_gui->inputText(StringBuilder<30>("##", str_id), buf, max_size)) return true;
if (ImGui::InputText(StringBuilder<30>("##", str_id), buf, max_size)) return true;
m_gui->sameLine();
ImGui::SameLine();
StringBuilder<50> popup_name("pu", str_id);
if (m_gui->button(StringBuilder<30>("...##browse", str_id)))
if (ImGui::Button(StringBuilder<30>("...##browse", str_id)))
{
ImGui::OpenPopup(popup_name);
}
m_gui->sameLine();
if (m_gui->button(StringBuilder<30>("View##go", str_id)))
ImGui::SameLine();
if (ImGui::Button(StringBuilder<30>("View##go", str_id)))
{
m_is_focus_requested = true;
m_is_opened = true;
m_wanted_resource = buf;
}
m_gui->sameLine();
m_gui->text(label);
ImGui::SameLine();
ImGui::Text(label);
ImGui::PopItemWidth();
if (ImGui::BeginPopup(popup_name))
{
static char filter[128] = "";
m_gui->inputText("Filter", filter, sizeof(filter));
ImGui::InputText("Filter", filter, sizeof(filter));
for (auto unv : getResources(type))
{
@ -376,28 +369,28 @@ void AssetBrowser::onGUIMaterial()
{
auto* material = static_cast<Lumix::Material*>(m_selected_resource);
if (m_gui->button("Save")) saveMaterial(material);
m_gui->sameLine();
if (m_gui->button("Open in external editor")) openInExternalEditor(material);
if (ImGui::Button("Save")) saveMaterial(material);
ImGui::SameLine();
if (ImGui::Button("Open in external editor")) openInExternalEditor(material);
bool b;
if (material->hasAlphaCutoutDefine())
{
b = material->isAlphaCutout();
if (m_gui->checkbox("Is alpha cutout", &b)) material->enableAlphaCutout(b);
if (ImGui::Checkbox("Is alpha cutout", &b)) material->enableAlphaCutout(b);
}
b = material->isBackfaceCulling();
if (m_gui->checkbox("Is backface culling", &b)) material->enableBackfaceCulling(b);
if (ImGui::Checkbox("Is backface culling", &b)) material->enableBackfaceCulling(b);
if (material->hasShadowReceivingDefine())
{
b = material->isShadowReceiver();
if (m_gui->checkbox("Is shadow receiver", &b)) material->enableShadowReceiving(b);
if (ImGui::Checkbox("Is shadow receiver", &b)) material->enableShadowReceiving(b);
}
b = material->isZTest();
if (m_gui->checkbox("Z test", &b)) material->enableZTest(b);
if (ImGui::Checkbox("Z test", &b)) material->enableZTest(b);
Lumix::Vec3 specular = material->getSpecular();
if (ImGui::ColorEdit3("Specular", &specular.x))
@ -406,7 +399,7 @@ void AssetBrowser::onGUIMaterial()
}
float shininess = material->getShininess();
if (m_gui->dragFloat("Shininess", &shininess))
if (ImGui::DragFloat("Shininess", &shininess))
{
material->setShininess(shininess);
}
@ -430,9 +423,9 @@ void AssetBrowser::onGUIMaterial()
}
if (!texture) continue;
m_gui->sameLine();
ImGui::SameLine();
StringBuilder<100> popup_name("pu", (Lumix::uint64)texture, slot.m_name);
if (m_gui->button(StringBuilder<100>("Advanced##adv", (Lumix::uint64)texture, slot.m_name)))
if (ImGui::Button(StringBuilder<100>("Advanced##adv", (Lumix::uint64)texture, slot.m_name)))
{
ImGui::OpenPopup(popup_name);
}
@ -440,22 +433,22 @@ void AssetBrowser::onGUIMaterial()
if (ImGui::BeginPopup(popup_name))
{
bool u_clamp = (texture->getFlags() & BGFX_TEXTURE_U_CLAMP) != 0;
if (m_gui->checkbox("u clamp", &u_clamp))
if (ImGui::Checkbox("u clamp", &u_clamp))
{
texture->setFlag(BGFX_TEXTURE_U_CLAMP, u_clamp);
}
bool v_clamp = (texture->getFlags() & BGFX_TEXTURE_V_CLAMP) != 0;
if (m_gui->checkbox("v clamp", &v_clamp))
if (ImGui::Checkbox("v clamp", &v_clamp))
{
texture->setFlag(BGFX_TEXTURE_V_CLAMP, v_clamp);
}
bool min_point = (texture->getFlags() & BGFX_TEXTURE_MIN_POINT) != 0;
if (m_gui->checkbox("Min point", &min_point))
if (ImGui::Checkbox("Min point", &min_point))
{
texture->setFlag(BGFX_TEXTURE_MIN_POINT, min_point);
}
bool mag_point = (texture->getFlags() & BGFX_TEXTURE_MAG_POINT) != 0;
if (m_gui->checkbox("Mag point", &mag_point))
if (ImGui::Checkbox("Mag point", &mag_point))
{
texture->setFlag(BGFX_TEXTURE_MAG_POINT, mag_point);
}
@ -480,11 +473,11 @@ void AssetBrowser::onGUIMaterial()
switch (uniform.m_type)
{
case Lumix::Material::Uniform::FLOAT:
m_gui->dragFloat(uniform.m_name, &uniform.m_float);
ImGui::DragFloat(uniform.m_name, &uniform.m_float);
break;
}
}
m_gui->columns(1);
ImGui::Columns(1);
}
@ -493,7 +486,7 @@ void AssetBrowser::onGUITexture()
auto* texture = static_cast<Lumix::Texture*>(m_selected_resource);
if (texture->isFailure())
{
m_gui->text("Texture failed to load");
ImGui::Text("Texture failed to load");
return;
}
@ -503,7 +496,7 @@ void AssetBrowser::onGUITexture()
if (bgfx::isValid(m_texture_handle))
{
ImGui::Image(&m_texture_handle, ImVec2(200, 200));
if (m_gui->button("Open"))
if (ImGui::Button("Open"))
{
openInExternalEditor(m_selected_resource);
}
@ -533,12 +526,12 @@ void AssetBrowser::onGUIClip()
auto* clip = static_cast<Lumix::Clip*>(m_selected_resource);
ImGui::LabelText("Length", "%f", clip->getLengthSeconds());
if (m_playing_clip && m_gui->button("Stop"))
if (m_playing_clip && ImGui::Button("Stop"))
{
stopAudio();
}
if (!m_playing_clip && m_gui->button("Play"))
if (!m_playing_clip && ImGui::Button("Play"))
{
stopAudio();
@ -560,7 +553,7 @@ void AssetBrowser::onGUILuaScript()
Lumix::copyString(m_text_buffer, script->getSourceCode());
}
ImGui::InputTextMultiline("Code", m_text_buffer, sizeof(m_text_buffer), ImVec2(0, 300));
if (m_gui->button("Save"))
if (ImGui::Button("Save"))
{
auto& fs = m_editor.getEngine().getFileSystem();
auto* file = fs.open(fs.getDiskDevice(),
@ -577,8 +570,8 @@ void AssetBrowser::onGUILuaScript()
file->write(m_text_buffer, Lumix::stringLength(m_text_buffer));
fs.close(*file);
}
m_gui->sameLine();
if (m_gui->button("Open in external editor"))
ImGui::SameLine();
if (ImGui::Button("Open in external editor"))
{
openInExternalEditor(m_selected_resource);
}
@ -601,35 +594,35 @@ void AssetBrowser::onGUIShader()
Lumix::PathUtils::getBasename(
basename, Lumix::lengthOf(basename), m_selected_resource->getPath().c_str());
path << "/shaders/" << basename;
if (m_gui->button("Open vertex shader"))
if (ImGui::Button("Open vertex shader"))
{
path << "_vs.sc";
PlatformInterface::shellExecuteOpen(path);
}
m_gui->sameLine();
if (m_gui->button("Open fragment shader"))
ImGui::SameLine();
if (ImGui::Button("Open fragment shader"))
{
path << "_fs.sc";
PlatformInterface::shellExecuteOpen(path);
}
if (m_gui->collapsingHeader("Texture slots", nullptr, true, true))
if (ImGui::CollapsingHeader("Texture slots", nullptr, true, true))
{
m_gui->columns(2);
m_gui->text("name");
m_gui->nextColumn();
m_gui->text("uniform");
m_gui->nextColumn();
m_gui->separator();
ImGui::Columns(2);
ImGui::Text("name");
ImGui::NextColumn();
ImGui::Text("uniform");
ImGui::NextColumn();
ImGui::Separator();
for (int i = 0; i < shader->getTextureSlotCount(); ++i)
{
auto& slot = shader->getTextureSlot(i);
m_gui->text(slot.m_name);
m_gui->nextColumn();
m_gui->text(slot.m_uniform);
m_gui->nextColumn();
ImGui::Text(slot.m_name);
ImGui::NextColumn();
ImGui::Text(slot.m_uniform);
ImGui::NextColumn();
}
m_gui->columns(1);
ImGui::Columns(1);
}
}
@ -743,17 +736,17 @@ static void insertInScene(Lumix::WorldEditor& editor, Lumix::Model* model)
void AssetBrowser::onGUIModel()
{
auto* model = static_cast<Lumix::Model*>(m_selected_resource);
if (m_gui->button("Insert in scene"))
if (ImGui::Button("Insert in scene"))
{
insertInScene(m_editor, model);
}
ImGui::LabelText("Bone count", "%d", model->getBoneCount());
if (model->getBoneCount() > 0 && m_gui->collapsingHeader("Bones"))
if (model->getBoneCount() > 0 && ImGui::CollapsingHeader("Bones"))
{
for (int i = 0; i < model->getBoneCount(); ++i)
{
m_gui->text(model->getBone(i).name.c_str());
ImGui::Text(model->getBone(i).name.c_str());
}
}
@ -762,26 +755,26 @@ void AssetBrowser::onGUIModel()
auto& lods = model->getLODs();
if (!lods.empty())
{
m_gui->separator();
m_gui->columns(3);
m_gui->text("LOD"); m_gui->nextColumn();
m_gui->text("Distance"); m_gui->nextColumn();
m_gui->text("# of meshes"); m_gui->nextColumn();
m_gui->separator();
ImGui::Separator();
ImGui::Columns(3);
ImGui::Text("LOD"); ImGui::NextColumn();
ImGui::Text("Distance"); ImGui::NextColumn();
ImGui::Text("# of meshes"); ImGui::NextColumn();
ImGui::Separator();
for (int i = 0; i < lods.size() - 1; ++i)
{
m_gui->text("%d", i); m_gui->nextColumn();
m_gui->dragFloat("", &lods[i].m_distance); m_gui->nextColumn();
m_gui->text("%d", lods[i].m_to_mesh - lods[i].m_from_mesh + 1); m_gui->nextColumn();
ImGui::Text("%d", i); ImGui::NextColumn();
ImGui::DragFloat("", &lods[i].m_distance); ImGui::NextColumn();
ImGui::Text("%d", lods[i].m_to_mesh - lods[i].m_from_mesh + 1); ImGui::NextColumn();
}
m_gui->text("%d", lods.size() - 1); m_gui->nextColumn();
m_gui->text("INFINITE"); m_gui->nextColumn();
m_gui->text("%d", lods.back().m_to_mesh - lods.back().m_from_mesh + 1);
m_gui->columns(1);
ImGui::Text("%d", lods.size() - 1); ImGui::NextColumn();
ImGui::Text("INFINITE"); ImGui::NextColumn();
ImGui::Text("%d", lods.back().m_to_mesh - lods.back().m_from_mesh + 1);
ImGui::Columns(1);
}
m_gui->separator();
ImGui::Separator();
for (int i = 0; i < model->getMeshCount(); ++i)
{
auto& mesh = model->getMesh(i);
@ -789,8 +782,8 @@ void AssetBrowser::onGUIModel()
{
ImGui::LabelText("Triangle count", "%d", mesh.getTriangleCount());
ImGui::LabelText("Material", mesh.getMaterial()->getPath().c_str());
m_gui->sameLine();
if (m_gui->button("->"))
ImGui::SameLine();
if (ImGui::Button("->"))
{
selectResource(mesh.getMaterial()->getPath());
}
@ -805,20 +798,20 @@ void AssetBrowser::onGUIResource()
if (!m_selected_resource) return;
const char* path = m_selected_resource->getPath().c_str();
m_gui->separator();
ImGui::Separator();
ImGui::LabelText("Selected resource", path);
if (!m_history.empty() && m_gui->button("Back"))
if (!m_history.empty() && ImGui::Button("Back"))
{
selectResource(m_history.back());
m_history.pop();
m_history.pop();
return;
}
m_gui->separator();
ImGui::Separator();
if (!m_selected_resource->isReady() && !m_selected_resource->isFailure())
{
m_gui->text("Not ready");
ImGui::Text("Not ready");
return;
}

View file

@ -14,7 +14,6 @@ namespace Lumix
class FileSystemWatcher;
class GUIInterface;
class Metadata;
@ -37,7 +36,6 @@ public:
public:
AssetBrowser(Lumix::WorldEditor& editor, Metadata& metadata);
~AssetBrowser();
void setGUIInterface(GUIInterface& gui);
void onGUI();
void update();
const Lumix::Array<Lumix::Path>& getResources(Type type) const;
@ -83,5 +81,4 @@ private:
bool m_is_focus_requested;
bgfx::TextureHandle m_texture_handle;
void* m_playing_clip;
GUIInterface* m_gui;
};

View file

@ -4,7 +4,7 @@
#include "core/profiler.h"
#include "core/resource_manager.h"
#include "engine/engine.h"
#include "gui_interface.h"
#include "ocornut-imgui/imgui.h"
#include "platform_interface.h"
#include "renderer/frame_buffer.h"
#include "renderer/pipeline.h"
@ -19,7 +19,6 @@ GameView::GameView()
, m_is_mouse_captured(false)
, m_editor(nullptr)
, m_is_mouse_hovering_window(false)
, m_gui(nullptr)
{
}
@ -29,12 +28,6 @@ GameView::~GameView()
}
void GameView::setGUIInterface(GUIInterface& gui)
{
m_gui = &gui;
}
void GameView::onUniverseCreated()
{
auto* scene = m_editor->getScene(Lumix::crc32("renderer"));
@ -96,7 +89,7 @@ void GameView::onGui()
if (!m_is_opened) return;
if (!m_pipeline_source->isReady()) return;
auto& io = m_gui->getIO();
auto& io = ImGui::GetIO();
bool is_foreground_win = PlatformInterface::isWindowActive();
if (m_is_mouse_captured && (io.KeysDown[ImGui::GetKeyIndex(ImGuiKey_Escape)] ||
@ -107,7 +100,7 @@ void GameView::onGui()
const char* window_name = "Game view###game_view";
if (m_is_mouse_captured) window_name = "Game view (mouse captured)###game_view";
if (m_gui->begin(window_name, &m_is_opened))
if (ImGui::Begin(window_name, &m_is_opened))
{
m_is_mouse_hovering_window = ImGui::IsMouseHoveringWindow();
@ -143,5 +136,5 @@ void GameView::onGui()
captureMouse(true);
}
}
m_gui->end();
ImGui::End();
}

View file

@ -5,7 +5,6 @@
#include <bgfx/bgfx.h>
class GUIInterface;
struct PlatformData;
@ -23,7 +22,6 @@ public:
GameView();
~GameView();
void setGUIInterface(GUIInterface& gui);
void init(Lumix::WorldEditor& editor);
void shutdown();
void onGui();
@ -45,5 +43,4 @@ private:
bgfx::TextureHandle m_texture_handle;
Lumix::WorldEditor* m_editor;
bool m_is_mouse_hovering_window;
GUIInterface* m_gui;
};

View file

@ -1,182 +0,0 @@
#include "gui_interface.h"
#include "core/iallocator.h"
struct GUIInterfaceImpl : public GUIInterface
{
GUIInterfaceImpl(Lumix::IAllocator& allocator)
: m_allocator(allocator)
{
}
~GUIInterfaceImpl() { ImGui::Shutdown(); }
ImGuiIO& getIO() override { return ImGui::GetIO(); }
ImGuiStyle& getStyle() override { return ImGui::GetStyle(); }
bool beginMainMenuBar() override { return ImGui::BeginMainMenuBar(); }
void endMainMenuBar() override { ImGui::EndMainMenuBar(); }
bool checkbox(const char* label, bool* v) override { return ImGui::Checkbox(label, v); }
bool collapsingHeader(const char* label,
const char* str_id = NULL,
bool display_frame = true,
bool default_open = false) override
{
return ImGui::CollapsingHeader(label, str_id, display_frame, default_open);
}
bool sliderFloat(const char* label,
float* v,
float v_min,
float v_max,
const char* display_format = "%.3f",
float power = 1.0f) override
{
return ImGui::SliderFloat(label, v, v_min, v_max, display_format, power);
}
void nextColumn() override
{
ImGui::NextColumn();
}
void columns(int count = 1, const char* id = NULL, bool border = true) override
{
ImGui::Columns(count, id, border);
}
bool dragFloat(const char* label,
float* v,
float v_speed = 1.0f,
float v_min = 0.0f,
float v_max = 0.0f,
const char* display_format = "%.3f",
float power = 1.0f) override
{
return ImGui::DragFloat(label, v, v_speed, v_min, v_max, display_format, power);
}
bool inputText(const char* label,
char* buf,
size_t buf_size,
ImGuiInputTextFlags flags = 0,
ImGuiTextEditCallback callback = NULL,
void* user_data = NULL) override
{
return ImGui::InputText(label, buf, buf_size, flags, callback, user_data);
}
bool beginMenu(const char* label, bool enabled) override
{
return ImGui::BeginMenu(label, enabled);
}
void endMenu() override { ImGui::EndMenu(); }
bool beginChild(const char* str_id,
const ImVec2& size = ImVec2(0, 0),
bool border = false,
ImGuiWindowFlags extra_flags = 0) override
{
return ImGui::BeginChild(str_id, size, border, extra_flags);
}
bool beginChild(ImGuiID id,
const ImVec2& size = ImVec2(0, 0),
bool border = false,
ImGuiWindowFlags extra_flags = 0) override
{
return ImGui::BeginChild(id, size, border, extra_flags);
}
void endChild() override { ImGui::EndChild(); }
void sameLine(float local_pos_x = 0.0f, float spacing_w = -1.0f) override
{
ImGui::SameLine(local_pos_x, spacing_w);
}
void indent() override { ImGui::Indent(); }
void unindent() override { ImGui::Unindent(); }
bool menuItem(const char* label,
const char* shortcut = NULL,
bool selected = false,
bool enabled = true) override
{
return ImGui::MenuItem(label, shortcut, selected, enabled);
}
bool menuItem(const char* label,
const char* shortcut,
bool* p_selected,
bool enabled = true) override
{
return ImGui::MenuItem(label, shortcut, p_selected, enabled);
}
void end() override { ImGui::End(); }
bool begin(const char* name, bool* p_opened = NULL, ImGuiWindowFlags flags = 0) override
{
return ImGui::Begin(name, p_opened, flags);
}
bool begin(const char* name,
bool* p_opened,
const ImVec2& size_on_first_use,
float bg_alpha = -1.0f,
ImGuiWindowFlags flags = 0)
{
return ImGui::Begin(name, p_opened, size_on_first_use, bg_alpha, flags);
}
void text(const char* text, ...) override
{
va_list args;
va_start(args, text);
ImGui::TextV(text, args);
va_end(args);
}
void separator() override { ImGui::Separator(); }
void bulletText(const char* text) override { ImGui::BulletText(text); }
bool button(const char* label, const ImVec2 size = ImVec2(0, 0)) override
{
return ImGui::Button(label, size);
}
Lumix::IAllocator& m_allocator;
};
GUIInterface* GUIInterface::create(Lumix::IAllocator& allocator)
{
return LUMIX_NEW(allocator, GUIInterfaceImpl)(allocator);
}
void GUIInterface::destroy(GUIInterface& instance)
{
auto& impl = static_cast<GUIInterfaceImpl&>(instance);
LUMIX_DELETE(impl.m_allocator, &impl);
}

View file

@ -1,90 +0,0 @@
#pragma once
#include "ocornut-imgui/imgui.h"
namespace Lumix
{
class IAllocator;
}
class GUIInterface
{
public:
virtual ImGuiIO& getIO() = 0;
virtual ImGuiStyle& getStyle() = 0;
virtual bool dragFloat(const char* label,
float* v,
float v_speed = 1.0f,
float v_min = 0.0f,
float v_max = 0.0f,
const char* display_format = "%.3f",
float power = 1.0f) = 0;
virtual bool sliderFloat(const char* label,
float* v,
float v_min,
float v_max,
const char* display_format = "%.3f",
float power = 1.0f) = 0;
virtual void columns(int count = 1, const char* id = NULL, bool border = true) = 0;
virtual void nextColumn() = 0;
virtual bool collapsingHeader(const char* label,
const char* str_id = NULL,
bool display_frame = true,
bool default_open = false) = 0;
virtual bool button(const char* label, const ImVec2 size = ImVec2(0, 0)) = 0;
virtual void text(const char* text, ...) = 0;
virtual void bulletText(const char* text) = 0;
virtual void separator() = 0;
virtual bool begin(const char* name, bool* p_opened = NULL, ImGuiWindowFlags flags = 0) = 0;
virtual bool begin(const char* name,
bool* p_opened,
const ImVec2& size_on_first_use,
float bg_alpha = -1.0f,
ImGuiWindowFlags flags = 0) = 0;
virtual void end() = 0;
virtual bool menuItem(const char* label,
const char* shortcut,
bool* p_selected,
bool enabled = true) = 0;
virtual bool menuItem(const char* label,
const char* shortcut = NULL,
bool selected = false,
bool enabled = true) = 0;
virtual bool beginMainMenuBar() = 0;
virtual void endMainMenuBar() = 0;
virtual bool beginMenu(const char* label, bool enabled = true) = 0;
virtual void endMenu() = 0;
virtual bool checkbox(const char* label, bool* v) = 0;
virtual bool inputText(const char* label,
char* buf,
size_t buf_size,
ImGuiInputTextFlags flags = 0,
ImGuiTextEditCallback callback = NULL,
void* user_data = NULL) = 0;
virtual bool beginChild(const char* str_id,
const ImVec2& size = ImVec2(0, 0),
bool border = false,
ImGuiWindowFlags extra_flags = 0) = 0;
virtual bool beginChild(ImGuiID id,
const ImVec2& size = ImVec2(0, 0),
bool border = false,
ImGuiWindowFlags extra_flags = 0) = 0;
virtual void endChild() = 0;
virtual void indent() = 0;
virtual void unindent() = 0;
virtual void sameLine(float local_pos_x = 0.0f, float spacing_w = -1.0f) = 0;
static GUIInterface* create(Lumix::IAllocator& allocator);
static void destroy(GUIInterface& instance);
};

View file

@ -14,10 +14,10 @@
#include "debug/floating_points.h"
#include "editor/world_editor.h"
#include "engine/engine.h"
#include "gui_interface.h"
#include "metadata.h"
#include "physics/physics_geometry_manager.h"
#include "ocornut-imgui/imgui.h"
#include "platform_interface.h"
#include "physics/physics_geometry_manager.h"
#include "renderer/model.h"
#define STB_IMAGE_IMPLEMENTATION
#include "stb/stb_image.h"
@ -1311,7 +1311,6 @@ ImportAssetDialog::ImportAssetDialog(Lumix::WorldEditor& editor, Metadata& metad
, m_convert_to_dds(false)
, m_convert_to_raw(false)
, m_raw_texture_scale(1)
, m_gui(nullptr)
{
m_is_opened = false;
m_message[0] = '\0';
@ -1333,12 +1332,6 @@ ImportAssetDialog::~ImportAssetDialog()
}
void ImportAssetDialog::setGUIInterface(GUIInterface& gui)
{
m_gui = &gui;
}
bool ImportAssetDialog::checkTexture(const char* source_dir, const char* texture_path, const char* message)
{
if (texture_path[0] == '*') return true;
@ -1545,18 +1538,18 @@ void ImportAssetDialog::onGUI()
{
if (!m_is_opened) return;
if (m_gui->begin("Import asset", &m_is_opened))
if (ImGui::Begin("Import asset", &m_is_opened))
{
if (hasMessage())
{
char msg[1024];
getMessage(msg, sizeof(msg));
m_gui->text(msg);
if (m_gui->button("OK"))
ImGui::Text(msg);
if (ImGui::Button("OK"))
{
setMessage("");
}
m_gui->end();
ImGui::End();
return;
}
@ -1574,20 +1567,20 @@ void ImportAssetDialog::onGUI()
{
Lumix::MT::SpinLock lock(m_mutex);
m_gui->text(m_import_message);
ImGui::Text(m_import_message);
}
m_gui->end();
ImGui::End();
return;
}
if (m_gui->checkbox("Optimize meshes", &m_optimize_mesh_on_import)) checkSource();
m_gui->sameLine();
if (m_gui->checkbox("Smooth normals", &m_gen_smooth_normal)) checkSource();
if (ImGui::Checkbox("Optimize meshes", &m_optimize_mesh_on_import)) checkSource();
ImGui::SameLine();
if (ImGui::Checkbox("Smooth normals", &m_gen_smooth_normal)) checkSource();
if (m_gui->inputText("Source", m_source, sizeof(m_source))) checkSource();
if (ImGui::InputText("Source", m_source, sizeof(m_source))) checkSource();
m_gui->sameLine();
if (m_gui->button("..."))
ImGui::SameLine();
if (ImGui::Button("..."))
{
PlatformInterface::getOpenFilename(m_source, sizeof(m_source), "All\0*.*\0");
checkSource();
@ -1595,64 +1588,64 @@ void ImportAssetDialog::onGUI()
if (isImage(m_source))
{
if (m_gui->checkbox("Convert to raw", &m_convert_to_raw))
if (ImGui::Checkbox("Convert to raw", &m_convert_to_raw))
{
if (m_convert_to_raw) m_convert_to_dds = false;
}
if (m_convert_to_raw)
{
m_gui->sameLine();
m_gui->dragFloat("Scale", &m_raw_texture_scale, 1.0f, 0.01f, 256.0f);
ImGui::SameLine();
ImGui::DragFloat("Scale", &m_raw_texture_scale, 1.0f, 0.01f, 256.0f);
}
if (m_gui->checkbox("Convert to DDS", &m_convert_to_dds))
if (ImGui::Checkbox("Convert to DDS", &m_convert_to_dds))
{
if (m_convert_to_dds) m_convert_to_raw = false;
}
m_gui->inputText("Output directory", m_output_dir, sizeof(m_output_dir));
m_gui->sameLine();
if (m_gui->button("...##browseoutput"))
ImGui::InputText("Output directory", m_output_dir, sizeof(m_output_dir));
ImGui::SameLine();
if (ImGui::Button("...##browseoutput"))
{
PlatformInterface::getOpenDirectory(m_output_dir, sizeof(m_output_dir));
}
if (m_gui->button("Import texture"))
if (ImGui::Button("Import texture"))
{
importTexture();
}
m_gui->end();
ImGui::End();
return;
}
if (m_importer.GetScene())
{
auto* scene = m_importer.GetScene();
m_gui->checkbox("Import model", &m_import_model);
ImGui::Checkbox("Import model", &m_import_model);
if (scene->HasMaterials())
{
m_gui->checkbox(StringBuilder<50>("Import materials (",
ImGui::Checkbox(StringBuilder<50>("Import materials (",
scene->mNumMaterials,
")"),
&m_import_materials);
m_gui->checkbox("Convert to DDS", &m_convert_to_dds);
ImGui::Checkbox("Convert to DDS", &m_convert_to_dds);
}
if (scene->HasAnimations())
{
m_gui->checkbox(StringBuilder<50>("Import animations (",
ImGui::Checkbox(StringBuilder<50>("Import animations (",
scene->mNumAnimations,
")"),
&m_import_animations);
}
m_gui->checkbox("Import physics", &m_import_physics);
ImGui::Checkbox("Import physics", &m_import_physics);
if (m_import_physics)
{
m_gui->sameLine();
m_gui->checkbox("Make convex", &m_make_convex);
ImGui::SameLine();
ImGui::Checkbox("Make convex", &m_make_convex);
}
if (scene->mNumMeshes > 1)
{
if (m_gui->collapsingHeader(StringBuilder<30>("Meshes (")
if (ImGui::CollapsingHeader(StringBuilder<30>("Meshes (")
<< scene->mNumMeshes
<< ")##Meshes",
nullptr,
@ -1663,7 +1656,7 @@ void ImportAssetDialog::onGUI()
{
const char* name = scene->mMeshes[i]->mName.C_Str();
bool b = m_mesh_mask[i];
m_gui->checkbox(name[0] == '\0'
ImGui::Checkbox(name[0] == '\0'
? StringBuilder<30>("N/A###na", (Lumix::uint64)&scene->mMeshes[i])
: name,
&b);
@ -1672,17 +1665,17 @@ void ImportAssetDialog::onGUI()
}
}
m_gui->inputText("Output directory", m_output_dir, sizeof(m_output_dir));
m_gui->sameLine();
if (m_gui->button("...##browseoutput"))
ImGui::InputText("Output directory", m_output_dir, sizeof(m_output_dir));
ImGui::SameLine();
if (ImGui::Button("...##browseoutput"))
{
PlatformInterface::getOpenDirectory(m_output_dir, sizeof(m_output_dir));
}
m_gui->inputText(
ImGui::InputText(
"Texture output directory", m_texture_output_dir, sizeof(m_texture_output_dir));
m_gui->sameLine();
if (m_gui->button("...##browsetextureoutput"))
ImGui::SameLine();
if (ImGui::Button("...##browsetextureoutput"))
{
PlatformInterface::getOpenDirectory(m_texture_output_dir, sizeof(m_texture_output_dir));
}
@ -1691,15 +1684,15 @@ void ImportAssetDialog::onGUI()
{
if (!isTextureDirValid())
{
m_gui->text("Texture output directory must be an ancestor of the working "
ImGui::Text("Texture output directory must be an ancestor of the working "
"directory or empty.");
}
else if (m_gui->button("Convert"))
else if (ImGui::Button("Convert"))
{
convert();
}
}
}
}
m_gui->end();
ImGui::End();
}

View file

@ -10,7 +10,6 @@
#include "lumix.h"
class GUIInterface;
class Metadata;
@ -37,7 +36,6 @@ class ImportAssetDialog
~ImportAssetDialog();
void setMessage(const char* message);
void setImportMessage(const char* message);
void setGUIInterface(GUIInterface& gui);
void onGUI();
@ -83,5 +81,4 @@ class ImportAssetDialog
Lumix::MT::Task* m_task;
Lumix::MT::SpinMutex m_mutex;
Metadata& m_metadata;
GUIInterface* m_gui;
};

View file

@ -1,6 +1,6 @@
#include "log_ui.h"
#include "core/log.h"
#include "gui_interface.h"
#include "ocornut-imgui/imgui.h"
LogUI::LogUI(Lumix::IAllocator& allocator)
@ -10,7 +10,6 @@ LogUI::LogUI(Lumix::IAllocator& allocator)
, m_notifications(allocator)
, m_last_uid(1)
, m_guard(false)
, m_gui(nullptr)
{
m_is_opened = false;
Lumix::g_log_info.getCallback().bind<LogUI, &LogUI::onInfo>(this);
@ -33,12 +32,6 @@ LogUI::~LogUI()
}
void LogUI::setGUIInterface(GUIInterface& gui)
{
m_gui = &gui;
}
void LogUI::setNotificationTime(int uid, float time)
{
for (auto& notif : m_notifications)
@ -110,7 +103,7 @@ void LogUI::showNotifications()
ImGui::SetNextWindowPos(ImVec2(10, 30));
bool opened;
if (!m_gui->begin("Notifications",
if (!ImGui::Begin("Notifications",
&opened,
ImVec2(200, 0),
0.3f,
@ -118,17 +111,17 @@ void LogUI::showNotifications()
ImGuiWindowFlags_NoMove |
ImGuiWindowFlags_NoSavedSettings))
{
m_gui->end();
ImGui::End();
return;
}
if (m_move_notifications_to_front) ImGui::BringToFront();
m_move_notifications_to_front = false;
for (int i = 0; i < m_notifications.size(); ++i)
{
if (i > 0) m_gui->separator();
m_gui->text(m_notifications[i].message.c_str());
if (i > 0) ImGui::Separator();
ImGui::Text(m_notifications[i].message.c_str());
}
m_gui->end();
ImGui::End();
}
@ -154,24 +147,24 @@ void LogUI::onGUI()
if (!m_is_opened) return;
if (m_gui->begin("Log", &m_is_opened))
if (ImGui::Begin("Log", &m_is_opened))
{
const char* labels[] = { "Info", "Warning", "Error", "BGFX" };
for (int i = 0; i < Lumix::lengthOf(labels); ++i)
{
char label[20];
fillLabel(label, sizeof(label), labels[i], m_new_message_count[i]);
if (i > 0) m_gui->sameLine();
if (m_gui->button(label))
if(i > 0) ImGui::SameLine();
if (ImGui::Button(label))
{
m_current_tab = i;
m_new_message_count[i] = 0;
}
}
auto* messages = &m_messages[m_current_tab];
if (m_gui->button("Clear"))
if (ImGui::Button("Clear"))
{
for (int i = 0; i < m_messages.size(); ++i)
{
@ -180,22 +173,22 @@ void LogUI::onGUI()
}
}
m_gui->sameLine();
ImGui::SameLine();
char filter[128] = "";
m_gui->inputText("Filter", filter, sizeof(filter));
ImGui::InputText("Filter", filter, sizeof(filter));
if (m_gui->beginChild("log_messages"))
if (ImGui::BeginChild("log_messages"))
{
for (int i = 0; i < messages->size(); ++i)
{
const char* msg = (*messages)[i].c_str();
if (filter[0] == '\0' || strstr(msg, filter) != nullptr)
{
m_gui->text(msg);
ImGui::Text(msg);
}
}
}
m_gui->endChild();
ImGui::EndChild();
}
m_gui->end();
ImGui::End();
}

View file

@ -6,9 +6,6 @@
#include "core/string.h"
class GUIInterface;
class LogUI
{
public:
@ -19,7 +16,6 @@ class LogUI
void update(float time_delta);
int addNotification(const char* text);
void setNotificationTime(int uid, float time);
void setGUIInterface(GUIInterface& gui);
public:
bool m_is_opened;
@ -62,5 +58,4 @@ class LogUI
int m_last_uid;
bool m_move_notifications_to_front;
Lumix::MT::SpinMutex m_guard;
GUIInterface* m_gui;
};

View file

@ -22,10 +22,10 @@
#include "engine.h"
#include "engine/plugin_manager.h"
#include "game_view.h"
#include "gui_interface.h"
#include "import_asset_dialog.h"
#include "log_ui.h"
#include "metadata.h"
#include "ocornut-imgui/imgui.h"
#include "platform_interface.h"
#include "profiler_ui.h"
#include "property_grid.h"
@ -70,7 +70,6 @@ public:
, m_shader_editor(nullptr)
, m_editor(nullptr)
, m_settings(m_allocator)
, m_gui(nullptr)
{
m_template_name[0] = '\0';
m_clip_manager_filter[0] = '\0';
@ -121,105 +120,105 @@ public:
ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoSavedSettings;
ImVec2 size((float)PlatformInterface::getWindowWidth(),
(float)PlatformInterface::getWindowHeight());
if (m_gui->begin("Welcome", nullptr, size, -1, flags))
if (ImGui::Begin("Welcome", nullptr, size, -1, flags))
{
m_gui->text("Welcome to Lumix Studio");
ImGui::Text("Welcome to Lumix Studio");
ImVec2 half_size = ImGui::GetContentRegionAvail();
half_size.x = half_size.x * 0.5f - m_gui->getStyle().FramePadding.x;
half_size.x = half_size.x * 0.5f - ImGui::GetStyle().FramePadding.x;
half_size.y *= 0.75f;
auto right_pos = ImGui::GetCursorPos();
right_pos.x += half_size.x + m_gui->getStyle().FramePadding.x;
if (m_gui->beginChild("left", half_size, true))
right_pos.x += half_size.x + ImGui::GetStyle().FramePadding.x;
if (ImGui::BeginChild("left", half_size, true))
{
if (m_gui->button("New Universe")) m_is_welcome_screen_opened = false;
if (ImGui::Button("New Universe")) m_is_welcome_screen_opened = false;
m_gui->separator();
m_gui->text("Open universe:");
m_gui->indent();
ImGui::Separator();
ImGui::Text("Open universe:");
ImGui::Indent();
auto& universes = m_asset_browser->getResources(AssetBrowser::UNIVERSE);
for (auto& univ : universes)
{
if (m_gui->menuItem(univ.c_str()))
if (ImGui::MenuItem(univ.c_str()))
{
m_editor->loadUniverse(univ);
setTitle(univ.c_str());
m_is_welcome_screen_opened = false;
}
}
m_gui->unindent();
ImGui::Unindent();
}
m_gui->endChild();
ImGui::EndChild();
ImGui::SetCursorPos(right_pos);
if (m_gui->beginChild("right", half_size, true))
if (ImGui::BeginChild("right", half_size, true))
{
if (m_gui->button("Download new version"))
if (ImGui::Button("Download new version"))
{
PlatformInterface::shellExecuteOpen(
"https://github.com/nem0/lumixengine_data/archive/master.zip");
}
if (m_gui->button("Show major releases"))
if (ImGui::Button("Show major releases"))
{
PlatformInterface::shellExecuteOpen("https://github.com/nem0/LumixEngine/releases");
}
if (m_gui->button("Show latest commits"))
if (ImGui::Button("Show latest commits"))
{
PlatformInterface::shellExecuteOpen("https://github.com/nem0/LumixEngine/commits/master");
}
if (m_gui->button("Show issues"))
if (ImGui::Button("Show issues"))
{
PlatformInterface::shellExecuteOpen("https://github.com/nem0/lumixengine/issues");
}
m_gui->separator();
ImGui::Separator();
m_gui->text("Version 0.19. - News");
m_gui->bulletText("File system UI");
m_gui->bulletText("Particle system player");
m_gui->bulletText("Particle system using bezier curves");
m_gui->bulletText("Bezier curves in GUI");
m_gui->separator();
m_gui->text("Version 0.18. - News");
m_gui->bulletText("Collision events are sent to scripts");
m_gui->bulletText("Multithread safe profiler");
m_gui->bulletText("XBox Controller support");
m_gui->bulletText("Each script component has its own environment");
m_gui->bulletText("Pipeline's features can be enabled/disabled in GUI");
m_gui->bulletText("Shader editor");
m_gui->bulletText("Audio system");
m_gui->bulletText("Basic particle system");
m_gui->separator();
m_gui->text("Version 0.17. - News");
m_gui->bulletText("Back button in the asset browser");
m_gui->bulletText("Grass culling");
m_gui->bulletText("Importing compressed embedded textures");
m_gui->bulletText("Euler angles");
m_gui->bulletText("Textures relative to root");
m_gui->bulletText("Painting entities - align with normal");
m_gui->bulletText("Painting entities - random x and z rotation");
m_gui->bulletText("Lua properties with types");
m_gui->bulletText("Moving the Light Texel-Sized Increments");
m_gui->bulletText("Terrain brush for removing entities");
m_gui->bulletText("Improved shadows on terrain");
m_gui->bulletText("Fog height");
m_gui->bulletText("Bitmap to heightmap convertor");
m_gui->bulletText("LOD preview");
m_gui->bulletText("New gizmo");
m_gui->bulletText("Orbit camera");
m_gui->bulletText("Welcome screen");
m_gui->bulletText("Visualization of physical contorller");
m_gui->bulletText("Game view fixed");
ImGui::Text("Version 0.19. - News");
ImGui::BulletText("File system UI");
ImGui::BulletText("Particle system player");
ImGui::BulletText("Particle system using bezier curves");
ImGui::BulletText("Bezier curves in GUI");
ImGui::Separator();
ImGui::Text("Version 0.18. - News");
ImGui::BulletText("Collision events are sent to scripts");
ImGui::BulletText("Multithread safe profiler");
ImGui::BulletText("XBox Controller support");
ImGui::BulletText("Each script component has its own environment");
ImGui::BulletText("Pipeline's features can be enabled/disabled in GUI");
ImGui::BulletText("Shader editor");
ImGui::BulletText("Audio system");
ImGui::BulletText("Basic particle system");
ImGui::Separator();
ImGui::Text("Version 0.17. - News");
ImGui::BulletText("Back button in the asset browser");
ImGui::BulletText("Grass culling");
ImGui::BulletText("Importing compressed embedded textures");
ImGui::BulletText("Euler angles");
ImGui::BulletText("Textures relative to root");
ImGui::BulletText("Painting entities - align with normal");
ImGui::BulletText("Painting entities - random x and z rotation");
ImGui::BulletText("Lua properties with types");
ImGui::BulletText("Moving the Light Texel-Sized Increments");
ImGui::BulletText("Terrain brush for removing entities");
ImGui::BulletText("Improved shadows on terrain");
ImGui::BulletText("Fog height");
ImGui::BulletText("Bitmap to heightmap convertor");
ImGui::BulletText("LOD preview");
ImGui::BulletText("New gizmo");
ImGui::BulletText("Orbit camera");
ImGui::BulletText("Welcome screen");
ImGui::BulletText("Visualization of physical contorller");
ImGui::BulletText("Game view fixed");
}
m_gui->endChild();
ImGui::EndChild();
if (m_gui->button("Close")) m_is_welcome_screen_opened = false;
if (ImGui::Button("Close")) m_is_welcome_screen_opened = false;
}
m_gui->end();
ImGui::End();
}
@ -229,7 +228,7 @@ public:
if (!m_gui_pipeline_source->isReady()) return;
ImGuiIO& io = m_gui->getIO();
ImGuiIO& io = ImGui::GetIO();
io.DisplaySize = ImVec2((float)PlatformInterface::getWindowWidth(),
(float)PlatformInterface::getWindowHeight());
io.DeltaTime = m_engine->getLastTimeDelta();
@ -298,7 +297,7 @@ public:
{
char buf[20];
getShortcut(a, buf, sizeof(buf));
if (m_gui->menuItem(a.label, buf, selected, enabled))
if (ImGui::MenuItem(a.label, buf, selected, enabled))
{
a.func.invoke();
}
@ -360,13 +359,13 @@ public:
void lookAtSelected() { m_editor->lookAtSelected(); }
void toggleStats() { m_gui_pipeline->toggleStats(); }
void autosnapDown()
void autosnapDown()
{
auto& gizmo = m_editor->getGizmo();
gizmo.setAutosnapDown(!gizmo.isAutosnapDown());
}
void toggleGizmoMode()
void toggleGizmoMode()
{
auto& gizmo = m_editor->getGizmo();
if (gizmo.getMode() == Lumix::Gizmo::Mode::TRANSLATE)
@ -379,7 +378,7 @@ public:
}
}
void setWireframe()
{
m_is_wireframe = !m_is_wireframe;
@ -448,74 +447,74 @@ public:
void showMainMenu()
{
bool is_any_entity_selected = !m_editor->getSelectedEntities().empty();
if (m_gui->beginMainMenuBar())
if (ImGui::BeginMainMenuBar())
{
if (m_gui->beginMenu("File"))
if (ImGui::BeginMenu("File"))
{
doMenuItem(getAction("newUniverse"), false, true);
if (m_gui->beginMenu("Open"))
if (ImGui::BeginMenu("Open"))
{
auto& universes = m_asset_browser->getResources(AssetBrowser::UNIVERSE);
for (auto& univ : universes)
{
if (m_gui->menuItem(univ.c_str()))
if (ImGui::MenuItem(univ.c_str()))
{
m_time_to_autosave = float(m_settings.m_autosave_time);
m_editor->loadUniverse(univ);
setTitle(univ.c_str());
}
}
m_gui->endMenu();
ImGui::EndMenu();
}
doMenuItem(getAction("save"), false, true);
doMenuItem(getAction("saveAs"), false, true);
doMenuItem(getAction("exit"), false, true);
m_gui->endMenu();
ImGui::EndMenu();
}
if (m_gui->beginMenu("Edit"))
if (ImGui::BeginMenu("Edit"))
{
doMenuItem(getAction("undo"), false, m_editor->canUndo());
doMenuItem(getAction("redo"), false, m_editor->canRedo());
m_gui->separator();
ImGui::Separator();
doMenuItem(getAction("copy"), false, is_any_entity_selected);
doMenuItem(getAction("paste"), false, m_editor->canPasteEntity());
m_gui->separator();
ImGui::Separator();
doMenuItem(getAction("orbitCamera"),
m_editor->isOrbitCamera(),
is_any_entity_selected || m_editor->isOrbitCamera());
doMenuItem(getAction("toggleGizmoMode"), false, is_any_entity_selected);
doMenuItem(getAction("togglePivotMode"), false, is_any_entity_selected);
doMenuItem(getAction("toggleCoordSystem"), false, is_any_entity_selected);
if (m_gui->beginMenu("Select"))
if (ImGui::BeginMenu("Select"))
{
if (m_gui->menuItem("Same mesh", nullptr, nullptr, is_any_entity_selected))
if (ImGui::MenuItem("Same mesh", nullptr, nullptr, is_any_entity_selected))
m_editor->selectEntitiesWithSameMesh();
m_gui->endMenu();
ImGui::EndMenu();
}
m_gui->endMenu();
ImGui::EndMenu();
}
if (m_gui->beginMenu("Entity"))
if (ImGui::BeginMenu("Entity"))
{
doMenuItem(getAction("createEntity"), false, true);
doMenuItem(getAction("destroyEntity"), false, is_any_entity_selected);
if (m_gui->beginMenu("Create template", is_any_entity_selected))
if (ImGui::BeginMenu("Create template", is_any_entity_selected))
{
static char name[255] = "";
m_gui->inputText("Name##templatename", name, sizeof(name));
if (m_gui->button("Create"))
ImGui::InputText("Name##templatename", name, sizeof(name));
if (ImGui::Button("Create"))
{
auto entity = m_editor->getSelectedEntities()[0];
auto& system = m_editor->getEntityTemplateSystem();
system.createTemplateFromEntity(name, entity);
ImGui::CloseCurrentPopup();
}
m_gui->endMenu();
ImGui::EndMenu();
}
if (m_gui->menuItem("Instantiate template",
if (ImGui::MenuItem("Instantiate template",
nullptr,
nullptr,
m_selected_template_name.length() > 0))
@ -524,58 +523,58 @@ public:
m_editor->getEntityTemplateSystem().createInstance(
m_selected_template_name.c_str(), pos);
}
doMenuItem(getAction("showEntities"), false, is_any_entity_selected);
doMenuItem(getAction("hideEntities"), false, is_any_entity_selected);
m_gui->endMenu();
ImGui::EndMenu();
}
if(m_gui->beginMenu("Tools"))
if (ImGui::BeginMenu("Tools"))
{
doMenuItem(getAction("toggleGameMode"), m_editor->isGameMode(), true);
doMenuItem(getAction("toggleMeasure"), m_editor->isMeasureToolActive(), true);
doMenuItem(getAction("snapDown"), false, is_any_entity_selected);
doMenuItem(getAction("autosnapDown"), m_editor->getGizmo().isAutosnapDown(), true);
if (m_gui->menuItem("Save commands")) saveUndoStack();
if (m_gui->menuItem("Load commands")) loadAndExecuteCommands();
if (ImGui::MenuItem("Save commands")) saveUndoStack();
if (ImGui::MenuItem("Load commands")) loadAndExecuteCommands();
m_gui->menuItem("Import asset", nullptr, &m_import_asset_dialog->m_is_opened);
m_gui->endMenu();
ImGui::MenuItem("Import asset", nullptr, &m_import_asset_dialog->m_is_opened);
ImGui::EndMenu();
}
if (m_gui->beginMenu("View"))
if (ImGui::BeginMenu("View"))
{
doMenuItem(getAction("lookAtSelected"), false, is_any_entity_selected);
doMenuItem(getAction("setWireframe"), m_is_wireframe, true);
doMenuItem(getAction("toggleStats"), false, true);
if (m_gui->beginMenu("Windows"))
if (ImGui::BeginMenu("Windows"))
{
m_gui->menuItem("Asset browser", nullptr, &m_asset_browser->m_is_opened);
m_gui->menuItem("Clip manager", nullptr, &m_is_clip_manager_opened);
m_gui->menuItem("Entity list", nullptr, &m_is_entity_list_opened);
m_gui->menuItem("Entity templates", nullptr, &m_is_entity_template_list_opened);
m_gui->menuItem("Game view", nullptr, &m_gameview.m_is_opened);
m_gui->menuItem("Log", nullptr, &m_log_ui->m_is_opened);
m_gui->menuItem("Profiler", nullptr, &m_profiler_ui->m_is_opened);
m_gui->menuItem("Properties", nullptr, &m_property_grid->m_is_opened);
m_gui->menuItem("Settings", nullptr, &m_settings.m_is_opened);
m_gui->menuItem("Shader editor", nullptr, &m_shader_editor->m_is_opened);
m_gui->menuItem("Style editor", nullptr, &m_is_style_editor_opened);
m_gui->endMenu();
ImGui::MenuItem("Asset browser", nullptr, &m_asset_browser->m_is_opened);
ImGui::MenuItem("Clip manager", nullptr, &m_is_clip_manager_opened);
ImGui::MenuItem("Entity list", nullptr, &m_is_entity_list_opened);
ImGui::MenuItem("Entity templates", nullptr, &m_is_entity_template_list_opened);
ImGui::MenuItem("Game view", nullptr, &m_gameview.m_is_opened);
ImGui::MenuItem("Log", nullptr, &m_log_ui->m_is_opened);
ImGui::MenuItem("Profiler", nullptr, &m_profiler_ui->m_is_opened);
ImGui::MenuItem("Properties", nullptr, &m_property_grid->m_is_opened);
ImGui::MenuItem("Settings", nullptr, &m_settings.m_is_opened);
ImGui::MenuItem("Shader editor", nullptr, &m_shader_editor->m_is_opened);
ImGui::MenuItem("Style editor", nullptr, &m_is_style_editor_opened);
ImGui::EndMenu();
}
m_gui->endMenu();
ImGui::EndMenu();
}
StringBuilder<100> stats("");
if (m_engine->getFileSystem().hasWork()) stats << "Loading... | ";
stats << "FPS: ";
stats << m_engine->getFPS();
auto stats_size = ImGui::CalcTextSize(stats);
m_gui->sameLine(ImGui::GetContentRegionMax().x - stats_size.x);
m_gui->text(stats);
ImGui::SameLine(ImGui::GetContentRegionMax().x - stats_size.x);
ImGui::Text(stats);
m_gui->endMainMenuBar();
ImGui::EndMainMenuBar();
}
}
@ -587,21 +586,21 @@ public:
{
if (!m_is_entity_template_list_opened) return;
if (m_gui->begin("Entity templates", &m_is_entity_template_list_opened))
if (ImGui::Begin("Entity templates", &m_is_entity_template_list_opened))
{
if (m_editor->getSelectedEntities().size() == 1)
{
m_gui->inputText("Template name", m_template_name, Lumix::lengthOf(m_template_name));
ImGui::InputText("Template name", m_template_name, Lumix::lengthOf(m_template_name));
if (m_gui->button("Create from selected"))
if (ImGui::Button("Create from selected"))
{
auto entity = m_editor->getSelectedEntities()[0];
auto& system = m_editor->getEntityTemplateSystem();
system.createTemplateFromEntity(m_template_name, entity);
}
m_gui->separator();
ImGui::Separator();
}
m_gui->text("Templates:");
ImGui::Text("Templates:");
auto& template_system = m_editor->getEntityTemplateSystem();
for (auto& template_name : template_system.getTemplateNames())
@ -613,7 +612,7 @@ public:
}
}
}
m_gui->end();
ImGui::End();
}
@ -621,9 +620,9 @@ public:
{
if (!m_is_clip_manager_opened) return;
if (m_gui->begin("Clip manager", &m_is_clip_manager_opened))
if (ImGui::Begin("Clip manager", &m_is_clip_manager_opened))
{
m_gui->inputText("Filter", m_clip_manager_filter, Lumix::lengthOf(m_clip_manager_filter));
ImGui::InputText("Filter", m_clip_manager_filter, Lumix::lengthOf(m_clip_manager_filter));
auto* audio_scene = static_cast<Lumix::AudioScene*>(m_editor->getScene(Lumix::crc32("audio")));
int clip_count = audio_scene->getClipCount();
@ -641,7 +640,7 @@ public:
{
char buf[30];
Lumix::copyString(buf, Lumix::lengthOf(buf), clip_info->name);
if (m_gui->inputText("Name", buf, sizeof(buf)))
if (ImGui::InputText("Name", buf, sizeof(buf)))
{
Lumix::copyString(clip_info->name, buf);
clip_info->name_hash = Lumix::crc32(buf);
@ -655,11 +654,11 @@ public:
audio_scene->setClip(clip_id, Lumix::Path(path));
}
bool looped = audio_scene->getClipInfo(clip_id)->looped;
if (m_gui->checkbox("Looped", &looped))
if (ImGui::Checkbox("Looped", &looped))
{
clip_info->looped = looped;
}
if (m_gui->button("Remove"))
if (ImGui::Button("Remove"))
{
audio_scene->removeClip(clip_info);
--clip_count;
@ -668,12 +667,12 @@ public:
}
}
if (m_gui->button("Add"))
if (ImGui::Button("Add"))
{
audio_scene->addClip("test", Lumix::Path("test.ogg"));
}
}
m_gui->end();
ImGui::End();
}
@ -681,15 +680,15 @@ public:
{
if (!m_is_entity_list_opened) return;
if (m_gui->begin("Entity list", &m_is_entity_list_opened))
if (ImGui::Begin("Entity list", &m_is_entity_list_opened))
{
auto* universe = m_editor->getUniverse();
int scroll_to = -1;
auto& groups = m_editor->getEntityGroups();
static char group_name[20] = "";
m_gui->inputText("New group name", group_name, Lumix::lengthOf(group_name));
if(m_gui->button("Create group"))
ImGui::InputText("New group name", group_name, Lumix::lengthOf(group_name));
if(ImGui::Button("Create group"))
{
if(group_name[0] == 0)
{
@ -705,7 +704,7 @@ public:
}
group_name[0] = 0;
}
m_gui->separator();
ImGui::Separator();
for(int i = 0; i < groups.getGroupCount(); ++i)
{
@ -747,19 +746,19 @@ public:
if(groups.getGroupCount() == 1)
{
m_gui->text("Can not delete - at least one group must exists");
ImGui::Text("Can not delete - at least one group must exists");
}
else if(m_gui->button("Delete group"))
else if(ImGui::Button("Delete group"))
{
groups.deleteGroup(i);
}
if(m_gui->button("Select all entities in group"))
if(ImGui::Button("Select all entities in group"))
{
m_editor->selectEntities(groups.getGroupEntities(i), groups.getGroupEntitiesCount(i));
}
if(m_gui->button("Assign selected entities to group"))
if(ImGui::Button("Assign selected entities to group"))
{
auto& selected = m_editor->getSelectedEntities();
for(auto e : selected)
@ -772,7 +771,7 @@ public:
}
}
}
m_gui->end();
ImGui::End();
}
@ -810,6 +809,7 @@ public:
shutdownImGui();
ProfilerUI::destroy(*m_profiler_ui);
LUMIX_DELETE(m_allocator, m_asset_browser);
LUMIX_DELETE(m_allocator, m_log_ui);
LUMIX_DELETE(m_allocator, m_property_grid);
@ -817,7 +817,6 @@ public:
LUMIX_DELETE(m_allocator, m_shader_compiler);
LUMIX_DELETE(m_allocator, m_shader_editor);
Lumix::WorldEditor::destroy(m_editor, m_allocator);
ProfilerUI::destroy(*m_profiler_ui);
m_sceneview.shutdown();
m_gameview.shutdown();
Lumix::PipelineInstance::destroy(m_gui_pipeline);
@ -837,7 +836,7 @@ public:
void shutdownImGui()
{
GUIInterface::destroy(*m_gui);
ImGui::Shutdown();
Lumix::Texture* texture = m_material->getTexture(0);
m_material->setTexture(0, nullptr);
@ -845,16 +844,12 @@ public:
LUMIX_DELETE(m_allocator, texture);
m_material->getResourceManager().get(Lumix::ResourceManager::MATERIAL)->unload(*m_material);
}
void initIMGUI()
{
m_gui = GUIInterface::create(m_allocator);
m_handler.m_gui = m_gui;
ImGuiIO& io = m_gui->getIO();
ImGuiIO& io = ImGui::GetIO();
io.Fonts->AddFontFromFileTTF("bin/VeraMono.ttf", 13);
io.KeyMap[ImGuiKey_Tab] = (int)PlatformInterface::Keys::TAB;
@ -893,17 +888,7 @@ public:
texture->create(width, height, pixels);
m_material->setTexture(0, texture);
m_gui->getStyle().WindowFillAlphaDefault = 1.0f;
m_asset_browser->setGUIInterface(*m_gui);
m_import_asset_dialog->setGUIInterface(*m_gui);
m_sceneview.setGUIInterface(*m_gui);
m_log_ui->setGUIInterface(*m_gui);
m_profiler_ui->setGUIInterface(*m_gui);
m_property_grid->setGUIInterface(*m_gui);
m_shader_editor->setGUIInterface(*m_gui);
m_gameview.setGUIInterface(*m_gui);
m_settings.setGUIInterface(*m_gui);
ImGui::GetStyle().WindowFillAlphaDefault = 1.0f;
}
@ -1086,7 +1071,7 @@ public:
m_app->m_sceneview.onMouseMove(x, y, rel_x, rel_y);
ImGuiIO& io = m_gui->getIO();
ImGuiIO& io = ImGui::GetIO();
io.MousePos.x = (float)x;
io.MousePos.y = (float)y;
}
@ -1094,7 +1079,7 @@ public:
void onMouseWheel(int amount) override
{
m_gui->getIO().MouseWheel = amount / 600.0f;
ImGui::GetIO().MouseWheel = amount / 600.0f;
}
@ -1103,12 +1088,12 @@ public:
switch (button)
{
case PlatformInterface::SystemEventHandler::MouseButton::LEFT:
m_app->m_editor->setAdditiveSelection(m_gui->getIO().KeyCtrl);
m_app->m_editor->setAdditiveSelection(ImGui::GetIO().KeyCtrl);
if (!m_app->m_sceneview.onMouseDown(
m_mouse_x, m_mouse_y, Lumix::MouseButton::LEFT) &&
!m_app->m_gameview.isMouseCaptured())
{
m_gui->getIO().MouseDown[0] = true;
ImGui::GetIO().MouseDown[0] = true;
}
break;
case PlatformInterface::SystemEventHandler::MouseButton::RIGHT:
@ -1116,7 +1101,7 @@ public:
m_mouse_x, m_mouse_y, Lumix::MouseButton::RIGHT) &&
!m_app->m_gameview.isMouseCaptured())
{
m_gui->getIO().MouseDown[1] = true;
ImGui::GetIO().MouseDown[1] = true;
}
break;
case PlatformInterface::SystemEventHandler::MouseButton::MIDDLE:
@ -1124,7 +1109,7 @@ public:
m_mouse_x, m_mouse_y, Lumix::MouseButton::MIDDLE) &&
!m_app->m_gameview.isMouseCaptured())
{
m_gui->getIO().MouseDown[2] = true;
ImGui::GetIO().MouseDown[2] = true;
}
break;
}
@ -1137,15 +1122,15 @@ public:
{
case PlatformInterface::SystemEventHandler::MouseButton::LEFT:
m_app->m_sceneview.onMouseUp(Lumix::MouseButton::LEFT);
m_gui->getIO().MouseDown[0] = false;
ImGui::GetIO().MouseDown[0] = false;
break;
case PlatformInterface::SystemEventHandler::MouseButton::RIGHT:
m_app->m_sceneview.onMouseUp(Lumix::MouseButton::RIGHT);
m_gui->getIO().MouseDown[1] = false;
ImGui::GetIO().MouseDown[1] = false;
break;
case PlatformInterface::SystemEventHandler::MouseButton::MIDDLE:
m_app->m_sceneview.onMouseUp(Lumix::MouseButton::MIDDLE);
m_gui->getIO().MouseDown[2] = false;
ImGui::GetIO().MouseDown[2] = false;
break;
}
}
@ -1153,27 +1138,26 @@ public:
void onKeyDown(int key) override
{
m_gui->getIO().KeysDown[key] = true;
ImGui::GetIO().KeysDown[key] = true;
m_app->checkShortcuts();
}
void onKeyUp(int key) override
{
m_gui->getIO().KeysDown[key] = false;
ImGui::GetIO().KeysDown[key] = false;
}
void onChar(int key)
{
m_gui->getIO().AddInputCharacter(key);
ImGui::GetIO().AddInputCharacter(key);
}
int m_mouse_x;
int m_mouse_y;
StudioApp* m_app;
GUIInterface* m_gui;
};
@ -1243,7 +1227,7 @@ public:
{
if (ImGui::IsAnyItemActive()) return;
bool* keysDown = m_gui->getIO().KeysDown;
bool* keysDown = ImGui::GetIO().KeysDown;
for (auto* a : m_actions)
{
if (!a->is_global || a->shortcut[0] == -1) continue;
@ -1284,7 +1268,7 @@ public:
void clearInputs()
{
auto& io = m_gui->getIO();
auto& io = ImGui::GetIO();
io.KeyAlt = false;
io.KeyCtrl = false;
io.KeyShift = false;
@ -1295,8 +1279,8 @@ public:
void setGUIProjection()
{
float width = m_gui->getIO().DisplaySize.x;
float height = m_gui->getIO().DisplaySize.y;
float width = ImGui::GetIO().DisplaySize.x;
float height = ImGui::GetIO().DisplaySize.y;
Lumix::Matrix ortho;
ortho.setOrtho(0.0f, width, 0.0f, height, -1.0f, 1.0f);
m_gui_pipeline->setViewProjection(ortho, (int)width, (int)height);
@ -1394,7 +1378,6 @@ public:
ShaderCompiler* m_shader_compiler;
Lumix::string m_selected_template_name;
Settings m_settings;
GUIInterface* m_gui;
Metadata m_metadata;
ShaderEditor* m_shader_editor;
char m_template_name[100];

View file

@ -12,7 +12,7 @@
#include "core/timer.h"
#include "debug/debug.h"
#include "engine/engine.h"
#include "gui_interface.h"
#include "ocornut-imgui/imgui.h"
#include "utils.h"
@ -34,9 +34,6 @@ enum MemoryColumn
};
class GUIInterface;
struct ProfilerUIImpl : public ProfilerUI
{
ProfilerUIImpl(Lumix::Debug::Allocator& allocator, Lumix::Engine& engine)
@ -46,7 +43,6 @@ struct ProfilerUIImpl : public ProfilerUI
, m_opened_files(allocator)
, m_device(allocator)
, m_engine(engine)
, m_gui(nullptr)
{
m_viewed_thread_id = 0;
m_allocation_size_from = 0;
@ -201,7 +197,7 @@ struct ProfilerUIImpl : public ProfilerUI
void onGUIFileSystem()
{
if (!m_gui->collapsingHeader("File system")) return;
if (!ImGui::CollapsingHeader("File system")) return;
auto getter = [](void* data, int index) -> float {
auto* ui = (ProfilerUIImpl*)data;
int abs_index = (ui->m_current_transfer_rate + index) % Lumix::lengthOf(ui->m_transfer_rates);
@ -218,15 +214,15 @@ struct ProfilerUIImpl : public ProfilerUI
FLT_MAX,
ImVec2(0, 100));
m_gui->inputText("filter##fs_filter", m_filter, Lumix::lengthOf(m_filter));
ImGui::InputText("filter##fs_filter", m_filter, Lumix::lengthOf(m_filter));
if (m_gui->button("Clear")) m_logs.clear();
if (ImGui::Button("Clear")) m_logs.clear();
if (m_gui->beginChild("list"))
if (ImGui::BeginChild("list"))
{
m_gui->columns(3);
m_gui->text("File");
m_gui->nextColumn();
ImGui::Columns(3);
ImGui::Text("File");
ImGui::NextColumn();
const char* duration_label = "Duration (ms)";
if (m_sort_order == TIME_ASC) duration_label = "Duration (ms) < ";
@ -235,7 +231,7 @@ struct ProfilerUIImpl : public ProfilerUI
{
sortByDuration();
}
m_gui->nextColumn();
ImGui::NextColumn();
const char* bytes_read_label = "Bytes read (kB)";
if (m_sort_order == BYTES_READ_ASC) bytes_read_label = "Bytes read (kB) <";
@ -244,29 +240,23 @@ struct ProfilerUIImpl : public ProfilerUI
{
sortByBytesRead();
}
m_gui->nextColumn();
m_gui->separator();
ImGui::NextColumn();
ImGui::Separator();
for (auto& log : m_logs)
{
if (m_filter[0] == 0 || Lumix::stristr(log.path, m_filter) != 0)
{
m_gui->text(log.path);
m_gui->nextColumn();
m_gui->text("%f", log.time * 1000.0f);
m_gui->nextColumn();
m_gui->text("%.3f", (float)((double)log.bytes / 1000.0f));
m_gui->nextColumn();
ImGui::Text(log.path);
ImGui::NextColumn();
ImGui::Text("%f", log.time * 1000.0f);
ImGui::NextColumn();
ImGui::Text("%.3f", (float)((double)log.bytes / 1000.0f));
ImGui::NextColumn();
}
}
m_gui->columns(1);
ImGui::Columns(1);
}
m_gui->endChild();
}
void setGUIInterface(GUIInterface& gui) override
{
m_gui = &gui;
ImGui::EndChild();
}
@ -294,14 +284,14 @@ struct ProfilerUIImpl : public ProfilerUI
if (!m_is_opened) return;
if (m_gui->begin("Profiler", &m_is_opened))
if (ImGui::Begin("Profiler", &m_is_opened))
{
onGUICPUProfiler();
onGUIMemoryProfiler();
onGUIResources();
onGUIFileSystem();
}
m_gui->end();
ImGui::End();
}
@ -429,7 +419,6 @@ struct ProfilerUIImpl : public ProfilerUI
volatile int m_bytes_read;
float m_next_transfer_rate_time;
SortOrder m_sort_order;
GUIInterface* m_gui;
};
@ -612,7 +601,7 @@ void ProfilerUIImpl::showProfileBlock(Block* block, int column)
int hit_count = m_current_frame < 0 ? block->m_int_values.back()
: block->m_int_values[m_current_frame];
m_gui->text("%d", hit_count);
ImGui::Text("%d", hit_count);
if (block->m_is_opened)
{
showProfileBlock(block->m_first_child, column);
@ -673,9 +662,9 @@ void ProfilerUIImpl::saveResourceList()
void ProfilerUIImpl::onGUIResources()
{
if (!m_gui->collapsingHeader("Resources")) return;
if (!ImGui::CollapsingHeader("Resources")) return;
m_gui->inputText("filter##resource_filter", m_resource_filter, Lumix::lengthOf(m_resource_filter));
ImGui::InputText("filter##resource_filter", m_resource_filter, Lumix::lengthOf(m_resource_filter));
Lumix::uint32 manager_types[] = { Lumix::ResourceManager::ANIMATION,
Lumix::ResourceManager::MATERIAL,
@ -697,21 +686,21 @@ void ProfilerUIImpl::onGUIResources()
ImGui::Indent();
for (int i = 0; i < Lumix::lengthOf(manager_types); ++i)
{
if (!m_gui->collapsingHeader(manager_names[i])) continue;
if (!ImGui::CollapsingHeader(manager_names[i])) continue;
auto* material_manager = m_resource_manager.get(manager_types[i]);
auto& resources = material_manager->getResourceTable();
m_gui->columns(4, "resc");
m_gui->text("Path");
m_gui->nextColumn();
m_gui->text("Size");
m_gui->nextColumn();
m_gui->text("Status");
m_gui->nextColumn();
m_gui->text("References");
m_gui->nextColumn();
m_gui->separator();
ImGui::Columns(4, "resc");
ImGui::Text("Path");
ImGui::NextColumn();
ImGui::Text("Size");
ImGui::NextColumn();
ImGui::Text("Status");
ImGui::NextColumn();
ImGui::Text("References");
ImGui::NextColumn();
ImGui::Separator();
size_t sum = 0;
for (auto iter = resources.begin(), end = resources.end(); iter != end; ++iter)
{
@ -721,24 +710,24 @@ void ProfilerUIImpl::onGUIResources()
continue;
}
m_gui->text(iter.value()->getPath().c_str());
m_gui->nextColumn();
m_gui->text("%.3fKB", iter.value()->size() / 1024.0f);
ImGui::Text(iter.value()->getPath().c_str());
ImGui::NextColumn();
ImGui::Text("%.3fKB", iter.value()->size() / 1024.0f);
sum += iter.value()->size();
m_gui->nextColumn();
m_gui->text(getResourceStateString(iter.value()->getState()));
m_gui->nextColumn();
m_gui->text("%u", iter.value()->getRefCount());
m_gui->nextColumn();
ImGui::NextColumn();
ImGui::Text(getResourceStateString(iter.value()->getState()));
ImGui::NextColumn();
ImGui::Text("%u", iter.value()->getRefCount());
ImGui::NextColumn();
}
m_gui->separator();
m_gui->text("All");
m_gui->nextColumn();
m_gui->text("%.3fKB", sum / 1024.0f);
m_gui->nextColumn();
m_gui->nextColumn();
ImGui::Separator();
ImGui::Text("All");
ImGui::NextColumn();
ImGui::Text("%.3fKB", sum / 1024.0f);
ImGui::NextColumn();
ImGui::NextColumn();
m_gui->columns(1);
ImGui::Columns(1);
}
@ -747,9 +736,9 @@ void ProfilerUIImpl::onGUIResources()
if (saved_displayed > 0)
{
--saved_displayed;
m_gui->text("Saved");
ImGui::Text("Saved");
}
else if (m_gui->button("Save"))
else if (ImGui::Button("Save"))
{
saved_displayed = 180;
saveResourceList();
@ -857,7 +846,7 @@ void ProfilerUIImpl::showAllocationTree(AllocationStackNode* node, int column)
#ifdef _MSC_VER
char size[50];
Lumix::toCStringPretty(node->m_inclusive_size, size, sizeof(size));
m_gui->text(size);
ImGui::Text(size);
if (node->m_opened)
{
for (auto* child : node->m_children)
@ -871,39 +860,39 @@ void ProfilerUIImpl::showAllocationTree(AllocationStackNode* node, int column)
void ProfilerUIImpl::onGUIMemoryProfiler()
{
if (!m_gui->collapsingHeader("Memory")) return;
if (!ImGui::CollapsingHeader("Memory")) return;
if (m_gui->button("Refresh"))
if (ImGui::Button("Refresh"))
{
refreshAllocations();
}
m_gui->sameLine();
if (m_gui->button("Check memory"))
ImGui::SameLine();
if (ImGui::Button("Check memory"))
{
m_main_allocator.checkGuards();
}
m_gui->text("Total size: %.3fMB", (m_main_allocator.getTotalSize() / 1024) / 1024.0f);
ImGui::Text("Total size: %.3fMB", (m_main_allocator.getTotalSize() / 1024) / 1024.0f);
m_gui->columns(2, "memc");
ImGui::Columns(2, "memc");
for (auto* child : m_allocation_root->m_children)
{
showAllocationTree(child, FUNCTION);
}
m_gui->nextColumn();
ImGui::NextColumn();
for (auto* child : m_allocation_root->m_children)
{
showAllocationTree(child, SIZE);
}
m_gui->columns(1);
ImGui::Columns(1);
}
void ProfilerUIImpl::onGUICPUProfiler()
{
if (!m_gui->collapsingHeader("CPU")) return;
if (!ImGui::CollapsingHeader("CPU")) return;
if (m_gui->checkbox("Pause", &m_is_paused))
if (ImGui::Checkbox("Pause", &m_is_paused))
{
if (m_viewed_thread_id == 0 && !m_root)
{
@ -917,7 +906,7 @@ void ProfilerUIImpl::onGUICPUProfiler()
return true;
};
int thread_idx = Lumix::Profiler::getThreadIndex(m_viewed_thread_id);
m_gui->sameLine();
ImGui::SameLine();
if (ImGui::Combo("Thread", &thread_idx, thread_getter, nullptr, Lumix::Profiler::getThreadCount()))
{
m_viewed_thread_id = Lumix::Profiler::getThreadID(thread_idx);
@ -928,14 +917,14 @@ void ProfilerUIImpl::onGUICPUProfiler()
if (!m_root) return;
m_gui->columns(3, "cpuc");
ImGui::Columns(3, "cpuc");
showProfileBlock(m_root, NAME);
m_gui->nextColumn();
ImGui::NextColumn();
showProfileBlock(m_root, TIME);
m_gui->nextColumn();
ImGui::NextColumn();
showProfileBlock(m_root, HIT_COUNT);
m_gui->nextColumn();
m_gui->columns(1);
ImGui::NextColumn();
ImGui::Columns(1);
auto* block = m_current_block ? m_current_block : m_root;
float width = ImGui::GetWindowContentRegionWidth();

View file

@ -12,7 +12,6 @@ class ProfilerUI
public:
virtual ~ProfilerUI() {}
virtual void onGUI() = 0;
virtual void setGUIInterface(class GUIInterface& gui) = 0;
static ProfilerUI* create(Lumix::Engine& engine);
static void destroy(ProfilerUI& ui);

View file

@ -7,9 +7,9 @@
#include "editor/property_register.h"
#include "editor/world_editor.h"
#include "engine/engine.h"
#include "gui_interface.h"
#include "lua_script/lua_script_manager.h"
#include "lua_script/lua_script_system.h"
#include "ocornut-imgui/imgui.h"
#include "renderer/render_scene.h"
#include "terrain_editor.h"
#include "utils.h"
@ -66,14 +66,14 @@ void PropertyGrid::showProperty(Lumix::IPropertyDescriptor& desc, int index, Lum
auto& d = static_cast<Lumix::IDecimalPropertyDescriptor&>(desc);
if ((d.getMax() - d.getMin()) / d.getStep() <= 100)
{
if (m_gui->sliderFloat(desc_name, &f, d.getMin(), d.getMax()))
if (ImGui::SliderFloat(desc_name, &f, d.getMin(), d.getMax()))
{
m_editor.setProperty(cmp.type, index, desc, &f, sizeof(f));
}
}
else
{
if (m_gui->dragFloat(desc_name, &f, d.getStep(), d.getMin(), d.getMax()))
if (ImGui::DragFloat(desc_name, &f, d.getStep(), d.getMin(), d.getMax()))
{
m_editor.setProperty(cmp.type, index, desc, &f, sizeof(f));
}
@ -94,7 +94,7 @@ void PropertyGrid::showProperty(Lumix::IPropertyDescriptor& desc, int index, Lum
{
bool b;
tmp.read(b);
if (m_gui->checkbox(desc_name, &b))
if (ImGui::Checkbox(desc_name, &b))
{
m_editor.setProperty(cmp.type, index, desc, &b, sizeof(b));
}
@ -180,7 +180,7 @@ void PropertyGrid::showProperty(Lumix::IPropertyDescriptor& desc, int index, Lum
{
char buf[1024];
Lumix::copyString(buf, (const char*)stream.getData());
if (m_gui->inputText(desc_name, buf, sizeof(buf)))
if (ImGui::InputText(desc_name, buf, sizeof(buf)))
{
m_editor.setProperty(cmp.type, index, desc, buf, Lumix::stringLength(buf) + 1);
}
@ -336,21 +336,14 @@ void PropertyGrid::showSampledFunctionProperty(Lumix::ComponentUID cmp, Lumix::I
}
void PropertyGrid::setGUIInterface(GUIInterface& gui)
{
m_gui = &gui;
m_terrain_editor->setGUIInterface(gui);
}
void PropertyGrid::showArrayProperty(Lumix::ComponentUID cmp, Lumix::IArrayDescriptor& desc)
{
StringBuilder<100> desc_name(desc.getName(), "###", (Lumix::uint64)&desc);
if (!m_gui->collapsingHeader(desc_name, nullptr, true, true)) return;
if (!ImGui::CollapsingHeader(desc_name, nullptr, true, true)) return;
int count = desc.getCount(cmp);
if (m_gui->button("Add"))
if (ImGui::Button("Add"))
{
m_editor.addArrayPropertyItem(cmp, desc);
}
@ -362,8 +355,8 @@ void PropertyGrid::showArrayProperty(Lumix::ComponentUID cmp, Lumix::IArrayDescr
Lumix::toCString(i, tmp, sizeof(tmp));
if (ImGui::TreeNode(tmp))
{
m_gui->sameLine();
if (m_gui->button("Remove"))
ImGui::SameLine();
if (ImGui::Button("Remove"))
{
m_editor.removeArrayPropertyItem(cmp, i, desc);
--i;
@ -385,7 +378,7 @@ void PropertyGrid::showArrayProperty(Lumix::ComponentUID cmp, Lumix::IArrayDescr
void PropertyGrid::showComponentProperties(Lumix::ComponentUID cmp)
{
if (!m_gui->collapsingHeader(
if (!ImGui::CollapsingHeader(
getComponentTypeName(cmp), nullptr, true, true))
return;
@ -393,9 +386,9 @@ void PropertyGrid::showComponentProperties(Lumix::ComponentUID cmp)
if (!m_editor.canRemove(cmp))
{
m_gui->text("Remove dependents first.");
ImGui::Text("Remove dependents first.");
}
else if (m_gui->button(
else if (ImGui::Button(
StringBuilder<30>("Remove component##", cmp.type)))
{
m_editor.destroyComponent(cmp);
@ -438,15 +431,15 @@ bool PropertyGrid::entityInput(const char* label, const char* str_id, Lumix::Ent
char buf[50];
getEntityListDisplayName(m_editor, buf, sizeof(buf), entity);
ImGui::LabelText("", buf);
m_gui->sameLine();
ImGui::SameLine();
StringBuilder<30> popup_name("pu", str_id);
if (m_gui->button(StringBuilder<30>("...###br", str_id)))
if (ImGui::Button(StringBuilder<30>("...###br", str_id)))
{
ImGui::OpenPopup(popup_name);
}
m_gui->sameLine();
m_gui->text(label);
ImGui::SameLine();
ImGui::Text(label);
ImGui::PopItemWidth();
if (ImGui::BeginPopup(popup_name))
@ -491,21 +484,20 @@ bool PropertyGrid::entityInput(const char* label, const char* str_id, Lumix::Ent
void PropertyGrid::onParticleEmitterGUI(Lumix::ComponentUID cmp)
{
m_gui->separator();
m_gui->checkbox("Update", &m_particle_emitter_updating);
m_gui->sameLine();
auto* scene = static_cast<Lumix::RenderScene*>(cmp.scene);
if(m_gui->button("Reset"))
{
scene->resetParticleEmitter(cmp.index);
}
ImGui::Separator();
ImGui::Checkbox("Update", &m_particle_emitter_updating);
if (m_particle_emitter_updating)
{
m_gui->dragFloat("Timescale", &m_particle_emitter_timescale, 0.01f, 0.01f, 10000.0f);
ImGui::DragFloat("Timescale", &m_particle_emitter_timescale, 0.01f, 0.01f, 10000.0f);
float time_delta = m_editor.getEngine().getLastTimeDelta();
auto* scene = static_cast<Lumix::RenderScene*>(cmp.scene);
scene->updateEmitter(cmp.index, time_delta * m_particle_emitter_timescale);
scene->drawEmitterGizmo(cmp.index);
if(ImGui::Button("Reset"))
{
scene->resetParticleEmitter(cmp.index);
}
}
}
@ -525,7 +517,7 @@ void PropertyGrid::onLuaScriptGUI(Lumix::ComponentUID cmp)
case Lumix::LuaScript::Property::FLOAT:
{
float f = (float)atof(buf);
if (m_gui->dragFloat(property_name, &f))
if (ImGui::DragFloat(property_name, &f))
{
Lumix::toCString(f, buf, sizeof(buf), 5);
scene->setPropertyValue(cmp.index, property_name, buf);
@ -544,7 +536,7 @@ void PropertyGrid::onLuaScriptGUI(Lumix::ComponentUID cmp)
}
break;
case Lumix::LuaScript::Property::ANY:
if (m_gui->inputText(property_name, buf, sizeof(buf)))
if (ImGui::InputText(property_name, buf, sizeof(buf)))
{
scene->setPropertyValue(cmp.index, property_name, buf);
}
@ -559,7 +551,7 @@ void PropertyGrid::showCoreProperties(Lumix::Entity entity)
char name[256];
const char* tmp = m_editor.getUniverse()->getEntityName(entity);
Lumix::copyString(name, tmp);
if (m_gui->inputText("Name", name, sizeof(name)))
if (ImGui::InputText("Name", name, sizeof(name)))
{
m_editor.setEntityName(entity, name);
}
@ -585,7 +577,7 @@ void PropertyGrid::showCoreProperties(Lumix::Entity entity)
}
float scale = m_editor.getUniverse()->getScale(entity);
if (m_gui->dragFloat("Scale", &scale, 0.1f))
if (ImGui::DragFloat("Scale", &scale, 0.1f))
{
m_editor.setEntitiesScales(&entity, &scale, 1);
}
@ -597,9 +589,9 @@ void PropertyGrid::onGUI()
if (!m_is_opened) return;
auto& ents = m_editor.getSelectedEntities();
if (m_gui->begin("Properties", &m_is_opened) && ents.size() == 1)
if (ImGui::Begin("Properties", &m_is_opened) && ents.size() == 1)
{
if (m_gui->button("Add component"))
if (ImGui::Button("Add component"))
{
ImGui::OpenPopup("AddComponentPopup");
}
@ -625,7 +617,7 @@ void PropertyGrid::onGUI()
showComponentProperties(cmp);
}
}
m_gui->end();
ImGui::End();
}

View file

@ -17,7 +17,6 @@ namespace Lumix
struct Action;
class AssetBrowser;
class GUIInterface;
class PropertyGrid
@ -29,7 +28,6 @@ public:
~PropertyGrid();
void onGUI();
void setGUIInterface(GUIInterface& gui);
public:
bool m_is_opened;
@ -55,5 +53,4 @@ private:
float m_particle_emitter_timescale;
bool m_particle_emitter_updating;
GUIInterface* m_gui;
};

View file

@ -5,7 +5,7 @@
#include "editor/gizmo.h"
#include "editor/world_editor.h"
#include "engine/engine.h"
#include "gui_interface.h"
#include "ocornut-imgui/imgui.h"
#include "renderer/frame_buffer.h"
#include "renderer/pipeline.h"
#include "renderer/render_scene.h"
@ -20,7 +20,6 @@ SceneView::SceneView()
m_pipeline = nullptr;
m_editor = nullptr;
m_camera_speed = 0.1f;
m_gui = nullptr;
}
@ -29,12 +28,6 @@ SceneView::~SceneView()
}
void SceneView::setGUIInterface(GUIInterface& gui)
{
m_gui = &gui;
}
void SceneView::setWireframe(bool wireframe)
{
m_pipeline->setWireframe(wireframe);
@ -189,7 +182,7 @@ void SceneView::onGUI()
PROFILE_FUNCTION();
m_is_opened = false;
m_is_mouse_hovering_window = false;
if (m_gui->begin(WINDOW_NAME))
if (ImGui::Begin(WINDOW_NAME))
{
m_is_mouse_hovering_window = ImGui::IsMouseHoveringWindow();
m_is_opened = true;
@ -214,25 +207,25 @@ void SceneView::onGUI()
}
ImGui::PushItemWidth(60);
m_gui->dragFloat("Camera speed", &m_camera_speed, 0.1f, 0.01f, 999.0f, "%.2f");
m_gui->sameLine();
ImGui::DragFloat("Camera speed", &m_camera_speed, 0.1f, 0.01f, 999.0f, "%.2f");
ImGui::SameLine();
if (m_editor->isMeasureToolActive())
{
m_gui->text("| Measured distance: %f", m_editor->getMeasuredDistance());
ImGui::Text("| Measured distance: %f", m_editor->getMeasuredDistance());
}
m_gui->sameLine();
ImGui::SameLine();
int step = m_editor->getGizmo().getStep();
if (ImGui::DragInt("Gizmo step", &step, 1.0f, 0, 200))
{
m_editor->getGizmo().setStep(step);
}
m_gui->sameLine();
ImGui::SameLine();
int count = m_pipeline->getParameterCount();
if (count)
{
if (m_gui->button("Pipeline"))
if (ImGui::Button("Pipeline"))
{
ImGui::OpenPopup("pipeline_parameters_popup");
}
@ -242,7 +235,7 @@ void SceneView::onGUI()
for (int i = 0; i < count; ++i)
{
bool b = m_pipeline->getParameter(i);
if (m_gui->checkbox(m_pipeline->getParameterName(i), &b))
if (ImGui::Checkbox(m_pipeline->getParameterName(i), &b))
{
auto* settings = Settings::getInstance();
if (settings)
@ -257,5 +250,5 @@ void SceneView::onGUI()
}
}
m_gui->end();
ImGui::End();
}

View file

@ -14,16 +14,12 @@ namespace Lumix
}
class GUIInterface;
class SceneView
{
public:
SceneView();
~SceneView();
void setGUIInterface(GUIInterface& gui);
void update();
bool init(Lumix::WorldEditor& editor, Lumix::Array<Action*>& actions);
void setScene(Lumix::RenderScene* scene);
@ -52,5 +48,4 @@ class SceneView
Lumix::PipelineInstance* m_pipeline;
Lumix::Pipeline* m_pipeline_source;
bgfx::TextureHandle m_texture_handle;
GUIInterface* m_gui;
};

View file

@ -2,7 +2,7 @@
#include "core/fs/os_file.h"
#include "core/log.h"
#include "debug/debug.h"
#include "gui_interface.h"
#include "ocornut-imgui/imgui.h"
#include "platform_interface.h"
#include "utils.h"
#include <cstdio>
@ -13,7 +13,7 @@ static const char SETTINGS_PATH[] = "studio.ini";
static Settings* g_instance = nullptr;
static void shortcutInput(GUIInterface&gui, int& shortcut)
static void shortcutInput(int& shortcut)
{
StringBuilder<50> popup_name("");
popup_name << (Lumix::int64)&shortcut;
@ -24,9 +24,9 @@ static void shortcutInput(GUIInterface&gui, int& shortcut)
StringBuilder<50> button_label(key_string);
button_label << "##" << (Lumix::int64)&shortcut;
if (gui.button(button_label, ImVec2(50, 0))) shortcut = -1;
if (ImGui::Button(button_label, ImVec2(50, 0))) shortcut = -1;
auto& io = gui.getIO();
auto& io = ImGui::GetIO();
if (ImGui::IsItemHovered())
{
for (int i = 0; i < Lumix::lengthOf(ImGui::GetIO().KeysDown); ++i)
@ -81,7 +81,6 @@ Settings::Settings(Lumix::IAllocator& allocator)
: m_allocator(allocator)
{
ASSERT(!g_instance);
m_gui = nullptr;
g_instance = this;
m_filter[0] = 0;
m_is_maximized = true;
@ -115,12 +114,6 @@ Settings::~Settings()
}
void Settings::setGUIInterface(GUIInterface& gui)
{
m_gui = &gui;
}
bool Settings::load(Action** actions, int actions_count)
{
auto L = m_state;
@ -285,9 +278,9 @@ bool Settings::save(Action** actions, int actions_count)
file << "actions = {\n";
for (int i = 0; i < actions_count; ++i)
{
file << "\t" << actions[i]->name << " = {"
file << "\t" << actions[i]->name << " = {"
<< actions[i]->shortcut[0] << ", "
<< actions[i]->shortcut[1] << ", "
<< actions[i]->shortcut[1] << ", "
<< actions[i]->shortcut[2] << "},\n";
}
file << "}\n";
@ -300,24 +293,24 @@ bool Settings::save(Action** actions, int actions_count)
void Settings::showShortcutSettings(Action** actions, int actions_count)
{
m_gui->inputText("Filter", m_filter, Lumix::lengthOf(m_filter));
m_gui->columns(4);
ImGui::InputText("Filter", m_filter, Lumix::lengthOf(m_filter));
ImGui::Columns(4);
for (int i = 0; i < actions_count; ++i)
{
Action& a = *actions[i];
if (m_filter[0] == 0 || Lumix::stristr(a.label, m_filter) != 0)
{
m_gui->text(a.label);
m_gui->nextColumn();
shortcutInput(*m_gui, a.shortcut[0]);
m_gui->nextColumn();
shortcutInput(*m_gui, a.shortcut[1]);
m_gui->nextColumn();
shortcutInput(*m_gui, a.shortcut[2]);
m_gui->nextColumn();
ImGui::Text(a.label);
ImGui::NextColumn();
shortcutInput(a.shortcut[0]);
ImGui::NextColumn();
shortcutInput(a.shortcut[1]);
ImGui::NextColumn();
shortcutInput(a.shortcut[2]);
ImGui::NextColumn();
}
}
m_gui->columns(1);
ImGui::Columns(1);
}
@ -325,21 +318,21 @@ void Settings::onGUI(Action** actions, int actions_count)
{
if (!m_is_opened) return;
if (m_gui->begin("Settings", &m_is_opened))
if (ImGui::Begin("Settings", &m_is_opened))
{
if (m_gui->button("Save")) save(actions, actions_count);
m_gui->sameLine();
if (m_gui->button("Reload")) load(actions, actions_count);
m_gui->sameLine();
m_gui->text("Settings are saved when the application closes");
if (ImGui::Button("Save")) save(actions, actions_count);
ImGui::SameLine();
if (ImGui::Button("Reload")) load(actions, actions_count);
ImGui::SameLine();
ImGui::Text("Settings are saved when the application closes");
ImGui::DragInt("Autosave time (seconds)", &m_autosave_time);
if (m_gui->checkbox("Crash reporting", &m_is_crash_reporting_enabled))
if (ImGui::Checkbox("Crash reporting", &m_is_crash_reporting_enabled))
{
Lumix::enableCrashReporting(m_is_crash_reporting_enabled);
}
if (m_gui->collapsingHeader("Shortcuts")) showShortcutSettings(actions, actions_count);
if (ImGui::CollapsingHeader("Shortcuts")) showShortcutSettings(actions, actions_count);
}
m_gui->end();
ImGui::End();
}

View file

@ -9,7 +9,6 @@ namespace Lumix
struct Action;
class GUIInterface;
struct lua_State;
@ -48,7 +47,6 @@ struct Settings
static Settings* getInstance();
void setGUIInterface(GUIInterface& gui);
bool save(Action** actions, int actions_count);
bool load(Action** actions, int actions_count);
void onGUI(Action** actions, int actions_count);
@ -60,7 +58,6 @@ struct Settings
private:
Lumix::IAllocator& m_allocator;
lua_State* m_state;
GUIInterface* m_gui;
private:
void showShortcutSettings(Action** actions, int actions_count);

View file

@ -6,7 +6,6 @@
#include "core/math_utils.h"
#include "core/path_utils.h"
#include "core/string.h"
#include "gui_interface.h"
#include "platform_interface.h"
#include "utils.h"
#include <cstdio>
@ -271,7 +270,7 @@ struct VertexOutputNode : public ShaderEditor::Node
}
void onGUI(GUIInterface& gui) override
void onGUI() override
{
int idx = (int)m_output;
auto getter = [](void*, int idx, const char** out_text) -> bool
@ -341,7 +340,7 @@ struct VertexInputNode : public ShaderEditor::Node
void generate(Lumix::OutputBlob&) override {}
void onGUI(GUIInterface& gui) override
void onGUI() override
{
auto getter = [](void*, int idx, const char** out) -> bool
{
@ -476,10 +475,10 @@ ShaderEditor::ValueType ShaderEditor::Node::getInputType(int index) const
}
void ShaderEditor::Node::onNodeGUI(GUIInterface& gui)
void ShaderEditor::Node::onNodeGUI()
{
ImGui::PushItemWidth(120);
onGUI(gui);
onGUI();
ImGui::PopItemWidth();
}
@ -554,10 +553,10 @@ struct OperatorNode : public ShaderEditor::Node
}
}
void onGUI(GUIInterface& gui) override
void onGUI() override
{
gui.text("A");
gui.text("B");
ImGui::Text("A");
ImGui::Text("B");
int o = m_operation;
if (ImGui::Combo("Operation", &o, "Addition\0Subtraction\0Multiplication\0Division\0"))
{
@ -635,13 +634,13 @@ struct Vec4MergeNode : public ShaderEditor::Node
}
void onGUI(GUIInterface& gui) override
void onGUI() override
{
gui.text("xyz");
gui.text("x");
gui.text("y");
gui.text("z");
gui.text("w");
ImGui::Text("xyz");
ImGui::Text("x");
ImGui::Text("y");
ImGui::Text("z");
ImGui::Text("w");
}
};
@ -684,9 +683,9 @@ struct FunctionNode : public ShaderEditor::Node
}
void onGUI(GUIInterface& gui) override
void onGUI() override
{
gui.text("value");
ImGui::Text("value");
auto getter = [](void* data, int idx, const char** out_text) -> bool {
*out_text = FUNCTIONS[idx].gui_name;
@ -747,10 +746,10 @@ struct BinaryFunctionNode : public ShaderEditor::Node
}
void onGUI(GUIInterface& gui) override
void onGUI() override
{
gui.text("argument 1");
gui.text("argument 2");
ImGui::Text("argument 1");
ImGui::Text("argument 2");
auto getter = [](void* data, int idx, const char** out_text) -> bool {
*out_text = BINARY_FUNCTIONS[idx].gui_name;
@ -790,9 +789,9 @@ struct InstanceMatrixNode : public ShaderEditor::Node
}
void onGUI(GUIInterface& gui) override
void onGUI() override
{
gui.text("Instance matrix");
ImGui::Text("Instance matrix");
}
};
@ -817,7 +816,7 @@ struct FloatConstNode : public ShaderEditor::Node
blob << m_value;
}
void onGUI(GUIInterface& gui) override { gui.dragFloat("value", &m_value, 0.1f); }
void onGUI() override { ImGui::DragFloat("value", &m_value, 0.1f); }
float m_value;
};
@ -842,7 +841,7 @@ struct ColorConstNode : public ShaderEditor::Node
<< m_color[2] << ", " << m_color[3] << ");\n";
}
void onGUI(GUIInterface& gui) override { ImGui::ColorEdit4("value", m_color); }
void onGUI() override { ImGui::ColorEdit4("value", m_color); }
float m_color[4];
};
@ -876,9 +875,9 @@ struct SampleNode : public ShaderEditor::Node
blob << ");\n";
}
void onGUI(GUIInterface& gui) override
void onGUI() override
{
gui.text("UV");
ImGui::Text("UV");
auto getter = [](void* data, int idx, const char** out) -> bool
{
*out = ((SampleNode*)data)->m_editor.getTextureName(idx);
@ -918,7 +917,7 @@ struct FragmentInputNode : public ShaderEditor::Node
}
void onGUI(GUIInterface& gui) override
void onGUI() override
{
auto getter = [](void*, int idx, const char** out) -> bool
{
@ -960,7 +959,7 @@ struct PositionOutputNode : public ShaderEditor::Node
}
void onGUI(GUIInterface& gui) override { gui.text("Output position"); }
void onGUI() override { ImGui::Text("Output position"); }
};
@ -989,7 +988,7 @@ struct FragmentOutputNode : public ShaderEditor::Node
}
void onGUI(GUIInterface& gui) override { gui.text("OUTPUT"); }
void onGUI() override { ImGui::Text("OUTPUT"); }
};
@ -1030,11 +1029,11 @@ struct MixNode : public ShaderEditor::Node
blob << ");";
}
void onGUI(GUIInterface& gui) override
void onGUI() override
{
gui.text("Input 1");
gui.text("Input 2");
gui.text("Weight");
ImGui::Text("Input 1");
ImGui::Text("Input 2");
ImGui::Text("Weight");
}
};
@ -1058,7 +1057,7 @@ struct PassNode : public ShaderEditor::Node
ShaderEditor::ValueType getOutputType(int) const override
{
if (!m_inputs[0]) return ShaderEditor::ValueType::NONE;
int idx = m_inputs[0]->m_outputs.indexOf(this);
if (idx == -1) return ShaderEditor::ValueType::NONE;
@ -1084,11 +1083,11 @@ struct PassNode : public ShaderEditor::Node
}
}
void onGUI(GUIInterface& gui) override
void onGUI() override
{
gui.text("if defined");
gui.text("if not defined");
gui.inputText("Pass", m_pass, sizeof(m_pass));
ImGui::Text("if defined");
ImGui::Text("if not defined");
ImGui::InputText("Pass", m_pass, sizeof(m_pass));
}
char m_pass[50];
@ -1125,7 +1124,7 @@ struct BuiltinUniformNode : public ShaderEditor::Node
void generate(Lumix::OutputBlob&) override {}
void onGUI(GUIInterface& gui) override
void onGUI() override
{
auto getter = [](void* data, int index, const char** out_text) -> bool {
*out_text = BUILTIN_UNIFORMS[index].gui_name;
@ -1169,7 +1168,7 @@ struct UniformNode : public ShaderEditor::Node
void generate(Lumix::OutputBlob&) override {}
void onGUI(GUIInterface& gui) override
void onGUI() override
{
auto getter = [](void*, int idx, const char** out_text) -> bool {
*out_text = getValueTypeName((ShaderEditor::ValueType)idx);
@ -1178,7 +1177,7 @@ struct UniformNode : public ShaderEditor::Node
int tmp = (int)m_value_type;
ImGui::Combo("Type", &tmp, getter, this, (int)ShaderEditor::ValueType::COUNT);
m_value_type = (ShaderEditor::ValueType)tmp;
gui.inputText("Name", m_name, sizeof(m_name));
ImGui::InputText("Name", m_name, sizeof(m_name));
}
char m_name[50];
@ -1436,7 +1435,6 @@ ShaderEditor::ShaderEditor(Lumix::IAllocator& allocator)
, m_is_focused(false)
, m_is_opened(false)
, m_current_shader_type(ShaderType::VERTEX)
, m_gui(nullptr)
{
newGraph();
}
@ -1448,12 +1446,6 @@ ShaderEditor::~ShaderEditor()
}
void ShaderEditor::setGUIInterface(GUIInterface& gui)
{
m_gui = &gui;
}
ShaderEditor::Node* ShaderEditor::getNodeByID(int id)
{
for(auto* node : m_fragment_nodes)
@ -1862,7 +1854,7 @@ static ImVec2 operator-(const ImVec2& a, const ImVec2& b)
void ShaderEditor::onGUIRightColumn()
{
m_gui->beginChild("right_col");
ImGui::BeginChild("right_col");
if(ImGui::IsWindowHovered() && !ImGui::IsAnyItemActive() && ImGui::IsMouseDragging(2, 0.0f))
{
@ -1883,7 +1875,7 @@ void ShaderEditor::onGUIRightColumn()
auto node_screen_pos = cursor_screen_pos + node->m_pos + m_canvas_pos;
ImGui::BeginNode(node->m_id, node_screen_pos);
node->onNodeGUI(*m_gui);
node->onNodeGUI();
ImGui::EndNode(node_screen_pos);
if(ImGui::IsItemHovered() && ImGui::IsMouseDown(1))
{
@ -1965,50 +1957,50 @@ void ShaderEditor::onGUIRightColumn()
ImVec2 add_pos(ImGui::GetMousePos() - cursor_screen_pos - m_canvas_pos);
if(m_current_node_id >= 0)
{
if(m_gui->menuItem("Remove"))
if(ImGui::MenuItem("Remove"))
{
execute(LUMIX_NEW(m_allocator, RemoveNodeCommand)(m_current_node_id, m_current_shader_type, *this));
m_current_node_id = -1;
}
}
if (m_gui->beginMenu("Add"))
if (ImGui::BeginMenu("Add"))
{
for (auto node_type : NODE_TYPES)
{
if (!node_type.is_frag && m_current_shader_type == ShaderType::FRAGMENT) continue;
if (!node_type.is_vert && m_current_shader_type == ShaderType::VERTEX) continue;
if (m_gui->menuItem(node_type.name))
if (ImGui::MenuItem(node_type.name))
{
execute(LUMIX_NEW(m_allocator, CreateNodeCommand)(
-1, node_type.type, m_current_shader_type, add_pos, *this));
}
}
m_gui->endMenu();
ImGui::EndMenu();
}
ImGui::EndPopup();
}
m_gui->endChild();
ImGui::EndChild();
}
void ShaderEditor::onGUILeftColumn()
{
m_gui->beginChild("left_col", ImVec2(120, 0));
ImGui::BeginChild("left_col", ImVec2(120, 0));
ImGui::PushItemWidth(120);
m_gui->separator();
m_gui->text("Textures");
m_gui->separator();
ImGui::Separator();
ImGui::Text("Textures");
ImGui::Separator();
for (int i = 0; i < Lumix::lengthOf(m_textures); ++i)
{
m_gui->inputText(StringBuilder<10>("###tex", i), m_textures[i], sizeof(m_textures[i]));
ImGui::InputText(StringBuilder<10>("###tex", i), m_textures[i], sizeof(m_textures[i]));
}
ImGui::PopItemWidth();
m_gui->endChild();
ImGui::EndChild();
}
@ -2190,25 +2182,25 @@ void ShaderEditor::onGUIMenu()
{
if(ImGui::BeginMenuBar())
{
if(m_gui->beginMenu("File"))
if(ImGui::BeginMenu("File"))
{
if (m_gui->menuItem("New")) newGraph();
if (m_gui->menuItem("Open")) load();
if (m_gui->menuItem("Save", nullptr, false, m_path.isValid())) save(m_path.c_str());
if (m_gui->menuItem("Save as"))
if (ImGui::MenuItem("New")) newGraph();
if (ImGui::MenuItem("Open")) load();
if (ImGui::MenuItem("Save", nullptr, false, m_path.isValid())) save(m_path.c_str());
if (ImGui::MenuItem("Save as"))
{
getSavePath();
if (m_path.isValid()) save(m_path.c_str());
}
m_gui->endMenu();
ImGui::EndMenu();
}
if (m_gui->beginMenu("Edit"))
if (ImGui::BeginMenu("Edit"))
{
if (m_gui->menuItem("Undo", nullptr, false, canUndo())) undo();
if (m_gui->menuItem("Redo", nullptr, false, canRedo())) redo();
m_gui->endMenu();
if (ImGui::MenuItem("Undo", nullptr, false, canUndo())) undo();
if (ImGui::MenuItem("Redo", nullptr, false, canRedo())) redo();
ImGui::EndMenu();
}
if (m_gui->menuItem("Generate", nullptr, false, m_path.isValid()))
if (ImGui::MenuItem("Generate", nullptr, false, m_path.isValid()))
{
generate(m_path.c_str(), ShaderType::VERTEX);
generate(m_path.c_str(), ShaderType::FRAGMENT);
@ -2226,14 +2218,14 @@ void ShaderEditor::onGUI()
StringBuilder<Lumix::MAX_PATH_LENGTH + 25> title("Shader editor");
if (m_path.isValid()) title << " - " << m_path.c_str();
title << "###Shader editor";
if (m_gui->begin(title, &m_is_opened, ImGuiWindowFlags_MenuBar))
if (ImGui::Begin(title, &m_is_opened, ImGuiWindowFlags_MenuBar))
{
m_is_focused = ImGui::IsRootWindowOrAnyChildFocused();
onGUIMenu();
onGUILeftColumn();
m_gui->sameLine();
ImGui::SameLine();
onGUIRightColumn();
}
m_gui->end();
ImGui::End();
}

View file

@ -13,9 +13,6 @@ namespace Lumix
}
class GUIInterface;
class ShaderEditor
{
public:
@ -58,7 +55,7 @@ public:
virtual ~Node();
ValueType getInputType(int index) const;
void onNodeGUI(GUIInterface& gui);
void onNodeGUI();
ImGuiID m_id;
ImVec2 m_pos;
@ -69,7 +66,7 @@ public:
ShaderEditor& m_editor;
protected:
virtual void onGUI(GUIInterface& gui) = 0;
virtual void onGUI() = 0;
};
public:
@ -77,7 +74,6 @@ public:
~ShaderEditor();
void onGUI();
void setGUIInterface(GUIInterface& gui);
const char* getTextureName(int index) const { return m_textures[index]; }
Lumix::IAllocator& getAllocator() { return m_allocator; }
Node* createNode(int type);
@ -139,5 +135,4 @@ private:
ShaderType m_current_shader_type;
bool m_is_focused;
ImVec2 m_canvas_pos;
GUIInterface* m_gui;
};

View file

@ -11,7 +11,7 @@
#include "editor/iproperty_descriptor.h"
#include "editor/property_register.h"
#include "engine.h"
#include "gui_interface.h"
#include "ocornut-imgui/imgui.h"
#include "platform_interface.h"
#include "renderer/material.h"
#include "renderer/model.h"
@ -1151,7 +1151,6 @@ TerrainEditor::TerrainEditor(Lumix::WorldEditor& editor, Lumix::Array<Action*>&
, m_brush_texture(nullptr)
, m_flat_height(0)
, m_is_enabled(false)
, m_gui(nullptr)
{
editor.registerEditorCommandCreator("paint_entities_on_terrain", createPaintEntitiesCommand);
editor.registerEditorCommandCreator("remove_entities_on_terrain", createRemoveEntitiesCommand);
@ -1204,12 +1203,6 @@ TerrainEditor::TerrainEditor(Lumix::WorldEditor& editor, Lumix::Array<Action*>&
}
void TerrainEditor::setGUIInterface(GUIInterface& gui)
{
m_gui = &gui;
}
void TerrainEditor::nextTerrainTexture()
{
auto* scene = static_cast<Lumix::RenderScene*>(m_component.scene);
@ -1535,18 +1528,18 @@ void TerrainEditor::onGUI()
if (m_decrease_texture_idx->isRequested()) m_decrease_texture_idx->func.invoke();
auto* scene = static_cast<Lumix::RenderScene*>(m_component.scene);
if (!m_gui->collapsingHeader("Terrain editor", nullptr, true, true)) return;
if (!ImGui::CollapsingHeader("Terrain editor", nullptr, true, true)) return;
m_gui->checkbox("Editor enabled", &m_is_enabled);
ImGui::Checkbox("Editor enabled", &m_is_enabled);
if (!m_is_enabled) return;
if (!getMaterial())
{
m_gui->text("No heightmap");
ImGui::Text("No heightmap");
return;
}
m_gui->sliderFloat("Brush size", &m_terrain_brush_size, MIN_BRUSH_SIZE, 100);
m_gui->sliderFloat("Brush strength", &m_terrain_brush_strength, 0, 1.0f);
ImGui::SliderFloat("Brush size", &m_terrain_brush_size, MIN_BRUSH_SIZE, 100);
ImGui::SliderFloat("Brush strength", &m_terrain_brush_strength, 0, 1.0f);
enum BrushType
{
@ -1558,7 +1551,7 @@ void TerrainEditor::onGUI()
bool is_grass_enabled = scene->isGrassEnabled();
if (m_gui->checkbox("Enable grass", &is_grass_enabled)) scene->enableGrass(is_grass_enabled);
if (ImGui::Checkbox("Enable grass", &is_grass_enabled)) scene->enableGrass(is_grass_enabled);
if (ImGui::Combo(
"Brush type", &m_current_brush, "Height\0Layer\0Entity\0Color\0"))
@ -1569,15 +1562,15 @@ void TerrainEditor::onGUI()
switch (m_current_brush)
{
case HEIGHT:
if (m_gui->button("Save heightmap"))
if (ImGui::Button("Save heightmap"))
getMaterial()->getTextureByUniform(HEIGHTMAP_UNIFORM)->save();
break;
case LAYER:
if (m_gui->button("Save layermap"))
if (ImGui::Button("Save layermap"))
getMaterial()->getTextureByUniform(SPLATMAP_UNIFORM)->save();
break;
case COLOR:
if (m_gui->button("Save colormap"))
if (ImGui::Button("Save colormap"))
getMaterial()->getTextureByUniform(COLORMAP_UNIFORM)->save();
break;
}
@ -1588,18 +1581,18 @@ void TerrainEditor::onGUI()
{
static auto th = m_brush_texture->getTextureHandle();
ImGui::Image(&th, ImVec2(100, 100));
if (m_gui->button("Clear mask"))
if (ImGui::Button("Clear mask"))
{
m_brush_texture->destroy();
LUMIX_DELETE(m_world_editor.getAllocator(), m_brush_texture);
m_brush_mask.clear();
m_brush_texture = nullptr;
}
m_gui->sameLine();
ImGui::SameLine();
}
m_gui->sameLine();
if (m_gui->button("Select mask"))
ImGui::SameLine();
if (ImGui::Button("Select mask"))
{
char filename[Lumix::MAX_PATH_LENGTH];
if (PlatformInterface::getOpenFilename(filename, Lumix::lengthOf(filename), "All\0*.*\0"))
@ -1642,15 +1635,15 @@ void TerrainEditor::onGUI()
case HEIGHT:
{
bool is_flat_tool = m_type == TerrainEditor::FLAT_HEIGHT;
if (m_gui->checkbox("Flat", &is_flat_tool))
if (ImGui::Checkbox("Flat", &is_flat_tool))
{
m_type = is_flat_tool ? TerrainEditor::FLAT_HEIGHT : TerrainEditor::RAISE_HEIGHT;
}
if (m_type == TerrainEditor::FLAT_HEIGHT)
{
m_gui->sameLine();
m_gui->text("- Press Ctrl to pick height");
ImGui::SameLine();
ImGui::Text("- Press Ctrl to pick height");
}
break;
}
@ -1668,7 +1661,7 @@ void TerrainEditor::onGUI()
{
for (int i = 0; i < tex->getAtlasSize() * tex->getAtlasSize(); ++i)
{
if (i % 4 != 0) m_gui->sameLine();
if (i % 4 != 0) ImGui::SameLine();
if (ImGui::RadioButton(StringBuilder<20>("", i, "###rb", i), m_texture_idx == i))
{
m_texture_idx = i;
@ -1684,7 +1677,7 @@ void TerrainEditor::onGUI()
auto& template_names = template_system.getTemplateNames();
if (template_names.empty())
{
m_gui->text("No templates, please create one.");
ImGui::Text("No templates, please create one.");
}
else
{
@ -1700,16 +1693,16 @@ void TerrainEditor::onGUI()
&template_names,
template_names.size());
}
if (m_gui->checkbox("Align with normal", &m_is_align_with_normal))
if (ImGui::Checkbox("Align with normal", &m_is_align_with_normal))
{
if (m_is_align_with_normal) m_is_rotate_x = m_is_rotate_z = false;
}
if (m_gui->checkbox("Rotate around X", &m_is_rotate_x))
if (ImGui::Checkbox("Rotate around X", &m_is_rotate_x))
{
if (m_is_rotate_x) m_is_align_with_normal = false;
}
m_gui->sameLine();
if (m_gui->checkbox("Rotate around Z", &m_is_rotate_z))
ImGui::SameLine();
if (ImGui::Checkbox("Rotate around Z", &m_is_rotate_z))
{
if (m_is_rotate_z) m_is_align_with_normal = false;
}

View file

@ -15,9 +15,6 @@ class Texture;
}
class GUIInterface;
class TerrainEditor : public Lumix::WorldEditor::Plugin
{
public:
@ -37,7 +34,6 @@ public:
TerrainEditor(Lumix::WorldEditor& editor, Lumix::Array<Action*>& actions);
~TerrainEditor();
void setGUIInterface(GUIInterface& gui);
void tick() override;
bool onEntityMouseDown(const Lumix::RayCastModelHit& hit, int, int) override;
void onMouseMove(int x, int y, int /*rel_x*/, int /*rel_y*/) override;
@ -91,5 +87,4 @@ private:
bool m_is_rotate_x;
bool m_is_rotate_z;
bool m_is_enabled;
GUIInterface* m_gui;
};