1 /*
2  *  Gump_manager.h - Object that manages all available gumps
3  *
4  *  Copyright (C) 2001-2013  The Exult Team
5  *
6  *  This program 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  *  This program 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 this program; if not, write to the Free Software
18  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19  */
20 
21 #ifndef GUMP_MANAGER_INCLUDED
22 #define GUMP_MANAGER_INCLUDED
23 
24 #include "singles.h"
25 #include "mouse.h"
26 #include "SDL_events.h"
27 
28 class Gump;
29 class Game_object;
30 class Game_window;
31 class Modal_gump;
32 class Paintable;
33 
34 class  Gump_manager : public Game_singletons {
35 	struct Gump_list {
36 		Gump        *gump = nullptr;
37 		Gump_list   *next = nullptr;
38 
39 		Gump_list() = default;
Gump_listGump_list40 		Gump_list(Gump *g) : gump(g) { }
41 	};
42 
43 	Gump_list   *open_gumps = nullptr;
44 	Gump        *kbd_focus = nullptr; // This gump gets kbd strokes.
45 	// So we can test for 'gump mode' quickly:
46 	int     non_persistent_count = 0;
47 	int modal_gump_count = 0;
48 	bool    right_click_close = true;
49 	bool    dont_pause_game = false;    // NEVER SET THIS MANUALLY! YOU MUST
50 	// CALL set_gumps_dont_pause_game.
51 public:
52 	void add_gump(Gump *gump);      // Add a single gump to screen
53 	// Show gump for obj
54 	void add_gump(Game_object *obj, int shapenum, bool actorgump = false);
55 
56 	bool remove_gump(Gump *gump);       // Detatch a gump from the list
57 	bool close_gump(Gump *gump);        // Close a gump
58 	void close_all_gumps(bool pers = false);// Close all gumps
59 	void set_kbd_focus(Gump *gump);
60 
61 	bool showing_gumps(bool no_pers = false) const; // Are gumps showing?
gump_mode()62 	bool gump_mode() const {            // Fast check.
63 		return non_persistent_count > 0;
64 	}
modal_gump_mode()65 	bool modal_gump_mode() const { // displaying a modal gump?
66 		return modal_gump_count > 0;
67 	}
68 
69 	Gump *find_gump(int x, int y, bool pers = true);// Find gump x,y is in
70 	Gump *find_gump(const Game_object *obj);  // Find gump that object is in
71 	// Find gump for object obj:
72 	Gump *find_gump(const Game_object *owner, int shapenum);
73 
74 	void update_gumps();
75 	void paint(bool modal);
76 
77 	bool double_clicked(int x, int y, Game_object *&obj);
78 	bool handle_kbd_event(void *ev);
79 	static void translate_numpad(SDL_Keycode& code, uint16& unicode, uint16 mod);
80 
can_right_click_close()81 	inline bool can_right_click_close() {
82 		return right_click_close;
83 	}
set_right_click_close(bool r)84 	inline void set_right_click_close(bool r) {
85 		right_click_close = r;
86 	}
87 
gumps_dont_pause_game()88 	inline bool gumps_dont_pause_game() {
89 		return dont_pause_game;
90 	}
91 	void set_gumps_dont_pause_game(bool p);
92 
93 	bool okay_to_quit();
94 	int prompt_for_number(int minval, int maxval, int step, int def,
95 	                      Paintable *paint = nullptr);
96 	bool do_modal_gump(Modal_gump *, Mouse::Mouse_shapes,
97 	                  Paintable *paint = nullptr);
98 	void paint_num(int num, int x, int y);
99 
100 	Gump_manager();
~Gump_manager()101 	~Gump_manager() {
102 		close_all_gumps(true);
103 	}
104 
105 private:
106 	bool handle_modal_gump_event(Modal_gump *gump, SDL_Event &event);
107 };
108 
109 #endif // GUMP_MANAGER_INCLUDED
110