summaryrefslogtreecommitdiff
path: root/shutdown
diff options
Diffstat (limited to 'shutdown')
-rw-r--r--shutdown/SessionButton.cpp27
-rw-r--r--shutdown/SessionButton.h5
-rw-r--r--shutdown/SessionController.cpp2
-rw-r--r--shutdown/SessionView.cpp20
-rw-r--r--shutdown/SessionView.h1
5 files changed, 31 insertions, 24 deletions
diff --git a/shutdown/SessionButton.cpp b/shutdown/SessionButton.cpp
index d7d0ebc05..fff33ca8f 100644
--- a/shutdown/SessionButton.cpp
+++ b/shutdown/SessionButton.cpp
@@ -23,8 +23,6 @@
#include <Nux/VLayout.h>
#include <glib/gi18n-lib.h>
-#include "unity-shared/RawPixel.h"
-
namespace unity
{
namespace session
@@ -42,10 +40,12 @@ NUX_IMPLEMENT_OBJECT_TYPE(Button);
Button::Button(Action action, NUX_FILE_LINE_DECL)
: nux::View(NUX_FILE_LINE_PARAM)
+ , scale(1.0)
, highlighted(false)
, action([this] { return action_; })
, label([this] { return label_view_->GetText(); })
, action_(action)
+ , texture_size_(-1)
{
SetAcceptKeyNavFocusOnMouseDown(false);
SetAcceptKeyNavFocusOnMouseEnter(true);
@@ -81,8 +81,8 @@ Button::Button(Action action, NUX_FILE_LINE_DECL)
break;
}
- normal_tex_.Adopt(nux::CreateTexture2DFromFile((texture_prefix + ".png").c_str(), -1, true));
- highlight_tex_.Adopt(nux::CreateTexture2DFromFile((texture_prefix + "_highlight.png").c_str(), -1, true));
+ GetDefaultMaxTextureSize(texture_prefix);
+ UpdateTextures(texture_prefix);
auto main_layout = new nux::VLayout();
main_layout->SetContentDistribution(nux::MAJOR_POSITION_CENTER);
@@ -93,8 +93,7 @@ Button::Button(Action action, NUX_FILE_LINE_DECL)
main_layout->SetSpaceBetweenChildren(style::BUTTON_SPACE.CP(new_scale));
label_view_->SetScale(new_scale);
- normal_tex_.Adopt(nux::CreateTexture2DFromFile((texture_prefix + ".png").c_str(), style::DEFAULT_TEXTURE_SIZE.CP(new_scale), true));
- highlight_tex_.Adopt(nux::CreateTexture2DFromFile((texture_prefix + "_highlight.png").c_str(), style::DEFAULT_TEXTURE_SIZE.CP(new_scale), true));
+ UpdateTextures(texture_prefix);
image_view_->SetTexture(highlighted ? highlight_tex_ : normal_tex_);
});
@@ -123,6 +122,22 @@ Button::Button(Action action, NUX_FILE_LINE_DECL)
});
}
+void Button::UpdateTextures(std::string const& texture_prefix)
+{
+ normal_tex_.Adopt(nux::CreateTexture2DFromFile((texture_prefix + ".png").c_str(), texture_size_.CP(scale), true));
+ highlight_tex_.Adopt(nux::CreateTexture2DFromFile((texture_prefix + "_highlight.png").c_str(), texture_size_.CP(scale), true));
+}
+
+void Button::GetDefaultMaxTextureSize(std::string const& texture_prefix)
+{
+ nux::Size size;
+ auto const& texture_name = (texture_prefix + ".png");
+ gdk_pixbuf_get_file_info(texture_name.c_str(), &size.width, &size.height);
+ int max_size = std::max(std::round(size.width * scale), std::round(size.height * scale));
+
+ texture_size_ = max_size;
+}
+
void Button::Draw(nux::GraphicsEngine& ctx, bool force)
{
GetLayout()->ProcessDraw(ctx, force);
diff --git a/shutdown/SessionButton.h b/shutdown/SessionButton.h
index cc5abe976..e46704271 100644
--- a/shutdown/SessionButton.h
+++ b/shutdown/SessionButton.h
@@ -26,6 +26,7 @@
#include "unity-shared/IconTexture.h"
#include "unity-shared/Introspectable.h"
+#include "unity-shared/RawPixel.h"
#include "unity-shared/StaticCairoText.h"
namespace unity
@@ -66,11 +67,15 @@ protected:
private:
friend class TestSessionButton;
+ void UpdateTextures(std::string const& texture_prefix);
+ void GetDefaultMaxTextureSize(std::string const& texture_prefix);
+
Action action_;
IconTexture* image_view_;
StaticCairoText* label_view_;
nux::ObjectPtr<nux::BaseTexture> normal_tex_;
nux::ObjectPtr<nux::BaseTexture> highlight_tex_;
+ RawPixel texture_size_;
};
} // namespace session
diff --git a/shutdown/SessionController.cpp b/shutdown/SessionController.cpp
index 5fc04a363..d29570d6e 100644
--- a/shutdown/SessionController.cpp
+++ b/shutdown/SessionController.cpp
@@ -151,6 +151,8 @@ void Controller::ConstructView()
{
view_->size_changed.connect([this] (nux::Area*, int, int) {
int monitor = UScreen::GetDefault()->GetMonitorWithMouse();
+ view_->monitor = monitor;
+
auto const& offset = GetOffsetPerMonitor(monitor);
view_window_->SetXY(offset.x, offset.y);
});
diff --git a/shutdown/SessionView.cpp b/shutdown/SessionView.cpp
index 43ff7edc2..375cc6779 100644
--- a/shutdown/SessionView.cpp
+++ b/shutdown/SessionView.cpp
@@ -82,8 +82,6 @@ View::View(Manager::Ptr const& manager)
if (new_mode == Mode::SHUTDOWN && !manager_->CanShutdown())
new_mode = Mode::LOGOUT;
- UpdateEMConverter();
-
if (target != new_mode)
{
target = new_mode;
@@ -94,32 +92,21 @@ View::View(Manager::Ptr const& manager)
});
mode.changed.connect([this] (Mode m) {
- UpdateEMConverter();
UpdateText();
Populate();
});
monitor.changed.connect([this] (bool changed) {
- UpdateEMConverter();
+ UpdateViewSize();
});
- Settings::Instance().dpi_changed.connect(sigc::mem_fun(this, &View::UpdateEMConverter));
+ Settings::Instance().dpi_changed.connect(sigc::mem_fun(this, &View::UpdateViewSize));
UpdateViewSize();
UpdateText();
Populate();
}
-void View::UpdateEMConverter()
-{
- int mouse_monitor = UScreen::GetDefault()->GetMonitorWithMouse();
- if (monitor != mouse_monitor)
- {
- monitor = mouse_monitor;
- UpdateViewSize();
- }
-}
-
void View::UpdateViewSize()
{
main_layout_->SetTopAndBottomPadding(cv_->CP(style::TOP_PADDING), cv_->CP(style::BOTTOM_PADDING));
@@ -133,7 +120,7 @@ void View::UpdateViewSize()
for (auto* area : buttons_layout_->GetChildren())
{
- auto* button = (Button*)area;
+ auto* button = static_cast<Button*>(area);
button->scale = cv_->DPIScale();
}
}
@@ -242,7 +229,6 @@ void View::Populate()
{
button = new Button(Button::Action::HIBERNATE, NUX_TRACKER_LOCATION);
button->scale = cv_->DPIScale();
- button->scale = cv_->DPIScale();
button->activated.connect(sigc::mem_fun(manager_.get(), &Manager::Hibernate));
AddButton(button);
}
diff --git a/shutdown/SessionView.h b/shutdown/SessionView.h
index dd7d0e6fd..3373c312c 100644
--- a/shutdown/SessionView.h
+++ b/shutdown/SessionView.h
@@ -73,7 +73,6 @@ protected:
private:
friend class TestSessionView;
- void UpdateEMConverter();
void UpdateViewSize();
void UpdateText();