Skip to content
Permalink
Browse files

Modernize various files (part 2)

* range-based for loops
* emplace_back instead of push_back
* code style
* C++ headers instead of C headers
* Default operators
* empty stl function
  • Loading branch information
nerzhul committed Aug 18, 2017
1 parent 55ab426 commit 1d086aee7cc193bed2f8ca09cc2e020f509378f1
Showing with 107 additions and 152 deletions.
  1. +1 −1 src/guiscalingfilter.h
  2. +1 −1 src/httpfetch.h
  3. +7 −9 src/hud.cpp
  4. +1 −1 src/imagefilters.cpp
  5. +18 −24 src/intlGUIEditBox.cpp
  6. +52 −85 src/inventory.cpp
  7. +1 −1 src/inventory.h
  8. +16 −18 src/inventorymanager.cpp
  9. +7 −7 src/inventorymanager.h
  10. +3 −5 src/itemstackmetadata.cpp
@@ -46,5 +46,5 @@ video::ITexture *guiScalingImageButton(video::IVideoDriver *driver, video::IText
*/
void draw2DImageFilterScaled(video::IVideoDriver *driver, video::ITexture *txr,
const core::rect<s32> &destrect, const core::rect<s32> &srcrect,
const core::rect<s32> *cliprect = 0, video::SColor *const colors = 0,
const core::rect<s32> *cliprect = 0, const video::SColor *const colors = 0,
bool usealpha = false);
@@ -76,7 +76,7 @@ struct HTTPFetchResult
unsigned long caller = HTTPFETCH_DISCARD;
unsigned long request_id = 0;

HTTPFetchResult() {}
HTTPFetchResult() = default;

HTTPFetchResult(const HTTPFetchRequest &fetch_request)
: caller(fetch_request.caller), request_id(fetch_request.request_id)
@@ -55,8 +55,8 @@ Hud::Hud(gui::IGUIEnvironment *guienv, Client *client, LocalPlayer *player,
m_hotbar_imagesize *= m_hud_scaling;
m_padding = m_hotbar_imagesize / 12;

for (unsigned int i = 0; i < 4; i++)
hbar_colors[i] = video::SColor(255, 255, 255, 255);
for (auto &hbar_color : hbar_colors)
hbar_color = video::SColor(255, 255, 255, 255);

tsrc = client->getTextureSource();

@@ -220,7 +220,7 @@ void Hud::drawItems(v2s32 upperleftpos, v2s32 screen_offset, s32 itemcount,
// Store hotbar_image in member variable, used by drawItem()
if (hotbar_image != player->hotbar_image) {
hotbar_image = player->hotbar_image;
if (hotbar_image != "")
if (!hotbar_image.empty())
use_hotbar_image = tsrc->isKnownSourceImage(hotbar_image);
else
use_hotbar_image = false;
@@ -229,7 +229,7 @@ void Hud::drawItems(v2s32 upperleftpos, v2s32 screen_offset, s32 itemcount,
// Store hotbar_selected_image in member variable, used by drawItem()
if (hotbar_selected_image != player->hotbar_selected_image) {
hotbar_selected_image = player->hotbar_selected_image;
if (hotbar_selected_image != "")
if (!hotbar_selected_image.empty())
use_hotbar_selected_image = tsrc->isKnownSourceImage(hotbar_selected_image);
else
use_hotbar_selected_image = false;
@@ -572,7 +572,7 @@ void Hud::updateSelectionMesh(const v3s16 &camera_offset)
m_selection_mesh = NULL;
}

if (!m_selection_boxes.size()) {
if (m_selection_boxes.empty()) {
// No pointed object
return;
}
@@ -597,10 +597,8 @@ void Hud::updateSelectionMesh(const v3s16 &camera_offset)
aabb3f halo_box(100.0, 100.0, 100.0, -100.0, -100.0, -100.0);
m_halo_boxes.clear();

for (std::vector<aabb3f>::iterator
i = m_selection_boxes.begin();
i != m_selection_boxes.end(); ++i) {
halo_box.addInternalBox(*i);
for (const auto &selection_box : m_selection_boxes) {
halo_box.addInternalBox(selection_box);
}

m_halo_boxes.push_back(halo_box);
@@ -18,7 +18,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,

#include "imagefilters.h"
#include "util/numeric.h"
#include <math.h>
#include <cmath>

/* Fill in RGB values for transparent pixels, to correct for odd colors
* appearing at borders when blending. This is because many PNG optimizers
@@ -630,8 +630,7 @@ bool intlGUIEditBox::processKey(const SEvent& event)
if ( !this->IsEnabled )
break;

if (Text.size())
{
if (!Text.empty()) {
core::stringw s;

if (MarkBegin != MarkEnd)
@@ -670,8 +669,7 @@ bool intlGUIEditBox::processKey(const SEvent& event)
if ( !this->IsEnabled )
break;

if (Text.size() != 0)
{
if (!Text.empty()) {
core::stringw s;

if (MarkBegin != MarkEnd)
@@ -820,8 +818,7 @@ void intlGUIEditBox::draw()
const bool prevOver = OverrideColorEnabled;
const video::SColor prevColor = OverrideColor;

if (Text.size())
{
if (!Text.empty()) {
if (!IsEnabled && !OverrideColorEnabled)
{
OverrideColorEnabled = true;
@@ -908,7 +905,7 @@ void intlGUIEditBox::draw()
// draw marked text
s = txtLine->subString(lineStartPos, lineEndPos - lineStartPos);

if (s.size())
if (!s.empty())
font->draw(s.c_str(), CurrentTextRect,
OverrideColorEnabled ? OverrideColor : skin->getColor(EGDC_HIGH_LIGHT_TEXT),
false, true, &localClipRect);
@@ -1057,24 +1054,22 @@ bool intlGUIEditBox::processMouse(const SEvent& event)
else
{
if (!AbsoluteClippingRect.isPointInside(
core::position2d<s32>(event.MouseInput.X, event.MouseInput.Y)))
{
core::position2d<s32>(event.MouseInput.X, event.MouseInput.Y))) {
return false;
}
else
{
// move cursor
CursorPos = getCursorPos(event.MouseInput.X, event.MouseInput.Y);

s32 newMarkBegin = MarkBegin;
if (!MouseMarking)
newMarkBegin = CursorPos;

MouseMarking = true;
setTextMarkers( newMarkBegin, CursorPos);
calculateScrollPos();
return true;
}
// move cursor
CursorPos = getCursorPos(event.MouseInput.X, event.MouseInput.Y);

s32 newMarkBegin = MarkBegin;
if (!MouseMarking)
newMarkBegin = CursorPos;

MouseMarking = true;
setTextMarkers( newMarkBegin, CursorPos);
calculateScrollPos();
return true;
}
default:
break;
@@ -1185,8 +1180,7 @@ void intlGUIEditBox::breakText()

if (c == L' ' || c == 0 || i == (size-1))
{
if (word.size())
{
if (!word.empty()) {
// here comes the next whitespace, look if
// we can break the last word to the next line.
s32 whitelgth = font->getDimension(whitespace.c_str()).Width;
@@ -1488,7 +1482,7 @@ void intlGUIEditBox::deserializeAttributes(io::IAttributes* in, io::SAttributeRe
setAutoScroll(in->getAttributeAsBool("AutoScroll"));
core::stringw ch = in->getAttributeAsStringW("PasswordChar");

if (!ch.size())
if (ch.empty())
setPasswordBox(in->getAttributeAsBool("PasswordBox"));
else
setPasswordBox(in->getAttributeAsBool("PasswordBox"), ch[0]);

0 comments on commit 1d086ae

Please sign in to comment.