Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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 1d086ae
Show file tree
Hide file tree
Showing 10 changed files with 107 additions and 152 deletions.
2 changes: 1 addition & 1 deletion src/guiscalingfilter.h
Expand Up @@ -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);
2 changes: 1 addition & 1 deletion src/httpfetch.h
Expand Up @@ -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)
Expand Down
16 changes: 7 additions & 9 deletions src/hud.cpp
Expand Up @@ -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();

Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
}
Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/imagefilters.cpp
Expand Up @@ -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
Expand Down
42 changes: 18 additions & 24 deletions src/intlGUIEditBox.cpp
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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]);
Expand Down

0 comments on commit 1d086ae

Please sign in to comment.