From ec5c2b77a11e2762921ff4736539d4f5239b5866 Mon Sep 17 00:00:00 2001
From: fluxgen <fluxgen>
Date: Fri, 22 Aug 2003 14:48:10 +0000
Subject: fixed scaling for winbuttons

---
 src/WinButtonTheme.cc | 46 +++++++++++++++++++++++++++++++++++++++-------
 src/WinButtonTheme.hh | 20 +++++++++++++-------
 2 files changed, 52 insertions(+), 14 deletions(-)

diff --git a/src/WinButtonTheme.cc b/src/WinButtonTheme.cc
index d90d4c8..38d2de5 100644
--- a/src/WinButtonTheme.cc
+++ b/src/WinButtonTheme.cc
@@ -19,11 +19,12 @@
 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 // DEALINGS IN THE SOFTWARE.
 
-// $Id: WinButtonTheme.cc,v 1.3 2003/05/06 23:56:46 fluxgen Exp $
+// $Id: WinButtonTheme.cc,v 1.4 2003/08/22 14:48:10 fluxgen Exp $
 
 #include "WinButtonTheme.hh"
 
-#include "App.hh"
+#include "FbTk/App.hh"
+#include "FbWinFrameTheme.hh"
 
 #ifdef HAVE_CONFIG_H
 #include "config.h"
@@ -44,8 +45,6 @@ setDefaultValue() {
     // create empty pixmap
     (*this)->pixmap = FbTk::FbPixmap(); // pixmap
     (*this)->mask = FbTk::FbPixmap(); // mask
-    (*this)->pixmap_scaled = FbTk::FbPixmap();
-    (*this)->mask_scaled = FbTk::FbPixmap();
 }
 
 template <>
@@ -77,7 +76,7 @@ setFromString(const char *str) {
     } 
 }
 
-WinButtonTheme::WinButtonTheme(int screen_num):
+WinButtonTheme::WinButtonTheme(int screen_num, const FbWinFrameTheme &frame_theme):
     FbTk::Theme(screen_num),
     m_close_pm(*this, "window.close.pixmap", "Window.Close.Pixmap"),
     m_close_unfocus_pm(*this, "window.close.unfocus.pixmap", "Window.Close.Unfocus.Pixmap"),
@@ -95,7 +94,8 @@ WinButtonTheme::WinButtonTheme(int screen_num):
     m_stick_unfocus_pm(*this, "window.stick.unfocus.pixmap", "Window.Stick.Unfocus.Pixmap"),
     m_stick_pressed_pm(*this, "window.stick.pressed.pixmap", "Window.Stick.Pressed.Pixmap"),
     m_stuck_pm(*this, "window.stuck.pixmap", "Window.Stuck.Pixmap"),
-    m_stuck_unfocus_pm(*this, "window.stuck.unfocus.pixmap", "Window.Stuck.Unfocus.Pixmap") {
+    m_stuck_unfocus_pm(*this, "window.stuck.unfocus.pixmap", "Window.Stuck.Unfocus.Pixmap"),
+    m_frame_theme(frame_theme) {
 
 }
 
@@ -104,6 +104,38 @@ WinButtonTheme::~WinButtonTheme() {
 }
 
 void WinButtonTheme::reconfigTheme() {
-    reconfigSig().notify();
+    // rescale the pixmaps to match frame theme height
+
+    unsigned int size = m_frame_theme.titleHeight();
+    if (m_frame_theme.titleHeight() == 0) {
+        // calculate height from font and border width to scale pixmaps
+        const int bevel = 1;
+        size = m_frame_theme.font().height() + bevel*2 + 2;
+
+    } // else  use specified height to scale pixmaps
+
+    // scale all pixmaps
+    m_close_pm->scale(size, size);
+    m_close_unfocus_pm->scale(size, size);
+    m_close_pressed_pm->scale(size, size);
+        
+    m_maximize_pm->scale(size, size);
+    m_maximize_unfocus_pm->scale(size, size);
+    m_maximize_pressed_pm->scale(size, size);
+
+    m_iconify_pm->scale(size, size);
+    m_iconify_unfocus_pm->scale(size, size);
+    m_iconify_pressed_pm->scale(size, size);
+
+    m_shade_pm->scale(size, size);
+    m_shade_unfocus_pm->scale(size, size);
+    m_shade_pressed_pm->scale(size, size);
+
+    m_stick_pm->scale(size, size);
+    m_stick_unfocus_pm->scale(size, size);
+    m_stick_pressed_pm->scale(size, size);
+
+    m_stuck_pm->scale(size, size);
+    m_stuck_unfocus_pm->scale(size, size);
 }
 
diff --git a/src/WinButtonTheme.hh b/src/WinButtonTheme.hh
index af2f011..dea88cf 100644
--- a/src/WinButtonTheme.hh
+++ b/src/WinButtonTheme.hh
@@ -19,25 +19,30 @@
 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 // DEALINGS IN THE SOFTWARE.
 
-// $Id: WinButtonTheme.hh,v 1.2 2003/05/06 23:52:55 fluxgen Exp $
+// $Id: WinButtonTheme.hh,v 1.3 2003/08/22 14:48:10 fluxgen Exp $
 
 #ifndef WINBUTTONTHEME_HH
 #define WINBUTTONTHEME_HH
 
 #include "Theme.hh"
-#include "Subject.hh"
 #include "FbPixmap.hh"
 
+class FbWinFrameTheme;
+
 class WinButtonTheme: public FbTk::Theme {
 public:
+    /// holds pixmap and a mask
     struct PixmapWithMask {
+        /// scale both pixmap and mask to specified size
+        void scale(unsigned int width, unsigned int height) {
+            pixmap.scale(width, height);
+            mask.scale(width, height);
+        }
         FbTk::FbPixmap pixmap;
-        FbTk::FbPixmap pixmap_scaled;
         FbTk::FbPixmap mask;
-        FbTk::FbPixmap mask_scaled;
     };
 
-    explicit WinButtonTheme(int screen_num);
+    WinButtonTheme(int screen_num, const FbWinFrameTheme &frame_theme);
     ~WinButtonTheme();
 
     void reconfigTheme();
@@ -74,9 +79,8 @@ public:
     inline PixmapWithMask &shadeUnfocusPixmap() { return *m_shade_unfocus_pm; }
     inline const PixmapWithMask &shadePressedPixmap() const { return *m_shade_pressed_pm; }
     inline PixmapWithMask &shadePressedPixmap() { return *m_shade_pressed_pm; }
-    FbTk::Subject &reconfigSig() { return m_reconf_sig; }
+
 private:
-    FbTk::Subject m_reconf_sig;
 
     FbTk::ThemeItem<PixmapWithMask> m_close_pm, m_close_unfocus_pm, m_close_pressed_pm;
     FbTk::ThemeItem<PixmapWithMask> m_maximize_pm, m_maximize_unfocus_pm, m_maximize_pressed_pm;
@@ -84,6 +88,8 @@ private:
     FbTk::ThemeItem<PixmapWithMask> m_shade_pm, m_shade_unfocus_pm, m_shade_pressed_pm;
     FbTk::ThemeItem<PixmapWithMask> m_stick_pm, m_stick_unfocus_pm, m_stick_pressed_pm;    
     FbTk::ThemeItem<PixmapWithMask> m_stuck_pm, m_stuck_unfocus_pm; 
+
+    const FbWinFrameTheme &m_frame_theme;
 };
 
 #endif // WINBUTTONTHEME_HH
-- 
cgit v0.11.2