widelands-dev team mailing list archive
-
widelands-dev team
-
Mailing list archive
-
Message #07406
[Merge] lp:~widelands-dev/widelands/bug-1535732-fun-with-pointers into lp:widelands
GunChleoc has proposed merging lp:~widelands-dev/widelands/bug-1535732-fun-with-pointers into lp:widelands.
Requested reviews:
kaputtnik (franku)
Related bugs:
Bug #1535732 in widelands: "Texts not displayed correctly with the new font renderer"
https://bugs.launchpad.net/widelands/+bug/1535732
For more details, see:
https://code.launchpad.net/~widelands-dev/widelands/bug-1535732-fun-with-pointers/+merge/292735
Another attempt at fixing the text textures in certain Windows installations.
--
Your team Widelands Developers is subscribed to branch lp:~widelands-dev/widelands/bug-1535732-fun-with-pointers.
=== modified file 'src/graphic/text/rt_render.cc'
--- src/graphic/text/rt_render.cc 2016-04-23 08:16:51 +0000
+++ src/graphic/text/rt_render.cc 2016-04-24 17:48:37 +0000
@@ -269,7 +269,8 @@
while (idx_ < all_nodes_.size()
&& all_nodes_[idx_]->is_non_mandatory_space()
&& shrink_to_fit) {
- delete all_nodes_[idx_++];
+ delete all_nodes_[idx_];
+ all_nodes_[idx_++] = nullptr;
}
uint16_t x = p.left;
@@ -551,7 +552,7 @@
Texture* rv = new Texture(w_, h_);
// Draw background image (tiling)
- if (background_image_) {
+ if (background_image_ != nullptr) {
Rect dst;
Rect srcrect(Point(0, 0), 1, 1);
for (uint16_t curx = 0; curx < w_; curx += background_image_->width()) {
@@ -617,7 +618,7 @@
}
// Draw background image (tiling)
- if (background_image_) {
+ if (background_image_ != nullptr) {
Rect dst;
Rect src(0, 0, 0, 0);
@@ -635,7 +636,7 @@
for (RenderNode* n : nodes_to_render_) {
Texture* node_texture = n->render(texture_cache);
- if (node_texture) {
+ if (node_texture != nullptr) {
Rect dst = Rect(n->x() + margin_.left,
n->y() + margin_.top,
node_texture->width(),
@@ -814,7 +815,7 @@
void TagHandler::emit_nodes(vector<RenderNode*>& nodes) {
for (Child* c : tag_.children()) {
- if (c->tag) {
+ if (c->tag != nullptr) {
std::unique_ptr<TagHandler> th(create_taghandler(*c->tag, font_cache_, nodestyle_, image_cache_,
renderer_style_, fontsets_));
th->enter();
@@ -972,7 +973,7 @@
else
sn = new SpaceNode(nodestyle_, 0, 0, true);
- if (background_image_)
+ if (background_image_ != nullptr)
sn->set_background(background_image_);
rn = sn;
}
=== modified file 'src/ui_basic/box.cc'
--- src/ui_basic/box.cc 2016-04-01 09:29:17 +0000
+++ src/ui_basic/box.cc 2016-04-24 17:48:37 +0000
@@ -211,7 +211,7 @@
void Box::update_positions()
{
- int32_t scrollpos = scrollbar_ ? scrollbar_->get_scrollpos() : 0;
+ int32_t scrollpos = scrollbar_ != nullptr ? scrollbar_->get_scrollpos() : 0;
uint32_t totaldepth = 0;
uint32_t totalbreadth = orientation_ == Horizontal ? get_inner_h() : get_inner_w();
=== modified file 'src/ui_basic/button.cc'
--- src/ui_basic/button.cc 2016-03-19 11:47:00 +0000
+++ src/ui_basic/button.cc 2016-04-24 17:48:37 +0000
@@ -155,7 +155,7 @@
{
// Draw the background
if (!flat_ || draw_flat_background_) {
- assert(pic_background_);
+ assert(pic_background_ != nullptr);
dst.fill_rect(Rect(Point(0, 0), get_w(), get_h()), RGBAColor(0, 0, 0, 255));
dst.tile(Rect(Point(0, 0), get_w(), get_h()), pic_background_, Point(get_x(), get_y()));
}
@@ -165,7 +165,7 @@
(Rect(Point(0, 0), get_w(), get_h()), MOUSE_OVER_BRIGHT_FACTOR);
// If we've got a picture, draw it centered
- if (pic_custom_) {
+ if (pic_custom_ != nullptr) {
if (keep_image_size_) {
if (enabled_) {
// ">> 1" is almost like "/ 2", but simpler for signed types (difference
=== modified file 'src/ui_basic/checkbox.cc'
--- src/ui_basic/checkbox.cc 2016-02-09 21:14:53 +0000
+++ src/ui_basic/checkbox.cc 2016-04-24 17:48:37 +0000
@@ -67,7 +67,7 @@
width > (kStateboxSize + kPadding) ? width - kStateboxSize - kPadding : 0))
{
pic_graphics_ = g_gr->images().get("images/ui_basic/checkbox_light.png");
- if (rendered_text_) {
+ if (rendered_text_ != nullptr) {
int w = rendered_text_->width() + kPadding + pic_graphics_->width() / 2;
int h = std::max(rendered_text_->height(), pic_graphics_->height());
set_desired_size(w, h);
@@ -142,7 +142,7 @@
Point image_anchor(0, 0);
Point text_anchor(kStateboxSize + kPadding, 0);
- if (rendered_text_) {
+ if (rendered_text_ != nullptr) {
if (UI::g_fh1->fontset()->is_rtl()) {
text_anchor.x = 0;
image_anchor.x = rendered_text_->width() + kPadding;
=== modified file 'src/ui_basic/icon.cc'
--- src/ui_basic/icon.cc 2016-03-19 11:47:00 +0000
+++ src/ui_basic/icon.cc 2016-04-24 17:48:37 +0000
@@ -55,7 +55,7 @@
}
void Icon::draw(RenderTarget & dst) {
- if (pic_) {
+ if (pic_ != nullptr) {
double scale = std::min(static_cast<double>(get_w()) / pic_->width(),
static_cast<double>(get_h()) / pic_->height());
scale = std::min(1., scale);
=== modified file 'src/ui_basic/listselect.cc'
--- src/ui_basic/listselect.cc 2016-03-25 17:01:05 +0000
+++ src/ui_basic/listselect.cc 2016-04-24 17:48:37 +0000
@@ -130,7 +130,7 @@
er->name = name;
er->tooltip = tooltip_text;
uint32_t entry_height = lineheight_;
- if (pic) {
+ if (pic != nullptr) {
uint16_t w = pic->width();
uint16_t h = pic->height();
entry_height = (h >= entry_height) ? h : entry_height;
@@ -168,7 +168,7 @@
er->tooltip = tooltip_text;
uint32_t entry_height = lineheight_;
- if (pic) {
+ if (pic != nullptr) {
uint16_t w = pic->width();
uint16_t h = pic->height();
entry_height = (h >= entry_height) ? h : entry_height;
=== modified file 'src/ui_basic/messagebox.cc'
--- src/ui_basic/messagebox.cc 2016-02-09 21:14:53 +0000
+++ src/ui_basic/messagebox.cc 2016-04-24 17:48:37 +0000
@@ -33,8 +33,8 @@
Align align)
: Window(parent, "message_box", 0, 0, 20, 20, caption.c_str()), type_(type) {
// Calculate textarea dimensions depending on text size
- const int outerwidth = parent ? parent->get_inner_w() : g_gr->get_xres();
- const int outerheight = parent ? parent->get_inner_h() : g_gr->get_yres();
+ const int outerwidth = parent != nullptr ? parent->get_inner_w() : g_gr->get_xres();
+ const int outerheight = parent != nullptr ? parent->get_inner_h() : g_gr->get_yres();
const int button_w = 120;
const int minwidth = 3.5 * button_w;
=== modified file 'src/ui_basic/panel.cc'
--- src/ui_basic/panel.cc 2016-03-10 15:00:32 +0000
+++ src/ui_basic/panel.cc 2016-04-24 17:48:37 +0000
@@ -63,10 +63,10 @@
tooltip_(tooltip_text)
{
assert(nparent != this);
- if (parent_) {
+ if (parent_ != nullptr) {
next_ = parent_->first_child_;
prev_ = nullptr;
- if (next_)
+ if (next_ != nullptr)
next_->prev_ = this;
else
parent_->last_child_ = this;
@@ -90,17 +90,17 @@
free_children();
// Unlink
- if (parent_) {
+ if (parent_ != nullptr) {
if (parent_->mousein_child_ == this)
parent_->mousein_child_ = nullptr;
if (parent_->focus_ == this)
parent_->focus_ = nullptr;
- if (prev_)
+ if (prev_ != nullptr)
prev_->next_ = next_;
else
parent_->first_child_ = next_;
- if (next_)
+ if (next_ != nullptr)
next_->prev_ = prev_;
else
parent_->last_child_ = prev_;
@@ -115,7 +115,7 @@
// Scan-build claims this results in double free.
// This is a false positive.
// See https://bugs.launchpad.net/widelands/+bug/1198928
- while (first_child_) delete first_child_;
+ while (first_child_ != nullptr) delete first_child_;
}
@@ -240,7 +240,7 @@
w_ = nw;
h_ = nh;
- if (parent_)
+ if (parent_ != nullptr)
move_inside_parent();
layout();
@@ -324,7 +324,7 @@
*/
Point Panel::to_parent(const Point & pt) const
{
- if (!parent_)
+ if (parent_ == nullptr)
return pt;
return pt + Point(lborder_ + x_, tborder_ + y_);
@@ -379,15 +379,15 @@
*/
void Panel::move_to_top()
{
- if (!parent_)
+ if (parent_ == nullptr)
return;
// unlink
- if (prev_)
+ if (prev_ != nullptr)
prev_->next_ = next_;
else
parent_->first_child_ = next_;
- if (next_)
+ if (next_ != nullptr)
next_->prev_ = prev_;
else
parent_->last_child_ = prev_;
@@ -396,7 +396,7 @@
prev_ = nullptr;
next_ = parent_->first_child_;
parent_->first_child_ = this;
- if (next_)
+ if (next_ != nullptr)
next_->prev_ = this;
else
parent_->last_child_ = this;
@@ -451,7 +451,7 @@
if (thinks())
think();
- for (Panel * child = first_child_; child; child = child->next_)
+ for (Panel * child = first_child_; child != nullptr; child = child->next_)
child->do_think();
}
@@ -461,7 +461,7 @@
*/
Point Panel::get_mouse_position() const {
return
- (parent_ ?
+ (parent_ != nullptr ?
parent_ ->get_mouse_position()
:
WLApplication::get()->get_mouse_position())
@@ -476,7 +476,7 @@
void Panel::set_mouse_pos(const Point p) {
const Point relative_p =
p + Point(get_x() + get_lborder(), get_y() + get_tborder());
- if (parent_)
+ if (parent_ != nullptr)
parent_ ->set_mouse_pos(relative_p);
else
WLApplication::get()->warp_mouse (relative_p);
@@ -548,7 +548,7 @@
bool Panel::handle_key(bool down, SDL_Keysym code)
{
if (down) {
- if (focus_) {
+ if (focus_ != nullptr) {
Panel * p = focus_->next_;
switch (code.sym) {
@@ -636,7 +636,7 @@
else {
flags_ &= ~pf_can_focus;
- if (parent_ && parent_->focus_ == this)
+ if (parent_ != nullptr && parent_->focus_ == this)
parent_->focus_ = nullptr;
}
}
@@ -659,7 +659,7 @@
}
}
- if (!parent_ || this == modal_) {
+ if (parent_ == nullptr || this == modal_) {
return;
}
if (parent_->focus_ == this)
@@ -693,7 +693,7 @@
{
flags_ |= pf_die;
- for (Panel * p = parent_; p; p = p->parent_) {
+ for (Panel * p = parent_; p != nullptr; p = p->parent_) {
p->flags_ |= pf_child_die;
if (p == modal_)
break;
@@ -725,7 +725,7 @@
void Panel::check_child_death()
{
Panel * next = first_child_;
- while (next) {
+ while (next != nullptr) {
Panel * p = next;
next = p->next_;
@@ -750,7 +750,7 @@
draw(dst);
// draw back to front
- for (Panel * child = last_child_; child; child = child->prev_)
+ for (Panel * child = last_child_; child != nullptr; child = child->prev_)
child->do_draw(dst);
draw_overlay(dst);
@@ -798,7 +798,7 @@
(int32_t const x, int32_t const y, Panel * child)
{
- for (; child; child = child->next_) {
+ for (; child != nullptr; child = child->next_) {
if (!child->handles_mouse() || !child->is_visible())
continue;
if
@@ -808,10 +808,10 @@
break;
}
- if (mousein_child_ && mousein_child_ != child)
+ if (mousein_child_ != nullptr && mousein_child_ != child)
mousein_child_->do_mousein(false);
mousein_child_ = child;
- if (child)
+ if (child != nullptr)
child->do_mousein(true);
return child;
@@ -823,7 +823,7 @@
*/
void Panel::do_mousein(bool const inside)
{
- if (!inside && mousein_child_) {
+ if (!inside && mousein_child_ != nullptr) {
mousein_child_->do_mousein(false);
mousein_child_ = nullptr;
}
@@ -862,7 +862,7 @@
// We need to find the actualy scrollable panel beneaththe mouse cursor,
// so we can have multiple scrollable elements on the same screen
// e.g. load map with a long desctiprion has 2 of them.
- if (focus_) {
+ if (focus_ != nullptr) {
if (focus_->do_mousewheel(which, x, y))
return true;
}
@@ -913,7 +913,7 @@
*/
bool Panel::do_key(bool const down, SDL_Keysym const code)
{
- if (focus_ && focus_->do_key(down, code)) {
+ if (focus_ != nullptr && focus_->do_key(down, code)) {
return true;
}
@@ -926,7 +926,7 @@
}
bool Panel::do_textinput(const std::string& text) {
- if (focus_ && focus_->do_textinput(text)) {
+ if (focus_ != nullptr && focus_->do_textinput(text)) {
return true;
}
@@ -939,7 +939,7 @@
bool Panel::do_tooltip()
{
- if (mousein_child_ && mousein_child_->do_tooltip()) {
+ if (mousein_child_ != nullptr && mousein_child_->do_tooltip()) {
return true;
}
return handle_tooltip();
@@ -963,14 +963,14 @@
Panel * mousein;
Panel * rcv = nullptr;
- if (mousegrab_)
+ if (mousegrab_ != nullptr)
mousein = rcv = mousegrab_;
else
mousein = modal_;
x -= mousein->x_;
y -= mousein->y_;
- for (Panel * p = mousein->parent_; p; p = p->parent_) {
+ for (Panel * p = mousein->parent_; p != nullptr; p = p->parent_) {
x -= p->lborder_ + p->x_;
y -= p->tborder_ + p->y_;
}
@@ -984,10 +984,10 @@
mousein = nullptr;
if (mousein != mousein_) {
- if (mousein_)
+ if (mousein_ != nullptr)
mousein_->do_mousein(false);
mousein_ = mousein;
- if (mousein_)
+ if (mousein_ != nullptr)
mousein_->do_mousein(true);
}
@@ -1057,12 +1057,12 @@
return true;
}
Panel* p = nullptr;
- if (mousein_) {
+ if (mousein_ != nullptr) {
p = mousein_;
} else {
- p = mousegrab_ ? mousegrab_ : modal_;
+ p = mousegrab_ != nullptr ? mousegrab_ : modal_;
}
- if (!p) {
+ if (p == nullptr) {
return false;
}
return p->do_mousewheel(which, x, y);
@@ -1107,7 +1107,7 @@
static const uint32_t TIP_WIDTH_MAX = 360;
const Image* rendered_text = g_fh1->render(text_to_render, TIP_WIDTH_MAX);
- if (!rendered_text) {
+ if (rendered_text == nullptr) {
return false;
}
uint16_t tip_width = rendered_text->width() + 4;
=== modified file 'src/ui_basic/radiobutton.cc'
--- src/ui_basic/radiobutton.cc 2016-02-18 18:27:52 +0000
+++ src/ui_basic/radiobutton.cc 2016-04-24 17:48:37 +0000
@@ -46,7 +46,7 @@
*/
Radiobutton::~Radiobutton()
{
- for (Radiobutton * * pp = &group_.buttons_; *pp; pp = &(*pp)->nextbtn_) {
+ for (Radiobutton * * pp = &group_.buttons_; *pp != nullptr; pp = &(*pp)->nextbtn_) {
if (*pp == this) {
*pp = nextbtn_;
break;
@@ -90,7 +90,7 @@
// Scan-build claims this results in double free.
// This is a false positive.
// See https://bugs.launchpad.net/widelands/+bug/1198928
- while (buttons_) delete buttons_;
+ while (buttons_ != nullptr) delete buttons_;
}
@@ -108,7 +108,7 @@
++highestid_;
Radiobutton * btn = new Radiobutton(parent, p, pic, *this, highestid_);
btn->set_tooltip(tooltip);
- if (ret_btn) (*ret_btn) = btn;
+ if (ret_btn != nullptr) (*ret_btn) = btn;
return highestid_;
}
@@ -124,7 +124,7 @@
return;
}
- for (Radiobutton * btn = buttons_; btn; btn = btn->nextbtn_)
+ for (Radiobutton * btn = buttons_; btn != nullptr; btn = btn->nextbtn_)
btn->set_state(btn->id_ == state);
state_ = state;
changed();
@@ -135,7 +135,7 @@
* Disable this radiogroup
*/
void Radiogroup::set_enabled(bool st) {
- for (Radiobutton * btn = buttons_; btn; btn = btn->nextbtn_)
+ for (Radiobutton * btn = buttons_; btn != nullptr; btn = btn->nextbtn_)
btn->set_enabled(st);
}
=== modified file 'src/ui_basic/scrollbar.cc'
--- src/ui_basic/scrollbar.cc 2016-03-25 17:01:05 +0000
+++ src/ui_basic/scrollbar.cc 2016-04-24 17:48:37 +0000
@@ -263,7 +263,7 @@
else if (area == Plus)
pic = pic_plus_;
- if (pic) {
+ if (pic != nullptr) {
double image_scale =
std::min(1.,
std::min(static_cast<double>(r.w - 4) / pic->width(),
=== modified file 'src/ui_basic/table.cc'
--- src/ui_basic/table.cc 2016-03-25 17:01:05 +0000
+++ src/ui_basic/table.cc 2016-04-24 17:48:37 +0000
@@ -126,7 +126,7 @@
columns_.push_back(c);
}
- if (!scrollbar_) {
+ if (scrollbar_ == nullptr) {
scrollbar_ =
new Scrollbar
(get_parent(),
@@ -238,7 +238,7 @@
}
entry_records_.clear();
- if (scrollbar_)
+ if (scrollbar_ != nullptr)
scrollbar_->set_steps(1);
scrollpos_ = 0;
selection_ = no_selection_index();
@@ -492,7 +492,7 @@
select(static_cast<uint32_t>(new_selection));
// Scroll to newly selected entry
- if (scrollbar_)
+ if (scrollbar_ != nullptr)
{
// Keep an unselected item above or below
int32_t scroll_item = new_selection + offset;
=== modified file 'src/ui_basic/tabpanel.cc'
--- src/ui_basic/tabpanel.cc 2016-03-14 07:06:20 +0000
+++ src/ui_basic/tabpanel.cc 2016-04-24 17:48:37 +0000
@@ -278,7 +278,7 @@
static_assert(2 < kTabPanelButtonHeight, "assert(2 < kTabPanelButtonSize) failed.");
static_assert(4 < kTabPanelButtonHeight, "assert(4 < kTabPanelButtonSize) failed.");
- if (pic_background_) {
+ if (pic_background_ != nullptr) {
if (!tabs_.empty()) {
dst.tile
(Rect(Point(0, 0), tabs_.back()->get_x() + tabs_.back()->get_w(), kTabPanelButtonHeight - 2),
=== modified file 'src/ui_basic/textarea.cc'
--- src/ui_basic/textarea.cc 2016-02-17 08:48:02 +0000
+++ src/ui_basic/textarea.cc 2016-04-24 17:48:37 +0000
@@ -224,7 +224,7 @@
uint32_t w = 0;
uint16_t h = 0;
- if (rendered_text_) {
+ if (rendered_text_ != nullptr) {
w = fixed_width_ > 0 ? fixed_width_ : rendered_text_->width();
h = rendered_text_->height();
// We want empty textareas to have height
=== modified file 'src/ui_basic/unique_window.cc'
--- src/ui_basic/unique_window.cc 2016-02-03 18:09:15 +0000
+++ src/ui_basic/unique_window.cc 2016-04-24 17:48:37 +0000
@@ -32,7 +32,7 @@
* Creates the window, if it does not exist.
*/
void UniqueWindow::Registry::create() {
- if (!window) {
+ if (window == nullptr) {
open_window();
}
}
@@ -41,7 +41,7 @@
* Destroys the window, if it eixsts.
*/
void UniqueWindow::Registry::destroy() {
- if (window) {
+ if (window != nullptr) {
window->die();
}
}
@@ -50,7 +50,7 @@
* Either destroys or creates the window.
*/
void UniqueWindow::Registry::toggle() {
- if (window) {
+ if (window != nullptr) {
window->die();
} else {
open_window();
@@ -80,7 +80,7 @@
registry_ (reg),
usedefaultpos_(true)
{
- if (registry_) {
+ if (registry_ != nullptr) {
delete registry_->window;
registry_->window = this;
@@ -100,7 +100,7 @@
*/
UniqueWindow::~UniqueWindow()
{
- if (registry_) {
+ if (registry_ != nullptr) {
assert(registry_->window == this);
registry_->window = nullptr;
=== modified file 'src/ui_basic/window.cc'
--- src/ui_basic/window.cc 2016-02-20 14:16:16 +0000
+++ src/ui_basic/window.cc 2016-04-24 17:48:37 +0000
@@ -132,7 +132,7 @@
*/
void Window::update_desired_size()
{
- if (center_panel_ && !is_minimal_) {
+ if (center_panel_ != nullptr && !is_minimal_) {
int innerw, innerh;
center_panel_->get_desired_size(&innerw, &innerh);
set_desired_size
@@ -147,7 +147,7 @@
*/
void Window::layout()
{
- if (center_panel_ && !is_minimal_) {
+ if (center_panel_ != nullptr && !is_minimal_) {
center_panel_->set_pos(Point(0, 0));
center_panel_->set_size(get_inner_w(), get_inner_h());
}
@@ -180,7 +180,7 @@
* Moves the mouse to the child panel that is activated as fast click panel
*/
void Window::warp_mouse_to_fastclick_panel() {
- if (fastclick_panel_) {
+ if (fastclick_panel_ != nullptr) {
Point pt(fastclick_panel_->get_w() / 2, fastclick_panel_->get_h() / 2);
UI::Panel * p = fastclick_panel_;
Follow ups