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 };
122 
123 // extended gadget type 1 is 62 (0x3e) bytes
124 class TextAreaGadget : public Gadget {
125 public:
126  uint16 _textGadget_i1;
127  uint16 _bufLen;
128 
129  Common::String dump() const override;
130  void draw(Graphics::ManagedSurface *dst) const override;
131 };
132 
133 // extended gadget type 2 is 74 (0x4a) bytes
134 class SliderGadget : public Gadget {
135 public:
136  SliderGadget();
137 
138  uint16 _gadget2_i1;
139  uint16 _gadget2_i2;
140  uint16 _gadget2_i3;
141  uint16 _gadget2_i4;
142 
143  Common::String dump() const override;
144  void draw(Graphics::ManagedSurface *dst) const override;
145 
148  void setSteps(int16 steps, bool lock) {
149  _steps = steps;
150  _lock = lock;
151  }
152 
153  void setValue(int16 val);
154  // Return the closest step value to the current handle position.
155  int16 getValue();
156 
161  int16 onClick(const Common::Point &mousePt);
162 
163  // Returns true if the mouse is over the handle and a drag operation should start
164  bool onMouseDown(const Common::Point &mousePt);
165  void onDrag(const Common::Point &mousePt);
166  // returns the new value
167  int16 onDragFinish(const Common::Point &mousePt);
168 
169 private:
170  bool _lock;
171  int16 _steps;
172  int16 _handleX;
173 
174  int16 getHandleWidth() const;
175  int16 getUsableWidth() const;
176 };
177 
178 // extended gadget type 8 is 68 (0x44) bytes
179 class ImageGadget : public Gadget {
180 public:
181  uint16 _xStep;
182  uint16 _yStep;
183 
184  Common::String dump() const override;
185  void draw(Graphics::ManagedSurface *dst) const override;
186 };
187 
188 class RequestData {
189 public:
190  uint16 _fileNum;
191  DgdsRect _rect;
192  uint16 _col1;
193  uint16 _col2;
194  uint16 _flags;
195  Common::Array<TextItem> _textItemList;
196  Common::Array<RequestFillArea> _fillAreaList;
198 
199  Common::String dump() const;
200  void drawBg(Graphics::ManagedSurface *dst) const;
201  void drawInvType(Graphics::ManagedSurface *dst);
202 
203  static const DgdsFont *getMenuFont();
204  static const Image *getCorners();
205 
206  static void fillBackground(Graphics::ManagedSurface *dst, uint16 x, uint16 y, uint16 width, uint16 height, int16 startoffset);
207  static void drawCorners(Graphics::ManagedSurface *dst, uint16 startNum, uint16 x, uint16 y, uint16 width, uint16 height);
208  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);
209  Gadget *findGadgetByNumWithFlags3Not0x40(int16 num);
210 
211 private:
212 
213  void drawBackgroundNoSliders(Graphics::ManagedSurface *dst, const Common::String &header) const;
214  void drawBackgroundWithSliderArea(Graphics::ManagedSurface *dst, int16 sliderHeight, const Common::String &header) const;
215 
216 };
217 
218 // A REQ file contains a sequence of REQ and GAD block pairs.
219 class REQFileData : public ParserData {
220 public:
221  Common::Array<RequestData> _requests;
222 
223  Common::String dump() const;
224 };
225 
232 class RequestParser : public DgdsParser {
233 public:
234  RequestParser(ResourceManager *resman, Decompressor *decompressor);
235  virtual ~RequestParser() {}
236 
237  bool handleChunk(DgdsChunkReader &chunk, ParserData *data) override;
238 
239 protected:
240  bool parseREQChunk(RequestData &data, DgdsChunkReader &chunk, int num);
241  bool parseGADChunk(RequestData &data, DgdsChunkReader &chunk, int num);
242 };
243 
244 
245 } // End of namespace Dgds
246 
247 #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:124
Definition: font.h:46
void setSteps(int16 steps, bool lock)
Definition: request.h:148
Definition: request.h:188
Definition: dgds_rect.h:32
Definition: request.h:179
Definition: request.h:112
Definition: request.h:36
Definition: rect.h:45
Definition: request.h:219
Definition: request.h:45
Definition: request.h:134
Definition: request.h:232
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