1 /*
2  * This file is part of EasyRPG Player.
3  *
4  * EasyRPG Player 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 3 of the License, or
7  * (at your option) any later version.
8  *
9  * EasyRPG Player 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 EasyRPG Player. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #ifndef EP_WINDOW_SELECTABLE_H
19 #define EP_WINDOW_SELECTABLE_H
20 
21 // Headers
22 #include <functional>
23 #include "window_base.h"
24 #include "window_help.h"
25 
26 /**
27  * Window Selectable class.
28  */
29 class Window_Selectable: public Window_Base {
30 public:
31 	Window_Selectable(int ix, int iy, int iwidth, int iheight);
32 
33 	/**
34 	 * Creates the contents based on how many items
35 	 * are currently in the window.
36 	 */
37 	void CreateContents();
38 
39 	int GetIndex() const;
40 	void SetIndex(int nindex);
41 	int GetRowMax() const;
42 	int GetTopRow() const;
43 	void SetTopRow(int row);
44 	int GetPageRowMax() const;
45 	int GetPageItemMax();
46 
47 	/**
48 	 * Returns the Item Rect used for item drawing.
49 	 *
50 	 * @param index index of item.
51 	 * @return Rect where the item is drawn.
52 	 */
53 	Rect GetItemRect(int index);
54 
55 	/**
56 	 * Function called by the base UpdateHelp() implementation.
57 	 * Passes in the Help Window and the current selected index
58 	 * Will not be called if the help_window is null
59 	 */
60 	std::function<void(Window_Help&, int)> UpdateHelpFn;
61 
62 	Window_Help* GetHelpWindow();
63 
64 	/**
65 	 * Assigns a help window that displays a description
66 	 * about the selected item.
67 	 *
68 	 * @param nhelp_window the help window.
69 	 */
70 	void SetHelpWindow(Window_Help* nhelp_window);
71 	virtual void UpdateCursorRect();
72 	void Update() override;
73 
74 	virtual void UpdateHelp();
75 
76 	/**
77 	 * Sets if endless scrolling is enabled.
78 	 *
79 	 * @param state true to enable (default), false to disable.
80 	 */
81 	void SetEndlessScrolling(bool state);
82 
83 	/**
84 	 * Sets the menu item height.
85 	 *
86 	 * @param height the menu item height.
87 	 */
88 	void SetMenuItemHeight(int height);
89 
90 protected:
91 	void UpdateArrows();
92 
93 	Window_Help* help_window = nullptr;
94 	int item_max = 1;
95 	int column_max = 1;
96 	int index = -1;
97 	int arrow_frame = 0;
98 
99 	bool endless_scrolling = true;
100 
101 	int menu_item_height = 16;
102 
103 	int scroll_dir = 0;
104 	int scroll_progress = 0;
105 };
106 
107 #endif
108