ScummVM API documentation
request.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 #ifndef DGDS_REQUEST_H
23 #define DGDS_REQUEST_H
24 
25 #include "common/stream.h"
26 #include "common/array.h"
27 
28 #include "dgds/parser.h"
29 #include "dgds/dgds_rect.h"
30 
31 namespace Dgds {
32 
33 class DgdsFont;
34 class Image;
35 
36 struct TextItem {
37  uint16 _x;
38  uint16 _y;
39  uint16 _vals[2];
40  Common::String _txt;
41 };
42 
43 // This struct is defined in the code, but seems
44 // to not be used in any of the games?
46  uint16 _x;
47  uint16 _y;
48  uint16 _width;
49  uint16 _height;
50  uint16 _col1;
51  uint16 _col2;
52 };
53 
54 enum GadgetType {
55  kGadgetNone = 0,
56  kGadgetText = 1,
57  kGadgetSlider = 2,
58  kGadgetButton = 4,
59  kGadgetImage = 8,
60 };
61 
62 // basic gadget is 52 (0x34) bytes
63 class Gadget {
64 public:
65  virtual ~Gadget() {}
66 
67  // NOTE: Most of these names are still guesses
68  uint16 _gadgetNo;
69  uint16 _x;
70  uint16 _y;
71  uint16 _width;
72  uint16 _height;
73  GadgetType _gadgetType;
74  uint16 _flags2;
75  uint16 _flags3;
76 
77  uint16 _sval1Type; // if 1 then use the string, else use the int
78  Common::String _sval1S;
79  uint16 _sval1I;
80 
81  uint16 _sval2Type; // if 1 then use the string, else use the int
82  Common::String _sval2S;
83  uint16 _sval2I;
84 
85  Common::String _buttonName;
86 
87  // some other fields..
88  uint16 _fontNo;
89  uint16 _col1;
90  uint16 _col2;
91  uint16 _col3;
92 
93  uint16 _field20_0x28;
94  uint16 _field21_0x2a;
95 
96  uint16 _parentX;
97  uint16 _parentY;
98 
99  virtual Common::String dump() const;
100  virtual void draw(Graphics::ManagedSurface *dst) const;
101  virtual void toggle(bool enable) {}
102 
103  bool containsPoint(const Common::Point &pt);
104  bool isVisible() const { return !(_flags3 & 0x40); }
105  void setVisible(bool visible);
106 
107  Common::Point topLeft() const;
108  Common::Point midPoint() const;
109 };
110 
111 // Button gadget has no additional fields, but some behavior differences.
112 class ButtonGadget : public Gadget {
113 public:
114  void draw(Graphics::ManagedSurface *dst) const override;
115  void toggle(bool enable) override;
116 private:
117  // Each of these return the text color
118  byte drawDragonBg(Graphics::ManagedSurface *dst, bool enabled) const;
119  byte drawChinaBg(Graphics::ManagedSurface *dst, bool enabled) const;
120  byte drawWillyBg(Graphics::ManagedSurface *dst, bool enabled) const;
121  void drawWillyBmpButtons(Graphics::ManagedSurface *dst) const;
122  void drawCenteredBmpIcon(Graphics::ManagedSurface *dst, int16 cornerNum) const;
123  void drawWillyLoadSaveIcon(Graphics::ManagedSurface *dst, bool isLoad) const;
124 };
125 
126 // extended gadget type 1 is 62 (0x3e) bytes
127 class TextAreaGadget : public Gadget {
128 public:
129  uint16 _textGadget_i1;
130  uint16 _bufLen;
131 
132  Common::String dump() const override;
133  void draw(Graphics::ManagedSurface *dst) const override;
134 };
135 
136 // extended gadget type 2 is 74 (0x4a) bytes
137 class SliderGadget : public Gadget {
138 public:
139  SliderGadget();
140 
141  uint16 _gadget2_i1;
142  uint16 _gadget2_i2;
143  uint16 _gadget2_i3;
144  uint16 _gadget2_i4;
145 
146  Common::String dump() const override;
147  void draw(Graphics::ManagedSurface *dst) const override;
148 
151  void setSteps(int16 steps, bool lock) {
152  _steps = steps;
153  _lock = lock;
154  }
155 
156  void setValue(int16 val);
157  // Return the closest step value to the current handle position.
158  int16 getValue();
159 
164  int16 onClick(const Common::Point &mousePt);
165 
166  // Returns true if the mouse is over the handle and a drag operation should start
167  bool onMouseDown(const Common::Point &mousePt);
168  void onDrag(const Common::Point &mousePt);
169  // returns the new value
170  int16 onDragFinish(const Common::Point &mousePt);
171 
172 private:
173  bool _lock;
174  int16 _steps;
175  int16 _handleX;
176 
177  void drawDragonBg(Graphics::ManagedSurface *dst) const;
178  void drawChinaBg(Graphics::ManagedSurface *dst) const;
179 
180  int16 getHandleWidth() const;
181  int16 getUsableWidth() const;
182 };
183 
184 // extended gadget type 8 is 68 (0x44) bytes
185 class ImageGadget : public Gadget {
186 public:
187  uint16 _xStep;
188  uint16 _yStep;
189 
190  Common::String dump() const override;
191  void draw(Graphics::ManagedSurface *dst) const override;
192 };
193 
194 class RequestData {
195 public:
196  uint16 _fileNum;
197  DgdsRect _rect;
198  uint16 _col1;
199  uint16 _col2;
200  uint16 _flags;
201  Common::Array<TextItem> _textItemList;
202  Common::Array<RequestFillArea> _fillAreaList;
204 
205  Common::String dump() const;
206  void drawBg(Graphics::ManagedSurface *dst) const;
207  void drawInvType(Graphics::ManagedSurface *dst);
208 
209  static const DgdsFont *getMenuFont();
210  static const Image *getCorners();
211 
212  static void fillBackground(Graphics::ManagedSurface *dst, uint16 x, uint16 y, uint16 width, uint16 height, int16 startoffset);
213  static void drawCorners(Graphics::ManagedSurface *dst, uint16 startNum, uint16 x, uint16 y, uint16 width, uint16 height);
214  static void drawHeader(Graphics::ManagedSurface *dst, int16 x, int16 y, int16 width, int16 yoffset, const Common::String &header, byte fontCol, bool drawBox, byte boxTopColor, byte boxBottomColor);
215  Gadget *findGadgetByNumWithFlags3Not0x40(int16 num);
216 
217 private:
218 
219  void drawBackgroundNoSliders(Graphics::ManagedSurface *dst, const Common::String &header) const;
220  void drawBackgroundWithSliderArea(Graphics::ManagedSurface *dst, int16 sliderHeight, const Common::String &header) const;
221 
222 };
223 
224 // A REQ file contains a sequence of REQ and GAD block pairs.
225 class REQFileData : public ParserData {
226 public:
227  Common::Array<RequestData> _requests;
228 
229  Common::String dump() const;
230 };
231 
238 class RequestParser : public DgdsParser {
239 public:
240  RequestParser(ResourceManager *resman, Decompressor *decompressor);
241  virtual ~RequestParser() {}
242 
243  bool handleChunk(DgdsChunkReader &chunk, ParserData *data) override;
244 
245 protected:
246  bool parseREQChunk(RequestData &data, DgdsChunkReader &chunk, int num);
247  bool parseGADChunk(RequestData &data, DgdsChunkReader &chunk, int num);
248 };
249 
250 
251 } // End of namespace Dgds
252 
253 #endif // DGDS_REQUEST_H
Definition: managed_surface.h:51
Definition: str.h:59
Definition: array.h:52
Definition: ads.h:28
Definition: request.h:63
Definition: request.h:127
Definition: font.h:46
void setSteps(int16 steps, bool lock)
Definition: request.h:151
Definition: request.h:194
Definition: dgds_rect.h:32
Definition: request.h:185
Definition: request.h:112
Definition: request.h:36
Definition: rect.h:45
Definition: request.h:225
Definition: request.h:45
Definition: request.h:137
Definition: request.h:238
Definition: resource.h:65
Definition: movie_decoder.h:32
Definition: parser.h:36
Definition: parser.h:38
Definition: decompress.h:67
Definition: resource.h:49