tmp
This commit is contained in:
parent
2160dfca34
commit
8171ba03da
7 changed files with 135 additions and 56 deletions
|
|
@ -12,7 +12,9 @@ public:
|
|||
EditorGUI() {
|
||||
Vec2F renderResolution = { 1000, 1000 };
|
||||
auto canvas = this->mGraphics->getCanvas();
|
||||
mGui = new EditorWidget<EventHandler, Canvas>(canvas, &geometry, renderResolution);
|
||||
// mGui = new EditorWidget<EventHandler, Canvas>(canvas, &geometry, renderResolution);
|
||||
|
||||
mGui = new ShortcutsTest<EventHandler, Canvas>();
|
||||
|
||||
loadMeshes(geometry, "rsc/scene.obj");
|
||||
|
||||
|
|
@ -30,15 +32,10 @@ public:
|
|||
|
||||
private:
|
||||
Scene geometry;
|
||||
EditorWidget<EventHandler, Canvas>* mGui;
|
||||
ShortcutsTest<EventHandler, Canvas>* mGui;
|
||||
};
|
||||
|
||||
int main() {
|
||||
GlobalGUIConfig mConfig;
|
||||
gGlobalGUIConfig = &mConfig;
|
||||
|
||||
{
|
||||
EditorGUI gui;
|
||||
gui.run();
|
||||
}
|
||||
EditorGUI gui;
|
||||
gui.run();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,14 +2,48 @@
|
|||
#include "Render.hpp"
|
||||
|
||||
namespace tp {
|
||||
|
||||
template <typename Events, typename Canvas>
|
||||
class ShortcutsTest : public Widget<Events, Canvas> {
|
||||
public:
|
||||
ShortcutsTest() { this->createConfig("ShortcutsTest"); }
|
||||
|
||||
void action(const Events&) {
|
||||
//
|
||||
}
|
||||
|
||||
void proc(const Events& events, const RectF& areaParent, const RectF& aArea) override {
|
||||
this->mArea = aArea;
|
||||
this->mVisible = areaParent.isOverlap(aArea);
|
||||
if (!this->mVisible) return;
|
||||
}
|
||||
|
||||
void draw(Canvas& canvas) override {
|
||||
if (!this->mVisible) return;
|
||||
canvas.rect(this->mArea, this->getColor("Base"));
|
||||
}
|
||||
|
||||
void populateConfig() override {
|
||||
this->addColor("Base", "Base");
|
||||
|
||||
this->addOperator("OperatorName", { this, [](void* self, const Events& events) {
|
||||
((ShortcutsTest*) self)->action(events);
|
||||
} });
|
||||
|
||||
this->getShortcuts("OperatorName").append({ { "Alt", "Hold" }, { "Mouse1", "Hold" } });
|
||||
this->getShortcuts("OperatorName").append({ { "Alt", "Hold" }, { "Mouse1", "Hold" } });
|
||||
}
|
||||
};
|
||||
|
||||
template <typename Events, typename Canvas>
|
||||
class ViewportWidget : public Widget<Events, Canvas> {
|
||||
public:
|
||||
explicit ViewportWidget(Canvas* canvas, Scene* geometry, Vec2F renderResolution) :
|
||||
mRender(renderResolution) {
|
||||
mGeometry = geometry;
|
||||
this->createConfig("ViewportWidget");
|
||||
|
||||
mImage = canvas->createImageFromTextId(mRender.getRenderBuffer(), mRender.getBufferSize());
|
||||
mGeometry = geometry;
|
||||
mCanvas = canvas;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -11,7 +11,12 @@ namespace tp {
|
|||
return hash(key);
|
||||
}
|
||||
|
||||
template <typename tKey, typename tVal, class tAllocator = DefaultAllocator, ualni (*tHashFunc)(SelectValueOrReference<tKey>) = DefaultHashFunc<tKey>, int tTableInitialSize = 4>
|
||||
template <
|
||||
typename tKey,
|
||||
typename tVal,
|
||||
class tAllocator = DefaultAllocator,
|
||||
ualni (*tHashFunc)(SelectValueOrReference<tKey>) = DefaultHashFunc<tKey>,
|
||||
int tTableInitialSize = 4>
|
||||
class Map {
|
||||
|
||||
enum {
|
||||
|
|
@ -223,6 +228,13 @@ namespace tp {
|
|||
return mTable[slot]->val;
|
||||
}
|
||||
|
||||
tVal& operator[](KeyArg key) {
|
||||
auto idx = presents(key);
|
||||
if (idx.isValid()) return getSlotVal(idx);
|
||||
put(key, {});
|
||||
return get(key);
|
||||
}
|
||||
|
||||
tVal& getSlotVal(ualni slot) {
|
||||
DEBUG_ASSERT(slot < mNSlots && (mTable[slot] && !isDeletedNode(mTable[slot])) && "Key Error")
|
||||
return mTable[slot]->val;
|
||||
|
|
|
|||
|
|
@ -10,22 +10,17 @@ public:
|
|||
ExampleGUI() = default;
|
||||
|
||||
void processFrame(EventHandler* eventHandler) override {
|
||||
auto rec = RectF( { 0, 0 }, mWindow->getSize() );
|
||||
auto rec = RectF({ 0, 0 }, mWindow->getSize());
|
||||
mGui.proc(*eventHandler, rec, rec);
|
||||
}
|
||||
|
||||
void drawFrame(Canvas* canvas) override {
|
||||
mGui.draw(*canvas);
|
||||
}
|
||||
void drawFrame(Canvas* canvas) override { mGui.draw(*canvas); }
|
||||
|
||||
private:
|
||||
ComplexWidget<EventHandler, Canvas> mGui;
|
||||
};
|
||||
|
||||
int main() {
|
||||
GlobalGUIConfig mConfig;
|
||||
gGlobalGUIConfig = &mConfig;
|
||||
|
||||
{
|
||||
ExampleGUI gui;
|
||||
gui.run();
|
||||
|
|
|
|||
|
|
@ -3,6 +3,4 @@
|
|||
|
||||
#include "Graphics.hpp"
|
||||
|
||||
namespace tp {
|
||||
GlobalGUIConfig* gGlobalGUIConfig = nullptr;
|
||||
}
|
||||
namespace tp {}
|
||||
|
|
@ -1,3 +1,4 @@
|
|||
;
|
||||
#pragma once
|
||||
|
||||
#include "WidgetConfig.hpp"
|
||||
|
|
@ -7,39 +8,47 @@ namespace tp {
|
|||
template <typename Events, typename Canvas>
|
||||
class Widget {
|
||||
public:
|
||||
Widget() {
|
||||
this->mArea = { 0, 0, 100, 100 };
|
||||
}
|
||||
using WidgetConfig = WidgetConfig<Events, Canvas>;
|
||||
using WidgetNode = WidgetConfig::Node;
|
||||
using GlobalGUIConfig = GlobalGUIConfig<Events, Canvas>;
|
||||
|
||||
Widget() { this->mArea = { 0, 0, 100, 100 }; }
|
||||
|
||||
virtual void populateConfig() {}
|
||||
|
||||
[[nodiscard]] const RGBA& getColor(const std::string& name) const {
|
||||
const auto& node = cfg->values.get(name);
|
||||
if (node.type == WidgetConfig::Node::REF) {
|
||||
return globalCfg->configs.get(node.refGroup).values.get(node.refName).color;
|
||||
if (node.type == WidgetNode::REF) {
|
||||
return mGlobalCfg.configs.get(node.refGroup).values.get(node.refName).color;
|
||||
}
|
||||
return cfg->values.get(name).color;
|
||||
}
|
||||
|
||||
[[nodiscard]] halnf getValue(const std::string& name) const {
|
||||
const auto& node = cfg->values.get(name);
|
||||
if (node.type == WidgetConfig::Node::REF) {
|
||||
return globalCfg->configs.get(node.refGroup).values.get(node.refName).value;
|
||||
if (node.type == WidgetNode::REF) {
|
||||
return mGlobalCfg.configs.get(node.refGroup).values.get(node.refName).value;
|
||||
}
|
||||
return cfg->values.get(name).value;
|
||||
}
|
||||
|
||||
void addColor(const std::string& name, const RGBA& val) { cfg->values.put(name, WidgetConfig::Node(val)); }
|
||||
void addValue(const std::string& name, halnf val) { cfg->values.put(name, WidgetConfig::Node(val)); }
|
||||
void addColor(const std::string& name, const RGBA& val) { cfg->values.put(name, WidgetNode(val)); }
|
||||
void addValue(const std::string& name, halnf val) { cfg->values.put(name, WidgetNode(val)); }
|
||||
|
||||
void addColor(const std::string& name, const std::string& presetName) {
|
||||
cfg->values.put(name, WidgetConfig::Node(presetName));
|
||||
cfg->values.put(name, WidgetNode(presetName));
|
||||
}
|
||||
void addValue(const std::string& name, const std::string& presetName) {
|
||||
cfg->values.put(name, WidgetConfig::Node(presetName));
|
||||
cfg->values.put(name, WidgetNode(presetName));
|
||||
}
|
||||
|
||||
void createConfig(const std::string& name) {
|
||||
globalCfg->configs.put(name, {});
|
||||
cfg = &globalCfg->configs.get(name);
|
||||
bool createConfig(const std::string& name) {
|
||||
auto idx = mGlobalCfg.configs.presents(name);
|
||||
if (idx) return false;
|
||||
mGlobalCfg.configs.put(name, {});
|
||||
cfg = &mGlobalCfg.configs.get(name);
|
||||
populateConfig();
|
||||
return true;
|
||||
}
|
||||
|
||||
virtual void proc(const Events& events, const tp::RectF& areaParent, const tp::RectF& aArea) {
|
||||
|
|
@ -57,10 +66,19 @@ namespace tp {
|
|||
}
|
||||
}
|
||||
|
||||
void addOperator(const std::string& name, WidgetConfig::WidgetCallback callback) {
|
||||
cfg->mOperators.put(name, callback);
|
||||
}
|
||||
|
||||
Buffer<WidgetShortcut>& getShortcuts(const std::string& name) { return cfg->mShortcuts[name]; }
|
||||
|
||||
public:
|
||||
GlobalGUIConfig* globalCfg = gGlobalGUIConfig;
|
||||
static GlobalGUIConfig mGlobalCfg;
|
||||
WidgetConfig* cfg = nullptr;
|
||||
RectF mArea;
|
||||
bool mVisible = false;
|
||||
};
|
||||
|
||||
template <typename Events, typename Canvas>
|
||||
GlobalGUIConfig<Events, Canvas> Widget<Events, Canvas>::mGlobalCfg;
|
||||
}
|
||||
|
|
@ -5,10 +5,29 @@
|
|||
#include "Rect.hpp"
|
||||
|
||||
#include "InputCodes.hpp"
|
||||
#include "Buffer.hpp"
|
||||
|
||||
namespace tp {
|
||||
|
||||
struct WidgetShortcut {
|
||||
struct Condition {
|
||||
std::string name;
|
||||
std::string state;
|
||||
};
|
||||
|
||||
WidgetShortcut() = default;
|
||||
WidgetShortcut(const InitialierList<Condition>&) {}
|
||||
};
|
||||
|
||||
template <typename Events, typename Canvas>
|
||||
struct WidgetConfig {
|
||||
|
||||
struct WidgetCallback {
|
||||
using CallbackType = void (*)(void* self, const Events&);
|
||||
void* self;
|
||||
CallbackType callback;
|
||||
};
|
||||
|
||||
struct Node {
|
||||
enum Type { NONE, VAL, COL, REF };
|
||||
|
||||
|
|
@ -40,34 +59,40 @@ namespace tp {
|
|||
};
|
||||
|
||||
Map<std::string, Node> values;
|
||||
Map<std::string, WidgetCallback> mOperators;
|
||||
Map<std::string, Buffer<WidgetShortcut>> mShortcuts;
|
||||
};
|
||||
|
||||
template <typename Events, typename Canvas>
|
||||
struct GlobalGUIConfig {
|
||||
using WidgetConfig = WidgetConfig<Events, Canvas>;
|
||||
using WidgetNode = WidgetConfig::Node;
|
||||
|
||||
GlobalGUIConfig() {
|
||||
configs.put("Presets", {});
|
||||
auto& presets = configs.get("Presets");
|
||||
|
||||
presets.values.put("FontSize", WidgetConfig::Node(15.f));
|
||||
presets.values.put("FontSizeDim", WidgetConfig::Node(12.f));
|
||||
presets.values.put("Rounding", WidgetConfig::Node(5.f));
|
||||
presets.values.put("Padding", WidgetConfig::Node(5.f));
|
||||
presets.values.put("HandleSize", WidgetConfig::Node(5.f));
|
||||
presets.values.put("FontSize", WidgetNode(15.f));
|
||||
presets.values.put("FontSizeDim", WidgetNode(12.f));
|
||||
presets.values.put("Rounding", WidgetNode(5.f));
|
||||
presets.values.put("Padding", WidgetNode(5.f));
|
||||
presets.values.put("HandleSize", WidgetNode(5.f));
|
||||
|
||||
presets.values.put("Background", WidgetConfig::Node(RGBA{ 0.03f, 0.03f, 0.03f, 1.f }));
|
||||
presets.values.put("Base", WidgetConfig::Node(RGBA{ 0.07f, 0.07f, 0.07f, 1.f }));
|
||||
presets.values.put("Accent", WidgetConfig::Node(RGBA{ 0.13f, 0.13f, 0.13f, 1.f }));
|
||||
presets.values.put("Interaction", WidgetConfig::Node(RGBA{ 0.33f, 0.33f, 0.3f, 1.f }));
|
||||
presets.values.put("Action", WidgetConfig::Node(RGBA{ 0.44f, 0.44f, 0.4f, 1.f }));
|
||||
presets.values.put("Front", WidgetConfig::Node(RGBA{ 1.f, 1.f, 1.f, 1.f }));
|
||||
presets.values.put("FrontDim", WidgetConfig::Node(RGBA{ 0.7f, 0.7f, 0.7f, 1.f }));
|
||||
presets.values.put("Background", WidgetNode(RGBA{ 0.03f, 0.03f, 0.03f, 1.f }));
|
||||
presets.values.put("Base", WidgetNode(RGBA{ 0.07f, 0.07f, 0.07f, 1.f }));
|
||||
presets.values.put("Accent", WidgetNode(RGBA{ 0.13f, 0.13f, 0.13f, 1.f }));
|
||||
presets.values.put("Interaction", WidgetNode(RGBA{ 0.33f, 0.33f, 0.3f, 1.f }));
|
||||
presets.values.put("Action", WidgetNode(RGBA{ 0.44f, 0.44f, 0.4f, 1.f }));
|
||||
presets.values.put("Front", WidgetNode(RGBA{ 1.f, 1.f, 1.f, 1.f }));
|
||||
presets.values.put("FrontDim", WidgetNode(RGBA{ 0.7f, 0.7f, 0.7f, 1.f }));
|
||||
}
|
||||
|
||||
~GlobalGUIConfig() { configs.removeAll(); }
|
||||
|
||||
void processShortcuts(const Events& events) {
|
||||
//
|
||||
}
|
||||
|
||||
Map<std::string, WidgetConfig> configs;
|
||||
|
||||
~GlobalGUIConfig() {
|
||||
configs.removeAll();
|
||||
}
|
||||
};
|
||||
|
||||
extern GlobalGUIConfig* gGlobalGUIConfig;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue