Initial commit

This commit is contained in:
2026-02-02 04:50:13 +01:00
commit 5b11698731
22592 changed files with 7677434 additions and 0 deletions

View File

@@ -0,0 +1,147 @@
/* 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
* 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/plugins/ags_sprite_font/ags_sprite_font.h"
#include "ags/shared/core/platform.h"
namespace AGS3 {
namespace Plugins {
namespace AGSSpriteFont {
#pragma region Defines
#define MIN_EDITOR_VERSION 1
#define MIN_ENGINE_VERSION 3
#define DEFAULT_RGB_R_SHIFT_32 16
#define DEFAULT_RGB_G_SHIFT_32 8
#define DEFAULT_RGB_B_SHIFT_32 0
#define DEFAULT_RGB_A_SHIFT_32 24
#define abs(a) ((a)<0 ? -(a) : (a))
#define ChannelBlend_Normal(B,L) ((uint8)(B))
#define ChannelBlend_Lighten(B,L) ((uint8)((L > B) ? L:B))
#define ChannelBlend_Darken(B,L) ((uint8)((L > B) ? B:L))
#define ChannelBlend_Multiply(B,L) ((uint8)((B * L) / 255))
#define ChannelBlend_Average(B,L) ((uint8)((B + L) / 2))
#define ChannelBlend_Add(B,L) ((uint8)(min(255, (B + L))))
#define ChannelBlend_Subtract(B,L) ((uint8)((B + L < 255) ? 0:(B + L - 255)))
#define ChannelBlend_Difference(B,L) ((uint8)(abs(B - L)))
#define ChannelBlend_Negation(B,L) ((uint8)(255 - abs(255 - B - L)))
#define ChannelBlend_Screen(B,L) ((uint8)(255 - (((255 - B) * (255 - L)) >> 8)))
#define ChannelBlend_Exclusion(B,L) ((uint8)(B + L - 2 * B * L / 255))
#define ChannelBlend_Overlay(B,L) ((uint8)((L < 128) ? (2 * B * L / 255):(255 - 2 * (255 - B) * (255 - L) / 255)))
#define ChannelBlend_SoftLight(B,L) ((uint8)((L < 128)?(2*((B>>1)+64))*((float)L/255):(255-(2*(255-((B>>1)+64))*(float)(255-L)/255))))
#define ChannelBlend_HardLight(B,L) (ChannelBlend_Overlay(L,B))
#define ChannelBlend_ColorDodge(B,L) ((uint8)((L == 255) ? L:min(255, ((B << 8 ) / (255 - L)))))
#define ChannelBlend_ColorBurn(B,L) ((uint8)((L == 0) ? L:max(0, (255 - ((255 - B) << 8 ) / L))))
#define ChannelBlend_LinearDodge(B,L)(ChannelBlend_Add(B,L))
#define ChannelBlend_LinearBurn(B,L) (ChannelBlend_Subtract(B,L))
#define ChannelBlend_LinearLight(B,L)((uint8)(L < 128)?ChannelBlend_LinearBurn(B,(2 * L)):ChannelBlend_LinearDodge(B,(2 * (L - 128))))
#define ChannelBlend_VividLight(B,L) ((uint8)(L < 128)?ChannelBlend_ColorBurn(B,(2 * L)):ChannelBlend_ColorDodge(B,(2 * (L - 128))))
#define ChannelBlend_PinLight(B,L) ((uint8)(L < 128)?ChannelBlend_Darken(B,(2 * L)):ChannelBlend_Lighten(B,(2 * (L - 128))))
#define ChannelBlend_HardMix(B,L) ((uint8)((ChannelBlend_VividLight(B,L) < 128) ? 0:255))
#define ChannelBlend_Reflect(B,L) ((uint8)((L == 255) ? L:min(255, (B * B / (255 - L)))))
#define ChannelBlend_Glow(B,L) (ChannelBlend_Reflect(L,B))
#define ChannelBlend_Phoenix(B,L) ((uint8)(min(B,L) - max(B,L) + 255))
#define ChannelBlend_Alpha(B,L,O) ((uint8)(O * B + (1 - O) * L))
#define ChannelBlend_AlphaF(B,L,F,O) (ChannelBlend_Alpha(F(B,L),B,O))
#pragma endregion
#define STRINGIFY(s) STRINGIFY_X(s)
#define STRINGIFY_X(s) #s
const char *AGSSpriteFont::AGS_GetPluginName() {
return "AGSSpriteFont";
}
void AGSSpriteFont::AGS_EngineStartup(IAGSEngine *engine) {
PluginBase::AGS_EngineStartup(engine);
if (_fontRenderer == nullptr) {
_engine->PrintDebugConsole("AGSSpriteFont: Init fixed width renderer");
_fontRenderer = new SpriteFontRenderer(engine);
}
if (_vWidthRenderer == nullptr) {
_engine->PrintDebugConsole("AGSSpriteFont: Init vari width renderer");
_vWidthRenderer = new VariableWidthSpriteFontRenderer(engine);
}
// Make sure it's got the version with the features we need
if (_engine->version < MIN_ENGINE_VERSION)
_engine->AbortGame("Plugin needs engine version " STRINGIFY(MIN_ENGINE_VERSION) " or newer.");
// Register functions
_engine->PrintDebugConsole("AGSSpriteFont: Register functions");
SCRIPT_METHOD(SetSpriteFont, AGSSpriteFont::SetSpriteFont);
SCRIPT_METHOD(SetVariableSpriteFont, AGSSpriteFont::SetVariableSpriteFont);
SCRIPT_METHOD(SetGlyph, AGSSpriteFont::SetGlyph);
SCRIPT_METHOD(SetSpacing, AGSSpriteFont::SetSpacing);
SCRIPT_METHOD(SetLineHeightAdjust, AGSSpriteFont::SetLineHeightAdjust);
}
void AGSSpriteFont::AGS_EngineShutdown() {
delete _fontRenderer;
delete _vWidthRenderer;
}
void AGSSpriteFont::SetSpriteFont(ScriptMethodParams &params) {
PARAMS9(int, fontNum, int, sprite, int, rows, int, columns, int, charWidth, int, charHeight, int, charMin, int, charMax, bool, use32bit);
_engine->PrintDebugConsole("AGSSpriteFont: SetSpriteFont");
_fontRenderer->SetSpriteFont(fontNum, sprite, rows, columns, charWidth, charHeight, charMin, charMax, use32bit);
if (_engine->version >= 26)
_engine->ReplaceFontRenderer2(fontNum, _fontRenderer);
else
_engine->ReplaceFontRenderer(fontNum, _fontRenderer);
}
void AGSSpriteFont::SetVariableSpriteFont(ScriptMethodParams &params) {
PARAMS2(int, fontNum, int, sprite);
_engine->PrintDebugConsole("AGSSpriteFont: SetVariableFont");
_vWidthRenderer->SetSprite(fontNum, sprite);
if (_engine->version >= 26)
_engine->ReplaceFontRenderer2(fontNum, _vWidthRenderer);
else
_engine->ReplaceFontRenderer(fontNum, _vWidthRenderer);
}
void AGSSpriteFont::SetGlyph(ScriptMethodParams &params) {
PARAMS6(int, fontNum, int, charNum, int, x, int, y, int, width, int, height);
_engine->PrintDebugConsole("AGSSpriteFont: SetGlyph");
_vWidthRenderer->SetGlyph(fontNum, charNum, x, y, width, height);
}
void AGSSpriteFont::SetSpacing(ScriptMethodParams &params) {
PARAMS2(int, fontNum, int, spacing);
_engine->PrintDebugConsole("AGSSpriteFont: SetSpacing");
_vWidthRenderer->SetSpacing(fontNum, spacing);
}
void AGSSpriteFont::SetLineHeightAdjust(ScriptMethodParams &params) {
//PARAMS4(int, v1, int, v2, int, v3, int, v4);
// TODO
}
} // namespace AGSSpriteFont
} // namespace Plugins
} // namespace AGS3

View File

@@ -0,0 +1,63 @@
/* 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
* 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/>.
*
*/
#ifndef AGS_PLUGINS_AGS_SPRITE_FONT_AGS_SPRITE_FONT_H
#define AGS_PLUGINS_AGS_SPRITE_FONT_AGS_SPRITE_FONT_H
#include "ags/plugins/ags_plugin.h"
#include "ags/plugins/ags_sprite_font/sprite_font_renderer.h"
#include "ags/plugins/ags_sprite_font/variable_width_sprite_font.h"
namespace AGS3 {
class IAGSEngine;
}
namespace AGS3 {
namespace Plugins {
namespace AGSSpriteFont {
class AGSSpriteFont : public PluginBase {
SCRIPT_HASH(AGSSpriteFont)
protected:
SpriteFontRenderer *_fontRenderer;
VariableWidthSpriteFontRenderer *_vWidthRenderer;
private:
void SetSpriteFont(ScriptMethodParams &params);
void SetVariableSpriteFont(ScriptMethodParams &params);
void SetGlyph(ScriptMethodParams &params);
void SetSpacing(ScriptMethodParams &params);
void SetLineHeightAdjust(ScriptMethodParams &params);
public:
AGSSpriteFont() : PluginBase(), _fontRenderer(nullptr), _vWidthRenderer(nullptr) {}
virtual ~AGSSpriteFont() {}
const char *AGS_GetPluginName() override;
void AGS_EngineStartup(IAGSEngine *lpEngine) override;
void AGS_EngineShutdown() override;
};
} // namespace AGSSpriteFont
} // namespace Plugins
} // namespace AGS3
#endif

