Skip to content

Commit 2eeb620

Browse files
committedApr 11, 2016
Hud: Cache hud_scaling, fix minor style issues
1 parent eae3395 commit 2eeb620

File tree

3 files changed

+28
-28
lines changed

3 files changed

+28
-28
lines changed
 

‎src/client.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ Client::Client(
265265
m_cache_smooth_lighting = g_settings->getBool("smooth_lighting");
266266
m_cache_enable_shaders = g_settings->getBool("enable_shaders");
267267
m_cache_use_tangent_vertices = m_cache_enable_shaders && (
268-
g_settings->getBool("enable_bumpmapping") ||
268+
g_settings->getBool("enable_bumpmapping") ||
269269
g_settings->getBool("enable_parallax_occlusion"));
270270
}
271271

‎src/hud.cpp

+24-24
Original file line numberDiff line numberDiff line change
@@ -41,24 +41,24 @@ with this program; if not, write to the Free Software Foundation, Inc.,
4141

4242
Hud::Hud(video::IVideoDriver *driver, scene::ISceneManager* smgr,
4343
gui::IGUIEnvironment* guienv, IGameDef *gamedef, LocalPlayer *player,
44-
Inventory *inventory) {
44+
Inventory *inventory)
45+
{
4546
this->driver = driver;
4647
this->smgr = smgr;
4748
this->guienv = guienv;
4849
this->gamedef = gamedef;
4950
this->player = player;
5051
this->inventory = inventory;
5152

53+
m_hud_scaling = g_settings->getFloat("hud_scaling");
5254
m_screensize = v2u32(0, 0);
5355
m_displaycenter = v2s32(0, 0);
5456
m_hotbar_imagesize = floor(HOTBAR_IMAGE_SIZE * porting::getDisplayDensity() + 0.5);
55-
m_hotbar_imagesize *= g_settings->getFloat("hud_scaling");
57+
m_hotbar_imagesize *= m_hud_scaling;
5658
m_padding = m_hotbar_imagesize / 12;
5759

58-
const video::SColor hbar_color(255, 255, 255, 255);
59-
for (unsigned int i=0; i < 4; i++ ){
60-
hbar_colors[i] = hbar_color;
61-
}
60+
for (unsigned int i = 0; i < 4; i++)
61+
hbar_colors[i] = video::SColor(255, 255, 255, 255);
6262

6363
tsrc = gamedef->getTextureSource();
6464

@@ -196,8 +196,8 @@ void Hud::drawItem(const ItemStack &item, const core::rect<s32>& rect,
196196
}
197197

198198
//NOTE: selectitem = 0 -> no selected; selectitem 1-based
199-
void Hud::drawItems(v2s32 upperleftpos, s32 itemcount, s32 inv_offset,
200-
InventoryList *mainlist, u16 selectitem, u16 direction, const v2s32 &offset)
199+
void Hud::drawItems(v2s32 upperleftpos, v2s32 screen_offset, s32 itemcount,
200+
s32 inv_offset, InventoryList *mainlist, u16 selectitem, u16 direction)
201201
{
202202
#ifdef HAVE_TOUCHSCREENGUI
203203
if (g_touchscreengui && inv_offset == 0)
@@ -213,8 +213,8 @@ void Hud::drawItems(v2s32 upperleftpos, s32 itemcount, s32 inv_offset,
213213
}
214214

215215
// Position of upper left corner of bar
216-
v2s32 pos = upperleftpos + offset;
217-
pos *= g_settings->getFloat("hud_scaling") * porting::getDisplayDensity();
216+
v2s32 pos = upperleftpos + screen_offset;
217+
pos *= m_hud_scaling * porting::getDisplayDensity();
218218

219219
if (hotbar_image != player->hotbar_image) {
220220
hotbar_image = player->hotbar_image;
@@ -235,7 +235,7 @@ void Hud::drawItems(v2s32 upperleftpos, s32 itemcount, s32 inv_offset,
235235
/* draw customized item background */
236236
if (use_hotbar_image) {
237237
core::rect<s32> imgrect2(-m_padding/2, -m_padding/2,
238-
width+m_padding/2, height+m_padding/2);
238+
width+m_padding/2, height+m_padding/2);
239239
core::rect<s32> rect2 = imgrect2 + pos;
240240
video::ITexture *texture = tsrc->getTexture(hotbar_image);
241241
core::dimension2di imgsize(texture->getOriginalSize());
@@ -265,7 +265,7 @@ void Hud::drawItems(v2s32 upperleftpos, s32 itemcount, s32 inv_offset,
265265
break;
266266
}
267267

268-
drawItem(mainlist->getItem(i), (imgrect + pos + steppos), (i +1) == selectitem );
268+
drawItem(mainlist->getItem(i), (imgrect + pos + steppos), (i + 1) == selectitem);
269269

270270
#ifdef HAVE_TOUCHSCREENGUI
271271
if (g_touchscreengui)
@@ -327,8 +327,8 @@ void Hud::drawLuaElements(const v3s16 &camera_offset)
327327
break; }
328328
case HUD_ELEM_INVENTORY: {
329329
InventoryList *inv = inventory->getList(e->text);
330-
v2s32 offs(e->offset.X, e->offset.Y);
331-
drawItems(pos, e->number, 0, inv, e->item, e->dir, offs);
330+
drawItems(pos, v2s32(e->offset.X, e->offset.Y), e->number, 0,
331+
inv, e->item, e->dir);
332332
break; }
333333
case HUD_ELEM_WAYPOINT: {
334334
v3f p_pos = player->getPosition() / BS;
@@ -381,8 +381,7 @@ void Hud::drawStatbar(v2s32 pos, u16 corner, u16 drawdir, std::string texture,
381381
if (size == v2s32()) {
382382
dstd = srcd;
383383
} else {
384-
double size_factor = g_settings->getFloat("hud_scaling") *
385-
porting::getDisplayDensity();
384+
float size_factor = m_hud_scaling * porting::getDisplayDensity();
386385
dstd.Height = size.Y * size_factor;
387386
dstd.Width = size.X * size_factor;
388387
offset.X *= size_factor;
@@ -450,18 +449,19 @@ void Hud::drawHotbar(u16 playeritem) {
450449
if ( (float) width / (float) porting::getWindowSize().X <=
451450
g_settings->getFloat("hud_hotbar_max_width")) {
452451
if (player->hud_flags & HUD_FLAG_HOTBAR_VISIBLE) {
453-
drawItems(pos, hotbar_itemcount, 0, mainlist, playeritem + 1, 0);
452+
drawItems(pos, v2s32(0, 0), hotbar_itemcount, 0, mainlist, playeritem + 1, 0);
454453
}
455-
}
456-
else {
454+
} else {
457455
pos.X += width/4;
458456

459457
v2s32 secondpos = pos;
460458
pos = pos - v2s32(0, m_hotbar_imagesize + m_padding);
461459

462460
if (player->hud_flags & HUD_FLAG_HOTBAR_VISIBLE) {
463-
drawItems(pos, hotbar_itemcount/2, 0, mainlist, playeritem + 1, 0);
464-
drawItems(secondpos, hotbar_itemcount, hotbar_itemcount/2, mainlist, playeritem + 1, 0);
461+
drawItems(pos, v2s32(0, 0), hotbar_itemcount / 2, 0,
462+
mainlist, playeritem + 1, 0);
463+
drawItems(secondpos, v2s32(0, 0), hotbar_itemcount,
464+
hotbar_itemcount / 2, mainlist, playeritem + 1, 0);
465465
}
466466
}
467467

@@ -486,8 +486,8 @@ void Hud::drawHotbar(u16 playeritem) {
486486
}
487487

488488

489-
void Hud::drawCrosshair() {
490-
489+
void Hud::drawCrosshair()
490+
{
491491
if (use_crosshair_image) {
492492
video::ITexture *crosshair = tsrc->getTexture("crosshair.png");
493493
v2u32 size = crosshair->getOriginalSize();
@@ -600,7 +600,7 @@ void Hud::updateSelectionMesh(const v3s16 &camera_offset)
600600
void Hud::resizeHotbar() {
601601
if (m_screensize != porting::getWindowSize()) {
602602
m_hotbar_imagesize = floor(HOTBAR_IMAGE_SIZE * porting::getDisplayDensity() + 0.5);
603-
m_hotbar_imagesize *= g_settings->getFloat("hud_scaling");
603+
m_hotbar_imagesize *= m_hud_scaling;
604604
m_padding = m_hotbar_imagesize / 12;
605605
m_screensize = porting::getWindowSize();
606606
m_displaycenter = v2s32(m_screensize.X/2,m_screensize.Y/2);

‎src/hud.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -148,13 +148,13 @@ class Hud {
148148
void drawStatbar(v2s32 pos, u16 corner, u16 drawdir, std::string texture,
149149
s32 count, v2s32 offset, v2s32 size=v2s32());
150150

151-
void drawItems(v2s32 upperleftpos, s32 itemcount, s32 inv_offset,
152-
InventoryList *mainlist, u16 selectitem, u16 direction,
153-
const v2s32 &offset = v2s32(0, 0));
151+
void drawItems(v2s32 upperleftpos, v2s32 screen_offset, s32 itemcount,
152+
s32 inv_offset, InventoryList *mainlist, u16 selectitem, u16 direction);
154153

155154
void drawItem(const ItemStack &item, const core::rect<s32>& rect,
156155
bool selected);
157156

157+
float m_hud_scaling;
158158
v3s16 m_camera_offset;
159159
v2u32 m_screensize;
160160
v2s32 m_displaycenter;

0 commit comments

Comments
 (0)
Please sign in to comment.