Advertisement
Guest User

Untitled

a guest
Feb 18th, 2020
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. void draw_text(int x, int y, unsigned long font, std::string string, bool text_centered, color colour)
  2. {
  3. DWORD const BuffSize = MultiByteToWideChar(CP_UTF8, 0, string.c_str(), string.length(), NULL, NULL);
  4. if (!BuffSize)
  5. return;
  6.  
  7. std::vector<wchar_t> Buffer;
  8. Buffer.resize(BuffSize);
  9.  
  10. if(!MultiByteToWideChar( CP_UTF8, 0, string.c_str(), -1, &Buffer[0], BuffSize ))
  11. return;
  12.  
  13. int width, height;
  14. interfaces::surface->get_text_size( font, Buffer.data(), width, height );
  15. interfaces::surface->set_text_color( colour.r, colour.g, colour.b, colour.a );
  16. interfaces::surface->draw_text_font( font );
  17.  
  18. if ( text_centered )
  19. interfaces::surface->draw_text_pos( x - ( width / 2 ), y );
  20. else
  21. interfaces::surface->draw_text_pos( x, y );
  22.  
  23. interfaces::surface->draw_render_text( Buffer.data(), Buffer.size() );
  24.  
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement