Skip to content

Commit

Permalink
[SUTK] Added HPaneTest (HPANE) and enabled C++20 in SGE
Browse files Browse the repository at this point in the history
  • Loading branch information
ravi688 committed Sep 9, 2024
1 parent 3b13823 commit 0af2684
Show file tree
Hide file tree
Showing 7 changed files with 155 additions and 3 deletions.
2 changes: 1 addition & 1 deletion dependencies/Common
2 changes: 1 addition & 1 deletion makefile
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ endif

COMPILER_FLAGS= -m64
C_COMPILER_FLAGS = $(COMPILER_FLAGS)
CPP_COMPILER_FLAGS = $(COMPILER_FLAGS)
CPP_COMPILER_FLAGS = $(COMPILER_FLAGS) -std=c++20
LINKER=g++
LINKER_FLAGS= -m64
DYNAMIC_LIBRARY_COMPILATION_FLAG = -shared
Expand Down
31 changes: 31 additions & 0 deletions sutk/include/sutk/HPaneContainer.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#pragma once

#include <sutk/Container.hpp>
#include <sutk/InputEventHandlerObject.hpp>

namespace SUTK
{
class RenderRectFill;

class HPaneContainer : public Container,
public MouseClickHandlerObject,
public MouseMoveHandlerObject
{
private:
bool m_isGrabbed;
std::vector<RenderRectFill*> m_handleRects;
std::vector<Container*> m_externalChilds;
protected:
virtual void onMouseClick(MouseButton button, KeyEvent action) override;
virtual void onMouseMove(Vec2Df position) override;

virtual void onAddChild(Container* child) override;
virtual void onRemoveChild(Container* child) override;
public:
HPaneContainer(UIDriver& driver, Container* parent = NULL) noexcept;
virtual ~HPaneContainer() noexcept = default;

std::vector<Container*>& getExternChilds() noexcept { return m_externalChilds; }
const std::vector<Container*>& getExternChilds() const noexcept { return m_externalChilds; }
};
}
35 changes: 35 additions & 0 deletions sutk/include/sutk/tests/HPaneTest.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#pragma once

#include <sutk/ITest.hpp>

#include <sge-cpp/sge.hpp>

#include <sutk/UIDriver.hpp>

namespace SUTK
{
class IGfxDriver;

class HPaneContainer;

class HPaneTest : public ITest
{
private:
UIDriver* m_uiDriver;
IGfxDriver* m_gfxDriver;
HPaneContainer* m_hPaneContainer;

public:
HPaneTest() : m_uiDriver(NULL), m_gfxDriver(NULL) { }

DriverInitializationData getInitializationData() override;

void initialize(SGE::Driver& driver) override;

void terminate(SGE::Driver& driver) override;

void render(SGE::Driver& driver) override;

void update(SGE::Driver& driver, float deltaTime) override;
};
}
43 changes: 43 additions & 0 deletions sutk/source/HPaneContainer.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#include <sutk/HPaneContainer.hpp>
#include <sutk/RenderRectFill.hpp>

#define HANDLE_HIGHLIGHT_COLOR Color4::grey(0.5f)

namespace SUTK
{
HPaneContainer::HPaneContainer(UIDriver& driver, Container* parent) noexcept : Container(driver, parent),
MouseClickHandlerObject(driver, this),
MouseMoveHandlerObject(driver, this)
{
}

void HPaneContainer::onMouseClick(MouseButton button, KeyEvent action)
{
// if((m_handleRect == NULL) || (button != MouseButton::Left))
// return;

// if(action == KeyEvent::Press)
// {
// Vec2Df pos = getInputDriver().getMousePosition();
// if(m_handleRect->containsGlobalCoords(pos))
// m_isGrabbed = true;
// }
// else
// m_isGrabbed = false;
}

void HPaneContainer::onMouseMove(Vec2Df position)
{
}

void HPaneContainer::onAddChild(Container* child)
{
m_externalChilds.push_back(child);
}

void HPaneContainer::onRemoveChild(Container* child)
{
bool result = com::find_erase(m_externalChilds, child);
_com_assert(result);
}
}
4 changes: 3 additions & 1 deletion sutk/source/ITest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <sutk/tests/ButtonTest.hpp>
#include <sutk/tests/VBoxTest.hpp>
#include <sutk/tests/HBoxTest.hpp>
#include <sutk/tests/HPaneTest.hpp>

namespace SUTK
{
Expand All @@ -27,7 +28,8 @@ namespace SUTK
{ "ROUND_RECT", [] () { return std::unique_ptr<ITest>(new RoundRectTest()); }},
{ "BUTTON", [] () { return std::unique_ptr<ITest>(new ButtonTest()); }},
{ "VBOX", [] () { return std::unique_ptr<ITest>(new VBoxTest()); }},
{ "HBOX", [] () { return std::unique_ptr<ITest>(new HBoxTest()); }}
{ "HBOX", [] () { return std::unique_ptr<ITest>(new HBoxTest()); }},
{ "HPANE", [] () { return std::unique_ptr<ITest>(new HPaneTest()); }}
};

std::unique_ptr<ITest> ITest::Create(const std::string& testName)
Expand Down
41 changes: 41 additions & 0 deletions sutk/source/tests/HPaneTest.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#include <sutk/tests/HPaneTest.hpp>

#include <sutk/SGEGfxDriver.hpp>
#include <sutk/HPaneContainer.hpp>
#include <sutk/FullWindowContainer.hpp>

namespace SUTK
{
DriverInitializationData HPaneTest::getInitializationData()
{
auto data = ITest::getInitializationData();
data.title = "Horizontal Pane Container Test";
return data;
}

void HPaneTest::initialize(SGE::Driver& driver)
{
m_gfxDriver = new SGEGfxDriver(driver);
m_uiDriver = new UIDriver(*m_gfxDriver);
FullWindowContainer* rootContainer = m_uiDriver->createContainer<FullWindowContainer>(NULL);
m_hPaneContainer = m_uiDriver->createContainer<HPaneContainer>(rootContainer);
m_hPaneContainer->alwaysFitInParent();
m_hPaneContainer->enableDebug();
}

void HPaneTest::terminate(SGE::Driver& driver)
{
delete m_uiDriver;
delete m_gfxDriver;
}

void HPaneTest::render(SGE::Driver& driver)
{
// SUTK::UIDriver::render() should only be called when there is an update in the UI or screen resize
m_uiDriver->render();
}

void HPaneTest::update(SGE::Driver& driver, float deltaTime)
{
}
}

0 comments on commit 0af2684

Please sign in to comment.