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 
61  virtual int16 fontHeight() const = 0;
62  virtual int16 stringLength(const char *s) const = 0;
63 
64  void displayBackground();
65  virtual void displayFrame(const int sx, const int sy, Seq *seq, const bool foreFl) = 0;
66  void displayList(int update, ...);
67  void displayRect(const int16 x, const int16 y, const int16 dx, const int16 dy);
68  void drawBoundaries();
69  void drawRectangle(const bool filledFl, const int16 x1, const int16 y1, const int16 x2, const int16 y2, const int color);
70  void drawShape(const int x, const int y, const int color1, const int color2);
71  void updateStatusText();
72  void updatePromptText(const char *command, char cursor);
73  void drawStatusText();
74  void displayStatusText();
75  void drawPromptText();
76  void displayPromptText();
77  void freeScreen();
78  void hideCursor();
79  void initDisplay();
80  void initNewScreenDisplay();
81  virtual void loadPalette(Common::SeekableReadStream &in) = 0;
82  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);
83  void remapPal(uint16 oldIndex, uint16 newIndex);
84  void resetInventoryObjId();
85  void restorePal(Common::ReadStream *f);
86  void savePal(Common::WriteStream *f) const;
87  void setBackgroundColor(const uint16 color);
88  void setCursorPal();
89  void selectInventoryObjId(const int16 objId);
90  void shadowStr(int16 sx, const int16 sy, const char *s, const byte color);
91  void showCursor();
92  void userHelp() const;
93  virtual void writeStr(int16 sx, const int16 sy, const char *s, const byte color) = 0;
94  Common::Rect drawDosText(byte x, byte y, const char *text, byte color);
95  byte getDosMessageBoxBorder() const;
96  Common::KeyState dosMessageBox(const Common::String &text, bool protect = false, TtsOptions ttsOptions = kTtsReplaceNewlines);
97  Common::String dosPromptBox(const Common::String &text);
98  Common::KeyState getKey();
99 
100  Icondib &getIconBuffer();
101  Viewdib &getBackBuffer();
102  Viewdib &getBackBufferBackup();
103  Viewdib &getFrontBuffer();
104  Viewdib &getGUIBuffer();
105 
106 protected:
107  HugoEngine *_vm;
108 
109  static const int kRectListSize = 16; // Size of add/restore rect lists
110  static const int kBlitListSize = kRectListSize * 2; // Size of dirty rect blit list
111  static const int kShapeSize = 24;
112  static const byte stdMouseCursorHeight = 20;
113  static const byte stdMouseCursorWidth = 12;
114 
115  byte *_mainPalette;
116  byte *_curPalette;
117  byte _paletteSize;
118 
119  Graphics::DosFont _dosFont;
120 
121  Viewdib _frontBuffer;
122  Graphics::Surface _frontSurface;
123 
124  inline bool isInX(const int16 x, const Rect *rect) const;
125  inline bool isInY(const int16 y, const Rect *rect) const;
126  inline bool isOverlapping(const Rect *rectA, const Rect *rectB) const;
127 
128  int16 center(const char *s) const;
129 
130 private:
131  byte _iconImage[kInvDx * kInvDy];
132 
133  Icondib _iconBuffer; // Inventory icon DIB
134 
135  int16 mergeLists(Rect *list, Rect *blist, const int16 len, int16 blen);
136 
137  Viewdib _backBuffer;
138  Viewdib _GUIBuffer; // User interface images
139  Viewdib _backBufferBackup; // Backup _backBuffer during inventory
140  Viewdib _frontBufferBoxBackup; // Backup _frontBuffer during DOS message boxes
141 
142  // Formerly static variables used by displayList()
143  int16 _dlAddIndex, _dlRestoreIndex; // Index into add/restore lists
144  Rect _dlRestoreList[kRectListSize]; // The restore list
145  Rect _dlAddList[kRectListSize]; // The add list
146  Rect _dlBlistList[kBlitListSize]; // The blit list
147  //
148 
149  void createPal();
150  void merge(const Rect *rectA, Rect *rectB);
151 };
152 
153 class Screen_v1d : public Screen {
154 public:
155  Screen_v1d(HugoEngine *vm);
156  ~Screen_v1d() override;
157 
158  void loadFont(int16 fontId) override;
159  int16 fontHeight() const override;
160  int16 stringLength(const char *s) const override;
161 
162  void displayFrame(const int sx, const int sy, Seq *seq, const bool foreFl) override;
163 
164  void loadPalette(Common::SeekableReadStream &in) override;
165 
166  void writeStr(int16 sx, const int16 sy, const char *s, const byte color) override;
167 protected:
168  OverlayState findOvl(Seq *seqPtr, ImagePtr dstPtr, uint16 y);
169 };
170 
171 class Screen_v1w : public Screen {
172 public:
173  Screen_v1w(HugoEngine *vm);
174  ~Screen_v1w() override;
175 
176  void loadFont(int16 fontId) override;
177  int16 fontHeight() const override;
178  int16 stringLength(const char *s) const override;
179 
180  void displayFrame(const int sx, const int sy, Seq *seq, const bool foreFl) override;
181 
182  void loadPalette(Common::SeekableReadStream &in) override;
183 
184  void writeStr(int16 sx, const int16 sy, const char *s, const byte color) override;
185 protected:
186  static const int kFontLength = 128; // Number of chars in font
187  static const int kFontSize = 1200; // Max size of font data
188  static const int kNumFonts = 3; // Number of dib fonts
189 
190  bool fontLoadedFl[kNumFonts];
191 
192  // Fonts used in dib (non-GDI)
193  byte _fnt; // Current font number
194  byte _fontdata[kNumFonts][kFontSize]; // Font data
195  byte *_font[kNumFonts][kFontLength]; // Ptrs to each char
196 
197  OverlayState findOvl(Seq *seqPtr, ImagePtr dstPtr, uint16 y);
198 private:
199  void writeChr(const int sx, const int sy, const byte color, const char *local_fontdata);
200 };
201 
202 } // End of namespace Hugo
203 
204 #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:171
Definition: display.h:49
Definition: display.h:153
Definition: keyboard.h:294
Definition: stream.h:385
Definition: hugo.h:219
Definition: game.h:115
Definition: dosfont.h:29