Made tpoint default-initializeable and cleaned up its uses
This commit is contained in:
parent
7434533b46
commit
ddc8d84c06
21 changed files with 48 additions and 52 deletions
|
@ -297,7 +297,7 @@ void tmouse_motion::show_tooltip()
|
|||
|
||||
hover_timer_ = 0;
|
||||
hover_widget_ = nullptr;
|
||||
hover_position_ = tpoint(0, 0);
|
||||
hover_position_ = tpoint();
|
||||
}
|
||||
|
||||
void tmouse_motion::mouse_leave()
|
||||
|
@ -354,7 +354,7 @@ void tmouse_motion::stop_hover_timer()
|
|||
|
||||
hover_timer_ = 0;
|
||||
hover_widget_ = nullptr;
|
||||
hover_position_ = tpoint(0, 0);
|
||||
hover_position_ = tpoint();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -328,16 +328,16 @@ void thandler::handle_event(const SDL_Event& event)
|
|||
|
||||
switch(event.type) {
|
||||
case SDL_MOUSEMOTION:
|
||||
mouse(SDL_MOUSE_MOTION, tpoint(event.motion.x, event.motion.y));
|
||||
mouse(SDL_MOUSE_MOTION, {event.motion.x, event.motion.y});
|
||||
break;
|
||||
|
||||
case SDL_MOUSEBUTTONDOWN:
|
||||
mouse_button_down(tpoint(event.button.x, event.button.y),
|
||||
mouse_button_down({event.button.x, event.button.y},
|
||||
event.button.button);
|
||||
break;
|
||||
|
||||
case SDL_MOUSEBUTTONUP:
|
||||
mouse_button_up(tpoint(event.button.x, event.button.y),
|
||||
mouse_button_up({event.button.x, event.button.y},
|
||||
event.button.button);
|
||||
break;
|
||||
|
||||
|
@ -399,8 +399,7 @@ void thandler::handle_event(const SDL_Event& event)
|
|||
break;
|
||||
|
||||
case SDL_WINDOWEVENT_RESIZED:
|
||||
video_resize(
|
||||
tpoint(event.window.data1, event.window.data2));
|
||||
video_resize({event.window.data1, event.window.data2});
|
||||
break;
|
||||
|
||||
case SDL_WINDOWEVENT_ENTER:
|
||||
|
|
|
@ -23,6 +23,10 @@ namespace gui2
|
|||
/** Holds a 2D point. */
|
||||
struct tpoint
|
||||
{
|
||||
tpoint() : x(0), y(0)
|
||||
{
|
||||
}
|
||||
|
||||
tpoint(const int x_, const int y_) : x(x_), y(y_)
|
||||
{
|
||||
}
|
||||
|
@ -53,14 +57,14 @@ struct tpoint
|
|||
|
||||
tpoint operator+(const tpoint& point) const
|
||||
{
|
||||
return tpoint(x + point.x, y + point.y);
|
||||
return {x + point.x, y + point.y};
|
||||
}
|
||||
|
||||
tpoint& operator+=(const tpoint& point);
|
||||
|
||||
tpoint operator-(const tpoint& point) const
|
||||
{
|
||||
return tpoint(x - point.x, y - point.y);
|
||||
return {x - point.x, y - point.y};
|
||||
}
|
||||
|
||||
tpoint& operator-=(const tpoint& point);
|
||||
|
|
|
@ -68,7 +68,7 @@ REGISTER_WINDOW(tooltip_large)
|
|||
class ttip : public tpopup
|
||||
{
|
||||
public:
|
||||
ttip() : tpopup(), window_id_(), message_(), mouse_(tpoint(0, 0))
|
||||
ttip() : tpopup(), window_id_(), message_(), mouse_()
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -217,7 +217,7 @@ tcontainer_::init_grid(const std::shared_ptr<tbuilder_grid>& grid_builder)
|
|||
|
||||
tpoint tcontainer_::border_space() const
|
||||
{
|
||||
return tpoint(0, 0);
|
||||
return tpoint();
|
||||
}
|
||||
|
||||
} // namespace gui2
|
||||
|
|
|
@ -208,8 +208,7 @@ void tcontrol::request_reduce_width(const unsigned maximum_width)
|
|||
if(!label_.empty() && can_wrap()) {
|
||||
|
||||
tpoint size = get_best_text_size(
|
||||
tpoint(0, 0),
|
||||
tpoint(maximum_width - config_->text_extra_width, 0));
|
||||
tpoint(), tpoint(maximum_width - config_->text_extra_width, 0));
|
||||
|
||||
size.x += config_->text_extra_width;
|
||||
size.y += config_->text_extra_height;
|
||||
|
@ -334,7 +333,7 @@ void tcontrol::set_label(const t_string& label)
|
|||
}
|
||||
|
||||
label_ = label;
|
||||
set_layout_size(tpoint(0, 0));
|
||||
set_layout_size(tpoint());
|
||||
update_canvas();
|
||||
set_is_dirty(true);
|
||||
}
|
||||
|
|
|
@ -469,7 +469,7 @@ private:
|
|||
* @returns The best size.
|
||||
*/
|
||||
tpoint get_best_text_size(const tpoint& minimum_size,
|
||||
const tpoint& maximum_size = tpoint(0, 0)) const;
|
||||
const tpoint& maximum_size = {0, 0}) const;
|
||||
|
||||
/**
|
||||
* Contains a helper cache for the rendering.
|
||||
|
|
|
@ -33,7 +33,7 @@ REGISTER_WIDGET(drawing)
|
|||
|
||||
tpoint tdrawing::calculate_best_size() const
|
||||
{
|
||||
return best_size_ != tpoint(0, 0) ? best_size_
|
||||
return best_size_ != tpoint() ? best_size_
|
||||
: tcontrol::calculate_best_size();
|
||||
}
|
||||
|
||||
|
|
|
@ -541,7 +541,7 @@ void tgrid::place(const tpoint& origin, const tpoint& size)
|
|||
|
||||
void tgrid::set_origin(const tpoint& origin)
|
||||
{
|
||||
const tpoint movement = tpoint(origin.x - get_x(), origin.y - get_y());
|
||||
const tpoint movement = {origin.x - get_x(), origin.y - get_y()};
|
||||
|
||||
// Inherited.
|
||||
twidget::set_origin(origin);
|
||||
|
@ -552,8 +552,7 @@ void tgrid::set_origin(const tpoint& origin)
|
|||
twidget* widget = child.widget();
|
||||
assert(widget);
|
||||
|
||||
widget->set_origin(tpoint(widget->get_x() + movement.x,
|
||||
widget->get_y() + movement.y));
|
||||
widget->set_origin(tpoint(widget->get_x() + movement.x, widget->get_y() + movement.y));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -708,7 +707,7 @@ tpoint tgrid::tchild::get_best_size() const
|
|||
DBG_GUI_L << LOG_CHILD_HEADER << " has widget " << true
|
||||
<< " widget visible " << false << " returning 0,0"
|
||||
<< ".\n";
|
||||
return tpoint(0, 0);
|
||||
return tpoint();
|
||||
}
|
||||
|
||||
const tpoint best_size = widget_->get_best_size() + border_space();
|
||||
|
@ -758,12 +757,12 @@ void tgrid::tchild::place(tpoint origin, tpoint size)
|
|||
|
||||
const tcontrol* control = dynamic_cast<const tcontrol*>(widget());
|
||||
const tpoint maximum_size = control ? control->get_config_maximum_size()
|
||||
: tpoint(0, 0);
|
||||
: tpoint();
|
||||
|
||||
if((flags_ & (HORIZONTAL_MASK | VERTICAL_MASK))
|
||||
== (HORIZONTAL_GROW_SEND_TO_CLIENT | VERTICAL_GROW_SEND_TO_CLIENT)) {
|
||||
|
||||
if(maximum_size == tpoint(0, 0) || size <= maximum_size) {
|
||||
if(maximum_size == tpoint() || size <= maximum_size) {
|
||||
|
||||
DBG_GUI_L << LOG_CHILD_HEADER
|
||||
<< " in maximum size range setting widget to " << origin
|
||||
|
@ -774,8 +773,7 @@ void tgrid::tchild::place(tpoint origin, tpoint size)
|
|||
}
|
||||
}
|
||||
|
||||
tpoint widget_size = tpoint(std::min(size.x, best_size.x),
|
||||
std::min(size.y, best_size.y));
|
||||
tpoint widget_size = tpoint(std::min(size.x, best_size.x), std::min(size.y, best_size.y));
|
||||
tpoint widget_orig = origin;
|
||||
|
||||
const unsigned v_flag = flags_ & VERTICAL_MASK;
|
||||
|
|
|
@ -48,8 +48,8 @@ tpoint timage::calculate_best_size() const
|
|||
const tpoint minimum = get_config_default_size();
|
||||
const tpoint maximum = get_config_maximum_size();
|
||||
|
||||
tpoint result = tpoint(image->w, image->h);
|
||||
if(best_size_ != tpoint(0, 0)) {
|
||||
tpoint result = {image->w, image->h};
|
||||
if(best_size_ != tpoint()) {
|
||||
result = best_size_;
|
||||
}
|
||||
|
||||
|
|
|
@ -275,7 +275,7 @@ bool tlistbox::update_content_size()
|
|||
return true;
|
||||
}
|
||||
|
||||
if(get_size() == tpoint(0, 0)) {
|
||||
if(get_size() == tpoint()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -369,7 +369,7 @@ void tpane::signal_handler_request_placement(tdispatcher& dispatcher,
|
|||
* what seems to work properly when showing and hiding
|
||||
* items. Might fail with new items (haven't tested yet).
|
||||
*/
|
||||
item.grid->place(tpoint(0, 0), item.grid->get_best_size());
|
||||
item.grid->place(tpoint(), item.grid->get_best_size());
|
||||
}
|
||||
place_or_set_origin_children();
|
||||
DBG_GUI_E << LOG_HEADER << ' ' << event << " handled.\n";
|
||||
|
|
|
@ -81,8 +81,7 @@ tpoint tpanel::border_space() const
|
|||
config());
|
||||
assert(conf);
|
||||
|
||||
return tpoint(conf->left_border + conf->right_border,
|
||||
conf->top_border + conf->bottom_border);
|
||||
return tpoint(conf->left_border + conf->right_border, conf->top_border + conf->bottom_border);
|
||||
}
|
||||
|
||||
const std::string& tpanel::get_control_type() const
|
||||
|
|
|
@ -310,14 +310,14 @@ tpoint tscrollbar_container::calculate_best_size() const
|
|||
const tpoint vertical_scrollbar
|
||||
= vertical_scrollbar_grid_->get_visible()
|
||||
== twidget::tvisible::invisible
|
||||
? tpoint(0, 0)
|
||||
? tpoint()
|
||||
: vertical_scrollbar_grid_->get_best_size();
|
||||
|
||||
/***** get horizontal scrollbar size *****/
|
||||
const tpoint horizontal_scrollbar
|
||||
= horizontal_scrollbar_grid_->get_visible()
|
||||
== twidget::tvisible::invisible
|
||||
? tpoint(0, 0)
|
||||
? tpoint()
|
||||
: horizontal_scrollbar_grid_->get_best_size();
|
||||
|
||||
/***** get content size *****/
|
||||
|
@ -555,7 +555,7 @@ bool tscrollbar_container::content_resize_request(const bool force_sizing)
|
|||
DBG_GUI_L << LOG_HEADER << " wanted size " << best_size
|
||||
<< " available size " << size << ".\n";
|
||||
|
||||
if(size == tpoint(0, 0)) {
|
||||
if(size == tpoint()) {
|
||||
DBG_GUI_L << LOG_HEADER << " initial setup not done, bailing out.\n";
|
||||
return false;
|
||||
}
|
||||
|
@ -621,7 +621,7 @@ bool tscrollbar_container::content_resize_request(const int width_modification,
|
|||
<< width_modification << " wanted height modification "
|
||||
<< height_modification << ".\n";
|
||||
|
||||
if(get_size() == tpoint(0, 0)) {
|
||||
if(get_size() == tpoint()) {
|
||||
DBG_GUI_L << LOG_HEADER << " initial setup not done, bailing out.\n";
|
||||
return false;
|
||||
}
|
||||
|
@ -1127,8 +1127,7 @@ void tscrollbar_container::scrollbar_moved()
|
|||
: vertical_scrollbar_->get_item_position()
|
||||
* vertical_scrollbar_->get_step_size();
|
||||
|
||||
const tpoint content_origin = tpoint(content_->get_x() - x_offset,
|
||||
content_->get_y() - y_offset);
|
||||
const tpoint content_origin = {content_->get_x() - x_offset, content_->get_y() - y_offset};
|
||||
|
||||
content_grid_->set_origin(content_origin);
|
||||
content_grid_->set_visible_rectangle(content_visible_area_);
|
||||
|
|
|
@ -30,7 +30,7 @@ REGISTER_WIDGET(spacer)
|
|||
|
||||
tpoint tspacer::calculate_best_size() const
|
||||
{
|
||||
return best_size_ != tpoint(0, 0) ? best_size_
|
||||
return best_size_ != tpoint() ? best_size_
|
||||
: tcontrol::calculate_best_size();
|
||||
}
|
||||
|
||||
|
|
|
@ -227,8 +227,7 @@ void ttext_box::handle_mouse_selection(tpoint mouse, const bool start_selection)
|
|||
return;
|
||||
}
|
||||
|
||||
int offset = get_column_line(tpoint(mouse.x - text_x_offset_,
|
||||
mouse.y - text_y_offset_)).x;
|
||||
int offset = get_column_line(tpoint(mouse.x - text_x_offset_, mouse.y - text_y_offset_)).x;
|
||||
|
||||
if(offset < 0) {
|
||||
return;
|
||||
|
|
|
@ -162,8 +162,7 @@ tpoint ttoggle_panel::border_space() const
|
|||
tresolution>(config());
|
||||
assert(conf);
|
||||
|
||||
return tpoint(conf->left_border + conf->right_border,
|
||||
conf->top_border + conf->bottom_border);
|
||||
return tpoint(conf->left_border + conf->right_border, conf->top_border + conf->bottom_border);
|
||||
}
|
||||
|
||||
void ttoggle_panel::set_value(const unsigned selected)
|
||||
|
|
|
@ -80,7 +80,7 @@ void ttree_view::remove_node(ttree_view_node* node)
|
|||
|
||||
node->parent_node_->children_.erase(itor);
|
||||
|
||||
if(get_size() == tpoint(0, 0)) {
|
||||
if(get_size() == tpoint()) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -154,7 +154,7 @@ ttree_view_node& ttree_view_node::add_child(
|
|||
return *itor;
|
||||
}
|
||||
|
||||
if(tree_view().get_size() == tpoint(0, 0)) {
|
||||
if(tree_view().get_size() == tpoint()) {
|
||||
return *itor;
|
||||
}
|
||||
|
||||
|
@ -395,7 +395,7 @@ bool ttree_view_node::disable_click_dismiss() const
|
|||
tpoint ttree_view_node::get_current_size(bool assume_visible) const
|
||||
{
|
||||
if(!assume_visible && parent_node_ && parent_node_->is_folded()) {
|
||||
return tpoint(0, 0);
|
||||
return tpoint();
|
||||
}
|
||||
|
||||
tpoint size = get_folded_size();
|
||||
|
@ -769,7 +769,7 @@ ttree_view_node* ttree_view_node::get_node_below()
|
|||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
|
|
@ -108,7 +108,7 @@ void tviewport::place(const tpoint& origin, const tpoint& size)
|
|||
{
|
||||
twidget::place(origin, size);
|
||||
|
||||
widget_.place(tpoint(0, 0), widget_.get_best_size());
|
||||
widget_.place(tpoint(), widget_.get_best_size());
|
||||
}
|
||||
|
||||
void tviewport::layout_initialise(const bool full_initialisation)
|
||||
|
|
|
@ -32,9 +32,9 @@ twidget::twidget()
|
|||
, y_(-1)
|
||||
, width_(0)
|
||||
, height_(0)
|
||||
, layout_size_(tpoint(0, 0))
|
||||
, layout_size_()
|
||||
#ifdef DEBUG_WINDOW_LAYOUT_GRAPHS
|
||||
, last_best_size_(tpoint(0, 0))
|
||||
, last_best_size_()
|
||||
#endif
|
||||
, linked_group_()
|
||||
, is_dirty_(true)
|
||||
|
@ -56,9 +56,9 @@ twidget::twidget(const tbuilder_widget& builder)
|
|||
, y_(-1)
|
||||
, width_(0)
|
||||
, height_(0)
|
||||
, layout_size_(tpoint(0, 0))
|
||||
, layout_size_()
|
||||
#ifdef DEBUG_WINDOW_LAYOUT_GRAPHS
|
||||
, last_best_size_(tpoint(0, 0))
|
||||
, last_best_size_()
|
||||
#endif
|
||||
, linked_group_(builder.linked_group)
|
||||
, is_dirty_(true)
|
||||
|
@ -164,7 +164,7 @@ void twidget::layout_initialise(const bool /*full_initialisation*/)
|
|||
assert(visible_ != tvisible::invisible);
|
||||
assert(get_window());
|
||||
|
||||
layout_size_ = tpoint(0, 0);
|
||||
layout_size_ = tpoint();
|
||||
if(!linked_group_.empty()) {
|
||||
get_window()->add_linked_widget(linked_group_, this);
|
||||
}
|
||||
|
@ -190,7 +190,7 @@ tpoint twidget::get_best_size() const
|
|||
assert(visible_ != tvisible::invisible);
|
||||
|
||||
tpoint result = layout_size_;
|
||||
if(result == tpoint(0, 0)) {
|
||||
if(result == tpoint()) {
|
||||
result = calculate_best_size();
|
||||
//Adjust to linked widget size if linked widget size was already calculated.
|
||||
if(!get_window()->get_need_layout() && !linked_group_.empty())
|
||||
|
|
Loading…
Add table
Reference in a new issue