diff options
| author | Marco Trevisan (Treviño) <mail@3v1n0.net> | 2016-03-30 21:27:12 +0200 |
|---|---|---|
| committer | Marco Trevisan (Treviño) <mail@3v1n0.net> | 2016-03-30 21:27:12 +0200 |
| commit | 03743b0d732000e7164d694d4d6c4446096c6b14 (patch) | |
| tree | 510fb5982ca6f81b2fcd74c625b966666a6ae68e /shutdown | |
| parent | 779e4d9dcc49b6b02da5e4db7ee7b5a37380b595 (diff) | |
SessionButton: make textures themeable
(bzr r4093.2.12)
Diffstat (limited to 'shutdown')
| -rw-r--r-- | shutdown/SessionButton.cpp | 34 |
1 files changed, 20 insertions, 14 deletions
diff --git a/shutdown/SessionButton.cpp b/shutdown/SessionButton.cpp index 2e0eac9f9..61a6e8e11 100644 --- a/shutdown/SessionButton.cpp +++ b/shutdown/SessionButton.cpp @@ -22,6 +22,7 @@ #include <Nux/VLayout.h> #include <glib/gi18n-lib.h> +#include "unity-shared/ThemeSettings.h" namespace unity { @@ -48,33 +49,33 @@ Button::Button(Action action, NUX_FILE_LINE_DECL) SetAcceptKeyNavFocusOnMouseDown(false); SetAcceptKeyNavFocusOnMouseEnter(true); - std::string texture_prefix = PKGDATADIR"/"; + std::string texture_prefix; std::string label; switch (action_) { case Action::LOCK: - texture_prefix += "lockscreen"; + texture_prefix = "lockscreen"; label = _("Lock"); break; case Action::LOGOUT: - texture_prefix += "logout"; + texture_prefix = "logout"; label = _("Log Out"); break; case Action::SUSPEND: - texture_prefix += "suspend"; + texture_prefix = "suspend"; label = _("Suspend"); break; case Action::HIBERNATE: - texture_prefix += "hibernate"; + texture_prefix = "hibernate"; label = _("Hibernate"); break; case Action::SHUTDOWN: - texture_prefix += "shutdown"; + texture_prefix = "shutdown"; label = _("Shut Down"); break; case Action::REBOOT: - texture_prefix += "restart"; + texture_prefix = "restart"; label = _("Restart"); break; } @@ -94,6 +95,8 @@ Button::Button(Action action, NUX_FILE_LINE_DECL) image_view_->SetTexture(highlighted ? highlight_tex_ : normal_tex_); }); + theme::Settings::Get()->theme.changed.connect(sigc::hide(sigc::bind(sigc::mem_fun(this, &Button::UpdateTextures), texture_prefix))); + image_view_ = new IconTexture(normal_tex_); image_view_->SetInputEventSensitivity(false); main_layout->AddView(image_view_, 1, nux::MINOR_POSITION_CENTER); @@ -127,17 +130,20 @@ Button::Button(Action action, NUX_FILE_LINE_DECL) void Button::UpdateTextures(std::string const& texture_prefix) { - RawPixel const texture_size = GetDefaultMaxTextureSize(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)); + auto const& theme = theme::Settings::Get(); + auto texture_path = theme->ThemedFilePath(texture_prefix, {PKGDATADIR}); + RawPixel const texture_size = GetDefaultMaxTextureSize(texture_path); + normal_tex_.Adopt(nux::CreateTexture2DFromFile(texture_path.c_str(), texture_size.CP(scale), true)); + + auto texture_highlight_path = theme->ThemedFilePath(texture_prefix + "_highlight", {PKGDATADIR}); + RawPixel const texture_highlight_size = GetDefaultMaxTextureSize(texture_path); + highlight_tex_.Adopt(nux::CreateTexture2DFromFile(texture_highlight_path.c_str(), texture_highlight_size.CP(scale), true)); } -RawPixel Button::GetDefaultMaxTextureSize(std::string const& texture_prefix) const +RawPixel Button::GetDefaultMaxTextureSize(std::string const& texture_path) const { nux::Size size; - auto const& texture_name = (texture_prefix + ".png"); - gdk_pixbuf_get_file_info(texture_name.c_str(), &size.width, &size.height); + gdk_pixbuf_get_file_info(texture_path.c_str(), &size.width, &size.height); RawPixel max_size = std::max(size.width, size.height); return max_size; |
