mirror of
https://github.com/edubart/otclient.git
synced 2025-12-26 09:47:11 +01:00
Tidy up the source code
* Replaced push_back calls with emplace_back where applicable. * Replaced size() == 0 and size() != 0 with empty() and !empty(). * Replaced C style loops for range for loops where applicable. * Fixed mismatching arg names between function declarations and definitions. * Replaced NULL and 0 (in the context of pointers) with nullptr. * Remove unnecessary calls to string::c_str() where applicable. * Replaced deprecated C headers with proper C++ headers. * Removed unnecessary null pointer checks when deleting pointers (deleting a null pointer has no effect). * Fixed a potential memory leak in apngloader.cpp file. * Replaced unsafe strcpy with strncpy in the demangle_name function.
This commit is contained in:
@@ -50,8 +50,8 @@ void UIParticles::drawSelf(Fw::DrawPane drawPane)
|
||||
else
|
||||
g_painter->translate(m_rect.x() + m_referencePos.x * m_rect.width(), m_rect.y() + m_referencePos.y * m_rect.height());
|
||||
|
||||
for(auto it = m_effects.begin(), end = m_effects.end(); it != end; ++it)
|
||||
(*it)->render();
|
||||
for(auto &effect: m_effects)
|
||||
effect->render();
|
||||
g_painter->restoreSavedState();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -397,9 +397,9 @@ void UITextEdit::appendText(std::string text)
|
||||
return;
|
||||
|
||||
// only ignore text append if it contains invalid characters
|
||||
if(m_validCharacters.size() > 0) {
|
||||
for(uint i = 0; i < text.size(); ++i) {
|
||||
if(m_validCharacters.find(text[i]) == std::string::npos)
|
||||
if(!m_validCharacters.empty()) {
|
||||
for(char i: text) {
|
||||
if(m_validCharacters.find(i) == std::string::npos)
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -424,7 +424,7 @@ void UITextEdit::appendCharacter(char c)
|
||||
if(m_maxLength > 0 && m_text.length() + 1 > m_maxLength)
|
||||
return;
|
||||
|
||||
if(m_validCharacters.size() > 0 && m_validCharacters.find(c) == std::string::npos)
|
||||
if(!m_validCharacters.empty() && m_validCharacters.find(c) == std::string::npos)
|
||||
return;
|
||||
|
||||
std::string tmp;
|
||||
|
||||
@@ -103,7 +103,7 @@ protected:
|
||||
virtual bool onMouseRelease(const Point& mousePos, Fw::MouseButton button);
|
||||
virtual bool onMouseMove(const Point& mousePos, const Point& mouseMoved);
|
||||
virtual bool onDoubleClick(const Point& mousePos);
|
||||
virtual void onTextAreaUpdate(const Point& vitualOffset, const Size& virtualSize, const Size& totalSize);
|
||||
virtual void onTextAreaUpdate(const Point& vitualOffset, const Size& visibleSize, const Size& totalSize);
|
||||
|
||||
private:
|
||||
void disableUpdates() { m_updatesEnabled = false; }
|
||||
|
||||
@@ -70,7 +70,7 @@ void UIWidget::draw(const Rect& visibleRect, Fw::DrawPane drawPane)
|
||||
|
||||
drawSelf(drawPane);
|
||||
|
||||
if(m_children.size() > 0) {
|
||||
if(!m_children.empty()) {
|
||||
if(m_clipping)
|
||||
g_painter->setClipRect(visibleRect.intersection(getPaddingRect()));
|
||||
|
||||
@@ -488,7 +488,7 @@ void UIWidget::unlockChild(const UIWidgetPtr& child)
|
||||
|
||||
// find new child to lock
|
||||
UIWidgetPtr lockedChild;
|
||||
if(m_lockedChildren.size() > 0) {
|
||||
if(!m_lockedChildren.empty()) {
|
||||
lockedChild = m_lockedChildren.front();
|
||||
assert(hasChild(lockedChild));
|
||||
}
|
||||
@@ -1043,8 +1043,8 @@ bool UIWidget::hasChild(const UIWidgetPtr& child)
|
||||
int UIWidget::getChildIndex(const UIWidgetPtr& child)
|
||||
{
|
||||
int index = 1;
|
||||
for(auto it = m_children.begin(); it != m_children.end(); ++it) {
|
||||
if(*it == child)
|
||||
for(auto &it: m_children) {
|
||||
if(it == child)
|
||||
return index;
|
||||
++index;
|
||||
}
|
||||
@@ -1713,8 +1713,7 @@ bool UIWidget::propagateOnMouseEvent(const Point& mousePos, UIWidgetList& widget
|
||||
bool UIWidget::propagateOnMouseMove(const Point& mousePos, const Point& mouseMoved, UIWidgetList& widgetList)
|
||||
{
|
||||
if(containsPaddingPoint(mousePos)) {
|
||||
for(auto it = m_children.begin(); it != m_children.end(); ++it) {
|
||||
const UIWidgetPtr& child = *it;
|
||||
for(auto &child: m_children) {
|
||||
if(child->isExplicitlyVisible() && child->isExplicitlyEnabled() && child->containsPoint(mousePos))
|
||||
child->propagateOnMouseMove(mousePos, mouseMoved, widgetList);
|
||||
|
||||
|
||||
@@ -246,7 +246,7 @@ public:
|
||||
bool isClipping() { return m_clipping; }
|
||||
bool isDestroyed() { return m_destroyed; }
|
||||
|
||||
bool hasChildren() { return m_children.size() > 0; }
|
||||
bool hasChildren() { return !m_children.empty(); }
|
||||
bool containsMarginPoint(const Point& point) { return getMarginRect().contains(point); }
|
||||
bool containsPaddingPoint(const Point& point) { return getPaddingRect().contains(point); }
|
||||
bool containsPoint(const Point& point) { return m_rect.contains(point); }
|
||||
|
||||
Reference in New Issue
Block a user