From 5636181b78bcffa934cb00b14edb68c2d3319139 Mon Sep 17 00:00:00 2001 From: Strangerke Date: Mon, 7 Dec 2015 07:48:54 +0100 Subject: LAB: Move text functions to DisplayMan, some renaming --- engines/lab/engine.cpp | 4 +- engines/lab/graphics.cpp | 128 ++++++++++++++++++++++++++++++++++++-- engines/lab/graphics.h | 13 ++++ engines/lab/intro.cpp | 2 +- engines/lab/intro.h | 1 - engines/lab/map.cpp | 2 - engines/lab/module.mk | 1 - engines/lab/resource.cpp | 13 ++-- engines/lab/resource.h | 1 - engines/lab/special.cpp | 13 ++-- engines/lab/text.cpp | 156 ----------------------------------------------- engines/lab/text.h | 59 ------------------ engines/lab/vga.cpp | 33 ---------- 13 files changed, 150 insertions(+), 276 deletions(-) delete mode 100644 engines/lab/text.cpp delete mode 100644 engines/lab/text.h delete mode 100644 engines/lab/vga.cpp (limited to 'engines') diff --git a/engines/lab/engine.cpp b/engines/lab/engine.cpp index 80035f3877..ce89225560 100644 --- a/engines/lab/engine.cpp +++ b/engines/lab/engine.cpp @@ -32,7 +32,6 @@ #include "lab/labfun.h" #include "lab/anim.h" #include "lab/image.h" -#include "lab/text.h" #include "lab/intro.h" #include "lab/parsefun.h" #include "lab/interface.h" @@ -1076,8 +1075,7 @@ void LabEngine::go() { } } - closeFont(_msgFont); - + _graphics->closeFont(_msgFont); _graphics->freePict(); freeScreens(); diff --git a/engines/lab/graphics.cpp b/engines/lab/graphics.cpp index 375ab228c6..857c25291d 100644 --- a/engines/lab/graphics.cpp +++ b/engines/lab/graphics.cpp @@ -34,7 +34,6 @@ #include "lab/image.h" #include "lab/labfun.h" #include "lab/parsefun.h" -#include "lab/text.h" #include "lab/resource.h" #include "lab/graphics.h" @@ -208,7 +207,7 @@ static void getWord(char *wordBuffer, const char *mainBuffer, uint16 *wordWidth) /* Gets a line of text for flowText; makes sure that its length is less than */ /* or equal to the maximum width. */ /******************************************************************************/ -static void getLine(TextFont *tf, char *lineBuffer, const char **mainBuffer, uint16 lineWidth) { +void DisplayMan::getLine(TextFont *tf, char *lineBuffer, const char **mainBuffer, uint16 lineWidth) { uint16 curWidth = 0, wordWidth; char wordBuffer[100]; bool doit = true; @@ -1159,9 +1158,128 @@ void DisplayMan::fade(bool fadein, uint16 res) { (0xF00 & fadeNumOut(0xF00 & FadePalette[palIdx], 0xF00 & res, i)); } - g_lab->_graphics->setAmigaPal(newpal, 16); - g_lab->waitTOF(); - g_lab->_music->updateMusic(); + setAmigaPal(newpal, 16); + _vm->waitTOF(); + _vm->_music->updateMusic(); + } +} + +/*****************************************************************************/ +/* Closes a font and frees all memory associated with it. */ +/*****************************************************************************/ +void DisplayMan::closeFont(TextFont *tf) { + if (tf) { + if (tf->_data && tf->_dataLength) + delete[] tf->_data; + + delete tf; + } +} + +/*****************************************************************************/ +/* Returns the length of a text in the specified font. */ +/*****************************************************************************/ +uint16 DisplayMan::textLength(TextFont *tf, const char *text, uint16 numchars) { + uint16 length = 0; + + if (tf) { + for (uint16 i = 0; i < numchars; i++) { + length += tf->_widths[(uint)*text]; + text++; + } + } + + return length; +} + +/*****************************************************************************/ +/* Returns the height of a specified font. */ +/*****************************************************************************/ +uint16 DisplayMan::textHeight(TextFont *tf) { + return (tf) ? tf->_height : 0; +} + +/*****************************************************************************/ +/* Draws the text to the screen. */ +/*****************************************************************************/ +void DisplayMan::text(TextFont *tf, uint16 x, uint16 y, uint16 color, const char *text, uint16 numchars) { + byte *VGATop, *VGACur, *VGATemp, *VGATempLine, *cdata; + uint32 RealOffset, SegmentOffset; + int32 templeft, LeftInSegment; + uint16 bwidth, mask, curpage, data; + + VGATop = getCurrentDrawingBuffer(); + + for (uint16 i = 0; i < numchars; i++) { + RealOffset = (_screenWidth * y) + x; + curpage = RealOffset / _screenBytesPerPage; + SegmentOffset = RealOffset - (curpage * _screenBytesPerPage); + LeftInSegment = _screenBytesPerPage - SegmentOffset; + VGACur = VGATop + SegmentOffset; + + if (tf->_widths[(uint)*text]) { + cdata = tf->_data + tf->_offsets[(uint)*text]; + bwidth = *cdata++; + VGATemp = VGACur; + VGATempLine = VGACur; + + for (uint16 rows = 0; rows < tf->_height; rows++) { + VGATemp = VGATempLine; + templeft = LeftInSegment; + + for (uint16 cols = 0; cols < bwidth; cols++) { + data = *cdata++; + + if (data && (templeft >= 8)) { + for (int j = 7; j >= 0; j--) { + if ((1 << j) & data) + *VGATemp = color; + VGATemp++; + } + + templeft -= 8; + } else if (data) { + mask = 0x80; + templeft = LeftInSegment; + + for (uint16 counterb = 0; counterb < 8; counterb++) { + if (templeft <= 0) { + curpage++; + VGATemp = (byte *)(VGATop - templeft); + /* Set up VGATempLine for next line */ + VGATempLine -= _screenBytesPerPage; + /* Set up LeftInSegment for next line */ + LeftInSegment += _screenBytesPerPage + templeft; + templeft += _screenBytesPerPage; + } + + if (mask & data) + *VGATemp = color; + + VGATemp++; + + mask = mask >> 1; + templeft--; + } + } else { + templeft -= 8; + VGATemp += 8; + } + } + + VGATempLine += _screenWidth; + LeftInSegment -= _screenWidth; + + if (LeftInSegment <= 0) { + curpage++; + VGATempLine -= _screenBytesPerPage; + LeftInSegment += _screenBytesPerPage; + } + } + } + + x += tf->_widths[(int)*text]; + text++; } } } // End of namespace Lab diff --git a/engines/lab/graphics.h b/engines/lab/graphics.h index 564f041607..5d97507c19 100644 --- a/engines/lab/graphics.h +++ b/engines/lab/graphics.h @@ -37,6 +37,14 @@ namespace Lab { class LabEngine; +struct TextFont { + uint32 _dataLength; + uint16 _height; + byte _widths[256]; + uint16 _offsets[256]; + byte *_data; +}; + class DisplayMan { private: LabEngine *_vm; @@ -129,6 +137,11 @@ public: void scrollDisplayX(int16 dx, uint16 x1, uint16 y1, uint16 x2, uint16 y2); void scrollDisplayY(int16 dy, uint16 x1, uint16 y1, uint16 x2, uint16 y2); void fade(bool fadein, uint16 res); + void closeFont(TextFont *tf); + uint16 textLength(TextFont *tf, const char *text, uint16 numchars); + uint16 textHeight(TextFont *tf); + void text(TextFont *tf, uint16 x, uint16 y, uint16 color, const char *text, uint16 numchars); + void getLine(TextFont *tf, char *lineBuffer, const char **mainBuffer, uint16 lineWidth); bool _longWinInFront; bool _lastMessageLong; diff --git a/engines/lab/intro.cpp b/engines/lab/intro.cpp index 7727ac1f93..4b0ed66f56 100644 --- a/engines/lab/intro.cpp +++ b/engines/lab/intro.cpp @@ -444,7 +444,7 @@ void Intro::introSequence() { _vm->_anim->_doBlack = true; } - closeFont(msgFont); + _vm->_graphics->closeFont(msgFont); } } // End of namespace Lab diff --git a/engines/lab/intro.h b/engines/lab/intro.h index 47b61daeca..c532bdfa1e 100644 --- a/engines/lab/intro.h +++ b/engines/lab/intro.h @@ -32,7 +32,6 @@ #define LAB_INTRO_H #include "lab/intro.h" -#include "lab/text.h" namespace Lab { diff --git a/engines/lab/map.cpp b/engines/lab/map.cpp index 7256562988..b7006a3dc9 100644 --- a/engines/lab/map.cpp +++ b/engines/lab/map.cpp @@ -32,12 +32,10 @@ #include "lab/labfun.h" #include "lab/anim.h" #include "lab/image.h" -#include "lab/text.h" #include "lab/parsefun.h" #include "lab/parsetypes.h" #include "lab/resource.h" #include "lab/interface.h" -#include "lab/text.h" namespace Lab { diff --git a/engines/lab/module.mk b/engines/lab/module.mk index 3985b1415f..5c0aed5783 100644 --- a/engines/lab/module.mk +++ b/engines/lab/module.mk @@ -17,7 +17,6 @@ MODULE_OBJS := \ resource.o \ savegame.o \ special.o \ - text.o \ tilepuzzle.o \ timing.o diff --git a/engines/lab/resource.cpp b/engines/lab/resource.cpp index c6c11059a4..f76aea0087 100644 --- a/engines/lab/resource.cpp +++ b/engines/lab/resource.cpp @@ -29,7 +29,6 @@ */ #include "lab/lab.h" -#include "lab/text.h" #include "lab/resource.h" namespace Lab { @@ -58,14 +57,14 @@ TextFont *Resource::getFont(const char *fileName) { _vm->_music->updateMusic(); TextFont *textfont = new TextFont(); - textfont->DataLength = fileSize - headerSize; - textfont->Height = dataFile->readUint16LE(); - dataFile->read(textfont->Widths, 256); + textfont->_dataLength = fileSize - headerSize; + textfont->_height = dataFile->readUint16LE(); + dataFile->read(textfont->_widths, 256); for (int i = 0; i < 256; i++) - textfont->Offsets[i] = dataFile->readUint16LE(); + textfont->_offsets[i] = dataFile->readUint16LE(); dataFile->skip(4); - textfont->data = new byte[textfont->DataLength + 4]; - dataFile->read(textfont->data, textfont->DataLength); + textfont->_data = new byte[textfont->_dataLength + 4]; + dataFile->read(textfont->_data, textfont->_dataLength); return textfont; } diff --git a/engines/lab/resource.h b/engines/lab/resource.h index 99996a1475..e050a156cb 100644 --- a/engines/lab/resource.h +++ b/engines/lab/resource.h @@ -32,7 +32,6 @@ #define LAB_RESOURCE_H #include "lab/labfun.h" -#include "lab/text.h" namespace Lab { diff --git a/engines/lab/special.cpp b/engines/lab/special.cpp index 0bed4181dd..6642865cda 100644 --- a/engines/lab/special.cpp +++ b/engines/lab/special.cpp @@ -39,7 +39,6 @@ #include "lab/parsefun.h" #include "lab/interface.h" #include "lab/anim.h" -#include "lab/text.h" #include "lab/parsetypes.h" #include "lab/resource.h" @@ -105,7 +104,7 @@ void LabEngine::doNotes() { g_lab->_graphics->flowText(noteFont, -2 + g_lab->_graphics->SVGACord(1), 0, 0, false, false, true, true, g_lab->_graphics->VGAScaleX(25) + g_lab->_graphics->SVGACord(15), g_lab->_graphics->VGAScaleY(50), g_lab->_graphics->VGAScaleX(295) - g_lab->_graphics->SVGACord(15), g_lab->_graphics->VGAScaleY(148), ntext); g_lab->_graphics->setPalette(g_lab->_anim->_diffPalette, 256); - closeFont(noteFont); + g_lab->_graphics->closeFont(noteFont); delete[] ntext; } @@ -123,7 +122,7 @@ void LabEngine::doWestPaper() { paperFont = g_lab->_resource->getFont("P:News22.fon"); ntext = g_lab->_resource->getText("Lab:Rooms/Date"); g_lab->_graphics->flowText(paperFont, 0, 0, 0, false, true, false, true, g_lab->_graphics->VGAScaleX(57), g_lab->_graphics->VGAScaleY(77) + g_lab->_graphics->SVGACord(2), g_lab->_graphics->VGAScaleX(262), g_lab->_graphics->VGAScaleY(91), ntext); - closeFont(paperFont); + g_lab->_graphics->closeFont(paperFont); delete[] ntext; paperFont = g_lab->_resource->getFont("P:News32.fon"); @@ -135,7 +134,7 @@ void LabEngine::doWestPaper() { g_lab->_graphics->flowText(paperFont, -8 - g_lab->_graphics->SVGACord(1), 0, 0, false, true, false, true, g_lab->_graphics->VGAScaleX(57), g_lab->_graphics->VGAScaleY(86) - g_lab->_graphics->SVGACord(2), g_lab->_graphics->VGAScaleX(262), g_lab->_graphics->VGAScaleY(132), ntext); } else y = 115 - g_lab->_graphics->SVGACord(5); - closeFont(paperFont); + g_lab->_graphics->closeFont(paperFont); delete[] ntext; paperFont = g_lab->_resource->getFont("P:Note.fon"); @@ -145,7 +144,7 @@ void LabEngine::doWestPaper() { ntext = g_lab->_resource->getText("Lab:Rooms/Col2"); CharsPrinted = g_lab->_graphics->flowTextScaled(paperFont, -4, 0, 0, false, false, false, true, 162, y, 275, 148, ntext); delete[] ntext; - closeFont(paperFont); + g_lab->_graphics->closeFont(paperFont); g_lab->_graphics->setPalette(g_lab->_anim->_diffPalette, 256); } @@ -470,7 +469,7 @@ void LabEngine::drawMonText(char *text, TextFont *monitorFont, uint16 x1, uint16 numlines += (*text - '0'); text += 2; - fheight = textHeight(monitorFont); + fheight = g_lab->_graphics->textHeight(monitorFont); x1 = MonButton->_width + _graphics->VGAScaleX(3); MonGadHeight = MonButton->_height + _graphics->VGAScaleY(3); @@ -645,7 +644,7 @@ void LabEngine::doMonitor(char *background, char *textfile, bool isinteractive, _graphics->fade(false, 0); _event->mouseHide(); delete[] ntext; - closeFont(monitorFont); + g_lab->_graphics->closeFont(monitorFont); _graphics->setAPen(0); _graphics->rectFill(0, 0, _graphics->_screenWidth - 1, _graphics->_screenHeight - 1); diff --git a/engines/lab/text.cpp b/engines/lab/text.cpp deleted file mode 100644 index f784c2126d..0000000000 --- a/engines/lab/text.cpp +++ /dev/null @@ -1,156 +0,0 @@ -/* 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. - * - */ - -/* - * This code is based on Labyrinth of Time code with assistance of - * - * Copyright (c) 1993 Terra Nova Development - * Copyright (c) 2004 The Wyrmkeep Entertainment Co. - * - */ - -#include "lab/lab.h" -#include "lab/labfun.h" -#include "lab/text.h" - -namespace Lab { - -/*****************************************************************************/ -/* Closes a font and frees all memory associated with it. */ -/*****************************************************************************/ -void closeFont(TextFont *tf) { - if (tf) { - if (tf->data && tf->DataLength) - delete[] tf->data; - - delete tf; - } -} - -/*****************************************************************************/ -/* Returns the length of a text in the specified font. */ -/*****************************************************************************/ -uint16 textLength(TextFont *tf, const char *text, uint16 numchars) { - uint16 length = 0; - - if (tf) { - for (uint16 i = 0; i < numchars; i++) { - length += tf->Widths[(uint)*text]; - text++; - } - } - - return length; -} - -/*****************************************************************************/ -/* Returns the height of a specified font. */ -/*****************************************************************************/ -uint16 textHeight(TextFont *tf) { - return (tf) ? tf->Height : 0; -} - -/*****************************************************************************/ -/* Draws the text to the screen. */ -/*****************************************************************************/ -void text(TextFont *tf, uint16 x, uint16 y, uint16 color, const char *text, uint16 numchars) { - byte *VGATop, *VGACur, *VGATemp, *VGATempLine, *cdata; - uint32 RealOffset, SegmentOffset; - int32 templeft, LeftInSegment; - uint16 bwidth, mask, curpage, data; - - VGATop = g_lab->_graphics->getCurrentDrawingBuffer(); - - for (uint16 i = 0; i < numchars; i++) { - RealOffset = (g_lab->_graphics->_screenWidth * y) + x; - curpage = RealOffset / g_lab->_graphics->_screenBytesPerPage; - SegmentOffset = RealOffset - (curpage * g_lab->_graphics->_screenBytesPerPage); - LeftInSegment = g_lab->_graphics->_screenBytesPerPage - SegmentOffset; - VGACur = VGATop + SegmentOffset; - - if (tf->Widths[(uint)*text]) { - cdata = tf->data + tf->Offsets[(uint)*text]; - bwidth = *cdata++; - VGATemp = VGACur; - VGATempLine = VGACur; - - for (uint16 rows = 0; rows < tf->Height; rows++) { - VGATemp = VGATempLine; - templeft = LeftInSegment; - - for (uint16 cols = 0; cols < bwidth; cols++) { - data = *cdata++; - - if (data && (templeft >= 8)) { - for (int j = 7; j >= 0; j--) { - if ((1 << j) & data) - *VGATemp = color; - VGATemp++; - } - - templeft -= 8; - } else if (data) { - mask = 0x80; - templeft = LeftInSegment; - - for (uint16 counterb = 0; counterb < 8; counterb++) { - if (templeft <= 0) { - curpage++; - VGATemp = (byte *)(VGATop - templeft); - /* Set up VGATempLine for next line */ - VGATempLine -= g_lab->_graphics->_screenBytesPerPage; - /* Set up LeftInSegment for next line */ - LeftInSegment += g_lab->_graphics->_screenBytesPerPage + templeft; - templeft += g_lab->_graphics->_screenBytesPerPage; - } - - if (mask & data) - *VGATemp = color; - - VGATemp++; - - mask = mask >> 1; - templeft--; - } - } else { - templeft -= 8; - VGATemp += 8; - } - } - - VGATempLine += g_lab->_graphics->_screenWidth; - LeftInSegment -= g_lab->_graphics->_screenWidth; - - if (LeftInSegment <= 0) { - curpage++; - VGATempLine -= g_lab->_graphics->_screenBytesPerPage; - LeftInSegment += g_lab->_graphics->_screenBytesPerPage; - } - } - } - - x += tf->Widths[(int)*text]; - text++; - } -} - -} // End of namespace Lab diff --git a/engines/lab/text.h b/engines/lab/text.h deleted file mode 100644 index 7401f02661..0000000000 --- a/engines/lab/text.h +++ /dev/null @@ -1,59 +0,0 @@ -/* 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. - * - */ - -/* - * This code is based on Labyrinth of Time code with assistance of - * - * Copyright (c) 1993 Terra Nova Development - * Copyright (c) 2004 The Wyrmkeep Entertainment Co. - * - */ - -#ifndef LAB_TEXT_H -#define LAB_TEXT_H - -namespace Lab { - -#if defined(WIN32) -#pragma pack(push, 1) -#endif - -struct TextFont { - uint32 DataLength; - uint16 Height; - byte Widths[256]; - uint16 Offsets[256]; - byte *data; -}; - -#if defined(WIN32) -#pragma pack(pop) -#endif - -void closeFont(TextFont *tf); -uint16 textLength(TextFont *tf, const char *text, uint16 numchars); -uint16 textHeight(TextFont *tf); -void text(TextFont *tf, uint16 x, uint16 y, uint16 color, const char *text, uint16 numchars); - -} // End of namespace Lab - -#endif /* LAB_TEXT_H */ diff --git a/engines/lab/vga.cpp b/engines/lab/vga.cpp deleted file mode 100644 index b80f338c1e..0000000000 --- a/engines/lab/vga.cpp +++ /dev/null @@ -1,33 +0,0 @@ -/* 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. - * - */ - -/* - * This code is based on Labyrinth of Time code with assistance of - * - * Copyright (c) 1993 Terra Nova Development - * Copyright (c) 2004 The Wyrmkeep Entertainment Co. - * - */ - -namespace Lab { - -} // End of namespace Lab -- cgit v1.2.3