]> git.lizzy.rs Git - minetest.git/blob - src/gui/guiButtonImage.h
Refactor to centralize GUIButton styling/rendering code (#9090)
[minetest.git] / src / gui / guiButtonImage.h
1 /*
2 Minetest
3 Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
4
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.
9
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.
14
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.
18 */
19
20 #include "guiButton.h"
21 #include "IGUIButton.h"
22
23 using namespace irr;
24
25 class GUIButtonImage : public GUIButton
26 {
27 public:
28         //! constructor
29         GUIButtonImage(gui::IGUIEnvironment *environment, gui::IGUIElement *parent,
30                         s32 id, core::rect<s32> rectangle, bool noclip = false);
31
32         virtual bool OnEvent(const SEvent& event) override;
33
34         void setForegroundImage(gui::EGUI_BUTTON_IMAGE_STATE state,
35                         video::ITexture *image = nullptr,
36                         const core::rect<s32> &sourceRect = core::rect<s32>(0, 0, 0, 0));
37
38         void setForegroundImage(video::ITexture *image = nullptr);
39         void setForegroundImage(video::ITexture *image, const core::rect<s32> &pos);
40
41         void setPressedForegroundImage(video::ITexture *image = nullptr);
42         void setPressedForegroundImage(video::ITexture *image, const core::rect<s32> &pos);
43
44         void setHoveredForegroundImage(video::ITexture *image = nullptr);
45         void setHoveredForegroundImage(video::ITexture *image, const core::rect<s32> &pos);
46
47         virtual void setFromStyle(const StyleSpec &style, ISimpleTextureSource *tsrc) override;
48
49         virtual void setScaleImage(bool scaleImage=true) override;
50
51         //! Do not drop returned handle
52         static GUIButtonImage *addButton(gui::IGUIEnvironment *environment,
53                         const core::rect<s32> &rectangle, IGUIElement *parent, s32 id,
54                         const wchar_t *text, const wchar_t *tooltiptext = L"");
55
56 private:
57         ButtonImage m_foreground_images[gui::EGBIS_COUNT];
58         gui::IGUIImage *m_image;
59 };