1 /*
2 	This file is part of Warzone 2100.
3 	Copyright (C) 1999-2004  Eidos Interactive
4 	Copyright (C) 2005-2020  Warzone 2100 Project
5 
6 	Warzone 2100 is free software; you can redistribute it and/or modify
7 	it under the terms of the GNU General Public License as published by
8 	the Free Software Foundation; either version 2 of the License, or
9 	(at your option) any later version.
10 
11 	Warzone 2100 is distributed in the hope that it will be useful,
12 	but WITHOUT ANY WARRANTY; without even the implied warranty of
13 	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 	GNU General Public License for more details.
15 
16 	You should have received a copy of the GNU General Public License
17 	along with Warzone 2100; if not, write to the Free Software
18 	Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20 /** @file
21  *  Definitions for multi but form functions.
22  */
23 
24 #ifndef __INCLUDED_LIB_WIDGET_MULTIBUTFORM_H__
25 #define __INCLUDED_LIB_WIDGET_MULTIBUTFORM_H__
26 
27 #include "lib/ivis_opengl/ivisdef.h"
28 
29 #include "widget.h"
30 #include "widgbase.h"
31 #include "form.h"
32 #include "label.h"
33 #include <map>
34 #include <functional>
35 #include <string>
36 
37 class MultibuttonWidget : public W_FORM
38 {
39 public:
40 	enum class ButtonAlignment {
41 		RIGHT_ALIGN,
42 		CENTER_ALIGN
43 	};
44 
45 public:
46 	MultibuttonWidget(int value = -1);
47 
48 	virtual void display(int xOffset, int yOffset);
49 	virtual void geometryChanged();
50 
51 	void setLabel(char const *text);
52 	void addButton(int value, const std::shared_ptr<W_BUTTON>& button);
53 	void setButtonMinClickInterval(UDWORD interval);
54 	void setButtonAlignment(ButtonAlignment alignment);
55 	void enable(bool enabled = true);
disable()56 	void disable()
57 	{
58 		enable(false);
59 	}
60 	void setGap(int gap);
currentValue()61 	int currentValue() const
62 	{
63 		return currentValue_;
64 	}
65 
66 	/* The optional "onChoose" callback function */
67 	typedef std::function<void (MultibuttonWidget& widget, int newValue)> W_ON_CHOOSE_FUNC;
68 
69 	void addOnChooseHandler(const W_ON_CHOOSE_FUNC& onChooseFunc);
70 
71 public:
72 	void choose(int value);
73 
74 private:
75 	void stateChanged();
76 
77 protected:
78 	std::shared_ptr<W_LABEL> label;
79 	std::vector<std::pair<std::shared_ptr<W_BUTTON>, int>> buttons;
80 	int currentValue_;
81 	bool disabled;
82 	int gap_;
83 	bool lockCurrent;
84 	ButtonAlignment butAlign = ButtonAlignment::RIGHT_ALIGN;
85 	std::vector<W_ON_CHOOSE_FUNC> onChooseHandlers;
86 };
87 
88 class MultichoiceWidget : public MultibuttonWidget
89 {
90 
91 public:
92 	MultichoiceWidget(int value = -1);
93 };
94 
95 
96 #endif // __INCLUDED_LIB_WIDGET_MULTIBUTFORM_H__
97