1 /*
2 Copyright (C) 2011-2013 The Exult Team
3 
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 as published by the Free Software Foundation; either version 2
7 of the License, or (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 Free Software
16 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
17 */
18 
19 #ifndef SHORTCUTBAR_GUMP_H
20 #define SHORTCUTBAR_GUMP_H
21 
22 
23 #include "SDL.h"
24 #include "gamewin.h"
25 #include "objs.h"
26 #include "misc_buttons.h"
27 #include "Modal_gump.h"
28 #include "Gamemenu_gump.h"
29 
30 #define SHORTCUT_BAR_USER_EVENT 0x53425545 // "SBUE"
31 
32 /* -------------------------------------------- */
33 
34 enum ShortcutBarButtonItemType {
35 	SB_ITEM_DISK,
36 	SB_ITEM_TOGGLE_COMBAT,
37 	SB_ITEM_MAP,
38 	SB_ITEM_SPELLBOOK,
39 	SB_ITEM_BACKPACK,
40 	SB_ITEM_KEY,
41 	SB_ITEM_KEYRING,
42 	SB_ITEM_NOTEBOOK,
43 	SB_ITEM_TARGET,
44 	SB_ITEM_JAWBONE,
45 	SB_ITEM_FEED
46 };
47 
48 Game_object *is_party_item(int shnum, int frnum = c_any_framenum,
49                    int qual = c_any_qual);
50 
51 struct ShortcutBarButtonItem {
52 	const char *name;
53 	ShortcutBarButtonItemType type;
54 	ShapeID *shapeId;
55 	TileRect rect; // Shortcut bar button click area
56 	int mx, my;		// Coordinates where shape is to be drawn
57 	bool pushed;
58 	bool translucent;
59 };
60 
61 #define MAX_SHORTCUT_BAR_ITEMS 10
62 
63 class ShortcutBar_gump: public Gump {
64 public:
65 	ShortcutBar_gump(int placex = 0, int placey = 0);
66 	~ShortcutBar_gump() override;
67 	int handle_event(SDL_Event *event);
68 	void paint() override;
69 
70 	// Don't close on end_gump_mode
is_persistent()71 	bool is_persistent() const override {
72 		return true;
73 	}
74 	// Can't be dragged with mouse
is_draggable()75 	bool is_draggable() const override {
76 		return false;
77 	}
78 	// Show the hand cursor
no_handcursor()79 	bool no_handcursor() const override {
80 		return true;
81 	}
82 
83 	int startx;
84 	int resx;
85 	int gamex;
86 	int starty;
87 	int resy;
88 	int gamey;
89 	void onUserEvent(SDL_Event *event);
90 // add dirty region, if dirty
91 	void update_gump() override;
set_changed()92 	void set_changed() { has_changed = true; }
93 	void check_for_updates(int shnum);
94 
95 private:
96 	ShortcutBarButtonItem buttonItems[MAX_SHORTCUT_BAR_ITEMS];
97 	int numButtons;
98 	int lastClickedButton;
99 	SDL_TimerID timerId;
100 	void createButtons();
101 	void deleteButtons();
102 	void onItemClicked(int index, bool doubleClicked);
103 	void mouse_down(SDL_Event *event, int mx, int my);
104 	void mouse_up(SDL_Event *event, int mx, int my);
105 	bool has_changed;
106 
107 	int locx;
108 	int locy;
109 	int width;
110 	int height;
111 };
112 
113 #endif
114