View File

@@ -0,0 +1,52 @@
/* 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/plugins/ags_sprite_font/ags_sprite_font_clifftop.h"
#include "ags/plugins/ags_sprite_font/sprite_font_renderer_clifftop.h"
#include "ags/plugins/ags_sprite_font/variable_width_sprite_font_clifftop.h"
namespace AGS3 {
namespace Plugins {
namespace AGSSpriteFont {
void AGSSpriteFontClifftopGames::AGS_EngineStartup(IAGSEngine *engine) {
// Use custom font renderers
// They need to be set before calling AGSSpriteFont::AGS_EngineStartup()
engine->PrintDebugConsole("AGSSpriteFont: Init fixed width renderer");
_fontRenderer = new SpriteFontRenderer(engine);
engine->PrintDebugConsole("AGSSpriteFont: Init vari width renderer");
_vWidthRenderer = new VariableWidthSpriteFontRendererClifftop(engine);
AGSSpriteFont::AGS_EngineStartup(engine);
SCRIPT_METHOD(SetLineHeightAdjust, AGSSpriteFontClifftopGames::SetLineHeightAdjust);
}
void AGSSpriteFontClifftopGames::SetLineHeightAdjust(ScriptMethodParams &params) {
PARAMS4(int, fontNum, int, LineHeight, int, SpacingHeight, int, SpacingOverride);
_vWidthRenderer->SetLineHeightAdjust(fontNum, LineHeight, SpacingHeight, SpacingOverride);
}
} // namespace AGSSpriteFont
} // namespace Plugins
} // namespace AGS3

View File

@@ -0,0 +1,48 @@
/* 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
* 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/>.
*
*/
#ifndef AGS_PLUGINS_AGS_SPRITE_FONT_CLIFFTOP_H
#define AGS_PLUGINS_AGS_SPRITE_FONT_CLIFFTOP_H
#include "ags/plugins/ags_sprite_font/ags_sprite_font.h"
namespace AGS3 {
namespace Plugins {
namespace AGSSpriteFont {
class AGSSpriteFontClifftopGames : public AGSSpriteFont {
SCRIPT_HASH_SUB(AGSSpriteFontClifftopGames, AGSSpriteFont)
private:
void SetLineHeightAdjust(ScriptMethodParams &params);
public:
AGSSpriteFontClifftopGames() : AGSSpriteFont() {}
virtual ~AGSSpriteFontClifftopGames() {}
void AGS_EngineStartup(IAGSEngine *engine) override;
};
} // namespace AGSSpriteFont
} // namespace Plugins
} // namespace AGS3
#endif

View File

