bool tlistbox::update_content_size() { if(get_visible() == twidget::tvisible::invisible) { return true; } if(get_size() == tpoint()) { return false; } if(content_resize_request(true)) { content_grid_->set_visible_rectangle(content_visible_area()); set_is_dirty(true); return true; } return false; }
ttree_view_node& ttree_view_node::add_child( const std::string& id, const std::map<std::string /* widget id */, string_map>& data, const int index) { boost::ptr_vector<ttree_view_node>::iterator itor = children_.end(); if(static_cast<size_t>(index) < children_.size()) { itor = children_.begin() + index; } itor = children_.insert( itor, new ttree_view_node( id, node_definitions_, this, tree_view(), data)); if(is_folded() || is_root_node()) { return *itor; } if(tree_view().get_size() == tpoint(0, 0)) { return *itor; } assert(tree_view().content_grid()); const int current_width = tree_view().content_grid()->get_width(); // Calculate width modification. tpoint best_size = itor->get_best_size(); best_size.x += get_indention_level() * tree_view().indention_step_size_; const unsigned width_modification = best_size.x > current_width ? best_size.x - current_width : 0; // Calculate height modification. const int height_modification = best_size.y; assert(height_modification > 0); // Request new size. tree_view().resize_content(width_modification, height_modification); return *itor; }
tpoint ttree_view::adjust_content_size(const tpoint& size) { if (!left_align_ || empty()) { return size; } tgrid& item = root_node_->children_.begin()->grid_; // by this time, hasn't called place(), cannot use get_size(). int height = item.get_best_size().y; if (height > size.y) { return size; } int list_height = size.y / height * height; // reduce hight if necessary. height = root_node_->get_best_size().y; if (list_height > height) { list_height = height; } return tpoint(size.x, list_height); }
twidget* tbuilder_spacer::build() const { tspacer* widget = new tspacer(); init_control(widget); const game_logic::map_formula_callable& size = get_screen_size_variables(); const unsigned width = width_(size); const unsigned height = height_(size); if(width || height) { widget->set_best_size(tpoint(width, height)); } DBG_GUI_G << "Window builder: placed spacer '" << id << "' with definition '" << definition << "'.\n"; return widget; }
void ptask_wait_for_period() { #ifdef TRACEPOINT_DEFINE if(_tp[ptask_idx].act_flag == NOW) tpoint("NOW", "b_wait_period"); else if(_tp[ptask_idx].act_flag == DEFERRED) tpoint("DEFERRED", "b_wait_period"); #endif pthread_mutex_lock(&_tp[ptask_idx].mux); if (_tp[ptask_idx].measure_flag) tstat_record(ptask_idx); if (_tp[ptask_idx].modes != NULL && !rtmode_taskfind(_tp[ptask_idx].modes, ptask_idx)) { maxsem_post(&_tp[ptask_idx].modes->manager, &_tp[ptask_idx].at); pthread_mutex_unlock(&_tp[ptask_idx].mux); ptask_wait_for_activation(); #ifdef TRACEPOINT_DEFINE if(_tp[ptask_idx].act_flag == NOW) tpoint("NOW", "e_wait_period"); else if(_tp[ptask_idx].act_flag == DEFERRED) tpoint("DEFERRED", "e_wait_period"); #endif return; } else { _tp[ptask_idx].state = TASK_WFP; pthread_mutex_unlock(&_tp[ptask_idx].mux); clock_nanosleep(CLOCK_MONOTONIC, TIMER_ABSTIME, &(_tp[ptask_idx].at), NULL); pthread_mutex_lock(&_tp[ptask_idx].mux); _tp[ptask_idx].state = TASK_ACTIVE; /* update absolute deadline */ _tp[ptask_idx].dl = tspec_add(&(_tp[ptask_idx].at), &_tp[ptask_idx].deadline); /* when awaken, update next activation time */ _tp[ptask_idx].at = tspec_add(&(_tp[ptask_idx].at), &_tp[ptask_idx].period); pthread_mutex_unlock(&_tp[ptask_idx].mux); #ifdef TRACEPOINT_DEFINE if(_tp[ptask_idx].act_flag == NOW) tpoint("NOW", "e_wait_period"); else if(_tp[ptask_idx].act_flag == DEFERRED) tpoint("DEFERRED", "e_wait_period"); #endif return; } }
twidget* tbuilder_drawing::build() const { tdrawing* widget = new tdrawing(); init_control(widget); const game_logic::map_formula_callable& size = get_screen_size_variables(); const unsigned w = width(size); const unsigned h = height(size); if(w || h) { widget->set_best_size(tpoint(w, h)); } widget->canvas().front().set_cfg(draw); DBG_GUI_G << "Window builder: placed drawing '" << id << "' with definition '" << definition << "'.\n"; return widget; }
tpoint twidget::get_best_size() const { assert(visible_ != tvisible::invisible); tpoint result = layout_size_; 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()) { tpoint linked_size = get_window()->get_linked_size(linked_group_); result.x = std::max(result.x, linked_size.x); result.y = std::max(result.y, linked_size.y); } } #ifdef DEBUG_WINDOW_LAYOUT_GRAPHS last_best_size_ = result; #endif return result; }
bool tscrollbar_container::content_resize_request( const int width_modification , const int height_modification) { DBG_GUI_L << LOG_HEADER << " wanted width modification " << width_modification << " wanted height modification " << height_modification << ".\n"; if(get_size() == tpoint(0, 0)) { DBG_GUI_L << LOG_HEADER << " initial setup not done, bailing out.\n"; return false; } twindow* window = get_window(); assert(window); if(window->get_need_layout()) { DBG_GUI_L << LOG_HEADER << " window already needs a layout phase, bailing out.\n"; return false; } assert(content_ && content_grid_); const bool result = content_resize_width(width_modification) && content_resize_height(height_modification); if(result) { /* * The subroutines set the new size of the scrollbar but don't * update the button status. */ set_scrollbar_button_status(); } DBG_GUI_L << LOG_HEADER << " result " << result << ".\n"; return result; }
void ttext_box::handle_mouse_selection(tpoint mouse, const bool start_selection) { mouse.x -= get_x(); mouse.y -= get_y(); // FIXME we don't test for overflow in width if(mouse.x < static_cast<int>(text_x_offset_) || mouse.y < static_cast<int>(text_y_offset_) || mouse.y >= static_cast<int>(text_y_offset_ + text_height_)) { return; } int offset = get_column_line(tpoint(mouse.x - text_x_offset_, mouse.y - text_y_offset_)).x; if(offset < 0) { return; } set_cursor(offset, !start_selection); update_canvas(); set_is_dirty(true); dragging_ |= start_selection; }
void tmouse_motion::show_tooltip() { DBG_GUI_E << LOG_HEADER << "Firing: " << event::SHOW_TOOLTIP << ".\n"; if(!hover_widget_) { // See tmouse_motion::stop_hover_timer. ERR_GUI_E << LOG_HEADER << event::SHOW_TOOLTIP << " bailing out, no hover widget.\n"; return; } /* * Ignore the result of the event, always mark the tooltip as shown. If * there was no handler, there is no reason to assume there will be one * next time. */ owner_.fire(SHOW_TOOLTIP, *hover_widget_, hover_position_); hover_shown_ = true; hover_timer_ = 0; hover_widget_ = NULL; hover_position_ = tpoint(0, 0); }
/** Returns the size of the widget. */ tpoint get_size() const { return tpoint(w_, h_); }
tpoint twidget::get_size() const { return tpoint(width_, height_); }
tpoint twidget::get_origin() const { return tpoint(x_, y_); }
/** Initializes the layout phase. */ virtual void layout_init() { layout_size_ = tpoint(0,0); }
tpoint tplacer_vertical_list::get_size() const { const int width = std::accumulate(columns_.begin(), columns_.end(), 0); const int height = rows_.back().first + rows_.back().second; return tpoint(width, height); }
/** Inherited from tcontrol. */ tpoint calculate_best_size() const { return best_size_ != tpoint(0, 0) ? best_size_ : tcontrol::calculate_best_size(); }
/** Returns the screen origin of the widget. */ tpoint get_origin() const { return tpoint(x_, y_); }
void tviewport::place(const tpoint& origin, const tpoint& size) { twidget::place(origin, size); widget_.place(tpoint(0, 0), widget_.get_best_size()); }
ttip() : tpopup(), window_id_(), message_(), mouse_(tpoint(0, 0)) { }
tpoint tplacer_horizontal_list::get_size() const { const int width = columns_.back().first + columns_.back().second; const int height = std::accumulate(rows_.begin(), rows_.end(), 0); return tpoint(width, height); }
/** Returns the space used by the border. */ virtual tpoint border_space() const { return tpoint(0, 0); }
/** * Initializes the layout phase. * * @param full_initialization Reset the widget to its initial state. This * flag is used to change the status in the * first layout run, but keep the status when a * relayout phase happens. */ virtual void layout_init2(const bool /*full_initialization*/) { layout_size_ = tpoint(0,0); }
tpoint tdrawing::calculate_best_size() const { return best_size_ != tpoint() ? best_size_ : tcontrol::calculate_best_size(); }
tpoint tcontainer_::border_space() const { return tpoint(0, 0); }
bool tscrollbar_container::content_resize_request(const bool force_sizing) { /** * @todo Try to handle auto_visible_first_run here as well. * * Handling it here makes the code a bit more complex but allows to not * reserve space for scrollbars, which will look nicer in the MP lobby. * But the extra complexity is no 1.8 material. */ assert(content_ && content_grid_); tpoint best_size = content_grid_->recalculate_best_size(); tpoint size = content_->get_size(); DBG_GUI_L << LOG_HEADER << " wanted size " << best_size << " available size " << size << ".\n"; if(size == tpoint(0, 0)) { DBG_GUI_L << LOG_HEADER << " initial setup not done, bailing out.\n"; return false; } if(best_size.x <= size.x && best_size.y <= size.y) { const tpoint content_size = content_grid_->get_size(); if(content_size.x > size.x || content_size.y > size.y) { DBG_GUI_L << LOG_HEADER << " will fit, only needs a resize.\n"; goto resize; } if(force_sizing) { DBG_GUI_L << LOG_HEADER << " fits, but resize forced.\n"; goto resize; } DBG_GUI_L << LOG_HEADER << " fits, nothing to do.\n"; return true; } if(best_size.x > size.x) { DBG_GUI_L << LOG_HEADER << " content too wide.\n"; if(horizontal_scrollbar_mode_ == always_invisible || (horizontal_scrollbar_mode_ == auto_visible_first_run && horizontal_scrollbar_grid_->get_visible() == twidget::tvisible::invisible)) { DBG_GUI_L << LOG_HEADER << " can't use horizontal scrollbar, ask window.\n"; twindow* window = get_window(); assert(window); window->invalidate_layout(); return false; } } if(best_size.y > size.y) { DBG_GUI_L << LOG_HEADER << " content too high.\n"; if(vertical_scrollbar_mode_ == always_invisible || (vertical_scrollbar_mode_ == auto_visible_first_run && vertical_scrollbar_grid_->get_visible() == twidget::tvisible::invisible)) { DBG_GUI_L << LOG_HEADER << " can't use vertical scrollbar, ask window.\n"; twindow* window = get_window(); assert(window); window->invalidate_layout(); return false; } } resize: DBG_GUI_L << LOG_HEADER << " handle resizing.\n"; place(get_origin(), get_size()); return true; }
tpoint operator-(const tpoint& point) const { return tpoint(x - point.x, y - point.y); }
tpoint operator+(const tpoint& point) const { return tpoint(x + point.x, y + point.y); }
void ttabbar::replacement_children() { int grid_width = report_->content_grid_->get_width(); int grid_height = report_->content_grid_->get_height(); if (grid_width <= 0) { return; } const tgrid::tchild* children = report_->content_grid()->children(); int vsize = report_->content_grid_->children_vsize(); int unit_w = report_->unit_size_.x; if (segment_) { if (!segment_childs_) { segment_childs_ = (grid_width + report_->gap_) / (report_->unit_size_.x + report_->gap_) - 2; VALIDATE(segment_childs_ > 0, null_str); } } else { segment_childs_ = 0; } int last_n = twidget::npos, last_width = 0; bool require_next = false; int n = front_childs; for (int tmp = 0; tmp < start_; n ++) { const tgrid::tchild& child = children[n]; twidget* widget = child.widget_; // these widget not in current group, as if user require visilbe, but invisible. widget->set_visible(twidget::INVISIBLE); if (get_visible2(children, n)) { tmp ++; } } twidget::tvisible previous_visible = twidget::INVISIBLE; if (start_) { previous_visible = twidget::VISIBLE; } else if (segment_) { previous_visible = twidget::HIDDEN; } children[0].widget_->set_visible(previous_visible); int additive_width = previous_visible != twidget::INVISIBLE? children[0].widget_->fix_width(): 0; int additive_child = 0; int end = vsize - back_childs; for (; n < end; n ++) { const tgrid::tchild& child = children[n]; twidget* widget = child.widget_; if (!get_visible2(children, n)) { // USER_PRIVATE(=1): user force it invisible. widget->set_visible(twidget::INVISIBLE); continue; } if (!report_->unit_size_.x) { unit_w = widget->get_best_size().x; } if (require_next || additive_width + unit_w > grid_width || (segment_ && additive_child == segment_childs_)) { widget->set_visible(twidget::INVISIBLE); if (!require_next) { if (!segment_) { if (grid_width - additive_width >= next_->fix_width()) { last_n = twidget::npos; } else { // residue width cannot hold "next" button, invisible last widget to lengthen residue width. additive_width -= last_width + report_->gap_; } } require_next = true; } continue; } widget->set_visible(twidget::VISIBLE); if (callback_show_) { callback_show_(this, child); } if (!segment_) { additive_width += unit_w + report_->gap_; last_n = n; last_width = unit_w; segment_childs_ ++; } else { additive_child ++; } } int spacer_width = 0; if (require_next) { if (last_n != twidget::npos) { children[last_n].widget_->set_visible(twidget::INVISIBLE); segment_childs_ --; } spacer_width = grid_width - additive_width - next_->fix_width(); } if (!report_->unit_size_.x) { // when fix size, don't insert spacer. this width maybe diffirent from fix width. stuff_widget_->set_best_size(tpoint(spacer_width, grid_height)); stuff_widget_->set_visible(twidget::VISIBLE); } next_->set_visible(require_next? twidget::VISIBLE: twidget::INVISIBLE); report_->replacement_children(); }