scummvm/engines/tony/font.h

375 lines
8.8 KiB
C
Raw Normal View History

/* 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/>.
*
*/
2012-05-14 05:43:50 +00:00
/*
* This code is based on original Tony Tough source code
*
* Copyright (c) 1997-2003 Nayma Software
*/
#ifndef TONY_FONT_H
#define TONY_FONT_H
#include "common/system.h"
#include "common/coroutines.h"
#include "tony/gfxcore.h"
#include "tony/resid.h"
namespace Tony {
2012-05-01 14:23:41 +00:00
class RMInput;
class RMInventory;
class RMItem;
2012-05-01 14:23:41 +00:00
class RMLoc;
class RMLocation;
class RMPointer;
/**
* Manages a font, in which there is a different surface for each letter
*/
class RMFont : public RMGfxTaskSetPrior {
protected:
2012-06-10 22:34:45 +00:00
int _nLetters;
2012-06-06 06:04:33 +00:00
RMGfxSourceBuffer8RLEByte *_letter;
public:
2012-06-06 06:04:33 +00:00
int _fontDimx, _fontDimy;
private:
2012-06-06 06:04:33 +00:00
int _dimx, _dimy;
2012-05-14 19:29:27 +00:00
class RMFontPrimitive : public RMGfxPrimitive {
public:
2012-06-13 22:11:56 +00:00
RMFontPrimitive() : RMGfxPrimitive() { _nChar = 0; }
RMFontPrimitive(RMGfxTask *task) : RMGfxPrimitive(task) { _nChar = 0; }
2020-02-09 11:05:33 +00:00
~RMFontPrimitive() override { }
RMGfxPrimitive *duplicate() override {
2012-05-14 19:29:27 +00:00
return new RMFontPrimitive(*this);
}
2012-06-06 06:04:33 +00:00
int _nChar;
2012-05-14 19:29:27 +00:00
};
protected:
// Loads the font
2012-06-06 06:04:33 +00:00
void load(uint32 resID, int nChars, int dimx, int dimy, uint32 palResID = RES_F_PAL);
void load(const byte *buf, int nChars, int dimx, int dimy, uint32 palResID = RES_F_PAL);
// Remove the font
void unload();
protected:
// Conversion form character to font index
2012-06-06 06:04:33 +00:00
virtual int convertToLetter(byte nChar) = 0;
// Character width
2012-06-06 06:04:33 +00:00
virtual int letterLength(int nChar, int nNext = 0) = 0;
public:
virtual int letterHeight() = 0;
public:
2012-05-14 19:29:27 +00:00
RMFont();
2020-02-09 11:05:33 +00:00
~RMFont() override;
// Initialization and closing
virtual void init() = 0;
virtual void close();
// Drawing
2020-02-09 11:05:33 +00:00
void draw(CORO_PARAM, RMGfxTargetBuffer &bigBug, RMGfxPrimitive *prim) override;
// Create a primitive for a letter
2012-06-06 06:04:33 +00:00
RMGfxPrimitive *makeLetterPrimitive(byte bChar, int &nLength);
// Length in pixels of a string with the current font
int stringLen(const Common::String &text);
2012-06-06 06:04:33 +00:00
int stringLen(char bChar, char bNext = 0);
};
class RMFontColor : public virtual RMFont {
private:
2012-06-10 22:34:45 +00:00
byte _fontR, _fontG, _fontB;
public:
2012-05-14 19:29:27 +00:00
RMFontColor();
2020-02-09 11:05:33 +00:00
~RMFontColor() override;
virtual void setBaseColor(byte r, byte g, byte b);
};
class RMFontWithTables : public virtual RMFont {
protected:
2012-06-10 22:34:45 +00:00
int _cTable[256];
int _lTable[256];
int _lDefault;
int _hDefault;
signed char _l2Table[256][256];
protected:
// Overloaded methods
2020-02-09 11:05:33 +00:00
int convertToLetter(byte nChar) override;
int letterLength(int nChar, int nNext = 0) override;
2012-05-14 19:29:27 +00:00
public:
2020-02-09 11:05:33 +00:00
int letterHeight() override {
2012-06-10 22:34:45 +00:00
return _hDefault;
2012-05-14 19:29:27 +00:00
}
2020-02-09 11:05:33 +00:00
~RMFontWithTables() override {}
};
2012-06-18 06:28:13 +00:00
class RMFontDialog : public RMFontColor, public RMFontWithTables {
public:
2020-02-09 11:05:33 +00:00
void init() override;
~RMFontDialog() override {}
};
class RMFontObj : public RMFontColor, public RMFontWithTables {
private:
2012-06-06 06:04:33 +00:00
void setBothCase(int nChar, int nNext, signed char spiazz);
public:
2020-02-09 11:05:33 +00:00
void init() override;
~RMFontObj() override {}
};
class RMFontMacc : public RMFontColor, public RMFontWithTables {
public:
2020-02-09 11:05:33 +00:00
void init() override;
~RMFontMacc() override {}
};
class RMFontCredits : public RMFontColor, public RMFontWithTables {
public:
2020-02-09 11:05:33 +00:00
void init() override;
~RMFontCredits() override {}
void setBaseColor(byte r, byte g, byte b) override {}
};
/**
* Manages writing text onto9 the screen
*/
class RMText : public RMGfxWoodyBuffer {
private:
2012-06-06 06:04:33 +00:00
static RMFontColor *_fonts[4];
2012-06-10 22:34:45 +00:00
int _maxLineLength;
public:
enum HorAlign {
HLEFT,
HLEFTPAR,
HCENTER,
HRIGHT
2012-05-14 19:29:27 +00:00
};
enum VerAlign {
VTOP,
VCENTER,
VBOTTOM
2012-05-14 19:29:27 +00:00
};
private:
HorAlign _aHorType;
VerAlign _aVerType;
2012-06-10 22:34:45 +00:00
byte _textR, _textG, _textB;
protected:
2012-06-06 06:04:33 +00:00
virtual void clipOnScreen(RMGfxPrimitive *prim);
public:
2012-05-14 19:29:27 +00:00
RMText();
2020-02-09 11:05:33 +00:00
~RMText() override;
2012-06-05 06:39:55 +00:00
static void initStatics();
2012-06-06 06:04:33 +00:00
static void unload();
// Set the alignment type
2012-09-02 08:34:11 +00:00
void setAlignType(HorAlign aHor, VerAlign aVer);
2012-05-14 19:29:27 +00:00
// Sets the maximum length of a line in pixels (used to format the text)
2012-06-06 06:04:33 +00:00
void setMaxLineLength(int max);
// Write the text
void writeText(const Common::String &text, int font, int *time = NULL);
void writeText(Common::String text, RMFontColor *font, int *time = NULL);
// Overloaded function to decide when you delete the object from the OT list
2020-02-09 11:05:33 +00:00
void removeThis(CORO_PARAM, bool &result) override;
// Overloading of the Draw to center the text, if necessary
2020-02-09 11:05:33 +00:00
void draw(CORO_PARAM, RMGfxTargetBuffer &bigBuf, RMGfxPrimitive *prim) override;
// Set the base color
2012-09-02 08:34:11 +00:00
void setColor(byte r, byte g, byte b);
};
/**
* Manages text in a dialog
*/
2012-05-01 14:23:41 +00:00
class RMTextDialog : public RMText {
2012-05-14 19:29:27 +00:00
protected:
2012-06-06 06:04:33 +00:00
int _startTime;
int _time;
bool _bSkipStatus;
2012-06-10 22:34:45 +00:00
RMPoint _dst;
uint32 _hEndDisplay;
2012-06-06 06:04:33 +00:00
bool _bShowed;
bool _bForceTime;
bool _bForceNoTime;
2012-06-10 22:34:45 +00:00
uint32 _hCustomSkip;
uint32 _hCustomSkip2;
2012-06-06 06:04:33 +00:00
RMInput *_input;
bool _bAlwaysDisplay;
bool _bNoTab;
2012-05-14 19:29:27 +00:00
public:
RMTextDialog();
2020-02-09 11:05:33 +00:00
~RMTextDialog() override;
2012-05-14 19:29:27 +00:00
// Write the text
void writeText(const Common::String &text, int font, int *time = NULL);
void writeText(const Common::String &text, RMFontColor *font, int *time = NULL);
2012-05-14 19:29:27 +00:00
// Overloaded function to decide when you delete the object from the OT list
2020-02-09 11:05:33 +00:00
void removeThis(CORO_PARAM, bool &result) override;
2012-05-14 19:29:27 +00:00
// Overloaded de-registration
2020-02-09 11:05:33 +00:00
void unregister() override;
2012-05-14 19:29:27 +00:00
// Overloading of the Draw to center the text, if necessary
2020-02-09 11:05:33 +00:00
void draw(CORO_PARAM, RMGfxTargetBuffer &bigBuf, RMGfxPrimitive *prim) override;
2012-05-14 19:29:27 +00:00
// Set the position
2012-09-02 08:34:11 +00:00
void setPosition(const RMPoint &pt);
2012-05-14 19:29:27 +00:00
// Waiting
2012-06-06 06:04:33 +00:00
void waitForEndDisplay(CORO_PARAM);
void setCustomSkipHandle(uint32 hCustomSkip);
void setCustomSkipHandle2(uint32 hCustomSkip);
void setSkipStatus(bool bEnabled);
void setForcedTime(uint32 dwTime);
void setNoTab();
void forceTime();
void forceNoTime();
void setAlwaysDisplay();
// Set the input device, to allow skip from mouse
2012-06-06 06:04:33 +00:00
void setInput(RMInput *input);
2012-05-14 19:29:27 +00:00
void show();
2012-06-06 06:04:33 +00:00
void hide(CORO_PARAM);
};
class RMTextDialogScrolling : public RMTextDialog {
protected:
2012-06-10 22:34:45 +00:00
RMLocation *_curLoc;
RMPoint _startScroll;
2020-02-09 11:05:33 +00:00
void clipOnScreen(RMGfxPrimitive *prim) override;
public:
2012-05-14 19:29:27 +00:00
RMTextDialogScrolling();
RMTextDialogScrolling(RMLocation *loc);
2020-02-09 11:05:33 +00:00
~RMTextDialogScrolling() override;
2020-02-09 11:05:33 +00:00
void draw(CORO_PARAM, RMGfxTargetBuffer &bigBuf, RMGfxPrimitive *prim) override;
};
/**
* Manages the name of a selected item on the screen
*/
class RMTextItemName : protected RMText {
protected:
2012-06-06 06:04:33 +00:00
RMPoint _mpos;
RMPoint _curscroll;
RMItem *_item;
public:
2012-05-14 19:29:27 +00:00
RMTextItemName();
2020-02-09 11:05:33 +00:00
~RMTextItemName() override;
2012-09-02 08:34:11 +00:00
void setMouseCoord(const RMPoint &m);
2012-05-14 19:29:27 +00:00
2012-06-06 06:04:33 +00:00
void doFrame(CORO_PARAM, RMGfxTargetBuffer &bigBuf, RMLocation &loc, RMPointer &ptr, RMInventory &inv);
2020-02-09 11:05:33 +00:00
void draw(CORO_PARAM, RMGfxTargetBuffer &bigBuf, RMGfxPrimitive *prim) override;
2012-06-06 06:04:33 +00:00
RMPoint getHotspot();
RMItem *getSelectedItem();
bool isItemSelected();
2020-02-09 11:05:33 +00:00
void removeThis(CORO_PARAM, bool &result) override;
};
/**
* Manages the selection of screen items in a box
*/
class RMDialogChoice : public RMGfxWoodyBuffer {
private:
2012-06-06 06:04:33 +00:00
int _curSelection;
int _numChoices;
RMText *_drawedStrings;
RMPoint *_ptDrawStrings;
int _curAdded;
bool _bShow;
2012-06-10 22:34:45 +00:00
RMGfxSourceBuffer8 _dlgText;
RMGfxSourceBuffer8 _dlgTextLine;
2012-06-06 06:04:33 +00:00
RMPoint _ptDrawPos;
2012-06-10 22:34:45 +00:00
uint32 _hUnreg;
bool _bRemoveFromOT;
protected:
2012-06-06 06:04:33 +00:00
void prepare(CORO_PARAM);
void setSelected(CORO_PARAM, int pos);
2012-05-14 19:29:27 +00:00
public:
2020-02-09 11:05:33 +00:00
void removeThis(CORO_PARAM, bool &result) override;
void draw(CORO_PARAM, RMGfxTargetBuffer &bigBuf, RMGfxPrimitive *prim) override;
void unregister() override;
public:
// Initialization
2012-05-14 19:29:27 +00:00
RMDialogChoice();
2020-02-09 11:05:33 +00:00
~RMDialogChoice() override;
2012-05-14 19:29:27 +00:00
// Initialization and closure
using RMGfxWoodyBuffer::init;
void init();
void close();
2012-05-14 19:29:27 +00:00
// Sets the number of possible sentences, which then be added with AddChoice()
2012-06-06 06:04:33 +00:00
void setNumChoices(int num);
2012-05-14 19:29:27 +00:00
// Adds a string with the choice
void addChoice(const Common::String &string);
2012-05-14 19:29:27 +00:00
// Show and hide the selection, with possible animations.
// NOTE: If no parameter is passed to Show(), it is the obligation of
// caller to ensure that the class is inserted into OT list
2012-06-06 06:04:33 +00:00
void show(CORO_PARAM, RMGfxTargetBuffer *bigBuf = NULL);
void hide(CORO_PARAM);
2012-05-14 19:29:27 +00:00
// Polling Update
2012-06-06 06:04:33 +00:00
void doFrame(CORO_PARAM, RMPoint ptMousePos);
2012-05-14 19:29:27 +00:00
// Returns the currently selected item, or -1 if none is selected
int getSelection();
};
} // End of namespace Tony
#endif