diff options
| author | Marco Trevisan (TreviƱo) <mail@3v1n0.net> | 2012-12-18 03:02:51 +0000 |
|---|---|---|
| committer | Tarmac <> | 2012-12-18 03:02:51 +0000 |
| commit | 4180c3872fe397f4bd816e8bb3dfecdca59d62b8 (patch) | |
| tree | d60c4f870088672a7de9c886842be486fca2bb03 /unity-shared | |
| parent | 3300f3f9118c6df734af587d9aa376c6b3aed0f2 (diff) | |
| parent | 6d3cc63be96fe0bec76f5199ec2acadbad977abb (diff) | |
PanelStyle: use smart pointers (update WindowButtons and PanelView).
Approved by Andrea Azzarone. (bzr r2998)
Diffstat (limited to 'unity-shared')
| -rw-r--r-- | unity-shared/PanelStyle.cpp | 50 | ||||
| -rw-r--r-- | unity-shared/PanelStyle.h | 8 |
2 files changed, 24 insertions, 34 deletions
diff --git a/unity-shared/PanelStyle.cpp b/unity-shared/PanelStyle.cpp index 9bf25e1e2..95c53d17f 100644 --- a/unity-shared/PanelStyle.cpp +++ b/unity-shared/PanelStyle.cpp @@ -21,6 +21,7 @@ #include "config.h" #include <math.h> +#include <array> #include <gtk/gtk.h> #include <boost/algorithm/string/predicate.hpp> @@ -166,7 +167,7 @@ GtkStyleContext* Style::GetStyleContext() return _style_context; } -nux::NBitmapData* Style::GetBackground(int width, int height, float opacity) +BaseTexturePtr Style::GetBackground(int width, int height, float opacity) { nux::CairoGraphics context(CAIRO_FORMAT_ARGB32, width, height); @@ -178,7 +179,7 @@ nux::NBitmapData* Style::GetBackground(int width, int height, float opacity) cairo_pop_group_to_source(cr); cairo_paint_with_alpha(cr, opacity); - return context.GetBitmap(); + return texture_ptr_from_cairo_graphics(context); } /*! @@ -192,19 +193,17 @@ nux::NBitmapData* Style::GetBackground(int width, int height, float opacity) std::vector<std::string> Style::GetWindowButtonFileNames(WindowButtonType type, WindowState state) { std::vector<std::string> files; - std::string names[] = { "close", "minimize", "unmaximize", "maximize" }; - std::string states[] = { "", "_focused_prelight", "_focused_pressed", "_unfocused", - "_unfocused", "_unfocused_prelight", "_unfocused_pressed"}; + static const std::array<std::string, 4> names = {{ "close", "minimize", "unmaximize", "maximize" }}; + static const std::array<std::string, 7> states = {{ "", "_focused_prelight", "_focused_pressed", "_unfocused", + "_unfocused", "_unfocused_prelight", "_unfocused_pressed" }}; - std::ostringstream subpath; - subpath << "unity/" << names[static_cast<int>(type)] - << states[static_cast<int>(state)] << ".png"; + std::string subpath = "unity/" + names[static_cast<int>(type)] + states[static_cast<int>(state)] + ".png"; // Look in home directory const char* home_dir = g_get_home_dir(); if (home_dir) { - glib::String filename(g_build_filename(home_dir, ".themes", _theme_name.c_str(), subpath.str().c_str(), NULL)); + glib::String filename(g_build_filename(home_dir, ".themes", _theme_name.c_str(), subpath.c_str(), NULL)); if (g_file_test(filename.Value(), G_FILE_TEST_EXISTS)) files.push_back (filename.Value()); @@ -214,33 +213,23 @@ std::vector<std::string> Style::GetWindowButtonFileNames(WindowButtonType type, if (!var) var = "/usr"; - glib::String filename(g_build_filename(var, "share", "themes", _theme_name.c_str(), subpath.str().c_str(), NULL)); + glib::String filename(g_build_filename(var, "share", "themes", _theme_name.c_str(), subpath.c_str(), NULL)); if (g_file_test(filename.Value(), G_FILE_TEST_EXISTS)) files.push_back (filename.Value()); return files; } -nux::BaseTexture* Style::GetWindowButton(WindowButtonType type, WindowState state) +BaseTexturePtr Style::GetWindowButton(WindowButtonType type, WindowState state) { - nux::BaseTexture* texture = NULL; + BaseTexturePtr texture; - std::vector<std::string> files = GetWindowButtonFileNames (type, state); - for (unsigned int i=0; i < files.size(); i++) + for (auto const& file : GetWindowButtonFileNames(type, state)) { - glib::Error error; - // Try loading the pixbuf - glib::Object<GdkPixbuf> pixbuf(gdk_pixbuf_new_from_file(files[i].c_str (), &error)); - if (error) - { - LOG_WARNING(logger) << "Unable to load window button " << files[i] << ": " << error.Message(); - } - else - { - texture = nux::CreateTexture2DFromPixbuf(pixbuf, true); - if (texture) - break; - } + texture.Adopt(nux::CreateTexture2DFromFile(file.c_str(), -1, true)); + + if (texture) + break; } if (!texture) @@ -249,7 +238,7 @@ nux::BaseTexture* Style::GetWindowButton(WindowButtonType type, WindowState stat return texture; } -nux::BaseTexture* Style::GetFallbackWindowButton(WindowButtonType type, +BaseTexturePtr Style::GetFallbackWindowButton(WindowButtonType type, WindowState state) { int width = 17, height = 17; @@ -265,7 +254,7 @@ nux::BaseTexture* Style::GetFallbackWindowButton(WindowButtonType type, float h = height / 3.0f; nux::CairoGraphics cairo_graphics(CAIRO_FORMAT_ARGB32, canvas_w, canvas_h); nux::Color main = (state != WindowState::UNFOCUSED) ? _text_color : nux::color::Gray; - cairo_t* cr = cairo_graphics.GetContext(); + cairo_t* cr = cairo_graphics.GetInternalContext(); if (type == WindowButtonType::CLOSE) { @@ -337,9 +326,8 @@ nux::BaseTexture* Style::GetFallbackWindowButton(WindowButtonType type, } cairo_stroke(cr); - cairo_destroy(cr); - return texture_from_cairo_graphics(cairo_graphics); + return texture_ptr_from_cairo_graphics(cairo_graphics); } glib::Object<GdkPixbuf> Style::GetHomeButton() diff --git a/unity-shared/PanelStyle.h b/unity-shared/PanelStyle.h index b73c05f74..681c54b2b 100644 --- a/unity-shared/PanelStyle.h +++ b/unity-shared/PanelStyle.h @@ -68,11 +68,13 @@ public: static Style& Instance(); + typedef nux::ObjectPtr<nux::BaseTexture> BaseTexturePtr; + GtkStyleContext* GetStyleContext(); - nux::NBitmapData* GetBackground(int width, int height, float opacity); - nux::BaseTexture* GetWindowButton(WindowButtonType type, WindowState state); + BaseTexturePtr GetBackground(int width, int height, float opacity); + BaseTexturePtr GetWindowButton(WindowButtonType type, WindowState state); + BaseTexturePtr GetFallbackWindowButton(WindowButtonType type, WindowState state); std::vector<std::string> GetWindowButtonFileNames(WindowButtonType type, WindowState state); - nux::BaseTexture* GetFallbackWindowButton(WindowButtonType type, WindowState state); glib::Object<GdkPixbuf> GetHomeButton(); std::string GetFontDescription(PanelItem item); int GetTextDPI(); |
