scummvm/engines/ags/engine/ac/label.cpp

167 lines
5.8 KiB
C++
Raw Normal View History

2020-11-21 08:58:42 -08:00
/* 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.
*
*/
2020-11-26 14:34:47 -08:00
#include "ags/engine/ac/label.h"
2020-11-22 20:31:43 -08:00
#include "ags/shared/ac/common.h"
2021-05-25 07:52:55 -07:00
#include "ags/shared/ac/game_setup_struct.h"
2020-11-26 14:34:47 -08:00
#include "ags/engine/ac/global_translation.h"
#include "ags/engine/ac/string.h"
#include "ags/shared/debugging/out.h"
#include "ags/engine/script/script_api.h"
#include "ags/engine/script/script_runtime.h"
2021-05-25 07:52:55 -07:00
#include "ags/engine/ac/dynobj/script_string.h"
#include "ags/globals.h"
namespace AGS3 {
// ** LABEL FUNCTIONS
2020-11-21 19:31:48 +00:00
const char *Label_GetText_New(GUILabel *labl) {
return CreateNewScriptString(labl->GetText().GetCStr());
}
void Label_GetText(GUILabel *labl, char *buffer) {
strcpy(buffer, labl->GetText().GetCStr());
}
void Label_SetText(GUILabel *labl, const char *newtx) {
2020-11-21 19:31:48 +00:00
newtx = get_translation(newtx);
if (labl->GetText() != newtx) {
2020-11-21 19:31:48 +00:00
labl->SetText(newtx);
}
}
2020-11-21 19:31:48 +00:00
int Label_GetTextAlignment(GUILabel *labl) {
return labl->TextAlignment;
}
2020-11-21 19:31:48 +00:00
void Label_SetTextAlignment(GUILabel *labl, int align) {
if (labl->TextAlignment != align) {
labl->TextAlignment = (HorAlignment)align;
2021-05-25 07:52:55 -07:00
labl->NotifyParentChanged();
2020-11-21 19:31:48 +00:00
}
}
int Label_GetColor(GUILabel *labl) {
2020-11-21 19:31:48 +00:00
return labl->TextColor;
}
void Label_SetColor(GUILabel *labl, int colr) {
2020-11-21 19:31:48 +00:00
if (labl->TextColor != colr) {
labl->TextColor = colr;
2021-05-25 07:52:55 -07:00
labl->NotifyParentChanged();
2020-11-21 19:31:48 +00:00
}
}
int Label_GetFont(GUILabel *labl) {
2020-11-21 19:31:48 +00:00
return labl->Font;
}
void Label_SetFont(GUILabel *guil, int fontnum) {
if ((fontnum < 0) || (fontnum >= _GP(game).numfonts))
2020-11-21 19:31:48 +00:00
quit("!SetLabelFont: invalid font number.");
2020-11-21 19:31:48 +00:00
if (fontnum != guil->Font) {
guil->Font = fontnum;
2021-05-25 07:52:55 -07:00
guil->NotifyParentChanged();
2020-11-21 19:31:48 +00:00
}
}
//=============================================================================
//
// Script API Functions
//
//=============================================================================
// void (GUILabel *labl, char *buffer)
RuntimeScriptValue Sc_Label_GetText(void *self, const RuntimeScriptValue *params, int32_t param_count) {
2020-11-21 19:31:48 +00:00
API_OBJCALL_VOID_POBJ(GUILabel, Label_GetText, char);
}
// void (GUILabel *labl, const char *newtx)
RuntimeScriptValue Sc_Label_SetText(void *self, const RuntimeScriptValue *params, int32_t param_count) {
2020-11-21 19:31:48 +00:00
API_OBJCALL_VOID_POBJ(GUILabel, Label_SetText, const char);
}
RuntimeScriptValue Sc_Label_GetTextAlignment(void *self, const RuntimeScriptValue *params, int32_t param_count) {
2020-11-21 19:31:48 +00:00
API_OBJCALL_INT(GUILabel, Label_GetTextAlignment);
}
RuntimeScriptValue Sc_Label_SetTextAlignment(void *self, const RuntimeScriptValue *params, int32_t param_count) {
2020-11-21 19:31:48 +00:00
API_OBJCALL_VOID_PINT(GUILabel, Label_SetTextAlignment);
}
// int (GUILabel *labl)
RuntimeScriptValue Sc_Label_GetFont(void *self, const RuntimeScriptValue *params, int32_t param_count) {
2020-11-21 19:31:48 +00:00
API_OBJCALL_INT(GUILabel, Label_GetFont);
}
// void (GUILabel *guil, int fontnum)
RuntimeScriptValue Sc_Label_SetFont(void *self, const RuntimeScriptValue *params, int32_t param_count) {
2020-11-21 19:31:48 +00:00
API_OBJCALL_VOID_PINT(GUILabel, Label_SetFont);
}
// const char* (GUILabel *labl)
RuntimeScriptValue Sc_Label_GetText_New(void *self, const RuntimeScriptValue *params, int32_t param_count) {
API_CONST_OBJCALL_OBJ(GUILabel, const char, _GP(myScriptStringImpl), Label_GetText_New);
}
// int (GUILabel *labl)
RuntimeScriptValue Sc_Label_GetColor(void *self, const RuntimeScriptValue *params, int32_t param_count) {
2020-11-21 19:31:48 +00:00
API_OBJCALL_INT(GUILabel, Label_GetColor);
}
// void (GUILabel *labl, int colr)
RuntimeScriptValue Sc_Label_SetColor(void *self, const RuntimeScriptValue *params, int32_t param_count) {
2020-11-21 19:31:48 +00:00
API_OBJCALL_VOID_PINT(GUILabel, Label_SetColor);
}
void RegisterLabelAPI() {
ccAddExternalObjectFunction("Label::GetText^1", Sc_Label_GetText);
ccAddExternalObjectFunction("Label::SetText^1", Sc_Label_SetText);
2020-11-21 19:31:48 +00:00
ccAddExternalObjectFunction("Label::get_TextAlignment", Sc_Label_GetTextAlignment);
ccAddExternalObjectFunction("Label::set_TextAlignment", Sc_Label_SetTextAlignment);
ccAddExternalObjectFunction("Label::get_Font", Sc_Label_GetFont);
ccAddExternalObjectFunction("Label::set_Font", Sc_Label_SetFont);
ccAddExternalObjectFunction("Label::get_Text", Sc_Label_GetText_New);
ccAddExternalObjectFunction("Label::set_Text", Sc_Label_SetText);
2020-11-21 19:31:48 +00:00
ccAddExternalObjectFunction("Label::get_TextColor", Sc_Label_GetColor);
ccAddExternalObjectFunction("Label::set_TextColor", Sc_Label_SetColor);
/* ----------------------- Registering unsafe exports for plugins -----------------------*/
ccAddExternalFunctionForPlugin("Label::GetText^1", (void *)Label_GetText);
ccAddExternalFunctionForPlugin("Label::SetText^1", (void *)Label_SetText);
ccAddExternalFunctionForPlugin("Label::get_Font", (void *)Label_GetFont);
ccAddExternalFunctionForPlugin("Label::set_Font", (void *)Label_SetFont);
ccAddExternalFunctionForPlugin("Label::get_Text", (void *)Label_GetText_New);
ccAddExternalFunctionForPlugin("Label::set_Text", (void *)Label_SetText);
ccAddExternalFunctionForPlugin("Label::get_TextColor", (void *)Label_GetColor);
ccAddExternalFunctionForPlugin("Label::set_TextColor", (void *)Label_SetColor);
}
} // namespace AGS3