Last active
June 30, 2025 23:34
-
-
Save KN4CK3R/59ff579afd2ed236730757476e41239a to your computer and use it in GitHub Desktop.
OSHGui::Drawing::Renderer implementation with Source Engine
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include "CSGOFont.hpp" | |
| using namespace OSHGui; | |
| using namespace OSHGui::Drawing; | |
| //--------------------------------------------------------------------------- | |
| //Constructor Test | |
| //--------------------------------------------------------------------------- | |
| CSGOFont::CSGOFont(Classes::IMatSystemSurface *surface_, const Misc::AnsiString &name, int size) | |
| : surface(surface_), | |
| font(surface_->CreateFont()) | |
| { | |
| ascender = size; | |
| if (!surface->SetFontGlyphSet(font, name.c_str(), size, 450, 0, 0, 0x400)) | |
| { | |
| throw; | |
| } | |
| } | |
| //--------------------------------------------------------------------------- | |
| //Getter/Setter | |
| //--------------------------------------------------------------------------- | |
| float CSGOFont::GetTextAdvance(const Misc::AnsiString &text, float scaleX) const | |
| { | |
| float width = 0; | |
| for (auto &c : text) | |
| { | |
| auto characterWidth = surface->GetCharacterWidth(font, c); | |
| width += (characterWidth >= 30 ? 10 : characterWidth) * scaleX; | |
| } | |
| return width; | |
| } | |
| //--------------------------------------------------------------------------- | |
| //Runtime-Functions | |
| //--------------------------------------------------------------------------- | |
| float CSGOFont::DrawText(GeometryBuffer &buffer, const Misc::AnsiString &text, const PointF &position, const RectangleF *clip, const ColorRectangle &colors, const float spaceExtra, const float scaleX, const float scaleY) const | |
| { | |
| union | |
| { | |
| struct | |
| { | |
| uint8_t B; | |
| uint8_t G; | |
| uint8_t R; | |
| uint8_t A; | |
| }; | |
| uint32_t ARGB; | |
| }; | |
| ARGB = colors.TopLeft.GetARGB(); | |
| surface->DrawColoredText(font, position.X, position.Y, R, G, B, A, text.c_str()); | |
| return 0; | |
| } | |
| //--------------------------------------------------------------------------- | |
| const OSHGui::Drawing::FontGlyph* CSGOFont::FindFontGlyph(const uint32_t codepoint) const | |
| { | |
| return nullptr; | |
| } | |
| //--------------------------------------------------------------------------- | |
| void CSGOFont::Rasterise(uint32_t start_codepoint, uint32_t end_codepoint) const | |
| { | |
| } | |
| //--------------------------------------------------------------------------- | |
| void CSGOFont::UpdateFont() | |
| { | |
| } | |
| //--------------------------------------------------------------------------- |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #pragma once | |
| #include <Drawing/Font.hpp> | |
| #include "../CSGOClasses.hpp" | |
| #ifdef DrawText | |
| #undef DrawText | |
| #endif | |
| class CSGOFont : public OSHGui::Drawing::Font | |
| { | |
| public: | |
| CSGOFont(Classes::IMatSystemSurface *surface, const OSHGui::Misc::AnsiString &filename, int size); | |
| virtual float DrawText(OSHGui::Drawing::GeometryBuffer &buffer, const OSHGui::Misc::AnsiString &text, const OSHGui::Drawing::PointF &position, const OSHGui::Drawing::RectangleF *clip, const OSHGui::Drawing::ColorRectangle &colors, const float spaceExtra = 0.0f, const float scaleX = 1.0f, const float scaleY = 1.0f) const override; | |
| virtual float GetTextAdvance(const OSHGui::Misc::AnsiString &text, float scaleX = 1.0f) const; | |
| protected: | |
| virtual const OSHGui::Drawing::FontGlyph* FindFontGlyph(const uint32_t codepoint) const override; | |
| virtual void Rasterise(uint32_t start_codepoint, uint32_t end_codepoint) const override; | |
| virtual void UpdateFont() override; | |
| private: | |
| Classes::IMatSystemSurface *surface; | |
| Classes::HFont font; | |
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include "CSGOGeometryBuffer.hpp" | |
| #include "CSGORenderer.hpp" | |
| #include "../CSGOClasses.hpp" | |
| using namespace OSHGui::Drawing; | |
| //--------------------------------------------------------------------------- | |
| //Constructor | |
| //--------------------------------------------------------------------------- | |
| CSGOGeometryBuffer::CSGOGeometryBuffer(CSGORenderer &owner_) | |
| : owner(owner_) | |
| { | |
| } | |
| //--------------------------------------------------------------------------- | |
| //Getter/Setter | |
| //--------------------------------------------------------------------------- | |
| void CSGOGeometryBuffer::SetTranslation(const Vector &translation) | |
| { | |
| } | |
| //--------------------------------------------------------------------------- | |
| void CSGOGeometryBuffer::SetRotation(const Quaternion &rotation) | |
| { | |
| } | |
| //--------------------------------------------------------------------------- | |
| void CSGOGeometryBuffer::SetPivot(const Vector &pivot) | |
| { | |
| } | |
| //--------------------------------------------------------------------------- | |
| void CSGOGeometryBuffer::SetClippingRegion(const RectangleF ®ion) | |
| { | |
| } | |
| //--------------------------------------------------------------------------- | |
| void CSGOGeometryBuffer::SetActiveTexture(const TexturePtr &texture) | |
| { | |
| } | |
| //--------------------------------------------------------------------------- | |
| void CSGOGeometryBuffer::SetClippingActive(const bool active) | |
| { | |
| } | |
| //--------------------------------------------------------------------------- | |
| bool CSGOGeometryBuffer::IsClippingActive() const | |
| { | |
| return false; | |
| } | |
| //--------------------------------------------------------------------------- | |
| //Runtime-Functions | |
| //--------------------------------------------------------------------------- | |
| void CSGOGeometryBuffer::AppendVertex(const Vertex &vertex) | |
| { | |
| throw; | |
| } | |
| //--------------------------------------------------------------------------- | |
| void CSGOGeometryBuffer::AppendGeometry(const Vertex *const vbuff, uint32_t count) | |
| { | |
| union | |
| { | |
| struct | |
| { | |
| uint8_t B; | |
| uint8_t G; | |
| uint8_t R; | |
| uint8_t A; | |
| }; | |
| uint32_t ARGB; | |
| }; | |
| ARGB = vbuff[0].Color.GetARGB(); | |
| auto surface = owner.GetSurface(); | |
| surface->DrawSetColor(R, G, B, A); | |
| if (drawMode == VertexDrawMode::TriangleList && count == 6) | |
| { | |
| surface->DrawFilledRect(vbuff[0].Position.x, vbuff[0].Position.y, vbuff[3].Position.x, vbuff[3].Position.y); | |
| } | |
| else if (drawMode == VertexDrawMode::LineList && count == 2) | |
| { | |
| surface->DrawLine(vbuff[0].Position.x, vbuff[0].Position.y, vbuff[1].Position.x, vbuff[1].Position.y); | |
| } | |
| else | |
| { | |
| throw; | |
| } | |
| } | |
| //--------------------------------------------------------------------------- | |
| void CSGOGeometryBuffer::Draw() const | |
| { | |
| } | |
| //--------------------------------------------------------------------------- | |
| void CSGOGeometryBuffer::Reset() | |
| { | |
| } | |
| //--------------------------------------------------------------------------- |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #pragma once | |
| #include <Drawing/GeometryBuffer.hpp> | |
| class CSGORenderer; | |
| class CSGOGeometryBuffer : public OSHGui::Drawing::GeometryBuffer | |
| { | |
| public: | |
| CSGOGeometryBuffer(CSGORenderer &owner); | |
| virtual void SetTranslation(const OSHGui::Drawing::Vector &translation) override; | |
| virtual void SetRotation(const OSHGui::Drawing::Quaternion &rotation) override; | |
| virtual void SetPivot(const OSHGui::Drawing::Vector &pivot) override; | |
| virtual void SetClippingRegion(const OSHGui::Drawing::RectangleF ®ion) override; | |
| virtual void SetActiveTexture(const OSHGui::Drawing::TexturePtr &texture) override; | |
| virtual void SetClippingActive(const bool active) override; | |
| virtual bool IsClippingActive() const override; | |
| virtual void AppendVertex(const OSHGui::Drawing::Vertex &vertex) override; | |
| virtual void AppendGeometry(const OSHGui::Drawing::Vertex *const vertices, uint32_t count) override; | |
| virtual void Draw() const override; | |
| virtual void Reset() override; | |
| private: | |
| CSGORenderer& owner; | |
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include "CSGORenderer.hpp" | |
| #include "CSGOGeometryBuffer.hpp" | |
| #include "CSGORenderTarget.hpp" | |
| #include "../CSGOClasses.hpp" | |
| #include <Misc/Exceptions.hpp> | |
| using namespace OSHGui::Drawing; | |
| //--------------------------------------------------------------------------- | |
| //Constructor | |
| //--------------------------------------------------------------------------- | |
| CSGORenderer::CSGORenderer(Classes::IMatSystemSurface *surface_, Classes::Engine *engine_) | |
| : surface(surface_), | |
| engine(engine_), | |
| defaultTarget(std::make_shared<CSGORenderTarget>(*this)) | |
| { | |
| SizeI screenSize; | |
| engine->GetScreenSize(screenSize.Width, screenSize.Height); | |
| SetDisplaySize(screenSize); | |
| } | |
| //--------------------------------------------------------------------------- | |
| //Getter/Setter | |
| //--------------------------------------------------------------------------- | |
| Classes::IMatSystemSurface* CSGORenderer::GetSurface() const | |
| { | |
| return surface; | |
| } | |
| //--------------------------------------------------------------------------- | |
| Classes::Engine* CSGORenderer::GetEngine() const | |
| { | |
| return engine; | |
| } | |
| //--------------------------------------------------------------------------- | |
| RenderTargetPtr& CSGORenderer::GetDefaultRenderTarget() | |
| { | |
| return defaultTarget; | |
| } | |
| //--------------------------------------------------------------------------- | |
| void CSGORenderer::SetDisplaySize(const SizeF &size) | |
| { | |
| displaySize = size; | |
| } | |
| //--------------------------------------------------------------------------- | |
| const SizeF& CSGORenderer::GetDisplaySize() const | |
| { | |
| return displaySize; | |
| } | |
| //--------------------------------------------------------------------------- | |
| const PointF& CSGORenderer::GetDisplayDPI() const | |
| { | |
| throw; | |
| } | |
| //--------------------------------------------------------------------------- | |
| uint32_t CSGORenderer::GetMaximumTextureSize() const | |
| { | |
| throw; | |
| } | |
| //--------------------------------------------------------------------------- | |
| //Runtime-Functions | |
| //--------------------------------------------------------------------------- | |
| GeometryBufferPtr CSGORenderer::CreateGeometryBuffer() | |
| { | |
| return std::make_shared<CSGOGeometryBuffer>(*this); | |
| } | |
| //--------------------------------------------------------------------------- | |
| TextureTargetPtr CSGORenderer::CreateTextureTarget() | |
| { | |
| throw; | |
| } | |
| //--------------------------------------------------------------------------- | |
| TexturePtr CSGORenderer::CreateTexture() | |
| { | |
| throw; | |
| } | |
| //--------------------------------------------------------------------------- | |
| TexturePtr CSGORenderer::CreateTexture(const OSHGui::Misc::AnsiString &filename) | |
| { | |
| throw; | |
| } | |
| //--------------------------------------------------------------------------- | |
| TexturePtr CSGORenderer::CreateTexture(const SizeF &size) | |
| { | |
| throw; | |
| } | |
| //--------------------------------------------------------------------------- | |
| void CSGORenderer::BeginRendering() | |
| { | |
| } | |
| //--------------------------------------------------------------------------- | |
| void CSGORenderer::EndRendering() | |
| { | |
| } | |
| //--------------------------------------------------------------------------- |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #pragma once | |
| #include <Drawing/Renderer.hpp> | |
| namespace Classes | |
| { | |
| class IMatSystemSurface; | |
| class Engine; | |
| } | |
| class CSGORenderer : public OSHGui::Drawing::Renderer | |
| { | |
| public: | |
| CSGORenderer(Classes::IMatSystemSurface *surface, Classes::Engine *engine); | |
| Classes::IMatSystemSurface* GetSurface() const; | |
| Classes::Engine* GetEngine() const; | |
| virtual OSHGui::Drawing::RenderTargetPtr& GetDefaultRenderTarget() override; | |
| virtual OSHGui::Drawing::GeometryBufferPtr CreateGeometryBuffer() override; | |
| virtual OSHGui::Drawing::TextureTargetPtr CreateTextureTarget() override; | |
| virtual OSHGui::Drawing::TexturePtr CreateTexture() override; | |
| virtual OSHGui::Drawing::TexturePtr CreateTexture(const OSHGui::Misc::AnsiString &filename) override; | |
| virtual OSHGui::Drawing::TexturePtr CreateTexture(const OSHGui::Drawing::SizeF &size) override; | |
| virtual void BeginRendering() override; | |
| virtual void EndRendering() override; | |
| virtual void SetDisplaySize(const OSHGui::Drawing::SizeF &sz) override; | |
| virtual const OSHGui::Drawing::SizeF& GetDisplaySize() const override; | |
| virtual const OSHGui::Drawing::PointF& GetDisplayDPI() const override; | |
| virtual uint32_t GetMaximumTextureSize() const override; | |
| private: | |
| Classes::IMatSystemSurface *surface; | |
| Classes::Engine *engine; | |
| OSHGui::Drawing::SizeF displaySize; | |
| OSHGui::Drawing::RenderTargetPtr defaultTarget; | |
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include "CSGORenderTarget.hpp" | |
| #include "CSGORenderer.hpp" | |
| #include "CSGOGeometryBuffer.hpp" | |
| #include <Drawing/RenderQueue.hpp> | |
| #include <Drawing/RenderTarget.hpp> | |
| #include <Drawing/Rectangle.hpp> | |
| using namespace OSHGui::Drawing; | |
| //--------------------------------------------------------------------------- | |
| //Constructor | |
| //--------------------------------------------------------------------------- | |
| CSGORenderTarget::CSGORenderTarget(CSGORenderer &owner_) | |
| : owner(owner_) | |
| { | |
| } | |
| //--------------------------------------------------------------------------- | |
| //Getter/Setter | |
| //--------------------------------------------------------------------------- | |
| void CSGORenderTarget::SetArea(const RectangleF &_area) | |
| { | |
| } | |
| //--------------------------------------------------------------------------- | |
| const RectangleF& CSGORenderTarget::GetArea() const | |
| { | |
| throw; | |
| } | |
| //--------------------------------------------------------------------------- | |
| //Runtime-Functions | |
| //--------------------------------------------------------------------------- | |
| void CSGORenderTarget::Draw(const GeometryBuffer &buffer) | |
| { | |
| buffer.Draw(); | |
| } | |
| //--------------------------------------------------------------------------- | |
| void CSGORenderTarget::Draw(const RenderQueue &queue) | |
| { | |
| queue.Draw(); | |
| } | |
| //--------------------------------------------------------------------------- | |
| void CSGORenderTarget::Activate() | |
| { | |
| } | |
| //--------------------------------------------------------------------------- | |
| void CSGORenderTarget::Deactivate() | |
| { | |
| } | |
| //--------------------------------------------------------------------------- | |
| bool CSGORenderTarget::IsImageryCache() const | |
| { | |
| return false; | |
| } | |
| //--------------------------------------------------------------------------- |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #pragma once | |
| #include <Drawing/RenderTarget.hpp> | |
| #include <Drawing/Rectangle.hpp> | |
| #include "CSGOGeometryBuffer.hpp" | |
| class CSGORenderer; | |
| class CSGORenderTarget : public OSHGui::Drawing::RenderTarget | |
| { | |
| public: | |
| CSGORenderTarget(CSGORenderer &owner); | |
| virtual void SetArea(const OSHGui::Drawing::RectangleF &area) override; | |
| virtual const OSHGui::Drawing::RectangleF& GetArea() const override; | |
| virtual void Draw(const OSHGui::Drawing::GeometryBuffer &buffer) override; | |
| virtual void Draw(const OSHGui::Drawing::RenderQueue &queue) override; | |
| virtual void Activate() override; | |
| virtual void Deactivate() override; | |
| virtual bool IsImageryCache() const override; | |
| private: | |
| CSGORenderer &owner; | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment