Gui drawing started, todo implement all the features
This commit is contained in:
parent
ea6cdc231c
commit
2c92ab2557
@ -1,19 +1,16 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
#include <vector>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <list>
|
|
||||||
namespace multi {
|
|
||||||
/*
|
|
||||||
|
|
||||||
*/
|
namespace multi {
|
||||||
template<class T>
|
template<typename T>
|
||||||
class connection {
|
class connection {
|
||||||
// bool = func(void* v)
|
std::vector<std::function<void(T)>> funcs;
|
||||||
std::vector<void(*)(T)> funcs;
|
|
||||||
std::vector<void(*)(void)> _funcs;
|
std::vector<void(*)(void)> _funcs;
|
||||||
public:
|
public:
|
||||||
int32_t connect(void(*func)(T)) {
|
int32_t connect(std::function<void(T)> func) {
|
||||||
funcs.push_back(func);
|
funcs.push_back(func);
|
||||||
return funcs.size() - 1;
|
return (int32_t)funcs.size() - 1;
|
||||||
}
|
}
|
||||||
int32_t connect(void(*func)()) {
|
int32_t connect(void(*func)()) {
|
||||||
_funcs.push_back(func);
|
_funcs.push_back(func);
|
||||||
@ -32,7 +29,19 @@ namespace multi {
|
|||||||
f();
|
f();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
int32_t operator+=(void(*func)(T)) {
|
void remove(int32_t id) {
|
||||||
|
if (id < 0) {
|
||||||
|
_funcs.erase((id * -1) - 1); //Normalize the id so it works with the vector
|
||||||
|
// Dealing with now obj connections
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
funcs.eraase(id);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
void operator-=(int32_t id) {
|
||||||
|
remove(id);
|
||||||
|
}
|
||||||
|
int32_t operator+=(std::function<void(T)> func) {
|
||||||
return connect(func);
|
return connect(func);
|
||||||
}
|
}
|
||||||
int32_t operator+=(void(*func)()) {
|
int32_t operator+=(void(*func)()) {
|
||||||
|
|||||||
70
DMS/DMS.cpp
70
DMS/DMS.cpp
@ -3,15 +3,15 @@
|
|||||||
#include <SFML/System.hpp>
|
#include <SFML/System.hpp>
|
||||||
#include "pch.h"
|
#include "pch.h"
|
||||||
#include "dms.h"
|
#include "dms.h"
|
||||||
|
#include "gui.h"
|
||||||
|
#include "actors.h"
|
||||||
|
|
||||||
using namespace dms;
|
using namespace dms;
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
// TODO fix disp cmd to handle the standard
|
// TODO fix disp cmd to handle the standard
|
||||||
|
|
||||||
|
multi::runner run;
|
||||||
/*milliseconds ms = duration_cast<milliseconds>(system_clock::now().time_since_epoch());
|
|
||||||
utils::print(ms.count());*/
|
|
||||||
|
|
||||||
LineParser parser = LineParser("test.dms");
|
LineParser parser = LineParser("test.dms");
|
||||||
dms_state* state = parser.Parse();
|
dms_state* state = parser.Parse();
|
||||||
@ -22,30 +22,40 @@ int main()
|
|||||||
|
|
||||||
sf::RenderWindow window(sf::VideoMode(1024, 768, 32), "Background Test");
|
sf::RenderWindow window(sf::VideoMode(1024, 768, 32), "Background Test");
|
||||||
|
|
||||||
sf::Texture texture;
|
gui::gui& root = gui::Root();
|
||||||
texture.loadFromFile("background.jpg");
|
//gui::framebase testframe(gui::DualDim(0, 0, 100, 100), gui::DualDim(0, 0, 0, 0));
|
||||||
sf::Sprite sprite;
|
|
||||||
sf::Vector2u size = texture.getSize();
|
|
||||||
sprite.setTexture(texture);
|
|
||||||
sprite.setOrigin(0, 0);
|
|
||||||
|
|
||||||
sf::Font font;
|
gui::gui& test = root.newFrame(gui::DualDim(0, 0, 100, 100), gui::DualDim(0, 0, 0, 0));
|
||||||
font.loadFromFile("font.ttf");
|
multi::alarm<multi::seconds> alarmtest(&run, 3, [&](multi::alarm<multi::seconds>* a) {
|
||||||
|
test.Offset.Position.Set(10, 10);
|
||||||
|
});
|
||||||
|
//std::cout << "Testing " << test.Parent;
|
||||||
|
//gui::framebase frame(gui::DualDim(0,0,100,100), gui::DualDim(0, 0, 0, 0));
|
||||||
|
|
||||||
sf::Text text("Hello this is a test|!", font);
|
//sf::Texture texture;
|
||||||
text.setCharacterSize(30);
|
//texture.loadFromFile("background.jpg");
|
||||||
text.setStyle(sf::Text::Bold);
|
//sf::Sprite sprite;
|
||||||
text.setFillColor(sf::Color::Black);
|
//sf::Vector2u size = texture.getSize();
|
||||||
auto test = text.getGlobalBounds();
|
//sprite.setTexture(texture);
|
||||||
std::cout << test.left << "," << test.top << "," << test.width << "," << test.height << std::endl;
|
//sprite.setOrigin(0, 0);
|
||||||
text.setPosition(11, 768 - 110 - (test.height-test.top));
|
|
||||||
//std::cout << test << std::endl;
|
|
||||||
|
|
||||||
sf::RectangleShape rectangle;
|
//sf::Font font;
|
||||||
rectangle.setSize(sf::Vector2f(1004, 100));
|
//font.loadFromFile("font.ttf");
|
||||||
rectangle.setOutlineColor(sf::Color::Red);
|
|
||||||
rectangle.setOutlineThickness(1);
|
//sf::Text text("Hello this is a test|!", font);
|
||||||
rectangle.setPosition(10, 768-110);
|
//text.setCharacterSize(30);
|
||||||
|
//text.setStyle(sf::Text::Bold);
|
||||||
|
//text.setFillColor(sf::Color::Black);
|
||||||
|
//auto test = text.getGlobalBounds();
|
||||||
|
//std::cout << test.left << "," << test.top << "," << test.width << "," << test.height << std::endl;
|
||||||
|
//text.setPosition(11, 768 - 110 - (test.height-test.top));
|
||||||
|
////std::cout << test << std::endl;
|
||||||
|
|
||||||
|
//sf::RectangleShape rectangle;
|
||||||
|
//rectangle.setSize(sf::Vector2f(1004, 100));
|
||||||
|
//rectangle.setOutlineColor(sf::Color::Red);
|
||||||
|
//rectangle.setOutlineThickness(1);
|
||||||
|
//rectangle.setPosition(10, 768-110);
|
||||||
|
|
||||||
//// run the program as long as the window is open
|
//// run the program as long as the window is open
|
||||||
while (window.isOpen())
|
while (window.isOpen())
|
||||||
@ -66,11 +76,17 @@ int main()
|
|||||||
// We should clean up some stuff here!
|
// We should clean up some stuff here!
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
// Update the runner
|
||||||
|
run.update();
|
||||||
|
|
||||||
// draw everything here...
|
// draw everything here...
|
||||||
window.draw(sprite);
|
|
||||||
window.draw(rectangle);
|
gui::Draw(&window);
|
||||||
window.draw(text);
|
|
||||||
|
//testframe.Draw(&window);
|
||||||
|
//window.draw(sprite);
|
||||||
|
//window.draw(rectangle);
|
||||||
|
//window.draw(text);
|
||||||
|
|
||||||
// end the current frame
|
// end the current frame
|
||||||
window.display();
|
window.display();
|
||||||
|
|||||||
@ -168,6 +168,7 @@
|
|||||||
<ClCompile Include="core.cpp" />
|
<ClCompile Include="core.cpp" />
|
||||||
<ClCompile Include="dms_custom.cpp" />
|
<ClCompile Include="dms_custom.cpp" />
|
||||||
<ClCompile Include="enviroment.cpp" />
|
<ClCompile Include="enviroment.cpp" />
|
||||||
|
<ClCompile Include="guiimpl.cpp" />
|
||||||
<ClCompile Include="Handlers.cpp" />
|
<ClCompile Include="Handlers.cpp" />
|
||||||
<ClCompile Include="chunk.cpp" />
|
<ClCompile Include="chunk.cpp" />
|
||||||
<ClCompile Include="cmd.cpp" />
|
<ClCompile Include="cmd.cpp" />
|
||||||
@ -175,6 +176,7 @@
|
|||||||
<ClCompile Include="DMS.cpp" />
|
<ClCompile Include="DMS.cpp" />
|
||||||
<ClCompile Include="dms_state.cpp" />
|
<ClCompile Include="dms_state.cpp" />
|
||||||
<ClCompile Include="dms_state_interpret.cpp" />
|
<ClCompile Include="dms_state_interpret.cpp" />
|
||||||
|
<ClCompile Include="multiimpl.cpp" />
|
||||||
<ClCompile Include="Invoker.cpp" />
|
<ClCompile Include="Invoker.cpp" />
|
||||||
<ClCompile Include="LineParserBuilds.cpp" />
|
<ClCompile Include="LineParserBuilds.cpp" />
|
||||||
<ClCompile Include="LineParserMatchProcess.cpp" />
|
<ClCompile Include="LineParserMatchProcess.cpp" />
|
||||||
@ -190,9 +192,9 @@
|
|||||||
<ClCompile Include="sound.cpp" />
|
<ClCompile Include="sound.cpp" />
|
||||||
<ClCompile Include="utils.cpp" />
|
<ClCompile Include="utils.cpp" />
|
||||||
<ClCompile Include="value.cpp" />
|
<ClCompile Include="value.cpp" />
|
||||||
<ClCompile Include="window.cpp" />
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<ClInclude Include="actors.h" />
|
||||||
<ClInclude Include="character.h" />
|
<ClInclude Include="character.h" />
|
||||||
<ClInclude Include="comparisons.h" />
|
<ClInclude Include="comparisons.h" />
|
||||||
<ClInclude Include="Connection.h" />
|
<ClInclude Include="Connection.h" />
|
||||||
@ -211,13 +213,13 @@
|
|||||||
<ClInclude Include="errors.h" />
|
<ClInclude Include="errors.h" />
|
||||||
<ClInclude Include="dms.h" />
|
<ClInclude Include="dms.h" />
|
||||||
<ClInclude Include="LineParser.h" />
|
<ClInclude Include="LineParser.h" />
|
||||||
|
<ClInclude Include="multibase.h" />
|
||||||
<ClInclude Include="pch.h" />
|
<ClInclude Include="pch.h" />
|
||||||
<ClInclude Include="sound.h" />
|
<ClInclude Include="sound.h" />
|
||||||
<ClInclude Include="s_value.h" />
|
<ClInclude Include="s_value.h" />
|
||||||
<ClInclude Include="token.h" />
|
<ClInclude Include="token.h" />
|
||||||
<ClInclude Include="utils.h" />
|
<ClInclude Include="utils.h" />
|
||||||
<ClInclude Include="value.h" />
|
<ClInclude Include="value.h" />
|
||||||
<ClInclude Include="window.h" />
|
|
||||||
<ClInclude Include="wrapper.h" />
|
<ClInclude Include="wrapper.h" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||||
|
|||||||
@ -52,6 +52,15 @@
|
|||||||
<Filter Include="Header Files\DMS\libraries">
|
<Filter Include="Header Files\DMS\libraries">
|
||||||
<UniqueIdentifier>{584d8d2d-e56e-4a89-a1fe-08a13c3d08a9}</UniqueIdentifier>
|
<UniqueIdentifier>{584d8d2d-e56e-4a89-a1fe-08a13c3d08a9}</UniqueIdentifier>
|
||||||
</Filter>
|
</Filter>
|
||||||
|
<Filter Include="Source Files\multi">
|
||||||
|
<UniqueIdentifier>{f3de0fc4-d3ed-4241-9432-4b9136f0b672}</UniqueIdentifier>
|
||||||
|
</Filter>
|
||||||
|
<Filter Include="Header Files\DMS\gui">
|
||||||
|
<UniqueIdentifier>{8b07822b-59fb-4826-89ce-7481977f640b}</UniqueIdentifier>
|
||||||
|
</Filter>
|
||||||
|
<Filter Include="Source Files\gui">
|
||||||
|
<UniqueIdentifier>{490b48c7-06fe-4e6f-9b95-93a0b01a963c}</UniqueIdentifier>
|
||||||
|
</Filter>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClCompile Include="cmd.cpp">
|
<ClCompile Include="cmd.cpp">
|
||||||
@ -120,8 +129,11 @@
|
|||||||
<ClCompile Include="sound.cpp">
|
<ClCompile Include="sound.cpp">
|
||||||
<Filter>Source Files\DMS\platformdep</Filter>
|
<Filter>Source Files\DMS\platformdep</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<ClCompile Include="window.cpp">
|
<ClCompile Include="multiimpl.cpp">
|
||||||
<Filter>Source Files\DMS\platformdep</Filter>
|
<Filter>Source Files\multi</Filter>
|
||||||
|
</ClCompile>
|
||||||
|
<ClCompile Include="guiimpl.cpp">
|
||||||
|
<Filter>Source Files\gui</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
@ -194,14 +206,17 @@
|
|||||||
<ClInclude Include="Connection.h">
|
<ClInclude Include="Connection.h">
|
||||||
<Filter>Header Files\multi</Filter>
|
<Filter>Header Files\multi</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
<ClInclude Include="gui.h">
|
|
||||||
<Filter>Header Files\DMS\libraries</Filter>
|
|
||||||
</ClInclude>
|
|
||||||
<ClInclude Include="sound.h">
|
<ClInclude Include="sound.h">
|
||||||
<Filter>Header Files\DMS\libraries</Filter>
|
<Filter>Header Files\DMS\libraries</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
<ClInclude Include="window.h">
|
<ClInclude Include="actors.h">
|
||||||
<Filter>Header Files\DMS\libraries</Filter>
|
<Filter>Header Files\multi</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="multibase.h">
|
||||||
|
<Filter>Header Files\multi</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="gui.h">
|
||||||
|
<Filter>Header Files\DMS\gui</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
||||||
182
DMS/actors.h
Normal file
182
DMS/actors.h
Normal file
@ -0,0 +1,182 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "multibase.h"
|
||||||
|
#include <chrono>
|
||||||
|
namespace multi {
|
||||||
|
class event : public mbase {
|
||||||
|
public:
|
||||||
|
event(runner* run, void(*func)(event*)) : mbase(mtype::mEvent,run) {
|
||||||
|
OnEvent += func;
|
||||||
|
}
|
||||||
|
event(runner* run) : mbase(mtype::mEvent,run) {}
|
||||||
|
connection<event*> OnEvent;
|
||||||
|
};
|
||||||
|
template <typename T>
|
||||||
|
class alarm : public mbase {
|
||||||
|
long long milli;
|
||||||
|
timer<T> t;
|
||||||
|
public:
|
||||||
|
alarm(runner* run, long long milli, std::function<void(alarm*)> func) : mbase(mtype::mAlarm,run) {
|
||||||
|
this->milli = milli;
|
||||||
|
OnRing += func;
|
||||||
|
t.start();
|
||||||
|
}
|
||||||
|
alarm(runner* run, long long milli) : mbase(mtype::mAlarm,run) {
|
||||||
|
this->milli = milli;
|
||||||
|
t.start();
|
||||||
|
}
|
||||||
|
alarm(runner* run, void(*func)(alarm*)) : mbase(mtype::mAlarm,run) {
|
||||||
|
OnRing += func;
|
||||||
|
milli = 1000;
|
||||||
|
t.start();
|
||||||
|
}
|
||||||
|
alarm(runner* run) : mbase(mtype::mAlarm, run) {
|
||||||
|
milli = 1000;
|
||||||
|
t.start();
|
||||||
|
};
|
||||||
|
void set(long long milli) {
|
||||||
|
this->milli = milli;
|
||||||
|
t.start();
|
||||||
|
}
|
||||||
|
void reset(long long milli) {
|
||||||
|
set(milli);
|
||||||
|
mbase::reset();
|
||||||
|
}
|
||||||
|
void reset() {
|
||||||
|
t.start();
|
||||||
|
mbase::reset();
|
||||||
|
}
|
||||||
|
void act(int id) override {
|
||||||
|
if (!active) return;
|
||||||
|
if (t.get() >= milli) {
|
||||||
|
stop();
|
||||||
|
OnRing.fire(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
connection<alarm*> OnRing;
|
||||||
|
};
|
||||||
|
class step : public mbase {
|
||||||
|
int start;
|
||||||
|
int endAt;
|
||||||
|
int count;
|
||||||
|
bool loop;
|
||||||
|
int pos;
|
||||||
|
public:
|
||||||
|
step(runner* run, int start, int endAt, int count = 1, bool loop = false) : mbase(mtype::mStep,run) {
|
||||||
|
update(start, endAt, count, loop);
|
||||||
|
}
|
||||||
|
void reset() {
|
||||||
|
pos = start;
|
||||||
|
mbase::reset();
|
||||||
|
}
|
||||||
|
void update(int start, int endAt, int count = 1, bool loop = false) {
|
||||||
|
this->start = start;
|
||||||
|
pos = start;
|
||||||
|
this->endAt = endAt;
|
||||||
|
this->count = count;
|
||||||
|
if (start > endAt && count == 1)
|
||||||
|
this->count = -1;
|
||||||
|
this->loop = loop;
|
||||||
|
}
|
||||||
|
void act(int id) override {
|
||||||
|
if (!active) return;
|
||||||
|
if (pos == start) OnStepBegin.fire(this);
|
||||||
|
OnStep.fire(pos);
|
||||||
|
pos += count;
|
||||||
|
if ((count > start && pos > endAt) || (count < start && pos < endAt)) {
|
||||||
|
stop();
|
||||||
|
OnStepEnd.fire(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
connection<step*> OnStepBegin; // before all steps start
|
||||||
|
connection<int> OnStep; // each step
|
||||||
|
connection<step*> OnStepEnd; // After end of all steps
|
||||||
|
};
|
||||||
|
class loop : public mbase {
|
||||||
|
public:
|
||||||
|
loop(runner* run,void(*func)(loop*)) : mbase(mtype::mLoop,run) {
|
||||||
|
OnLoop += func;
|
||||||
|
}
|
||||||
|
void act(int id) override {
|
||||||
|
if (!active) return;
|
||||||
|
OnLoop.fire(this);
|
||||||
|
}
|
||||||
|
loop(runner* run) : mbase(mtype::mLoop,run) {}
|
||||||
|
connection<loop*> OnLoop;
|
||||||
|
};
|
||||||
|
template<typename T>
|
||||||
|
class tstep : public mbase {
|
||||||
|
long long milli;
|
||||||
|
timer<T> t;
|
||||||
|
int start;
|
||||||
|
int endAt;
|
||||||
|
int count;
|
||||||
|
bool loop;
|
||||||
|
int pos;
|
||||||
|
public:
|
||||||
|
tstep(runner* run, long long milli, int start, int endAt, int count = 1, bool loop = false) : mbase(mtype::mTStep, run) {
|
||||||
|
update(start, endAt, count, loop);
|
||||||
|
reset(milli);
|
||||||
|
}
|
||||||
|
void reset() override {
|
||||||
|
pos = start;
|
||||||
|
mbase::reset();
|
||||||
|
}
|
||||||
|
void reset(long long milli) {
|
||||||
|
pos = start;
|
||||||
|
set(milli);
|
||||||
|
mbase::reset();
|
||||||
|
}
|
||||||
|
void set(long long milli) {
|
||||||
|
this->milli = milli;
|
||||||
|
t.start();
|
||||||
|
}
|
||||||
|
void update(int start, int endAt, int count = 1, bool loop = false) {
|
||||||
|
this->start = start;
|
||||||
|
pos = start;
|
||||||
|
this->endAt = endAt;
|
||||||
|
this->count = count;
|
||||||
|
if (start > endAt && count == 1)
|
||||||
|
this->count = -1;
|
||||||
|
this->loop = loop;
|
||||||
|
}
|
||||||
|
void act(int id) override {
|
||||||
|
if (!active) return;
|
||||||
|
if (t.get() >= milli) {
|
||||||
|
if (pos == start) OnStepBegin.fire(this);
|
||||||
|
OnStep.fire(pos);
|
||||||
|
pos += count;
|
||||||
|
t.start();
|
||||||
|
if ((count > start && pos > endAt) || (count < start && pos < endAt)) {
|
||||||
|
stop();
|
||||||
|
OnStepEnd.fire(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
connection<tstep*> OnStepBegin; // before all steps start
|
||||||
|
connection<int> OnStep; // each step
|
||||||
|
connection<tstep*> OnStepEnd; // After end of all steps
|
||||||
|
};
|
||||||
|
template <typename T>
|
||||||
|
class tloop : public mbase {
|
||||||
|
long long milli;
|
||||||
|
timer<T> t;
|
||||||
|
public:
|
||||||
|
tloop(runner* run, long long milli, void(*func)(tloop*)) : mbase(mtype::mTLoop, run) {
|
||||||
|
OnLoop += func;
|
||||||
|
this->milli = milli;
|
||||||
|
}
|
||||||
|
void set(long long milli) {
|
||||||
|
this->milli = milli;
|
||||||
|
t.start();
|
||||||
|
}
|
||||||
|
void act(int id) override {
|
||||||
|
if (!active) return;
|
||||||
|
if (t.get() >= milli) {
|
||||||
|
OnLoop.fire(this);
|
||||||
|
t.start();
|
||||||
|
reset();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
connection<tloop*> OnLoop;
|
||||||
|
};
|
||||||
|
}
|
||||||
BIN
DMS/dump.bin
BIN
DMS/dump.bin
Binary file not shown.
BIN
DMS/dump.txt
BIN
DMS/dump.txt
Binary file not shown.
211
DMS/gui.h
211
DMS/gui.h
@ -1,17 +1,17 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "window.h"
|
|
||||||
#include "pch.h"
|
#include "pch.h"
|
||||||
#include "dms_state.h"
|
#include "dms_state.h"
|
||||||
|
#include <SFML/Graphics.hpp>
|
||||||
|
#include <SFML/Window.hpp>
|
||||||
|
#include <SFML/System.hpp>
|
||||||
|
#include "multibase.h"
|
||||||
namespace gui {
|
namespace gui {
|
||||||
using namespace std;
|
using namespace std;
|
||||||
using namespace dms;
|
using namespace dms;
|
||||||
int __ElementCount = 0;
|
/// <summary>
|
||||||
void init(dms_state* state) {
|
/// This is the number of gui elements that exist! It isn't constant, but set as a read only variable.
|
||||||
// While very unlikely it is possible multiple windows to be created! It might be a good idea to support it sometime down the line
|
/// </summary>
|
||||||
window::OnWindowCreated += [](sf::RenderWindow* window) {
|
const int GuiElementCount = 0;
|
||||||
|
|
||||||
};
|
|
||||||
}
|
|
||||||
/*
|
/*
|
||||||
textbox
|
textbox
|
||||||
textbutton
|
textbutton
|
||||||
@ -27,33 +27,58 @@ namespace gui {
|
|||||||
|
|
||||||
|
|
||||||
*/
|
*/
|
||||||
enum class gui_types{frame,text,text,image,sprite,video};
|
enum class gui_types{root, frame,text,image,sprite,video};
|
||||||
struct Dim {
|
struct Dim {
|
||||||
float x;
|
const float x = 0;
|
||||||
float y;
|
const float y = 0;
|
||||||
Dim() {x = 0;y = 0;}
|
Dim() : x(0), y(0) {}
|
||||||
Dim(const Dim &d) { x = d.x; y = d.y;}
|
Dim(const Dim &d) : x(d.x),y(d.y) {}
|
||||||
Dim(float x, float y) { this->x = x; this->y = y;}
|
Dim(float x, float y) : x(x),y(y) {}
|
||||||
inline void Set(Dim d) {x = d.x; y = d.y;}
|
inline void Set(Dim d) { const_cast<float&>(x) = d.x; const_cast<float&>(y) = d.y; OnValueChanged.fire(this); }
|
||||||
inline void Set(float x, float y) { this->x = x; this->y = y;}
|
inline void Set(float x, float y) { const_cast<float&>(this->x) = x; const_cast<float&>(this->y) = y; OnValueChanged.fire(this);}
|
||||||
|
void operator=(const Dim& dd) {
|
||||||
|
Set(dd);
|
||||||
|
}
|
||||||
|
void operator=(const sf::Vector2u& v) {
|
||||||
|
Set(v.x, v.y);
|
||||||
|
}
|
||||||
|
operator sf::Vector2u () {
|
||||||
|
return sf::Vector2u((int)x, (int)y);
|
||||||
|
}
|
||||||
|
operator sf::Vector2f() {
|
||||||
|
return sf::Vector2f(x, y);
|
||||||
|
}
|
||||||
|
multi::connection<Dim*> OnValueChanged;
|
||||||
};
|
};
|
||||||
struct DualDim {
|
struct DualDim {
|
||||||
Dim Position;
|
Dim Position;
|
||||||
Dim Size;
|
Dim Size;
|
||||||
DualDim() {Position.x = 0;Position.y = 0;Size.x = 0;Size.y = 0;}
|
void init() {
|
||||||
DualDim(const DualDim& d) { Position = d.Position; Size = d.Size;}
|
Position.OnValueChanged += [&](Dim* d) {
|
||||||
DualDim(Dim pos, Dim size) { Position = pos; Size = size;}
|
OnValueChanged.fire(this);
|
||||||
DualDim(float x, float y, float x2, float y2) { Position.x = x; Position.y = y; Size.x = x2; Size.y = y2; }
|
};
|
||||||
inline void Set(DualDim d){ Position = d.Position; Size = d.Size;}
|
Size.OnValueChanged += [&](Dim* d) {
|
||||||
inline void Set(Dim pos, Dim size) {Position.x = pos.x;Position.y = pos.y;Size.x = size.x;Size.y = size.y;}
|
OnValueChanged.fire(this);
|
||||||
inline void Set(float x, float y, float x2, float y2) { Position.x = x; Position.y = y; Size.x = x2; Size.y = y2;}
|
};
|
||||||
|
}
|
||||||
|
DualDim() : Position(0,0),Size(0,0) { init(); }
|
||||||
|
DualDim(const DualDim& d) : Position(d.Position.x,d.Position.y), Size(d.Size.x,d.Size.y) {init(); }
|
||||||
|
DualDim(Dim pos, Dim size) : Position(pos.x,pos.y), Size(size.x,size.y) { init(); }
|
||||||
|
DualDim(float x, float y, float x2, float y2) : Position(x,y),Size(x2,y2) { init(); }
|
||||||
|
inline void Set(DualDim d){ Position.Set(d.Position); Size.Set(d.Size);OnValueChanged.fire(this);}
|
||||||
|
inline void Set(Dim pos, Dim size) { Position.Set(pos); Size.Set(size); OnValueChanged.fire(this);}
|
||||||
|
inline void Set(float x, float y, float x2, float y2) { Position.Set(x, y), Size.Set(x2, y2); OnValueChanged.fire(this);}
|
||||||
|
DualDim operator=(const DualDim& dd) {
|
||||||
|
Set(dd);
|
||||||
|
}
|
||||||
|
multi::connection<DualDim*> OnValueChanged;
|
||||||
};
|
};
|
||||||
struct MouseStats {
|
struct MouseStats {
|
||||||
float x;
|
float x = 0;
|
||||||
float y;
|
float y = 0;
|
||||||
float dx;
|
float dx = 0;
|
||||||
float dy;
|
float dy = 0;
|
||||||
char button;
|
char button = 0;
|
||||||
MouseStats(Dim pos, char b) {
|
MouseStats(Dim pos, char b) {
|
||||||
x = pos.x;
|
x = pos.x;
|
||||||
y = pos.y;
|
y = pos.y;
|
||||||
@ -75,7 +100,57 @@ namespace gui {
|
|||||||
struct Keyboard {
|
struct Keyboard {
|
||||||
//
|
//
|
||||||
};
|
};
|
||||||
struct guibase {
|
|
||||||
|
class gui {
|
||||||
|
|
||||||
|
public:
|
||||||
|
gui_types Type = gui_types::root;
|
||||||
|
DualDim Offset;
|
||||||
|
DualDim Scale;
|
||||||
|
Dim AbsolutePosition;
|
||||||
|
Dim AbsoluteSize;
|
||||||
|
gui* Parent = nullptr;
|
||||||
|
vector<gui*> Children;
|
||||||
|
bool Visible = true;
|
||||||
|
|
||||||
|
//map<string, gui*> Named;
|
||||||
|
|
||||||
|
gui() {
|
||||||
|
const_cast<int&>(GuiElementCount) += 1;
|
||||||
|
|
||||||
|
}
|
||||||
|
gui(DualDim offset, DualDim scale) : gui() { Offset.Set(offset); Scale.Set(scale);}
|
||||||
|
gui(float x,float y,float w,float h,float sx,float sy,float sw,float sh) : gui() {
|
||||||
|
Offset.Set(x, y, w, h);
|
||||||
|
Scale.Set(sx, sy, sw, sh);
|
||||||
|
}
|
||||||
|
void SetDualDim(DualDim offset,DualDim scale) {Offset = offset;Scale.Set(scale);}
|
||||||
|
|
||||||
|
virtual void Draw(sf::RenderWindow* window) {
|
||||||
|
return; // Override this.
|
||||||
|
}
|
||||||
|
|
||||||
|
inline vector<gui*>& GetChildren() {return Children;}
|
||||||
|
inline void GetAllChildren(vector<gui*>& ref) {
|
||||||
|
auto temp = GetChildren();
|
||||||
|
for (int i = 0; i < temp.size(); i++) {
|
||||||
|
ref.push_back(temp[i]);
|
||||||
|
temp[i]->GetAllChildren(ref);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
inline vector<gui*> GetAllChildren() {
|
||||||
|
auto temp = GetChildren();
|
||||||
|
vector<gui*> everything;
|
||||||
|
everything.reserve(GuiElementCount); // Reserve Space for all the current elements that exist
|
||||||
|
for (int i = 0; i < temp.size(); i++) {
|
||||||
|
everything.push_back(temp[i]);
|
||||||
|
temp[i]->GetAllChildren(everything);
|
||||||
|
}
|
||||||
|
return everything;
|
||||||
|
}
|
||||||
|
|
||||||
|
gui& newFrame(DualDim offset, DualDim scale);
|
||||||
|
|
||||||
//Connections and objects to inheret
|
//Connections and objects to inheret
|
||||||
multi::connection<MouseStats> OnPressed;
|
multi::connection<MouseStats> OnPressed;
|
||||||
multi::connection<MouseStats> OnReleased;
|
multi::connection<MouseStats> OnReleased;
|
||||||
@ -89,54 +164,46 @@ namespace gui {
|
|||||||
|
|
||||||
|
|
||||||
multi::connection<gui*> OnUpdate;
|
multi::connection<gui*> OnUpdate;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
struct framebase : public gui {
|
||||||
|
sf::RectangleShape rect;
|
||||||
|
framebase(DualDim offset, DualDim scale) : gui(offset,scale) {
|
||||||
|
Type = gui_types::frame;
|
||||||
|
rect.setFillColor(sf::Color(120, 120, 120, 255));
|
||||||
|
rect.setOutlineColor(sf::Color::Red);
|
||||||
|
rect.setSize(offset.Size);
|
||||||
|
rect.setPosition(offset.Position);
|
||||||
|
Offset.OnValueChanged += [&](DualDim* o) {
|
||||||
|
rect.setSize(o->Size);
|
||||||
|
rect.setPosition(o->Position);
|
||||||
|
};
|
||||||
|
Scale.OnValueChanged += [](DualDim* s) {
|
||||||
|
|
||||||
};
|
};
|
||||||
class gui : guibase {
|
|
||||||
|
|
||||||
public:
|
|
||||||
gui_types Type;
|
|
||||||
DualDim Offset;
|
|
||||||
DualDim Scale;
|
|
||||||
DualDim Absolute;
|
|
||||||
vector<gui> Children;
|
|
||||||
bool Visible = true;
|
|
||||||
|
|
||||||
//map<string, gui*> Named;
|
|
||||||
|
|
||||||
gui() {__ElementCount++;}
|
|
||||||
gui(DualDim offset, DualDim scale) { Offset = offset; Scale = scale;}
|
|
||||||
gui(float x,float y,float w,float h,float sx,float sy,float sw,float sh){Offset.Position.x = x;Offset.Position.y = y;Offset.Size.x = w;Offset.Size.y = h;Scale.Position.x = sx;Scale.Position.y = sy;Scale.Size.x = sw;Scale.Size.y = sh;}
|
|
||||||
void SetDualDim(DualDim offset,DualDim scale) {Offset = offset;Scale = scale;}
|
|
||||||
|
|
||||||
virtual void Draw() {
|
|
||||||
return; // Override this.
|
|
||||||
}
|
}
|
||||||
|
void Draw(sf::RenderWindow* window) override {
|
||||||
inline vector<gui>& GetChildren() {return Children;}
|
window->draw(rect);
|
||||||
inline void GetAllChildren(vector<gui*>& ref) {
|
|
||||||
auto temp = GetChildren();
|
|
||||||
for (int i = 0; i < temp.size(); i++) {
|
|
||||||
ref.push_back(&temp[i]);
|
|
||||||
temp[i].GetAllChildren(ref);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
inline vector<gui*> GetAllChildren() {
|
|
||||||
auto temp = GetChildren();
|
|
||||||
vector<gui*> everything;
|
|
||||||
everything.reserve(__ElementCount); // Reserve all the current elements that exist
|
|
||||||
for (int i = 0; i < temp.size(); i++) {
|
|
||||||
everything.push_back(&temp[i]);
|
|
||||||
temp[i].GetAllChildren(everything);
|
|
||||||
}
|
|
||||||
return everything;
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
// Draw Everything
|
struct imagebase : public framebase {
|
||||||
gui _Root;
|
sf::Texture texture;
|
||||||
void Draw() {
|
imagebase(std::string imagepath, DualDim offset, DualDim scale) : framebase(offset,scale) {
|
||||||
auto childs = _Root.GetAllChildren();
|
Type = gui_types::image;
|
||||||
for (int i = 0; i < childs.size(); i++) {
|
texture.loadFromFile(imagepath);
|
||||||
childs[i]->Draw();
|
sf::Sprite sprite;
|
||||||
|
sf::Vector2u size = texture.getSize();
|
||||||
|
sprite.setTexture(texture);
|
||||||
|
sprite.setOrigin(0, 0);
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
struct textbase : public framebase {
|
||||||
|
textbase(std::string text, sf::Font font, DualDim offset, DualDim scale) : framebase(offset, scale) {
|
||||||
|
Type = gui_types::text;
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
gui& Root();
|
||||||
|
void Draw(sf::RenderWindow* window);
|
||||||
}
|
}
|
||||||
22
DMS/guiimpl.cpp
Normal file
22
DMS/guiimpl.cpp
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
#include "gui.h"
|
||||||
|
namespace gui {
|
||||||
|
gui& gui::newFrame(DualDim offset, DualDim scale) {
|
||||||
|
gui* fb = new framebase(offset, scale);
|
||||||
|
fb->Parent = this;
|
||||||
|
Children.push_back(fb);
|
||||||
|
return *fb;
|
||||||
|
}
|
||||||
|
// Draw Everything
|
||||||
|
gui _Root;
|
||||||
|
std::vector<gui*> childs; // This tends to always grow, rarely strinking. So make it once so we arent allocating meme each loop!
|
||||||
|
void Draw(sf::RenderWindow* window) {
|
||||||
|
_Root.AbsoluteSize = window->getSize();
|
||||||
|
childs = _Root.GetAllChildren();
|
||||||
|
for (int i = 0; i < childs.size(); i++) {
|
||||||
|
childs[i]->Draw(window);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
gui& Root() {
|
||||||
|
return _Root;
|
||||||
|
}
|
||||||
|
}
|
||||||
109
DMS/multibase.h
Normal file
109
DMS/multibase.h
Normal file
@ -0,0 +1,109 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "connection.h"
|
||||||
|
#include <unordered_map>
|
||||||
|
#include <chrono>
|
||||||
|
#include <thread>
|
||||||
|
#include <iostream>
|
||||||
|
namespace multi {
|
||||||
|
// Keeps track of time.
|
||||||
|
typedef std::chrono::high_resolution_clock Clock;
|
||||||
|
typedef std::chrono::nanoseconds nanoseconds;
|
||||||
|
typedef std::chrono::microseconds microseconds;
|
||||||
|
typedef std::chrono::milliseconds milliseconds;
|
||||||
|
typedef std::chrono::seconds seconds;
|
||||||
|
typedef std::chrono::minutes minutes;
|
||||||
|
typedef std::chrono::hours hours;
|
||||||
|
|
||||||
|
const char _nanosecond = 0x0;
|
||||||
|
const char _microsecond = 0x1;
|
||||||
|
const char _millisecond = 0x2;
|
||||||
|
const char _second = 0x3;
|
||||||
|
const char _minute = 0x4;
|
||||||
|
const char _hour = 0x5;
|
||||||
|
|
||||||
|
typedef std::chrono::time_point<std::chrono::high_resolution_clock> time;
|
||||||
|
template <typename T>
|
||||||
|
struct timer {
|
||||||
|
inline void start() {
|
||||||
|
t = Clock::now();
|
||||||
|
}
|
||||||
|
inline long long get() const {
|
||||||
|
return std::chrono::duration_cast<T>(Clock::now() - t).count();
|
||||||
|
}
|
||||||
|
inline void sleep(long long s) {
|
||||||
|
std::this_thread::sleep_for(T(s));
|
||||||
|
}
|
||||||
|
private:
|
||||||
|
time t;
|
||||||
|
};
|
||||||
|
class mbase;
|
||||||
|
enum class mtype { mEvent, mStep, mLoop, mAlarm, mTStep, mTLoop, mService, mUpdater };
|
||||||
|
const std::unordered_map<mtype, const char*> mtypes {
|
||||||
|
{mtype::mEvent,"Event"},
|
||||||
|
{mtype::mStep,"Step"},
|
||||||
|
{mtype::mLoop,"Loop"},
|
||||||
|
{mtype::mAlarm,"Alarm"},
|
||||||
|
{mtype::mTStep,"TStep"},
|
||||||
|
{mtype::mTLoop,"TLoop"},
|
||||||
|
{mtype::mService,"Service"},
|
||||||
|
{mtype::mUpdater,"Updater"}
|
||||||
|
};
|
||||||
|
/// <summary>
|
||||||
|
/// Class responsible for driving multi objects
|
||||||
|
/// </summary>
|
||||||
|
class runner {
|
||||||
|
friend class mbase;
|
||||||
|
bool active = true;
|
||||||
|
std::vector<mbase*> mObjects;
|
||||||
|
public:
|
||||||
|
bool update();
|
||||||
|
void mainloop();
|
||||||
|
/// <summary>
|
||||||
|
/// Event Triggered when the multi object is created
|
||||||
|
/// </summary>
|
||||||
|
connection<mbase*> OnCreate;
|
||||||
|
/// <summary>
|
||||||
|
/// Event Triggered when the multi object is destroyed
|
||||||
|
/// </summary>
|
||||||
|
connection<mbase*> OnDestroyed;
|
||||||
|
};
|
||||||
|
class mbase {
|
||||||
|
public:
|
||||||
|
runner* Parent = nullptr;
|
||||||
|
const mtype Type;
|
||||||
|
const bool active = true;
|
||||||
|
const bool paused = false;
|
||||||
|
mbase(mtype type, runner* run) : Type(type) {
|
||||||
|
Parent = run;
|
||||||
|
run->mObjects.push_back(this);
|
||||||
|
}
|
||||||
|
virtual void act(int mid) {}
|
||||||
|
virtual void reset() { const_cast<bool&>(active) = true; };
|
||||||
|
void pause() {
|
||||||
|
if (!paused)
|
||||||
|
OnPaused.fire(this);
|
||||||
|
const_cast<bool&>(paused) = true;
|
||||||
|
}
|
||||||
|
void resume() {
|
||||||
|
if (paused)
|
||||||
|
OnResume.fire(this);
|
||||||
|
const_cast<bool&>(paused) = false;
|
||||||
|
}
|
||||||
|
void stop() {
|
||||||
|
OnStopped.fire(this);
|
||||||
|
const_cast<bool&>(active) = false;
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Event Triggered when the multi object is paused
|
||||||
|
/// </summary>
|
||||||
|
connection<mbase*> OnPaused;
|
||||||
|
/// <summary>
|
||||||
|
/// Event Triggered when the multi object is resumed
|
||||||
|
/// </summary>
|
||||||
|
connection<mbase*> OnResume;
|
||||||
|
/// <summary>
|
||||||
|
/// Event Triggered when the multi object is stopped
|
||||||
|
/// </summary>
|
||||||
|
connection<mbase*> OnStopped;
|
||||||
|
};
|
||||||
|
}
|
||||||
15
DMS/multiimpl.cpp
Normal file
15
DMS/multiimpl.cpp
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
#include "actors.h"
|
||||||
|
namespace multi {
|
||||||
|
bool runner::update() {
|
||||||
|
if (!active)
|
||||||
|
return false;
|
||||||
|
size_t id = 0;
|
||||||
|
for (auto mobj : mObjects) {
|
||||||
|
mobj->act(id++);
|
||||||
|
}
|
||||||
|
return active;
|
||||||
|
}
|
||||||
|
void runner::mainloop() {
|
||||||
|
while (update());
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,22 +0,0 @@
|
|||||||
#include "pch.h"
|
|
||||||
#include "window.h"
|
|
||||||
namespace dms::window {
|
|
||||||
Invoker* inv = new Invoker;
|
|
||||||
void init(dms_state* state) {
|
|
||||||
/*
|
|
||||||
inv->registerFunction("getStatus", getStatus);
|
|
||||||
|
|
||||||
state->assoiateType("audiostream",inv);
|
|
||||||
state->invoker.registerFunction("loadMusic", loadMusic);
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
value newWindow(void* self, dms_state* state, dms_args* args) {
|
|
||||||
if (dms::utils::valueassert(*args, state, datatypes::number, datatypes::number, datatypes::number)) {
|
|
||||||
|
|
||||||
}
|
|
||||||
else if (dms::utils::valueassert(*args, state, datatypes::int64, datatypes::int64, datatypes::int64)) {
|
|
||||||
|
|
||||||
}
|
|
||||||
sf::RenderWindow window(sf::VideoMode(1024, 768, 32), "Background Test");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
14
DMS/window.h
14
DMS/window.h
@ -1,14 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
#include <SFML/Window.hpp>
|
|
||||||
#include <SFML/Graphics.hpp>
|
|
||||||
#include "dms_state.h"
|
|
||||||
#include "utils.h"
|
|
||||||
#include <stdio.h>
|
|
||||||
#include "Connection.h"
|
|
||||||
namespace dms::window {
|
|
||||||
multi::connection<sf::RenderWindow*> OnWindowCreated;
|
|
||||||
void init(dms_state*);
|
|
||||||
bool windowIsReady = false;
|
|
||||||
std::vector<sf::RenderWindow*> windows;
|
|
||||||
value newWindow(void*, dms_state*, dms_args*);
|
|
||||||
}
|
|
||||||
Loading…
x
Reference in New Issue
Block a user