@@ -0,0 +1,41 @@
/* 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
* 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/plugins/ags_sprite_font/character_entry.h"
namespace AGS3 {
namespace Plugins {
namespace AGSSpriteFont {
CharacterEntry::CharacterEntry(void) {
X = 0;
Y = 0;
Width = 0;
Height = 0;
Character = 0;
}
CharacterEntry::~CharacterEntry(void) {}
} // namespace AGSSpriteFont
} // namespace Plugins
} // namespace AGS3

View File

@@ -0,0 +1,44 @@
/* 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
* 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/>.
*
*/
#ifndef AGS_PLUGINS_AGS_SPRITE_FONT_CHAR_ENTRY_H
#define AGS_PLUGINS_AGS_SPRITE_FONT_CHAR_ENTRY_H
namespace AGS3 {
namespace Plugins {
namespace AGSSpriteFont {
class CharacterEntry {
public:
CharacterEntry(void);
~CharacterEntry(void);
int X;
int Y;
int Width;
int Height;
char Character;
};
} // namespace AGSSpriteFont
} // namespace Plugins
} // namespace AGS3
#endif

View File

@@ -0,0 +1,57 @@
/* 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
* 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/plugins/ags_sprite_font/color.h"
namespace AGS3 {
namespace Plugins {
namespace AGSSpriteFont {
int getr32(int c) {
return ((c >> DEFAULT_RGB_R_SHIFT_32) & 0xFF);
}
int getg32(int c) {
return ((c >> DEFAULT_RGB_G_SHIFT_32) & 0xFF);
}
int getb32(int c) {
return ((c >> DEFAULT_RGB_B_SHIFT_32) & 0xFF);
}
int geta32(int c) {
return ((c >> DEFAULT_RGB_A_SHIFT_32) & 0xFF);
}
int makeacol32(int r, int g, int b, int a) {
return ((r << DEFAULT_RGB_R_SHIFT_32) |
(g << DEFAULT_RGB_G_SHIFT_32) |
(b << DEFAULT_RGB_B_SHIFT_32) |
(a << DEFAULT_RGB_A_SHIFT_32));
}
} // namespace AGSSpriteFont
} // namespace Plugins
} // namespace AGS3

View File

@@ -0,0 +1,50 @@
/* 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
* 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/>.
*
*/
#ifndef AGS_PLUGINS_AGS_SPRITE_FONT_COLOR_H
#define AGS_PLUGINS_AGS_SPRITE_FONT_COLOR_H
namespace AGS3 {
namespace Plugins {
namespace AGSSpriteFont {
#define MAX(a, b) (((a) > (b)) ? (a) : (b))
#define DEFAULT_RGB_R_SHIFT_32 16
#define DEFAULT_RGB_G_SHIFT_32 8
#define DEFAULT_RGB_B_SHIFT_32 0
#define DEFAULT_RGB_A_SHIFT_32 24
#pragma region Color_Functions
int getr32(int c);
int getg32(int c);
int getb32(int c);
int geta32(int c);
int makeacol32(int r, int g, int b, int a);
#pragma endregion
} // namespace AGSSpriteFont
} // namespace Plugins
} // namespace AGS3
#endif

View File

@@ -0,0 +1,35 @@
/* 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
* 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/plugins/ags_sprite_font/sprite_font.h"
namespace AGS3 {
namespace Plugins {
namespace AGSSpriteFont {
SpriteFont::SpriteFont(void) {}
SpriteFont::~SpriteFont(void) {}
} // namespace AGSSpriteFont
} // namespace Plugins
} // namespace AGS3

View File

@@ -0,0 +1,48 @@
/* 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
* 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/>.
*
*/
#ifndef AGS_PLUGINS_AGS_SPRITE_FONT_SPRITE_FONT_H
#define AGS_PLUGINS_AGS_SPRITE_FONT_SPRITE_FONT_H
namespace AGS3 {
namespace Plugins {
namespace AGSSpriteFont {
class SpriteFont {
public:
SpriteFont(void);
~SpriteFont(void);
int SpriteNumber;
int MinChar;
int MaxChar;
int Rows;
int Columns;
int FontReplaced;
int CharHeight;
int CharWidth;
bool Use32bit;
};
} // namespace AGSSpriteFont
} // namespace Plugins
} // namespace AGS3
#endif

View File

