diff options
| author | Marco Trevisan (Treviño) <mail@3v1n0.net> | 2016-03-30 20:48:42 +0200 | 
|---|---|---|
| committer | Marco Trevisan (Treviño) <mail@3v1n0.net> | 2016-03-30 20:48:42 +0200 | 
| commit | 2de281b18437c332ad03202ca7115f8efeaa08d7 (patch) | |
| tree | a31fc1754bc463140cba24531ca163908bfa5e87 /hud | |
| parent | f563f04ce7dfeb9c48a018269b4bf03091466d29 (diff) | |
HudView: only create the icon instance if needed
This tiny icon is actually more expensive than expected, since it uses the IconRenderer and thus could cause reloading some textures for no gain. Also this is not visible in default configuration (bzr r4093.2.10)
Diffstat (limited to 'hud')
| -rw-r--r-- | hud/HudController.cpp | 1 | ||||
| -rw-r--r-- | hud/HudView.cpp | 29 | ||||
| -rw-r--r-- | hud/HudView.h | 1 | 
3 files changed, 13 insertions, 18 deletions
| diff --git a/hud/HudController.cpp b/hud/HudController.cpp index b09726be4..bfc7256ad 100644 --- a/hud/HudController.cpp +++ b/hud/HudController.cpp @@ -425,6 +425,7 @@ void Controller::HideHud()  need_show_ = false;  EnsureHud();  view_->AboutToHide(); + view_->ShowEmbeddedIcon(false);  window_->CaptureMouseDownAnyWhereElse(false);  window_->EnableInputWindow(false, "Hud", true, false);  visible_ = false; diff --git a/hud/HudView.cpp b/hud/HudView.cpp index 2e03c8c67..c7b8f9712 100644 --- a/hud/HudView.cpp +++ b/hud/HudView.cpp @@ -67,7 +67,6 @@ View::View()  , last_known_height_(0)  , current_height_(0)  , selected_button_(0) - , show_embedded_icon_(true)  , keyboard_stole_focus_(false)  , overlay_window_buttons_(new OverlayWindowButtons())  { @@ -303,21 +302,24 @@ void View::SetIcon(std::string const& icon_name, unsigned int tile_size, unsigne  void View::ShowEmbeddedIcon(bool show)  {  LOG_DEBUG(logger) << "Hide icon called"; - if (show == show_embedded_icon_) + if (show == icon_.IsValid())  return; - show_embedded_icon_ = show; - - if (show_embedded_icon_) + if (show)  { - layout_->AddView(icon_.GetPointer(), 0, nux::MINOR_POSITION_START, - nux::MINOR_SIZE_FULL, 100.0f, nux::LayoutPosition::NUX_LAYOUT_BEGIN); - AddChild(icon_.GetPointer()); + if (!icon_) + { + icon_ = new Icon(); + layout_->AddView(icon_.GetPointer(), 0, nux::MINOR_POSITION_START, + nux::MINOR_SIZE_FULL, 100.0f, nux::LayoutPosition::NUX_LAYOUT_BEGIN); + AddChild(icon_.GetPointer()); + }  } - else + else if (icon_)  {  layout_->RemoveChildObject(icon_.GetPointer());  RemoveChild(icon_.GetPointer()); + icon_ = nullptr;  }  UpdateLayoutGeometry(); @@ -332,7 +334,7 @@ nux::Geometry View::GetBestFitGeometry(nux::Geometry const& for_geo)  int width = DEFAULT_WIDTH.CP(scale);  int height = DEFAULT_HEIGHT.CP(scale); - if (show_embedded_icon_) + if (icon_)  width += icon_->GetGeometry().width;  LOG_DEBUG (logger) << "best fit is, " << width << ", " << height; @@ -370,13 +372,6 @@ void View::SetupViews()  nux::VLayout* super_layout = new nux::VLayout();  layout_ = new nux::HLayout();  { - // fill layout with icon - icon_ = new Icon(); - { - AddChild(icon_.GetPointer()); - layout_->AddView(icon_.GetPointer(), 0, nux::MINOR_POSITION_START, nux::MINOR_SIZE_FULL); - } -  // fill the content layout  content_layout_ = new nux::VLayout();  { diff --git a/hud/HudView.h b/hud/HudView.h index b099edd7a..c05c880c8 100644 --- a/hud/HudView.h +++ b/hud/HudView.h @@ -120,7 +120,6 @@ private:  int last_known_height_;  int current_height_;  int selected_button_; - bool show_embedded_icon_;  bool activated_signal_sent_;  bool keyboard_stole_focus_; | 
