ScummVM API documentation
display.h
1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 /*
23  * This code is based on original Hugo Trilogy source code
24  *
25  * Copyright (c) 1989-1995 David P. Gray
26  *
27  */
28 
29 #ifndef HUGO_DISPLAY_H
30 #define HUGO_DISPLAY_H
31 
32 #include "graphics/surface.h"
33 #include "graphics/fonts/dosfont.h"
34 
35 namespace Common {
36 class ReadStream;
37 class SeekableReadStream;
38 class WriteStream;
39 }
40 
41 namespace Hugo {
42 enum OverlayState {kOvlUndef, kOvlForeground, kOvlBackground}; // Overlay state
43 
44 static const int kCenter = -1; // Used to center text in x
45 
46 
47 class Screen {
48 public:
49  struct Rect { // Rectangle used in Display list
50  int16 _x; // Position in dib
51  int16 _y; // Position in dib
52  int16 _dx; // width
53  int16 _dy; // height
54  };
55 
56  Screen(HugoEngine *vm);
57  virtual ~Screen();
58 
59  virtual void loadFont(int16 fontId) = 0;
60  virtual void loadFontArr(Common::ReadStream &in) = 0;
61 
62  int16 fontHeight() const;
63  int16 stringLength(const char *s) const;
64 
65  void displayBackground();
66  virtual void displayFrame(const int sx, const int sy, Seq *seq, const bool foreFl) = 0;
67  void displayList(int update, ...);
68  void displayRect(const int16 x, const int16 y, const int16 dx, const int16 dy);
69  void drawBoundaries();
70  void drawRectangle(const bool filledFl, const int16 x1, const int16 y1, const int16 x2, const int16 y2, const int color);
71  void drawShape(const int x, const int y, const int color1, const int color2);
72  void updateStatusText();
73  void updatePromptText(const char *command, char cursor);
74  void drawStatusText();
75  void displayStatusText();
76  void drawPromptText();
77  void displayPromptText();
78  void freeScreen();
79  void hideCursor();
80  void initDisplay();
81  void initNewScreenDisplay();
82  virtual void loadPalette(Common::SeekableReadStream &in) = 0;
83  void moveImage(ImagePtr srcImage, const int16 x1, const int16 y1, const int16 dx, int16 dy, const int16 width1, ImagePtr dstImage, const int16 x2, const int16 y2, const int16 width2);
84  void remapPal(uint16 oldIndex, uint16 newIndex);
85  void resetInventoryObjId();
86  void restorePal(Common::ReadStream *f);
87  void savePal(Common::WriteStream *f) const;
88  void setBackgroundColor(const uint16 color);
89  void setCursorPal();
90  void selectInventoryObjId(const int16 objId);
91  void shadowStr(int16 sx, const int16 sy, const char *s, const byte color);
92  void showCursor();
93  void userHelp() const;
94  void writeStr(int16 sx, const int16 sy, const char *s, const byte color);
95  Common::Rect drawDosText(byte x, byte y, const char *text, byte color);
96  byte getDosMessageBoxBorder() const;
97  Common::KeyState dosMessageBox(const Common::String &text, bool protect = false, TtsOptions ttsOptions = kTtsReplaceNewlines);
98  Common::String dosPromptBox(const Common::String &text);
99  Common::KeyState getKey();
100 
101  Icondib &getIconBuffer();
102  Viewdib &getBackBuffer();
103  Viewdib &getBackBufferBackup();
104  Viewdib &getFrontBuffer();
105  Viewdib &getGUIBuffer();
106 
107 protected:
108  HugoEngine *_vm;
109 
110  static const int kRectListSize = 16; // Size of add/restore rect lists
111  static const int kBlitListSize = kRectListSize * 2; // Size of dirty rect blit list
112  static const int kShapeSize = 24;
113  static const int kFontLength = 128; // Number of chars in font
114  static const int kFontSize = 1200; // Max size of font data
115  static const int kNumFonts = 3; // Number of dib fonts
116  static const byte stdMouseCursorHeight = 20;
117  static const byte stdMouseCursorWidth = 12;
118 
119  bool fontLoadedFl[kNumFonts];
120 
121  // Fonts used in dib (non-GDI)
122  byte *_arrayFont[kNumFonts];
123  byte _fnt; // Current font number
124  byte _fontdata[kNumFonts][kFontSize]; // Font data
125  byte *_font[kNumFonts][kFontLength]; // Ptrs to each char
126  int16 _arrayFontSize[kNumFonts];
127  byte *_mainPalette;
128  byte *_curPalette;
129  byte _paletteSize;
130 
131  Graphics::DosFont _dosFont;
132 
133  Viewdib _frontBuffer;
134  Graphics::Surface _frontSurface;
135 
136  inline bool isInX(const int16 x, const Rect *rect) const;
137  inline bool isInY(const int16 y, const Rect *rect) const;
138  inline bool isOverlapping(const Rect *rectA, const Rect *rectB) const;
139 
140 private:
141  byte _iconImage[kInvDx * kInvDy];
142 
143  Icondib _iconBuffer; // Inventory icon DIB
144 
145  int16 mergeLists(Rect *list, Rect *blist, const int16 len, int16 blen);
146  int16 center(const char *s) const;
147 
148  Viewdib _backBuffer;
149  Viewdib _GUIBuffer; // User interface images
150  Viewdib _backBufferBackup; // Backup _backBuffer during inventory
151  Viewdib _frontBufferBoxBackup; // Backup _frontBuffer during DOS message boxes
152 
153  // Formerly static variables used by displayList()
154  int16 _dlAddIndex, _dlRestoreIndex; // Index into add/restore lists
155  Rect _dlRestoreList[kRectListSize]; // The restore list
156  Rect _dlAddList[kRectListSize]; // The add list
157  Rect _dlBlistList[kBlitListSize]; // The blit list
158  //
159 
160  void createPal();
161  void merge(const Rect *rectA, Rect *rectB);
162  void writeChr(const int sx, const int sy, const byte color, const char *local_fontdata);
163 };
164 
165 class Screen_v1d : public Screen {
166 public:
167  Screen_v1d(HugoEngine *vm);
168  ~Screen_v1d() override;
169 
170  void loadFont(int16 fontId) override;
171  void loadFontArr(Common::ReadStream &in) override;
172 
173  void displayFrame(const int sx, const int sy, Seq *seq, const bool foreFl) override;
174 
175  void loadPalette(Common::SeekableReadStream &in) override;
176 protected:
177  OverlayState findOvl(Seq *seqPtr, ImagePtr dstPtr, uint16 y);
178 };
179 
180 class Screen_v1w : public Screen {
181 public:
182  Screen_v1w(HugoEngine *vm);
183  ~Screen_v1w() override;
184 
185  void loadFont(int16 fontId) override;
186  void loadFontArr(Common::ReadStream &in) override;
187 
188  void displayFrame(const int sx, const int sy, Seq *seq, const bool foreFl) override;
189 
190  void loadPalette(Common::SeekableReadStream &in) override;
191 protected:
192  OverlayState findOvl(Seq *seqPtr, ImagePtr dstPtr, uint16 y);
193 };
194 
195 } // End of namespace Hugo
196 
197 #endif //HUGO_DISPLAY_H
Definition: console.h:27
byte * ImagePtr
Definition: game.h:97
Definition: str.h:59
Definition: surface.h:67
Definition: stream.h:77
Definition: display.h:47
Definition: rect.h:524
Definition: stream.h:745
Definition: algorithm.h:29
Definition: display.h:180
Definition: display.h:49
Definition: display.h:165
Definition: keyboard.h:294
Definition: stream.h:385
Definition: hugo.h:219
Definition: game.h:115
Definition: dosfont.h:29