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

« back to all changes in this revision

Viewing changes to unity-shared/DashStyle.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:
102
102
  BaseTexturePtr const& texture();
103
103
private:
104
104
  void LoadTexture();
 
105
  void UnloadTexture();
105
106
private:
106
107
  std::string filename_;
107
108
  int size_;
173
174
  BaseTexturePtr LoadScaledTexture(std::string const& name, double scale)
174
175
  {
175
176
    int w, h;
176
 
    gdk_pixbuf_get_file_info((PKGDATADIR"/" + name).c_str(), &w, &h);
 
177
    auto const& path = theme::Settings::Get()->ThemedFilePath(name, {PKGDATADIR});
 
178
    gdk_pixbuf_get_file_info(path.c_str(), &w, &h);
177
179
    return TextureCache::GetDefault().FindTexture(name, RawPixel(w).CP(scale), RawPixel(h).CP(scale));
178
180
  }
179
181
 
249
251
  , text_color_(nux::color::White)
250
252
  , text_width_(0)
251
253
  , text_height_(0)
252
 
  , category_texture_("/category_gradient.png")
253
 
  , category_texture_no_filters_("/category_gradient_no_refine.png")
254
 
  , dash_shine_("/dash_sheen.png")
255
 
  , information_texture_("/information_icon.svg")
256
 
  , refine_gradient_corner_("/refine_gradient_corner.png")
257
 
  , refine_gradient_dash_("/refine_gradient_dash.png")
258
 
  , group_unexpand_texture_("/dash_group_unexpand.png")
259
 
  , group_expand_texture_("/dash_group_expand.png")
260
 
  , star_deselected_texture_("/star_deselected.png")
261
 
  , star_selected_texture_("/star_selected.png")
262
 
  , star_highlight_texture_("/star_highlight.png")
 
254
  , category_texture_("category_gradient")
 
255
  , category_texture_no_filters_("category_gradient_no_refine")
 
256
  , dash_shine_("dash_sheen")
 
257
  , information_texture_("information_icon")
 
258
  , refine_gradient_corner_("refine_gradient_corner")
 
259
  , refine_gradient_dash_("refine_gradient_dash")
 
260
  , group_unexpand_texture_("dash_group_unexpand")
 
261
  , group_expand_texture_("dash_group_expand")
 
262
  , star_deselected_texture_("star_deselected")
 
263
  , star_selected_texture_("star_selected")
 
264
  , star_highlight_texture_("star_highlight")
263
265
{
264
266
  auto refresh_cb = sigc::hide(sigc::mem_fun(this, &Impl::Refresh));
265
267
 
271
273
  settings.font_scaling.changed.connect(refresh_cb);
272
274
  settings.form_factor.changed.connect(sigc::mem_fun(this, &Impl::UpdateFormFactor));
273
275
 
 
276
  TextureCache::GetDefault().themed_invalidated.connect(sigc::mem_fun(&owner_->textures_changed, &decltype(owner_->textures_changed)::emit));
 
277
 
274
278
  Refresh();
275
279
  UpdateFormFactor(settings.form_factor());
276
280
 
2082
2086
  return true;
2083
2087
}
2084
2088
 
2085
 
BaseTexturePtr Style::GetDashHorizontalTile(double scale, DashPosition dash_position) const
 
2089
BaseTexturePtr Style::GetDashHorizontalTile(double scale, Position dash_position) const
2086
2090
{
2087
2091
  std::string horizontal_tile;
2088
 
  if (dash_position == DashPosition::BOTTOM)
2089
 
    horizontal_tile = "dash_top_border_tile.png";
 
2092
  if (dash_position == Position::BOTTOM)
 
2093
    horizontal_tile = "dash_top_border_tile";
2090
2094
  else
2091
 
    horizontal_tile = "dash_bottom_border_tile.png";
 
2095
    horizontal_tile = "dash_bottom_border_tile";
2092
2096
  return pimpl->LoadScaledTexture(horizontal_tile, scale);
2093
2097
}
2094
2098
 
2095
 
BaseTexturePtr Style::GetDashHorizontalTileMask(double scale, DashPosition dash_position) const
 
2099
BaseTexturePtr Style::GetDashHorizontalTileMask(double scale, Position dash_position) const
2096
2100
{
2097
2101
  std::string horizontal_tile_mask;
2098
 
  if (dash_position == DashPosition::BOTTOM)
2099
 
    horizontal_tile_mask = "dash_top_border_tile_mask.png";
 
2102
  if (dash_position == Position::BOTTOM)
 
2103
    horizontal_tile_mask = "dash_top_border_tile_mask";
2100
2104
  else
2101
 
    horizontal_tile_mask = "dash_bottom_border_tile_mask.png";
 
2105
    horizontal_tile_mask = "dash_bottom_border_tile_mask";
2102
2106
  return pimpl->LoadScaledTexture(horizontal_tile_mask, scale);
2103
2107
}
2104
2108
 
