clientdynamicinfo.cpp 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /*
  2. Minetest
  3. Copyright (C) 2022-3 rubenwardy <rw@rubenwardy.com>
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU Lesser General Public License as published by
  6. the Free Software Foundation; either version 2.1 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public License along
  13. with this program; if not, write to the Free Software Foundation, Inc.,
  14. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  15. */
  16. #ifndef SERVER
  17. #include "clientdynamicinfo.h"
  18. #include "settings.h"
  19. #include "client/renderingengine.h"
  20. #include "gui/touchscreengui.h"
  21. ClientDynamicInfo ClientDynamicInfo::getCurrent()
  22. {
  23. v2u32 screen_size = RenderingEngine::getWindowSize();
  24. f32 density = RenderingEngine::getDisplayDensity();
  25. f32 gui_scaling = g_settings->getFloat("gui_scaling", 0.5f, 20.0f);
  26. f32 hud_scaling = g_settings->getFloat("hud_scaling", 0.5f, 20.0f);
  27. f32 real_gui_scaling = gui_scaling * density;
  28. f32 real_hud_scaling = hud_scaling * density;
  29. bool touch_controls = g_touchscreengui;
  30. return {
  31. screen_size, real_gui_scaling, real_hud_scaling,
  32. ClientDynamicInfo::calculateMaxFSSize(screen_size, gui_scaling),
  33. touch_controls
  34. };
  35. }
  36. v2f32 ClientDynamicInfo::calculateMaxFSSize(v2u32 render_target_size, f32 gui_scaling)
  37. {
  38. f32 factor = (g_settings->getBool("enable_touch") ? 10 : 15) / gui_scaling;
  39. f32 ratio = (f32)render_target_size.X / (f32)render_target_size.Y;
  40. if (ratio < 1)
  41. return { factor, factor / ratio };
  42. else
  43. return { factor * ratio, factor };
  44. }
  45. #endif