mirror of
https://github.com/minetest/minetest.git
synced 2024-08-19 21:14:15 +02:00
Limit crosshair scaling to integer multiples to avoid distortion (#14501)
This commit is contained in:
parent
97066bf795
commit
6e3246c5fd
@ -44,6 +44,11 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||||||
#define OBJECT_CROSSHAIR_LINE_SIZE 8
|
#define OBJECT_CROSSHAIR_LINE_SIZE 8
|
||||||
#define CROSSHAIR_LINE_SIZE 10
|
#define CROSSHAIR_LINE_SIZE 10
|
||||||
|
|
||||||
|
static void setting_changed_callback(const std::string &name, void *data)
|
||||||
|
{
|
||||||
|
static_cast<Hud*>(data)->readScalingSetting();
|
||||||
|
}
|
||||||
|
|
||||||
Hud::Hud(Client *client, LocalPlayer *player,
|
Hud::Hud(Client *client, LocalPlayer *player,
|
||||||
Inventory *inventory)
|
Inventory *inventory)
|
||||||
{
|
{
|
||||||
@ -52,12 +57,8 @@ Hud::Hud(Client *client, LocalPlayer *player,
|
|||||||
this->player = player;
|
this->player = player;
|
||||||
this->inventory = inventory;
|
this->inventory = inventory;
|
||||||
|
|
||||||
m_hud_scaling = g_settings->getFloat("hud_scaling", 0.5f, 20.0f);
|
readScalingSetting();
|
||||||
m_scale_factor = m_hud_scaling * RenderingEngine::getDisplayDensity();
|
g_settings->registerChangedCallback("hud_scaling", setting_changed_callback, this);
|
||||||
m_hotbar_imagesize = std::floor(HOTBAR_IMAGE_SIZE *
|
|
||||||
RenderingEngine::getDisplayDensity() + 0.5f);
|
|
||||||
m_hotbar_imagesize *= m_hud_scaling;
|
|
||||||
m_padding = m_hotbar_imagesize / 12;
|
|
||||||
|
|
||||||
for (auto &hbar_color : hbar_colors)
|
for (auto &hbar_color : hbar_colors)
|
||||||
hbar_color = video::SColor(255, 255, 255, 255);
|
hbar_color = video::SColor(255, 255, 255, 255);
|
||||||
@ -138,8 +139,20 @@ Hud::Hud(Client *client, LocalPlayer *player,
|
|||||||
m_rotation_mesh_buffer.setHardwareMappingHint(scene::EHM_STATIC);
|
m_rotation_mesh_buffer.setHardwareMappingHint(scene::EHM_STATIC);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Hud::readScalingSetting()
|
||||||
|
{
|
||||||
|
m_hud_scaling = g_settings->getFloat("hud_scaling", 0.5f, 20.0f);
|
||||||
|
m_scale_factor = m_hud_scaling * RenderingEngine::getDisplayDensity();
|
||||||
|
m_hotbar_imagesize = std::floor(HOTBAR_IMAGE_SIZE *
|
||||||
|
RenderingEngine::getDisplayDensity() + 0.5f);
|
||||||
|
m_hotbar_imagesize *= m_hud_scaling;
|
||||||
|
m_padding = m_hotbar_imagesize / 12;
|
||||||
|
}
|
||||||
|
|
||||||
Hud::~Hud()
|
Hud::~Hud()
|
||||||
{
|
{
|
||||||
|
g_settings->deregisterChangedCallback("hud_scaling", setting_changed_callback, this);
|
||||||
|
|
||||||
if (m_selection_mesh)
|
if (m_selection_mesh)
|
||||||
m_selection_mesh->drop();
|
m_selection_mesh->drop();
|
||||||
}
|
}
|
||||||
@ -786,9 +799,9 @@ void Hud::drawCrosshair()
|
|||||||
{
|
{
|
||||||
auto draw_image_crosshair = [this] (video::ITexture *tex) {
|
auto draw_image_crosshair = [this] (video::ITexture *tex) {
|
||||||
core::dimension2di orig_size(tex->getOriginalSize());
|
core::dimension2di orig_size(tex->getOriginalSize());
|
||||||
core::dimension2di scaled_size(
|
// Integer scaling to avoid artifacts, floor instead of round since too
|
||||||
core::round32(orig_size.Width * m_scale_factor),
|
// small looks better than too large in this case.
|
||||||
core::round32(orig_size.Height * m_scale_factor));
|
core::dimension2di scaled_size = orig_size * std::floor(m_scale_factor);
|
||||||
|
|
||||||
core::rect<s32> src_rect(orig_size);
|
core::rect<s32> src_rect(orig_size);
|
||||||
core::position2d pos(m_displaycenter.X - scaled_size.Width / 2,
|
core::position2d pos(m_displaycenter.X - scaled_size.Width / 2,
|
||||||
|
@ -57,6 +57,7 @@ public:
|
|||||||
|
|
||||||
Hud(Client *client, LocalPlayer *player,
|
Hud(Client *client, LocalPlayer *player,
|
||||||
Inventory *inventory);
|
Inventory *inventory);
|
||||||
|
void readScalingSetting();
|
||||||
~Hud();
|
~Hud();
|
||||||
|
|
||||||
enum BlockBoundsMode toggleBlockBounds();
|
enum BlockBoundsMode toggleBlockBounds();
|
||||||
|
Loading…
Reference in New Issue
Block a user