Text Rendering
This commit is contained in:
51
Engine/Src/Inc/IAEngine/Components/IUIComponent.hpp
Normal file
51
Engine/Src/Inc/IAEngine/Components/IUIComponent.hpp
Normal file
@ -0,0 +1,51 @@
|
||||
// IAEngine: 2D Game Engine by IA
|
||||
// Copyright (C) 2025 IASoft (PVT) LTD (oss@iasoft.dev)
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <IAEngine/Base.hpp>
|
||||
|
||||
namespace ia::iae
|
||||
{
|
||||
class UINode;
|
||||
|
||||
class IUIComponent
|
||||
{
|
||||
public:
|
||||
PURE_VIRTUAL(VOID Draw());
|
||||
PURE_VIRTUAL(VOID DebugDraw());
|
||||
PURE_VIRTUAL(VOID Update());
|
||||
PURE_VIRTUAL(VOID FixedUpdate());
|
||||
|
||||
public:
|
||||
IUIComponent(IN UINode *node) : m_node(node)
|
||||
{
|
||||
}
|
||||
|
||||
UINode *GetNode()
|
||||
{
|
||||
return m_node;
|
||||
}
|
||||
|
||||
CONST UINode *GetNode() CONST
|
||||
{
|
||||
return m_node;
|
||||
}
|
||||
|
||||
protected:
|
||||
UINode *CONST m_node{};
|
||||
};
|
||||
}
|
||||
48
Engine/Src/Inc/IAEngine/Components/UILabelComponent.hpp
Normal file
48
Engine/Src/Inc/IAEngine/Components/UILabelComponent.hpp
Normal file
@ -0,0 +1,48 @@
|
||||
// IAEngine: 2D Game Engine by IA
|
||||
// Copyright (C) 2025 IASoft (PVT) LTD (oss@iasoft.dev)
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <IAEngine/Components/IUIComponent.hpp>
|
||||
|
||||
namespace ia::iae
|
||||
{
|
||||
class UILabelComponent : public IUIComponent
|
||||
{
|
||||
public:
|
||||
UILabelComponent(IN UINode* node);
|
||||
|
||||
String &Label()
|
||||
{
|
||||
return m_label;
|
||||
}
|
||||
|
||||
CONST String &Label() CONST
|
||||
{
|
||||
return m_label;
|
||||
}
|
||||
|
||||
public:
|
||||
VOID Draw();
|
||||
VOID DebugDraw();
|
||||
|
||||
VOID Update();
|
||||
VOID FixedUpdate();
|
||||
|
||||
private:
|
||||
String m_label{};
|
||||
};
|
||||
} // namespace ia::iae
|
||||
@ -44,11 +44,14 @@ namespace ia::iae
|
||||
|
||||
// Renderer Functions
|
||||
STATIC Handle GetGeometry_Quad();
|
||||
STATIC Handle GetGeometry_Circle();
|
||||
STATIC Handle CreateGeometry(IN CONST Vector<GeometryVertex> &vertices, IN CONST Vector<INT32> &indices);
|
||||
STATIC VOID DestroyGeometry(IN Handle geometry);
|
||||
STATIC VOID DrawGeometry(IN Handle handle, IN UINT8 layer, IN UINT16 sortIndex);
|
||||
STATIC IVec2 GetDisplayExtent();
|
||||
STATIC FLOAT32 GetDisplayAspectRatio();
|
||||
STATIC VOID ResizeDisplay(IN INT32 newWidth, IN INT32 newHeight);
|
||||
STATIC VOID DrawText(IN CONST String& text, IN Vec2 position, IN FLOAT32 scale, IN FLOAT32 rotation, IN UINT8 layer, IN UINT16 sortIndex);
|
||||
|
||||
// Renderer State Functions
|
||||
STATIC VOID SetRenderState_Scissor(IN IVec4 rect);
|
||||
@ -96,33 +99,35 @@ namespace ia::iae
|
||||
|
||||
// Scene Functions
|
||||
STATIC Scene *GetActiveScene();
|
||||
STATIC VOID ChangeActiveScene(IN RefPtr<Scene> scene);
|
||||
STATIC VOID ChangeActiveScene(IN Scene* scene);
|
||||
STATIC VOID AddNodeToActiveScene(IN RefPtr<INode> node);
|
||||
STATIC INode *GetNodeFromActiveScene(IN CONST String &name);
|
||||
STATIC VOID RemoveNodeFromActiveScene(IN CONST String &name);
|
||||
|
||||
// Input Functions
|
||||
STATIC Vec2 GetInputAxis();
|
||||
STATIC VOID SwitchInputModeToText();
|
||||
STATIC VOID SwitchInputModeToAction();
|
||||
STATIC Vec2 GetInputPointerPosition();
|
||||
STATIC BOOL IsInputKeyDown(IN InputKey key);
|
||||
STATIC BOOL WasInputKeyPressed(IN InputKey key);
|
||||
STATIC BOOL WasInputKeyReleased(IN InputKey key);
|
||||
STATIC BOOL IsInputActionDown(IN Handle action);
|
||||
STATIC BOOL WasInputActionPressed(IN Handle action);
|
||||
STATIC BOOL WasInputActionReleased(IN Handle action);
|
||||
STATIC BOOL IsInputActionDown(IN CONST String &action);
|
||||
STATIC BOOL WasInputActionPressed(IN CONST String &action);
|
||||
STATIC BOOL WasInputActionReleased(IN CONST String &action);
|
||||
STATIC Handle BindInputAction(IN CONST String &name, IN InputKey key);
|
||||
STATIC VOID BindInputAxis(IN InputKey upKey, IN InputKey downKey, IN InputKey leftKey, IN InputKey rightKey);
|
||||
STATIC VOID SetAxisUp(IN BOOL v);
|
||||
STATIC VOID SetAxisDown(IN BOOL v);
|
||||
STATIC VOID SetAxisLeft(IN BOOL v);
|
||||
STATIC VOID SetAxisRight(IN BOOL v);
|
||||
STATIC VOID SetKey(IN InputKey key, IN BOOL state);
|
||||
STATIC VOID SetAxis(IN BOOL up, IN BOOL down, IN BOOL left, IN BOOL right);
|
||||
STATIC VOID Input_SwitchModeToText();
|
||||
STATIC VOID Input_SwitchModeToAction();
|
||||
STATIC Vec2 Input_GetPointerPosition();
|
||||
STATIC BOOL Input_IsKeyDown(IN InputKey key);
|
||||
STATIC BOOL Input_WasKeyPressed(IN InputKey key);
|
||||
STATIC BOOL Input_WasKeyReleased(IN InputKey key);
|
||||
STATIC VOID Input_SetupOnScreenGamePad();
|
||||
STATIC VOID Input_SetupKeyboardGamePad(IN InputKey axisLeft, IN InputKey axisRight, IN InputKey axisDown,
|
||||
IN InputKey axisUp, IN InputKey buttonA, IN InputKey buttonB,
|
||||
IN InputKey buttonC, IN InputKey buttonD);
|
||||
STATIC BOOL Input_GetButtonA();
|
||||
STATIC BOOL Input_GetButtonB();
|
||||
STATIC BOOL Input_GetButtonC();
|
||||
STATIC BOOL Input_GetButtonD();
|
||||
STATIC INT16 Input_GetVerticalAxis();
|
||||
STATIC INT16 Input_GetHorizontalAxis();
|
||||
STATIC IVec2 Input_GetDirectionalInput();
|
||||
STATIC VOID Input_SetButtonA(IN BOOL value);
|
||||
STATIC VOID Input_SetButtonB(IN BOOL value);
|
||||
STATIC VOID Input_SetButtonC(IN BOOL value);
|
||||
STATIC VOID Input_SetButtonD(IN BOOL value);
|
||||
STATIC VOID Input_SetVerticalAxis(IN INT16 value);
|
||||
STATIC VOID Input_SetHorizontalAxis(IN INT16 value);
|
||||
|
||||
// Utility Functions
|
||||
STATIC String ReadTextAsset(IN CONST String& path);
|
||||
|
||||
@ -23,8 +23,10 @@ using namespace ia::iae;
|
||||
|
||||
struct GameRequestedConfig
|
||||
{
|
||||
INT32 ScreenWidth{};
|
||||
INT32 ScreenHeight{};
|
||||
INT32 DesignWidth{};
|
||||
INT32 DesignHeight{};
|
||||
INT32 WindowWidth{};
|
||||
INT32 WindowHeight{};
|
||||
};
|
||||
|
||||
C_DECL(GameRequestedConfig* Game_GetConfigRequest());
|
||||
|
||||
0
Engine/Src/Inc/IAEngine/Nodes/UIButtonNode.hpp
Normal file
0
Engine/Src/Inc/IAEngine/Nodes/UIButtonNode.hpp
Normal file
0
Engine/Src/Inc/IAEngine/Nodes/UIImageNode.hpp
Normal file
0
Engine/Src/Inc/IAEngine/Nodes/UIImageNode.hpp
Normal file
38
Engine/Src/Inc/IAEngine/Nodes/UILabelNode.hpp
Normal file
38
Engine/Src/Inc/IAEngine/Nodes/UILabelNode.hpp
Normal file
@ -0,0 +1,38 @@
|
||||
// IAEngine: 2D Game Engine by IA
|
||||
// Copyright (C) 2025 IASoft (PVT) LTD (oss@iasoft.dev)
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <IAEngine/Components/UILabelComponent.hpp>
|
||||
#include <IAEngine/Nodes/UINode.hpp>
|
||||
|
||||
namespace ia::iae
|
||||
{
|
||||
class UILabelNode : public UINode
|
||||
{
|
||||
public:
|
||||
UILabelNode(IN CONST String &name);
|
||||
|
||||
public:
|
||||
UILabelComponent *GetLabelComponent()
|
||||
{
|
||||
return m_labelComponent;
|
||||
}
|
||||
|
||||
protected:
|
||||
UILabelComponent *CONST m_labelComponent{};
|
||||
};
|
||||
} // namespace ia::iae
|
||||
@ -17,8 +17,161 @@
|
||||
#pragma once
|
||||
|
||||
#include <IAEngine/Nodes/INode.hpp>
|
||||
#include <IAEngine/Components/IUIComponent.hpp>
|
||||
|
||||
namespace ia::iae
|
||||
{
|
||||
|
||||
class UINode : public INode
|
||||
{
|
||||
public:
|
||||
UINode(IN CONST String &name);
|
||||
~UINode();
|
||||
|
||||
public:
|
||||
template<typename _component_type> _component_type *AddComponent()
|
||||
{
|
||||
const auto t = new _component_type(this);
|
||||
m_components.pushBack(t);
|
||||
return t;
|
||||
}
|
||||
|
||||
template<typename _component_type> _component_type *GetComponent()
|
||||
{
|
||||
for (auto &c : m_components)
|
||||
{
|
||||
_component_type *comp = dynamic_cast<_component_type *>(c);
|
||||
if (comp)
|
||||
return comp;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
template<typename _component_type> Vector<_component_type *> GetComponents()
|
||||
{
|
||||
Vector<_component_type *> result;
|
||||
for (auto &c : m_components)
|
||||
{
|
||||
_component_type *comp = dynamic_cast<_component_type *>(c);
|
||||
if (comp)
|
||||
result.pushBack(comp);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
VOID AddChild(IN RefPtr<UINode> node)
|
||||
{
|
||||
node->m_parent = this;
|
||||
m_children.pushBack(node);
|
||||
}
|
||||
|
||||
public:
|
||||
VOID Translate(IN Vec2 v)
|
||||
{
|
||||
m_local.Position += v;
|
||||
RecalculatePosition();
|
||||
}
|
||||
|
||||
VOID Scale(IN FLOAT32 v)
|
||||
{
|
||||
m_local.Scale *= v;
|
||||
RecalculateScale();
|
||||
}
|
||||
|
||||
VOID Rotate(IN FLOAT32 v)
|
||||
{
|
||||
m_local.Rotation += v;
|
||||
RecalculateRotation();
|
||||
}
|
||||
|
||||
VOID SetLocalPosition(IN CONST Vec2 &v)
|
||||
{
|
||||
m_local.Position = v;
|
||||
RecalculatePosition();
|
||||
}
|
||||
|
||||
VOID SetLocalScale(IN CONST FLOAT32 &v)
|
||||
{
|
||||
m_local.Scale = v;
|
||||
RecalculateScale();
|
||||
}
|
||||
|
||||
VOID SetLocalRotation(IN FLOAT32 v)
|
||||
{
|
||||
m_local.Rotation = v;
|
||||
RecalculateRotation();
|
||||
}
|
||||
|
||||
public:
|
||||
CONST Vec2 &GetPosition() CONST
|
||||
{
|
||||
return m_global.Position;
|
||||
}
|
||||
|
||||
CONST FLOAT32 &GetScale() CONST
|
||||
{
|
||||
return m_global.Scale;
|
||||
}
|
||||
|
||||
CONST FLOAT32 &GetRotation() CONST
|
||||
{
|
||||
return m_global.Rotation;
|
||||
}
|
||||
|
||||
CONST Vec2 &GetLocalPosition() CONST
|
||||
{
|
||||
return m_local.Position;
|
||||
}
|
||||
|
||||
CONST FLOAT32 &GetLocalScale() CONST
|
||||
{
|
||||
return m_local.Scale;
|
||||
}
|
||||
|
||||
CONST FLOAT32 &GetLocalRotation() CONST
|
||||
{
|
||||
return m_local.Rotation;
|
||||
}
|
||||
|
||||
protected:
|
||||
VOID RecalculatePosition()
|
||||
{
|
||||
m_global.Position = (m_parent ? m_parent->GetPosition() : Vec2{}) + m_local.Position;
|
||||
for (auto &c : m_children)
|
||||
c->RecalculatePosition();
|
||||
}
|
||||
|
||||
VOID RecalculateRotation()
|
||||
{
|
||||
m_global.Rotation = (m_parent ? m_parent->GetRotation() : 0) + m_local.Rotation;
|
||||
for (auto &c : m_children)
|
||||
c->RecalculateRotation();
|
||||
}
|
||||
|
||||
VOID RecalculateScale()
|
||||
{
|
||||
m_global.Scale = (m_parent ? m_parent->GetScale() : 0.0f) + m_local.Scale;
|
||||
for (auto &c : m_children)
|
||||
c->RecalculateScale();
|
||||
}
|
||||
|
||||
protected:
|
||||
UINode* m_parent{};
|
||||
Vector<IUIComponent *> m_components;
|
||||
Vector<RefPtr<UINode>> m_children{};
|
||||
|
||||
private:
|
||||
struct
|
||||
{
|
||||
FLOAT32 Rotation{0.0f};
|
||||
Vec2 Position{0.0f, 0.0f};
|
||||
FLOAT32 Scale{1.0f};
|
||||
} m_local{}, m_global{};
|
||||
|
||||
public:
|
||||
VOID Draw();
|
||||
VOID DebugDraw();
|
||||
|
||||
VOID Update();
|
||||
VOID FixedUpdate();
|
||||
};
|
||||
}
|
||||
0
Engine/Src/Inc/IAEngine/Nodes/UITextNode.hpp
Normal file
0
Engine/Src/Inc/IAEngine/Nodes/UITextNode.hpp
Normal file
@ -24,10 +24,8 @@ namespace ia::iae
|
||||
class Scene
|
||||
{
|
||||
public:
|
||||
Scene();
|
||||
STATIC RefPtr<Scene> Create();
|
||||
STATIC RefPtr<Scene> Create(
|
||||
IN CONST String &sceneXML, IN std::function<RefPtr<Node2D>(IN CONST String &, IN Handle)> getCustomNode,
|
||||
IN std::function<Handle(IN ResourceType type, IN CONST String &, IN INT64)> getResource);
|
||||
|
||||
public:
|
||||
VOID AddNode(IN RefPtr<INode> node);
|
||||
@ -70,11 +68,11 @@ namespace ia::iae
|
||||
Map<String, RefPtr<INode>> m_nodes;
|
||||
|
||||
public:
|
||||
VOID Draw();
|
||||
VOID DebugDraw();
|
||||
|
||||
VOID FixedUpdate();
|
||||
VOID Update();
|
||||
VIRTUAL VOID Draw();
|
||||
VIRTUAL VOID DebugDraw();
|
||||
|
||||
VIRTUAL VOID FixedUpdate();
|
||||
VIRTUAL VOID Update();
|
||||
|
||||
private:
|
||||
VOID OnActivate();
|
||||
|
||||
50
Engine/Src/Inc/IAEngine/SceneManager.hpp
Normal file
50
Engine/Src/Inc/IAEngine/SceneManager.hpp
Normal file
@ -0,0 +1,50 @@
|
||||
// IAEngine: 2D Game Engine by IA
|
||||
// Copyright (C) 2025 IASoft (PVT) LTD (oss@iasoft.dev)
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <IAEngine/Scene.hpp>
|
||||
|
||||
namespace ia::iae
|
||||
{
|
||||
class SceneManager
|
||||
{
|
||||
public:
|
||||
SceneManager(IN std::function<RefPtr<Node2D>(IN CONST String &, IN CONST Vector<String>&)> getCustomNode,
|
||||
IN std::function<Handle(IN ResourceType type, IN CONST String &, IN INT64)> getResource);
|
||||
~SceneManager();
|
||||
|
||||
VOID SwitchTo(IN CONST String &name);
|
||||
|
||||
Scene *GetScene(IN CONST String &name);
|
||||
|
||||
public:
|
||||
template<typename SceneType> SceneType* AddScene(IN CONST String &name, IN CONST String &xml)
|
||||
{
|
||||
const auto t = (Scene*)new SceneType();
|
||||
AddScene(t, name, xml);
|
||||
return (SceneType*)t;
|
||||
}
|
||||
|
||||
private:
|
||||
VOID AddScene(IN Scene *scene, IN CONST String &name, IN CONST String &xml);
|
||||
|
||||
private:
|
||||
Map<String, Scene *> m_scenes;
|
||||
std::function<RefPtr<Node2D>(IN CONST String &, IN CONST Vector<String>&)> m_customNodeGetter;
|
||||
std::function<Handle(IN ResourceType type, IN CONST String &, IN INT64)> m_resourceGetter;
|
||||
};
|
||||
} // namespace ia::iae
|
||||
@ -22,6 +22,9 @@ namespace ia::iae
|
||||
{
|
||||
class UI
|
||||
{
|
||||
public:
|
||||
STATIC CONSTEXPR UINT8 MAX_VARIABLE_COUNT = 10;
|
||||
|
||||
public:
|
||||
STATIC VOID AddFontFromFile(IN CONST String &path);
|
||||
|
||||
@ -33,6 +36,18 @@ namespace ia::iae
|
||||
STATIC VOID AddPointerExitEvent(IN PCCHAR elementId, IN std::function<VOID()> callback);
|
||||
STATIC VOID AddPointerEnterEvent(IN PCCHAR elementId, IN std::function<VOID()> callback);
|
||||
|
||||
STATIC VOID SetNumericVariable(IN UINT8 index, IN INT64 value);
|
||||
STATIC VOID SetStringVariable(IN UINT8 index, IN CONST String &value);
|
||||
|
||||
STATIC INT64 GetNumericVariable(IN UINT8 index);
|
||||
STATIC String GetStringVariable(IN UINT8 index);
|
||||
|
||||
STATIC INT32 GetElementWidth(IN CONST String &elementId);
|
||||
STATIC VOID SetElementWidth(IN CONST String &elementId, IN INT32 value);
|
||||
|
||||
STATIC INT32 GetElementHeight(IN CONST String &elementId);
|
||||
STATIC VOID SetElementHeight(IN CONST String &elementId, IN INT32 value);
|
||||
|
||||
public:
|
||||
STATIC VOID Initialize();
|
||||
STATIC VOID Terminate();
|
||||
@ -42,5 +57,9 @@ namespace ia::iae
|
||||
|
||||
STATIC VOID OnSDLEvent(IN PVOID event);
|
||||
STATIC VOID OnScreenResize(IN INT32 newWidth, IN INT32 newHeight);
|
||||
|
||||
private:
|
||||
STATIC INT64 s_numericVariables[MAX_VARIABLE_COUNT];
|
||||
STATIC std::string s_stringVariables[MAX_VARIABLE_COUNT];
|
||||
};
|
||||
} // namespace ia::iae
|
||||
Reference in New Issue
Block a user