123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064 |
- // Copyright (C) 2002-2012 Nikolaus Gebhardt
- // This file is part of the "Irrlicht Engine".
- // For conditions of distribution and use, see copyright notice in irrlicht.h
- #include "CAttributes.h"
- #include "fast_atof.h"
- #include "ITexture.h"
- #include "IVideoDriver.h"
- namespace irr
- {
- namespace io
- {
- /*
- basic types
- */
- // Attribute implemented for boolean values
- class CBoolAttribute : public IAttribute
- {
- public:
- CBoolAttribute(const char* name, bool value)
- {
- Name = name;
- setBool(value);
- }
- virtual s32 getInt()
- {
- return BoolValue ? 1 : 0;
- }
- virtual f32 getFloat()
- {
- return BoolValue ? 1.0f : 0.0f;
- }
- virtual bool getBool()
- {
- return BoolValue;
- }
- virtual core::stringw getStringW()
- {
- return core::stringw( BoolValue ? L"true" : L"false" );
- }
- virtual void setInt(s32 intValue)
- {
- BoolValue = (intValue != 0);
- }
- virtual void setFloat(f32 floatValue)
- {
- BoolValue = (floatValue != 0);
- }
- virtual void setBool(bool boolValue)
- {
- BoolValue = boolValue;
- }
- virtual void setString(const char* string)
- {
- BoolValue = strcmp(string, "true") == 0;
- }
- virtual E_ATTRIBUTE_TYPE getType() const
- {
- return EAT_BOOL;
- }
- virtual const wchar_t* getTypeString() const
- {
- return L"bool";
- }
- bool BoolValue;
- };
- // Attribute implemented for integers
- class CIntAttribute : public IAttribute
- {
- public:
- CIntAttribute(const char* name, s32 value)
- {
- Name = name;
- setInt(value);
- }
- virtual s32 getInt()
- {
- return Value;
- }
- virtual f32 getFloat()
- {
- return (f32)Value;
- }
- virtual bool getBool()
- {
- return (Value != 0);
- }
- virtual core::stringw getStringW()
- {
- return core::stringw(Value);
- }
- virtual void setInt(s32 intValue)
- {
- Value = intValue;
- }
- virtual void setFloat(f32 floatValue)
- {
- Value = (s32)floatValue;
- };
- virtual void setString(const char* text)
- {
- Value = atoi(text);
- }
- virtual E_ATTRIBUTE_TYPE getType() const
- {
- return EAT_INT;
- }
- virtual const wchar_t* getTypeString() const
- {
- return L"int";
- }
- s32 Value;
- };
- // Attribute implemented for floats
- class CFloatAttribute : public IAttribute
- {
- public:
- CFloatAttribute(const char* name, f32 value)
- {
- Name = name;
- setFloat(value);
- }
- virtual s32 getInt()
- {
- return (s32)Value;
- }
- virtual f32 getFloat()
- {
- return Value;
- }
- virtual bool getBool()
- {
- return (Value != 0);
- }
- virtual core::stringw getStringW()
- {
- return core::stringw((double)Value);
- }
- virtual void setInt(s32 intValue)
- {
- Value = (f32)intValue;
- }
- virtual void setFloat(f32 floatValue)
- {
- Value = floatValue;
- }
- virtual void setString(const char* text)
- {
- Value = core::fast_atof(text);
- }
- virtual E_ATTRIBUTE_TYPE getType() const
- {
- return EAT_FLOAT;
- }
- virtual const wchar_t* getTypeString() const
- {
- return L"float";
- }
- f32 Value;
- };
- /*
- Types which can be represented as a list of numbers
- */
- // Base class for all attributes which are a list of numbers-
- // vectors, colors, positions, triangles, etc
- class CNumbersAttribute : public IAttribute
- {
- public:
- CNumbersAttribute(const char* name, video::SColorf value) :
- ValueI(), ValueF(), Count(4), IsFloat(true)
- {
- Name = name;
- ValueF.push_back(value.r);
- ValueF.push_back(value.g);
- ValueF.push_back(value.b);
- ValueF.push_back(value.a);
- }
- CNumbersAttribute(const char* name, video::SColor value) :
- ValueI(), ValueF(), Count(4), IsFloat(false)
- {
- Name = name;
- ValueI.push_back(value.getRed());
- ValueI.push_back(value.getGreen());
- ValueI.push_back(value.getBlue());
- ValueI.push_back(value.getAlpha());
- }
- CNumbersAttribute(const char* name, core::vector3df value) :
- ValueI(), ValueF(), Count(3), IsFloat(true)
- {
- Name = name;
- ValueF.push_back(value.X);
- ValueF.push_back(value.Y);
- ValueF.push_back(value.Z);
- }
- CNumbersAttribute(const char* name, core::rect<s32> value) :
- ValueI(), ValueF(), Count(4), IsFloat(false)
- {
- Name = name;
- ValueI.push_back(value.UpperLeftCorner.X);
- ValueI.push_back(value.UpperLeftCorner.Y);
- ValueI.push_back(value.LowerRightCorner.X);
- ValueI.push_back(value.LowerRightCorner.Y);
- }
- CNumbersAttribute(const char* name, core::rect<f32> value) :
- ValueI(), ValueF(), Count(4), IsFloat(true)
- {
- Name = name;
- ValueF.push_back(value.UpperLeftCorner.X);
- ValueF.push_back(value.UpperLeftCorner.Y);
- ValueF.push_back(value.LowerRightCorner.X);
- ValueF.push_back(value.LowerRightCorner.Y);
- }
- CNumbersAttribute(const char* name, core::matrix4 value) :
- ValueI(), ValueF(), Count(16), IsFloat(true)
- {
- Name = name;
- for (s32 r=0; r<4; ++r)
- for (s32 c=0; c<4; ++c)
- ValueF.push_back(value(r,c));
- }
- CNumbersAttribute(const char* name, core::quaternion value) :
- ValueI(), ValueF(), Count(4), IsFloat(true)
- {
- Name = name;
- ValueF.push_back(value.X);
- ValueF.push_back(value.Y);
- ValueF.push_back(value.Z);
- ValueF.push_back(value.W);
- }
- CNumbersAttribute(const char* name, core::aabbox3d<f32> value) :
- ValueI(), ValueF(), Count(6), IsFloat(true)
- {
- Name = name;
- ValueF.push_back(value.MinEdge.X);
- ValueF.push_back(value.MinEdge.Y);
- ValueF.push_back(value.MinEdge.Z);
- ValueF.push_back(value.MaxEdge.X);
- ValueF.push_back(value.MaxEdge.Y);
- ValueF.push_back(value.MaxEdge.Z);
- }
- CNumbersAttribute(const char* name, core::plane3df value) :
- ValueI(), ValueF(), Count(4), IsFloat(true)
- {
- Name = name;
- ValueF.push_back(value.Normal.X);
- ValueF.push_back(value.Normal.Y);
- ValueF.push_back(value.Normal.Z);
- ValueF.push_back(value.D);
- }
- CNumbersAttribute(const char* name, core::triangle3df value) :
- ValueI(), ValueF(), Count(9), IsFloat(true)
- {
- Name = name;
- ValueF.push_back(value.pointA.X);
- ValueF.push_back(value.pointA.Y);
- ValueF.push_back(value.pointA.Z);
- ValueF.push_back(value.pointB.X);
- ValueF.push_back(value.pointB.Y);
- ValueF.push_back(value.pointB.Z);
- ValueF.push_back(value.pointC.X);
- ValueF.push_back(value.pointC.Y);
- ValueF.push_back(value.pointC.Z);
- }
- CNumbersAttribute(const char* name, core::vector2df value) :
- ValueI(), ValueF(), Count(2), IsFloat(true)
- {
- Name = name;
- ValueF.push_back(value.X);
- ValueF.push_back(value.Y);
- }
- CNumbersAttribute(const char* name, core::vector2di value) :
- ValueI(), ValueF(), Count(2), IsFloat(false)
- {
- Name = name;
- ValueI.push_back(value.X);
- ValueI.push_back(value.Y);
- }
- CNumbersAttribute(const char* name, core::line2di value) :
- ValueI(), ValueF(), Count(4), IsFloat(false)
- {
- Name = name;
- ValueI.push_back(value.start.X);
- ValueI.push_back(value.start.Y);
- ValueI.push_back(value.end.X);
- ValueI.push_back(value.end.Y);
- }
- CNumbersAttribute(const char* name, core::line2df value) :
- ValueI(), ValueF(), Count(4), IsFloat(true)
- {
- Name = name;
- ValueF.push_back(value.start.X);
- ValueF.push_back(value.start.Y);
- ValueF.push_back(value.end.X);
- ValueF.push_back(value.end.Y);
- }
- CNumbersAttribute(const char* name, core::line3df value) :
- ValueI(), ValueF(), Count(6), IsFloat(true)
- {
- Name = name;
- ValueF.push_back(value.start.X);
- ValueF.push_back(value.start.Y);
- ValueF.push_back(value.start.Z);
- ValueF.push_back(value.end.X);
- ValueF.push_back(value.end.Y);
- ValueF.push_back(value.end.Z);
- }
- CNumbersAttribute(const char* name, core::dimension2du value) :
- ValueI(), ValueF(), Count(2), IsFloat(false)
- {
- Name = name;
- ValueI.push_back(value.Width);
- ValueI.push_back(value.Height);
- }
- CNumbersAttribute(const char* name, core::dimension2df value) :
- ValueI(), ValueF(), Count(2), IsFloat(true)
- {
- Name = name;
- ValueF.push_back(value.Width);
- ValueF.push_back(value.Height);
- }
- // getting values
- virtual s32 getInt()
- {
- if (Count==0)
- return 0;
- if (IsFloat)
- return (s32)ValueF[0];
- else
- return ValueI[0];
- }
- virtual f32 getFloat()
- {
- if (Count==0)
- return 0.0f;
- if (IsFloat)
- return ValueF[0];
- else
- return (f32)ValueI[0];
- }
- virtual bool getBool()
- {
- // return true if any number is nonzero
- bool ret=false;
- for (u32 i=0; i < Count; ++i)
- if ( IsFloat ? (ValueF[i] != 0) : (ValueI[i] != 0) )
- {
- ret=true;
- break;
- }
- return ret;
- }
- virtual core::stringc getString()
- {
- core::stringc outstr;
- for (u32 i=0; i <Count; ++i)
- {
- if (IsFloat)
- outstr += ValueF[i];
- else
- outstr += ValueI[i];
- if (i < Count-1)
- outstr += ", ";
- }
- return outstr;
- }
- virtual core::stringw getStringW()
- {
- core::stringw outstr;
- for (u32 i=0; i <Count; ++i)
- {
- if (IsFloat)
- outstr += ValueF[i];
- else
- outstr += ValueI[i];
- if (i < Count-1)
- outstr += L", ";
- }
- return outstr;
- }
- virtual core::position2di getPosition()
- {
- core::position2di p;
- if (IsFloat)
- {
- p.X = (s32)(Count > 0 ? ValueF[0] : 0);
- p.Y = (s32)(Count > 1 ? ValueF[1] : 0);
- }
- else
- {
- p.X = Count > 0 ? ValueI[0] : 0;
- p.Y = Count > 1 ? ValueI[1] : 0;
- }
- return p;
- }
- virtual core::vector3df getVector()
- {
- core::vector3df v;
- if (IsFloat)
- {
- v.X = Count > 0 ? ValueF[0] : 0;
- v.Y = Count > 1 ? ValueF[1] : 0;
- v.Z = Count > 2 ? ValueF[2] : 0;
- }
- else
- {
- v.X = (f32)(Count > 0 ? ValueI[0] : 0);
- v.Y = (f32)(Count > 1 ? ValueI[1] : 0);
- v.Z = (f32)(Count > 2 ? ValueI[2] : 0);
- }
- return v;
- }
- virtual core::vector2df getVector2d()
- {
- core::vector2df v;
- if (IsFloat)
- {
- v.X = Count > 0 ? ValueF[0] : 0;
- v.Y = Count > 1 ? ValueF[1] : 0;
- }
- else
- {
- v.X = (f32)(Count > 0 ? ValueI[0] : 0);
- v.Y = (f32)(Count > 1 ? ValueI[1] : 0);
- }
- return v;
- }
- virtual video::SColorf getColorf()
- {
- video::SColorf c;
- if (IsFloat)
- {
- c.setColorComponentValue(0, Count > 0 ? ValueF[0] : 0);
- c.setColorComponentValue(1, Count > 1 ? ValueF[1] : 0);
- c.setColorComponentValue(2, Count > 2 ? ValueF[2] : 0);
- c.setColorComponentValue(3, Count > 3 ? ValueF[3] : 0);
- }
- else
- {
- c.setColorComponentValue(0, Count > 0 ? (f32)(ValueI[0]) / 255.0f : 0);
- c.setColorComponentValue(1, Count > 1 ? (f32)(ValueI[1]) / 255.0f : 0);
- c.setColorComponentValue(2, Count > 2 ? (f32)(ValueI[2]) / 255.0f : 0);
- c.setColorComponentValue(3, Count > 3 ? (f32)(ValueI[3]) / 255.0f : 0);
- }
- return c;
- }
- virtual video::SColor getColor()
- {
- return getColorf().toSColor();
- }
- virtual core::rect<s32> getRect()
- {
- core::rect<s32> r;
- if (IsFloat)
- {
- r.UpperLeftCorner.X = (s32)(Count > 0 ? ValueF[0] : 0);
- r.UpperLeftCorner.Y = (s32)(Count > 1 ? ValueF[1] : 0);
- r.LowerRightCorner.X = (s32)(Count > 2 ? ValueF[2] : r.UpperLeftCorner.X);
- r.LowerRightCorner.Y = (s32)(Count > 3 ? ValueF[3] : r.UpperLeftCorner.Y);
- }
- else
- {
- r.UpperLeftCorner.X = Count > 0 ? ValueI[0] : 0;
- r.UpperLeftCorner.Y = Count > 1 ? ValueI[1] : 0;
- r.LowerRightCorner.X = Count > 2 ? ValueI[2] : r.UpperLeftCorner.X;
- r.LowerRightCorner.Y = Count > 3 ? ValueI[3] : r.UpperLeftCorner.Y;
- }
- return r;
- }
- virtual core::dimension2du getDimension2d()
- {
- core::dimension2d<u32> dim;
- if (IsFloat)
- {
- dim.Width = (u32)(Count > 0 ? ValueF[0] : 0);
- dim.Height = (u32)(Count > 1 ? ValueF[1] : 0);
- }
- else
- {
- dim.Width = (u32)(Count > 0 ? ValueI[0] : 0);
- dim.Height = (u32)(Count > 1 ? ValueI[1] : 0);
- }
- return dim;
- }
- virtual core::matrix4 getMatrix()
- {
- core::matrix4 ret;
- if (IsFloat)
- {
- for (u32 r=0; r<4; ++r)
- for (u32 c=0; c<4; ++c)
- if (Count > c+r*4)
- ret(r,c) = ValueF[c+r*4];
- }
- else
- {
- for (u32 r=0; r<4; ++r)
- for (u32 c=0; c<4; ++c)
- if (Count > c+r*4)
- ret(r,c) = (f32)ValueI[c+r*4];
- }
- return ret;
- }
- virtual core::quaternion getQuaternion()
- {
- core::quaternion ret;
- if (IsFloat)
- {
- ret.X = Count > 0 ? ValueF[0] : 0.0f;
- ret.Y = Count > 1 ? ValueF[1] : 0.0f;
- ret.Z = Count > 2 ? ValueF[2] : 0.0f;
- ret.W = Count > 3 ? ValueF[3] : 0.0f;
- }
- else
- {
- ret.X = Count > 0 ? (f32)ValueI[0] : 0.0f;
- ret.Y = Count > 1 ? (f32)ValueI[1] : 0.0f;
- ret.Z = Count > 2 ? (f32)ValueI[2] : 0.0f;
- ret.W = Count > 3 ? (f32)ValueI[3] : 0.0f;
- }
- return ret;
- }
- virtual core::triangle3df getTriangle()
- {
- core::triangle3df ret;
- if (IsFloat)
- {
- ret.pointA.X = Count > 0 ? ValueF[0] : 0.0f;
- ret.pointA.Y = Count > 1 ? ValueF[1] : 0.0f;
- ret.pointA.Z = Count > 2 ? ValueF[2] : 0.0f;
- ret.pointB.X = Count > 3 ? ValueF[3] : 0.0f;
- ret.pointB.Y = Count > 4 ? ValueF[4] : 0.0f;
- ret.pointB.Z = Count > 5 ? ValueF[5] : 0.0f;
- ret.pointC.X = Count > 6 ? ValueF[6] : 0.0f;
- ret.pointC.Y = Count > 7 ? ValueF[7] : 0.0f;
- ret.pointC.Z = Count > 8 ? ValueF[8] : 0.0f;
- }
- else
- {
- ret.pointA.X = Count > 0 ? (f32)ValueI[0] : 0.0f;
- ret.pointA.Y = Count > 1 ? (f32)ValueI[1] : 0.0f;
- ret.pointA.Z = Count > 2 ? (f32)ValueI[2] : 0.0f;
- ret.pointB.X = Count > 3 ? (f32)ValueI[3] : 0.0f;
- ret.pointB.Y = Count > 4 ? (f32)ValueI[4] : 0.0f;
- ret.pointB.Z = Count > 5 ? (f32)ValueI[5] : 0.0f;
- ret.pointC.X = Count > 6 ? (f32)ValueI[6] : 0.0f;
- ret.pointC.Y = Count > 7 ? (f32)ValueI[7] : 0.0f;
- ret.pointC.Z = Count > 8 ? (f32)ValueI[8] : 0.0f;
- }
- return ret;
- }
- virtual core::plane3df getPlane()
- {
- core::plane3df ret;
- if (IsFloat)
- {
- ret.Normal.X = Count > 0 ? ValueF[0] : 0.0f;
- ret.Normal.Y = Count > 1 ? ValueF[1] : 0.0f;
- ret.Normal.Z = Count > 2 ? ValueF[2] : 0.0f;
- ret.D = Count > 3 ? ValueF[3] : 0.0f;
- }
- else
- {
- ret.Normal.X = Count > 0 ? (f32)ValueI[0] : 0.0f;
- ret.Normal.Y = Count > 1 ? (f32)ValueI[1] : 0.0f;
- ret.Normal.Z = Count > 2 ? (f32)ValueI[2] : 0.0f;
- ret.D = Count > 3 ? (f32)ValueI[3] : 0.0f;
- }
- return ret;
- }
- virtual core::aabbox3df getBBox()
- {
- core::aabbox3df ret;
- if (IsFloat)
- {
- ret.MinEdge.X = Count > 0 ? ValueF[0] : 0.0f;
- ret.MinEdge.Y = Count > 1 ? ValueF[1] : 0.0f;
- ret.MinEdge.Z = Count > 2 ? ValueF[2] : 0.0f;
- ret.MaxEdge.X = Count > 3 ? ValueF[3] : 0.0f;
- ret.MaxEdge.Y = Count > 4 ? ValueF[4] : 0.0f;
- ret.MaxEdge.Z = Count > 5 ? ValueF[5] : 0.0f;
- }
- else
- {
- ret.MinEdge.X = Count > 0 ? (f32)ValueI[0] : 0.0f;
- ret.MinEdge.Y = Count > 1 ? (f32)ValueI[1] : 0.0f;
- ret.MinEdge.Z = Count > 2 ? (f32)ValueI[2] : 0.0f;
- ret.MaxEdge.X = Count > 3 ? (f32)ValueI[3] : 0.0f;
- ret.MaxEdge.Y = Count > 4 ? (f32)ValueI[4] : 0.0f;
- ret.MaxEdge.Z = Count > 5 ? (f32)ValueI[5] : 0.0f;
- }
- return ret;
- }
- virtual core::line2df getLine2d()
- {
- core::line2df ret;
- if (IsFloat)
- {
- ret.start.X = Count > 0 ? ValueF[0] : 0.0f;
- ret.start.Y = Count > 1 ? ValueF[1] : 0.0f;
- ret.end.X = Count > 2 ? ValueF[2] : 0.0f;
- ret.end.Y = Count > 3 ? ValueF[3] : 0.0f;
- }
- else
- {
- ret.start.X = Count > 0 ? (f32)ValueI[0] : 0.0f;
- ret.start.Y = Count > 1 ? (f32)ValueI[1] : 0.0f;
- ret.end.X = Count > 2 ? (f32)ValueI[2] : 0.0f;
- ret.end.Y = Count > 3 ? (f32)ValueI[3] : 0.0f;
- }
- return ret;
- }
- virtual core::line3df getLine3d()
- {
- core::line3df ret;
- if (IsFloat)
- {
- ret.start.X = Count > 0 ? ValueF[0] : 0.0f;
- ret.start.Y = Count > 1 ? ValueF[1] : 0.0f;
- ret.start.Z = Count > 2 ? ValueF[2] : 0.0f;
- ret.end.X = Count > 3 ? ValueF[3] : 0.0f;
- ret.end.Y = Count > 4 ? ValueF[4] : 0.0f;
- ret.end.Z = Count > 5 ? ValueF[5] : 0.0f;
- }
- else
- {
- ret.start.X = Count > 0 ? (f32)ValueI[0] : 0.0f;
- ret.start.Y = Count > 1 ? (f32)ValueI[1] : 0.0f;
- ret.start.Z = Count > 2 ? (f32)ValueI[2] : 0.0f;
- ret.end.X = Count > 3 ? (f32)ValueI[3] : 0.0f;
- ret.end.Y = Count > 4 ? (f32)ValueI[4] : 0.0f;
- ret.end.Z = Count > 5 ? (f32)ValueI[5] : 0.0f;
- }
- return ret;
- }
- //! get float array
- virtual core::array<f32> getFloatArray()
- {
- if (!IsFloat)
- {
- ValueF.clear();
- for (u32 i=0; i<Count; ++i)
- ValueF.push_back( (f32) ValueI[i] );
- }
- return ValueF;
- }
- //! get int array
- virtual core::array<s32> getIntArray()
- {
- if (IsFloat)
- {
- ValueI.clear();
- for (u32 i=0; i<Count; ++i)
- ValueI.push_back( (s32) ValueF[i] );
- }
- return ValueI;
- }
- // setting values
- virtual void setInt(s32 intValue)
- {
- // set all values
- for (u32 i=0; i < Count; ++i)
- if (IsFloat)
- ValueF[i] = (f32)intValue;
- else
- ValueI[i] = intValue;
- }
- virtual void setFloat(f32 floatValue)
- {
- // set all values
- for (u32 i=0; i < Count; ++i)
- if (IsFloat)
- ValueF[i] = floatValue;
- else
- ValueI[i] = (s32)floatValue;
- }
- virtual void setBool(bool boolValue)
- {
- setInt( boolValue ? 1 : 0);
- }
- virtual void setString(const char* text)
- {
- // parse text
- const char* P = (const char*)text;
- reset();
- u32 i=0;
- for ( i=0; i<Count && *P; ++i )
- {
- while(*P && P[0]!='-' && ( P[0]==' ' || (P[0] < '0' || P[0] > '9') ) )
- ++P;
- // set value
- if ( *P)
- {
- if (IsFloat)
- {
- f32 c = 0;
- P = core::fast_atof_move(P, c);
- ValueF[i] = c;
- }
- else
- {
- // todo: fix this to read ints properly
- f32 c = 0;
- P = core::fast_atof_move(P, c);
- ValueI[i] = (s32)c;
- }
- }
- }
- // todo: warning message
- //if (i < Count-1)
- //{
- //
- //}
- }
- virtual void setPosition(core::position2di v)
- {
- reset();
- if (IsFloat)
- {
- if (Count > 0) ValueF[0] = (f32)v.X;
- if (Count > 1) ValueF[1] = (f32)v.Y;
- }
- else
- {
- if (Count > 0) ValueI[0] = v.X;
- if (Count > 1) ValueI[1] = v.Y;
- }
- }
- virtual void setVector(core::vector3df v)
- {
- reset();
- if (IsFloat)
- {
- if (Count > 0) ValueF[0] = v.X;
- if (Count > 1) ValueF[1] = v.Y;
- if (Count > 2) ValueF[2] = v.Z;
- }
- else
- {
- if (Count > 0) ValueI[0] = (s32)v.X;
- if (Count > 1) ValueI[1] = (s32)v.Y;
- if (Count > 2) ValueI[2] = (s32)v.Z;
- }
- }
- virtual void setColor(video::SColorf color)
- {
- reset();
- if (IsFloat)
- {
- if (Count > 0) ValueF[0] = color.r;
- if (Count > 1) ValueF[1] = color.g;
- if (Count > 2) ValueF[2] = color.b;
- if (Count > 3) ValueF[3] = color.a;
- }
- else
- {
- if (Count > 0) ValueI[0] = (s32)(color.r * 255);
- if (Count > 1) ValueI[1] = (s32)(color.g * 255);
- if (Count > 2) ValueI[2] = (s32)(color.b * 255);
- if (Count > 3) ValueI[3] = (s32)(color.a * 255);
- }
- }
- virtual void setColor(video::SColor color)
- {
- reset();
- if (IsFloat)
- {
- if (Count > 0) ValueF[0] = (f32)color.getRed() / 255.0f;
- if (Count > 1) ValueF[1] = (f32)color.getGreen() / 255.0f;
- if (Count > 2) ValueF[2] = (f32)color.getBlue() / 255.0f;
- if (Count > 3) ValueF[3] = (f32)color.getAlpha() / 255.0f;
- }
- else
- {
- if (Count > 0) ValueI[0] = color.getRed();
- if (Count > 1) ValueI[1] = color.getGreen();
- if (Count > 2) ValueI[2] = color.getBlue();
- if (Count > 3) ValueI[3] = color.getAlpha();
- }
- }
- virtual void setRect(core::rect<s32> value)
- {
- reset();
- if (IsFloat)
- {
- if (Count > 0) ValueF[0] = (f32)value.UpperLeftCorner.X;
- if (Count > 1) ValueF[1] = (f32)value.UpperLeftCorner.Y;
- if (Count > 2) ValueF[2] = (f32)value.LowerRightCorner.X;
- if (Count > 3) ValueF[3] = (f32)value.LowerRightCorner.Y;
- }
- else
- {
- if (Count > 0) ValueI[0] = value.UpperLeftCorner.X;
- if (Count > 1) ValueI[1] = value.UpperLeftCorner.Y;
- if (Count > 2) ValueI[2] = value.LowerRightCorner.X;
- if (Count > 3) ValueI[3] = value.LowerRightCorner.Y;
- }
- }
- virtual void setMatrix(core::matrix4 value)
- {
- reset();
- if (IsFloat)
- {
- for (u32 r=0; r<4; ++r)
- for (u32 c=0; c<4; ++c)
- if (Count > c+r*4)
- ValueF[c+r*4] = value(r,c);
- }
- else
- {
- for (u32 r=0; r<4; ++r)
- for (u32 c=0; c<4; ++c)
- if (Count > c+r*4)
- ValueI[c+r*4] = (s32)value(r,c);
- }
- }
- virtual void setQuaternion(core::quaternion value)
- {
- reset();
- if (IsFloat)
- {
- if (Count > 0) ValueF[0] = value.X;
- if (Count > 1) ValueF[1] = value.Y;
- if (Count > 2) ValueF[2] = value.Z;
- if (Count > 3) ValueF[3] = value.W;
- }
- else
- {
- if (Count > 0) ValueI[0] = (s32)value.X;
- if (Count > 1) ValueI[1] = (s32)value.Y;
- if (Count > 2) ValueI[2] = (s32)value.Z;
- if (Count > 3) ValueI[3] = (s32)value.W;
- }
- }
- virtual void setBoundingBox(core::aabbox3d<f32> value)
- {
- reset();
- if (IsFloat)
- {
- if (Count > 0) ValueF[0] = value.MinEdge.X;
- if (Count > 1) ValueF[1] = value.MinEdge.Y;
- if (Count > 2) ValueF[2] = value.MinEdge.Z;
- if (Count > 3) ValueF[3] = value.MaxEdge.X;
- if (Count > 4) ValueF[4] = value.MaxEdge.Y;
- if (Count > 5) ValueF[5] = value.MaxEdge.Z;
- }
- else
- {
- if (Count > 0) ValueI[0] = (s32)value.MinEdge.X;
- if (Count > 1) ValueI[1] = (s32)value.MinEdge.Y;
- if (Count > 2) ValueI[2] = (s32)value.MinEdge.Z;
- if (Count > 3) ValueI[3] = (s32)value.MaxEdge.X;
- if (Count > 4) ValueI[4] = (s32)value.MaxEdge.Y;
- if (Count > 5) ValueI[5] = (s32)value.MaxEdge.Z;
- }
- }
- virtual void setPlane(core::plane3df value)
- {
- reset();
- if (IsFloat)
- {
- if (Count > 0) ValueF[0] = value.Normal.X;
- if (Count > 1) ValueF[1] = value.Normal.Y;
- if (Count > 2) ValueF[2] = value.Normal.Z;
- if (Count > 3) ValueF[3] = value.D;
- }
- else
- {
- if (Count > 0) ValueI[0] = (s32)value.Normal.X;
- if (Count > 1) ValueI[1] = (s32)value.Normal.Y;
- if (Count > 2) ValueI[2] = (s32)value.Normal.Z;
- if (Count > 3) ValueI[3] = (s32)value.D;
- }
- }
- virtual void setTriangle3d(core::triangle3df value)
- {
- reset();
- if (IsFloat)
- {
- if (Count > 0) ValueF[0] = value.pointA.X;
- if (Count > 1) ValueF[1] = value.pointA.Y;
- if (Count > 2) ValueF[2] = value.pointA.Z;
- if (Count > 3) ValueF[3] = value.pointB.X;
- if (Count > 4) ValueF[4] = value.pointB.Y;
- if (Count > 5) ValueF[5] = value.pointB.Z;
- if (Count > 6) ValueF[6] = value.pointC.X;
- if (Count > 7) ValueF[7] = value.pointC.Y;
- if (Count > 8) ValueF[8] = value.pointC.Z;
- }
- else
- {
- if (Count > 0) ValueI[0] = (s32)value.pointA.X;
- if (Count > 1) ValueI[1] = (s32)value.pointA.Y;
- if (Count > 2) ValueI[2] = (s32)value.pointA.Z;
- if (Count > 3) ValueI[3] = (s32)value.pointB.X;
- if (Count > 4) ValueI[4] = (s32)value.pointB.Y;
- if (Count > 5) ValueI[5] = (s32)value.pointB.Z;
- if (Count > 6) ValueI[6] = (s32)value.pointC.X;
- if (Count > 7) ValueI[7] = (s32)value.pointC.Y;
- if (Count > 8) ValueI[8] = (s32)value.pointC.Z;
- }
- }
- virtual void setVector2d(core::vector2df v)
- {
- reset();
- if (IsFloat)
- {
- if (Count > 0) ValueF[0] = v.X;
- if (Count > 1) ValueF[1] = v.Y;
- }
- else
- {
- if (Count > 0) ValueI[0] = (s32)v.X;
- if (Count > 1) ValueI[1] = (s32)v.Y;
- }
- }
- virtual void setVector2d(core::vector2di v)
- {
- reset();
- if (IsFloat)
- {
- if (Count > 0) ValueF[0] = (f32)v.X;
- if (Count > 1) ValueF[1] = (f32)v.Y;
- }
- else
- {
- if (Count > 0) ValueI[0] = v.X;
- if (Count > 1) ValueI[1] = v.Y;
- }
- }
- virtual void setLine2d(core::line2di v)
- {
- reset();
- if (IsFloat)
- {
- if (Count > 0) ValueF[0] = (f32)v.start.X;
- if (Count > 1) ValueF[1] = (f32)v.start.Y;
- if (Count > 2) ValueF[2] = (f32)v.end.X;
- if (Count > 3) ValueF[3] = (f32)v.end.Y;
- }
- else
- {
- if (Count > 0) ValueI[0] = v.start.X;
- if (Count > 1) ValueI[1] = v.start.Y;
- if (Count > 2) ValueI[2] = v.end.X;
- if (Count > 3) ValueI[3] = v.end.Y;
- }
- }
- virtual void setLine2d(core::line2df v)
- {
- reset();
- if (IsFloat)
- {
- if (Count > 0) ValueF[0] = v.start.X;
- if (Count > 1) ValueF[1] = v.start.Y;
- if (Count > 2) ValueF[2] = v.end.X;
- if (Count > 3) ValueF[3] = v.end.Y;
- }
- else
- {
- if (Count > 0) ValueI[0] = (s32)v.start.X;
- if (Count > 1) ValueI[1] = (s32)v.start.Y;
- if (Count > 2) ValueI[2] = (s32)v.end.X;
- if (Count > 3) ValueI[3] = (s32)v.end.Y;
- }
- }
- virtual void setDimension2d(core::dimension2du v)
- {
- reset();
- if (IsFloat)
- {
- if (Count > 0) ValueF[0] = (f32)v.Width;
- if (Count > 1) ValueF[1] = (f32)v.Height;
- }
- else
- {
- if (Count > 0) ValueI[0] = (s32)v.Width;
- if (Count > 1) ValueI[1] = (s32)v.Height;
- }
- }
- //! set float array
- virtual void setFloatArray(core::array<f32> &vals)
- {
- reset();
- for (u32 i=0; i<vals.size() && i<Count; ++i)
- {
- if (IsFloat)
- ValueF[i] = vals[i];
- else
- ValueI[i] = (s32)vals[i];
- }
- }
- //! set int array
- virtual void setIntArray(core::array<s32> &vals)
- {
- reset();
- for (u32 i=0; i<vals.size() && i<Count; ++i)
- {
- if (IsFloat)
- ValueF[i] = (f32)vals[i];
- else
- ValueI[i] = vals[i];
- }
- }
- //! is it a number list?
- virtual bool isNumberList()
- {
- return true;
- }
- //! is it a float list?
- virtual bool isFloat()
- {
- return IsFloat;
- }
- virtual E_ATTRIBUTE_TYPE getType() const
- {
- if (IsFloat)
- return EAT_FLOATARRAY;
- else
- return EAT_INTARRAY;
- }
- virtual const wchar_t* getTypeString() const
- {
- if (IsFloat)
- return L"floatlist";
- else
- return L"intlist";
- }
- protected:
- //! clear all values
- void reset()
- {
- if (IsFloat)
- for (u32 i=0; i < Count ; ++i)
- ValueF[i] = 0.0f;
- else
- for (u32 i=0; i < Count ; ++i)
- ValueI[i] = 0;
- }
- core::array<s32> ValueI;
- core::array<f32> ValueF;
- u32 Count;
- bool IsFloat;
- };
- // Attribute implemented for floating point colors
- class CColorfAttribute : public CNumbersAttribute
- {
- public:
- CColorfAttribute(const char* name, video::SColorf value) : CNumbersAttribute(name, value) {}
- virtual s32 getInt()
- {
- return getColor().color;
- }
- virtual f32 getFloat()
- {
- return (f32)getColor().color;
- }
- virtual void setInt(s32 intValue)
- {
- video::SColorf c = video::SColor(intValue);
- ValueF[0] = c.r;
- ValueF[1] = c.g;
- ValueF[2] = c.b;
- ValueF[3] = c.a;
- }
- virtual void setFloat(f32 floatValue)
- {
- setInt((s32)floatValue);
- }
- virtual E_ATTRIBUTE_TYPE getType() const
- {
- return EAT_COLORF;
- }
- virtual const wchar_t* getTypeString() const
- {
- return L"colorf";
- }
- };
- // Attribute implemented for colors
- class CColorAttribute : public CNumbersAttribute
- {
- public:
- CColorAttribute(const char* name, const video::SColorf& value) : CNumbersAttribute(name, value) {}
- CColorAttribute(const char* name, const video::SColor& value) : CNumbersAttribute(name, value) {}
- virtual s32 getInt()
- {
- return getColor().color;
- }
- virtual f32 getFloat()
- {
- return (f32)getColor().color;
- }
- virtual void setInt(s32 intValue)
- {
- video::SColorf c = video::SColor(intValue);
- ValueF[0] = c.r;
- ValueF[1] = c.g;
- ValueF[2] = c.b;
- ValueF[3] = c.a;
- }
- virtual void setFloat(f32 floatValue)
- {
- setInt((s32)floatValue);
- }
- virtual core::stringw getStringW()
- {
- char tmp[10];
- const video::SColor c = getColor();
- sprintf(tmp, "%02x%02x%02x%02x", c.getAlpha(), c.getRed(), c.getGreen(), c.getBlue());
- return core::stringw(tmp);
- }
- virtual void setString(const char* text)
- {
- u32 c;
- if (sscanf(text, "%08x", &c)!=1)
- {
- CNumbersAttribute::setString(text);
- }
- else
- setColor(c);
- }
- virtual E_ATTRIBUTE_TYPE getType() const
- {
- return EAT_COLOR;
- }
- virtual const wchar_t* getTypeString() const
- {
- return L"color";
- }
- };
- // Attribute implemented for 3d vectors
- class CVector3DAttribute : public CNumbersAttribute
- {
- public:
- CVector3DAttribute(const char* name, core::vector3df value) : CNumbersAttribute(name, value) {}
- virtual E_ATTRIBUTE_TYPE getType() const
- {
- return EAT_VECTOR3D;
- }
- virtual core::matrix4 getMatrix()
- {
- core::matrix4 ret;
- ret.makeIdentity();
- ret.setTranslation( core::vector3df(ValueF[0],ValueF[1],ValueF[2]) );
- return ret;
- }
- virtual const wchar_t* getTypeString() const
- {
- return L"vector3d";
- }
- };
- // Attribute implemented for 2d vectors
- class CVector2DAttribute : public CNumbersAttribute
- {
- public:
- CVector2DAttribute(const char* name, core::vector2df value) : CNumbersAttribute(name, value) {}
- virtual E_ATTRIBUTE_TYPE getType() const
- {
- return EAT_VECTOR2D;
- }
- virtual const wchar_t* getTypeString() const
- {
- return L"vector2d";
- }
- };
- // Attribute implemented for 2d vectors
- class CPosition2DAttribute : public CNumbersAttribute
- {
- public:
- CPosition2DAttribute(const char* name, core::position2di value) : CNumbersAttribute(name, value) {}
- virtual E_ATTRIBUTE_TYPE getType() const
- {
- return EAT_POSITION2D;
- }
- virtual const wchar_t* getTypeString() const
- {
- return L"position";
- }
- };
- // Attribute implemented for rectangles
- class CRectAttribute : public CNumbersAttribute
- {
- public:
- CRectAttribute(const char* name, core::rect<s32> value) : CNumbersAttribute(name, value) { }
- virtual E_ATTRIBUTE_TYPE getType() const
- {
- return EAT_RECT;
- }
- virtual const wchar_t* getTypeString() const
- {
- return L"rect";
- }
- };
- // Attribute implemented for dimension
- class CDimension2dAttribute : public CNumbersAttribute
- {
- public:
- CDimension2dAttribute (const char* name, core::dimension2d<u32> value) : CNumbersAttribute(name, value) { }
- virtual E_ATTRIBUTE_TYPE getType() const
- {
- return EAT_DIMENSION2D;
- }
- virtual const wchar_t* getTypeString() const
- {
- return L"dimension2d";
- }
- };
- // Attribute implemented for matrices
- class CMatrixAttribute : public CNumbersAttribute
- {
- public:
- CMatrixAttribute(const char* name, core::matrix4 value) : CNumbersAttribute(name, value) { }
- virtual E_ATTRIBUTE_TYPE getType() const
- {
- return EAT_MATRIX;
- }
- virtual core::quaternion getQuaternion()
- {
- return core::quaternion(getMatrix());
- }
- virtual const wchar_t* getTypeString() const
- {
- return L"matrix";
- }
- };
- // Attribute implemented for quaternions
- class CQuaternionAttribute : public CNumbersAttribute
- {
- public:
- CQuaternionAttribute(const char* name, core::quaternion value) : CNumbersAttribute(name, value) { }
- virtual E_ATTRIBUTE_TYPE getType() const
- {
- return EAT_QUATERNION;
- }
- virtual core::matrix4 getMatrix()
- {
- return getQuaternion().getMatrix();
- }
- virtual const wchar_t* getTypeString() const
- {
- return L"quaternion";
- }
- };
- // Attribute implemented for bounding boxes
- class CBBoxAttribute : public CNumbersAttribute
- {
- public:
- CBBoxAttribute(const char* name, core::aabbox3df value) : CNumbersAttribute(name, value) { }
- virtual E_ATTRIBUTE_TYPE getType() const
- {
- return EAT_BBOX;
- }
- virtual const wchar_t* getTypeString() const
- {
- return L"box3d";
- }
- };
- // Attribute implemented for planes
- class CPlaneAttribute : public CNumbersAttribute
- {
- public:
- CPlaneAttribute(const char* name, core::plane3df value) : CNumbersAttribute(name, value) { }
- virtual E_ATTRIBUTE_TYPE getType() const
- {
- return EAT_PLANE;
- }
- virtual const wchar_t* getTypeString() const
- {
- return L"plane";
- }
- };
- // Attribute implemented for triangles
- class CTriangleAttribute : public CNumbersAttribute
- {
- public:
- CTriangleAttribute(const char* name, core::triangle3df value) : CNumbersAttribute(name, value) { }
- virtual E_ATTRIBUTE_TYPE getType() const
- {
- return EAT_TRIANGLE3D;
- }
- virtual core::plane3df getPlane()
- {
- return getTriangle().getPlane();
- }
- virtual const wchar_t* getTypeString() const
- {
- return L"triangle";
- }
- };
- // Attribute implemented for 2d lines
- class CLine2dAttribute : public CNumbersAttribute
- {
- public:
- CLine2dAttribute(const char* name, core::line2df value) : CNumbersAttribute(name, value) { }
- virtual E_ATTRIBUTE_TYPE getType() const
- {
- return EAT_LINE2D;
- }
- virtual const wchar_t* getTypeString() const
- {
- return L"line2d";
- }
- };
- // Attribute implemented for 3d lines
- class CLine3dAttribute : public CNumbersAttribute
- {
- public:
- CLine3dAttribute(const char* name, core::line3df value) : CNumbersAttribute(name, value) { }
- virtual E_ATTRIBUTE_TYPE getType() const
- {
- return EAT_LINE3D;
- }
- virtual const wchar_t* getTypeString() const
- {
- return L"line3d";
- }
- };
- // vector2df
- // dimension2du
- /*
- Special attributes
- */
- // Attribute implemented for enumeration literals
- class CEnumAttribute : public IAttribute
- {
- public:
- CEnumAttribute(const char* name, const char* value, const char* const* literals)
- {
- Name = name;
- setEnum(value, literals);
- }
- virtual void setEnum(const char* enumValue, const char* const* enumerationLiterals)
- {
- int literalCount = 0;
- if (enumerationLiterals)
- {
- s32 i;
- for (i=0; enumerationLiterals[i]; ++i)
- ++literalCount;
- EnumLiterals.reallocate(literalCount);
- for (i=0; enumerationLiterals[i]; ++i)
- EnumLiterals.push_back(enumerationLiterals[i]);
- }
- setString(enumValue);
- }
- virtual s32 getInt()
- {
- for (s32 i=0; EnumLiterals.size(); ++i)
- if (Value.equals_ignore_case(EnumLiterals[i]))
- {
- return i;
- }
- return -1;
- }
- virtual f32 getFloat()
- {
- return (f32)getInt();
- }
- virtual bool getBool()
- {
- return (getInt() != 0); // does not make a lot of sense, I know
- }
- virtual core::stringc getString()
- {
- return Value;
- }
- virtual core::stringw getStringW()
- {
- return core::stringw(Value.c_str());
- }
- virtual void setInt(s32 intValue)
- {
- if (intValue>=0 && intValue<(s32)EnumLiterals.size())
- Value = EnumLiterals[intValue];
- else
- Value = "";
- }
- virtual void setFloat(f32 floatValue)
- {
- setInt((s32)floatValue);
- };
- virtual void setString(const char* text)
- {
- Value = text;
- }
- virtual const char* getEnum()
- {
- return Value.c_str();
- }
- virtual E_ATTRIBUTE_TYPE getType() const
- {
- return EAT_ENUM;
- }
- virtual const wchar_t* getTypeString() const
- {
- return L"enum";
- }
- core::stringc Value;
- core::array<core::stringc> EnumLiterals;
- };
- // Attribute implemented for strings
- class CStringAttribute : public IAttribute
- {
- public:
- CStringAttribute(const char* name, const char* value)
- {
- IsStringW=false;
- Name = name;
- setString(value);
- }
- CStringAttribute(const char* name, const wchar_t* value)
- {
- IsStringW = true;
- Name = name;
- setString(value);
- }
- CStringAttribute(const char* name, void* binaryData, s32 lenghtInBytes)
- {
- IsStringW=false;
- Name = name;
- setBinary(binaryData, lenghtInBytes);
- }
- virtual s32 getInt()
- {
- if (IsStringW)
- return atoi(core::stringc(ValueW.c_str()).c_str());
- else
- return atoi(Value.c_str());
- }
- virtual f32 getFloat()
- {
- if (IsStringW)
- return core::fast_atof(core::stringc(ValueW.c_str()).c_str());
- else
- return core::fast_atof(Value.c_str());
- }
- virtual bool getBool()
- {
- if (IsStringW)
- return ValueW.equals_ignore_case(L"true");
- else
- return Value.equals_ignore_case("true");
- }
- virtual core::stringc getString()
- {
- if (IsStringW)
- return core::stringc(ValueW.c_str());
- else
- return Value;
- }
- virtual core::stringw getStringW()
- {
- if (IsStringW)
- return ValueW;
- else
- return core::stringw(Value.c_str());
- }
- virtual void setInt(s32 intValue)
- {
- if (IsStringW)
- ValueW = core::stringw(intValue);
- else
- Value = core::stringc(intValue);
- }
- virtual void setFloat(f32 floatValue)
- {
- if (IsStringW)
- {
- ValueW = core::stringw((double)floatValue);
- }
- else
- {
- Value = core::stringc((double)floatValue);
- }
- };
- virtual void setString(const char* text)
- {
- if (IsStringW)
- ValueW = core::stringw(text);
- else
- Value = text;
- }
- virtual void setString(const wchar_t* text)
- {
- if (IsStringW)
- ValueW = text;
- else
- Value = core::stringc(text);
- }
- virtual E_ATTRIBUTE_TYPE getType() const
- {
- return EAT_STRING;
- }
- virtual const wchar_t* getTypeString() const
- {
- return L"string";
- }
- virtual void getBinary(void* outdata, s32 maxLength)
- {
- s32 dataSize = maxLength;
- c8* datac8 = (c8*)(outdata);
- s32 p = 0;
- const c8* dataString = Value.c_str();
- for (s32 i=0; i<dataSize; ++i)
- datac8[i] = 0;
- while(dataString[p] && p<dataSize)
- {
- s32 v = getByteFromHex((c8)dataString[p*2]) * 16;
- if (dataString[(p*2)+1])
- v += getByteFromHex((c8)dataString[(p*2)+1]);
- datac8[p] = v;
- ++p;
- }
- };
- virtual void setBinary(void* data, s32 maxLength)
- {
- s32 dataSize = maxLength;
- c8* datac8 = (c8*)(data);
- char tmp[3];
- tmp[2] = 0;
- Value = "";
- for (s32 b=0; b<dataSize; ++b)
- {
- getHexStrFromByte(datac8[b], tmp);
- Value.append(tmp);
- }
- };
- bool IsStringW;
- core::stringc Value;
- core::stringw ValueW;
- protected:
- static inline s32 getByteFromHex(c8 h)
- {
- if (h >= '0' && h <='9')
- return h-'0';
- if (h >= 'a' && h <='f')
- return h-'a' + 10;
- return 0;
- }
- static inline void getHexStrFromByte(c8 byte, c8* out)
- {
- s32 b = (byte & 0xf0) >> 4;
- for (s32 i=0; i<2; ++i)
- {
- if (b >=0 && b <= 9)
- out[i] = b+'0';
- if (b >=10 && b <= 15)
- out[i] = (b-10)+'a';
- b = byte & 0x0f;
- }
- }
- };
- // Attribute implemented for binary data
- class CBinaryAttribute : public CStringAttribute
- {
- public:
- CBinaryAttribute(const char* name, void* binaryData, s32 lenghtInBytes)
- : CStringAttribute(name, binaryData, lenghtInBytes)
- {
- }
- virtual E_ATTRIBUTE_TYPE getType() const
- {
- return EAT_BINARY;
- }
- virtual const wchar_t* getTypeString() const
- {
- return L"binary";
- }
- };
- // Attribute implemented for texture references
- class CTextureAttribute : public IAttribute
- {
- // Explicitly hide base method
- using IAttribute::setTexture;
- public:
- CTextureAttribute(const char* name, video::ITexture* value, video::IVideoDriver* driver, const io::path& filename)
- : Value(0), Driver(driver), OverrideName(filename)
- {
- if (Driver)
- Driver->grab();
- Name = name;
- setTexture(value);
- }
- ~CTextureAttribute()
- {
- if (Driver)
- Driver->drop();
- if (Value)
- Value->drop();
- }
- virtual video::ITexture* getTexture()
- {
- return Value;
- }
- virtual bool getBool()
- {
- return (Value != 0);
- }
- virtual core::stringw getStringW()
- {
- return core::stringw(OverrideName.size()?OverrideName:
- Value ? Value->getName().getPath().c_str() : 0);
- }
- virtual core::stringc getString()
- {
- // since texture names can be stringw we are careful with the types
- return core::stringc(OverrideName.size()?OverrideName:
- Value ? Value->getName().getPath().c_str() : 0);
- }
- virtual void setString(const char* text)
- {
- if (Driver)
- {
- if (text && *text)
- {
- setTexture(Driver->getTexture(text));
- OverrideName=text;
- }
- else
- setTexture(0);
- }
- }
- virtual void setTexture(video::ITexture* value)
- {
- if ( value == Value )
- return;
- if (Value)
- Value->drop();
- Value = value;
- if (Value)
- Value->grab();
- }
- virtual E_ATTRIBUTE_TYPE getType() const
- {
- return EAT_TEXTURE;
- }
- virtual const wchar_t* getTypeString() const
- {
- return L"texture";
- }
- video::ITexture* Value;
- video::IVideoDriver* Driver;
- io::path OverrideName;
- };
- // Attribute implemented for array of stringw
- class CStringWArrayAttribute : public IAttribute
- {
- public:
- CStringWArrayAttribute(const char* name, const core::array<core::stringw>& value)
- {
- Name = name;
- setArray(value);
- }
- virtual core::array<core::stringw> getArray()
- {
- return Value;
- }
- virtual void setArray(const core::array<core::stringw>& value)
- {
- Value = value;
- }
- virtual E_ATTRIBUTE_TYPE getType() const
- {
- return EAT_STRINGWARRAY;
- }
- virtual const wchar_t* getTypeString() const
- {
- return L"stringwarray";
- }
- core::array<core::stringw> Value;
- };
- // Attribute implemented for user pointers
- class CUserPointerAttribute : public IAttribute
- {
- public:
- CUserPointerAttribute(const char* name, void* value)
- {
- Name = name;
- Value = value;
- }
- virtual s32 getInt()
- {
- return *static_cast<s32*>(Value);
- }
- virtual bool getBool()
- {
- return (Value != 0);
- }
- virtual core::stringw getStringW()
- {
- wchar_t buf[32];
- swprintf(buf, 32, L"%p", Value);
- return core::stringw(buf);
- }
- virtual void setString(const char* text)
- {
- u32 tmp;
- sscanf(text, "0x%x", &tmp);
- Value = reinterpret_cast<void *>(tmp);
- }
- virtual E_ATTRIBUTE_TYPE getType() const
- {
- return EAT_USER_POINTER;
- }
- virtual void setUserPointer(void* v)
- {
- Value = v;
- }
- virtual void* getUserPointer()
- {
- return Value;
- }
- virtual const wchar_t* getTypeString() const
- {
- return L"userPointer";
- }
- void* Value;
- };
- // todo: CGUIFontAttribute
- } // end namespace io
- } // end namespace irr
|