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 namespace Common {
33 class ReadStream;
34 class WriteStream;
35 }
36 
37 namespace Hugo {
38 enum OverlayState {kOvlUndef, kOvlForeground, kOvlBackground}; // Overlay state
39 
40 static const int kCenter = -1; // Used to center text in x
41 
42 
43 class Screen {
44 public:
45  struct Rect { // Rectangle used in Display list
46  int16 _x; // Position in dib
47  int16 _y; // Position in dib
48  int16 _dx; // width
49  int16 _dy; // height
50  };
51 
52  Screen(HugoEngine *vm);
53  virtual ~Screen();
54 
55  virtual void loadFont(int16 fontId) = 0;
56  virtual void loadFontArr(Common::ReadStream &in) = 0;
57 
58  int16 fontHeight() const;
59  int16 stringLength(const char *s) const;
60 
61  void displayBackground();
62  void displayFrame(const int sx, const int sy, Seq *seq, const bool foreFl);
63  void displayList(int update, ...);
64  void displayRect(const int16 x, const int16 y, const int16 dx, const int16 dy);
65  void drawBoundaries();
66  void drawRectangle(const bool filledFl, const int16 x1, const int16 y1, const int16 x2, const int16 y2, const int color);
67  void drawShape(const int x, const int y, const int color1, const int color2);
68  void drawStatusText();
69  void freeScreen();
70  void hideCursor();
71  void initDisplay();
72  void initNewScreenDisplay();
73  void loadPalette(Common::ReadStream &in);
74  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);
75  void remapPal(uint16 oldIndex, uint16 newIndex);
76  void resetInventoryObjId();
77  void restorePal(Common::ReadStream *f);
78  void savePal(Common::WriteStream *f) const;
79  void setBackgroundColor(const uint16 color);
80  void setCursorPal();
81  void selectInventoryObjId(const int16 objId);
82  void shadowStr(int16 sx, const int16 sy, const char *s, const byte color);
83  void showCursor();
84  void userHelp() const;
85  void writeStr(int16 sx, const int16 sy, const char *s, const byte color);
86 
87  Icondib &getIconBuffer();
88  Viewdib &getBackBuffer();
89  Viewdib &getBackBufferBackup();
90  Viewdib &getFrontBuffer();
91  Viewdib &getGUIBuffer();
92 
93 protected:
94  HugoEngine *_vm;
95 
96  static const int kRectListSize = 16; // Size of add/restore rect lists
97  static const int kBlitListSize = kRectListSize * 2; // Size of dirty rect blit list
98  static const int kShapeSize = 24;
99  static const int kFontLength = 128; // Number of chars in font
100  static const int kFontSize = 1200; // Max size of font data
101  static const int kNumFonts = 3; // Number of dib fonts
102  static const byte stdMouseCursorHeight = 20;
103  static const byte stdMouseCursorWidth = 12;
104 
105  bool fontLoadedFl[kNumFonts];
106 
107  // Fonts used in dib (non-GDI)
108  byte *_arrayFont[kNumFonts];
109  byte _fnt; // Current font number
110  byte _fontdata[kNumFonts][kFontSize]; // Font data
111  byte *_font[kNumFonts][kFontLength]; // Ptrs to each char
112  byte *_mainPalette;
113  int16 _arrayFontSize[kNumFonts];
114 
115  Viewdib _frontBuffer;
116 
117  inline bool isInX(const int16 x, const Rect *rect) const;
118  inline bool isInY(const int16 y, const Rect *rect) const;
119  inline bool isOverlapping(const Rect *rectA, const Rect *rectB) const;
120 
121  virtual OverlayState findOvl(Seq *seqPtr, ImagePtr dstPtr, uint16 y) = 0;
122 
123 private:
124  byte *_curPalette;
125  byte _iconImage[kInvDx * kInvDy];
126  byte _paletteSize;
127 
128  Icondib _iconBuffer; // Inventory icon DIB
129 
130  int16 mergeLists(Rect *list, Rect *blist, const int16 len, int16 blen);
131  int16 center(const char *s) const;
132 
133  Viewdib _backBuffer;
134  Viewdib _GUIBuffer; // User interface images
135  Viewdib _backBufferBackup; // Backup _backBuffer during inventory
136 
137  // Formerly static variables used by displayList()
138  int16 _dlAddIndex, _dlRestoreIndex; // Index into add/restore lists
139  Rect _dlRestoreList[kRectListSize]; // The restore list
140  Rect _dlAddList[kRectListSize]; // The add list
141  Rect _dlBlistList[kBlitListSize]; // The blit list
142  //
143 
144  void createPal();
145  void merge(const Rect *rectA, Rect *rectB);
146  void writeChr(const int sx, const int sy, const byte color, const char *local_fontdata);
147 };
148 
149 class Screen_v1d : public Screen {
150 public:
151  Screen_v1d(HugoEngine *vm);
152  ~Screen_v1d() override;
153 
154  void loadFont(int16 fontId) override;
155  void loadFontArr(Common::ReadStream &in) override;
156 protected:
157  OverlayState findOvl(Seq *seqPtr, ImagePtr dstPtr, uint16 y) override;
158 };
159 
160 class Screen_v1w : public Screen {
161 public:
162  Screen_v1w(HugoEngine *vm);
163  ~Screen_v1w() override;
164 
165  void loadFont(int16 fontId) override;
166  void loadFontArr(Common::ReadStream &in) override;
167 protected:
168  OverlayState findOvl(Seq *seqPtr, ImagePtr dstPtr, uint16 y) override;
169 };
170 
171 } // End of namespace Hugo
172 
173 #endif //HUGO_DISPLAY_H
Definition: console.h:27
byte * ImagePtr
Definition: game.h:96
Definition: stream.h:77
Definition: display.h:43
Definition: algorithm.h:29
Definition: display.h:160
Definition: display.h:45
Definition: display.h:149
Definition: stream.h:385
Definition: hugo.h:210
Definition: game.h:114