diff options
| -rw-r--r-- | resources/dialog_border_corner.png (renamed from resources/switcher_corner.png) | bin | 733 -> 733 bytes | |||
| -rw-r--r-- | resources/dialog_border_left.png (renamed from resources/switcher_left.png) | bin | 220 -> 220 bytes | |||
| -rw-r--r-- | resources/dialog_border_top.png (renamed from resources/switcher_top.png) | bin | 211 -> 211 bytes | |||
| -rw-r--r-- | tests/test_thumbnail_generator.cpp | 4 | ||||
| -rw-r--r-- | tests/test_unity_window_view.cpp | 6 | ||||
| -rw-r--r-- | unity-shared/UnityWindowStyle.cpp | 70 | ||||
| -rw-r--r-- | unity-shared/UnityWindowStyle.h | 19 | ||||
| -rw-r--r-- | unity-shared/UnityWindowView.cpp | 17 |
8 files changed, 62 insertions, 54 deletions
diff --git a/resources/switcher_corner.png b/resources/dialog_border_corner.png Binary files differindex 4bae2412f..4bae2412f 100644 --- a/resources/switcher_corner.png +++ b/resources/dialog_border_corner.png diff --git a/resources/switcher_left.png b/resources/dialog_border_left.png Binary files differindex b852b10f1..b852b10f1 100644 --- a/resources/switcher_left.png +++ b/resources/dialog_border_left.png diff --git a/resources/switcher_top.png b/resources/dialog_border_top.png Binary files differindex 595d842dd..595d842dd 100644 --- a/resources/switcher_top.png +++ b/resources/dialog_border_top.png diff --git a/tests/test_thumbnail_generator.cpp b/tests/test_thumbnail_generator.cpp index c807392ad..19dc75a4a 100644 --- a/tests/test_thumbnail_generator.cpp +++ b/tests/test_thumbnail_generator.cpp @@ -121,8 +121,8 @@ TEST(TestThumbnailGenerator, TestGetManyFileThumbnail) ThumbnailGenerator thumbnail_generator; const char* thumbs[] = { "file://" SOURCEDATADIR "/switcher_background.png" , "file://" SOURCEDATADIR "/star_highlight.png", - "file://" SOURCEDATADIR "/launcher_bfb.png", "file://" SOURCEDATADIR "/switcher_corner.png", - "file://" SOURCEDATADIR "/switcher_top.png", "file://" SOURCEDATADIR "/switcher_left.png", + "file://" SOURCEDATADIR "/launcher_bfb.png", "file://" SOURCEDATADIR "/dialog_border_corner.png", + "file://" SOURCEDATADIR "/dialog_border_top.png", "file://" SOURCEDATADIR "/dialog_border_left.png", "file://" SOURCEDATADIR "/dash_bottom_left_corner.png", "file://" SOURCEDATADIR "/dash_bottom_right_corner.png"}; std::vector<LoadResult> results; diff --git a/tests/test_unity_window_view.cpp b/tests/test_unity_window_view.cpp index 1eb0d2562..9b49c9573 100644 --- a/tests/test_unity_window_view.cpp +++ b/tests/test_unity_window_view.cpp @@ -85,7 +85,7 @@ TEST_F(TestUnityWindowView, Closable) EXPECT_EQ(view.close_button_->texture(), view.style()->GetTexture(view.scale, WindowTextureType::CLOSE_ICON)); EXPECT_EQ(view.close_button_->GetParentObject(), &view); - int padding = view.style()->GetCloseButtonPadding(view.scale); + int padding = view.style()->GetCloseButtonPadding().CP(view.scale); EXPECT_EQ(view.close_button_->GetBaseX(), padding); EXPECT_EQ(view.close_button_->GetBaseY(), padding); } @@ -185,7 +185,7 @@ TEST_F(TestUnityWindowView, SetLayoutWrapsOriginalLayout) view.SetLayout(layout); view.ComputeContentSize(); - int offset = view.style()->GetInternalOffset(view.scale); + int offset = view.style()->GetInternalOffset().CP(view.scale); EXPECT_EQ(layout->GetBaseX(), offset); EXPECT_EQ(layout->GetBaseY(), offset); } @@ -199,7 +199,7 @@ TEST_F(TestUnityWindowView, GetLayout) TEST_F(TestUnityWindowView, GetInternalBackground) { - int offset = view.style()->GetInternalOffset(view.scale); + int offset = view.style()->GetInternalOffset().CP(view.scale); view.background_geo_.Set(g_random_int(), g_random_int(), g_random_int(), g_random_int()); EXPECT_EQ(view.GetInternalBackground(), view.background_geo_.GetExpand(-offset, -offset)); } diff --git a/unity-shared/UnityWindowStyle.cpp b/unity-shared/UnityWindowStyle.cpp index 598380a2c..ec9598df7 100644 --- a/unity-shared/UnityWindowStyle.cpp +++ b/unity-shared/UnityWindowStyle.cpp @@ -21,8 +21,10 @@ #include <NuxCore/Logger.h> -#include "UnitySettings.h" #include "UnityWindowStyle.h" + +#include "ThemeSettings.h" +#include "UnitySettings.h" #include "UScreen.h" #include "config.h" @@ -34,23 +36,22 @@ namespace ui { namespace { - const char* const SWITCHER_TOP = PKGDATADIR"/switcher_top.png"; - const char* const SWITCHER_LEFT = PKGDATADIR"/switcher_left.png"; - const char* const SWITCHER_CORNER = PKGDATADIR"/switcher_corner.png"; + // THemeable + const std::string DIALOG_BORDER_TOP = "dialog_border_top"; + const std::string DIALOG_BORDER_LEFT = "dialog_border_left"; + const std::string DIALOG_BORDER_CORNER = "dialog_border_corner"; - const char* const DIALOG_CLOSE = PKGDATADIR"/dialog_close.png"; - const char* const DIALOG_HIGHLIGHT = PKGDATADIR"/dialog_close_highlight.png"; - const char* const DIALOG_PRESS = PKGDATADIR"/dialog_close_press.png"; + const std::string DIALOG_CLOSE = "dialog_close"; + const std::string DIALOG_HIGHLIGHT = "dialog_close_highlight"; + const std::string DIALOG_PRESS = "dialog_close_press"; + const RawPixel BORDER_SIZE = 30_em; // as measured from textures + const RawPixel INTERNAL_OFFSET = 20_em; + const RawPixel CLOSE_PADDING = 3_em; - RawPixel const INTERNAL_OFFSET = 20_em; - RawPixel const BORDER_SIZE = 30_em; - RawPixel const CLOSE_PADDING = 3_em; + DECLARE_LOGGER(logger, "unity.ui.window.style"); } -DECLARE_LOGGER(logger, "unity.ui.unity.window.style"); - - UnityWindowStyle::UnityWindowStyle() { unsigned monitors = UScreen::GetDefault()->GetPluggedMonitorsNumber(); @@ -67,31 +68,33 @@ UnityWindowStyle::UnityWindowStyle() settings.Instance().dpi_changed.connect(sigc::mem_fun(this, &UnityWindowStyle::CleanUpUnusedTextures)); UScreen::GetDefault()->changed.connect(sigc::mem_fun(this, &UnityWindowStyle::OnMonitorChanged)); + theme::Settings::Get()->font.changed.connect(sigc::mem_fun(this, &UnityWindowStyle::OnThemeChanged)); } void UnityWindowStyle::LoadAllTextureInScale(double scale) { auto& window_textures = unity_window_textures_[scale]; - window_textures[unsigned(WindowTextureType::BACKGROUND_TOP)] = LoadTexture(scale, SWITCHER_TOP); - window_textures[unsigned(WindowTextureType::BACKGROUND_LEFT)] = LoadTexture(scale, SWITCHER_LEFT); - window_textures[unsigned(WindowTextureType::BACKGROUND_CORNER)] = LoadTexture(scale, SWITCHER_CORNER); + window_textures[unsigned(WindowTextureType::BORDER_TOP)] = LoadTexture(DIALOG_BORDER_TOP, scale); + window_textures[unsigned(WindowTextureType::BORDER_LEFT)] = LoadTexture(DIALOG_BORDER_LEFT, scale); + window_textures[unsigned(WindowTextureType::BORDER_CORNER)] = LoadTexture(DIALOG_BORDER_CORNER, scale); - window_textures[unsigned(WindowTextureType::CLOSE_ICON)] = LoadTexture(scale, DIALOG_CLOSE); - window_textures[unsigned(WindowTextureType::CLOSE_ICON_HIGHLIGHTED)] = LoadTexture(scale, DIALOG_HIGHLIGHT); - window_textures[unsigned(WindowTextureType::CLOSE_ICON_PRESSED)] = LoadTexture(scale, DIALOG_PRESS); + window_textures[unsigned(WindowTextureType::CLOSE_ICON)] = LoadTexture(DIALOG_CLOSE, scale); + window_textures[unsigned(WindowTextureType::CLOSE_ICON_HIGHLIGHTED)] = LoadTexture(DIALOG_HIGHLIGHT, scale); + window_textures[unsigned(WindowTextureType::CLOSE_ICON_PRESSED)] = LoadTexture(DIALOG_PRESS, scale); } -nux::BaseTexture* UnityWindowStyle::LoadTexture(double scale, const char* const texture_name) const +nux::BaseTexture* UnityWindowStyle::LoadTexture(std::string const& texture_name, double scale) const { - RawPixel max_size = GetDefaultMaxTextureSize(texture_name); - return nux::CreateTexture2DFromFile(texture_name, max_size.CP(scale), true); + auto const& texture_path = theme::Settings::Get()->ThemedFilePath(texture_name, {PKGDATADIR}); + RawPixel max_size = GetDefaultMaxTextureSize(texture_path); + return nux::CreateTexture2DFromFile(texture_path.c_str(), max_size.CP(scale), true); } -RawPixel UnityWindowStyle::GetDefaultMaxTextureSize(const char* const texture_name) const +RawPixel UnityWindowStyle::GetDefaultMaxTextureSize(std::string const& texture_path) const { nux::Size size; - gdk_pixbuf_get_file_info(texture_name, &size.width, &size.height); + gdk_pixbuf_get_file_info(texture_path.c_str(), &size.width, &size.height); RawPixel max_size = std::max(std::round(size.width), std::round(size.height)); return max_size; @@ -102,6 +105,11 @@ void UnityWindowStyle::OnMonitorChanged(int primary, std::vector<nux::Geometry> CleanUpUnusedTextures(); } +void UnityWindowStyle::OnThemeChanged(std::string const&) +{ + unity_window_textures_.clear(); +} + // Get current in use scale values, if a scaled value is allocated, but // not in use clean up the scaled textures in unity_window_textures void UnityWindowStyle::CleanUpUnusedTextures() @@ -133,19 +141,19 @@ UnityWindowStyle::Ptr const& UnityWindowStyle::Get() return instance; } -int UnityWindowStyle::GetBorderSize(double scale) const +RawPixel UnityWindowStyle::GetBorderSize() const { - return BORDER_SIZE.CP(scale); // as measured from textures + return BORDER_SIZE; } -int UnityWindowStyle::GetInternalOffset(double scale) const +RawPixel UnityWindowStyle::GetInternalOffset() const { - return INTERNAL_OFFSET.CP(scale); + return INTERNAL_OFFSET; } -int UnityWindowStyle::GetCloseButtonPadding(double scale) const +RawPixel UnityWindowStyle::GetCloseButtonPadding() const { - return CLOSE_PADDING.CP(scale); + return CLOSE_PADDING; } UnityWindowStyle::BaseTexturePtr UnityWindowStyle::GetTexture(double scale, WindowTextureType const& type) @@ -159,7 +167,7 @@ UnityWindowStyle::BaseTexturePtr UnityWindowStyle::GetTexture(double scale, Wind if (it == unity_window_textures_.end()) { LOG_ERROR(logger) << "Failed to create unity window style textures, for scale size: " << scale; - return BaseTexturePtr(nullptr); + return BaseTexturePtr(); } } diff --git a/unity-shared/UnityWindowStyle.h b/unity-shared/UnityWindowStyle.h index 99080a735..8471a0fd8 100644 --- a/unity-shared/UnityWindowStyle.h +++ b/unity-shared/UnityWindowStyle.h @@ -34,9 +34,9 @@ namespace ui enum class WindowTextureType : unsigned { - BACKGROUND_TOP, - BACKGROUND_LEFT, - BACKGROUND_CORNER, + BORDER_TOP, + BORDER_LEFT, + BORDER_CORNER, CLOSE_ICON, CLOSE_ICON_HIGHLIGHTED, CLOSE_ICON_PRESSED, @@ -52,19 +52,20 @@ public: static UnityWindowStyle::Ptr const& Get(); BaseTexturePtr GetTexture(double scale, WindowTextureType const& type); - int GetCloseButtonPadding(double scale) const; - int GetBorderSize(double scale) const; - int GetInternalOffset(double scale) const; + RawPixel GetCloseButtonPadding() const; + RawPixel GetBorderSize() const; + RawPixel GetInternalOffset() const; private: UnityWindowStyle(); void ReloadIcons(); void LoadAllTextureInScale(double scale); - nux::BaseTexture* LoadTexture(double scale, const char* const texture_name) const; - RawPixel GetDefaultMaxTextureSize(const char* const texture_name) const; - + nux::BaseTexture* LoadTexture(std::string const& texture_name, double scale) const; + RawPixel GetDefaultMaxTextureSize(std::string const& texture_path) const; + void OnMonitorChanged(int primary, std::vector<nux::Geometry> const& monitors); + void OnThemeChanged(std::string const&); void CleanUpUnusedTextures(); typedef std::array<BaseTexturePtr, size_t(WindowTextureType::Size)> UnityWindowTextures; diff --git a/unity-shared/UnityWindowView.cpp b/unity-shared/UnityWindowView.cpp index f751386f7..30bed3cee 100644 --- a/unity-shared/UnityWindowView.cpp +++ b/unity-shared/UnityWindowView.cpp @@ -70,7 +70,7 @@ void UnityWindowView::OnDPIChanged() if (internal_layout_) { - int offset = style()->GetInternalOffset(scale); + int offset = style()->GetInternalOffset().CP(scale); view_layout_->SetPadding(offset, offset); } } @@ -138,7 +138,7 @@ void UnityWindowView::OnClosableChanged(bool closable) } auto const& texture = style()->GetTexture(scale, WindowTextureType::CLOSE_ICON); - int padding = style()->GetCloseButtonPadding(scale); + int padding = style()->GetCloseButtonPadding().CP(scale); close_button_ = new IconTexture(texture); close_button_->SetBaseXY(padding, padding); @@ -179,7 +179,7 @@ bool UnityWindowView::SetLayout(nux::Layout* layout) { if (layout && layout->IsLayout()) { - int offset = style()->GetInternalOffset(scale); + int offset = style()->GetInternalOffset().CP(scale); // We wrap the internal layout adding some padding, so that inherited classes // can ignore the offsets we define here. @@ -204,7 +204,7 @@ nux::Layout* UnityWindowView::GetLayout() nux::Geometry UnityWindowView::GetInternalBackground() { - int offset = style()->GetInternalOffset(scale); + int offset = style()->GetInternalOffset().CP(scale); return GetBackgroundGeometry().GetExpand(-offset, -offset); } @@ -355,9 +355,8 @@ void UnityWindowView::Draw(nux::GraphicsEngine& GfxContext, bool force_draw) void UnityWindowView::DrawBackground(nux::GraphicsEngine& GfxContext, nux::Geometry const& geo) { - int border = style()->GetBorderSize(scale); - - auto background_corner_textrue = style()->GetTexture(scale, WindowTextureType::BACKGROUND_CORNER)->GetDeviceTexture(); + int border = style()->GetBorderSize().CP(scale); + auto background_corner_textrue = style()->GetTexture(scale, WindowTextureType::BORDER_CORNER)->GetDeviceTexture(); GfxContext.GetRenderStates().SetBlend(true, GL_ONE, GL_ONE_MINUS_SRC_ALPHA); @@ -403,7 +402,7 @@ void UnityWindowView::DrawBackground(nux::GraphicsEngine& GfxContext, nux::Geome GfxContext.QRP_1Tex (geo.x + geo.width - border, geo.y + geo.height - border, border, border, background_corner_textrue, texxform, nux::color::White); - auto background_top = style()->GetTexture(scale, WindowTextureType::BACKGROUND_TOP); + auto background_top = style()->GetTexture(scale, WindowTextureType::BORDER_TOP); int top_width = background_top->GetWidth(); int top_height = background_top->GetHeight(); @@ -425,7 +424,7 @@ void UnityWindowView::DrawBackground(nux::GraphicsEngine& GfxContext, nux::Geome texxform.flip_v_coord = true; GfxContext.QRP_1Tex (geo.x + border, geo.y + geo.height - border, geo.width - border - border, border, background_top->GetDeviceTexture(), texxform, nux::color::White); - auto background_left = style()->GetTexture(scale, WindowTextureType::BACKGROUND_LEFT); + auto background_left = style()->GetTexture(scale, WindowTextureType::BORDER_LEFT); int left_width = background_left->GetWidth(); int left_height = background_left->GetHeight(); |
