102 character.
_value = editText;
110 character.
_value = externalImage;
130 sprite = boost::get<Sprite>(
_value);
137 shape = boost::get<Shape>(
_value);
144 font = boost::get<Font>(
_value);
151 editText = boost::get<EditText>(
_value);
158 externalImage = boost::get<ExternalImage>(
_value);
164 control.
_value = placeObject;
172 control.
_value = doAction;
185 placeObject = boost::get<PlaceObject>(
_value);
192 doAction = boost::get<DoAction>(
_value);
207 std::map<Common::UString, uint16>::iterator iter =
_exportTable.find(
id);
215 std::map<uint16, GFXCharacter>::iterator iter =
_characters.find(
id);
246 size_t oldSize =
_gfx->pos();
325 const byte denominator =
_gfx->readByte();
326 const byte numerator =
_gfx->readByte();
327 _frameRate = numerator + (denominator ? (1/denominator) : 0);
347 for (
unsigned int i = 0; i < count; ++i) {
360 assert(reserved == 1);
361 reserved =
_gfx->readByte();
362 assert(reserved == 0);
365 for (
unsigned int i = 0; i < count; ++i) {
369 uint16 exportId =
import.getExportedAssetId(name);
379 const bool useDirectBlit = bitStream.getBit() == 1;
380 const bool useGPU = bitStream.getBit() == 1;
381 const bool hasMetadata = bitStream.getBit() == 1;
382 const bool actionScript3 = bitStream.getBit() == 1;
384 const bool useNetwork = bitStream.getBit() == 1;
386 const uint32 zeros = bitStream.getBits(24);
390 warning(
"Direct Blit is not supported");
392 warning(
"useGPU flag is ignored");
394 warning(
"Metadata loading is not supported");
396 warning(
"ActionScript3 is not supported");
398 warning(
"Network usage is not supported");
407 std::vector<GFXControl> control;
412 const size_t oldSize =
_gfx->pos();
460 const bool placeFlagHasClipActions = bitStream.
getBit() == 1;
461 const bool placeFlagHasClipDepth = bitStream.getBit() == 1;
462 const bool placeFlagHasName = bitStream.getBit() == 1;
463 const bool placeFlagHasRatio = bitStream.getBit() == 1;
464 const bool placeFlagHasColorTransform = bitStream.getBit() == 1;
465 const bool placeFlagHasMatrix = bitStream.getBit() == 1;
466 const bool placeFlagHasCharacter = bitStream.getBit() == 1;
467 const bool placeFlagMove = bitStream.getBit() == 1;
469 bool placeFlagOpaqueBackground =
false;
470 bool placeFlagHasVisible =
false;
471 bool placeFlagHasImage =
false;
472 bool placeFlagHasClassName =
false;
473 bool placeFlagHasCacheAsBitmap =
false;
474 bool placeFlagHasBlendMode =
false;
475 bool placeFlagHasFilter =
false;
478 placeFlagOpaqueBackground = bitStream.getBit() == 1;
479 placeFlagHasVisible = bitStream.getBit() == 1;
480 placeFlagHasImage = bitStream.getBit() == 1;
481 placeFlagHasClassName = bitStream.getBit() == 1;
482 placeFlagHasCacheAsBitmap = bitStream.getBit() == 1;
483 placeFlagHasBlendMode = bitStream.getBit() == 1;
484 placeFlagHasFilter = bitStream.getBit() == 1;
487 if (placeFlagOpaqueBackground)
488 throw Common::Exception(
"GFXFile::readPlaceObject() Opaque background not supported");
489 if (placeFlagHasVisible)
490 throw Common::Exception(
"GFXFile::readPlaceObject() Visible flag not supported");
494 placeObject.
hasMove = placeFlagMove;
495 placeObject.
depth =
_gfx->readUint16LE();
497 if (placeFlagHasClassName || (placeFlagHasImage && placeFlagHasCharacter))
499 if (placeFlagHasCharacter)
501 if (placeFlagHasMatrix)
503 if (placeFlagHasColorTransform)
505 if (placeFlagHasRatio)
507 if (placeFlagHasName)
509 if (placeFlagHasClipDepth)
511 if (placeFlagHasFilter)
513 if (placeFlagHasBlendMode)
515 if (placeFlagHasCacheAsBitmap)
517 if (placeFlagHasClipActions)
529 const bool fontFlagHasLayout = bitStream.
getBit() == 1;
530 const bool fontFlagShiftJIS = bitStream.getBit() == 1;
531 const bool fontFlagHasSmallText = bitStream.getBit() == 1;
532 const bool fontFlagANSI = bitStream.getBit() == 1;
533 const bool fontFlagWideOffsets = bitStream.getBit() == 1;
534 const bool fontFlagWideCodes = bitStream.getBit() == 1;
535 const bool fontFlagItalic = bitStream.getBit() == 1;
536 const bool fontFlagBold = bitStream.getBit() == 1;
538 if (fontFlagShiftJIS)
539 warning(
"GFXFile::readDefineFont() ShiftJIS Encoding not supported");
540 if (fontFlagHasSmallText)
541 warning(
"GFXFile::readDefineFont() Small Text not supported");
543 warning(
"GFXFile::readDefineFont() ANSI Encoding not supported");
546 warning(
"GFXFile::readDefineFont() Italic fonts are not supported");
548 warning(
"GFXFile::readDefineFont() Bold Fonts are not supported");
550 const byte languageCode =
_gfx->readByte();
551 if (languageCode < 1 || languageCode > 5)
552 warning(
"GFXFile::readDefineFont() Invalid language code");
556 const uint16 numGlyphs =
_gfx->readUint16LE();
558 const size_t startOffsetTable =
_gfx->pos();
560 std::vector<uint32> offsetTable;
561 for (
unsigned int i = 0; i < numGlyphs; ++i) {
562 if (fontFlagWideOffsets) {
563 offsetTable.push_back(
_gfx->readUint32LE());
565 offsetTable.push_back(
_gfx->readUint16LE());
570 if (fontFlagWideOffsets)
571 codeTableOffset =
_gfx->readUint32LE();
573 codeTableOffset =
_gfx->readUint16LE();
575 std::vector<std::vector<GFXCharacter::ShapeRecord> > glyphRecords;
576 for (
unsigned int i = 0; i < numGlyphs; ++i) {
577 std::vector<GFXCharacter::ShapeRecord> records =
readShape(0,
false);
578 glyphRecords.push_back(records);
581 assert(codeTableOffset ==
_gfx->pos() - startOffsetTable);
583 std::vector<uint16> codeTable;
584 for (
unsigned int i = 0; i < numGlyphs; ++i) {
585 codeTable.push_back(
_gfx->readUint16LE());
588 std::vector<Common::Rect> bounds;
589 std::vector<int16> advance;
590 std::vector<GFXCharacter::KerningCode> kerningCodes;
591 if (fontFlagHasLayout) {
596 for (
unsigned int i = 0; i < numGlyphs; ++i) {
597 advance.push_back(
_gfx->readSint16LE());
600 for (
unsigned int i = 0; i < numGlyphs; ++i) {
604 const uint16 kerningCount =
_gfx->readUint16LE();
605 kerningCodes.resize(kerningCount);
606 for (
unsigned int i = 0; i < kerningCount; ++i) {
607 if (fontFlagWideCodes) {
608 kerningCodes[i].code1 =
_gfx->readUint16LE();
609 kerningCodes[i].code2 =
_gfx->readUint16LE();
611 kerningCodes[i].code1 =
_gfx->readByte();
612 kerningCodes[i].code2 =
_gfx->readByte();
615 kerningCodes[i].adjustment =
_gfx->readSint16LE();
621 std::vector<GFXCharacter::Glyph> glyphs;
623 for (
unsigned int i = 0; i < numGlyphs; ++i) {
626 glyph.
code = codeTable[i];
632 glyphs.push_back(glyph);
641 const uint16 characterId =
_gfx->readUint16LE();
648 const bool hasText = bitStream.
getBit() == 1;
649 const bool wordWrap = bitStream.getBit() == 1;
650 const bool multiLine = bitStream.getBit() == 1;
651 const bool password = bitStream.getBit() == 1;
652 const bool readOnly = bitStream.getBit() == 1;
653 const bool hasTextColor = bitStream.getBit() == 1;
654 const bool hasMaxLength = bitStream.getBit() == 1;
655 const bool hasFont = bitStream.getBit() == 1;
656 const bool hasFontClass = bitStream.getBit() == 1;
657 const bool autoSize = bitStream.getBit() == 1;
658 const bool hasLayout = bitStream.getBit() == 1;
659 const bool noSelect = bitStream.getBit() == 1;
660 const bool border = bitStream.getBit() == 1;
661 const bool wasStatic = bitStream.getBit() == 1;
662 const bool html = bitStream.getBit() == 1;
663 const bool useOutlines = bitStream.getBit() == 1;
666 warning(
"GFXFile::readDefineEditText() static text is not supported");
669 warning(
"GFXFile::readDefineEditText() border drawing is not supported");
672 warning(
"GFXFile::readDefineEditText() device fonts are nto supported");
680 editText.
html = html;
723 warning(
"Failed executing actionscript: %s", e.
what());
728 const size_t start =
_gfx->pos();
732 actionCode =
_gfx->readByte();
733 if (actionCode >= 0x80)
735 }
while (actionCode != 0);
737 const size_t stop =
_gfx->pos();
749 const size_t oldPos =
_gfx->pos();
752 if (version > 0x010A)
755 const uint16 bitmapFormat =
_gfx->readUint16LE();
756 assert(bitmapFormat == 14);
758 const byte prefixLen =
_gfx->readByte();
759 assert(prefixLen == 0);
765 for (
unsigned int i = 0; i < numCodeOffsets; ++i) {
772 const size_t oldPos =
_gfx->pos();
776 id =
_gfx->readUint16LE();
778 id =
_gfx->readUint32LE();
783 externalImage.
width =
_gfx->readUint16LE();
803 recordHeader.
tagType = bitStream.getBits(10);
804 recordHeader.
tagLength = bitStream.getBits(6);
816 const unsigned int nBits = bitStream.
getBits(5);
835 const bool hasScale = bitStream.
getBit() == 1;
837 uint32 numScaleBits = bitStream.getBits(5);
838 matrix[0][0] =
readNintendoFixedPoint(bitStream.getBits(numScaleBits), numScaleBits > 16, MAX<int32>(0, numScaleBits % 16 - 1), MIN<uint32>(numScaleBits, 16));
839 matrix[1][1] =
readNintendoFixedPoint(bitStream.getBits(numScaleBits), numScaleBits > 16, MAX<int32>(0, numScaleBits % 16 - 1), MIN<uint32>(numScaleBits, 16));
842 const bool hasRotate = bitStream.getBit() == 1;
844 uint32 numRotateBits = bitStream.getBits(5);
845 matrix[1][0] = bitStream.getBits(numRotateBits);
846 matrix[0][1] = bitStream.getBits(numRotateBits);
849 const uint32 numTranslateBits = bitStream.getBits(5);
858 r =
_gfx->readByte();
859 g =
_gfx->readByte();
860 b =
_gfx->readByte();
861 return glm::u8vec3(r, g, b);
866 r =
_gfx->readByte();
867 g =
_gfx->readByte();
868 b =
_gfx->readByte();
869 a =
_gfx->readByte();
870 return glm::u8vec4(r, g, b, a);
874 std::vector<GFXCharacter::FillStyle> fillStyleArray;
876 if (fillStyleCount == 0xFF)
877 fillStyleCount =
_gfx->readUint16LE();
879 for (
unsigned int i = 0; i < fillStyleCount; ++i) {
883 return fillStyleArray;
890 switch (fillStyle.
type) {
899 fillStyle.
value = fill;
911 uint32 numGradients = bitStream.getBits(4);
913 for (
uint32 i = 0; i < numGradients; ++i) {
917 fillStyle.
value = gradient;
924 bitmap.
id =
_gfx->readUint16LE();
927 fillStyle.
value = bitmap;
939 std::vector<GFXCharacter::LineStyle> lineStyleArray;
940 if (lineStyleCount == 0xFF)
941 lineStyleCount =
_gfx->readUint16LE();
943 for (
unsigned int i = 0; i < lineStyleCount; ++i) {
947 return lineStyleArray;
970 const unsigned int nbits = bitStream.getBits(4);
973 colorTransform.
mulR = bitStream.getBits(nbits);
974 colorTransform.
mulG = bitStream.getBits(nbits);
975 colorTransform.
mulB = bitStream.getBits(nbits);
976 colorTransform.
mulA = bitStream.getBits(nbits);
980 colorTransform.
addR = bitStream.getBits(nbits);
981 colorTransform.
addG = bitStream.getBits(nbits);
982 colorTransform.
addB = bitStream.getBits(nbits);
983 colorTransform.
addA = bitStream.getBits(nbits);
986 return colorTransform;
1005 std::vector<GFXCharacter::FillStyle> fillStyles;
1006 std::vector<GFXCharacter::LineStyle> lineStyles;
1018 byte numLineBits = bitStream.getBits(4);
1020 std::vector<GFXCharacter::ShapeRecord> shapeRecords;
1024 const bool type = bitStream.getBit() == 1;
1027 const bool straightEdge = bitStream.getBit() == 1;
1028 uint32 numBits = bitStream.getBits(4);
1031 const bool generalLine = bitStream.getBit() == 1;
1036 vertLine = bitStream.getBit() == 1;
1038 if (generalLine || !vertLine)
1042 if (generalLine || vertLine)
1053 const bool stateNewStyles = bitStream.getBit() == 1;
1054 const bool stateLineStyle = bitStream.getBit() == 1;
1055 const bool stateFillStyle1 = bitStream.getBit() == 1;
1056 const bool stateFillStyle0 = bitStream.getBit() == 1;
1057 const bool stateMoveTo = bitStream.getBit() == 1;
1059 if (!stateNewStyles && !stateLineStyle && !stateFillStyle1 && !stateFillStyle0 && !stateMoveTo)
1063 const size_t moveBits = bitStream.getBits(5);
1069 if (stateFillStyle0) {
1070 const uint32 index = bitStream.getBits(numFillBits);
1071 if (!fillStyles.empty()) {
1079 if (stateFillStyle1) {
1080 const uint32 index = bitStream.getBits(numFillBits);
1081 if (!fillStyles.empty()) {
1089 if (stateLineStyle) {
1090 const uint32 index = bitStream.getBits(numLineBits);
1091 if (!lineStyles.empty()) {
1099 if (stateNewStyles) {
1101 throw Common::Exception(
"New styles can only be defined by DefineShape2 and DefineShape3");
1106 if (bitStream.pos() % 8 != 0)
1107 bitStream.skip(8 - (bitStream.pos() % 8));
1109 numFillBits = bitStream.getBits(4);
1110 numLineBits = bitStream.getBits(4);
1114 shapeRecords.push_back(record);
1117 return shapeRecords;
1125 const byte length =
_gfx->readByte();
1131 const uint32 sign = v >> (n - 1) << (n - 1);
1132 const int32 value = -sign + (v ^ sign);
Class for parsing gfx files.
void readFileAttributes()
Read the file attributes tag.
#define ResMan
Shortcut for accessing the sound manager.
Common::UString readNullTerminatedString()
Read a null terminated string.
int32 read2ComplementValue(Common::BitStream &bitStream, size_t n)
Read a 2's complement value.
#define MKTAG(a0, a1, a2, a3)
A wrapper macro used around four character constants, like 'DATA', to ensure portability.
std::vector< GradientRecord > records
std::vector< KerningCode > kerningCodes
static GFXCharacter createSprite(uint16 id, Sprite sprite)
Create a sprite character.
boost::optional< uint16 > fontHeight
void readFocalGradient(byte version)
Read a focal gradient record.
A class holding an UTF-8 string.
boost::optional< uint16 > characterId
GFXFile(const Common::UString &resref, Aurora::ActionScript::AVM &avm)
Open a gfx file specified by the reference and used with the specified avm.
void reset(PointerType o=0)
Resets the pointer with the new value.
boost::variant< Fill, Gradient, Bitmap > value
GFX files are used for the dragonage and dragonage2 guis.
GFXCharacter::FillStyle readFillStyle(byte version)
Read an FillStyle record.
std::vector< GFXControl > controls
ControlType
The possible control types.
TextAlignment
The alignment of text.
void load(Common::SeekableReadStream *gfx, Aurora::ActionScript::AVM &avm)
boost::variant< Sprite, Shape, EditText, Font, ExternalImage > _value
boost::optional< uint8 > blendMode
std::vector< ShapeRecord > shapeRecords
boost::optional< uint16 > maxLength
static GFXCharacter createExternalImage(uint16 id, ExternalImage externalImage)
Create an external image character.
void readImportAssets(ActionScript::AVM &avm)
Read an import assets tag.
boost::optional< uint16 > fontAscent
boost::optional< EditTextLayout > layout
An edit text character, mostly used as static, but sometimes also used as editable text...
GFXCharacter getCharacter(uint16 id)
Get a character by id.
uint32 getBit()
Read a bit from the bit stream.
uint32 getBits(size_t n)
Read a multi-bit value from the bit stream.
GFXControl readPlaceObject(byte version=1)
Read a place object tag.
GFXCharacter::LineStyle readLineStyle(byte version)
Read a line style.
boost::variant< PlaceObject, DoAction > _value
struct Aurora::GFXCharacter::ShapeRecord::@3 straightEdge
std::vector< GFXControl > _controlTags
All root control tags.
Exception that provides a stack of explanations.
std::vector< GFXCharacter::FillStyle > readFillStyleArray(byte version)
Read an fillstyle array.
boost::optional< int16 > fontLeading
Common::ScopedPtr< Common::SeekableReadStream > _gfx
The read stream of this gfx file.
struct Aurora::GFXCharacter::ShapeRecord::@2 move
std::vector< ShapeRecord > shapeRecords
void getExternalImage(ExternalImage &externalImage) const
Get the external image character.
A control tag is used for controlling stuff in the scene, like placing or removing objects...
std::vector< Glyph > glyphs
boost::optional< Common::UString > name
void readInitAction(ActionScript::AVM &avm)
Read a DoInitAction tag.
static GFXCharacter createShape(uint16 id, Shape shape)
Create a shape character.
std::vector< GFXCharacter::ShapeRecord > readShape(byte version, bool withStyle)
Read a shape.
void readDefineSprite()
Read a define sprite tag.
std::map< uint16, GFXCharacter > _characters
Every character associated with it's character id.
An external image character, which loads an image resource from the guis texture atlas files...
Utility templates and functions.
Aurora::ActionScript::ASBuffer * readAction()
Read a DoAction tag.
void readGFXDefineExternalImage(RecordHeader header, byte version=0)
Load an external image reference.
void getDoAction(DoAction &doAction) const
Get do action control.
virtual size_t skip(ptrdiff_t offset)
Skip the specified number of bytes, adding that offset to the current position in the stream...
void readExportAssets()
Read an export assets tag.
boost::optional< ColorTransform > colorTransform
GFXCharacter::GradientRecord readGradientRecord(byte version)
Read a gradient record.
Common::Rect _frameSize
The standard bounds of the ui in this file.
uint16 getExportedAssetId(const Common::UString &id)
Get the corresponding character id for an exported asset.
double readNintendoFixedPoint(uint32 value, bool sign, uint8 iBits, uint8 fBits)
Read a fixed-point value, in a format used by the Nintendo DS.
Simple memory based 'stream', which implements the ReadStream interface for a plain memory block...
void readDefineFont()
Read a font definition version 3.
Utility functions for working with differing string encodings.
static GFXControl createShowFrame()
Create a show frame control.
glm::mat3x2 readMatrix()
Read a matrix.
RecordHeader readRecordHeader()
Read a record header for the next tag.
void readHeader()
Load all header information.
A scoped plain pointer, allowing pointer-y access and normal deletion.
glm::u8vec4 readRGBA()
Reag an RGBA color record.
A Scaleform GFx font, usable for rendering letters in the ui.
void readDefineShape(byte version)
Read a DefineShape tag.
Element placeable in the current scene.
void warning(const char *s,...)
virtual size_t size() const =0
Obtains the total size of the stream, measured in bytes.
CharacterType getType() const
Get the type of this character.
struct Aurora::GFXCharacter::ShapeRecord::@1 style
Basic reading stream interfaces.
void readGFXExporterInfo(RecordHeader header)
Load the information about the gfx exporter.
byte * decompressDeflateWithoutOutputSize(const byte *data, size_t inputSize, size_t &outputSize, int windowBits, unsigned int frameSize)
Decompress (inflate) using zlib's DEFLATE algorithm without knowing the output size.
uint32 readUint32BE()
Read an unsigned 32-bit word stored in big endian (MSB first) order from the stream and return it...
static GFXCharacter createEditText(uint16 id, EditText editText)
Create an edit text character.
Seek from the current position of the stream.
void skip(size_t n)
Skip the specified amount of bits.
void getPlaceObject(PlaceObject &placeObject) const
Get the place object control.
Plain, unextended ASCII (7bit clean).
void readBackgroundColor()
Read the background color tag.
GFXControl::ColorTransform readColorTransform()
Read a color transform.
static const int kWindowBitsMax
PointerType get() const
Returns the plain pointer value.
Aurora::ActionScript::ASBuffer * asBuffer
A shape character, which is a static image shape with bounds.
static UString getStem(const UString &p)
Return a file name's stem.
glm::u8vec3 readRGB()
Read an RGB color record.
Common::UString readLengthPrefixedString()
Read a byte length prefixed string.
void getFont(Font &font) const
Get the font character.
Common::Rect readRectangle()
Read a basic rectangle type from the gfx file.
boost::optional< uint16 > fontDescent
static const uint32 kCFXID
void readDefineEditText()
Read an edit text character.
Optional layout for edit texts.
void getSprite(Sprite &sprite) const
Get the sprite character.
void getEditText(EditText &editText) const
Get the edit text character.
virtual uint32 getBits(size_t n)=0
Read a multi-bit value from the bit stream.
UString readString(SeekableReadStream &stream, Encoding encoding)
Read a string with the given encoding of a stream.
boost::optional< glm::u8vec4 > textColor
CharacterType
The possible element types, used in the scene.
Vector graphics animation, Scaleform GFx.
std::map< Common::UString, uint16 > _exportTable
Every exported character id with the associated export name.
A place object control tag for placing objects.
A template implementing a bit stream for different data memory layouts.
UString readStringFixed(SeekableReadStream &stream, Encoding encoding, size_t length)
Read length bytes as a string with the given encoding out of a stream.
SeekableSubReadStream provides access to a SeekableReadStream restricted to the range [begin...
const char * what() const
std::vector< GFXCharacter::LineStyle > readLineStyleArray(byte version)
Read a line style array.
Compress (deflate) and decompress (inflate) using zlib's DEFLATE algorithm.
uint16 getId() const
Get the character id of this character.
unsigned short _frameCount
The count of frames in this gfx file.
boost::optional< uint16 > fontId
Interface for a seekable & readable data stream.
struct Aurora::GFXCharacter::ShapeRecord::@4 curvedEdge
void getShape(Shape &shape) const
Get the shape character.
The global resource manager for Aurora resources.
Utility class for manipulating file paths.
static GFXControl createDoAction(DoAction)
Create a do action control.
boost::optional< Common::UString > initialText
float _frameRate
The frame rate, how fast this gui should be played.
A sprite character, which is basically a container with control statements and other characters...
boost::optional< glm::mat3x2 > matrix
static GFXCharacter createFont(uint16 id, Font font)
Create a font character.
GFXCharacter(uint16 id, CharacterType type)
GFXControl(ControlType type)
static GFXControl createPlaceObject(PlaceObject)
Create a place object control.
The Action script virtual machine (AVM).
A character glyph for a font.