diff options
-rw-r--r-- | src/FbTk/MenuTheme.cc | 135 | ||||
-rw-r--r-- | src/FbTk/MenuTheme.hh | 97 |
2 files changed, 232 insertions, 0 deletions
diff --git a/src/FbTk/MenuTheme.cc b/src/FbTk/MenuTheme.cc new file mode 100644 index 0000000..1b7a187 --- /dev/null +++ b/src/FbTk/MenuTheme.cc | |||
@@ -0,0 +1,135 @@ | |||
1 | // MenuTheme.cc for FbTk | ||
2 | // Copyright (c) 2002 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: MenuTheme.cc,v 1.1 2002/12/25 11:42:05 fluxgen Exp $ | ||
23 | |||
24 | #include "MenuTheme.hh" | ||
25 | |||
26 | #include "Color.hh" | ||
27 | #include "Texture.hh" | ||
28 | #include "Font.hh" | ||
29 | #include "App.hh" | ||
30 | //TODO change this | ||
31 | #include "../StringUtil.hh" | ||
32 | |||
33 | namespace FbTk { | ||
34 | |||
35 | MenuTheme::MenuTheme(int screen_num): | ||
36 | FbTk::Theme(screen_num), | ||
37 | t_text(*this, "menu.title.textColor", "Menu.Title.TextColor"), | ||
38 | f_text(*this, "menu.frame.textColor", "Menu.Frame.TextColor"), | ||
39 | h_text(*this, "menu.hilite.textColor", "Menu.Hilite.TextColor"), | ||
40 | d_text(*this, "menu.frame.disableColor", "Menu.Frame.DisableColor"), | ||
41 | title(*this, "menu.title", "Menu.Title"), | ||
42 | frame(*this, "menu.frame", "Menu.Frame"), | ||
43 | hilite(*this, "menu.hilite", "Menu.Hilite"), | ||
44 | titlefont(*this, "menu.title.font", "Menu.Title.Font"), | ||
45 | framefont(*this, "menu.frame.font", "Menu.Frame.Font"), | ||
46 | framefont_justify(*this, "menu.frame.justify", "Menu.Frame.Justify"), | ||
47 | titlefont_justify(*this, "menu.title.justify", "Menu.Title.Justify"), | ||
48 | bullet_pos(*this, "menu.bulletPos", "Menu.BulletPos"), | ||
49 | m_bullet(*this, "menu.bullet", "Menu.Bullet"), | ||
50 | m_display(FbTk::App::instance()->display()) { | ||
51 | |||
52 | Window rootwindow = RootWindow(m_display, screen_num); | ||
53 | |||
54 | XGCValues gcv; | ||
55 | unsigned long gc_value_mask = GCForeground; | ||
56 | gcv.foreground = t_text->pixel(); | ||
57 | |||
58 | t_text_gc = XCreateGC(m_display, rootwindow, gc_value_mask, &gcv); | ||
59 | |||
60 | gcv.foreground = f_text->pixel(); | ||
61 | |||
62 | f_text_gc = XCreateGC(m_display, rootwindow, gc_value_mask, &gcv); | ||
63 | |||
64 | gcv.foreground = h_text->pixel(); | ||
65 | h_text_gc = XCreateGC(m_display, rootwindow, gc_value_mask, &gcv); | ||
66 | |||
67 | gcv.foreground = d_text->pixel(); | ||
68 | d_text_gc = XCreateGC(m_display, rootwindow, gc_value_mask, &gcv); | ||
69 | |||
70 | gcv.foreground = hilite->color().pixel(); | ||
71 | hilite_gc = XCreateGC(m_display, rootwindow, gc_value_mask, &gcv); | ||
72 | } | ||
73 | |||
74 | MenuTheme::~MenuTheme() { | ||
75 | XFreeGC(m_display, t_text_gc); | ||
76 | XFreeGC(m_display, f_text_gc); | ||
77 | XFreeGC(m_display, h_text_gc); | ||
78 | XFreeGC(m_display, d_text_gc); | ||
79 | XFreeGC(m_display, hilite_gc); | ||
80 | } | ||
81 | |||
82 | void MenuTheme::reconfigTheme() { | ||
83 | |||
84 | XGCValues gcv; | ||
85 | unsigned long gc_value_mask = GCForeground; | ||
86 | |||
87 | gcv.foreground = t_text->pixel(); | ||
88 | |||
89 | XChangeGC(m_display, t_text_gc, | ||
90 | gc_value_mask, &gcv); | ||
91 | |||
92 | gcv.foreground = f_text->pixel(); | ||
93 | |||
94 | XChangeGC(m_display, f_text_gc, | ||
95 | gc_value_mask, &gcv); | ||
96 | |||
97 | gcv.foreground = h_text->pixel(); | ||
98 | XChangeGC(m_display, h_text_gc, | ||
99 | gc_value_mask, &gcv); | ||
100 | |||
101 | gcv.foreground = d_text->pixel(); | ||
102 | XChangeGC(m_display, d_text_gc, | ||
103 | gc_value_mask, &gcv); | ||
104 | |||
105 | gcv.foreground = hilite->color().pixel(); | ||
106 | XChangeGC(m_display, hilite_gc, | ||
107 | gc_value_mask, &gcv); | ||
108 | |||
109 | } | ||
110 | |||
111 | |||
112 | template <> | ||
113 | void ThemeItem<MenuTheme::BulletType>::setDefaultValue() { | ||
114 | m_value = MenuTheme::EMPTY; | ||
115 | } | ||
116 | |||
117 | template <> | ||
118 | void ThemeItem<MenuTheme::BulletType>::setFromString(const char *str) { | ||
119 | // do nothing | ||
120 | if (StringUtil::strcasestr(str, "EMPTY") == 0) | ||
121 | m_value = MenuTheme::EMPTY; | ||
122 | else if (StringUtil::strcasestr(str, "SQUARE") == 0) | ||
123 | m_value = MenuTheme::SQUARE; | ||
124 | else if (StringUtil::strcasestr(str, "TRIANGLE") == 0) | ||
125 | m_value = MenuTheme::TRIANGLE; | ||
126 | else | ||
127 | setDefaultValue(); | ||
128 | } | ||
129 | |||
130 | template <> | ||
131 | void ThemeItem<MenuTheme::BulletType>::load() { | ||
132 | // do nothing, we don't have anything extra to load | ||
133 | } | ||
134 | |||
135 | }; // end namespace FbTk | ||
diff --git a/src/FbTk/MenuTheme.hh b/src/FbTk/MenuTheme.hh new file mode 100644 index 0000000..c0ac490 --- /dev/null +++ b/src/FbTk/MenuTheme.hh | |||
@@ -0,0 +1,97 @@ | |||
1 | // MenuTheme.hh for FbTk | ||
2 | // Copyright (c) 2002 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: MenuTheme.hh,v 1.1 2002/12/25 11:41:53 fluxgen Exp $ | ||
23 | |||
24 | #ifndef FBTK_MENUTHEME_HH | ||
25 | #define FBTK_MENUTHEME_HH | ||
26 | |||
27 | #include "Theme.hh" | ||
28 | #include "Color.hh" | ||
29 | #include "Font.hh" | ||
30 | #include "Texture.hh" | ||
31 | #include "Text.hh" | ||
32 | |||
33 | namespace FbTk { | ||
34 | |||
35 | class MenuTheme:public FbTk::Theme { | ||
36 | public: | ||
37 | enum BulletType { EMPTY, SQUARE, TRIANGLE}; | ||
38 | MenuTheme(int screen_num); | ||
39 | virtual ~MenuTheme(); | ||
40 | void reconfigTheme(); | ||
41 | /** | ||
42 | @name text colors | ||
43 | */ | ||
44 | ///@{ | ||
45 | const FbTk::Color &titleTextColor() const { return *t_text; } | ||
46 | const FbTk::Color &frameTextColor() const { return *f_text; } | ||
47 | const FbTk::Color &highlightTextColor() const { return *h_text; } | ||
48 | const FbTk::Color &disableTextColor() const { return *d_text; } | ||
49 | ///@} | ||
50 | /** | ||
51 | @name textures | ||
52 | */ | ||
53 | ///@{ | ||
54 | const FbTk::Texture &titleTexture() const { return *title; } | ||
55 | const FbTk::Texture &frameTexture() const { return *frame; } | ||
56 | const FbTk::Texture &hiliteTexture() const { return *hilite; } | ||
57 | ///@} | ||
58 | /** | ||
59 | @name fonts | ||
60 | */ | ||
61 | ///@{ | ||
62 | const FbTk::Font &titleFont() const { return *titlefont; } | ||
63 | const FbTk::Font &frameFont() const { return *framefont; } | ||
64 | ///@} | ||
65 | |||
66 | FbTk::Justify frameFontJustify() const { return *framefont_justify; } | ||
67 | FbTk::Justify titleFontJustify() const { return *titlefont_justify; } | ||
68 | |||
69 | /** | ||
70 | @name graphic contexts | ||
71 | */ | ||
72 | ///@{ | ||
73 | GC titleTextGC() const { return t_text_gc; } | ||
74 | GC frameTextGC() const { return f_text_gc; } | ||
75 | GC hiliteTextGC() const { return h_text_gc; } | ||
76 | GC disableTextGC() const { return d_text_gc; } | ||
77 | GC hiliteGC() const { return hilite_gc; } | ||
78 | ///@} | ||
79 | BulletType bullet() const { return *m_bullet; } | ||
80 | FbTk::Justify bulletPos() const { return *bullet_pos; } | ||
81 | |||
82 | private: | ||
83 | FbTk::ThemeItem<FbTk::Color> t_text, f_text, h_text, d_text; | ||
84 | FbTk::ThemeItem<FbTk::Texture> title, frame, hilite; | ||
85 | FbTk::ThemeItem<FbTk::Font> titlefont, framefont; | ||
86 | FbTk::ThemeItem<FbTk::Justify> framefont_justify, titlefont_justify; | ||
87 | FbTk::ThemeItem<FbTk::Justify> bullet_pos; | ||
88 | FbTk::ThemeItem<BulletType> m_bullet; | ||
89 | |||
90 | Display *m_display; | ||
91 | GC t_text_gc, f_text_gc, h_text_gc, d_text_gc, hilite_gc; | ||
92 | |||
93 | }; | ||
94 | |||
95 | }; // end namespace FbTk | ||
96 | |||
97 | #endif // FBTK_MENUTHEME_HH | ||