@@ -0,0 +1,215 @@
/* 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
* 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/plugins/ags_sprite_font/sprite_font_renderer.h"
#include "ags/plugins/ags_sprite_font/color.h"
namespace AGS3 {
namespace Plugins {
namespace AGSSpriteFont {
SpriteFontRenderer::SpriteFontRenderer(IAGSEngine *engine) {
_engine = engine;
}
SpriteFontRenderer::~SpriteFontRenderer(void) {
}
void SpriteFontRenderer::FreeMemory(int fontNum) {
for(auto it = _fonts.begin(); it != _fonts.end() ; ++it) {
SpriteFont *font = *it;
if (font->FontReplaced == fontNum) {
_fonts.erase(it);
delete font;
return;
}
}
}
void SpriteFontRenderer::SetSpriteFont(int fontNum, int sprite, int rows, int columns, int charWidth, int charHeight, int charMin, int charMax, bool use32bit) {
SpriteFont *font = getFontFor(fontNum);
font->SpriteNumber = sprite;
font->Rows = rows;
font->Columns = columns;
font->MinChar = charMin;
font->MaxChar = charMax;
font->Use32bit = use32bit;
font->CharHeight = charHeight;
font->CharWidth = charWidth;
}
void SpriteFontRenderer::EnsureTextValidForFont(char *text, int fontNumber) {
SpriteFont *font = getFontFor(fontNumber);
for (int i = 0; i < (int)strlen(text); i++) {
if (text[i] < font->MinChar || text[i] > font->MaxChar) {
if (font->MinChar < 63 || font->MaxChar > 63) text[i] = 63;
else text[i] = font->MinChar;
}
}
}
bool SpriteFontRenderer::SupportsExtendedCharacters(int fontNumber) {
return false;
}
int SpriteFontRenderer::GetTextWidth(const char *text, int fontNumber) {
SpriteFont *font = getFontFor(fontNumber);
int len = (int)strlen(text);
return font->CharWidth * len;
}
int SpriteFontRenderer::GetTextHeight(const char *text, int fontNumber) {
SpriteFont *font = getFontFor(fontNumber);
return font->CharHeight;
}
int SpriteFontRenderer::GetFontHeight(int fontNumber) {
SpriteFont *font = getFontFor(fontNumber);
return font->CharHeight;
}
SpriteFont *SpriteFontRenderer::getFontFor(int fontNum) {
SpriteFont *font;
for (int i = 0; i < (int)_fonts.size(); i ++) {
font = _fonts.at(i);
if (font->FontReplaced == fontNum) return font;
}
//not found
font = new SpriteFont();
font->FontReplaced = fontNum;
_fonts.push_back(font);
return font;
}
void SpriteFontRenderer::RenderText(const char *text, int fontNumber, BITMAP *destination, int x, int y, int colour) {
SpriteFont *font = getFontFor(fontNumber);
//BITMAP *vScreen = _engine->GetVirtualScreen();
//_engine->SetVirtualScreen(destination);
int len_text = (int)strlen(text);
for (int i = 0; i < len_text; i++) {
char c = text[i];
c -= font->MinChar;
int row = c / font->Columns;
int column = c % font->Columns;
BITMAP *src = _engine->GetSpriteGraphic(font->SpriteNumber);
Draw(src, destination, x + (i * font->CharWidth), y, column * font->CharWidth, row * font->CharHeight, font->CharWidth, font->CharHeight, colour);
}
//_engine->SetVirtualScreen(vScreen);
}
void SpriteFontRenderer::Draw(BITMAP *src, BITMAP *dest, int destx, int desty, int srcx, int srcy, int width, int height, int colour) {
int32 srcWidth, srcHeight, destWidth, destHeight, srcColDepth, destColDepth;
uint8 *srccharbuffer = _engine->GetRawBitmapSurface(src);
uint8 *destcharbuffer = _engine->GetRawBitmapSurface(dest);
uint32 transColor = _engine->GetBitmapTransparentColor(src);
int srcPitch = _engine->GetBitmapPitch(src);
int destPitch = _engine->GetBitmapPitch(dest);
_engine->GetBitmapDimensions(src, &srcWidth, &srcHeight, &srcColDepth);
_engine->GetBitmapDimensions(dest, &destWidth, &destHeight, &destColDepth);
int bpp = destColDepth / 8;
if (srcy + height > srcHeight || srcx + width > srcWidth || srcx < 0 || srcy < 0) return;
if (width + destx > destWidth) width = destWidth - destx;
if (height + desty > destHeight) height = destHeight - desty;
int startx = MAX(0, (-1 * destx));
int starty = MAX(0, (-1 * desty));
int srca, srcr, srcg, srcb, desta, destr, destg, destb, finalr, finalg, finalb, finala, col, col_r, col_g, col_b;
col_r = getr32(colour);
col_g = getg32(colour);
col_b = getb32(colour);
int srcxx = (startx + srcx) * bpp;
int destxx = (startx + destx) * bpp;
for (int x = startx; x < width; ++x, srcxx += bpp, destxx += bpp) {
int srcyy = (starty + srcy) * srcPitch;
int destyy = (starty + desty) * destPitch;
for (int y = starty; y < height; ++y, srcyy += srcPitch, destyy += destPitch) {
uint8 *srcCol = srccharbuffer + srcyy + srcxx;
uint8 *destCol = destcharbuffer + destyy + destxx;
if (destColDepth == 8) {
if (*srcCol != transColor)
*destCol = *srcCol;
} else if (destColDepth == 16) {
if (*((uint16 *)srcCol) != transColor)
*((uint16 *)destCol) = *((uint16 *)srcCol);
} else if (destColDepth == 32) {
//if (*((uint32*)srcCol) != transColor)
// *((uint32*)destCol) = *((uint32*)srcCol);
uint32 srcargb = *((uint32 *)srcCol);
uint32 &destargb = *((uint32 *)destCol);
srca = (geta32(srcargb));
if (srca != 0) {
srcr = getr32(srcargb);
srcg = getg32(srcargb);
srcb = getb32(srcargb);
destr = getr32(destargb);
destg = getg32(destargb);
destb = getb32(destargb);
desta = geta32(destargb);
finalr = (col_r * srcr) / 255;
finalg = (col_g * srcg) / 255;
finalb = (col_b * srcb) / 255;
finala = 255 - (255 - srca) * (255 - desta) / 255;
finalr = srca * finalr / finala + desta * destr * (255 - srca) / finala / 255;
finalg = srca * finalg / finala + desta * destg * (255 - srca) / finala / 255;
finalb = srca * finalb / finala + desta * destb * (255 - srca) / finala / 255;
col = makeacol32(finalr, finalg, finalb, finala);
destargb = col;
}
}
}
}
_engine->ReleaseBitmapSurface(src);
_engine->ReleaseBitmapSurface(dest);
}
} // namespace AGSSpriteFont
} // namespace Plugins
} // namespace AGS3

View File

@@ -0,0 +1,70 @@
/* 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
* 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/>.
*
*/
#ifndef AGS_PLUGINS_AGS_SPRITE_FONT_SPR_FONT_RENDERER_H
#define AGS_PLUGINS_AGS_SPRITE_FONT_SPR_FONT_RENDERER_H
#include "ags/plugins/ags_sprite_font/sprite_font.h"
#include "ags/plugins/ags_plugin.h"
#include "common/std/vector.h"
namespace AGS3 {
namespace Plugins {
namespace AGSSpriteFont {
class SpriteFontRenderer : public IAGSFontRenderer2 {
protected:
IAGSEngine *_engine;
SpriteFont *getFontFor(int fontNum);
void Draw(BITMAP *src, BITMAP *dest, int destx, int desty, int srcx, int srcy, int width, int height, int colour);
std::vector<SpriteFont *> _fonts;
public:
SpriteFontRenderer(IAGSEngine *engine);
virtual ~SpriteFontRenderer();
void SetSpriteFont(int fontNum, int sprite, int rows, int columns, int charWidth, int charHeight, int charMin, int charMax, bool use32bit);
// IAGSFontRenderer implementation
bool LoadFromDisk(int fontNumber, int fontSize) override {
return true;
}
void FreeMemory(int fontNumber) override;
bool SupportsExtendedCharacters(int fontNumber) override;
int GetTextWidth(const char *text, int fontNumber) override;
int GetTextHeight(const char *text, int fontNumber) override;
void RenderText(const char *text, int fontNumber, BITMAP *destination, int x, int y, int colour) override;
void AdjustYCoordinateForFont(int *ycoord, int fontNumber) override { }
void EnsureTextValidForFont(char *text, int fontNumber) override;
// IAGSFontRenderer2 implementation
int GetVersion() override { return 26; /* compatible engine API ver */ }
const char *GetRendererName() override { return "SpriteFontRenderer"; }
const char *GetFontName(int fontNumber) override { return ""; /* not supported */ }
int GetFontHeight(int fontNumber) override;
int GetLineSpacing(int fontNumber) override { return 0; /* not specified */ }
};
} // namespace AGSSpriteFont
} // namespace Plugins
} // namespace AGS3
#endif

