diff options
author | rathnor <rathnor> | 2004-08-26 15:09:33 (GMT) |
---|---|---|
committer | rathnor <rathnor> | 2004-08-26 15:09:33 (GMT) |
commit | 346a6598a62350c5d234e3177de9e6c6c1963475 (patch) | |
tree | 02706013944f306c549ca627144a13d6552cd098 | |
parent | 13bf2a7fddff4242581eec62243222acd49a1537 (diff) | |
download | fluxbox_lack-346a6598a62350c5d234e3177de9e6c6c1963475.zip fluxbox_lack-346a6598a62350c5d234e3177de9e6c6c1963475.tar.bz2 |
make arrow button's arrow size scalable by the user
-rw-r--r-- | ChangeLog | 12 | ||||
-rw-r--r-- | src/ArrowButton.cc | 33 | ||||
-rw-r--r-- | src/ArrowButton.hh | 5 | ||||
-rw-r--r-- | src/ButtonTheme.cc | 3 | ||||
-rw-r--r-- | src/ButtonTheme.hh | 2 | ||||
-rw-r--r-- | src/ButtonTool.cc | 3 | ||||
-rw-r--r-- | src/FbTk/Button.hh | 7 |
7 files changed, 51 insertions, 14 deletions
@@ -1,8 +1,16 @@ | |||
1 | (Format: Year/Month/Day) | 1 | (Format: Year/Month/Day) |
2 | Changes for 0.9.10: | 2 | Changes for 0.9.10: |
3 | *04/08/26: | 3 | *04/08/26: |
4 | * Fixed 2 possible Memleaks (Mathias) | 4 | * Make arrow in toolbar buttons scalable size (Simon) |
5 | Ewmh.cc | 5 | - new theme item: toolbar.button.scale: <number> |
6 | The number is a scale factor, which is divided into 100 to give | ||
7 | the size relative to the button. 100 gives a arrow the same size | ||
8 | as button, 200 gives half the size, 300 a third, etc. | ||
9 | - default is now 300, not 200 | ||
10 | - also fix size balance with left/right arrows | ||
11 | ArrowButton.hh/cc ButtonTheme.hh/cc ButtonTool.cc FbTk/Button.hh | ||
12 | * Fixed 2 possible Memleaks (Mathias) | ||
13 | Ewmh.cc | ||
6 | * Re-implement bevels in toolbar, plus numerous toolbar-related theme | 14 | * Re-implement bevels in toolbar, plus numerous toolbar-related theme |
7 | fixes => old styles now look like they used to! (Simon) | 15 | fixes => old styles now look like they used to! (Simon) |
8 | Toolbar.cc ToolbarItem.h ToolTheme.cc ToolbarTheme.cc ToolFactory.cc | 16 | 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 @@ | |||
19 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | 19 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
20 | // DEALINGS IN THE SOFTWARE. | 20 | // DEALINGS IN THE SOFTWARE. |
21 | 21 | ||
22 | // $Id: ArrowButton.cc,v 1.7 2004/08/25 17:16:40 rathnor Exp $ | 22 | // $Id: ArrowButton.cc,v 1.8 2004/08/26 15:09:33 rathnor Exp $ |
23 | 23 | ||
24 | #include "ArrowButton.hh" | 24 | #include "ArrowButton.hh" |
25 | #include "ButtonTheme.hh" | ||
25 | 26 | ||
26 | ArrowButton::ArrowButton(ArrowButton::Type arrow_type, | 27 | ArrowButton::ArrowButton(ArrowButton::Type arrow_type, |
27 | const FbTk::FbWindow &parent, | 28 | const FbTk::FbWindow &parent, |
@@ -29,7 +30,8 @@ ArrowButton::ArrowButton(ArrowButton::Type arrow_type, | |||
29 | unsigned int width, unsigned int height): | 30 | unsigned int width, unsigned int height): |
30 | FbTk::Button(parent, x, y, width, height), | 31 | FbTk::Button(parent, x, y, width, height), |
31 | m_arrow_type(arrow_type), | 32 | m_arrow_type(arrow_type), |
32 | m_mouse_handler(0) { | 33 | m_mouse_handler(0), |
34 | m_arrowscale(300) { | ||
33 | 35 | ||
34 | setEventMask(ExposureMask | ButtonPressMask | ButtonReleaseMask | | 36 | setEventMask(ExposureMask | ButtonPressMask | ButtonReleaseMask | |
35 | EnterWindowMask | LeaveWindowMask); | 37 | EnterWindowMask | LeaveWindowMask); |
@@ -41,7 +43,8 @@ ArrowButton::ArrowButton(ArrowButton::Type arrow_type, | |||
41 | unsigned int width, unsigned int height): | 43 | unsigned int width, unsigned int height): |
42 | FbTk::Button(screen_num, x, y, width, height), | 44 | FbTk::Button(screen_num, x, y, width, height), |
43 | m_arrow_type(arrow_type), | 45 | m_arrow_type(arrow_type), |
44 | m_mouse_handler(0) { | 46 | m_mouse_handler(0), |
47 | m_arrowscale(300) { | ||
45 | 48 | ||
46 | setEventMask(ExposureMask | ButtonPressMask | ButtonReleaseMask | | 49 | setEventMask(ExposureMask | ButtonPressMask | ButtonReleaseMask | |
47 | EnterWindowMask | LeaveWindowMask); | 50 | EnterWindowMask | LeaveWindowMask); |
@@ -84,15 +87,20 @@ void ArrowButton::drawArrow() { | |||
84 | XPoint pts[3]; | 87 | XPoint pts[3]; |
85 | unsigned int w = width(); | 88 | unsigned int w = width(); |
86 | unsigned int h = height(); | 89 | unsigned int h = height(); |
87 | // arrow size: half of the button | 90 | |
88 | unsigned int ax = w / 2; | 91 | int arrowscale_n = m_arrowscale; |
89 | unsigned int ay = h / 2; | 92 | int arrowscale_d = 100; |
93 | unsigned int ax = arrowscale_d * w / arrowscale_n; | ||
94 | unsigned int ay = arrowscale_d * h / arrowscale_n; | ||
95 | // if these aren't an even number, left and right arrows end up different | ||
96 | if (( ax % 2 ) == 1) ax++; | ||
97 | if (( ay % 2 ) == 1) ay++; | ||
90 | switch (m_arrow_type) { | 98 | switch (m_arrow_type) { |
91 | case LEFT: | 99 | case LEFT: |
92 | // start at the tip | 100 | // start at the tip |
93 | pts[0].x = (w / 2) - (ax / 2); pts[0].y = h / 2; | 101 | pts[0].x = (w / 2) - (ax / 2); pts[0].y = h / 2; |
94 | pts[1].x = ax; pts[1].y = ay / 2; | 102 | pts[1].x = ax; pts[1].y = -ay / 2; |
95 | pts[2].x = 0; pts[2].y = - ay; | 103 | pts[2].x = 0; pts[2].y = ay; |
96 | break; | 104 | break; |
97 | case RIGHT: | 105 | case RIGHT: |
98 | pts[0].x = (w / 2) + (ax / 2); pts[0].y = h / 2; | 106 | pts[0].x = (w / 2) + (ax / 2); pts[0].y = h / 2; |
@@ -118,3 +126,12 @@ void ArrowButton::drawArrow() { | |||
118 | } | 126 | } |
119 | } | 127 | } |
120 | 128 | ||
129 | void ArrowButton::updateTheme(const FbTk::Theme &theme) { | ||
130 | // it must be a button theme | ||
131 | const ButtonTheme &btheme = static_cast<const ButtonTheme &>(theme); | ||
132 | |||
133 | m_arrowscale = btheme.scale(); | ||
134 | if (m_arrowscale == 0) m_arrowscale = 300; // default is 0 => 300 | ||
135 | else if (m_arrowscale < 100) m_arrowscale = 100; // otherwise clamp | ||
136 | else if (m_arrowscale > 100000) m_arrowscale = 100000; // clamp below overflow when *100 | ||
137 | } | ||
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 @@ | |||
19 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | 19 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
20 | // DEALINGS IN THE SOFTWARE. | 20 | // DEALINGS IN THE SOFTWARE. |
21 | 21 | ||
22 | // $Id: ArrowButton.hh,v 1.4 2003/10/13 23:51:04 fluxgen Exp $ | 22 | // $Id: ArrowButton.hh,v 1.5 2004/08/26 15:09:33 rathnor Exp $ |
23 | 23 | ||
24 | #ifndef ARROWBUTTON_HH | 24 | #ifndef ARROWBUTTON_HH |
25 | #define ARROWBUTTON_HH | 25 | #define ARROWBUTTON_HH |
@@ -45,10 +45,13 @@ public: | |||
45 | void leaveNotifyEvent(XCrossingEvent &ce); | 45 | void leaveNotifyEvent(XCrossingEvent &ce); |
46 | 46 | ||
47 | void setMouseMotionHandler(FbTk::EventHandler *eh) { m_mouse_handler = eh; } | 47 | void setMouseMotionHandler(FbTk::EventHandler *eh) { m_mouse_handler = eh; } |
48 | |||
49 | void updateTheme(const FbTk::Theme &theme); | ||
48 | private: | 50 | private: |
49 | void drawArrow(); | 51 | void drawArrow(); |
50 | Type m_arrow_type; | 52 | Type m_arrow_type; |
51 | FbTk::EventHandler *m_mouse_handler; | 53 | FbTk::EventHandler *m_mouse_handler; |
54 | int m_arrowscale; | ||
52 | }; | 55 | }; |
53 | 56 | ||
54 | #endif // ARROWBUTTON_HH | 57 | #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, | |||
8 | ToolTheme(screen_num, name, alt_name), | 8 | ToolTheme(screen_num, name, alt_name), |
9 | m_pic_color(*this, name + ".picColor", alt_name + ".PicColor"), | 9 | m_pic_color(*this, name + ".picColor", alt_name + ".PicColor"), |
10 | m_pressed_texture(*this, name + ".pressed", alt_name + ".Pressed"), | 10 | m_pressed_texture(*this, name + ".pressed", alt_name + ".Pressed"), |
11 | m_gc(RootWindow(FbTk::App::instance()->display(), screen_num)) { | 11 | m_gc(RootWindow(FbTk::App::instance()->display(), screen_num)), |
12 | m_scale(*this, name + ".scale", alt_name + ".Scale") { | ||
12 | 13 | ||
13 | } | 14 | } |
14 | 15 | ||
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: | |||
16 | 16 | ||
17 | inline const FbTk::Texture &pressed() const { return *m_pressed_texture; } | 17 | inline const FbTk::Texture &pressed() const { return *m_pressed_texture; } |
18 | inline GC gc() const { return m_gc.gc(); } | 18 | inline GC gc() const { return m_gc.gc(); } |
19 | inline int scale() const { return *m_scale; } // scale factor for inside objects | ||
19 | private: | 20 | private: |
20 | FbTk::ThemeItem<FbTk::Color> m_pic_color; | 21 | FbTk::ThemeItem<FbTk::Color> m_pic_color; |
21 | FbTk::ThemeItem<FbTk::Texture> m_pressed_texture; | 22 | FbTk::ThemeItem<FbTk::Texture> m_pressed_texture; |
22 | FbTk::GContext m_gc; | 23 | FbTk::GContext m_gc; |
24 | FbTk::ThemeItem<int> m_scale; | ||
23 | }; | 25 | }; |
24 | 26 | ||
25 | #endif // BUTTONTHEME_HH | 27 | #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 @@ | |||
19 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | 19 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
20 | // DEALINGS IN THE SOFTWARE. | 20 | // DEALINGS IN THE SOFTWARE. |
21 | 21 | ||
22 | // $Id: ButtonTool.cc,v 1.3 2004/01/13 14:41:32 rathnor Exp $ | 22 | // $Id: ButtonTool.cc,v 1.4 2004/08/26 15:09:33 rathnor Exp $ |
23 | 23 | ||
24 | #include "ButtonTool.hh" | 24 | #include "ButtonTool.hh" |
25 | 25 | ||
@@ -55,6 +55,7 @@ void ButtonTool::renderTheme() { | |||
55 | btn.setBorderColor(theme().border().color()); | 55 | btn.setBorderColor(theme().border().color()); |
56 | btn.setBorderWidth(theme().border().width()); | 56 | btn.setBorderWidth(theme().border().width()); |
57 | btn.setAlpha(theme().alpha()); | 57 | btn.setAlpha(theme().alpha()); |
58 | btn.updateTheme(static_cast<const FbTk::Theme &>(theme())); | ||
58 | 59 | ||
59 | Pixmap old_pm = m_cache_pm; | 60 | Pixmap old_pm = m_cache_pm; |
60 | if (!theme().texture().usePixmap()) { | 61 | 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 @@ | |||
19 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | 19 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
20 | // DEALINGS IN THE SOFTWARE. | 20 | // DEALINGS IN THE SOFTWARE. |
21 | 21 | ||
22 | // $Id: Button.hh,v 1.8 2003/12/16 17:06:49 fluxgen Exp $ | 22 | // $Id: Button.hh,v 1.9 2004/08/26 15:09:33 rathnor Exp $ |
23 | 23 | ||
24 | #ifndef FBTK_BUTTON_HH | 24 | #ifndef FBTK_BUTTON_HH |
25 | #define FBTK_BUTTON_HH | 25 | #define FBTK_BUTTON_HH |
@@ -36,6 +36,8 @@ | |||
36 | 36 | ||
37 | namespace FbTk { | 37 | namespace FbTk { |
38 | 38 | ||
39 | class Theme; | ||
40 | |||
39 | class Button:public FbTk::FbWindow, public EventHandler, | 41 | class Button:public FbTk::FbWindow, public EventHandler, |
40 | private NotCopyable { | 42 | private NotCopyable { |
41 | public: | 43 | public: |
@@ -67,6 +69,9 @@ public: | |||
67 | virtual void exposeEvent(XExposeEvent &event); | 69 | virtual void exposeEvent(XExposeEvent &event); |
68 | //@} | 70 | //@} |
69 | 71 | ||
72 | // in case it cares about a theme | ||
73 | virtual void updateTheme(const FbTk::Theme &theme) {} | ||
74 | |||
70 | /// @return true if the button is pressed, else false | 75 | /// @return true if the button is pressed, else false |
71 | bool pressed() const { return m_pressed; } | 76 | bool pressed() const { return m_pressed; } |
72 | 77 | ||