diff --git a/SHADE_Managed/premake5.lua b/SHADE_Managed/premake5.lua index 70b01e18..463e80b8 100644 --- a/SHADE_Managed/premake5.lua +++ b/SHADE_Managed/premake5.lua @@ -33,6 +33,8 @@ project "SHADE_Managed" "%{IncludeDir.imgui}", "%{IncludeDir.imguizmo}", "%{IncludeDir.imnodes}", + "%{IncludeDir.msdf_atlas_gen}", + "%{IncludeDir.msdfgen}", "%{IncludeDir.yamlcpp}", "%{IncludeDir.SDL}\\include", "%{IncludeDir.RTTR}/include", @@ -53,6 +55,8 @@ project "SHADE_Managed" links { "yaml-cpp", + "msdfgen", + "msdf-atlas-gen", "imgui", "SDL2.lib", "SDL2main.lib", @@ -89,6 +93,8 @@ project "SHADE_Managed" dependson { "yaml-cpp", + "msdfgen", + "msdf-atlas-gen", "imgui", "SHADE_Engine" } diff --git a/SHADE_Managed/src/Assets/Font.cxx b/SHADE_Managed/src/Assets/Font.cxx new file mode 100644 index 00000000..782b0688 --- /dev/null +++ b/SHADE_Managed/src/Assets/Font.cxx @@ -0,0 +1,32 @@ +/************************************************************************************//*! +\file Font.cxx +\author Tng Kah Wei, kahwei.tng, 390009620 +\par email: kahwei.tng\@digipen.edu +\date Oct 28, 2022 +\brief Contains the implementation of the functions of the managed Font class. + + Note: This file is written in C++17/CLI. + +Copyright (C) 2022 DigiPen Institute of Technology. +Reproduction or disclosure of this file or its contents without the prior written consent +of DigiPen Institute of Technology is prohibited. +*//*************************************************************************************/ +// Precompiled Headers +#include "SHpch.h" +// Primary Header +#include "Font.hxx" + +namespace SHADE +{ + /*---------------------------------------------------------------------------------*/ + /* Explicit Template Instantiation */ + /*---------------------------------------------------------------------------------*/ + template ref class NativeAsset; + + /*---------------------------------------------------------------------------------*/ + /* Constructors/Destructor */ + /*---------------------------------------------------------------------------------*/ + Font::Font(Handle font) + : NativeAsset { font } + {} +} diff --git a/SHADE_Managed/src/Assets/Font.hxx b/SHADE_Managed/src/Assets/Font.hxx new file mode 100644 index 00000000..fd194d1a --- /dev/null +++ b/SHADE_Managed/src/Assets/Font.hxx @@ -0,0 +1,41 @@ +/************************************************************************************//*! +\file Font.hxx +\author Tng Kah Wei, kahwei.tng, 390009620 +\par email: kahwei.tng\@digipen.edu +\date Oct 28, 2022 +\brief Contains the definition of the managed Font class. + + Note: This file is written in C++17/CLI. + +Copyright (C) 2022 DigiPen Institute of Technology. +Reproduction or disclosure of this file or its contents without the prior written consent +of DigiPen Institute of Technology is prohibited. +*//*************************************************************************************/ +#pragma once + +// External Dependencies +#include "Resource/SHHandle.h" +#include "Graphics/MiddleEnd/TextRendering/SHFont.h" +// Project Includes +#include "NativeAsset.hxx" +#include "Engine/GenericHandle.hxx" + +namespace SHADE +{ + /// + /// Managed counterpart of the native Font object that can be fed to TextRenderables + /// for rendering. + /// + public ref class Font : public NativeAsset + { + internal: + /*-----------------------------------------------------------------------------*/ + /* Constructors/Destructor */ + /*-----------------------------------------------------------------------------*/ + /// + /// Constructor for the Font. + /// + /// Handle to the font object. + Font(Handle font); + }; +} diff --git a/SHADE_Managed/src/Assets/NativeAsset.h++ b/SHADE_Managed/src/Assets/NativeAsset.h++ index a4cd94b4..6b583a5c 100644 --- a/SHADE_Managed/src/Assets/NativeAsset.h++ +++ b/SHADE_Managed/src/Assets/NativeAsset.h++ @@ -16,6 +16,7 @@ of DigiPen Institute of Technology is prohibited. // Primary Include #include "NativeAsset.hxx" +#include "Utility/Convert.hxx" namespace SHADE { diff --git a/SHADE_Managed/src/Components/TextRenderable.cxx b/SHADE_Managed/src/Components/TextRenderable.cxx new file mode 100644 index 00000000..c5859854 --- /dev/null +++ b/SHADE_Managed/src/Components/TextRenderable.cxx @@ -0,0 +1,57 @@ +/************************************************************************************//*! +\file TextRenderable.cxx +\author Tng Kah Wei, kahwei.tng, 390009620 +\par email: kahwei.tng\@digipen.edu +\date Oct 28, 2022 +\brief Contains the definition of the functions of the managed TextRenderable + class. + + Note: This file is written in C++17/CLI. + +Copyright (C) 2022 DigiPen Institute of Technology. +Reproduction or disclosure of this file or its contents without the prior written consent +of DigiPen Institute of Technology is prohibited. +*//*************************************************************************************/ +// Precompiled Headers +#include "SHpch.h" +// Primary Header +#include "TextRenderable.hxx" +#include "Assets/NativeAsset.hxx" +#include "Utility/Convert.hxx" + +namespace SHADE +{ + /*---------------------------------------------------------------------------------*/ + /* Constructors */ + /*---------------------------------------------------------------------------------*/ + TextRenderable::TextRenderable(Entity entity) + : Component(entity) + {} + + /*---------------------------------------------------------------------------------*/ + /* Properties */ + /*---------------------------------------------------------------------------------*/ + System::String^ TextRenderable::Text::get() + { + return Convert::ToCLI(GetNativeComponent()->GetText()); + } + void TextRenderable::Text::set(System::String^ value) + { + GetNativeComponent()->SetText(Convert::ToNative(value)); + } + SHADE::Font^ TextRenderable::Font::get() + { + return gcnew SHADE::Font(GetNativeComponent()->GetFont()); + } + void TextRenderable::Font::set(SHADE::Font^ value) + { + if (value == nullptr) + { + GetNativeComponent()->SetFont(Handle()); + } + else + { + GetNativeComponent()->SetFont(Handle(Convert::ToNative(value->NativeObjectHandle))); + } + } +} diff --git a/SHADE_Managed/src/Components/TextRenderable.hxx b/SHADE_Managed/src/Components/TextRenderable.hxx new file mode 100644 index 00000000..5418b6e5 --- /dev/null +++ b/SHADE_Managed/src/Components/TextRenderable.hxx @@ -0,0 +1,65 @@ +/************************************************************************************//*! +\file TextRenderable.hxx +\author Tng Kah Wei, kahwei.tng, 390009620 +\par email: kahwei.tng\@digipen.edu +\date Nov 21, 2022 +\brief Contains the definition of the managed TextRenderable class with the + declaration of functions for working with it. + + Note: This file is written in C++17/CLI. + +Copyright (C) 2022 DigiPen Institute of Technology. +Reproduction or disclosure of this file or its contents without the prior written consent +of DigiPen Institute of Technology is prohibited. +*//*************************************************************************************/ +#pragma once + +// External Dependencies +#include "Graphics/MiddleEnd/TextRendering/SHTextRenderableComponent.h" +// Project Includes +#include "Components/Component.hxx" +#include "Math/Vector3.hxx" +#include "Math/Quaternion.hxx" +#include "Assets/Font.hxx" + +namespace SHADE +{ + /// + /// CLR version of the SHADE Engine's SHTextRenderableComponent. + /// + public ref class TextRenderable : public Component + { + internal: + /*-----------------------------------------------------------------------------*/ + /* Constructors */ + /*-----------------------------------------------------------------------------*/ + /// + /// Constructs a TextRenderable Component that represents a native TextRenderable + /// component tied to the specified Entity. + /// + /// Entity that this Component will be tied to. + TextRenderable(Entity entity); + + public: + /*-----------------------------------------------------------------------------*/ + /* Properties */ + /*-----------------------------------------------------------------------------*/ + /// + /// Text to render using this TextRenderable. + /// + property System::String^ Text + { + System::String^ get(); + void set(System::String^ value); + } + /// + /// Font to use to render using this TextRenderable. + /// + property SHADE::Font^ Font + { + SHADE::Font^ get(); + void set(SHADE::Font^ value); + } + }; +} + diff --git a/SHADE_Managed/src/Utility/Convert.cxx b/SHADE_Managed/src/Utility/Convert.cxx index 38ea2f50..590a3cf0 100644 --- a/SHADE_Managed/src/Utility/Convert.cxx +++ b/SHADE_Managed/src/Utility/Convert.cxx @@ -89,6 +89,8 @@ namespace SHADE /*---------------------------------------------------------------------------------*/ std::string Convert::ToNative(System::String^ str) { + if (str == nullptr) + return ""; return msclr::interop::marshal_as(str); }