3 Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation; either version 2.1 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 #include "guiButtonImage.h"
22 #include "client/guiscalingfilter.h"
24 #include "IGUIEnvironment.h"
25 #include "IGUIImage.h"
26 #include "IVideoDriver.h"
27 #include "StyleSpec.h"
32 GUIButtonImage::GUIButtonImage(gui::IGUIEnvironment *environment,
33 gui::IGUIElement *parent, s32 id, core::rect<s32> rectangle,
34 ISimpleTextureSource *tsrc, bool noclip) :
35 GUIButton(environment, parent, id, rectangle, tsrc, noclip)
37 m_image = Environment->addImage(core::rect<s32>(0, 0, rectangle.getWidth(),
38 rectangle.getHeight()),
40 m_image->setScaleImage(isScalingImage());
44 void GUIButtonImage::setForegroundImage(video::ITexture *image)
46 if (image == m_foreground_image)
52 if (m_foreground_image != nullptr)
53 m_foreground_image->drop();
55 m_foreground_image = image;
56 m_image->setImage(image);
59 //! Set element properties from a StyleSpec
60 void GUIButtonImage::setFromStyle(const StyleSpec &style)
62 GUIButton::setFromStyle(style);
64 video::IVideoDriver *driver = Environment->getVideoDriver();
66 if (style.isNotDefault(StyleSpec::FGIMG)) {
67 video::ITexture *texture =
68 style.getTexture(StyleSpec::FGIMG, getTextureSource());
70 setForegroundImage(guiScalingImageButton(driver, texture,
71 AbsoluteRect.getWidth(), AbsoluteRect.getHeight()));
74 setForegroundImage(nullptr);
78 void GUIButtonImage::setScaleImage(bool scaleImage)
80 GUIButton::setScaleImage(scaleImage);
81 m_image->setScaleImage(scaleImage);
84 GUIButtonImage *GUIButtonImage::addButton(IGUIEnvironment *environment,
85 const core::rect<s32> &rectangle, ISimpleTextureSource *tsrc,
86 IGUIElement *parent, s32 id, const wchar_t *text,
87 const wchar_t *tooltiptext)
89 GUIButtonImage *button = new GUIButtonImage(environment,
90 parent ? parent : environment->getRootGUIElement(), id, rectangle,
94 button->setText(text);
97 button->setToolTipText(tooltiptext);