aboutsummaryrefslogtreecommitdiff
path: root/engines/cryomni3d/versailles/toolbar.h
blob: cb1eeb4b501230cb7a63daaa9419f0510e542114 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
/* ScummVM - Graphic Adventure Engine
 *
 * ScummVM is the legal property of its developers, whose names
 * are too numerous to list here. Please refer to the COPYRIGHT
 * file distributed with this source distribution.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 *
 */

#ifndef CRYOMNI3D_VERSAILLES_TOOLBAR_H
#define CRYOMNI3D_VERSAILLES_TOOLBAR_H

#include "common/array.h"
#include "common/rect.h"
#include "graphics/managed_surface.h"
#include "graphics/surface.h"

#include "cryomni3d/font_manager.h"
#include "cryomni3d/objects.h"
#include "cryomni3d/sprites.h"

namespace CryOmni3D {
class CryOmni3DEngine;

namespace Versailles {


class Toolbar {
public:
	Toolbar() : _sprites(nullptr), _fontManager(nullptr), _inventory(nullptr),
		_messages(nullptr), _inventoryOffset(0), _engine(nullptr),
		_inventoryHovered(uint(-1)), _inventorySelected(uint(-1)), _inventoryEnabled(true),
		_position(60) { }
	~Toolbar();

	void init(const Sprites *sprites, FontManager *fontManager,
	          const Common::Array<Common::String> *messages, Inventory *inventory, CryOmni3DEngine *engine);

	Graphics::Surface &getBackgroundSurface() { return _bgSurface; }
	bool displayToolbar(const Graphics::Surface *original);
	void inventoryChanged(uint newPosition);
	uint inventoryOffset() const { return _inventoryOffset; }
	void setInventoryOffset(uint offset) { _inventoryOffset = offset; }
	void setInventoryEnabled(bool enabled) { _inventoryEnabled = enabled; }

private:
	typedef uint(Toolbar::*ZoneCallback)(uint dragStatus);
	struct Zone {
		Common::Rect rect;
		uint16 imageMain;
		uint16 imageSecondary;
		ZoneCallback callback;
		bool secondary;
		bool hidden;
	};
	Common::Array<Zone> _zones;
	const Sprites *_sprites;
	FontManager *_fontManager;
	const Common::Array<Common::String> *_messages;
	Inventory *_inventory;
	CryOmni3DEngine *_engine;

	static const uint kTextOffset = 13;

	void addZone(uint16 cursorMainId, uint16 cursorSecondaryId, Common::Point position,
	             ZoneCallback callback);
	void updateZones();
	Common::Array<Zone>::const_iterator hitTestZones(const Common::Point &mousePos) const;
	uint captureEvent(const Common::Point &mousePos, uint dragStatus);
	void drawToolbar(const Graphics::Surface *original);
	void handleToolbarEvents(const Graphics::Surface *original);

	bool _inventoryEnabled;
	uint _inventoryMaxOffset;
	uint _inventoryOffset;
	uint _inventoryHovered;
	uint _inventorySelected;

	Object *_backup_selected_object;
	bool _mouse_in_options;
	bool _mouse_in_view_object;
	bool _inventory_button_dragging;

	bool _parentMustRedraw;
	bool _shortExit;
	uint _position;

	Graphics::Surface _bgSurface;
	Graphics::ManagedSurface _destSurface;

	template<uint N>
	uint callbackInventory(uint dragStatus) { return callbackInventory(N, dragStatus); }
	uint callbackInventory(uint invId, uint dragStatus);
	uint callbackInventoryPrev(uint dragStatus);
	uint callbackInventoryNext(uint dragStatus);
	uint callbackViewObject(uint dragStatus);
	uint callbackOptions(uint dragStatus);
	uint callbackDocumentation(uint dragStatus);
};

} // End of namespace Versailles
} // End of namespace CryOmni3D

#endif