View File

@@ -0,0 +1,138 @@
/* 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
* 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/plugins/ags_sprite_font/sprite_font_renderer_clifftop.h"
#include "ags/plugins/ags_sprite_font/color.h"
namespace AGS3 {
namespace Plugins {
namespace AGSSpriteFont {
SpriteFontRendererClifftop::SpriteFontRendererClifftop(IAGSEngine *engine) : SpriteFontRenderer(engine) {
}
SpriteFontRendererClifftop::~SpriteFontRendererClifftop(void) {
}
bool SpriteFontRendererClifftop::SupportsExtendedCharacters(int fontNumber) {
return true;
}
void SpriteFontRendererClifftop::RenderText(const char *text, int fontNumber, BITMAP *destination, int x, int y, int colour) {
SpriteFont *font = getFontFor(fontNumber);
int len_text = (int)strlen(text);
for (int i = 0; i < len_text; i++) {
char c = text[i];
c -= font->MinChar;
int row = c / font->Columns;
int column = c % font->Columns;
BITMAP *src = _engine->GetSpriteGraphic(font->SpriteNumber);
Draw(src, destination, x + (i * font->CharWidth), y, column * font->CharWidth, row * font->CharHeight, font->CharWidth, font->CharHeight, colour);
}
}
void SpriteFontRendererClifftop::Draw(BITMAP *src, BITMAP *dest, int destx, int desty, int srcx, int srcy, int width, int height, int colour) {
int32 srcWidth = 0, srcHeight = 0, destWidth = 0, destHeight = 0, srcColDepth = 0, destColDepth = 0;
uint8 *srccharbuffer = _engine->GetRawBitmapSurface(src);
uint8 *destcharbuffer = _engine->GetRawBitmapSurface(dest);
uint32 transColor = _engine->GetBitmapTransparentColor(src);
int srcPitch = _engine->GetBitmapPitch(src);
int destPitch = _engine->GetBitmapPitch(dest);
_engine->GetBitmapDimensions(src, &srcWidth, &srcHeight, &srcColDepth);
_engine->GetBitmapDimensions(dest, &destWidth, &destHeight, &destColDepth);
int bpp = destColDepth / 8;
if (srcy + height > srcHeight || srcx + width > srcWidth || srcx < 0 || srcy < 0) return;
if (width + destx > destWidth) width = destWidth - destx;
if (height + desty > destHeight) height = destHeight - desty;
int startx = MAX(0, (-1 * destx));
int starty = MAX(0, (-1 * desty));
int srca, srcr, srcg, srcb, desta, destr, destg, destb, finalr, finalg, finalb, finala, col, col_r, col_g, col_b;
col_r = getr32(colour);
col_g = getg32(colour);
col_b = getb32(colour);
int srcxx = (startx + srcx) * bpp;
int destxx = (startx + destx) * bpp;
for (int x = startx; x < width; ++x, srcxx += bpp, destxx += bpp) {
int srcyy = (starty + srcy) * srcPitch;
int destyy = (starty + desty) * destPitch;
for (int y = starty; y < height; ++y, srcyy += srcPitch, destyy += destPitch) {
uint8 *srcCol = srccharbuffer + srcyy + srcxx;
uint8 *destCol = destcharbuffer + destyy + destxx;
if (destColDepth == 8) {
if (*srcCol != transColor)
*destCol = *srcCol;
} else if (destColDepth == 16) {
if (*((uint16 *)srcCol) != transColor)
*((uint16 *)destCol) = *((uint16 *)srcCol);
} else if (destColDepth == 32) {
//if (*((uint32*)srcCol) != transColor)
// *((uint32*)destCol) = *((uint32*)srcCol);
uint32 srcargb = *((uint32 *)srcCol);
uint32 &destargb = *((uint32 *)destCol);
srca = (geta32(srcargb));
if (srca != 0) {
srcr = getr32(srcargb);
srcg = getg32(srcargb);
srcb = getb32(srcargb);
destr = getr32(destargb);
destg = getg32(destargb);
destb = getb32(destargb);
desta = geta32(destargb);
finalr = (col_r * srcr) / 255;
finalg = (col_g * srcg) / 255;
finalb = (col_b * srcb) / 255;
finala = 255 - (255 - srca) * (255 - desta) / 255;
finalr = srca * col_r / finala + desta * destr * (255 - srca) / finala / 255;
finalg = srca * col_g / finala + desta * destg * (255 - srca) / finala / 255;
finalb = srca * col_b / finala + desta * destb * (255 - srca) / finala / 255;
col = makeacol32(finalr, finalg, finalb, finala);
destargb = col;
}
}
}
}
_engine->ReleaseBitmapSurface(src);
_engine->ReleaseBitmapSurface(dest);
}
} // namespace AGSSpriteFont
} // namespace Plugins
} // namespace AGS3

View File

@@ -0,0 +1,48 @@
/* 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
* 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/>.
*
*/
#ifndef AGS_PLUGINS_AGS_SPRITE_FONT_SPR_FONT_RENDERER_CLIFFTOP_H
#define AGS_PLUGINS_AGS_SPRITE_FONT_SPR_FONT_RENDERER_CLIFFTOP_H
#include "ags/plugins/ags_sprite_font/sprite_font_renderer.h"
namespace AGS3 {
namespace Plugins {
namespace AGSSpriteFont {
class SpriteFontRendererClifftop : public SpriteFontRenderer {
public:
SpriteFontRendererClifftop(IAGSEngine *engine);
~SpriteFontRendererClifftop(void) override;
bool SupportsExtendedCharacters(int fontNumber) override;
void RenderText(const char *text, int fontNumber, BITMAP *destination, int x, int y, int colour) override;
private:
void Draw(BITMAP *src, BITMAP *dest, int destx, int desty, int srcx, int srcy, int width, int height, int colour);
};
} // namespace AGSSpriteFont
} // namespace Plugins
} // namespace AGS3
#endif

View File

