1
// MenuIcon.cc for FbTk - Fluxbox ToolKit
2
// Copyright (c) 2004 - 2005 Henrik Kinnunen (fluxgen at fluxbox dot org)
3
// and Simon Bowden (rathnor at users.sourceforge.net)
5
// Permission is hereby granted, free of charge, to any person obtaining a
6
// copy of this software and associated documentation files (the "Software"),
7
// to deal in the Software without restriction, including without limitation
8
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
9
// and/or sell copies of the Software, and to permit persons to whom the
10
// Software is furnished to do so, subject to the following conditions:
12
// The above copyright notice and this permission notice shall be included in
13
// all copies or substantial portions of the Software.
15
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21
// DEALINGS IN THE SOFTWARE.
23
// $Id: MenuIcon.cc 3954 2005-04-26 01:41:55Z simonb $
25
#include "MenuIcon.hh"
27
#include "MenuTheme.hh"
33
MenuIcon::MenuIcon(const std::string &filename, const std::string &label, int screen_num):
34
MenuItem(label.c_str()),
35
m_filename(filename) {
36
FbTk::PixmapWithMask *pm = Image::load(filename.c_str(), screen_num);
38
m_pixmap = pm->pixmap().release();
39
m_mask = pm->mask().release();
45
void MenuIcon::updateTheme(const MenuTheme &theme) {
46
FbTk::PixmapWithMask *pm = Image::load(m_filename.c_str(), theme.screenNum());
48
m_pixmap = pm->pixmap().release();
49
m_mask = pm->mask().release();
54
void MenuIcon::draw(FbDrawable &drawable,
55
const MenuTheme &theme,
56
bool highlight, bool draw_foreground, bool draw_background,
58
unsigned int width, unsigned int height) const {
61
if (draw_background) {
62
Display *disp = FbTk::App::instance()->display();
63
if (height - 2*theme.bevelWidth() != m_pixmap.height() &&
64
!m_filename.empty()) {
65
unsigned int scale_size = height - 2*theme.bevelWidth();
66
m_pixmap.scale(scale_size, scale_size);
67
m_mask.scale(scale_size, scale_size);
70
if (m_pixmap.drawable() != 0) {
71
GC gc = theme.frameTextGC().gc();
74
XSetClipMask(disp, gc, m_mask.drawable());
75
XSetClipOrigin(disp, gc, x + theme.bevelWidth(), y + theme.bevelWidth());
77
drawable.copyArea(m_pixmap.drawable(),
80
x + theme.bevelWidth(), y + theme.bevelWidth(),
81
m_pixmap.width(), m_pixmap.height());
84
XSetClipMask(disp, gc, None);
87
FbTk::MenuItem::draw(drawable, theme, highlight,
88
draw_background, draw_foreground, x, y, width, height);
91
unsigned int MenuIcon::width(const MenuTheme &theme) const {
92
return MenuItem::width(theme) + 2 * (theme.bevelWidth() + height(theme));
95
} // end namespace FbTk