summaryrefslogtreecommitdiff
path: root/editor.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'editor.cpp')
-rw-r--r--editor.cpp65
1 files changed, 61 insertions, 4 deletions
diff --git a/editor.cpp b/editor.cpp
index 5b96db6..698b5ff 100644
--- a/editor.cpp
+++ b/editor.cpp
@@ -5,11 +5,16 @@
#include "ui.hpp"
#include "world.hpp"
+extern "C" {
+#include "memory.h"
+}
+
static struct {
+ Editor_Settings settings;
UI* ui;
UI::Toolbar* toolbar;
- UI::Button* mat_btn, * ent_btn;
- UI::Modal* mat_win, * ent_win;
+ UI::Button* mat_btn, * ent_btn, * phy_btn;
+ UI::Modal* mat_win, * ent_win, * phy_win;
UI::Label* mat_name;
UI::Slider* metalness_input;
UI::Slider* roughness_input;
@@ -131,8 +136,7 @@ static int mat_btn_handler(UI::Element* e, const UI::Message& m) {
return 0;
}
-static int ent_win_handler(UI::Element* e, const UI::Message& m) {
- (void)e;
+static int ent_win_handler(UI::Element* e, const UI::Message& m) { (void)e;
if (m.type == UI::Message::Type::destroy) {
editor.ent_btn->enable();
editor.ent_win = 0;
@@ -141,6 +145,7 @@ static int ent_win_handler(UI::Element* e, const UI::Message& m) {
}
static int ent_btn_handler(UI::Element* e, const UI::Message& m) {
+ (void)e;
if (m.type == UI::Message::Type::click) {
auto ui = editor.ui;
editor.ent_win = ui->create_element<UI::Modal>(
@@ -167,6 +172,47 @@ static int ent_btn_handler(UI::Element* e, const UI::Message& m) {
return 0;
}
+static int phy_win_handler(UI::Element* e, const UI::Message& m) { (void)e;
+ if (m.type == UI::Message::Type::destroy) {
+ editor.phy_btn->enable();
+ editor.phy_win = 0;
+ }
+ return 0;
+}
+
+static int phy_btn_handler(UI::Element* e, const UI::Message& m) {
+ (void)e;
+ if (m.type == UI::Message::Type::click) {
+ auto ui = editor.ui;
+ editor.phy_win = ui->create_element<UI::Modal>(
+ editor.ui->root,
+ "Physics Debugger"
+ );
+ auto cont = editor.phy_win->contents;
+ editor.phy_win->handler = phy_win_handler;
+ editor.phy_btn->disable();
+ auto cdebug = ui->create_element<UI::Checkbox>(cont, "Debug Draw");
+ cdebug->handler = [](UI::Element* e, const UI::Message& m) {
+ if (m.type == UI::Message::Type::checkbox_changed) {
+ UI::Checkbox* ch = (UI::Checkbox*)e;
+ editor.settings.debug_physics = ch->val;
+ }
+ return 0;
+ };
+ cdebug->set_val(editor.settings.debug_physics);
+ auto cpause = ui->create_element<UI::Checkbox>(cont, "Pause");
+ cpause->set_val(editor.settings.pause_physics);
+ cpause->handler = [](UI::Element* e, const UI::Message& m) {
+ if (m.type == UI::Message::Type::checkbox_changed) {
+ UI::Checkbox* ch = (UI::Checkbox*)e;
+ editor.settings.pause_physics = ch->val;
+ }
+ return 0;
+ };
+ }
+ return 0;
+}
+
void init_editor(UI* ui, World* world) {
editor.ui = ui;
editor.toolbar = ui->create_element<UI::Toolbar>(ui->root);
@@ -180,9 +226,16 @@ void init_editor(UI* ui, World* world) {
"Entity Debugger"
);
editor.ent_btn->handler = ent_btn_handler;
+ editor.phy_btn = ui->create_element<UI::Button>(
+ editor.toolbar,
+ "Physics Debugger"
+ );
+ editor.phy_btn->handler = phy_btn_handler;
editor.mat_win = 0;
editor.ent_win = 0;
+ editor.phy_win = 0;
editor.world = world;
+ zero(&editor.settings, sizeof editor.settings);
}
void deinit_editor() {
@@ -215,3 +268,7 @@ void editor_draw(Line_Renderer& lr) {
);
}
}
+
+Editor_Settings& editor_settings() {
+ return editor.settings;
+}