@@ -0,0 +1,44 @@
/* 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
* 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/plugins/ags_sprite_font/variable_width_font.h"
namespace AGS3 {
namespace Plugins {
namespace AGSSpriteFont {
void VariableWidthFont::SetGlyph(int character, int x, int y, int width, int height) {
characters[character].X = x;
characters[character].Y = y;
characters[character].Width = width;
characters[character].Height = height;
characters[character].Character = character;
}
void VariableWidthFont::SetLineHeightAdjust(int LineHeight, int SpacingHeight, int SpacingOverride) {
LineHeightAdjust = LineHeight;
LineSpacingAdjust = SpacingHeight;
LineSpacingOverride = SpacingOverride;
}
} // namespace AGSSpriteFont
} // namespace Plugins
} // namespace AGS3

View File

@@ -0,0 +1,53 @@
/* 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
* 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/>.
*
*/
#ifndef AGS_PLUGINS_AGS_SPRITE_FONT_VAR_WIDTH_FONT_H
#define AGS_PLUGINS_AGS_SPRITE_FONT_VAR_WIDTH_FONT_H
#include "ags/plugins/ags_sprite_font/character_entry.h"
#include "ags/plugins/ags_plugin.h"
#include "common/std/map.h"
namespace AGS3 {
namespace Plugins {
namespace AGSSpriteFont {
class VariableWidthFont {
public:
int SpriteNumber = 0;
int FontReplaced = 0;
int Spacing = 0;
std::map<char, CharacterEntry> characters;
// Clifftop Games custom plugin support
int LineHeightAdjust = 0;
int LineSpacingAdjust = 0;
int LineSpacingOverride = 0;
public:
void SetGlyph(int character, int x, int y, int width, int height);
void SetLineHeightAdjust(int LineHeight, int SpacingHeight, int SpacingOverride);
};
} // namespace AGSSpriteFont
} // namespace Plugins
} // namespace AGS3
#endif

View File