2105
2109
BaseTexturePtr Style::GetDashRightTile(double scale) const
2106
2110
{
2107
 
  return pimpl->LoadScaledTexture("dash_right_border_tile.png", scale);
 
2111
  return pimpl->LoadScaledTexture("dash_right_border_tile", scale);
2108
2112
}
2109
2113
 
2110
2114
BaseTexturePtr Style::GetDashRightTileMask(double scale) const
2111
2115
{
2112
 
  return pimpl->LoadScaledTexture("dash_right_border_tile_mask.png", scale);
 
2116
  return pimpl->LoadScaledTexture("dash_right_border_tile_mask", scale);
2113
2117
}
2114
2118
 
2115
2119
BaseTexturePtr Style::GetDashLeftTile(double scale) const
2116
2120
{
2117
 
  return pimpl->LoadScaledTexture("dash_left_tile.png", scale);
 
2121
  return pimpl->LoadScaledTexture("dash_left_tile", scale);
2118
2122
}
2119
2123
 
2120
 
BaseTexturePtr Style::GetDashTopOrBottomTile(double scale, DashPosition dash_position) const
 
2124
BaseTexturePtr Style::GetDashTopOrBottomTile(double scale, Position dash_position) const
2121
2125
{
2122
2126
  std::string top_bottom_tile;
2123
 
  if (dash_position == DashPosition::BOTTOM)
2124
 
    top_bottom_tile = "dash_bottom_tile.png";
 
2127
  if (dash_position == Position::BOTTOM)
 
2128
    top_bottom_tile = "dash_bottom_tile";
2125
2129
  else
2126
 
    top_bottom_tile = "dash_top_tile.png";
 
2130
    top_bottom_tile = "dash_top_tile";
2127
2131
  return pimpl->LoadScaledTexture(top_bottom_tile, scale);
2128
2132
}
2129
2133
 
2130
 
BaseTexturePtr Style::GetDashCorner(double scale, DashPosition dash_position) const
 
2134
BaseTexturePtr Style::GetDashCorner(double scale, Position dash_position) const
2131
2135
{
2132
2136
  std::string corner;
2133
 
  if (dash_position == DashPosition::BOTTOM)
2134
 
    corner = "dash_top_right_corner_rotated.png";
 
2137
  if (dash_position == Position::BOTTOM)
 
2138
    corner = "dash_top_right_corner_rotated";
2135
2139
  else
2136
 
    corner = "dash_bottom_right_corner.png";
 
2140
    corner = "dash_bottom_right_corner";
2137
2141
  return pimpl->LoadScaledTexture(corner, scale);
2138
2142
}
2139
2143
 
2140
 
BaseTexturePtr Style::GetDashCornerMask(double scale, DashPosition dash_position) const
 
2144
BaseTexturePtr Style::GetDashCornerMask(double scale, Position dash_position) const
2141
2145
{
2142
2146
  std::string corner_mask;
2143
 
  if (dash_position == DashPosition::BOTTOM)
2144
 
    corner_mask = "dash_top_right_corner_rotated_mask.png";
 
2147
  if (dash_position == Position::BOTTOM)
 
2148
    corner_mask = "dash_top_right_corner_rotated_mask";
2145
2149
  else
2146
 
    corner_mask = "dash_bottom_right_corner_mask.png";
 
2150
    corner_mask = "dash_bottom_right_corner_mask";
2147
2151
  return pimpl->LoadScaledTexture(corner_mask, scale);
2148
2152
}
2149
2153
 
2150
 
BaseTexturePtr Style::GetDashLeftCorner(double scale, DashPosition dash_position) const
 
2154
BaseTexturePtr Style::GetDashLeftCorner(double scale, Position dash_position) const
2151
2155
{
2152
2156
  std::string left_corner;
2153
 
  if (dash_position == DashPosition::BOTTOM)
2154
 
    left_corner = "dash_top_left_corner.png";
 
2157
  if (dash_position == Position::BOTTOM)
 
2158
    left_corner = "dash_top_left_corner";
2155
2159
  else
2156
 
    left_corner = "dash_bottom_left_corner.png";
 
2160
    left_corner = "dash_bottom_left_corner";
2157
2161
  return pimpl->LoadScaledTexture(left_corner, scale);
2158
2162
}
2159
2163
 
