From fdb81a898151278a66af544dfae6bfcbbf9dc3d2 Mon Sep 17 00:00:00 2001 From: jz0 Date: Sun, 3 May 2020 22:38:59 +0300 Subject: Initial commit --- source2-basehook/Renderer/Renderer.cpp | 80 ++++++++++++++++++++++++++++++++++ source2-basehook/Renderer/Renderer.hpp | 17 ++++++++ 2 files changed, 97 insertions(+) create mode 100644 source2-basehook/Renderer/Renderer.cpp create mode 100644 source2-basehook/Renderer/Renderer.hpp (limited to 'source2-basehook/Renderer') diff --git a/source2-basehook/Renderer/Renderer.cpp b/source2-basehook/Renderer/Renderer.cpp new file mode 100644 index 0000000..50610c7 --- /dev/null +++ b/source2-basehook/Renderer/Renderer.cpp @@ -0,0 +1,80 @@ +#include "Renderer.hpp" + +IVGuiPaintSurface* pRendererSurface = nullptr; + +void EngineRenderer::DrawRect(int x, int y, int w, int h, Color color) +{ + pRendererSurface->DrawSetColor(color.r, color.g, color.b, color.a); + pRendererSurface->DrawFilledRect(x, y, x + w, y + h); +} + +void EngineRenderer::DrawOutlinedRect(int x, int y, int w, int h, Color color) +{ + pRendererSurface->DrawSetColor(color.r, color.g, color.b, color.a); + pRendererSurface->DrawOutlinedRect(x, y, x + w, y + h); +} + +void EngineRenderer::DrawGradientRect(Vector2D pos, Vector2D size, Color top, Color bottom, bool horizontal) +{ + pRendererSurface->DrawSetColor(top.r, top.g, top.b, top.a); + pRendererSurface->DrawFilledRectFade(pos.x, pos.y, pos.x + size.x, pos.y + size.y, 255, 255, horizontal); + + pRendererSurface->DrawSetColor(bottom.r, bottom.g, bottom.b, bottom.a); + pRendererSurface->DrawFilledRectFade(pos.x, pos.y, pos.x + size.x, pos.y + size.y, 0, 255, horizontal); +} + +void EngineRenderer::DrawLine(int x0, int y0, int x1, int y1, Color color) +{ + pRendererSurface->DrawSetColor(color.r, color.g, color.b, color.a); + pRendererSurface->DrawLine(x0, y0, x1, y1); +} + +void EngineRenderer::DrawColoredCircle(int x, int y, float radius, Color color) +{ + //pRendererSurface->DrawSetColor(color.r, color.g, color.b, color.a); + //pRendererSurface->DrawOutlinedCircle(250, 250, 50, 8); + //pRendererSurface->DrawColoredCircle(x, y, radius, color.r, color.g, color.b, color.a); + pRendererSurface->DrawColoredCircle(x, y, radius, color.r, color.g, color.b, color.a); +} + +void EngineRenderer::DrawTexturedPolygon(int n, Vertex_t* vertice, Color color) +{ + static int TextureID = pRendererSurface->CreateNewTextureID(true); + static unsigned char Buf[4] = { 255, 255, 255, 255 }; + pRendererSurface->DrawSetTextureRGBA(TextureID, Buf, 1, 1); + pRendererSurface->DrawSetColor(color.r, color.g, color.b, color.a); + pRendererSurface->DrawSetTexture(TextureID); + pRendererSurface->DrawTexturedPolygon(n, vertice); +} + +void EngineRenderer::DrawFilledCircle(Vector2D position, float smoothness, float radius, Color color) +{ + std::vector vertices; + float step = (float)M_PI * 2.0f / smoothness; + + for (float a = 0; a < (M_PI * 2.0f); a += step) + vertices.push_back(Vertex_t(Vector2D(radius * cosf(a) + position.x, radius * sinf(a) + position.y))); + + DrawTexturedPolygon((int)smoothness, vertices.data(), color); +} + +void EngineRenderer::DrawString(unsigned long font, int x, int y, Color color, const char* str, ...) +{ + if (!str) + return; + + va_list arg; + char buffer[1024]; + wchar_t wstring[1024]; + + va_start(arg, str); + _vsnprintf_s(buffer, sizeof(buffer), str, arg); + va_end(arg); + + MultiByteToWideChar(CP_UTF8, 0, buffer, 256, wstring, 256); + + pRendererSurface->DrawSetTextPos(x, y); + pRendererSurface->DrawSetTextFont(font); + pRendererSurface->DrawSetTextColor(color.r, color.g, color.b, color.a); + pRendererSurface->DrawPrintText(wstring, wcslen(wstring)); +} \ No newline at end of file diff --git a/source2-basehook/Renderer/Renderer.hpp b/source2-basehook/Renderer/Renderer.hpp new file mode 100644 index 0000000..9d65fd2 --- /dev/null +++ b/source2-basehook/Renderer/Renderer.hpp @@ -0,0 +1,17 @@ +#pragma once +#include "../Source2SDK/SDK.hpp" +#include "../Include.hpp" + +namespace EngineRenderer +{ + void DrawRect(int x, int y, int w, int h, Color color); + void DrawOutlinedRect(int x, int y, int w, int h, Color color); + void DrawGradientRect(Vector2D Position, Vector2D Size, Color Top, Color Bottom, bool Horizontal); + void DrawLine(int x0, int y0, int x1, int y1, Color color); + void DrawColoredCircle(int x, int y, float radius, Color color); + void DrawTexturedPolygon(int n, Vertex_t* vertice, Color color); + void DrawFilledCircle(Vector2D position, float smoothness, float radius, Color color); + void DrawString(unsigned long font, int x, int y, Color color, const char* str, ...); +} + +extern IVGuiPaintSurface* pRendererSurface; \ No newline at end of file -- cgit v1.2.3