File: global_gui.cpp

package info (click to toggle)
scummvm 2.9.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 450,580 kB
  • sloc: cpp: 4,299,825; asm: 28,322; python: 12,901; sh: 11,302; java: 9,289; xml: 7,895; perl: 2,639; ansic: 2,465; yacc: 1,670; javascript: 1,020; makefile: 933; lex: 578; awk: 275; objc: 82; sed: 11; php: 1
file content (256 lines) | stat: -rw-r--r-- 8,154 bytes parent folder | download | duplicates (2)
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
/* 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 3 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, see <http://www.gnu.org/licenses/>.
 *
 */

#include "ags/shared/ac/common.h"
#include "ags/engine/ac/display.h"
#include "ags/engine/ac/draw.h"
#include "ags/shared/ac/game_setup_struct.h"
#include "ags/engine/ac/game_state.h"
#include "ags/engine/ac/global_game.h"
#include "ags/engine/ac/global_gui.h"
#include "ags/engine/ac/gui.h"
#include "ags/engine/ac/gui_control.h"
#include "ags/engine/ac/mouse.h"
#include "ags/engine/ac/string.h"
#include "ags/engine/debugging/debug_log.h"
#include "ags/shared/font/fonts.h"
#include "ags/shared/gui/gui_main.h"
#include "ags/engine/script/runtime_script_value.h"
#include "ags/shared/util/string_compat.h"

