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 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437
|
/* 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/gui_control.h"
#include "ags/engine/ac/global_gui.h"
#include "ags/engine/ac/mouse.h"
#include "ags/engine/ac/string.h"
#include "ags/engine/debugging/debug_log.h"
#include "ags/shared/gui/gui_button.h"
#include "ags/shared/gui/gui_inv.h"
#include "ags/shared/gui/gui_label.h"
#include "ags/shared/gui/gui_listbox.h"
#include "ags/shared/gui/gui_main.h"
#include "ags/shared/gui/gui_slider.h"
#include "ags/shared/gui/gui_textbox.h"
#include "ags/engine/script/runtime_script_value.h"
#include "ags/engine/ac/dynobj/cc_gui.h"
#include "ags/engine/ac/dynobj/cc_gui_object.h"
#include "ags/engine/ac/dynobj/script_string.h"
#include "ags/shared/debugging/out.h"
#include "ags/engine/script/script_api.h"
#include "ags/engine/script/script_runtime.h"
#include "ags/globals.h"
namespace AGS3 {
using namespace AGS::Shared;
GUIObject *GetGUIControlAtLocation(int xx, int yy) {
int guinum = GetGUIAt(xx, yy);
if (guinum == -1)
return nullptr;
data_to_game_coords(&xx, &yy);
int32_t toret = _GP(guis)[guinum].FindControlAt(xx, yy, 0, false);
if (toret < 0)
return nullptr;
return _GP(guis)[guinum].GetControl(toret);
}
int GUIControl_GetVisible(GUIObject *guio) {
return guio->IsVisible();
}
void GUIControl_SetVisible(GUIObject *guio, int visible) {
const bool on = visible != 0;
if (on != guio->IsVisible()) {
guio->SetVisible(on);
}
}
int GUIControl_GetClickable(GUIObject *guio) {
if (guio->IsClickable())
return 1;
return 0;
}
void GUIControl_SetClickable(GUIObject *guio, int enabled) {
const bool on = enabled != 0;
if (on != guio->IsClickable()) {
guio->SetClickable(on);
}
}
int GUIControl_GetEnabled(GUIObject *guio) {
return guio->IsEnabled() ? 1 : 0;
}
void GUIControl_SetEnabled(GUIObject *guio, int enabled) {
const bool on = enabled != 0;
if (on != guio->IsEnabled()) {
guio->SetEnabled(on);
}
}
int GUIControl_GetID(GUIObject *guio) {
return guio->Id;
}
const char *GUIControl_GetScriptName(GUIObject *guio) {
return CreateNewScriptString(guio->Name);
}
ScriptGUI *GUIControl_GetOwningGUI(GUIObject *guio) {
return &_GP(scrGui)[guio->ParentId];
}
GUIButton *GUIControl_GetAsButton(GUIObject *guio) {
if (_GP(guis)[guio->ParentId].GetControlType(guio->Id) != kGUIButton)
return nullptr;
return (GUIButton *)guio;
}
GUIInvWindow *GUIControl_GetAsInvWindow(GUIObject *guio) {
if (_GP(guis)[guio->ParentId].GetControlType(guio->Id) != kGUIInvWindow)
return nullptr;
return (GUIInvWindow *)guio;
}
GUILabel *GUIControl_GetAsLabel(GUIObject *guio) {
if (_GP(guis)[guio->ParentId].GetControlType(guio->Id) != kGUILabel)
return nullptr;
return (GUILabel *)guio;
}
GUIListBox *GUIControl_GetAsListBox(GUIObject *guio) {
if (_GP(guis)[guio->ParentId].GetControlType(guio->Id) != kGUIListBox)
return nullptr;
return (GUIListBox *)guio;
}
GUISlider *GUIControl_GetAsSlider(GUIObject *guio) {
if (_GP(guis)[guio->ParentId].GetControlType(guio->Id) != kGUISlider)
return nullptr;
return (GUISlider *)guio;
}
GUITextBox *GUIControl_GetAsTextBox(GUIObject *guio) {
if (_GP(guis)[guio->ParentId].GetControlType(guio->Id) != kGUITextBox)
return nullptr;
return (GUITextBox *)guio;
}
int GUIControl_GetX(GUIObject *guio) {
return game_to_data_coord(guio->X);
}
void GUIControl_SetX(GUIObject *guio, int xx) {
guio->X = data_to_game_coord(xx);
_GP(guis)[guio->ParentId].NotifyControlPosition(); // update control under cursor
}
int GUIControl_GetY(GUIObject *guio) {
return game_to_data_coord(guio->Y);
}
void GUIControl_SetY(GUIObject *guio, int yy) {
guio->Y = data_to_game_coord(yy);
_GP(guis)[guio->ParentId].NotifyControlPosition(); // update control under cursor
}
int GUIControl_GetZOrder(GUIObject *guio) {
return guio->ZOrder;
}
void GUIControl_SetZOrder(GUIObject *guio, int zorder) {
_GP(guis)[guio->ParentId].SetControlZOrder(guio->Id, zorder);
}
void GUIControl_SetPosition(GUIObject *guio, int xx, int yy) {
GUIControl_SetX(guio, xx);
GUIControl_SetY(guio, yy);
}
int GUIControl_GetWidth(GUIObject *guio) {
return game_to_data_coord(guio->GetWidth());
}
void GUIControl_SetWidth(GUIObject *guio, int newwid) {
guio->SetWidth(data_to_game_coord(newwid));
}
int GUIControl_GetHeight(GUIObject *guio) {
return game_to_data_coord(guio->GetHeight());
}
void GUIControl_SetHeight(GUIObject *guio, int newhit) {
guio->SetHeight(data_to_game_coord(newhit));
}
void GUIControl_SetSize(GUIObject *guio, int newwid, int newhit) {
if ((newwid < 2) || (newhit < 2))
quit("!SetGUIObjectSize: new size is too small (must be at least 2x2)");
debug_script_log("SetGUIObject %d,%d size %d,%d", guio->ParentId, guio->Id, newwid, newhit);
GUIControl_SetWidth(guio, newwid);
GUIControl_SetHeight(guio, newhit);
}
void GUIControl_SendToBack(GUIObject *guio) {
_GP(guis)[guio->ParentId].SendControlToBack(guio->Id);
}
void GUIControl_BringToFront(GUIObject *guio) {
_GP(guis)[guio->ParentId].BringControlToFront(guio->Id);
}
int GUIControl_GetTransparency(GUIObject *guio) {
return GfxDef::LegacyTrans255ToTrans100(guio->GetTransparency());
}
void GUIControl_SetTransparency(GUIObject *guio, int trans) {
if ((trans < 0) | (trans > 100))
quit("!SetGUITransparency: transparency value must be between 0 and 100");
guio->SetTransparency(GfxDef::Trans100ToLegacyTrans255(trans));
}
//=============================================================================
//
// Script API Functions
//
//=============================================================================
GUIObject *GUIControl_GetByName(const char *name) {
return static_cast<GUIObject *>(ccGetScriptObjectAddress(name, _GP(ccDynamicGUIObject).GetType()));
}
RuntimeScriptValue Sc_GUIControl_GetByName(const RuntimeScriptValue *params, int32_t param_count) {
API_SCALL_OBJ_POBJ(GUIObject, _GP(ccDynamicGUIObject), GUIControl_GetByName, const char);
}
// void (GUIObject *guio)
RuntimeScriptValue Sc_GUIControl_BringToFront(void *self, const RuntimeScriptValue *params, int32_t param_count) {
API_OBJCALL_VOID(GUIObject, GUIControl_BringToFront);
}
// GUIObject *(int xx, int yy)
RuntimeScriptValue Sc_GetGUIControlAtLocation(const RuntimeScriptValue *params, int32_t param_count) {
API_SCALL_OBJ_PINT2(GUIObject, _GP(ccDynamicGUIObject), GetGUIControlAtLocation);
}
// void (GUIObject *guio)
RuntimeScriptValue Sc_GUIControl_SendToBack(void *self, const RuntimeScriptValue *params, int32_t param_count) {
API_OBJCALL_VOID(GUIObject, GUIControl_SendToBack);
}
// void (GUIObject *guio, int xx, int yy)
RuntimeScriptValue Sc_GUIControl_SetPosition(void *self, const RuntimeScriptValue *params, int32_t param_count) {
API_OBJCALL_VOID_PINT2(GUIObject, GUIControl_SetPosition);
}
// void (GUIObject *guio, int newwid, int newhit)
RuntimeScriptValue Sc_GUIControl_SetSize(void *self, const RuntimeScriptValue *params, int32_t param_count) {
API_OBJCALL_VOID_PINT2(GUIObject, GUIControl_SetSize);
}
// GUIButton* (GUIObject *guio)
RuntimeScriptValue Sc_GUIControl_GetAsButton(void *self, const RuntimeScriptValue *params, int32_t param_count) {
API_OBJCALL_OBJ(GUIObject, GUIButton, _GP(ccDynamicGUI), GUIControl_GetAsButton);
}
// GUIInvWindow* (GUIObject *guio)
RuntimeScriptValue Sc_GUIControl_GetAsInvWindow(void *self, const RuntimeScriptValue *params, int32_t param_count) {
API_OBJCALL_OBJ(GUIObject, GUIInvWindow, _GP(ccDynamicGUI), GUIControl_GetAsInvWindow);
}
// GUILabel* (GUIObject *guio)
RuntimeScriptValue Sc_GUIControl_GetAsLabel(void *self, const RuntimeScriptValue *params, int32_t param_count) {
API_OBJCALL_OBJ(GUIObject, GUILabel, _GP(ccDynamicGUI), GUIControl_GetAsLabel);
}
// GUIListBox* (GUIObject *guio)
RuntimeScriptValue Sc_GUIControl_GetAsListBox(void *self, const RuntimeScriptValue *params, int32_t param_count) {
API_OBJCALL_OBJ(GUIObject, GUIListBox, _GP(ccDynamicGUI), GUIControl_GetAsListBox);
}
// GUISlider* (GUIObject *guio)
RuntimeScriptValue Sc_GUIControl_GetAsSlider(void *self, const RuntimeScriptValue *params, int32_t param_count) {
API_OBJCALL_OBJ(GUIObject, GUISlider, _GP(ccDynamicGUI), GUIControl_GetAsSlider);
}
// GUITextBox* (GUIObject *guio)
RuntimeScriptValue Sc_GUIControl_GetAsTextBox(void *self, const RuntimeScriptValue *params, int32_t param_count) {
API_OBJCALL_OBJ(GUIObject, GUITextBox, _GP(ccDynamicGUI), GUIControl_GetAsTextBox);
}
// int (GUIObject *guio)
RuntimeScriptValue Sc_GUIControl_GetClickable(void *self, const RuntimeScriptValue *params, int32_t param_count) {
API_OBJCALL_INT(GUIObject, GUIControl_GetClickable);
}
// void (GUIObject *guio, int enabled)
RuntimeScriptValue Sc_GUIControl_SetClickable(void *self, const RuntimeScriptValue *params, int32_t param_count) {
API_OBJCALL_VOID_PINT(GUIObject, GUIControl_SetClickable);
}
// int (GUIObject *guio)
RuntimeScriptValue Sc_GUIControl_GetEnabled(void *self, const RuntimeScriptValue *params, int32_t param_count) {
API_OBJCALL_INT(GUIObject, GUIControl_GetEnabled);
}
// void (GUIObject *guio, int enabled)
RuntimeScriptValue Sc_GUIControl_SetEnabled(void *self, const RuntimeScriptValue *params, int32_t param_count) {
API_OBJCALL_VOID_PINT(GUIObject, GUIControl_SetEnabled);
}
// int (GUIObject *guio)
RuntimeScriptValue Sc_GUIControl_GetHeight(void *self, const RuntimeScriptValue *params, int32_t param_count) {
API_OBJCALL_INT(GUIObject, GUIControl_GetHeight);
}
// void (GUIObject *guio, int newhit)
RuntimeScriptValue Sc_GUIControl_SetHeight(void *self, const RuntimeScriptValue *params, int32_t param_count) {
API_OBJCALL_VOID_PINT(GUIObject, GUIControl_SetHeight);
}
// int (GUIObject *guio)
RuntimeScriptValue Sc_GUIControl_GetID(void *self, const RuntimeScriptValue *params, int32_t param_count) {
API_OBJCALL_INT(GUIObject, GUIControl_GetID);
}
RuntimeScriptValue Sc_GUIControl_GetScriptName(void *self, const RuntimeScriptValue *params, int32_t param_count) {
API_OBJCALL_OBJ(GUIObject, const char, _GP(myScriptStringImpl), GUIControl_GetScriptName);
}
// ScriptGUI* (GUIObject *guio)
RuntimeScriptValue Sc_GUIControl_GetOwningGUI(void *self, const RuntimeScriptValue *params, int32_t param_count) {
API_OBJCALL_OBJ(GUIObject, ScriptGUI, _GP(ccDynamicGUI), GUIControl_GetOwningGUI);
}
// int (GUIObject *guio)
RuntimeScriptValue Sc_GUIControl_GetVisible(void *self, const RuntimeScriptValue *params, int32_t param_count) {
API_OBJCALL_INT(GUIObject, GUIControl_GetVisible);
}
// void (GUIObject *guio, int visible)
RuntimeScriptValue Sc_GUIControl_SetVisible(void *self, const RuntimeScriptValue *params, int32_t param_count) {
API_OBJCALL_VOID_PINT(GUIObject, GUIControl_SetVisible);
}
// int (GUIObject *guio)
RuntimeScriptValue Sc_GUIControl_GetWidth(void *self, const RuntimeScriptValue *params, int32_t param_count) {
API_OBJCALL_INT(GUIObject, GUIControl_GetWidth);
}
// void (GUIObject *guio, int newwid)
RuntimeScriptValue Sc_GUIControl_SetWidth(void *self, const RuntimeScriptValue *params, int32_t param_count) {
API_OBJCALL_VOID_PINT(GUIObject, GUIControl_SetWidth);
}
// int (GUIObject *guio)
RuntimeScriptValue Sc_GUIControl_GetX(void *self, const RuntimeScriptValue *params, int32_t param_count) {
API_OBJCALL_INT(GUIObject, GUIControl_GetX);
}
// void (GUIObject *guio, int xx)
RuntimeScriptValue Sc_GUIControl_SetX(void *self, const RuntimeScriptValue *params, int32_t param_count) {
API_OBJCALL_VOID_PINT(GUIObject, GUIControl_SetX);
}
// int (GUIObject *guio)
RuntimeScriptValue Sc_GUIControl_GetY(void *self, const RuntimeScriptValue *params, int32_t param_count) {
API_OBJCALL_INT(GUIObject, GUIControl_GetY);
}
// void (GUIObject *guio, int yy)
RuntimeScriptValue Sc_GUIControl_SetY(void *self, const RuntimeScriptValue *params, int32_t param_count) {
API_OBJCALL_VOID_PINT(GUIObject, GUIControl_SetY);
}
RuntimeScriptValue Sc_GUIControl_GetZOrder(void *self, const RuntimeScriptValue *params, int32_t param_count) {
API_OBJCALL_INT(GUIObject, GUIControl_GetZOrder);
}
RuntimeScriptValue Sc_GUIControl_SetZOrder(void *self, const RuntimeScriptValue *params, int32_t param_count) {
API_OBJCALL_VOID_PINT(GUIObject, GUIControl_SetZOrder);
}
RuntimeScriptValue Sc_GUIControl_GetTransparency(void *self, const RuntimeScriptValue *params, int32_t param_count) {
API_OBJCALL_INT(GUIObject, GUIControl_GetTransparency);
}
RuntimeScriptValue Sc_GUIControl_SetTransparency(void *self, const RuntimeScriptValue *params, int32_t param_count) {
API_OBJCALL_VOID_PINT(GUIObject, GUIControl_SetTransparency);
}
void RegisterGUIControlAPI() {
ScFnRegister guicontrol_api[] = {
{"GUIControl::GetAtScreenXY^2", API_FN_PAIR(GetGUIControlAtLocation)},
{"GUIControl::GetByName", API_FN_PAIR(GUIControl_GetByName)},
{"GUIControl::BringToFront^0", API_FN_PAIR(GUIControl_BringToFront)},
{"GUIControl::SendToBack^0", API_FN_PAIR(GUIControl_SendToBack)},
{"GUIControl::SetPosition^2", API_FN_PAIR(GUIControl_SetPosition)},
{"GUIControl::SetSize^2", API_FN_PAIR(GUIControl_SetSize)},
{"GUIControl::get_AsButton", API_FN_PAIR(GUIControl_GetAsButton)},
{"GUIControl::get_AsInvWindow", API_FN_PAIR(GUIControl_GetAsInvWindow)},
{"GUIControl::get_AsLabel", API_FN_PAIR(GUIControl_GetAsLabel)},
{"GUIControl::get_AsListBox", API_FN_PAIR(GUIControl_GetAsListBox)},
{"GUIControl::get_AsSlider", API_FN_PAIR(GUIControl_GetAsSlider)},
{"GUIControl::get_AsTextBox", API_FN_PAIR(GUIControl_GetAsTextBox)},
{"GUIControl::get_Clickable", API_FN_PAIR(GUIControl_GetClickable)},
{"GUIControl::set_Clickable", API_FN_PAIR(GUIControl_SetClickable)},
{"GUIControl::get_Enabled", API_FN_PAIR(GUIControl_GetEnabled)},
{"GUIControl::set_Enabled", API_FN_PAIR(GUIControl_SetEnabled)},
{"GUIControl::get_Height", API_FN_PAIR(GUIControl_GetHeight)},
{"GUIControl::set_Height", API_FN_PAIR(GUIControl_SetHeight)},
{"GUIControl::get_ID", API_FN_PAIR(GUIControl_GetID)},
{"GUIControl::get_OwningGUI", API_FN_PAIR(GUIControl_GetOwningGUI)},
{"GUIControl::get_ScriptName", API_FN_PAIR(GUIControl_GetScriptName)},
{"GUIControl::get_Visible", API_FN_PAIR(GUIControl_GetVisible)},
{"GUIControl::set_Visible", API_FN_PAIR(GUIControl_SetVisible)},
{"GUIControl::get_Width", API_FN_PAIR(GUIControl_GetWidth)},
{"GUIControl::set_Width", API_FN_PAIR(GUIControl_SetWidth)},
{"GUIControl::get_X", API_FN_PAIR(GUIControl_GetX)},
{"GUIControl::set_X", API_FN_PAIR(GUIControl_SetX)},
{"GUIControl::get_Y", API_FN_PAIR(GUIControl_GetY)},
{"GUIControl::set_Y", API_FN_PAIR(GUIControl_SetY)},
{"GUIControl::get_ZOrder", API_FN_PAIR(GUIControl_GetZOrder)},
{"GUIControl::set_ZOrder", API_FN_PAIR(GUIControl_SetZOrder)},
{"GUIControl::get_Transparency", API_FN_PAIR(GUIControl_GetTransparency)},
{"GUIControl::set_Transparency", API_FN_PAIR(GUIControl_SetTransparency)},
};
ccAddExternalFunctions361(guicontrol_api);
}
} // namespace AGS3
|