@@ -0,0 +1,260 @@
/* 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
* 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/plugins/ags_sprite_font/variable_width_sprite_font.h"
#include "ags/plugins/ags_sprite_font/color.h"
namespace AGS3 {
namespace Plugins {
namespace AGSSpriteFont {
VariableWidthSpriteFontRenderer::VariableWidthSpriteFontRenderer(IAGSEngine *engine) {
_engine = engine;
}
VariableWidthSpriteFontRenderer::~VariableWidthSpriteFontRenderer(void) {
}
void VariableWidthSpriteFontRenderer::FreeMemory(int fontNum) {
for(auto it = _fonts.begin(); it != _fonts.end() ; ++it) {
VariableWidthFont *font = *it;
if (font->FontReplaced == fontNum) {
_fonts.erase(it);
delete font;
return;
}
}
}
bool VariableWidthSpriteFontRenderer::SupportsExtendedCharacters(int fontNumber) {
return false;
}
int VariableWidthSpriteFontRenderer::GetTextWidth(const char *text, int fontNumber) {
int total = 0;
VariableWidthFont *font = getFontFor(fontNumber);
int len_text = (int)strlen(text);
for (int i = 0; i < len_text; i++) {
if (font->characters.count(text[i]) > 0) {
total += font->characters[text[i]].Width;
if (text[i] != ' ') total += font->Spacing;
}
}
return total;
}
int VariableWidthSpriteFontRenderer::GetTextHeight(const char *text, int fontNumber) {
VariableWidthFont *font = getFontFor(fontNumber);
int len_text = (int)strlen(text);
for (int i = 0; i < len_text; i++) {
if (font->characters.count(text[i]) > 0) {
return font->characters[text[i]].Height;
}
}
return 0;
}
int VariableWidthSpriteFontRenderer::GetFontHeight(int fontNumber) {
VariableWidthFont *font = getFontFor(fontNumber);
if (font->characters.size() > 0) {
return font->characters.begin()->_value.Height + font->LineSpacingAdjust;
}
return 0;
}
int VariableWidthSpriteFontRenderer::GetLineSpacing(int fontNumber) {
// CHECKME: it's not clear whether LineSpacingOverride was ever meant as an
// actual, normal line spacing. In Clifftop's custom engine this value has
// been used specifically to tell the spacing for *empty lines* when
// printing a wrapped text on a GUI Label. Official engine does not have
// such functionality.
return 0; // use default (font height)
}
void VariableWidthSpriteFontRenderer::SetSpacing(int fontNum, int spacing) {
VariableWidthFont *font = getFontFor(fontNum);
font->Spacing = spacing;
}
void VariableWidthSpriteFontRenderer::SetLineHeightAdjust(int fontNum, int lineHeight, int spacingHeight, int spacingOverride) {
VariableWidthFont *font = getFontFor(fontNum);
font->LineHeightAdjust = lineHeight;
font->LineSpacingAdjust = spacingHeight;
font->LineSpacingOverride = spacingOverride;
char buf[1024];
snprintf(buf, sizeof(buf),
"VariableWidth::SetLineHeightAdjust: font %d, lineHeight %d, spacingHeight %d, spacingOverride %d",
fontNum, lineHeight, spacingHeight, spacingOverride);
_engine->PrintDebugConsole(buf);
if (_engine->version >= 26)
_engine->NotifyFontUpdated(fontNum);
}
void VariableWidthSpriteFontRenderer::EnsureTextValidForFont(char *text, int fontNumber) {
VariableWidthFont *font = getFontFor(fontNumber);
Common::String s(text);
size_t ln = s.size();
for (int i = (int)s.size() - 1; i >= 0 ; i--) {
if (font->characters.count(s[i]) == 0) {
s.erase(i, 1);
}
}
// We never grow the text
Common::strcpy_s(text, ln + 1, s.c_str());
}
void VariableWidthSpriteFontRenderer::SetGlyph(int fontNum, int charNum, int x, int y, int width, int height) {
VariableWidthFont *font = getFontFor(fontNum);
font->SetGlyph(charNum, x, y, width, height);
// Only notify engine at the first engine glyph,
// that should be enough for calculating font height metrics,
// and will reduce work load (sadly there's no Begin/EndUpdate functions).
if ((_engine->version >= 26) && (font->characters.size() == 1))
_engine->NotifyFontUpdated(fontNum);
}
void VariableWidthSpriteFontRenderer::SetSprite(int fontNum, int spriteNum) {
VariableWidthFont *font = getFontFor(fontNum);
font->SpriteNumber = spriteNum;
}
VariableWidthFont *VariableWidthSpriteFontRenderer::getFontFor(int fontNum) {
VariableWidthFont *font;
for (int i = 0; i < (int)_fonts.size(); i ++) {
font = _fonts.at(i);
if (font->FontReplaced == fontNum) return font;
}
//not found
font = new VariableWidthFont;
font->FontReplaced = fontNum;
_fonts.push_back(font);
return font;
}
void VariableWidthSpriteFontRenderer::RenderText(const char *text, int fontNumber, BITMAP *destination, int x, int y, int colour) {
VariableWidthFont *font = getFontFor(fontNumber);
int totalWidth = 0;
int len_text = (int)strlen(text);
for (int i = 0; i < len_text; i++) {
char c = text[i];
BITMAP *src = _engine->GetSpriteGraphic(font->SpriteNumber);
Draw(src, destination, x + totalWidth, y, font->characters[c].X, font->characters[c].Y, font->characters[c].Width, font->characters[c].Height, colour);
totalWidth += font->characters[c].Width;
if (text[i] != ' ') totalWidth += font->Spacing;
}
}
void VariableWidthSpriteFontRenderer::Draw(BITMAP *src, BITMAP *dest, int destx, int desty, int srcx, int srcy, int width, int height, int colour) {
int32 srcWidth, srcHeight, destWidth, destHeight, srcColDepth, destColDepth;
uint8 *srccharbuffer = _engine->GetRawBitmapSurface(src);
uint8 *destcharbuffer = _engine->GetRawBitmapSurface(dest);
uint32 transColor = _engine->GetBitmapTransparentColor(src);
int srcPitch = _engine->GetBitmapPitch(src);
int destPitch = _engine->GetBitmapPitch(dest);
_engine->GetBitmapDimensions(src, &srcWidth, &srcHeight, &srcColDepth);
_engine->GetBitmapDimensions(dest, &destWidth, &destHeight, &destColDepth);
int bpp = destColDepth / 8;
if (srcy + height > srcHeight || srcx + width > srcWidth || srcx < 0 || srcy < 0) return;
if (width + destx > destWidth) width = destWidth - destx;
if (height + desty > destHeight) height = destHeight - desty;
int startx = MAX(0, (-1 * destx));
int starty = MAX(0, (-1 * desty));
int srca, srcr, srcg, srcb, desta, destr, destg, destb, finalr, finalg, finalb, finala, col, col_r, col_g, col_b;;
col_r = getr32(colour);
col_g = getg32(colour);
col_b = getb32(colour);
int srcxx = (startx + srcx) * bpp;
int destxx = (startx + destx) * bpp;
for (int x = startx; x < width; ++x, srcxx += bpp, destxx += bpp) {
int srcyy = (starty + srcy) * srcPitch;
int destyy = (starty + desty) * destPitch;
for (int y = starty; y < height; ++y, srcyy += srcPitch, destyy += destPitch) {
uint8 *srcCol = srccharbuffer + srcyy + srcxx;
uint8 *destCol = destcharbuffer + destyy + destxx;
if (destColDepth == 8) {
if (*srcCol != transColor)
*destCol = *srcCol;
} else if (destColDepth == 16) {
if (*((uint16 *)srcCol) != transColor)
*((uint16 *)destCol) = *((uint16 *)srcCol);
} else if (destColDepth == 32) {
//if (*((uint32*)srcCol) != transColor)
// *((uint32*)destCol) = *((uint32*)srcCol);
uint32 srcargb = *((uint32 *)srcCol);
uint32 &destargb = *((uint32 *)destCol);
srca = (geta32(srcargb));
if (srca != 0) {
srcr = getr32(srcargb);
srcg = getg32(srcargb);
srcb = getb32(srcargb);
destr = getr32(destargb);
destg = getg32(destargb);
destb = getb32(destargb);
desta = geta32(destargb);
finalr = (col_r * srcr) / 255;
finalg = (col_g * srcg) / 255;
finalb = (col_b * srcb) / 255;
finala = 255 - (255 - srca) * (255 - desta) / 255;
finalr = srca * finalr / finala + desta * destr * (255 - srca) / finala / 255;
finalg = srca * finalg / finala + desta * destg * (255 - srca) / finala / 255;
finalb = srca * finalb / finala + desta * destb * (255 - srca) / finala / 255;
col = makeacol32(finalr, finalg, finalb, finala);
destargb = col;
}
}
}
}
_engine->ReleaseBitmapSurface(src);
_engine->ReleaseBitmapSurface(dest);
}
} // namespace AGSSpriteFont
} // namespace Plugins
} // namespace AGS3

View File

@@ -0,0 +1,75 @@
/* 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
* 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/>.
*
*/
#ifndef AGS_PLUGINS_AGS_SPRITE_FONT_VAR_WIDTH_SPR_FONT_H
#define AGS_PLUGINS_AGS_SPRITE_FONT_VAR_WIDTH_SPR_FONT_H
#include "ags/plugins/plugin_base.h"
#include "ags/plugins/ags_plugin.h"
#include "ags/plugins/ags_sprite_font/variable_width_font.h"
namespace AGS3 {
namespace Plugins {
namespace AGSSpriteFont {
class VariableWidthSpriteFontRenderer : public IAGSFontRenderer2 {
protected:
IAGSEngine *_engine;
std::vector<VariableWidthFont *> _fonts;
VariableWidthFont *getFontFor(int fontNum);
void Draw(BITMAP *src, BITMAP *dest, int destx, int desty, int srcx, int srcy, int width, int height, int colour);
public:
VariableWidthSpriteFontRenderer(IAGSEngine *engine);
virtual ~VariableWidthSpriteFontRenderer();
void SetGlyph(int fontNum, int charNum, int x, int y, int width, int height);
void SetSprite(int fontNum, int spriteNum);
void SetSpacing(int fontNum, int spacing);
// Clifftop Games custom plugin support
void SetLineHeightAdjust(int fontNum, int LineHeight, int SpacingHeight, int SpacingOverride);
// IAGSFontRenderer implementation
bool LoadFromDisk(int fontNumber, int fontSize) override {
return true;
}
void FreeMemory(int fontNumber) override;
bool SupportsExtendedCharacters(int fontNumber) override;
int GetTextWidth(const char *text, int fontNumber) override;
int GetTextHeight(const char *text, int fontNumber) override;
void RenderText(const char *text, int fontNumber, BITMAP *destination, int x, int y, int colour) override;
void AdjustYCoordinateForFont(int *ycoord, int fontNumber) override { }
void EnsureTextValidForFont(char *text, int fontNumber) override;
// IAGSFontRenderer2 implementation
int GetVersion() override { return 26; /* compatible engine API ver */ }
const char *GetRendererName() override { return "VariableWidthSpriteFontRenderer"; }
const char *GetFontName(int fontNumber) override { return ""; /* not supported */ }
int GetFontHeight(int fontNumber) override;
int GetLineSpacing(int fontNumber) override;
};
} // namespace AGSSpriteFont
} // namespace Plugins
} // namespace AGS3
#endif

