designer1337 / csgo-cheat-base

simple csgo internal base.
MIT License
238 stars 50 forks source link

Text Alignment #84

Closed zacherysun closed 3 years ago

zacherysun commented 3 years ago

So does anyone know how to align text to the left(right to left)?

example a93e74d2885ad7c37dc18fbeea60ba6d

VortexShrimp commented 3 years ago

You can draw text with the render::text() function (call in PaintTraverse hook). You can hard code the width to get it to the left or right of the screen or you can use get_screen_size(int& width, int& height) and then subtract the size of the text from the width and draw it there (might require some guessing). You can also get the screen width and height through the directx device and then even draw the text through directx which is arguably better when it comes to performance, but that would require an EndScene or Present hook.

int width;
int height;

interfaces::surface->get_screen_size(width, height);
render::text(width - 10 /*10 for example, subtract size of text*/, 10, /*font*/,  "text", true, /*color*/ );
zacherysun commented 3 years ago

Thanks

bardiukz commented 3 years ago

Wrong! (but not at all)

Use get_screen_size with get_text_size

right to left: screen_width - text_width middle: screen_width - text_width / 2

YNXModz commented 3 years ago

Wrong! (but not at all)

Use get_screen_size with get_text_size

right to left: screen_width - text_width middle: screen_width - text_width / 2

int w, h;
std::string text = "your text";
render::text(w - render::get_text_size(render::fonts::watermark_font, text).x - 10, 10, render::fonts::watermark_font, text, false, color::white());
bardiukz commented 3 years ago

Wrong! (but not at all) Use get_screen_size with get_text_size right to left: screen_width - text_width middle: screen_width - text_width / 2

int w, h;
std::string text = "your text";
render::text(w - render::get_text_size(render::fonts::watermark_font, text).x - 10, 10, render::fonts::watermark_font, text, false, color::white());

where's get_screen_size... but yeah, that's how you use it.