mirror of
https://github.com/minetest/minetest.git
synced 2024-11-04 14:53:45 +01:00
Hud: Cache hud_scaling, fix minor style issues
This commit is contained in:
parent
eae33951ad
commit
2eeb62057a
@ -265,7 +265,7 @@ Client::Client(
|
|||||||
m_cache_smooth_lighting = g_settings->getBool("smooth_lighting");
|
m_cache_smooth_lighting = g_settings->getBool("smooth_lighting");
|
||||||
m_cache_enable_shaders = g_settings->getBool("enable_shaders");
|
m_cache_enable_shaders = g_settings->getBool("enable_shaders");
|
||||||
m_cache_use_tangent_vertices = m_cache_enable_shaders && (
|
m_cache_use_tangent_vertices = m_cache_enable_shaders && (
|
||||||
g_settings->getBool("enable_bumpmapping") ||
|
g_settings->getBool("enable_bumpmapping") ||
|
||||||
g_settings->getBool("enable_parallax_occlusion"));
|
g_settings->getBool("enable_parallax_occlusion"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
48
src/hud.cpp
48
src/hud.cpp
@ -41,7 +41,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||||||
|
|
||||||
Hud::Hud(video::IVideoDriver *driver, scene::ISceneManager* smgr,
|
Hud::Hud(video::IVideoDriver *driver, scene::ISceneManager* smgr,
|
||||||
gui::IGUIEnvironment* guienv, IGameDef *gamedef, LocalPlayer *player,
|
gui::IGUIEnvironment* guienv, IGameDef *gamedef, LocalPlayer *player,
|
||||||
Inventory *inventory) {
|
Inventory *inventory)
|
||||||
|
{
|
||||||
this->driver = driver;
|
this->driver = driver;
|
||||||
this->smgr = smgr;
|
this->smgr = smgr;
|
||||||
this->guienv = guienv;
|
this->guienv = guienv;
|
||||||
@ -49,16 +50,15 @@ Hud::Hud(video::IVideoDriver *driver, scene::ISceneManager* smgr,
|
|||||||
this->player = player;
|
this->player = player;
|
||||||
this->inventory = inventory;
|
this->inventory = inventory;
|
||||||
|
|
||||||
|
m_hud_scaling = g_settings->getFloat("hud_scaling");
|
||||||
m_screensize = v2u32(0, 0);
|
m_screensize = v2u32(0, 0);
|
||||||
m_displaycenter = v2s32(0, 0);
|
m_displaycenter = v2s32(0, 0);
|
||||||
m_hotbar_imagesize = floor(HOTBAR_IMAGE_SIZE * porting::getDisplayDensity() + 0.5);
|
m_hotbar_imagesize = floor(HOTBAR_IMAGE_SIZE * porting::getDisplayDensity() + 0.5);
|
||||||
m_hotbar_imagesize *= g_settings->getFloat("hud_scaling");
|
m_hotbar_imagesize *= m_hud_scaling;
|
||||||
m_padding = m_hotbar_imagesize / 12;
|
m_padding = m_hotbar_imagesize / 12;
|
||||||
|
|
||||||
const video::SColor hbar_color(255, 255, 255, 255);
|
for (unsigned int i = 0; i < 4; i++)
|
||||||
for (unsigned int i=0; i < 4; i++ ){
|
hbar_colors[i] = video::SColor(255, 255, 255, 255);
|
||||||
hbar_colors[i] = hbar_color;
|
|
||||||
}
|
|
||||||
|
|
||||||
tsrc = gamedef->getTextureSource();
|
tsrc = gamedef->getTextureSource();
|
||||||
|
|
||||||
@ -196,8 +196,8 @@ void Hud::drawItem(const ItemStack &item, const core::rect<s32>& rect,
|
|||||||
}
|
}
|
||||||
|
|
||||||
//NOTE: selectitem = 0 -> no selected; selectitem 1-based
|
//NOTE: selectitem = 0 -> no selected; selectitem 1-based
|
||||||
void Hud::drawItems(v2s32 upperleftpos, s32 itemcount, s32 inv_offset,
|
void Hud::drawItems(v2s32 upperleftpos, v2s32 screen_offset, s32 itemcount,
|
||||||
InventoryList *mainlist, u16 selectitem, u16 direction, const v2s32 &offset)
|
s32 inv_offset, InventoryList *mainlist, u16 selectitem, u16 direction)
|
||||||
{
|
{
|
||||||
#ifdef HAVE_TOUCHSCREENGUI
|
#ifdef HAVE_TOUCHSCREENGUI
|
||||||
if (g_touchscreengui && inv_offset == 0)
|
if (g_touchscreengui && inv_offset == 0)
|
||||||
@ -213,8 +213,8 @@ void Hud::drawItems(v2s32 upperleftpos, s32 itemcount, s32 inv_offset,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Position of upper left corner of bar
|
// Position of upper left corner of bar
|
||||||
v2s32 pos = upperleftpos + offset;
|
v2s32 pos = upperleftpos + screen_offset;
|
||||||
pos *= g_settings->getFloat("hud_scaling") * porting::getDisplayDensity();
|
pos *= m_hud_scaling * porting::getDisplayDensity();
|
||||||
|
|
||||||
if (hotbar_image != player->hotbar_image) {
|
if (hotbar_image != player->hotbar_image) {
|
||||||
hotbar_image = player->hotbar_image;
|
hotbar_image = player->hotbar_image;
|
||||||
@ -235,7 +235,7 @@ void Hud::drawItems(v2s32 upperleftpos, s32 itemcount, s32 inv_offset,
|
|||||||
/* draw customized item background */
|
/* draw customized item background */
|
||||||
if (use_hotbar_image) {
|
if (use_hotbar_image) {
|
||||||
core::rect<s32> imgrect2(-m_padding/2, -m_padding/2,
|
core::rect<s32> imgrect2(-m_padding/2, -m_padding/2,
|
||||||
width+m_padding/2, height+m_padding/2);
|
width+m_padding/2, height+m_padding/2);
|
||||||
core::rect<s32> rect2 = imgrect2 + pos;
|
core::rect<s32> rect2 = imgrect2 + pos;
|
||||||
video::ITexture *texture = tsrc->getTexture(hotbar_image);
|
video::ITexture *texture = tsrc->getTexture(hotbar_image);
|
||||||
core::dimension2di imgsize(texture->getOriginalSize());
|
core::dimension2di imgsize(texture->getOriginalSize());
|
||||||
@ -265,7 +265,7 @@ void Hud::drawItems(v2s32 upperleftpos, s32 itemcount, s32 inv_offset,
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
drawItem(mainlist->getItem(i), (imgrect + pos + steppos), (i +1) == selectitem );
|
drawItem(mainlist->getItem(i), (imgrect + pos + steppos), (i + 1) == selectitem);
|
||||||
|
|
||||||
#ifdef HAVE_TOUCHSCREENGUI
|
#ifdef HAVE_TOUCHSCREENGUI
|
||||||
if (g_touchscreengui)
|
if (g_touchscreengui)
|
||||||
@ -327,8 +327,8 @@ void Hud::drawLuaElements(const v3s16 &camera_offset)
|
|||||||
break; }
|
break; }
|
||||||
case HUD_ELEM_INVENTORY: {
|
case HUD_ELEM_INVENTORY: {
|
||||||
InventoryList *inv = inventory->getList(e->text);
|
InventoryList *inv = inventory->getList(e->text);
|
||||||
v2s32 offs(e->offset.X, e->offset.Y);
|
drawItems(pos, v2s32(e->offset.X, e->offset.Y), e->number, 0,
|
||||||
drawItems(pos, e->number, 0, inv, e->item, e->dir, offs);
|
inv, e->item, e->dir);
|
||||||
break; }
|
break; }
|
||||||
case HUD_ELEM_WAYPOINT: {
|
case HUD_ELEM_WAYPOINT: {
|
||||||
v3f p_pos = player->getPosition() / BS;
|
v3f p_pos = player->getPosition() / BS;
|
||||||
@ -381,8 +381,7 @@ void Hud::drawStatbar(v2s32 pos, u16 corner, u16 drawdir, std::string texture,
|
|||||||
if (size == v2s32()) {
|
if (size == v2s32()) {
|
||||||
dstd = srcd;
|
dstd = srcd;
|
||||||
} else {
|
} else {
|
||||||
double size_factor = g_settings->getFloat("hud_scaling") *
|
float size_factor = m_hud_scaling * porting::getDisplayDensity();
|
||||||
porting::getDisplayDensity();
|
|
||||||
dstd.Height = size.Y * size_factor;
|
dstd.Height = size.Y * size_factor;
|
||||||
dstd.Width = size.X * size_factor;
|
dstd.Width = size.X * size_factor;
|
||||||
offset.X *= size_factor;
|
offset.X *= size_factor;
|
||||||
@ -450,18 +449,19 @@ void Hud::drawHotbar(u16 playeritem) {
|
|||||||
if ( (float) width / (float) porting::getWindowSize().X <=
|
if ( (float) width / (float) porting::getWindowSize().X <=
|
||||||
g_settings->getFloat("hud_hotbar_max_width")) {
|
g_settings->getFloat("hud_hotbar_max_width")) {
|
||||||
if (player->hud_flags & HUD_FLAG_HOTBAR_VISIBLE) {
|
if (player->hud_flags & HUD_FLAG_HOTBAR_VISIBLE) {
|
||||||
drawItems(pos, hotbar_itemcount, 0, mainlist, playeritem + 1, 0);
|
drawItems(pos, v2s32(0, 0), hotbar_itemcount, 0, mainlist, playeritem + 1, 0);
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
pos.X += width/4;
|
pos.X += width/4;
|
||||||
|
|
||||||
v2s32 secondpos = pos;
|
v2s32 secondpos = pos;
|
||||||
pos = pos - v2s32(0, m_hotbar_imagesize + m_padding);
|
pos = pos - v2s32(0, m_hotbar_imagesize + m_padding);
|
||||||
|
|
||||||
if (player->hud_flags & HUD_FLAG_HOTBAR_VISIBLE) {
|
if (player->hud_flags & HUD_FLAG_HOTBAR_VISIBLE) {
|
||||||
drawItems(pos, hotbar_itemcount/2, 0, mainlist, playeritem + 1, 0);
|
drawItems(pos, v2s32(0, 0), hotbar_itemcount / 2, 0,
|
||||||
drawItems(secondpos, hotbar_itemcount, hotbar_itemcount/2, mainlist, playeritem + 1, 0);
|
mainlist, playeritem + 1, 0);
|
||||||
|
drawItems(secondpos, v2s32(0, 0), hotbar_itemcount,
|
||||||
|
hotbar_itemcount / 2, mainlist, playeritem + 1, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -486,8 +486,8 @@ void Hud::drawHotbar(u16 playeritem) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Hud::drawCrosshair() {
|
void Hud::drawCrosshair()
|
||||||
|
{
|
||||||
if (use_crosshair_image) {
|
if (use_crosshair_image) {
|
||||||
video::ITexture *crosshair = tsrc->getTexture("crosshair.png");
|
video::ITexture *crosshair = tsrc->getTexture("crosshair.png");
|
||||||
v2u32 size = crosshair->getOriginalSize();
|
v2u32 size = crosshair->getOriginalSize();
|
||||||
@ -600,7 +600,7 @@ void Hud::updateSelectionMesh(const v3s16 &camera_offset)
|
|||||||
void Hud::resizeHotbar() {
|
void Hud::resizeHotbar() {
|
||||||
if (m_screensize != porting::getWindowSize()) {
|
if (m_screensize != porting::getWindowSize()) {
|
||||||
m_hotbar_imagesize = floor(HOTBAR_IMAGE_SIZE * porting::getDisplayDensity() + 0.5);
|
m_hotbar_imagesize = floor(HOTBAR_IMAGE_SIZE * porting::getDisplayDensity() + 0.5);
|
||||||
m_hotbar_imagesize *= g_settings->getFloat("hud_scaling");
|
m_hotbar_imagesize *= m_hud_scaling;
|
||||||
m_padding = m_hotbar_imagesize / 12;
|
m_padding = m_hotbar_imagesize / 12;
|
||||||
m_screensize = porting::getWindowSize();
|
m_screensize = porting::getWindowSize();
|
||||||
m_displaycenter = v2s32(m_screensize.X/2,m_screensize.Y/2);
|
m_displaycenter = v2s32(m_screensize.X/2,m_screensize.Y/2);
|
||||||
|
@ -148,13 +148,13 @@ private:
|
|||||||
void drawStatbar(v2s32 pos, u16 corner, u16 drawdir, std::string texture,
|
void drawStatbar(v2s32 pos, u16 corner, u16 drawdir, std::string texture,
|
||||||
s32 count, v2s32 offset, v2s32 size=v2s32());
|
s32 count, v2s32 offset, v2s32 size=v2s32());
|
||||||
|
|
||||||
void drawItems(v2s32 upperleftpos, s32 itemcount, s32 inv_offset,
|
void drawItems(v2s32 upperleftpos, v2s32 screen_offset, s32 itemcount,
|
||||||
InventoryList *mainlist, u16 selectitem, u16 direction,
|
s32 inv_offset, InventoryList *mainlist, u16 selectitem, u16 direction);
|
||||||
const v2s32 &offset = v2s32(0, 0));
|
|
||||||
|
|
||||||
void drawItem(const ItemStack &item, const core::rect<s32>& rect,
|
void drawItem(const ItemStack &item, const core::rect<s32>& rect,
|
||||||
bool selected);
|
bool selected);
|
||||||
|
|
||||||
|
float m_hud_scaling;
|
||||||
v3s16 m_camera_offset;
|
v3s16 m_camera_offset;
|
||||||
v2u32 m_screensize;
|
v2u32 m_screensize;
|
||||||
v2s32 m_displaycenter;
|
v2s32 m_displaycenter;
|
||||||
|
Loading…
Reference in New Issue
Block a user