diff options
| author | jz0 <[email protected]> | 2020-05-03 22:38:59 +0300 |
|---|---|---|
| committer | jz0 <[email protected]> | 2020-05-03 22:38:59 +0300 |
| commit | fdb81a898151278a66af544dfae6bfcbbf9dc3d2 (patch) | |
| tree | 8884fc5c21b3daf0a32cc145c4488b9e708deec4 /source2-basehook/Renderer/Renderer.cpp | |
| download | archived-source2-basehook-fdb81a898151278a66af544dfae6bfcbbf9dc3d2.tar.xz archived-source2-basehook-fdb81a898151278a66af544dfae6bfcbbf9dc3d2.zip | |
Initial commit
Diffstat (limited to 'source2-basehook/Renderer/Renderer.cpp')
| -rw-r--r-- | source2-basehook/Renderer/Renderer.cpp | 80 |
1 files changed, 80 insertions, 0 deletions
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<Vertex_t> 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 |