~ci-train-bot/unity/unity-ubuntu-xenial-landing-028

« back to all changes in this revision

Viewing changes to shutdown/SessionButton.cpp

  • Committer: CI Train Bot
  • Author(s): Marco Trevisan (Treviño)
  • Date: 2016-04-01 23:11:21 UTC
  • mfrom: (4093.2.30 themed-texture-cache)
  • Revision ID: ci-train-bot@canonical.com-20160401231121-or6ge8fgw25y4m41
TextureCache: add support for loading themed textures

When a themed texture is requested, we add it to a list so that we can invalidate
it on theme changes.

Use themed textures in any case we load local files, falling back to the default path if
theme doesn't provide any customized asset. Fixes: #903179, #1208790
Approved by: Andrea Azzarone

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
 
23
23
#include <Nux/VLayout.h>
24
24
#include <glib/gi18n-lib.h>
 
25
#include "unity-shared/ThemeSettings.h"
25
26
 
26
27
namespace unity
27
28
{
48
49
  SetAcceptKeyNavFocusOnMouseDown(false);
49
50
  SetAcceptKeyNavFocusOnMouseEnter(true);
50
51
 
51
 
  std::string texture_prefix = PKGDATADIR"/";
 
52
  std::string texture_prefix;
52
53
  std::string label;
53
54
 
54
55
  switch (action_)
55
56
  {
56
57
    case Action::LOCK:
57
 
      texture_prefix += "lockscreen";
 
58
      texture_prefix = "lockscreen";
58
59
      label = _("Lock");
59
60
      break;
60
61
    case Action::LOGOUT:
61
 
      texture_prefix += "logout";
 
62
      texture_prefix = "logout";
62
63
      label = _("Log Out");
63
64
      break;
64
65
    case Action::SUSPEND:
65
 
      texture_prefix += "suspend";
 
66
      texture_prefix = "suspend";
66
67
      label = _("Suspend");
67
68
      break;
68
69
    case Action::HIBERNATE:
69
 
      texture_prefix += "hibernate";
 
70
      texture_prefix = "hibernate";
70
71
      label = _("Hibernate");
71
72
      break;
72
73
    case Action::SHUTDOWN:
73
 
      texture_prefix += "shutdown";
 
74
      texture_prefix = "shutdown";
74
75
      label = _("Shut Down");
75
76
      break;
76
77
    case Action::REBOOT:
77
 
      texture_prefix += "restart";
 
78
      texture_prefix = "restart";
78
79
      label = _("Restart");
79
80
      break;
80
81
  }
94
95
    image_view_->SetTexture(highlighted ? highlight_tex_ : normal_tex_);
95
96
  });
96
97
 
 
98
  theme::Settings::Get()->theme.changed.connect(sigc::hide(sigc::bind(sigc::mem_fun(this, &Button::UpdateTextures), texture_prefix)));
 
99
 
97
100
  image_view_ = new IconTexture(normal_tex_);
98
101
  image_view_->SetInputEventSensitivity(false);
99
102
  main_layout->AddView(image_view_, 1, nux::MINOR_POSITION_CENTER);
127
130
 
128
131
void Button::UpdateTextures(std::string const& texture_prefix)
129
132
{
130
 
  RawPixel const texture_size = GetDefaultMaxTextureSize(texture_prefix);
 
133
  auto const& theme = theme::Settings::Get();
 
134
  auto texture_path = theme->ThemedFilePath(texture_prefix, {PKGDATADIR});
 
135
  RawPixel const texture_size = GetDefaultMaxTextureSize(texture_path);
 
136
  normal_tex_.Adopt(nux::CreateTexture2DFromFile(texture_path.c_str(), texture_size.CP(scale), true));
131
137
 
132
 
  normal_tex_.Adopt(nux::CreateTexture2DFromFile((texture_prefix + ".png").c_str(), texture_size.CP(scale), true));
133
 
  highlight_tex_.Adopt(nux::CreateTexture2DFromFile((texture_prefix + "_highlight.png").c_str(), texture_size.CP(scale), true));
 
138
  auto texture_highlight_path = theme->ThemedFilePath(texture_prefix + "_highlight", {PKGDATADIR});
 
139
  RawPixel const texture_highlight_size = GetDefaultMaxTextureSize(texture_path);
 
140
  highlight_tex_.Adopt(nux::CreateTexture2DFromFile(texture_highlight_path.c_str(), texture_highlight_size.CP(scale), true));
134
141
}
135
142
 
136
 
RawPixel Button::GetDefaultMaxTextureSize(std::string const& texture_prefix) const
 
143
RawPixel Button::GetDefaultMaxTextureSize(std::string const& texture_path) const
137
144
{
138
145
  nux::Size size;
139
 
  auto const& texture_name = (texture_prefix + ".png");
140
 
  gdk_pixbuf_get_file_info(texture_name.c_str(), &size.width, &size.height);
 
146
  gdk_pixbuf_get_file_info(texture_path.c_str(), &size.width, &size.height);
141
147
  RawPixel max_size = std::max(size.width, size.height);
142
148
 
143
149
  return max_size;