aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorfluxgen <fluxgen>2003-10-13 23:38:17 (GMT)
committerfluxgen <fluxgen>2003-10-13 23:38:17 (GMT)
commitec1049e89458f67c040bff905e1df862ae1587d7 (patch)
tree10ee6485ed5a12acde1b9e13000569e757a2a9ad
parent53be8d6f67a70527990ed32efc22e8e7763af3fb (diff)
downloadfluxbox_pavel-ec1049e89458f67c040bff905e1df862ae1587d7.zip
fluxbox_pavel-ec1049e89458f67c040bff905e1df862ae1587d7.tar.bz2
helper tool class for button tools
-rw-r--r--src/ButtonTool.cc86
-rw-r--r--src/ButtonTool.hh49
2 files changed, 135 insertions, 0 deletions
diff --git a/src/ButtonTool.cc b/src/ButtonTool.cc
new file mode 100644
index 0000000..7f350f5
--- /dev/null
+++ b/src/ButtonTool.cc
@@ -0,0 +1,86 @@
1// ButtonTool.cc for Fluxbox
2// Copyright (c) 2003 Henrik Kinnunen (fluxgen at users.sourceforge.net)
3//
4// Permission is hereby granted, free of charge, to any person obtaining a
5// copy of this software and associated documentation files (the "Software"),
6// to deal in the Software without restriction, including without limitation
7// the rights to use, copy, modify, merge, publish, distribute, sublicense,
8// and/or sell copies of the Software, and to permit persons to whom the
9// Software is furnished to do so, subject to the following conditions:
10//
11// The above copyright notice and this permission notice shall be included in
12// all copies or substantial portions of the Software.
13//
14// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20// DEALINGS IN THE SOFTWARE.
21
22// $Id: ButtonTool.cc,v 1.1 2003/10/13 23:38:17 fluxgen Exp $
23
24#include "ButtonTool.hh"
25
26#include "FbTk/Button.hh"
27#include "FbTk/ImageControl.hh"
28#include "ButtonTheme.hh"
29
30ButtonTool::ButtonTool(FbTk::Button *button,
31 ToolbarItem::Type type,
32 ButtonTheme &theme,
33 FbTk::ImageControl &img_ctrl):
34 GenericTool(button, type, theme),
35 m_cache_pm(0),
36 m_cache_pressed_pm(0),
37 m_image_ctrl(img_ctrl) {
38
39 renderTheme();
40}
41
42ButtonTool::~ButtonTool() {
43 if (m_cache_pm)
44 m_image_ctrl.removeImage(m_cache_pm);
45
46 if (m_cache_pressed_pm)
47 m_image_ctrl.removeImage(m_cache_pressed_pm);
48
49}
50
51void ButtonTool::renderTheme() {
52 FbTk::Button &btn = static_cast<FbTk::Button &>(window());
53
54 btn.setGC(static_cast<const ButtonTheme &>(theme()).gc());
55 btn.setBorderColor(theme().border().color());
56 btn.setBorderWidth(theme().border().width());
57
58 Pixmap old_pm = m_cache_pm;
59 if (theme().texture().type() == (FbTk::Texture::FLAT | FbTk::Texture::SOLID)) {
60 m_cache_pm = 0;
61 btn.setBackgroundColor(theme().texture().color());
62 } else {
63 m_cache_pm = m_image_ctrl.renderImage(width(), height(),
64 theme().texture());
65 btn.setBackgroundPixmap(m_cache_pm);
66 }
67 if (old_pm)
68 m_image_ctrl.removeImage(old_pm);
69
70 old_pm = m_cache_pressed_pm;
71 if (static_cast<const ButtonTheme &>(theme()).pressed().type() ==
72 (FbTk::Texture::FLAT | FbTk::Texture::SOLID)) {
73 m_cache_pressed_pm = 0;
74 btn.setPressedColor(static_cast<const ButtonTheme &>(theme()).pressed().color());
75 } else {
76 m_cache_pressed_pm = m_image_ctrl.renderImage(width(), height(),
77 static_cast<const ButtonTheme &>(theme()).pressed());
78 btn.setPressedPixmap(m_cache_pressed_pm);
79 }
80
81 if (old_pm)
82 m_image_ctrl.removeImage(old_pm);
83
84 btn.clear();
85}
86
diff --git a/src/ButtonTool.hh b/src/ButtonTool.hh
new file mode 100644
index 0000000..b40c5a7
--- /dev/null
+++ b/src/ButtonTool.hh
@@ -0,0 +1,49 @@
1// ButtonTool.hh for Fluxbox
2// Copyright (c) 2003 Henrik Kinnunen (fluxgen at users.sourceforge.net)
3//
4// Permission is hereby granted, free of charge, to any person obtaining a
5// copy of this software and associated documentation files (the "Software"),
6// to deal in the Software without restriction, including without limitation
7// the rights to use, copy, modify, merge, publish, distribute, sublicense,
8// and/or sell copies of the Software, and to permit persons to whom the
9// Software is furnished to do so, subject to the following conditions:
10//
11// The above copyright notice and this permission notice shall be included in
12// all copies or substantial portions of the Software.
13//
14// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20// DEALINGS IN THE SOFTWARE.
21
22// $Id: ButtonTool.hh,v 1.1 2003/10/13 23:38:17 fluxgen Exp $
23
24#ifndef BUTTONTOOL_HH
25#define BUTTONTOOL_HH
26
27#include "GenericTool.hh"
28#include "FbTk/Observer.hh"
29
30class ButtonTheme;
31
32namespace FbTk {
33class Button;
34class ImageControl;
35};
36
37class ButtonTool: public GenericTool {
38public:
39 ButtonTool(FbTk::Button *button, ToolbarItem::Type type,
40 ButtonTheme &theme, FbTk::ImageControl &img_ctrl);
41 virtual ~ButtonTool();
42
43protected:
44 void renderTheme();
45 Pixmap m_cache_pm, m_cache_pressed_pm;
46 FbTk::ImageControl &m_image_ctrl;
47};
48
49#endif // BUTTONTOOL_HH