2160
 
BaseTexturePtr Style::GetDashLeftCornerMask(double scale, DashPosition dash_position) const
 
2164
BaseTexturePtr Style::GetDashLeftCornerMask(double scale, Position dash_position) const
2161
2165
{
2162
2166
  std::string left_corner_mask;
2163
 
  if (dash_position == DashPosition::BOTTOM)
2164
 
    left_corner_mask = "dash_top_left_corner_mask.png";
 
2167
  if (dash_position == Position::BOTTOM)
 
2168
    left_corner_mask = "dash_top_left_corner_mask";
2165
2169
  else
2166
 
    left_corner_mask = "dash_bottom_left_corner_mask.png";
 
2170
    left_corner_mask = "dash_bottom_left_corner_mask";
2167
2171
  return pimpl->LoadScaledTexture(left_corner_mask, scale);
2168
2172
}
2169
2173
 
2170
 
BaseTexturePtr Style::GetDashRightCorner(double scale, DashPosition dash_position) const
 
2174
BaseTexturePtr Style::GetDashRightCorner(double scale, Position dash_position) const
2171
2175
{
2172
2176
  std::string right_corner;
2173
 
  if (dash_position == DashPosition::BOTTOM)
2174
 
    right_corner = "dash_bottom_right_corner_rotated.png";
 
2177
  if (dash_position == Position::BOTTOM)
 
2178
    right_corner = "dash_bottom_right_corner_rotated";
2175
2179
  else
2176
 
    right_corner = "dash_top_right_corner.png";
 
2180
    right_corner = "dash_top_right_corner";
2177
2181
  return pimpl->LoadScaledTexture(right_corner, scale);
2178
2182
}
2179
2183
 
2180
 
BaseTexturePtr Style::GetDashRightCornerMask(double scale, DashPosition dash_position) const
 
2184
BaseTexturePtr Style::GetDashRightCornerMask(double scale, Position dash_position) const
2181
2185
{
2182
2186
  std::string right_corner_mask;
2183
 
  if (dash_position == DashPosition::BOTTOM)
2184
 
    right_corner_mask = "dash_bottom_right_corner_rotated_mask.png";
 
2187
  if (dash_position == Position::BOTTOM)
 
2188
    right_corner_mask = "dash_bottom_right_corner_rotated_mask";
2185
2189
  else
2186
 
    right_corner_mask = "dash_top_right_corner_mask.png";
 
2190
    right_corner_mask = "dash_top_right_corner_mask";
2187
2191
  return pimpl->LoadScaledTexture(right_corner_mask, scale);
2188
2192
}
2189
2193
 
2190
2194
BaseTexturePtr Style::GetSearchMagnifyIcon(double scale) const
2191
2195
{
2192
 
  return pimpl->LoadScaledTexture("search_magnify.svg", scale);
 
2196
  return pimpl->LoadScaledTexture("search_magnify", scale);
2193
2197
}
2194
2198
 
2195
2199
BaseTexturePtr Style::GetSearchCircleIcon(double scale) const
2196
2200
{
2197
 
  return pimpl->LoadScaledTexture("search_circle.svg", scale);
 
2201
  return pimpl->LoadScaledTexture("search_circle", scale);
2198
2202
}
2199
2203
 
2200
2204
BaseTexturePtr Style::GetSearchCloseIcon(double scale) const
2201
2205
{
2202
 
  return pimpl->LoadScaledTexture("search_close.svg", scale);
 
2206
  return pimpl->LoadScaledTexture("search_close", scale);
2203
2207
}
2204
2208
 
2205
2209
BaseTexturePtr Style::GetSearchSpinIcon(double scale) const
2206
2210
{
2207
 
  return pimpl->LoadScaledTexture("search_spin.svg", scale);
 
2211
  return pimpl->LoadScaledTexture("search_spin", scale);
2208
2212
}
2209
2213
 
2210
2214
 
2525
2529
  : filename_(filename)
2526
2530
  , size_(size)
2527
2531
{
 
2532
  TextureCache::GetDefault().themed_invalidated.connect(sigc::mem_fun(this, &LazyLoadTexture::UnloadTexture));
2528
2533
}
2529
2534
 
2530
2535
BaseTexturePtr const& LazyLoadTexture::texture()
2540
2545
  texture_ = cache.FindTexture(filename_, size_, size_);
2541
2546
}
2542
2547
 
 
2548
void LazyLoadTexture::UnloadTexture()
 
2549
{
 
2550
  texture_ = nullptr;
 
2551
}
 
2552
 
2543
2553
} // anon namespace
2544
2554
 
2545
2555
} // namespace dash