1 /*
2 Copyright © 2011-2012 Clint Bellanger
3 Copyright © 2013 Joseph Bleau
4 Copyright © 2013 Kurt Rinnert
5 Copyright © 2012-2016 Justin Jacobs
6 
7 This file is part of FLARE.
8 
9 FLARE is free software: you can redistribute it and/or modify it under the terms
10 of the GNU General Public License as published by the Free Software Foundation,
11 either version 3 of the License, or (at your option) any later version.
12 
13 FLARE is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
15 PARTICULAR PURPOSE.  See the GNU General Public License for more details.
16 
17 You should have received a copy of the GNU General Public License along with
18 FLARE.  If not, see http://www.gnu.org/licenses/
19 */
20 
21 #ifndef WIDGET_H
22 #define WIDGET_H
23 
24 /**
25  * Base interface all widget needs to implement
26  */
27 #include "CommonIncludes.h"
28 #include "Utils.h"
29 
30 class Widget {
31 public:
32 	enum {
33 		SCROLL_VERTICAL = 0,
34 		SCROLL_HORIZONTAL = 1,
35 		SCROLL_TWO_DIRECTIONS = 2
36 	};
37 
38 	Widget();
39 
40 	virtual ~Widget();
41 	virtual void render() = 0;
42 	virtual void activate();
43 	virtual void deactivate();
44 	virtual void defocus();
45 	virtual bool getNext();  // getNext and getPrev should be implemented
46 	virtual bool getPrev(); // if the widget has items internally that can be iterated
47 	virtual void setBasePos(int x, int y, int a);
48 	virtual void setPos(int offset_x, int offset_y);
49 	bool in_focus;
50 	bool focusable;
51 	bool enable_tablist_nav; // when disabled, this widget will be skipped during tablist navigation
52 	bool tablist_nav_right; // uses the center-right point for tablist nav instead of the center. Primarily for MenuConfig widgets
53 	uint8_t scroll_type;
54 	Rect pos; // This is the position of the button within the screen
55 	Rect local_frame; // Local reference frame is this is a daughter widget
56 	Point local_offset; // Offset in local frame is this is a daughter widget
57 	Point pos_base; // the initial x/y position of this widget, often from a config file
58 	int alignment;
59 };
60 
61 class TabList {
62 private:
63 	std::vector<Widget*> widgets;
64 	int current;
65 	int previous;
66 	bool locked;
67 	bool current_is_valid();
68 	bool previous_is_valid();
69 	uint8_t scrolltype;
70 	int MV_LEFT;
71 	int MV_RIGHT;
72 	int ACTIVATE;
73 	TabList *prev_tablist;
74 	TabList *next_tablist;
75 public:
76 	enum {
77 		WIDGET_SELECT_AUTO = 0,
78 		WIDGET_SELECT_LEFT = 1,
79 		WIDGET_SELECT_RIGHT = 2,
80 		WIDGET_SELECT_UP = 3,
81 		WIDGET_SELECT_DOWN = 4
82 	};
83 
84 	static const bool GET_INNER = true;
85 
86 	TabList();
87 	~TabList();
88 
89 	void lock();
90 	void unlock();
91 	void add(Widget* widget);			// Add a widget
92 	void remove(Widget* widget);		// Remove a widget
93 	void clear();						// Remove all widgets
94 	void setCurrent(Widget* widget);
95 	int getCurrent();
96 	Widget* getWidgetByIndex(int index);
97 	unsigned size();
98 	Widget* getNext(bool inner, uint8_t dir);	// Increment current selected, return widget
99 	Widget* getPrev(bool inner, uint8_t dir);	// Decrement current selected, return widget
100 	int getNextRelativeIndex(uint8_t dir);
101 	void deactivatePrevious();
102 	void activate();					// Fire off what happens when the user presses 'accept'
103 	void defocus();						// Call when user clicks outside of a widget, resets current
104 	void setPrevTabList(TabList *tl);
105 	void setNextTabList(TabList *tl);
106 	void setScrollType(uint8_t _scrolltype);
107 	void setInputs(int _LEFT, int _RIGHT, int _ACTIVATE);
108 
109 	void logic();
110 
111 	bool ignore_no_mouse;
112 };
113 
114 #endif
115 
116