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