1 /***************************************************************************
2  *      Mechanized Assault and Exploration Reloaded Projectfile            *
3  *                                                                         *
4  *   This program is free software; you can redistribute it and/or modify  *
5  *   it under the terms of the GNU General Public License as published by  *
6  *   the Free Software Foundation; either version 2 of the License, or     *
7  *   (at your option) any later version.                                   *
8  *                                                                         *
9  *   This program is distributed in the hope that it will be useful,       *
10  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
11  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
12  *   GNU General Public License for more details.                          *
13  *                                                                         *
14  *   You should have received a copy of the GNU General Public License     *
15  *   along with this program; if not, write to the                         *
16  *   Free Software Foundation, Inc.,                                       *
17  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
18  ***************************************************************************/
19 
20 #ifndef ui_graphical_menu_widgets_pushbuttonH
21 #define ui_graphical_menu_widgets_pushbuttonH
22 
23 #include <string>
24 
25 #include "maxrconfig.h"
26 #include "ui/graphical/menu/widgets/clickablewidget.h"
27 #include "utility/autosurface.h"
28 #include "utility/signal/signal.h"
29 #include "unifonts.h"
30 #include "sound.h"
31 
32 enum class ePushButtonType
33 {
34 	StandardBig,
35 	StandardSmall,
36 	Huge,
37 	ArrowUpBig,
38 	ArrowDownBig,
39 	ArrowLeftBig,
40 	ArrowRightBig,
41 	ArrowUpSmall,
42 	ArrowDownSmall,
43 	ArrowLeftSmall,
44 	ArrowRightSmall,
45 	ArrowUpBar,
46 	ArrowDownBar,
47 	Angular,
48 
49 	HudHelp,
50 	HudCenter,
51 	HudNext,
52 	HudPrev,
53 	HudDone,
54 	HudReport,
55 	HudChat,
56 
57 	HudPreferences,
58 	HudFiles,
59 	HudEnd,
60 	HudPlay,
61 	HudStop,
62 
63 	UnitContextMenu,
64 
65 	Destroy,
66 
67 	Invisible,
68 
69 	ArrowUpSmallModern,
70 	ArrowDownSmallModern,
71 	ArrowLeftSmallModern,
72 	ArrowRightSmallModern,
73 };
74 
75 class cPushButton : public cClickableWidget
76 {
77 public:
78 	explicit cPushButton (const cBox<cPosition>& area);
79 	cPushButton (const cPosition& position, ePushButtonType buttonType);
80 	cPushButton (const cPosition& position, ePushButtonType buttonType, cSoundChunk* clickSound);
81 	cPushButton (const cPosition& position, ePushButtonType buttonType, const std::string& text, eUnicodeFontType fontType = FONT_LATIN_BIG);
82 	cPushButton (const cPosition& position, ePushButtonType buttonType, cSoundChunk* clickSound, const std::string& text, eUnicodeFontType fontType = FONT_LATIN_BIG);
83 
84 	virtual void draw (SDL_Surface& destination, const cBox<cPosition>& clipRect) MAXR_OVERRIDE_FUNCTION;
85 
86 	virtual bool handleMousePressed (cApplication& application, cMouse& mouse, eMouseButtonType button) MAXR_OVERRIDE_FUNCTION;
87 	virtual bool handleMouseReleased (cApplication& application, cMouse& mouse, eMouseButtonType button) MAXR_OVERRIDE_FUNCTION;
88 
89 	void lock();
90 	void unlock();
91 
92 	cSignal<void ()> clicked;
93 protected:
94 	virtual void setPressed (bool pressed) MAXR_OVERRIDE_FUNCTION;
95 
96 	virtual bool handleClicked (cApplication& application, cMouse& mouse, eMouseButtonType button) MAXR_OVERRIDE_FUNCTION;
97 
98 private:
99 	AutoSurface surface;
100 	ePushButtonType buttonType;
101 
102 	eUnicodeFontType fontType;
103 	std::string text;
104 
105 	cSoundChunk* clickSound;
106 
107 	bool isLocked;
108 
109 	void renewSurface();
110 
111 	int getBordersSize() const;
112 	int getTextYOffset() const;
113 };
114 
115 #endif // ui_graphical_menu_widgets_pushbuttonH
116