xoreos  0.0.5
gfxfile.h
Go to the documentation of this file.
1 /* xoreos - A reimplementation of BioWare's Aurora engine
2  *
3  * xoreos is the legal property of its developers, whose names
4  * can be found in the AUTHORS file distributed with this source
5  * distribution.
6  *
7  * xoreos is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 3
10  * of the License, or (at your option) any later version.
11  *
12  * xoreos 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 xoreos. If not, see <http://www.gnu.org/licenses/>.
19  */
20 
25 #ifndef AURORA_GFXFILE_H
26 #define AURORA_GFXFILE_H
27 
28 #include <boost/variant.hpp>
29 #include <boost/optional.hpp>
30 
31 #include "glm/glm.hpp"
32 
33 #include "src/common/scopedptr.h"
34 #include "src/common/ustring.h"
35 #include "src/common/readstream.h"
36 #include "src/common/rect.h"
37 #include "src/common/bitstream.h"
38 
40 
41 namespace Aurora {
42 
43 // Forward declaration.
44 class GFXControl;
45 
49 class GFXCharacter {
50 public:
60  };
61 
63  struct GradientRecord {
65  glm::u8vec4 color;
66  };
67 
69  struct Fill {
70  glm::u8vec4 color;
71  };
72 
74  struct Gradient {
75  glm::mat3x2 matrix;
78  std::vector<GradientRecord> records;
79  };
80 
82  struct Bitmap {
84  glm::mat3x2 matrix;
85  };
86 
88  struct FillStyle {
90  boost::variant<Fill, Gradient, Bitmap> value;
91 
93  type = 0xFF;
94  }
95  };
96 
98  struct LineStyle {
100  glm::u8vec4 color;
101 
103  width = 0;
104  }
105  };
106 
112  struct ShapeRecord {
113  struct {
116  } style;
117  struct {
119  } move;
120  struct {
122  } straightEdge;
123  struct {
126  } curvedEdge;
127 
129  move.deltaX = 0;
130  move.deltaY = 0;
131  straightEdge.deltaX = 0;
132  straightEdge.deltaY = 0;
133  curvedEdge.controlDeltaX = 0;
134  curvedEdge.controlDeltaY = 0;
135  curvedEdge.anchorDeltaX = 0;
136  curvedEdge.anchorDeltaY = 0;
137  }
138  };
139 
141  struct Glyph {
144  std::vector<ShapeRecord> shapeRecords;
145  };
146 
150  struct KerningCode {
153  };
154 
157  kLeft = 0,
158  kRight = 1,
159  kCenter = 2,
161  };
162 
167  struct Sprite {
169  std::vector<GFXControl> controls;
170  };
171 
175  struct Shape {
177  std::vector<ShapeRecord> shapeRecords;
178  };
179 
181  struct EditTextLayout {
187  };
188 
193  struct EditText {
195  bool wordWrap;
196  bool multiLine;
197  bool password;
198  bool readOnly;
199  bool autosize;
200  bool noSelect;
201  bool html;
202  boost::optional<uint16> fontId;
203  boost::optional<uint16> fontHeight;
204  boost::optional<glm::u8vec4> textColor;
205  boost::optional<uint16> maxLength;
206  boost::optional<Common::UString> initialText;
207  boost::optional<EditTextLayout> layout;
208  };
209 
213  struct Font {
215  std::vector<Glyph> glyphs;
216  std::vector<KerningCode> kerningCodes;
217  boost::optional<uint16> fontAscent;
218  boost::optional<uint16> fontDescent;
219  boost::optional<int16> fontLeading;
220  };
221 
226  struct ExternalImage {
230  };
231 
233  static GFXCharacter createSprite(uint16 id, Sprite sprite);
235  static GFXCharacter createShape(uint16 id, Shape shape);
237  static GFXCharacter createEditText(uint16 id, EditText editText);
239  static GFXCharacter createFont(uint16 id, Font font);
241  static GFXCharacter createExternalImage(uint16 id, ExternalImage externalImage);
242 
244  CharacterType getType() const;
246  uint16 getId() const;
247 
249  void getSprite(Sprite &sprite) const;
251  void getShape(Shape &shape) const;
253  void getFont(Font &font) const;
255  void getEditText(EditText &editText) const;
257  void getExternalImage(ExternalImage &externalImage) const;
258 
259 private:
260  boost::variant<
261  Sprite,
262  Shape,
263  EditText,
264  Font,
267 
270 
272 };
273 
278 class GFXControl {
279 public:
283  enum ControlType {
287  };
288 
290  struct ColorTransform {
292  int mulR, mulG, mulB, mulA;
293  int addR, addG, addB, addA;
294 
296  mulR = mulG = mulB = mulA = 0;
297  addR = addG = addB = addA = 0;
298  mulTransform = false;
299  addTransform = false;
300  }
301  };
302 
304  struct PlaceObject {
305  bool hasMove;
306 
308  boost::optional<uint16> characterId;
309  boost::optional<Common::UString> name;
310  boost::optional<glm::mat3x2> matrix;
311  boost::optional<ColorTransform> colorTransform;
312  boost::optional<uint8> blendMode;
313  };
314 
316  struct DoAction {
318  };
319 
325  static GFXControl createShowFrame();
326 
328  ControlType getType() const { return _type; };
329 
331  void getPlaceObject(PlaceObject &placeObject) const;
333  void getDoAction(DoAction &doAction) const;
334 
335 private:
336  boost::variant<PlaceObject, DoAction> _value;
337 
339 
340  explicit GFXControl(ControlType type);
341 };
342 
348 class GFXFile {
349 public:
356 
358  float getFrameRate() { return _frameRate; };
359 
364 
366  std::vector<GFXControl> getControls() { return _controlTags; };
367 
368 private:
370  struct RecordHeader {
373  };
374 
376  std::map<Common::UString, uint16> _exportTable;
378  std::map<uint16, GFXCharacter> _characters;
380  std::vector<GFXControl> _controlTags;
381 
384 
388  float _frameRate;
390  unsigned short _frameCount;
391 
393 
395  void readHeader();
396 
398  void readDefineShape(byte version);
400  void readBackgroundColor();
402  void readExportAssets();
406  void readFileAttributes();
408  void readDefineSprite();
410  GFXControl readPlaceObject(byte version = 1);
412  void readDefineFont();
414  void readDefineEditText();
419 
420  // .--- Scaleform specific tags based on https://github.com/jindrapetrik/jpexs-decompiler.
421 
423  void readGFXExporterInfo(RecordHeader header);
425  void readGFXDefineExternalImage(RecordHeader header, byte version = 0);
426 
427  // '---
428 
429  // .--- Utility types inside gfx files
430 
436  glm::mat3x2 readMatrix();
438  glm::u8vec3 readRGB();
440  glm::u8vec4 readRGBA();
442  std::vector<GFXCharacter::FillStyle> readFillStyleArray(byte version);
446  std::vector<GFXCharacter::LineStyle> readLineStyleArray(byte version);
452  void readFocalGradient(byte version);
456  std::vector<GFXCharacter::ShapeRecord> readShape(byte version, bool withStyle);
457 
458  // '---
459 
460  // .--- GFx utility methods
461 
467  int32 read2ComplementValue(Common::BitStream &bitStream, size_t n);
468 
469  // '---
470 };
471 
472 } // End of namespace Aurora
473 
474 #endif // AURORA_GFXFILE_H
Class for parsing gfx files.
Definition: gfxfile.h:348
void readFileAttributes()
Read the file attributes tag.
Definition: gfxfile.cpp:375
A record for a shape.
Definition: gfxfile.h:112
Common::UString readNullTerminatedString()
Read a null terminated string.
Definition: gfxfile.cpp:1120
int32 read2ComplementValue(Common::BitStream &bitStream, size_t n)
Read a 2&#39;s complement value.
Definition: gfxfile.cpp:1129
std::vector< GradientRecord > records
Definition: gfxfile.h:78
std::vector< KerningCode > kerningCodes
Definition: gfxfile.h:216
static GFXCharacter createSprite(uint16 id, Sprite sprite)
Create a sprite character.
Definition: gfxfile.cpp:75
A simple one-color fill.
Definition: gfxfile.h:69
boost::optional< uint16 > fontHeight
Definition: gfxfile.h:203
void readFocalGradient(byte version)
Read a focal gradient record.
Definition: gfxfile.cpp:989
A class holding an UTF-8 string.
Definition: ustring.h:48
boost::optional< uint16 > characterId
Definition: gfxfile.h:308
GFXFile(const Common::UString &resref, Aurora::ActionScript::AVM &avm)
Open a gfx file specified by the reference and used with the specified avm.
Definition: gfxfile.cpp:198
boost::variant< Fill, Gradient, Bitmap > value
Definition: gfxfile.h:90
GFXCharacter::FillStyle readFillStyle(byte version)
Read an FillStyle record.
Definition: gfxfile.cpp:886
std::vector< GFXControl > controls
Definition: gfxfile.h:169
ControlType
The possible control types.
Definition: gfxfile.h:283
uint8_t uint8
Definition: types.h:200
TextAlignment
The alignment of text.
Definition: gfxfile.h:156
void load(Common::SeekableReadStream *gfx, Aurora::ActionScript::AVM &avm)
Definition: gfxfile.cpp:222
boost::variant< Sprite, Shape, EditText, Font, ExternalImage > _value
Definition: gfxfile.h:266
boost::optional< uint8 > blendMode
Definition: gfxfile.h:312
std::vector< ShapeRecord > shapeRecords
Definition: gfxfile.h:177
boost::optional< uint16 > maxLength
Definition: gfxfile.h:205
float getFrameRate()
Get the framerate for this gfx file.
Definition: gfxfile.h:358
static GFXCharacter createExternalImage(uint16 id, ExternalImage externalImage)
Create an external image character.
Definition: gfxfile.cpp:107
void readImportAssets(ActionScript::AVM &avm)
Read an import assets tag.
Definition: gfxfile.cpp:355
Buffer for handling actionscript byte code.
boost::optional< uint16 > fontAscent
Definition: gfxfile.h:217
boost::optional< EditTextLayout > layout
Definition: gfxfile.h:207
An edit text character, mostly used as static, but sometimes also used as editable text...
Definition: gfxfile.h:193
GFXCharacter getCharacter(uint16 id)
Get a character by id.
Definition: gfxfile.cpp:214
GFXControl readPlaceObject(byte version=1)
Read a place object tag.
Definition: gfxfile.cpp:457
GFXCharacter::LineStyle readLineStyle(byte version)
Read a line style.
Definition: gfxfile.cpp:950
boost::variant< PlaceObject, DoAction > _value
Definition: gfxfile.h:336
struct Aurora::GFXCharacter::ShapeRecord::@3 straightEdge
std::vector< GFXControl > _controlTags
All root control tags.
Definition: gfxfile.h:380
int16_t int16
Definition: types.h:201
Common::UString name
Definition: gfxfile.h:214
std::vector< GFXCharacter::FillStyle > readFillStyleArray(byte version)
Read an fillstyle array.
Definition: gfxfile.cpp:873
boost::optional< int16 > fontLeading
Definition: gfxfile.h:219
A simple scoped smart pointer template.
Common::ScopedPtr< Common::SeekableReadStream > _gfx
The read stream of this gfx file.
Definition: gfxfile.h:383
struct Aurora::GFXCharacter::ShapeRecord::@2 move
std::vector< ShapeRecord > shapeRecords
Definition: gfxfile.h:144
void getExternalImage(ExternalImage &externalImage) const
Get the external image character.
Definition: gfxfile.cpp:154
A control tag is used for controlling stuff in the scene, like placing or removing objects...
Definition: gfxfile.h:278
std::vector< Glyph > glyphs
Definition: gfxfile.h:215
boost::optional< Common::UString > name
Definition: gfxfile.h:309
void readInitAction(ActionScript::AVM &avm)
Read a DoInitAction tag.
Definition: gfxfile.cpp:716
A simple rectangle helper class.
static GFXCharacter createShape(uint16 id, Shape shape)
Create a shape character.
Definition: gfxfile.cpp:83
std::vector< GFXCharacter::ShapeRecord > readShape(byte version, bool withStyle)
Read a shape.
Definition: gfxfile.cpp:1004
The standard header of every tag.
Definition: gfxfile.h:370
void readDefineSprite()
Read a define sprite tag.
Definition: gfxfile.cpp:401
std::map< uint16, GFXCharacter > _characters
Every character associated with it&#39;s character id.
Definition: gfxfile.h:378
uint16_t uint16
Definition: types.h:202
ControlType _type
Definition: gfxfile.h:338
An external image character, which loads an image resource from the guis texture atlas files...
Definition: gfxfile.h:226
A color tranformation of the specific object.
Definition: gfxfile.h:290
Aurora::ActionScript::ASBuffer * readAction()
Read a DoAction tag.
Definition: gfxfile.cpp:727
void readGFXDefineExternalImage(RecordHeader header, byte version=0)
Load an external image reference.
Definition: gfxfile.cpp:771
void getDoAction(DoAction &doAction) const
Get do action control.
Definition: gfxfile.cpp:188
void readExportAssets()
Read an export assets tag.
Definition: gfxfile.cpp:345
boost::optional< ColorTransform > colorTransform
Definition: gfxfile.h:311
GFXCharacter::GradientRecord readGradientRecord(byte version)
Read a gradient record.
Definition: gfxfile.cpp:993
Common::Rect _frameSize
The standard bounds of the ui in this file.
Definition: gfxfile.h:386
A do action control tag.
Definition: gfxfile.h:316
uint16 getExportedAssetId(const Common::UString &id)
Get the corresponding character id for an exported asset.
Definition: gfxfile.cpp:206
void readDefineFont()
Read a font definition version 3.
Definition: gfxfile.cpp:523
static GFXControl createShowFrame()
Create a show frame control.
Definition: gfxfile.cpp:177
glm::mat3x2 readMatrix()
Read a matrix.
Definition: gfxfile.cpp:828
RecordHeader readRecordHeader()
Read a record header for the next tag.
Definition: gfxfile.cpp:799
void readHeader()
Load all header information.
Definition: gfxfile.cpp:322
glm::u8vec4 readRGBA()
Reag an RGBA color record.
Definition: gfxfile.cpp:864
A Scaleform GFx font, usable for rendering letters in the ui.
Definition: gfxfile.h:213
void readDefineShape(byte version)
Read a DefineShape tag.
Definition: gfxfile.cpp:331
Element placeable in the current scene.
Definition: gfxfile.h:49
CharacterType getType() const
Get the type of this character.
Definition: gfxfile.cpp:118
struct Aurora::GFXCharacter::ShapeRecord::@1 style
Basic reading stream interfaces.
void readGFXExporterInfo(RecordHeader header)
Load the information about the gfx exporter.
Definition: gfxfile.cpp:748
A bit stream.
static GFXCharacter createEditText(uint16 id, EditText editText)
Create an edit text character.
Definition: gfxfile.cpp:99
Unicode string handling.
void getPlaceObject(PlaceObject &placeObject) const
Get the place object control.
Definition: gfxfile.cpp:181
void readBackgroundColor()
Read the background color tag.
Definition: gfxfile.cpp:341
GFXControl::ColorTransform readColorTransform()
Read a color transform.
Definition: gfxfile.cpp:962
CharacterType _type
Definition: gfxfile.h:269
Aurora::ActionScript::ASBuffer * asBuffer
Definition: gfxfile.h:317
A shape character, which is a static image shape with bounds.
Definition: gfxfile.h:175
glm::u8vec3 readRGB()
Read an RGB color record.
Definition: gfxfile.cpp:856
Common::UString readLengthPrefixedString()
Read a byte length prefixed string.
Definition: gfxfile.cpp:1124
void getFont(Font &font) const
Get the font character.
Definition: gfxfile.cpp:140
Common::Rect readRectangle()
Read a basic rectangle type from the gfx file.
Definition: gfxfile.cpp:813
A style for the border.
Definition: gfxfile.h:98
boost::optional< uint16 > fontDescent
Definition: gfxfile.h:218
uint32_t uint32
Definition: types.h:204
Part of a gradient.
Definition: gfxfile.h:63
void readDefineEditText()
Read an edit text character.
Definition: gfxfile.cpp:640
Optional layout for edit texts.
Definition: gfxfile.h:181
void getSprite(Sprite &sprite) const
Get the sprite character.
Definition: gfxfile.cpp:126
void getEditText(EditText &editText) const
Get the edit text character.
Definition: gfxfile.cpp:147
boost::optional< glm::u8vec4 > textColor
Definition: gfxfile.h:204
CharacterType
The possible element types, used in the scene.
Definition: gfxfile.h:54
std::map< Common::UString, uint16 > _exportTable
Every exported character id with the associated export name.
Definition: gfxfile.h:376
A place object control tag for placing objects.
Definition: gfxfile.h:304
A style for filling.
Definition: gfxfile.h:88
std::vector< GFXControl > getControls()
Get all root controls.
Definition: gfxfile.h:366
std::vector< GFXCharacter::LineStyle > readLineStyleArray(byte version)
Read a line style array.
Definition: gfxfile.cpp:937
ControlType getType() const
Get the type of this control.
Definition: gfxfile.h:328
uint16 getId() const
Get the character id of this character.
Definition: gfxfile.cpp:122
unsigned short _frameCount
The count of frames in this gfx file.
Definition: gfxfile.h:390
A kerning code, which determines the adjustment of specific characters to another.
Definition: gfxfile.h:150
boost::optional< uint16 > fontId
Definition: gfxfile.h:202
Interface for a seekable & readable data stream.
Definition: readstream.h:265
struct Aurora::GFXCharacter::ShapeRecord::@4 curvedEdge
A bit stream.
Definition: bitstream.h:40
void getShape(Shape &shape) const
Get the shape character.
Definition: gfxfile.cpp:133
static GFXControl createDoAction(DoAction)
Create a do action control.
Definition: gfxfile.cpp:169
uint8 byte
Definition: types.h:209
float _frameRate
The frame rate, how fast this gui should be played.
Definition: gfxfile.h:388
boost::optional< Common::UString > initialText
Definition: gfxfile.h:206
A sprite character, which is basically a container with control statements and other characters...
Definition: gfxfile.h:167
boost::optional< glm::mat3x2 > matrix
Definition: gfxfile.h:310
static GFXCharacter createFont(uint16 id, Font font)
Create a font character.
Definition: gfxfile.cpp:91
int32_t int32
Definition: types.h:203
GFXCharacter(uint16 id, CharacterType type)
Definition: gfxfile.cpp:115
GFXControl(ControlType type)
Definition: gfxfile.cpp:195
static GFXControl createPlaceObject(PlaceObject)
Create a place object control.
Definition: gfxfile.cpp:161
The Action script virtual machine (AVM).
Definition: avm.h:46
A character glyph for a font.
Definition: gfxfile.h:141