namespace AGS3 {

using namespace AGS::Shared;

int IsGUIOn(int guinum) {
	if ((guinum < 0) || (guinum >= _GP(game).numgui))
		quit("!IsGUIOn: invalid GUI number specified");
	return (_GP(guis)[guinum].IsDisplayed()) ? 1 : 0;
}

// This is an internal script function, and is undocumented.
// It is used by the editor's automatic macro generation.
int FindGUIID(const char *GUIName) {
	for (int ii = 0; ii < _GP(game).numgui; ii++) {
		if (_GP(guis)[ii].Name.IsEmpty())
			continue;
		if (_GP(guis)[ii].Name == GUIName)
			return ii;
		if ((_GP(guis)[ii].Name[0u] == 'g') && (ags_stricmp(_GP(guis)[ii].Name.GetCStr() + 1, GUIName) == 0))
			return ii;
	}
	quit("FindGUIID: No matching GUI found: GUI may have been deleted");
	return -1;
}

void InterfaceOn(int ifn) {
	if ((ifn < 0) | (ifn >= _GP(game).numgui))
		quit("!GUIOn: invalid GUI specified");

	EndSkippingUntilCharStops();

	if (_GP(guis)[ifn].IsVisible()) {
		return;
	}
	_GP(guis)[ifn].SetVisible(true);
	debug_script_log("GUI %d turned on", ifn);
	// modal interface
	if (_GP(guis)[ifn].PopupStyle == kGUIPopupModal) PauseGame();
	_GP(guis)[ifn].Poll(_G(mousex), _G(mousey));
}

void InterfaceOff(int ifn) {
	if ((ifn < 0) | (ifn >= _GP(game).numgui)) quit("!GUIOff: invalid GUI specified");
	if (!_GP(guis)[ifn].IsVisible()) {
		return;
	}
	debug_script_log("GUI %d turned off", ifn);
	_GP(guis)[ifn].SetVisible(false);
	// modal interface
	if (_GP(guis)[ifn].PopupStyle == kGUIPopupModal) UnPauseGame();
}

void SetGUIObjectEnabled(int guin, int objn, int enabled) {
	if ((guin < 0) || (guin >= _GP(game).numgui))
		quit("!SetGUIObjectEnabled: invalid GUI number");
	if ((objn < 0) || (objn >= _GP(guis)[guin].GetControlCount()))
		quit("!SetGUIObjectEnabled: invalid object number");

	GUIControl_SetEnabled(_GP(guis)[guin].GetControl(objn), enabled);
}

void SetGUIObjectPosition(int guin, int objn, int xx, int yy) {
	if ((guin < 0) || (guin >= _GP(game).numgui))
		quit("!SetGUIObjectPosition: invalid GUI number");
	if ((objn < 0) || (objn >= _GP(guis)[guin].GetControlCount()))
		quit("!SetGUIObjectPosition: invalid object number");

	GUIControl_SetPosition(_GP(guis)[guin].GetControl(objn), xx, yy);
}

void SetGUIPosition(int ifn, int xx, int yy) {
	if ((ifn < 0) || (ifn >= _GP(game).numgui))
		quit("!SetGUIPosition: invalid GUI number");

	GUI_SetPosition(&_GP(scrGui)[ifn], xx, yy);
}

void SetGUIObjectSize(int ifn, int objn, int newwid, int newhit) {
	if ((ifn < 0) || (ifn >= _GP(game).numgui))
		quit("!SetGUIObjectSize: invalid GUI number");

	if ((objn < 0) || (objn >= _GP(guis)[ifn].GetControlCount()))
		quit("!SetGUIObjectSize: invalid object number");

	GUIControl_SetSize(_GP(guis)[ifn].GetControl(objn), newwid, newhit);
}

void SetGUISize(int ifn, int widd, int hitt) {
	if ((ifn < 0) || (ifn >= _GP(game).numgui))
		quit("!SetGUISize: invalid GUI number");

	GUI_SetSize(&_GP(scrGui)[ifn], widd, hitt);
}

void SetGUIZOrder(int guin, int z) {
	if ((guin < 0) || (guin >= _GP(game).numgui))
		quit("!SetGUIZOrder: invalid GUI number");

	GUI_SetZOrder(&_GP(scrGui)[guin], z);
}

void SetGUIClickable(int guin, int clickable) {
	if ((guin < 0) || (guin >= _GP(game).numgui))
		quit("!SetGUIClickable: invalid GUI number");

	GUI_SetClickable(&_GP(scrGui)[guin], clickable);
}

// pass trans=0 for fully solid, trans=100 for fully transparent
void SetGUITransparency(int ifn, int trans) {
	if ((ifn < 0) | (ifn >= _GP(game).numgui))
		quit("!SetGUITransparency: invalid GUI number");

	GUI_SetTransparency(&_GP(scrGui)[ifn], trans);
}

void CentreGUI(int ifn) {
	if ((ifn < 0) | (ifn >= _GP(game).numgui))
		quit("!CentreGUI: invalid GUI number");

	GUI_Centre(&_GP(scrGui)[ifn]);
}

int GetTextWidth(const char *text, int fontnum) {
	VALIDATE_STRING(text);
	if ((fontnum < 0) || (fontnum >= _GP(game).numfonts))
		quit("!GetTextWidth: invalid font number.");

	return game_to_data_coord(get_text_width_outlined(text, fontnum));
}

int GetTextHeight(const char *text, int fontnum, int width) {
	VALIDATE_STRING(text);
	if ((fontnum < 0) || (fontnum >= _GP(game).numfonts))
		quit("!GetTextHeight: invalid font number.");

	if (break_up_text_into_lines(text, _GP(Lines), data_to_game_coord(width), fontnum) == 0)
		return 0;
	return game_to_data_coord(get_text_lines_height(fontnum, _GP(Lines).Count()));
}

int GetFontHeight(int fontnum) {
	if ((fontnum < 0) || (fontnum >= _GP(game).numfonts))
		quit("!GetFontHeight: invalid font number.");
	return game_to_data_coord(get_font_height_outlined(fontnum));
}

int GetFontLineSpacing(int fontnum) {
	if ((fontnum < 0) || (fontnum >= _GP(game).numfonts))
		quit("!GetFontLineSpacing: invalid font number.");
	return game_to_data_coord(get_font_linespacing(fontnum));
}

void SetGUIBackgroundPic(int guin, int slotn) {
	if ((guin < 0) | (guin >= _GP(game).numgui))
		quit("!SetGUIBackgroundPic: invalid GUI number");

	GUI_SetBackgroundGraphic(&_GP(scrGui)[guin], slotn);
}

void DisableInterface() {
	// If GUI looks change when disabled, then mark all of them for redraw
	bool redraw_gui = (_GP(play).disabled_user_interface == 0) && // only if was enabled before
					  (GUI::Options.DisabledStyle != kGuiDis_Unchanged);
	GUI::MarkAllGUIForUpdate(redraw_gui, true);
	_GP(play).disabled_user_interface++;
	set_mouse_cursor(CURS_WAIT);
}

void EnableInterface() {
	_GP(play).disabled_user_interface--;
	if (_GP(play).disabled_user_interface < 1) {
		_GP(play).disabled_user_interface = 0;
		set_default_cursor();
		// If GUI looks change when disabled, then mark all of them for redraw
		GUI::MarkAllGUIForUpdate(GUI::Options.DisabledStyle != kGuiDis_Unchanged, true);
	}
}

// Returns 1 if user interface is enabled, 0 if disabled
int IsInterfaceEnabled() {
	return (_GP(play).disabled_user_interface > 0) ? 0 : 1;
}

int GetGUIObjectAt(int xx, int yy) {
	GUIObject *toret = GetGUIControlAtLocation(xx, yy);
	if (toret == nullptr)
		return -1;

	return toret->Id;
}

int GetGUIAt(int xx, int yy) {
	data_to_game_coords(&xx, &yy);

	// Test in the opposite order (from closer to further)
	for (auto g = _GP(play).gui_draw_order.crbegin();
			g < _GP(play).gui_draw_order.crend(); ++g) {
		if (_GP(guis)[*g].IsInteractableAt(xx, yy))
			return *g;
	}
	return -1;
}

void SetTextWindowGUI(int guinum) {
	if ((guinum < -1) | (guinum >= _GP(game).numgui))
		quit("!SetTextWindowGUI: invalid GUI number");

	if (guinum < 0);  // disable it
	else if (!_GP(guis)[guinum].IsTextWindow())
		quit("!SetTextWindowGUI: specified GUI is not a text window");

	if (_GP(play).speech_textwindow_gui == _GP(game).options[OPT_TWCUSTOM])
		_GP(play).speech_textwindow_gui = guinum;
	_GP(game).options[OPT_TWCUSTOM] = guinum;
}

} // namespace AGS3