From 346a6598a62350c5d234e3177de9e6c6c1963475 Mon Sep 17 00:00:00 2001 From: rathnor Date: Thu, 26 Aug 2004 15:09:33 +0000 Subject: make arrow button's arrow size scalable by the user --- ChangeLog | 12 ++++++++++-- src/ArrowButton.cc | 33 +++++++++++++++++++++++++-------- src/ArrowButton.hh | 5 ++++- src/ButtonTheme.cc | 3 ++- src/ButtonTheme.hh | 2 ++ src/ButtonTool.cc | 3 ++- src/FbTk/Button.hh | 7 ++++++- 7 files changed, 51 insertions(+), 14 deletions(-) diff --git a/ChangeLog b/ChangeLog index 8f91e86..117e7b2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,8 +1,16 @@ (Format: Year/Month/Day) Changes for 0.9.10: *04/08/26: - * Fixed 2 possible Memleaks (Mathias) - Ewmh.cc + * Make arrow in toolbar buttons scalable size (Simon) + - new theme item: toolbar.button.scale: + The number is a scale factor, which is divided into 100 to give + the size relative to the button. 100 gives a arrow the same size + as button, 200 gives half the size, 300 a third, etc. + - default is now 300, not 200 + - also fix size balance with left/right arrows + ArrowButton.hh/cc ButtonTheme.hh/cc ButtonTool.cc FbTk/Button.hh + * Fixed 2 possible Memleaks (Mathias) + Ewmh.cc * Re-implement bevels in toolbar, plus numerous toolbar-related theme fixes => old styles now look like they used to! (Simon) Toolbar.cc ToolbarItem.h ToolTheme.cc ToolbarTheme.cc ToolFactory.cc diff --git a/src/ArrowButton.cc b/src/ArrowButton.cc index c62df2a..724562f 100644 --- a/src/ArrowButton.cc +++ b/src/ArrowButton.cc @@ -19,9 +19,10 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -// $Id: ArrowButton.cc,v 1.7 2004/08/25 17:16:40 rathnor Exp $ +// $Id: ArrowButton.cc,v 1.8 2004/08/26 15:09:33 rathnor Exp $ #include "ArrowButton.hh" +#include "ButtonTheme.hh" ArrowButton::ArrowButton(ArrowButton::Type arrow_type, const FbTk::FbWindow &parent, @@ -29,7 +30,8 @@ ArrowButton::ArrowButton(ArrowButton::Type arrow_type, unsigned int width, unsigned int height): FbTk::Button(parent, x, y, width, height), m_arrow_type(arrow_type), - m_mouse_handler(0) { + m_mouse_handler(0), + m_arrowscale(300) { setEventMask(ExposureMask | ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask); @@ -41,7 +43,8 @@ ArrowButton::ArrowButton(ArrowButton::Type arrow_type, unsigned int width, unsigned int height): FbTk::Button(screen_num, x, y, width, height), m_arrow_type(arrow_type), - m_mouse_handler(0) { + m_mouse_handler(0), + m_arrowscale(300) { setEventMask(ExposureMask | ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask); @@ -84,15 +87,20 @@ void ArrowButton::drawArrow() { XPoint pts[3]; unsigned int w = width(); unsigned int h = height(); - // arrow size: half of the button - unsigned int ax = w / 2; - unsigned int ay = h / 2; + + int arrowscale_n = m_arrowscale; + int arrowscale_d = 100; + unsigned int ax = arrowscale_d * w / arrowscale_n; + unsigned int ay = arrowscale_d * h / arrowscale_n; + // if these aren't an even number, left and right arrows end up different + if (( ax % 2 ) == 1) ax++; + if (( ay % 2 ) == 1) ay++; switch (m_arrow_type) { case LEFT: // start at the tip pts[0].x = (w / 2) - (ax / 2); pts[0].y = h / 2; - pts[1].x = ax; pts[1].y = ay / 2; - pts[2].x = 0; pts[2].y = - ay; + pts[1].x = ax; pts[1].y = -ay / 2; + pts[2].x = 0; pts[2].y = ay; break; case RIGHT: pts[0].x = (w / 2) + (ax / 2); pts[0].y = h / 2; @@ -118,3 +126,12 @@ void ArrowButton::drawArrow() { } } +void ArrowButton::updateTheme(const FbTk::Theme &theme) { + // it must be a button theme + const ButtonTheme &btheme = static_cast(theme); + + m_arrowscale = btheme.scale(); + if (m_arrowscale == 0) m_arrowscale = 300; // default is 0 => 300 + else if (m_arrowscale < 100) m_arrowscale = 100; // otherwise clamp + else if (m_arrowscale > 100000) m_arrowscale = 100000; // clamp below overflow when *100 +} diff --git a/src/ArrowButton.hh b/src/ArrowButton.hh index 6a74a30..ccd0346 100644 --- a/src/ArrowButton.hh +++ b/src/ArrowButton.hh @@ -19,7 +19,7 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -// $Id: ArrowButton.hh,v 1.4 2003/10/13 23:51:04 fluxgen Exp $ +// $Id: ArrowButton.hh,v 1.5 2004/08/26 15:09:33 rathnor Exp $ #ifndef ARROWBUTTON_HH #define ARROWBUTTON_HH @@ -45,10 +45,13 @@ public: void leaveNotifyEvent(XCrossingEvent &ce); void setMouseMotionHandler(FbTk::EventHandler *eh) { m_mouse_handler = eh; } + + void updateTheme(const FbTk::Theme &theme); private: void drawArrow(); Type m_arrow_type; FbTk::EventHandler *m_mouse_handler; + int m_arrowscale; }; #endif // ARROWBUTTON_HH diff --git a/src/ButtonTheme.cc b/src/ButtonTheme.cc index 663da77..abd8c24 100644 --- a/src/ButtonTheme.cc +++ b/src/ButtonTheme.cc @@ -8,7 +8,8 @@ ButtonTheme::ButtonTheme(int screen_num, ToolTheme(screen_num, name, alt_name), m_pic_color(*this, name + ".picColor", alt_name + ".PicColor"), m_pressed_texture(*this, name + ".pressed", alt_name + ".Pressed"), - m_gc(RootWindow(FbTk::App::instance()->display(), screen_num)) { + m_gc(RootWindow(FbTk::App::instance()->display(), screen_num)), + m_scale(*this, name + ".scale", alt_name + ".Scale") { } diff --git a/src/ButtonTheme.hh b/src/ButtonTheme.hh index 2636960..0df252c 100644 --- a/src/ButtonTheme.hh +++ b/src/ButtonTheme.hh @@ -16,10 +16,12 @@ public: inline const FbTk::Texture &pressed() const { return *m_pressed_texture; } inline GC gc() const { return m_gc.gc(); } + inline int scale() const { return *m_scale; } // scale factor for inside objects private: FbTk::ThemeItem m_pic_color; FbTk::ThemeItem m_pressed_texture; FbTk::GContext m_gc; + FbTk::ThemeItem m_scale; }; #endif // BUTTONTHEME_HH diff --git a/src/ButtonTool.cc b/src/ButtonTool.cc index a3b4d7b..78edbe7 100644 --- a/src/ButtonTool.cc +++ b/src/ButtonTool.cc @@ -19,7 +19,7 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -// $Id: ButtonTool.cc,v 1.3 2004/01/13 14:41:32 rathnor Exp $ +// $Id: ButtonTool.cc,v 1.4 2004/08/26 15:09:33 rathnor Exp $ #include "ButtonTool.hh" @@ -55,6 +55,7 @@ void ButtonTool::renderTheme() { btn.setBorderColor(theme().border().color()); btn.setBorderWidth(theme().border().width()); btn.setAlpha(theme().alpha()); + btn.updateTheme(static_cast(theme())); Pixmap old_pm = m_cache_pm; if (!theme().texture().usePixmap()) { diff --git a/src/FbTk/Button.hh b/src/FbTk/Button.hh index 9df0bcd..791de24 100644 --- a/src/FbTk/Button.hh +++ b/src/FbTk/Button.hh @@ -19,7 +19,7 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -// $Id: Button.hh,v 1.8 2003/12/16 17:06:49 fluxgen Exp $ +// $Id: Button.hh,v 1.9 2004/08/26 15:09:33 rathnor Exp $ #ifndef FBTK_BUTTON_HH #define FBTK_BUTTON_HH @@ -36,6 +36,8 @@ namespace FbTk { +class Theme; + class Button:public FbTk::FbWindow, public EventHandler, private NotCopyable { public: @@ -67,6 +69,9 @@ public: virtual void exposeEvent(XExposeEvent &event); //@} + // in case it cares about a theme + virtual void updateTheme(const FbTk::Theme &theme) {} + /// @return true if the button is pressed, else false bool pressed() const { return m_pressed; } -- cgit v0.11.2