View File

@@ -0,0 +1,136 @@
/* 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
* 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/plugins/ags_sprite_font/variable_width_sprite_font_clifftop.h"
#include "ags/plugins/ags_sprite_font/color.h"
namespace AGS3 {
namespace Plugins {
namespace AGSSpriteFont {
VariableWidthSpriteFontRendererClifftop::VariableWidthSpriteFontRendererClifftop(IAGSEngine *engine) : VariableWidthSpriteFontRenderer(engine) {
}
VariableWidthSpriteFontRendererClifftop::~VariableWidthSpriteFontRendererClifftop(void) {
}
void VariableWidthSpriteFontRendererClifftop::RenderText(const char *text, int fontNumber, BITMAP *destination, int x, int y, int colour) {
VariableWidthFont *font = getFontFor(fontNumber);
int totalWidth = 0;
int len_text = (int)strlen(text);
for (int i = 0; i < len_text; i++) {
char c = text[i];
BITMAP *src = _engine->GetSpriteGraphic(font->SpriteNumber);
Draw(src, destination, x + totalWidth, y, font->characters[c].X, font->characters[c].Y, font->characters[c].Width, font->characters[c].Height, colour);
totalWidth += font->characters[c].Width;
if (text[i] != ' ') totalWidth += font->Spacing;
}
}
void VariableWidthSpriteFontRendererClifftop::Draw(BITMAP *src, BITMAP *dest, int destx, int desty, int srcx, int srcy, int width, int height, int colour) {
int32 srcWidth, srcHeight, destWidth, destHeight, srcColDepth, destColDepth;
uint8 *srccharbuffer = _engine->GetRawBitmapSurface(src);
uint8 *destcharbuffer = _engine->GetRawBitmapSurface(dest);
uint32 transColor = _engine->GetBitmapTransparentColor(src);
int srcPitch = _engine->GetBitmapPitch(src);
int destPitch = _engine->GetBitmapPitch(dest);
_engine->GetBitmapDimensions(src, &srcWidth, &srcHeight, &srcColDepth);
_engine->GetBitmapDimensions(dest, &destWidth, &destHeight, &destColDepth);
int bpp = destColDepth / 8;
if (srcy + height > srcHeight || srcx + width > srcWidth || srcx < 0 || srcy < 0) return;
if (width + destx > destWidth) width = destWidth - destx;
if (height + desty > destHeight) height = destHeight - desty;
int startx = MAX(0, (-1 * destx));
int starty = MAX(0, (-1 * desty));
int srca, srcr, srcg, srcb, desta, destr, destg, destb, finalr, finalg, finalb, finala, col, col_r, col_g, col_b;
col_r = getr32(colour);
col_g = getg32(colour);
col_b = getb32(colour);
int srcxx = (startx + srcx) * bpp;
int destxx = (startx + destx) * bpp;
for (int x = startx; x < width; ++x, srcxx += bpp, destxx += bpp) {
int srcyy = (starty + srcy) * srcPitch;
int destyy = (starty + desty) * destPitch;
for (int y = starty; y < height; ++y, srcyy += srcPitch, destyy += destPitch) {
uint8 *srcCol = srccharbuffer + srcyy + srcxx;
uint8 *destCol = destcharbuffer + destyy + destxx;
if (destColDepth == 8) {
if (*srcCol != transColor)
*destCol = *srcCol;
} else if (destColDepth == 16) {
if (*((uint16 *)srcCol) != transColor)
*((uint16 *)destCol) = *((uint16 *)srcCol);
} else if (destColDepth == 32) {
//if (*((uint32*)srcCol) != transColor)
// *((uint32*)destCol) = *((uint32*)srcCol);
uint32 srcargb = *((uint32 *)srcCol);
uint32 &destargb = *((uint32 *)destCol);
srca = (geta32(srcargb));
if (srca != 0) {
srcr = getr32(srcargb);
srcg = getg32(srcargb);
srcb = getb32(srcargb);
destr = getr32(destargb);
destg = getg32(destargb);
destb = getb32(destargb);
desta = geta32(destargb);
finalr = (col_r * srcr) / 255;
finalg = (col_g * srcg) / 255;
finalb = (col_b * srcb) / 255;
finala = 255 - (255 - srca) * (255 - desta) / 255;
finalr = srca * finalr / finala + desta * destr * (255 - srca) / finala / 255;
finalg = srca * finalg / finala + desta * destg * (255 - srca) / finala / 255;
finalb = srca * finalb / finala + desta * destb * (255 - srca) / finala / 255;
col = makeacol32(finalr, finalg, finalb, finala);
destargb = col;
}
}
}
}
_engine->ReleaseBitmapSurface(src);
_engine->ReleaseBitmapSurface(dest);
}
} // namespace AGSSpriteFont
} // namespace Plugins
} // namespace AGS3

View File

@@ -0,0 +1,48 @@
/* 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
* 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/>.
*
*/
#ifndef AGS_PLUGINS_AGS_SPRITE_FONT_VAR_WIDTH_SPR_FONT_CLIFFTOP_H
#define AGS_PLUGINS_AGS_SPRITE_FONT_VAR_WIDTH_SPR_FONT_CLIFFTOP_H
#include "ags/plugins/ags_sprite_font/variable_width_sprite_font.h"
namespace AGS3 {
namespace Plugins {
namespace AGSSpriteFont {
class VariableWidthSpriteFontRendererClifftop : public VariableWidthSpriteFontRenderer {
private:
void Draw(BITMAP *src, BITMAP *dest, int destx, int desty, int srcx, int srcy, int width, int height, int colour);
public:
VariableWidthSpriteFontRendererClifftop(IAGSEngine *engine);
~VariableWidthSpriteFontRendererClifftop(void) override;
void RenderText(const char *text, int fontNumber, BITMAP *destination, int x, int y, int colour) override;
};
} // namespace AGSSpriteFont
} // namespace Plugins
} // namespace AGS3
#endif