babylon.canvas2d.d.ts 220 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569
  1. declare module BABYLON {
  2. class PropertyChangedInfo {
  3. /**
  4. * Previous value of the property
  5. */
  6. oldValue: any;
  7. /**
  8. * New value of the property
  9. */
  10. newValue: any;
  11. /**
  12. * Name of the property that changed its value
  13. */
  14. propertyName: string;
  15. }
  16. /**
  17. * Custom type of the propertyChanged observable
  18. */
  19. /**
  20. * Property Changed interface
  21. */
  22. interface IPropertyChanged {
  23. /**
  24. * PropertyChanged observable
  25. */
  26. propertyChanged: Observable<PropertyChangedInfo>;
  27. }
  28. /**
  29. * The purpose of this class is to provide a base implementation of the IPropertyChanged interface for the user to avoid rewriting a code needlessly.
  30. * Typical use of this class is to check for equality in a property set(), then call the onPropertyChanged method if values are different after the new value is set. The protected method will notify observers of the change.
  31. * Remark: onPropertyChanged detects reentrant code and acts in a way to make sure everything is fine, fast and allocation friendly (when there no reentrant code which should be 99% of the time)
  32. */
  33. abstract class PropertyChangedBase implements IPropertyChanged {
  34. /**
  35. * Protected method to call when there's a change of value in a property set
  36. * @param propName the name of the concerned property
  37. * @param oldValue its old value
  38. * @param newValue its new value
  39. * @param mask an optional observable mask
  40. */
  41. protected onPropertyChanged<T>(propName: string, oldValue: T, newValue: T, mask?: number): void;
  42. /**
  43. * An observable that is triggered when a property (using of the XXXXLevelProperty decorator) has its value changing.
  44. * You can add an observer that will be triggered only for a given set of Properties using the Mask feature of the Observable and the corresponding Prim2DPropInfo.flagid value (e.g. Prim2DBase.positionProperty.flagid|Prim2DBase.rotationProperty.flagid to be notified only about position or rotation change)
  45. */
  46. readonly propertyChanged: Observable<PropertyChangedInfo>;
  47. _propertyChanged: Observable<PropertyChangedInfo>;
  48. private static pci;
  49. private static calling;
  50. }
  51. }
  52. declare module BABYLON {
  53. /**
  54. * Class for the ObservableArray.onArrayChanged observable
  55. */
  56. class ArrayChanged<T> {
  57. constructor();
  58. /**
  59. * Contain the action that were made on the ObservableArray, it's one of the ArrayChanged.xxxAction members.
  60. * Note the action's value can be used in the "mask" field of the Observable to only be notified about given action(s)
  61. */
  62. action: number;
  63. /**
  64. * Only valid if the action is newItemsAction
  65. */
  66. newItems: {
  67. index: number;
  68. value: T;
  69. }[];
  70. /**
  71. * Only valid if the action is removedItemsAction
  72. */
  73. removedItems: {
  74. index: number;
  75. value: T;
  76. }[];
  77. /**
  78. * Only valid if the action is changedItemAction
  79. */
  80. changedItems: {
  81. index: number;
  82. value: T;
  83. }[];
  84. /**
  85. * Get the index of the first item inserted
  86. */
  87. newStartingIndex: number;
  88. /**
  89. * Get the index of the first item removed
  90. */
  91. removedStartingIndex: number;
  92. /**
  93. * Get the index of the first changed item
  94. */
  95. changedStartingIndex: number;
  96. /**
  97. * The content of the array was totally cleared
  98. */
  99. static readonly clearAction: number;
  100. /**
  101. * A new item was added, the newItems field contains the key/value pairs
  102. */
  103. static readonly newItemsAction: number;
  104. /**
  105. * An existing item was removed, the removedKey field contains its key
  106. */
  107. static readonly removedItemsAction: number;
  108. /**
  109. * One or many items in the array were changed, the
  110. */
  111. static readonly changedItemAction: number;
  112. /**
  113. * The array's content was totally changed
  114. * Depending on the method that used this mode the ChangedArray object may contains more information
  115. */
  116. static readonly replacedArrayAction: number;
  117. /**
  118. * The length of the array changed
  119. */
  120. static readonly lengthChangedAction: number;
  121. private static _clearAction;
  122. private static _newItemsAction;
  123. private static _removedItemsAction;
  124. private static _replacedArrayAction;
  125. private static _lengthChangedAction;
  126. private static _changedItemAction;
  127. clear(): void;
  128. }
  129. class OAWatchedObjectChangedInfo<T> {
  130. object: T;
  131. propertyChanged: PropertyChangedInfo;
  132. }
  133. /**
  134. * This class mimics the Javascript Array and TypeScript Array<T> classes, adding new features concerning the Observable pattern.
  135. *
  136. */
  137. class ObservableArray<T> extends PropertyChangedBase {
  138. /**
  139. * Create an Observable Array.
  140. * @param watchObjectsPropertyChange
  141. * @param array and optional array that will be encapsulated by this ObservableArray instance. That's right, it's NOT a copy!
  142. */
  143. constructor(watchObjectsPropertyChange: boolean, array?: Array<T>);
  144. /**
  145. * Gets or sets the length of the array. This is a number one higher than the highest element defined in an array.
  146. */
  147. length: number;
  148. getAt(index: number): T;
  149. setAt(index: number, value: T): boolean;
  150. /**
  151. * Returns a string representation of an array.
  152. */
  153. toString(): string;
  154. toLocaleString(): string;
  155. /**
  156. * Appends new elements to an array, and returns the new length of the array.
  157. * @param items New elements of the Array.
  158. */
  159. push(...items: T[]): number;
  160. /**
  161. * Removes the last element from an array and returns it.
  162. */
  163. pop(): T;
  164. /**
  165. * Combines two or more arrays.
  166. * @param items Additional items to add to the end of array1.
  167. */
  168. concat(...items: T[]): ObservableArray<T>;
  169. /**
  170. * Adds all the elements of an array separated by the specified separator string.
  171. * @param separator A string used to separate one element of an array from the next in the resulting String. If omitted, the array elements are separated with a comma.
  172. */
  173. join(separator?: string): string;
  174. /**
  175. * Reverses the elements in an Array.
  176. * The arrayChanged action is
  177. */
  178. reverse(): T[];
  179. /**
  180. * Removes the first element from an array and returns it, shift all subsequents element one element before.
  181. * The ArrayChange action is replacedArrayAction, the whole array changes and must be reevaluate as such, the removed element is in removedItems.
  182. *
  183. */
  184. shift(): T;
  185. /**
  186. * Returns a section of an array.
  187. * @param start The beginning of the specified portion of the array.
  188. * @param end The end of the specified portion of the array.
  189. */
  190. slice(start?: number, end?: number): ObservableArray<T>;
  191. /**
  192. * Sorts an array.
  193. * @param compareFn The name of the function used to determine the order of the elements. If omitted, the elements are sorted in ascending, ASCII character order.
  194. * On the contrary of the Javascript Array's implementation, this method returns nothing
  195. */
  196. sort(compareFn?: (a: T, b: T) => number): void;
  197. /**
  198. * Removes elements from an array and, if necessary, inserts new elements in their place, returning the deleted elements.
  199. * @param start The zero-based location in the array from which to start removing elements.
  200. * @param deleteCount The number of elements to remove.
  201. * @param items Elements to insert into the array in place of the deleted elements.
  202. */
  203. splice(start: number, deleteCount: number, ...items: T[]): T[];
  204. /**
  205. * Inserts new elements at the start of an array.
  206. * @param items Elements to insert at the start of the Array.
  207. * The ChangedArray action is replacedArrayAction, newItems contains the list of the added items
  208. */
  209. unshift(...items: T[]): number;
  210. /**
  211. * Returns the index of the first occurrence of a value in an array.
  212. * @param searchElement The value to locate in the array.
  213. * @param fromIndex The array index at which to begin the search. If fromIndex is omitted, the search starts at index 0.
  214. */
  215. indexOf(searchElement: T, fromIndex?: number): number;
  216. /**
  217. * Returns the index of the last occurrence of a specified value in an array.
  218. * @param searchElement The value to locate in the array.
  219. * @param fromIndex The array index at which to begin the search. If fromIndex is omitted, the search starts at the last index in the array.
  220. */
  221. lastIndexOf(searchElement: T, fromIndex?: number): number;
  222. /**
  223. * Determines whether all the members of an array satisfy the specified test.
  224. * @param callbackfn A function that accepts up to three arguments. The every method calls the callbackfn function for each element in array1 until the callbackfn returns false, or until the end of the array.
  225. * @param thisArg An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value.
  226. */
  227. every(callbackfn: (value: T, index: number, array: T[]) => boolean, thisArg?: any): boolean;
  228. /**
  229. * Determines whether the specified callback function returns true for any element of an array.
  230. * @param callbackfn A function that accepts up to three arguments. The some method calls the callbackfn function for each element in array1 until the callbackfn returns true, or until the end of the array.
  231. * @param thisArg An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value.
  232. */
  233. some(callbackfn: (value: T, index: number, array: T[]) => boolean, thisArg?: any): boolean;
  234. /**
  235. * Performs the specified action for each element in an array.
  236. * @param callbackfn A function that accepts up to three arguments. forEach calls the callbackfn function one time for each element in the array.
  237. * @param thisArg An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value.
  238. */
  239. forEach(callbackfn: (value: T, index: number, array: T[]) => void, thisArg?: any): void;
  240. /**
  241. * Calls a defined callback function on each element of an array, and returns an array that contains the results.
  242. * @param callbackfn A function that accepts up to three arguments. The map method calls the callbackfn function one time for each element in the array.
  243. * @param thisArg An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value.
  244. */
  245. map<U>(callbackfn: (value: T, index: number, array: T[]) => U, thisArg?: any): U[];
  246. /**
  247. * Returns the elements of an array that meet the condition specified in a callback function.
  248. * @param callbackfn A function that accepts up to three arguments. The filter method calls the callbackfn function one time for each element in the array.
  249. * @param thisArg An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value.
  250. */
  251. filter(callbackfn: (value: T, index: number, array: T[]) => boolean, thisArg?: any): T[];
  252. /**
  253. * Calls the specified callback function for all the elements in an array. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function.
  254. * @param callbackfn A function that accepts up to four arguments. The reduce method calls the callbackfn function one time for each element in the array.
  255. * @param initialValue If initialValue is specified, it is used as the initial value to start the accumulation. The first call to the callbackfn function provides this value as an argument instead of an array value.
  256. */
  257. reduce(callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: T[]) => T, initialValue?: T): T;
  258. /**
  259. * Calls the specified callback function for all the elements in an array, in descending order. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function.
  260. * @param callbackfn A function that accepts up to four arguments. The reduceRight method calls the callbackfn function one time for each element in the array.
  261. * @param initialValue If initialValue is specified, it is used as the initial value to start the accumulation. The first call to the callbackfn function provides this value as an argument instead of an array value.
  262. */
  263. reduceRight(callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: T[]) => T, initialValue?: T): T;
  264. readonly arrayChanged: Observable<ArrayChanged<T>>;
  265. protected getArrayChangedObject(): ArrayChanged<T>;
  266. protected feedNotifArray(array: {
  267. index: number;
  268. value: T;
  269. }[], startindIndex: number, ...items: T[]): void;
  270. protected callArrayChanged(ac: ArrayChanged<T>): void;
  271. readonly watchedObjectChanged: Observable<OAWatchedObjectChangedInfo<T>>;
  272. private _addWatchedElement(...items);
  273. private _removeWatchedElement(...items);
  274. protected onWatchedObjectChanged(key: string, object: T, propChanged: PropertyChangedInfo): void;
  275. private _array;
  276. private _arrayChanged;
  277. private dci;
  278. private _callingArrayChanged;
  279. private _watchedObjectChanged;
  280. private _woci;
  281. private _callingWatchedObjectChanged;
  282. private _watchObjectsPropertyChange;
  283. private _watchedObjectList;
  284. }
  285. }
  286. declare module BABYLON {
  287. /**
  288. * Class for the ObservableStringDictionary.onDictionaryChanged observable
  289. */
  290. class DictionaryChanged<T> {
  291. /**
  292. * Contain the action that were made on the dictionary, it's one of the DictionaryChanged.xxxAction members.
  293. * Note the action's value can be used in the "mask" field of the Observable to only be notified about given action(s)
  294. */
  295. action: number;
  296. /**
  297. * Only valid if the action is newItemAction
  298. */
  299. newItem: {
  300. key: string;
  301. value: T;
  302. };
  303. /**
  304. * Only valid if the action is removedItemAction
  305. */
  306. removedKey: string;
  307. /**
  308. * Only valid if the action is itemValueChangedAction
  309. */
  310. changedItem: {
  311. key: string;
  312. oldValue: T;
  313. newValue: T;
  314. };
  315. /**
  316. * The content of the dictionary was totally cleared
  317. */
  318. static readonly clearAction: number;
  319. /**
  320. * A new item was added, the newItem field contains the key/value pair
  321. */
  322. static readonly newItemAction: number;
  323. /**
  324. * An existing item was removed, the removedKey field contains its key
  325. */
  326. static readonly removedItemAction: number;
  327. /**
  328. * An existing item had a value change, the changedItem field contains the key/value
  329. */
  330. static readonly itemValueChangedAction: number;
  331. /**
  332. * The dictionary's content was reset and replaced by the content of another dictionary.
  333. * DictionaryChanged<T> contains no further information about this action
  334. */
  335. static readonly replacedAction: number;
  336. private static _clearAction;
  337. private static _newItemAction;
  338. private static _removedItemAction;
  339. private static _itemValueChangedAction;
  340. private static _replacedAction;
  341. }
  342. class OSDWatchedObjectChangedInfo<T> {
  343. key: string;
  344. object: T;
  345. propertyChanged: PropertyChangedInfo;
  346. }
  347. class ObservableStringDictionary<T> extends StringDictionary<T> implements IPropertyChanged {
  348. constructor(watchObjectsPropertyChange: boolean);
  349. /**
  350. * This will clear this dictionary and copy the content from the 'source' one.
  351. * If the T value is a custom object, it won't be copied/cloned, the same object will be used
  352. * @param source the dictionary to take the content from and copy to this dictionary
  353. */
  354. copyFrom(source: StringDictionary<T>): void;
  355. /**
  356. * Get a value from its key or add it if it doesn't exist.
  357. * This method will ensure you that a given key/data will be present in the dictionary.
  358. * @param key the given key to get the matching value from
  359. * @param factory the factory that will create the value if the key is not present in the dictionary.
  360. * The factory will only be invoked if there's no data for the given key.
  361. * @return the value corresponding to the key.
  362. */
  363. getOrAddWithFactory(key: string, factory: (key: string) => T): T;
  364. /**
  365. * Add a new key and its corresponding value
  366. * @param key the key to add
  367. * @param value the value corresponding to the key
  368. * @return true if the operation completed successfully, false if we couldn't insert the key/value because there was already this key in the dictionary
  369. */
  370. add(key: string, value: T): boolean;
  371. getAndRemove(key: string): T;
  372. private _add(key, value, fireNotif, registerWatcher);
  373. private _addWatchedElement(key, el);
  374. private _removeWatchedElement(key, el);
  375. set(key: string, value: T): boolean;
  376. /**
  377. * Remove a key/value from the dictionary.
  378. * @param key the key to remove
  379. * @return true if the item was successfully deleted, false if no item with such key exist in the dictionary
  380. */
  381. remove(key: string): boolean;
  382. private _remove(key, fireNotif, element?);
  383. /**
  384. * Clear the whole content of the dictionary
  385. */
  386. clear(): void;
  387. readonly propertyChanged: Observable<PropertyChangedInfo>;
  388. protected onPropertyChanged<T>(propName: string, oldValue: T, newValue: T, mask?: number): void;
  389. readonly dictionaryChanged: Observable<DictionaryChanged<T>>;
  390. protected onDictionaryChanged(action: number, newItem: {
  391. key: string;
  392. value: T;
  393. }, removedKey: string, changedItem: {
  394. key: string;
  395. oldValue: T;
  396. newValue: T;
  397. }): void;
  398. readonly watchedObjectChanged: Observable<OSDWatchedObjectChangedInfo<T>>;
  399. protected onWatchedObjectChanged(key: string, object: T, propChanged: PropertyChangedInfo): void;
  400. private _propertyChanged;
  401. private static pci;
  402. private static callingPropChanged;
  403. private _dictionaryChanged;
  404. private dci;
  405. private _callingDicChanged;
  406. private _watchedObjectChanged;
  407. private _woci;
  408. private _callingWatchedObjectChanged;
  409. private _watchObjectsPropertyChange;
  410. private _watchedObjectList;
  411. }
  412. }
  413. declare module BABYLON {
  414. /**
  415. * This class given information about a given character.
  416. */
  417. class CharInfo {
  418. /**
  419. * The normalized ([0;1]) top/left position of the character in the texture
  420. */
  421. topLeftUV: Vector2;
  422. /**
  423. * The normalized ([0;1]) right/bottom position of the character in the texture
  424. */
  425. bottomRightUV: Vector2;
  426. charWidth: number;
  427. }
  428. /**
  429. * This is an abstract base class to hold a Texture that will contain a FontMap
  430. */
  431. abstract class BaseFontTexture extends Texture {
  432. constructor(url: string, scene: Scene, noMipmap?: boolean, invertY?: boolean, samplingMode?: number);
  433. /**
  434. * Is the Font is using Super Sampling (each font texel is doubled).
  435. */
  436. readonly isSuperSampled: boolean;
  437. /**
  438. * Is the Font was rendered using the Signed Distance Field algorithm
  439. * @returns {}
  440. */
  441. readonly isSignedDistanceField: boolean;
  442. /**
  443. * Get the Width (in pixel) of the Space character
  444. */
  445. readonly spaceWidth: number;
  446. /**
  447. * Get the Line height (in pixel)
  448. */
  449. readonly lineHeight: number;
  450. /**
  451. * When the FontTexture is retrieved through the FontCache, there's a reference counter that is incremented for each use.
  452. * You also have the possibility to extend the lifetime of the FontTexture when passing it to another object by calling this method
  453. * Don't forget to call the corresponding decCachedFontTextureCounter method when you no longer have use of the FontTexture.
  454. * Each call to incCachedFontTextureCounter must have a corresponding call to decCachedFontTextureCounter.
  455. */
  456. abstract incCachedFontTextureCounter(): any;
  457. /**
  458. * Decrement the reference counter, if it reaches 0 the FontTexture is disposed
  459. */
  460. abstract decCachedFontTextureCounter(): any;
  461. /**
  462. * Is the font dynamically updated, if true is returned then you have to call the update() before using the font in rendering if new character were adding using getChar()
  463. */
  464. readonly abstract isDynamicFontTexture: boolean;
  465. /**
  466. * Will fetch the new characters retrieved with getChar() to the texture.
  467. * If there were no new char, this call is harmless and quit in no time.
  468. * If there were new chars a texture lock/update is made, which is a costy operation.
  469. */
  470. abstract update(): void;
  471. /**
  472. * Measure the width/height that will take a given text
  473. * @param text the text to measure
  474. * @param tabulationSize the size (in space character) of the tabulation character, default value must be 4
  475. */
  476. measureText(text: string, tabulationSize?: number): Size;
  477. /**
  478. * Retrieve the CharInfo object for a given character
  479. * @param char the character to retrieve the CharInfo object from (e.g.: "A", "a", etc.)
  480. */
  481. abstract getChar(char: string): CharInfo;
  482. protected _charInfos: StringDictionary<CharInfo>;
  483. protected _lineHeight: number;
  484. protected _spaceWidth: any;
  485. protected _superSample: boolean;
  486. protected _signedDistanceField: boolean;
  487. protected _cachedFontId: string;
  488. }
  489. class BitmapFontInfo {
  490. kerningDic: StringDictionary<number>;
  491. charDic: StringDictionary<CharInfo>;
  492. textureSize: Size;
  493. atlasName: string;
  494. padding: Vector4;
  495. lineHeight: number;
  496. textureUrl: string;
  497. textureFile: string;
  498. }
  499. interface IBitmapFontLoader {
  500. loadFont(fontDataContent: any, scene: Scene, invertY: boolean): {
  501. bfi: BitmapFontInfo;
  502. errorMsg: string;
  503. errorCode: number;
  504. };
  505. }
  506. class BitmapFontTexture extends BaseFontTexture {
  507. constructor(scene: Scene, bmFontUrl: string, textureUrl?: string, noMipmap?: boolean, invertY?: boolean, samplingMode?: number, onLoad?: () => void, onError?: (msg: string, code: number) => void);
  508. static GetCachedFontTexture(scene: Scene, fontTexture: BitmapFontTexture): BitmapFontTexture;
  509. static ReleaseCachedFontTexture(scene: Scene, fontTexture: BitmapFontTexture): void;
  510. /**
  511. * Is the font dynamically updated, if true is returned then you have to call the update() before using the font in rendering if new character were adding using getChar()
  512. */
  513. readonly isDynamicFontTexture: boolean;
  514. /**
  515. * This method does nothing for a BitmapFontTexture object as it's a static texture
  516. */
  517. update(): void;
  518. /**
  519. * Retrieve the CharInfo object for a given character
  520. * @param char the character to retrieve the CharInfo object from (e.g.: "A", "a", etc.)
  521. */
  522. getChar(char: string): CharInfo;
  523. /**
  524. * For FontTexture retrieved using GetCachedFontTexture, use this method when you transfer this object's lifetime to another party in order to share this resource.
  525. * When the other party is done with this object, decCachedFontTextureCounter must be called.
  526. */
  527. incCachedFontTextureCounter(): void;
  528. /**
  529. * Use this method only in conjunction with incCachedFontTextureCounter, call it when you no longer need to use this shared resource.
  530. */
  531. decCachedFontTextureCounter(): void;
  532. private _usedCounter;
  533. static addLoader(fileExtension: string, plugin: IBitmapFontLoader): void;
  534. static plugins: StringDictionary<IBitmapFontLoader[]>;
  535. }
  536. /**
  537. * This class is a special kind of texture which generates on the fly characters of a given css style "fontName".
  538. * The generated texture will be updated when new characters will be retrieved using the getChar() method, but you have
  539. * to call the update() method for the texture to fetch these changes, you can harmlessly call update any time you want, if no
  540. * change were made, nothing will happen.
  541. * The Font Texture can be rendered in three modes: normal size, super sampled size (x2) or using Signed Distance Field rendering.
  542. * Signed Distance Field should be prefered because the texture can be rendered using AlphaTest instead of Transparency, which is way more faster. More about SDF here (http://www.valvesoftware.com/publications/2007/SIGGRAPH2007_AlphaTestedMagnification.pdf).
  543. * The only flaw of SDF is that the rendering quality may not be the best or the edges too sharp is the font thickness is too thin.
  544. */
  545. class FontTexture extends BaseFontTexture {
  546. private _canvas;
  547. private _context;
  548. private _lineHeightSuper;
  549. private _xMargin;
  550. private _yMargin;
  551. private _offset;
  552. private _currentFreePosition;
  553. private _curCharCount;
  554. private _lastUpdateCharCount;
  555. private _spaceWidthSuper;
  556. private _sdfCanvas;
  557. private _sdfContext;
  558. private _sdfScale;
  559. private _usedCounter;
  560. readonly isDynamicFontTexture: boolean;
  561. static GetCachedFontTexture(scene: Scene, fontName: string, supersample?: boolean, signedDistanceField?: boolean): FontTexture;
  562. static ReleaseCachedFontTexture(scene: Scene, fontName: string, supersample?: boolean, signedDistanceField?: boolean): void;
  563. /**
  564. * Create a new instance of the FontTexture class
  565. * @param name the name of the texture
  566. * @param font the font to use, use the W3C CSS notation
  567. * @param scene the scene that owns the texture
  568. * @param maxCharCount the approximative maximum count of characters that could fit in the texture. This is an approximation because most of the fonts are proportional (each char has its own Width). The 'W' character's width is used to compute the size of the texture based on the given maxCharCount
  569. * @param samplingMode the texture sampling mode
  570. * @param superSample if true the FontTexture will be created with a font of a size twice bigger than the given one but all properties (lineHeight, charWidth, etc.) will be according to the original size. This is made to improve the text quality.
  571. */
  572. constructor(name: string, font: string, scene: Scene, maxCharCount?: number, samplingMode?: number, superSample?: boolean, signedDistanceField?: boolean);
  573. /**
  574. * Make sure the given char is present in the font map.
  575. * @param char the character to get or add
  576. * @return the CharInfo instance corresponding to the given character
  577. */
  578. getChar(char: string): CharInfo;
  579. private _computeSDFChar(source);
  580. private getSuperSampleFont(font);
  581. private getFontHeight(font);
  582. readonly canRescale: boolean;
  583. getContext(): CanvasRenderingContext2D;
  584. /**
  585. * Call this method when you've call getChar() at least one time, this will update the texture if needed.
  586. * Don't be afraid to call it, if no new character was added, this method simply does nothing.
  587. */
  588. update(): void;
  589. clone(): FontTexture;
  590. /**
  591. * For FontTexture retrieved using GetCachedFontTexture, use this method when you transfer this object's lifetime to another party in order to share this resource.
  592. * When the other party is done with this object, decCachedFontTextureCounter must be called.
  593. */
  594. incCachedFontTextureCounter(): void;
  595. /**
  596. * Use this method only in conjunction with incCachedFontTextureCounter, call it when you no longer need to use this shared resource.
  597. */
  598. decCachedFontTextureCounter(): void;
  599. }
  600. function BitmapFontLoaderPlugin(fileExtension: string, plugin: IBitmapFontLoader): (target: Object) => void;
  601. }
  602. declare module BABYLON {
  603. /**
  604. * Stores 2D Bounding Information.
  605. * This class handles a circle area and a bounding rectangle one.
  606. */
  607. class BoundingInfo2D {
  608. /**
  609. * The coordinate of the center of the bounding info
  610. */
  611. center: Vector2;
  612. /**
  613. * The radius of the bounding circle, from the center of the bounded object
  614. */
  615. radius: number;
  616. /**
  617. * The extent of the bounding rectangle, from the center of the bounded object.
  618. * This is an absolute value in both X and Y of the vector which describe the right/top corner of the rectangle, you can easily reconstruct the whole rectangle by negating X &| Y.
  619. */
  620. extent: Vector2;
  621. constructor();
  622. /**
  623. * Create a BoundingInfo2D object from a given size
  624. * @param size the size that will be used to set the extend, radius will be computed from it.
  625. */
  626. static CreateFromSize(size: Size): BoundingInfo2D;
  627. /**
  628. * Create a BoundingInfo2D object from a given radius
  629. * @param radius the radius to use, the extent will be computed from it.
  630. */
  631. static CreateFromRadius(radius: number): BoundingInfo2D;
  632. /**
  633. * Create a BoundingInfo2D object from a list of points.
  634. * The resulted object will be the smallest bounding area that includes all the given points.
  635. * @param points an array of points to compute the bounding object from.
  636. */
  637. static CreateFromPoints(points: Vector2[]): BoundingInfo2D;
  638. /**
  639. * Update a BoundingInfo2D object using the given Size as input
  640. * @param size the bounding data will be computed from this size.
  641. * @param b must be a valid/allocated object, it will contain the result of the operation
  642. */
  643. static CreateFromSizeToRef(size: Size, b: BoundingInfo2D): void;
  644. /**
  645. * Update a BoundingInfo2D object using the given radius as input
  646. * @param radius the bounding data will be computed from this radius
  647. * @param b must be a valid/allocated object, it will contain the result of the operation
  648. */
  649. static CreateFromRadiusToRef(radius: number, b: BoundingInfo2D): void;
  650. /**
  651. * Update a BoundingInfo2D object using the given points array as input
  652. * @param points the point array to use to update the bounding data
  653. * @param b must be a valid/allocated object, it will contain the result of the operation
  654. */
  655. static CreateFromPointsToRef(points: Vector2[], b: BoundingInfo2D): void;
  656. /**
  657. * Update a BoundingInfo2D object using the given min/max values as input
  658. * @param xmin the smallest x coordinate
  659. * @param xmax the biggest x coordinate
  660. * @param ymin the smallest y coordinate
  661. * @param ymax the buggest y coordinate
  662. * @param b must be a valid/allocated object, it will contain the result of the operation
  663. */
  664. static CreateFromMinMaxToRef(xmin: number, xmax: number, ymin: number, ymax: number, b: BoundingInfo2D): void;
  665. /**
  666. * Duplicate this instance and return a new one
  667. * @return the duplicated instance
  668. */
  669. clone(): BoundingInfo2D;
  670. clear(): void;
  671. copyFrom(src: BoundingInfo2D): void;
  672. /**
  673. * return the max extend of the bounding info
  674. */
  675. max(): Vector2;
  676. /**
  677. * return the min/max extend of the bounding info.
  678. * x, y, z, w are left, bottom, right and top
  679. */
  680. minMax(): Vector4;
  681. /**
  682. * Update a vector2 with the max extend of the bounding info
  683. * @param result must be a valid/allocated vector2 that will contain the result of the operation
  684. */
  685. maxToRef(result: Vector2): void;
  686. /**
  687. * Update a vector4 with the min/max extend of the bounding info
  688. * x, y, z, w are left, bottom, right and top
  689. * @param result must be a valid/allocated vector4 that will contain the result of the operation
  690. */
  691. minMaxToRef(result: Vector4): void;
  692. /**
  693. * Return the size of the boundingInfo rect surface
  694. */
  695. size(): Size;
  696. /**
  697. * Stores in the result object the size of the boundingInfo rect surface
  698. * @param result
  699. */
  700. sizeToRef(result: Size): void;
  701. /**
  702. * Inflate the boundingInfo with the given vector
  703. * @param offset the extent will be incremented with offset and the radius will be computed again
  704. */
  705. inflate(offset: Vector2): void;
  706. /**
  707. * Apply a transformation matrix to this BoundingInfo2D and return a new instance containing the result
  708. * @param matrix the transformation matrix to apply
  709. * @return the new instance containing the result of the transformation applied on this BoundingInfo2D
  710. */
  711. transform(matrix: Matrix): BoundingInfo2D;
  712. /**
  713. * Compute the union of this BoundingInfo2D with a given one, returns a new BoundingInfo2D as a result
  714. * @param other the second BoundingInfo2D to compute the union with this one
  715. * @return a new instance containing the result of the union
  716. */
  717. union(other: BoundingInfo2D): BoundingInfo2D;
  718. private static _transform;
  719. /**
  720. * Transform this BoundingInfo2D with a given matrix and store the result in an existing BoundingInfo2D instance.
  721. * This is a GC friendly version, try to use it as much as possible, specially if your transformation is inside a loop, allocate the result object once for good outside of the loop and use it every time.
  722. * @param matrix The matrix to use to compute the transformation
  723. * @param result A VALID (i.e. allocated) BoundingInfo2D object where the result will be stored
  724. */
  725. transformToRef(matrix: Matrix, result: BoundingInfo2D): void;
  726. /**
  727. * Compute the union of this BoundingInfo2D with another one and store the result in a third valid BoundingInfo2D object
  728. * This is a GC friendly version, try to use it as much as possible, specially if your transformation is inside a loop, allocate the result object once for good outside of the loop and use it every time.
  729. * @param other the second object used to compute the union
  730. * @param result a VALID BoundingInfo2D instance (i.e. allocated) where the result will be stored
  731. */
  732. unionToRef(other: BoundingInfo2D, result: BoundingInfo2D): void;
  733. /**
  734. * Check if the given point is inside the BoundingInfo.
  735. * The test is first made on the radius, then inside the rectangle described by the extent
  736. * @param pickPosition the position to test
  737. * @return true if the point is inside, false otherwise
  738. */
  739. doesIntersect(pickPosition: Vector2): boolean;
  740. }
  741. }
  742. declare module BABYLON {
  743. class LayoutEngineBase implements ILockable {
  744. constructor();
  745. updateLayout(prim: Prim2DBase): void;
  746. readonly isChildPositionAllowed: boolean;
  747. isLocked(): boolean;
  748. lock(): boolean;
  749. layoutDirtyOnPropertyChangedMask: any;
  750. private _isLocked;
  751. }
  752. class CanvasLayoutEngine extends LayoutEngineBase {
  753. static Singleton: CanvasLayoutEngine;
  754. updateLayout(prim: Prim2DBase): void;
  755. private _doUpdate(prim);
  756. readonly isChildPositionAllowed: boolean;
  757. }
  758. class StackPanelLayoutEngine extends LayoutEngineBase {
  759. constructor();
  760. static readonly Horizontal: StackPanelLayoutEngine;
  761. static readonly Vertical: StackPanelLayoutEngine;
  762. private static _horizontal;
  763. private static _vertical;
  764. isHorizontal: boolean;
  765. private _isHorizontal;
  766. private static dstOffset;
  767. private static dstArea;
  768. updateLayout(prim: Prim2DBase): void;
  769. readonly isChildPositionAllowed: boolean;
  770. }
  771. }
  772. declare module BABYLON {
  773. /**
  774. * This interface is used to implement a lockable instance pattern.
  775. * Classes that implements it may be locked at any time, making their content immutable from now on.
  776. * You also can query if a given instance is locked or not.
  777. * This allow instances to be shared among several 'consumers'.
  778. */
  779. interface ILockable {
  780. /**
  781. * Query the lock state
  782. * @returns returns true if the object is locked and immutable, false if it's not
  783. */
  784. isLocked(): boolean;
  785. /**
  786. * A call to this method will definitely lock the instance, making its content immutable
  787. * @returns the previous lock state of the object. so if true is returned the object were already locked and this method does nothing, if false is returned it means the object wasn't locked and this call locked it for good.
  788. */
  789. lock(): boolean;
  790. }
  791. /**
  792. * This interface defines the IBrush2D contract.
  793. * Classes implementing a new type of Brush2D must implement this interface
  794. */
  795. interface IBrush2D extends ILockable {
  796. /**
  797. * Define if the brush will use transparency / alpha blending
  798. * @returns true if the brush use transparency
  799. */
  800. isTransparent(): boolean;
  801. /**
  802. * It is critical for each instance of a given Brush2D type to return a unique string that identifies it because the Border instance will certainly be part of the computed ModelKey for a given Primitive
  803. * @returns A string identifier that uniquely identify the instance
  804. */
  805. toString(): string;
  806. }
  807. /**
  808. * Base class implementing the ILocable interface.
  809. * The particularity of this class is to call the protected onLock() method when the instance is about to be locked for good.
  810. */
  811. class LockableBase implements ILockable {
  812. isLocked(): boolean;
  813. private _isLocked;
  814. lock(): boolean;
  815. /**
  816. * Protected handler that will be called when the instance is about to be locked.
  817. */
  818. protected onLock(): void;
  819. }
  820. class SolidColorBrush2D extends LockableBase implements IBrush2D {
  821. constructor(color: Color4, lock?: boolean);
  822. /**
  823. * Return true if the brush is transparent, false if it's totally opaque
  824. */
  825. isTransparent(): boolean;
  826. /**
  827. * The color used by this instance to render
  828. * @returns the color object. Note that it's not a clone of the actual object stored in the instance so you MUST NOT modify it, otherwise unexpected behavior might occurs.
  829. */
  830. color: Color4;
  831. /**
  832. * Return a unique identifier of the instance, which is simply the hexadecimal representation (CSS Style) of the solid color.
  833. */
  834. toString(): string;
  835. private _color;
  836. }
  837. class GradientColorBrush2D extends LockableBase implements IBrush2D {
  838. constructor(color1: Color4, color2: Color4, translation?: Vector2, rotation?: number, scale?: number, lock?: boolean);
  839. /**
  840. * Return true if the brush is transparent, false if it's totally opaque
  841. */
  842. isTransparent(): boolean;
  843. /**
  844. * First color, the blend will start from this color
  845. */
  846. color1: Color4;
  847. /**
  848. * Second color, the blend will end to this color
  849. */
  850. color2: Color4;
  851. /**
  852. * Translation vector to apply on the blend
  853. * Default is [0;0]
  854. */
  855. translation: Vector2;
  856. /**
  857. * Rotation in radian to apply to the brush
  858. * Default direction of the brush is vertical, you can change this using this property.
  859. * Default is 0.
  860. */
  861. rotation: number;
  862. /**
  863. * Scale factor to apply to the gradient.
  864. * Default is 1: no scale.
  865. */
  866. scale: number;
  867. /**
  868. * Return a string describing the brush
  869. */
  870. toString(): string;
  871. /**
  872. * Build a unique key string for the given parameters
  873. */
  874. static BuildKey(color1: Color4, color2: Color4, translation: Vector2, rotation: number, scale: number): string;
  875. private _color1;
  876. private _color2;
  877. private _translation;
  878. private _rotation;
  879. private _scale;
  880. }
  881. }
  882. declare module BABYLON {
  883. class Prim2DClassInfo {
  884. }
  885. class Prim2DPropInfo {
  886. static PROPKIND_MODEL: number;
  887. static PROPKIND_INSTANCE: number;
  888. static PROPKIND_DYNAMIC: number;
  889. id: number;
  890. flagId: number;
  891. kind: number;
  892. name: string;
  893. dirtyBoundingInfo: boolean;
  894. dirtyParentBoundingInfo: boolean;
  895. typeLevelCompare: boolean;
  896. bindingMode: number;
  897. bindingUpdateSourceTrigger: number;
  898. }
  899. class ClassTreeInfo<TClass, TProp> {
  900. constructor(baseClass: ClassTreeInfo<TClass, TProp>, type: Object, classContentFactory: (base: TClass) => TClass);
  901. readonly classContent: TClass;
  902. readonly type: Object;
  903. readonly levelContent: StringDictionary<TProp>;
  904. readonly fullContent: StringDictionary<TProp>;
  905. getLevelOf(type: Object): ClassTreeInfo<TClass, TProp>;
  906. getOrAddType(baseType: Object, type: Object): ClassTreeInfo<TClass, TProp>;
  907. static get<TClass, TProp>(type: Object): ClassTreeInfo<TClass, TProp>;
  908. static getOrRegister<TClass, TProp>(type: Object, classContentFactory: (base: TClass) => TClass): ClassTreeInfo<TClass, TProp>;
  909. private _type;
  910. private _classContent;
  911. private _baseClass;
  912. private _subClasses;
  913. private _levelContent;
  914. private _fullContent;
  915. private _classContentFactory;
  916. }
  917. class DataBinding {
  918. /**
  919. * Use the mode specified in the SmartProperty declaration
  920. */
  921. static MODE_DEFAULT: number;
  922. /**
  923. * Update the binding target only once when the Smart Property's value is first accessed
  924. */
  925. static MODE_ONETIME: number;
  926. /**
  927. * Update the smart property when the source changes.
  928. * The source won't be updated if the smart property value is set.
  929. */
  930. static MODE_ONEWAY: number;
  931. /**
  932. * Only update the source when the target's data is changing.
  933. */
  934. static MODE_ONEWAYTOSOURCE: number;
  935. /**
  936. * Update the bind target when the source changes and update the source when the Smart Property value is set.
  937. */
  938. static MODE_TWOWAY: number;
  939. /**
  940. * Use the Update Source Trigger defined in the SmartProperty declaration
  941. */
  942. static UPDATESOURCETRIGGER_DEFAULT: number;
  943. /**
  944. * Update the source as soon as the Smart Property has a value change
  945. */
  946. static UPDATESOURCETRIGGER_PROPERTYCHANGED: number;
  947. /**
  948. * Update the source when the binding target loses focus
  949. */
  950. static UPDATESOURCETRIGGER_LOSTFOCUS: number;
  951. /**
  952. * Update the source will be made by explicitly calling the UpdateFromDataSource method
  953. */
  954. static UPDATESOURCETRIGGER_EXPLICIT: number;
  955. constructor();
  956. /**
  957. * Provide a callback that will convert the value obtained by the Data Binding to the type of the SmartProperty it's bound to.
  958. * If no value are set, then it's assumed that the sourceValue is of the same type as the SmartProperty's one.
  959. * If the SmartProperty type is a basic data type (string, boolean or number) and no converter is specified but the sourceValue is of a different type, the conversion will be implicitly made, if possible.
  960. * @param sourceValue the source object retrieve by the Data Binding mechanism
  961. * @returns the object of a compatible type with the SmartProperty it's bound to
  962. */
  963. converter: (sourceValue: any) => any;
  964. /**
  965. * Set the mode to use for the data flow in the binding. Set one of the MODE_xxx static member of this class. If not specified then MODE_DEFAULT will be used
  966. */
  967. mode: number;
  968. /**
  969. * You can override the Data Source object with this member which is the Id of a uiElement existing in the UI Logical tree.
  970. * If not set and source no set too, then the dataSource property will be used.
  971. */
  972. uiElementId: string;
  973. /**
  974. * You can override the Data Source object with this member which is the source object to use directly.
  975. * If not set and uiElement no set too, then the dataSource property of the SmartPropertyBase object will be used.
  976. */
  977. dataSource: IPropertyChanged;
  978. /**
  979. * The path & name of the property to get from the source object.
  980. * Once the Source object is evaluated (it's either the one got from uiElementId, source or dataSource) you can specify which property of this object is the value to bind to the smartProperty.
  981. * If nothing is set then the source object will be used.
  982. * You can specify an indirect property using the format "firstProperty.indirectProperty" like "address.postalCode" if the source is a Customer object which contains an address property and the Address class contains a postalCode property.
  983. * If the property is an Array and you want to address a particular element then use the 'arrayProperty[index]' notation. For example "phoneNumbers[0]" to get the first element of the phoneNumber property which is an array.
  984. */
  985. propertyPathName: string;
  986. /**
  987. * If the Smart Property is of the string type, you can use the string interpolation notation to provide how the sourceValue will be formatted, reference to the source value must be made via the token: ${value}. For instance `Customer Name: ${value}`
  988. */
  989. stringFormat: (value: any) => string;
  990. /**
  991. * Specify how the source should be updated, use one of the UPDATESOURCETRIGGER_xxx member of this class, if not specified then UPDATESOURCETRIGGER_DEFAULT will be used.
  992. */
  993. updateSourceTrigger: number;
  994. canUpdateTarget(resetUpdateCounter: boolean): boolean;
  995. updateTarget(): void;
  996. _storeBoundValue(watcher: SmartPropertyBase, value: any): void;
  997. private _getActualDataSource();
  998. _registerDataSource(updateTarget: boolean): void;
  999. _unregisterDataSource(): void;
  1000. /**
  1001. * The PropInfo of the property the binding is bound to
  1002. */
  1003. _boundTo: Prim2DPropInfo;
  1004. _owner: SmartPropertyBase;
  1005. private _converter;
  1006. private _mode;
  1007. private _uiElementId;
  1008. private _dataSource;
  1009. _currentDataSource: IPropertyChanged;
  1010. private _propertyPathName;
  1011. private _stringFormat;
  1012. private _updateSourceTrigger;
  1013. private _updateCounter;
  1014. }
  1015. abstract class SmartPropertyBase extends PropertyChangedBase {
  1016. constructor();
  1017. readonly disposeObservable: Observable<SmartPropertyBase>;
  1018. /**
  1019. * Check if the object is disposed or not.
  1020. * @returns true if the object is dispose, false otherwise.
  1021. */
  1022. readonly isDisposed: boolean;
  1023. /**
  1024. * Disposable pattern, this method must be overloaded by derived types in order to clean up hardware related resources.
  1025. * @returns false if the object is already dispose, true otherwise. Your implementation must call super.dispose() and check for a false return and return immediately if it's the case.
  1026. */
  1027. dispose(): boolean;
  1028. /**
  1029. * Check if a given set of properties are dirty or not.
  1030. * @param flags a ORed combination of Prim2DPropInfo.flagId values
  1031. * @return true if at least one property is dirty, false if none of them are.
  1032. */
  1033. checkPropertiesDirty(flags: number): boolean;
  1034. /**
  1035. * Clear a given set of properties.
  1036. * @param flags a ORed combination of Prim2DPropInfo.flagId values
  1037. * @return the new set of property still marked as dirty
  1038. */
  1039. protected clearPropertiesDirty(flags: number): number;
  1040. _resetPropertiesDirty(): void;
  1041. /**
  1042. * Add an externally attached data from its key.
  1043. * This method call will fail and return false, if such key already exists.
  1044. * If you don't care and just want to get the data no matter what, use the more convenient getOrAddExternalDataWithFactory() method.
  1045. * @param key the unique key that identifies the data
  1046. * @param data the data object to associate to the key for this Engine instance
  1047. * @return true if no such key were already present and the data was added successfully, false otherwise
  1048. */
  1049. addExternalData<T>(key: string, data: T): boolean;
  1050. /**
  1051. * Get an externally attached data from its key
  1052. * @param key the unique key that identifies the data
  1053. * @return the associated data, if present (can be null), or undefined if not present
  1054. */
  1055. getExternalData<T>(key: string): T;
  1056. /**
  1057. * Get an externally attached data from its key, create it using a factory if it's not already present
  1058. * @param key the unique key that identifies the data
  1059. * @param factory the factory that will be called to create the instance if and only if it doesn't exists
  1060. * @return the associated data, can be null if the factory returned null.
  1061. */
  1062. getOrAddExternalDataWithFactory<T>(key: string, factory: (k: string) => T): T;
  1063. /**
  1064. * Remove an externally attached data from the Engine instance
  1065. * @param key the unique key that identifies the data
  1066. * @return true if the data was successfully removed, false if it doesn't exist
  1067. */
  1068. removeExternalData(key: any): boolean;
  1069. static _hookProperty<T>(propId: number, piStore: (pi: Prim2DPropInfo) => void, kind: number, settings?: {
  1070. bindingMode?: number;
  1071. bindingUpdateSourceTrigger?: number;
  1072. typeLevelCompare?: boolean;
  1073. dirtyBoundingInfo?: boolean;
  1074. dirtyParentBoundingBox?: boolean;
  1075. }): (target: Object, propName: string | symbol, descriptor: TypedPropertyDescriptor<T>) => void;
  1076. private static _createPropInfo(target, propName, propId, kind, settings);
  1077. /**
  1078. * Access the dictionary of properties metadata. Only properties decorated with XXXXLevelProperty are concerned
  1079. * @returns the dictionary, the key is the property name as declared in Javascript, the value is the metadata object
  1080. */
  1081. protected readonly propDic: StringDictionary<Prim2DPropInfo>;
  1082. private static _checkUnchanged(curValue, newValue);
  1083. private static propChangedInfo;
  1084. private static propChangeGuarding;
  1085. protected _handlePropChanged<T>(curValue: T, newValue: T, propName: string, propInfo: Prim2DPropInfo, typeLevelCompare: boolean): void;
  1086. protected _triggerPropertyChanged(propInfo: Prim2DPropInfo, newValue: any): void;
  1087. /**
  1088. * Set the object from which Smart Properties using Binding will take/update their data from/to.
  1089. * When the object is part of a graph (with parent/children relationship) if the dataSource of a given instance is not specified, then the parent's one is used.
  1090. */
  1091. dataSource: IPropertyChanged;
  1092. protected _getDataSource(): IPropertyChanged;
  1093. createSimpleDataBinding(propInfo: Prim2DPropInfo, propertyPathName: string, mode?: number): DataBinding;
  1094. createDataBinding(propInfo: Prim2DPropInfo, binding: DataBinding): DataBinding;
  1095. removeDataBinding(propInfo: Prim2DPropInfo): boolean;
  1096. updateFromDataSource(): void;
  1097. private _dataSource;
  1098. private _dataSourceObserver;
  1099. private _isDisposed;
  1100. private _externalData;
  1101. protected _instanceDirtyFlags: number;
  1102. private _propInfo;
  1103. _bindings: Array<DataBinding>;
  1104. private _hasBinding;
  1105. private _bindingSourceChanged;
  1106. private _disposeObservable;
  1107. }
  1108. abstract class SmartPropertyPrim extends SmartPropertyBase {
  1109. static SMARTPROPERTYPRIM_PROPCOUNT: number;
  1110. constructor();
  1111. /**
  1112. * Disposable pattern, this method must be overloaded by derived types in order to clean up hardware related resources.
  1113. * @returns false if the object is already dispose, true otherwise. Your implementation must call super.dispose() and check for a false return and return immediately if it's the case.
  1114. */
  1115. dispose(): boolean;
  1116. /**
  1117. * Animation array, more info: http://doc.babylonjs.com/tutorials/Animations
  1118. */
  1119. animations: Animation[];
  1120. /**
  1121. * Returns as a new array populated with the Animatable used by the primitive. Must be overloaded by derived primitives.
  1122. * Look at Sprite2D for more information
  1123. */
  1124. getAnimatables(): IAnimatable[];
  1125. /**
  1126. * Property giving the Model Key associated to the property.
  1127. * This value is constructed from the type of the primitive and all the name/value of its properties declared with the modelLevelProperty decorator
  1128. * @returns the model key string.
  1129. */
  1130. readonly modelKey: string;
  1131. /**
  1132. * States if the Primitive is dirty and should be rendered again next time.
  1133. * @returns true is dirty, false otherwise
  1134. */
  1135. readonly isDirty: boolean;
  1136. protected _boundingBoxDirty(): void;
  1137. protected _handlePropChanged<T>(curValue: T, newValue: T, propName: string, propInfo: Prim2DPropInfo, typeLevelCompare: boolean): void;
  1138. protected onPrimitivePropertyDirty(propFlagId: number): void;
  1139. protected handleGroupChanged(prop: Prim2DPropInfo): void;
  1140. _resetPropertiesDirty(): void;
  1141. /**
  1142. * Retrieve the boundingInfo for this Primitive, computed based on the primitive itself and NOT its children
  1143. */
  1144. readonly levelBoundingInfo: BoundingInfo2D;
  1145. /**
  1146. * This method must be overridden by a given Primitive implementation to compute its boundingInfo
  1147. */
  1148. protected updateLevelBoundingInfo(): void;
  1149. /**
  1150. * Property method called when the Primitive becomes dirty
  1151. */
  1152. protected onPrimBecomesDirty(): void;
  1153. /**
  1154. * Check if a given flag is set
  1155. * @param flag the flag value
  1156. * @return true if set, false otherwise
  1157. */
  1158. _isFlagSet(flag: number): boolean;
  1159. /**
  1160. * Check if all given flags are set
  1161. * @param flags the flags ORed
  1162. * @return true if all the flags are set, false otherwise
  1163. */
  1164. _areAllFlagsSet(flags: number): boolean;
  1165. /**
  1166. * Check if at least one flag of the given flags is set
  1167. * @param flags the flags ORed
  1168. * @return true if at least one flag is set, false otherwise
  1169. */
  1170. _areSomeFlagsSet(flags: number): boolean;
  1171. /**
  1172. * Clear the given flags
  1173. * @param flags the flags to clear
  1174. */
  1175. _clearFlags(flags: number): void;
  1176. /**
  1177. * Set the given flags to true state
  1178. * @param flags the flags ORed to set
  1179. * @return the flags state before this call
  1180. */
  1181. _setFlags(flags: number): number;
  1182. /**
  1183. * Change the state of the given flags
  1184. * @param flags the flags ORed to change
  1185. * @param state true to set them, false to clear them
  1186. */
  1187. _changeFlags(flags: number, state: boolean): void;
  1188. static flagNoPartOfLayout: number;
  1189. static flagLevelBoundingInfoDirty: number;
  1190. static flagModelDirty: number;
  1191. static flagLayoutDirty: number;
  1192. static flagLevelVisible: number;
  1193. static flagBoundingInfoDirty: number;
  1194. static flagIsPickable: number;
  1195. static flagIsVisible: number;
  1196. static flagVisibilityChanged: number;
  1197. static flagPositioningDirty: number;
  1198. static flagTrackedGroup: number;
  1199. static flagWorldCacheChanged: number;
  1200. static flagChildrenFlatZOrder: number;
  1201. static flagZOrderDirty: number;
  1202. static flagActualOpacityDirty: number;
  1203. static flagPrimInDirtyList: number;
  1204. static flagIsContainer: number;
  1205. static flagNeedRefresh: number;
  1206. static flagActualScaleDirty: number;
  1207. static flagDontInheritParentScale: number;
  1208. static flagGlobalTransformDirty: number;
  1209. static flagLayoutBoundingInfoDirty: number;
  1210. private _flags;
  1211. private _modelKey;
  1212. protected _levelBoundingInfo: BoundingInfo2D;
  1213. protected _boundingInfo: BoundingInfo2D;
  1214. protected _layoutBoundingInfo: BoundingInfo2D;
  1215. }
  1216. function dependencyProperty<T>(propId: number, piStore: (pi: Prim2DPropInfo) => void, mode?: number, updateSourceTrigger?: number): (target: Object, propName: string | symbol, descriptor: TypedPropertyDescriptor<T>) => void;
  1217. function modelLevelProperty<T>(propId: number, piStore: (pi: Prim2DPropInfo) => void, typeLevelCompare?: boolean, dirtyBoundingInfo?: boolean, dirtyParentBoundingBox?: boolean): (target: Object, propName: string | symbol, descriptor: TypedPropertyDescriptor<T>) => void;
  1218. function instanceLevelProperty<T>(propId: number, piStore: (pi: Prim2DPropInfo) => void, typeLevelCompare?: boolean, dirtyBoundingInfo?: boolean, dirtyParentBoundingBox?: boolean): (target: Object, propName: string | symbol, descriptor: TypedPropertyDescriptor<T>) => void;
  1219. function dynamicLevelProperty<T>(propId: number, piStore: (pi: Prim2DPropInfo) => void, typeLevelCompare?: boolean, dirtyBoundingInfo?: boolean, dirtyParentBoundingBox?: boolean): (target: Object, propName: string | symbol, descriptor: TypedPropertyDescriptor<T>) => void;
  1220. }
  1221. declare module BABYLON {
  1222. class PrepareRender2DContext {
  1223. constructor();
  1224. /**
  1225. * True if the primitive must be refreshed no matter what
  1226. * This mode is needed because sometimes the primitive doesn't change by itself, but external changes make a refresh of its InstanceData necessary
  1227. */
  1228. forceRefreshPrimitive: boolean;
  1229. }
  1230. class Render2DContext {
  1231. constructor(renderMode: number);
  1232. /**
  1233. * Define which render Mode should be used to render the primitive: one of Render2DContext.RenderModeXxxx property
  1234. */
  1235. readonly renderMode: number;
  1236. /**
  1237. * If true hardware instancing is supported and must be used for the rendering. The groupInfoPartData._partBuffer must be used.
  1238. * If false rendering on a per primitive basis must be made. The following properties must be used
  1239. * - groupInfoPartData._partData: contains the primitive instances data to render
  1240. * - partDataStartIndex: the index into instanceArrayData of the first instance to render.
  1241. * - partDataCount: the number of primitive to render
  1242. */
  1243. useInstancing: boolean;
  1244. /**
  1245. * If specified, must take precedence from the groupInfoPartData. partIndex is the same as groupInfoPardData
  1246. */
  1247. instancedBuffers: WebGLBuffer[];
  1248. /**
  1249. * To use when instancedBuffers is specified, gives the count of instances to draw
  1250. */
  1251. instancesCount: number;
  1252. /**
  1253. * Contains the data related to the primitives instances to render
  1254. */
  1255. groupInfoPartData: GroupInfoPartData[];
  1256. /**
  1257. * The index into groupInfoPartData._partData of the first primitive to render. This is an index, not an offset: it represent the nth primitive which is the first to render.
  1258. */
  1259. partDataStartIndex: number;
  1260. /**
  1261. * The exclusive end index, you have to render the primitive instances until you reach this one, but don't render this one!
  1262. */
  1263. partDataEndIndex: number;
  1264. /**
  1265. * The set of primitives to render is opaque.
  1266. * This is the first rendering pass. All Opaque primitives are rendered. Depth Compare and Write are both enabled.
  1267. */
  1268. static readonly RenderModeOpaque: number;
  1269. /**
  1270. * The set of primitives to render is using Alpha Test (aka masking).
  1271. * Alpha Blend is enabled, the AlphaMode must be manually set, the render occurs after the RenderModeOpaque and is depth independent (i.e. primitives are not sorted by depth). Depth Compare and Write are both enabled.
  1272. */
  1273. static readonly RenderModeAlphaTest: number;
  1274. /**
  1275. * The set of primitives to render is transparent.
  1276. * Alpha Blend is enabled, the AlphaMode must be manually set, the render occurs after the RenderModeAlphaTest and is depth dependent (i.e. primitives are stored by depth and rendered back to front). Depth Compare is on, but Depth write is Off.
  1277. */
  1278. static readonly RenderModeTransparent: number;
  1279. private static _renderModeOpaque;
  1280. private static _renderModeAlphaTest;
  1281. private static _renderModeTransparent;
  1282. private _renderMode;
  1283. }
  1284. /**
  1285. * This class store information for the pointerEventObservable Observable.
  1286. * The Observable is divided into many sub events (using the Mask feature of the Observable pattern): PointerOver, PointerEnter, PointerDown, PointerMouseWheel, PointerMove, PointerUp, PointerDown, PointerLeave, PointerGotCapture and PointerLostCapture.
  1287. */
  1288. class PrimitivePointerInfo {
  1289. private static _pointerOver;
  1290. private static _pointerEnter;
  1291. private static _pointerDown;
  1292. private static _pointerMouseWheel;
  1293. private static _pointerMove;
  1294. private static _pointerUp;
  1295. private static _pointerOut;
  1296. private static _pointerLeave;
  1297. private static _pointerGotCapture;
  1298. private static _pointerLostCapture;
  1299. private static _mouseWheelPrecision;
  1300. /**
  1301. * This event type is raised when a pointing device is moved into the hit test boundaries of a primitive.
  1302. * Bubbles: yes
  1303. */
  1304. static readonly PointerOver: number;
  1305. /**
  1306. * This event type is raised when a pointing device is moved into the hit test boundaries of a primitive or one of its descendants.
  1307. * Bubbles: no
  1308. */
  1309. static readonly PointerEnter: number;
  1310. /**
  1311. * This event type is raised when a pointer enters the active button state (non-zero value in the buttons property). For mouse it's when the device transitions from no buttons depressed to at least one button depressed. For touch/pen this is when a physical contact is made.
  1312. * Bubbles: yes
  1313. */
  1314. static readonly PointerDown: number;
  1315. /**
  1316. * This event type is raised when the pointer is a mouse and it's wheel is rolling
  1317. * Bubbles: yes
  1318. */
  1319. static readonly PointerMouseWheel: number;
  1320. /**
  1321. * This event type is raised when a pointer change coordinates or when a pointer changes button state, pressure, tilt, or contact geometry and the circumstances produce no other pointers events.
  1322. * Bubbles: yes
  1323. */
  1324. static readonly PointerMove: number;
  1325. /**
  1326. * This event type is raised when the pointer leaves the active buttons states (zero value in the buttons property). For mouse, this is when the device transitions from at least one button depressed to no buttons depressed. For touch/pen, this is when physical contact is removed.
  1327. * Bubbles: yes
  1328. */
  1329. static readonly PointerUp: number;
  1330. /**
  1331. * This event type is raised when a pointing device is moved out of the hit test the boundaries of a primitive.
  1332. * Bubbles: yes
  1333. */
  1334. static readonly PointerOut: number;
  1335. /**
  1336. * This event type is raised when a pointing device is moved out of the hit test boundaries of a primitive and all its descendants.
  1337. * Bubbles: no
  1338. */
  1339. static readonly PointerLeave: number;
  1340. /**
  1341. * This event type is raised when a primitive receives the pointer capture. This event is fired at the element that is receiving pointer capture. Subsequent events for that pointer will be fired at this element.
  1342. * Bubbles: yes
  1343. */
  1344. static readonly PointerGotCapture: number;
  1345. /**
  1346. * This event type is raised after pointer capture is released for a pointer.
  1347. * Bubbles: yes
  1348. */
  1349. static readonly PointerLostCapture: number;
  1350. static readonly MouseWheelPrecision: number;
  1351. /**
  1352. * Event Type, one of the static PointerXXXX property defined above (PrimitivePointerInfo.PointerOver to PrimitivePointerInfo.PointerLostCapture)
  1353. */
  1354. eventType: number;
  1355. /**
  1356. * Position of the pointer relative to the bottom/left of the Canvas
  1357. */
  1358. canvasPointerPos: Vector2;
  1359. /**
  1360. * Position of the pointer relative to the bottom/left of the primitive that registered the Observer
  1361. */
  1362. primitivePointerPos: Vector2;
  1363. /**
  1364. * The primitive where the event was initiated first (in case of bubbling)
  1365. */
  1366. relatedTarget: Prim2DBase;
  1367. /**
  1368. * Position of the pointer relative to the bottom/left of the relatedTarget
  1369. */
  1370. relatedTargetPointerPos: Vector2;
  1371. /**
  1372. * An observable can set this property to true to stop bubbling on the upper levels
  1373. */
  1374. cancelBubble: boolean;
  1375. /**
  1376. * True if the Control keyboard key is down
  1377. */
  1378. ctrlKey: boolean;
  1379. /**
  1380. * true if the Shift keyboard key is down
  1381. */
  1382. shiftKey: boolean;
  1383. /**
  1384. * true if the Alt keyboard key is down
  1385. */
  1386. altKey: boolean;
  1387. /**
  1388. * true if the Meta keyboard key is down
  1389. */
  1390. metaKey: boolean;
  1391. /**
  1392. * For button, buttons, refer to https://www.w3.org/TR/pointerevents/#button-states
  1393. */
  1394. button: number;
  1395. /**
  1396. * For button, buttons, refer to https://www.w3.org/TR/pointerevents/#button-states
  1397. */
  1398. buttons: number;
  1399. /**
  1400. * The amount of mouse wheel rolled
  1401. */
  1402. mouseWheelDelta: number;
  1403. /**
  1404. * Id of the Pointer involved in the event
  1405. */
  1406. pointerId: number;
  1407. width: number;
  1408. height: number;
  1409. presssure: number;
  1410. tilt: Vector2;
  1411. /**
  1412. * true if the involved pointer is captured for a particular primitive, false otherwise.
  1413. */
  1414. isCaptured: boolean;
  1415. constructor();
  1416. updateRelatedTarget(prim: Prim2DBase, primPointerPos: Vector2): void;
  1417. static getEventTypeName(mask: number): string;
  1418. }
  1419. /**
  1420. * Defines the horizontal and vertical alignment information for a Primitive.
  1421. */
  1422. class PrimitiveAlignment {
  1423. constructor(changeCallback?: () => void);
  1424. /**
  1425. * Alignment is made relative to the left edge of the Primitive. Valid for horizontal alignment only.
  1426. */
  1427. static readonly AlignLeft: number;
  1428. /**
  1429. * Alignment is made relative to the top edge of the Primitive. Valid for vertical alignment only.
  1430. */
  1431. static readonly AlignTop: number;
  1432. /**
  1433. * Alignment is made relative to the right edge of the Primitive. Valid for horizontal alignment only.
  1434. */
  1435. static readonly AlignRight: number;
  1436. /**
  1437. * Alignment is made relative to the bottom edge of the Primitive. Valid for vertical alignment only.
  1438. */
  1439. static readonly AlignBottom: number;
  1440. /**
  1441. * Alignment is made to center the content from equal distance to the opposite edges of the Primitive
  1442. */
  1443. static readonly AlignCenter: number;
  1444. /**
  1445. * The content is stretched toward the opposite edges of the Primitive
  1446. */
  1447. static readonly AlignStretch: number;
  1448. private static _AlignLeft;
  1449. private static _AlignTop;
  1450. private static _AlignRight;
  1451. private static _AlignBottom;
  1452. private static _AlignCenter;
  1453. private static _AlignStretch;
  1454. /**
  1455. * Get/set the horizontal alignment. Use one of the AlignXXX static properties of this class
  1456. */
  1457. horizontal: number;
  1458. /**
  1459. * Get/set the vertical alignment. Use one of the AlignXXX static properties of this class
  1460. */
  1461. vertical: number;
  1462. private onChangeCallback();
  1463. private _changedCallback;
  1464. private _horizontal;
  1465. private _vertical;
  1466. /**
  1467. * Set the horizontal alignment from a string value.
  1468. * @param text can be either: 'left','right','center','stretch'
  1469. */
  1470. setHorizontal(text: string): void;
  1471. /**
  1472. * Set the vertical alignment from a string value.
  1473. * @param text can be either: 'top','bottom','center','stretch'
  1474. */
  1475. setVertical(text: string): void;
  1476. /**
  1477. * Set the horizontal and or vertical alignments from a string value.
  1478. * @param text can be: [<h:|horizontal:><left|right|center|stretch>], [<v:|vertical:><top|bottom|center|stretch>]
  1479. */
  1480. fromString(value: string): void;
  1481. copyFrom(pa: PrimitiveAlignment): void;
  1482. readonly isDefault: boolean;
  1483. }
  1484. /**
  1485. * Stores information about a Primitive that was intersected
  1486. */
  1487. class PrimitiveIntersectedInfo {
  1488. prim: Prim2DBase;
  1489. intersectionLocation: Vector2;
  1490. constructor(prim: Prim2DBase, intersectionLocation: Vector2);
  1491. }
  1492. /**
  1493. * Define a thickness toward every edges of a Primitive to allow margin and padding.
  1494. * The thickness can be expressed as pixels, percentages, inherit the value of the parent primitive or be auto.
  1495. */
  1496. class PrimitiveThickness {
  1497. constructor(parentAccess: () => PrimitiveThickness, changedCallback?: () => void);
  1498. /**
  1499. * Set the thickness from a string value
  1500. * @param thickness format is "top: <value>, left:<value>, right:<value>, bottom:<value>" or "<value>" (same for all edges) each are optional, auto will be set if it's omitted.
  1501. * Values are: 'auto', 'inherit', 'XX%' for percentage, 'XXpx' or 'XX' for pixels.
  1502. */
  1503. fromString(thickness: string): void;
  1504. /**
  1505. * Set the thickness from multiple string
  1506. * Possible values are: 'auto', 'inherit', 'XX%' for percentage, 'XXpx' or 'XX' for pixels.
  1507. * @param top the top thickness to set
  1508. * @param left the left thickness to set
  1509. * @param right the right thickness to set
  1510. * @param bottom the bottom thickness to set
  1511. */
  1512. fromStrings(top: string, left: string, right: string, bottom: string): PrimitiveThickness;
  1513. /**
  1514. * Set the thickness from pixel values
  1515. * @param top the top thickness in pixels to set
  1516. * @param left the left thickness in pixels to set
  1517. * @param right the right thickness in pixels to set
  1518. * @param bottom the bottom thickness in pixels to set
  1519. */
  1520. fromPixels(top: number, left: number, right: number, bottom: number): PrimitiveThickness;
  1521. /**
  1522. * Apply the same pixel value to all edges
  1523. * @param margin the value to set, in pixels.
  1524. */
  1525. fromUniformPixels(margin: number): PrimitiveThickness;
  1526. copyFrom(pt: PrimitiveThickness): void;
  1527. /**
  1528. * Set all edges in auto
  1529. */
  1530. auto(): PrimitiveThickness;
  1531. private _clear();
  1532. private _extractString(value, emitChanged);
  1533. private _setStringValue(value, index, emitChanged);
  1534. private _setPixels(value, index, emitChanged);
  1535. private _setPercentage(value, index, emitChanged);
  1536. private _getStringValue(index);
  1537. private _isType(index, type);
  1538. private _getType(index, processInherit);
  1539. private _setType(index, type);
  1540. setTop(value: number | string): void;
  1541. setLeft(value: number | string): void;
  1542. setRight(value: number | string): void;
  1543. setBottom(value: number | string): void;
  1544. /**
  1545. * Get/set the top thickness. Possible values are: 'auto', 'inherit', 'XX%' for percentage, 'XXpx' or 'XX' for pixels.
  1546. */
  1547. top: string;
  1548. /**
  1549. * Get/set the left thickness. Possible values are: 'auto', 'inherit', 'XX%' for percentage, 'XXpx' or 'XX' for pixels.
  1550. */
  1551. left: string;
  1552. /**
  1553. * Get/set the right thickness. Possible values are: 'auto', 'inherit', 'XX%' for percentage, 'XXpx' or 'XX' for pixels.
  1554. */
  1555. right: string;
  1556. /**
  1557. * Get/set the bottom thickness. Possible values are: 'auto', 'inherit', 'XX%' for percentage, 'XXpx' or 'XX' for pixels.
  1558. */
  1559. bottom: string;
  1560. /**
  1561. * Get/set the top thickness in pixel.
  1562. */
  1563. topPixels: number;
  1564. /**
  1565. * Get/set the left thickness in pixel.
  1566. */
  1567. leftPixels: number;
  1568. /**
  1569. * Get/set the right thickness in pixel.
  1570. */
  1571. rightPixels: number;
  1572. /**
  1573. * Get/set the bottom thickness in pixel.
  1574. */
  1575. bottomPixels: number;
  1576. /**
  1577. * Get/set the top thickness in percentage.
  1578. * The get will return a valid value only if the edge type is percentage.
  1579. * The Set will change the edge mode if needed
  1580. */
  1581. topPercentage: number;
  1582. /**
  1583. * Get/set the left thickness in percentage.
  1584. * The get will return a valid value only if the edge mode is percentage.
  1585. * The Set will change the edge mode if needed
  1586. */
  1587. leftPercentage: number;
  1588. /**
  1589. * Get/set the right thickness in percentage.
  1590. * The get will return a valid value only if the edge mode is percentage.
  1591. * The Set will change the edge mode if needed
  1592. */
  1593. rightPercentage: number;
  1594. /**
  1595. * Get/set the bottom thickness in percentage.
  1596. * The get will return a valid value only if the edge mode is percentage.
  1597. * The Set will change the edge mode if needed
  1598. */
  1599. bottomPercentage: number;
  1600. /**
  1601. * Get/set the top mode. The setter shouldn't be used, other setters with value should be preferred
  1602. */
  1603. topMode: number;
  1604. /**
  1605. * Get/set the left mode. The setter shouldn't be used, other setters with value should be preferred
  1606. */
  1607. leftMode: number;
  1608. /**
  1609. * Get/set the right mode. The setter shouldn't be used, other setters with value should be preferred
  1610. */
  1611. rightMode: number;
  1612. /**
  1613. * Get/set the bottom mode. The setter shouldn't be used, other setters with value should be preferred
  1614. */
  1615. bottomMode: number;
  1616. readonly isDefault: boolean;
  1617. private _parentAccess;
  1618. private _changedCallback;
  1619. private _pixels;
  1620. private _percentages;
  1621. private _flags;
  1622. static Auto: number;
  1623. static Inherit: number;
  1624. static Percentage: number;
  1625. static Pixel: number;
  1626. private _computePixels(index, sourceArea, emitChanged);
  1627. private onChangeCallback();
  1628. /**
  1629. * Compute the positioning/size of an area considering the thickness of this object and a given alignment
  1630. * @param sourceArea the source area where the content must be sized/positioned
  1631. * @param contentSize the content size to position/resize
  1632. * @param alignment the alignment setting
  1633. * @param dstOffset the position of the content, x, y, z, w are left, bottom, right, top
  1634. * @param dstArea the new size of the content
  1635. */
  1636. computeWithAlignment(sourceArea: Size, contentSize: Size, alignment: PrimitiveAlignment, dstOffset: Vector4, dstArea: Size, computeLayoutArea?: boolean): void;
  1637. /**
  1638. * Compute an area and its position considering this thickness properties based on a given source area
  1639. * @param sourceArea the source area
  1640. * @param dstOffset the position of the resulting area
  1641. * @param dstArea the size of the resulting area
  1642. */
  1643. compute(sourceArea: Size, dstOffset: Vector4, dstArea: Size): void;
  1644. /**
  1645. * Compute an area considering this thickness properties based on a given source area
  1646. * @param sourceArea the source area
  1647. * @param result the resulting area
  1648. */
  1649. computeArea(sourceArea: Size, result: Size): void;
  1650. enlarge(sourceArea: Size, dstOffset: Vector4, enlargedArea: Size): void;
  1651. }
  1652. /**
  1653. * Main class used for the Primitive Intersection API
  1654. */
  1655. class IntersectInfo2D {
  1656. constructor();
  1657. /**
  1658. * Set the pick position, relative to the primitive where the intersection test is made
  1659. */
  1660. pickPosition: Vector2;
  1661. /**
  1662. * If true the intersection will stop at the first hit, if false all primitives will be tested and the intersectedPrimitives array will be filled accordingly (false default)
  1663. */
  1664. findFirstOnly: boolean;
  1665. /**
  1666. * If true the intersection test will also be made on hidden primitive (false default)
  1667. */
  1668. intersectHidden: boolean;
  1669. _globalPickPosition: Vector2;
  1670. _localPickPosition: Vector2;
  1671. /**
  1672. * The topmost intersected primitive
  1673. */
  1674. topMostIntersectedPrimitive: PrimitiveIntersectedInfo;
  1675. /**
  1676. * The array containing all intersected primitive, in no particular order.
  1677. */
  1678. intersectedPrimitives: Array<PrimitiveIntersectedInfo>;
  1679. /**
  1680. * true if at least one primitive intersected during the test
  1681. */
  1682. readonly isIntersected: boolean;
  1683. isPrimIntersected(prim: Prim2DBase): Vector2;
  1684. _exit(firstLevel: boolean): void;
  1685. }
  1686. class Prim2DBase extends SmartPropertyPrim {
  1687. static PRIM2DBASE_PROPCOUNT: number;
  1688. static _bigInt: number;
  1689. constructor(settings: {
  1690. parent?: Prim2DBase;
  1691. id?: string;
  1692. children?: Array<Prim2DBase>;
  1693. position?: Vector2;
  1694. x?: number;
  1695. y?: number;
  1696. rotation?: number;
  1697. scale?: number;
  1698. scaleX?: number;
  1699. scaleY?: number;
  1700. dontInheritParentScale?: boolean;
  1701. opacity?: number;
  1702. zOrder?: number;
  1703. origin?: Vector2;
  1704. layoutEngine?: LayoutEngineBase | string;
  1705. isVisible?: boolean;
  1706. isPickable?: boolean;
  1707. isContainer?: boolean;
  1708. childrenFlatZOrder?: boolean;
  1709. marginTop?: number | string;
  1710. marginLeft?: number | string;
  1711. marginRight?: number | string;
  1712. marginBottom?: number | string;
  1713. margin?: number | string;
  1714. marginHAlignment?: number;
  1715. marginVAlignment?: number;
  1716. marginAlignment?: string;
  1717. paddingTop?: number | string;
  1718. paddingLeft?: number | string;
  1719. paddingRight?: number | string;
  1720. paddingBottom?: number | string;
  1721. padding?: string;
  1722. });
  1723. readonly actionManager: ActionManager;
  1724. /**
  1725. * From 'this' primitive, traverse up (from parent to parent) until the given predicate is true
  1726. * @param predicate the predicate to test on each parent
  1727. * @return the first primitive where the predicate was successful
  1728. */
  1729. traverseUp(predicate: (p: Prim2DBase) => boolean): Prim2DBase;
  1730. /**
  1731. * Retrieve the owner Canvas2D
  1732. */
  1733. readonly owner: Canvas2D;
  1734. /**
  1735. * Get the parent primitive (can be the Canvas, only the Canvas has no parent)
  1736. */
  1737. readonly parent: Prim2DBase;
  1738. /**
  1739. * The array of direct children primitives
  1740. */
  1741. readonly children: Prim2DBase[];
  1742. /**
  1743. * The identifier of this primitive, may not be unique, it's for information purpose only
  1744. */
  1745. id: string;
  1746. /**
  1747. * Metadata of the position property
  1748. */
  1749. static positionProperty: Prim2DPropInfo;
  1750. /**
  1751. * Metadata of the left property
  1752. */
  1753. static xProperty: Prim2DPropInfo;
  1754. /**
  1755. * Metadata of the bottom property
  1756. */
  1757. static yProperty: Prim2DPropInfo;
  1758. /**
  1759. * Metadata of the actualPosition property
  1760. */
  1761. static actualPositionProperty: Prim2DPropInfo;
  1762. /**
  1763. * Metadata of the actualX (Left) property
  1764. */
  1765. static actualXProperty: Prim2DPropInfo;
  1766. /**
  1767. * Metadata of the actualY (Bottom) property
  1768. */
  1769. static actualYProperty: Prim2DPropInfo;
  1770. /**
  1771. * Metadata of the size property
  1772. */
  1773. static sizeProperty: Prim2DPropInfo;
  1774. /**
  1775. * Metadata of the width property
  1776. */
  1777. static widthProperty: Prim2DPropInfo;
  1778. /**
  1779. * Metadata of the height property
  1780. */
  1781. static heightProperty: Prim2DPropInfo;
  1782. /**
  1783. * Metadata of the rotation property
  1784. */
  1785. static rotationProperty: Prim2DPropInfo;
  1786. /**
  1787. * Metadata of the scale property
  1788. */
  1789. static scaleProperty: Prim2DPropInfo;
  1790. /**
  1791. * Metadata of the actualSize property
  1792. */
  1793. static actualSizeProperty: Prim2DPropInfo;
  1794. /**
  1795. * Metadata of the actualWidth property
  1796. */
  1797. static actualWidthProperty: Prim2DPropInfo;
  1798. /**
  1799. * Metadata of the actualHeight property
  1800. */
  1801. static actualHeightProperty: Prim2DPropInfo;
  1802. /**
  1803. * Metadata of the origin property
  1804. */
  1805. static originProperty: Prim2DPropInfo;
  1806. /**
  1807. * Metadata of the levelVisible property
  1808. */
  1809. static levelVisibleProperty: Prim2DPropInfo;
  1810. /**
  1811. * Metadata of the isVisible property
  1812. */
  1813. static isVisibleProperty: Prim2DPropInfo;
  1814. /**
  1815. * Metadata of the zOrder property
  1816. */
  1817. static zOrderProperty: Prim2DPropInfo;
  1818. /**
  1819. * Metadata of the margin property
  1820. */
  1821. static marginProperty: Prim2DPropInfo;
  1822. /**
  1823. * Metadata of the margin property
  1824. */
  1825. static paddingProperty: Prim2DPropInfo;
  1826. /**
  1827. * Metadata of the marginAlignment property
  1828. */
  1829. static marginAlignmentProperty: Prim2DPropInfo;
  1830. /**
  1831. * Metadata of the opacity property
  1832. */
  1833. static opacityProperty: Prim2DPropInfo;
  1834. /**
  1835. * Metadata of the scaleX property
  1836. */
  1837. static scaleXProperty: Prim2DPropInfo;
  1838. /**
  1839. * Metadata of the scaleY property
  1840. */
  1841. static scaleYProperty: Prim2DPropInfo;
  1842. /**
  1843. * Metadata of the actualScale property
  1844. */
  1845. static actualScaleProperty: Prim2DPropInfo;
  1846. /**
  1847. * DO NOT INVOKE for internal purpose only
  1848. */
  1849. actualPosition: Vector2;
  1850. private static _nullPosition;
  1851. /**
  1852. * Shortcut to actualPosition.x
  1853. */
  1854. actualX: number;
  1855. /**
  1856. * Shortcut to actualPosition.y
  1857. */
  1858. actualY: number;
  1859. /**
  1860. * Position of the primitive, relative to its parent.
  1861. * BEWARE: if you change only position.x or y it won't trigger a property change and you won't have the expected behavior.
  1862. * Use this property to set a new Vector2 object, otherwise to change only the x/y use Prim2DBase.x or y properties.
  1863. * Setting this property may have no effect is specific alignment are in effect.
  1864. */
  1865. position: Vector2;
  1866. /**
  1867. * Direct access to the position.x value of the primitive
  1868. * Use this property when you only want to change one component of the position property
  1869. */
  1870. x: number;
  1871. /**
  1872. * Direct access to the position.y value of the primitive
  1873. * Use this property when you only want to change one component of the position property
  1874. */
  1875. y: number;
  1876. private static boundinbBoxReentrency;
  1877. protected static nullSize: Size;
  1878. /**
  1879. * Size of the primitive or its bounding area
  1880. * BEWARE: if you change only size.width or height it won't trigger a property change and you won't have the expected behavior.
  1881. * Use this property to set a new Size object, otherwise to change only the width/height use Prim2DBase.width or height properties.
  1882. */
  1883. size: Size;
  1884. protected internalGetSize(): Size;
  1885. protected internalSetSize(value: Size): void;
  1886. /**
  1887. * Direct access to the size.width value of the primitive
  1888. * Use this property when you only want to change one component of the size property
  1889. */
  1890. width: number;
  1891. /**
  1892. * Direct access to the size.height value of the primitive
  1893. * Use this property when you only want to change one component of the size property
  1894. */
  1895. height: number;
  1896. rotation: number;
  1897. scale: number;
  1898. /**
  1899. * Return the size of the primitive as it's being rendered into the target.
  1900. * This value may be different of the size property when layout/alignment is used or specific primitive types can implement a custom logic through this property.
  1901. * BEWARE: don't use the setter, it's for internal purpose only
  1902. * Note to implementers: you have to override this property and declare if necessary a @xxxxInstanceLevel decorator
  1903. */
  1904. actualSize: Size;
  1905. /**
  1906. * Shortcut to actualSize.width
  1907. */
  1908. actualWidth: number;
  1909. /**
  1910. * Shortcut to actualPosition.height
  1911. */
  1912. actualHeight: number;
  1913. readonly actualZOffset: number;
  1914. /**
  1915. * Get or set the minimal size the Layout Engine should respect when computing the primitive's actualSize.
  1916. * The Primitive's size won't be less than specified.
  1917. * The default value depends of the Primitive type
  1918. */
  1919. minSize: Size;
  1920. /**
  1921. * Get or set the maximal size the Layout Engine should respect when computing the primitive's actualSize.
  1922. * The Primitive's size won't be more than specified.
  1923. * The default value depends of the Primitive type
  1924. */
  1925. maxSize: Size;
  1926. /**
  1927. * The origin defines the normalized coordinate of the center of the primitive, from the bottom/left corner.
  1928. * The origin is used only to compute transformation of the primitive, it has no meaning in the primitive local frame of reference
  1929. * For instance:
  1930. * 0,0 means the center is bottom/left. Which is the default for Canvas2D instances
  1931. * 0.5,0.5 means the center is at the center of the primitive, which is default of all types of Primitives
  1932. * 0,1 means the center is top/left
  1933. * @returns The normalized center.
  1934. */
  1935. origin: Vector2;
  1936. levelVisible: boolean;
  1937. isVisible: boolean;
  1938. zOrder: number;
  1939. readonly isManualZOrder: boolean;
  1940. margin: PrimitiveThickness;
  1941. /**
  1942. * Check for both margin and marginAlignment, return true if at least one of them is specified with a non default value
  1943. */
  1944. readonly _hasMargin: boolean;
  1945. padding: PrimitiveThickness;
  1946. private readonly _hasPadding;
  1947. marginAlignment: PrimitiveAlignment;
  1948. /**
  1949. * Check if there a marginAlignment specified (non null and not default)
  1950. */
  1951. readonly _hasMarginAlignment: boolean;
  1952. opacity: number;
  1953. scaleX: number;
  1954. scaleY: number;
  1955. protected _spreadActualScaleDirty(): void;
  1956. /**
  1957. * Returns the actual scale of this Primitive, the value is computed from the scale property of this primitive, multiplied by the actualScale of its parent one (if any). The Vector2 object returned contains the scale for both X and Y axis
  1958. */
  1959. readonly actualScale: Vector2;
  1960. /**
  1961. * Get the actual Scale of the X axis, shortcut for this.actualScale.x
  1962. */
  1963. readonly actualScaleX: number;
  1964. /**
  1965. * Get the actual Scale of the Y axis, shortcut for this.actualScale.y
  1966. */
  1967. readonly actualScaleY: number;
  1968. /**
  1969. * Get the actual opacity level, this property is computed from the opacity property, multiplied by the actualOpacity of its parent (if any)
  1970. */
  1971. readonly actualOpacity: number;
  1972. /**
  1973. * Get/set the layout engine to use for this primitive.
  1974. * The default layout engine is the CanvasLayoutEngine.
  1975. */
  1976. layoutEngine: LayoutEngineBase;
  1977. /**
  1978. * Get/set the layout are of this primitive.
  1979. * The Layout area is the zone allocated by the Layout Engine for this particular primitive. Margins/Alignment will be computed based on this area.
  1980. * The setter should only be called by a Layout Engine class.
  1981. */
  1982. layoutArea: Size;
  1983. /**
  1984. * Get/set the layout area position (relative to the parent primitive).
  1985. * The setter should only be called by a Layout Engine class.
  1986. */
  1987. layoutAreaPos: Vector2;
  1988. /**
  1989. * Define if the Primitive can be subject to intersection test or not (default is true)
  1990. */
  1991. isPickable: boolean;
  1992. /**
  1993. * Define if the Primitive acts as a container or not
  1994. * A container will encapsulate its children for interaction event.
  1995. * If it's not a container events will be process down to children if the primitive is not pickable.
  1996. * Default value is true
  1997. */
  1998. isContainer: boolean;
  1999. /**
  2000. * Return the depth level of the Primitive into the Canvas' Graph. A Canvas will be 0, its direct children 1, and so on.
  2001. */
  2002. readonly hierarchyDepth: number;
  2003. /**
  2004. * Retrieve the Group that is responsible to render this primitive
  2005. */
  2006. readonly renderGroup: Group2D;
  2007. /**
  2008. * Get the global transformation matrix of the primitive
  2009. */
  2010. readonly globalTransform: Matrix;
  2011. /**
  2012. * return the global position of the primitive, relative to its canvas
  2013. */
  2014. getGlobalPosition(): Vector2;
  2015. /**
  2016. * return the global position of the primitive, relative to its canvas
  2017. * @param v the valid Vector2 object where the global position will be stored
  2018. */
  2019. getGlobalPositionByRef(v: Vector2): void;
  2020. /**
  2021. * Get invert of the global transformation matrix of the primitive
  2022. */
  2023. readonly invGlobalTransform: Matrix;
  2024. /**
  2025. * Get the local transformation of the primitive
  2026. */
  2027. readonly localTransform: Matrix;
  2028. private static _bMinMax;
  2029. private static _bMax;
  2030. private static _bSize;
  2031. private static _tpsBB;
  2032. /**
  2033. * Get the boundingInfo associated to the primitive and its children.
  2034. * The value is supposed to be always up to date
  2035. */
  2036. readonly boundingInfo: BoundingInfo2D;
  2037. /**
  2038. * Get the boundingInfo of the primitive's content arranged by a layout Engine
  2039. * If a particular child is not arranged by layout, it's boundingInfo is used instead to produce something as accurate as possible
  2040. */
  2041. readonly layoutBoundingInfo: BoundingInfo2D;
  2042. /**
  2043. * Determine if the size is automatically computed or fixed because manually specified.
  2044. * Use the actualSize property to get the final/real size of the primitive
  2045. * @returns true if the size is automatically computed, false if it were manually specified.
  2046. */
  2047. readonly isSizeAuto: boolean;
  2048. /**
  2049. * Return true if this prim has an auto size which is set by the children's global bounding box
  2050. */
  2051. readonly isSizedByContent: boolean;
  2052. /**
  2053. * Determine if the position is automatically computed or fixed because manually specified.
  2054. * Use the actualPosition property to get the final/real position of the primitive
  2055. * @returns true if the position is automatically computed, false if it were manually specified.
  2056. */
  2057. readonly isPositionAuto: boolean;
  2058. /**
  2059. * Interaction with the primitive can be create using this Observable. See the PrimitivePointerInfo class for more information
  2060. */
  2061. readonly pointerEventObservable: Observable<PrimitivePointerInfo>;
  2062. readonly zActualOrderChangedObservable: Observable<number>;
  2063. displayDebugAreas: boolean;
  2064. private _updateDebugArea();
  2065. findById(id: string): Prim2DBase;
  2066. protected onZOrderChanged(): void;
  2067. protected levelIntersect(intersectInfo: IntersectInfo2D): boolean;
  2068. /**
  2069. * Capture all the Events of the given PointerId for this primitive.
  2070. * Don't forget to call releasePointerEventsCapture when done.
  2071. * @param pointerId the Id of the pointer to capture the events from.
  2072. */
  2073. setPointerEventCapture(pointerId: number): boolean;
  2074. /**
  2075. * Release a captured pointer made with setPointerEventCapture.
  2076. * @param pointerId the Id of the pointer to release the capture from.
  2077. */
  2078. releasePointerEventsCapture(pointerId: number): boolean;
  2079. /**
  2080. * Make an intersection test with the primitive, all inputs/outputs are stored in the IntersectInfo2D class, see its documentation for more information.
  2081. * @param intersectInfo contains the settings of the intersection to perform, to setup before calling this method as well as the result, available after a call to this method.
  2082. */
  2083. private static _bypassGroup2DExclusion;
  2084. intersect(intersectInfo: IntersectInfo2D): boolean;
  2085. /**
  2086. * Move a child object into a new position regarding its siblings to change its rendering order.
  2087. * You can also use the shortcut methods to move top/bottom: moveChildToTop, moveChildToBottom, moveToTop, moveToBottom.
  2088. * @param child the object to move
  2089. * @param previous the object which will be before "child", if child has to be the first among sibling, set "previous" to null.
  2090. */
  2091. moveChild(child: Prim2DBase, previous: Prim2DBase): boolean;
  2092. /**
  2093. * Move the given child so it's displayed on the top of all its siblings
  2094. * @param child the primitive to move to the top
  2095. */
  2096. moveChildToTop(child: Prim2DBase): boolean;
  2097. /**
  2098. * Move the given child so it's displayed on the bottom of all its siblings
  2099. * @param child the primitive to move to the top
  2100. */
  2101. moveChildToBottom(child: Prim2DBase): boolean;
  2102. /**
  2103. * Move this primitive to be at the top among all its sibling
  2104. */
  2105. moveToTop(): boolean;
  2106. /**
  2107. * Move this primitive to be at the bottom among all its sibling
  2108. */
  2109. moveToBottom(): boolean;
  2110. private addChild(child);
  2111. /**
  2112. * Dispose the primitive, remove it from its parent.
  2113. */
  2114. dispose(): boolean;
  2115. protected onPrimBecomesDirty(): void;
  2116. _needPrepare(): boolean;
  2117. _prepareRender(context: PrepareRender2DContext): void;
  2118. _prepareRenderPre(context: PrepareRender2DContext): void;
  2119. _prepareRenderPost(context: PrepareRender2DContext): void;
  2120. protected _canvasPreInit(settings: any): void;
  2121. protected static _isCanvasInit: boolean;
  2122. protected static CheckParent(parent: Prim2DBase): void;
  2123. protected updateCachedStatesOf(list: Prim2DBase[], recurse: boolean): void;
  2124. private _parentLayoutDirty();
  2125. protected _setLayoutDirty(): void;
  2126. private _checkPositionChange();
  2127. protected _positioningDirty(): void;
  2128. protected _spreadActualOpacityChanged(): void;
  2129. private _changeLayoutEngine(engine);
  2130. private static _t0;
  2131. private static _t1;
  2132. private static _t2;
  2133. private static _v0;
  2134. private _updateLocalTransform();
  2135. private static _transMtx;
  2136. protected updateCachedStates(recurse: boolean): void;
  2137. private static _icPos;
  2138. private static _icZone;
  2139. private static _icArea;
  2140. private static _size;
  2141. private _updatePositioning();
  2142. /**
  2143. * Get the content are of this primitive, this area is computed using the padding property and also possibly the primitive type itself.
  2144. * Children of this primitive will be positioned relative to the bottom/left corner of this area.
  2145. */
  2146. readonly contentArea: Size;
  2147. _patchHierarchy(owner: Canvas2D): void;
  2148. private static _zOrderChangedNotifList;
  2149. private static _zRebuildReentrency;
  2150. private _updateZOrder();
  2151. private static _totalCount;
  2152. private _updatePrimitiveLinearPosition(prevLinPos);
  2153. private _updatePrimitiveZOrder(startPos, startZ, deltaZ);
  2154. private _updatePrimitiveFlatZOrder(newZ);
  2155. private _setZOrder(newZ, directEmit);
  2156. protected _updateRenderMode(): void;
  2157. /**
  2158. * This method is used to alter the contentArea of the Primitive before margin is applied.
  2159. * In most of the case you won't need to override this method, but it can prove some usefulness, check the Rectangle2D class for a concrete application.
  2160. * @param primSize the current size of the primitive
  2161. * @param initialContentPosition the position of the initial content area to compute, a valid object is passed, you have to set its properties. PLEASE ROUND the values, we're talking about pixels and fraction of them is not a good thing! x, y, z, w area left, bottom, right, top
  2162. * @param initialContentArea the size of the initial content area to compute, a valid object is passed, you have to set its properties. PLEASE ROUND the values, we're talking about pixels and fraction of them is not a good thing!
  2163. */
  2164. protected _getInitialContentAreaToRef(primSize: Size, initialContentPosition: Vector4, initialContentArea: Size): void;
  2165. /**
  2166. * This method is used to calculate the new size of the primitive based on the content which must stay the same
  2167. * Check the Rectangle2D implementation for a concrete application.
  2168. * @param primSize the current size of the primitive
  2169. * @param newPrimSize the new size of the primitive. PLEASE ROUND THE values, we're talking about pixels and fraction of them are not our friends!
  2170. */
  2171. protected _getActualSizeFromContentToRef(primSize: Size, newPrimSize: Size): void;
  2172. private _owner;
  2173. private _parent;
  2174. private _actionManager;
  2175. protected _children: Array<Prim2DBase>;
  2176. private _renderGroup;
  2177. protected _hierarchyDepth: number;
  2178. protected _zOrder: number;
  2179. private _manualZOrder;
  2180. protected _zMax: number;
  2181. private _firstZDirtyIndex;
  2182. private _primLinearPosition;
  2183. private _margin;
  2184. private _padding;
  2185. private _marginAlignment;
  2186. _pointerEventObservable: Observable<PrimitivePointerInfo>;
  2187. private _actualZOrderChangedObservable;
  2188. private _id;
  2189. private _position;
  2190. private _actualPosition;
  2191. protected _size: Size;
  2192. protected _actualSize: Size;
  2193. _boundingSize: Size;
  2194. protected _minSize: Size;
  2195. protected _maxSize: Size;
  2196. protected _desiredSize: Size;
  2197. private _layoutEngine;
  2198. private _marginOffset;
  2199. private _paddingOffset;
  2200. private _parentPaddingOffset;
  2201. private _parentContentArea;
  2202. private _lastAutoSizeArea;
  2203. private _layoutAreaPos;
  2204. private _layoutArea;
  2205. private _contentArea;
  2206. private _rotation;
  2207. private _scale;
  2208. private _origin;
  2209. protected _opacity: number;
  2210. private _actualOpacity;
  2211. private _actualScale;
  2212. private _displayDebugAreas;
  2213. private _debugAreaGroup;
  2214. protected _parentTransformStep: number;
  2215. protected _globalTransformStep: number;
  2216. protected _globalTransformProcessStep: number;
  2217. protected _localTransform: Matrix;
  2218. protected _globalTransform: Matrix;
  2219. protected _invGlobalTransform: Matrix;
  2220. }
  2221. }
  2222. declare module BABYLON {
  2223. const enum ShaderDataType {
  2224. Vector2 = 0,
  2225. Vector3 = 1,
  2226. Vector4 = 2,
  2227. Matrix = 3,
  2228. float = 4,
  2229. Color3 = 5,
  2230. Color4 = 6,
  2231. Size = 7,
  2232. }
  2233. class GroupInstanceInfo {
  2234. constructor(owner: Group2D, mrc: ModelRenderCache, partCount: number);
  2235. dispose(): boolean;
  2236. private _isDisposed;
  2237. owner: Group2D;
  2238. modelRenderCache: ModelRenderCache;
  2239. partIndexFromId: StringDictionary<number>;
  2240. readonly hasOpaqueData: boolean;
  2241. readonly hasAlphaTestData: boolean;
  2242. readonly hasTransparentData: boolean;
  2243. opaqueDirty: boolean;
  2244. readonly opaqueData: GroupInfoPartData[];
  2245. alphaTestDirty: boolean;
  2246. readonly alphaTestData: GroupInfoPartData[];
  2247. transparentOrderDirty: boolean;
  2248. transparentDirty: boolean;
  2249. readonly transparentData: TransparentGroupInfoPartData[];
  2250. sortTransparentData(): void;
  2251. readonly usedShaderCategories: string[];
  2252. readonly strides: number[];
  2253. private _partCount;
  2254. private _strides;
  2255. private _usedShaderCategories;
  2256. private _opaqueData;
  2257. private _alphaTestData;
  2258. private _transparentData;
  2259. }
  2260. class TransparentSegment {
  2261. constructor();
  2262. dispose(engine: Engine): void;
  2263. groupInsanceInfo: GroupInstanceInfo;
  2264. startZ: number;
  2265. endZ: number;
  2266. startDataIndex: number;
  2267. endDataIndex: number;
  2268. partBuffers: WebGLBuffer[];
  2269. }
  2270. class GroupInfoPartData {
  2271. _partData: DynamicFloatArray;
  2272. _partBuffer: WebGLBuffer;
  2273. _partBufferSize: number;
  2274. constructor(stride: number);
  2275. dispose(engine: Engine): boolean;
  2276. private _isDisposed;
  2277. }
  2278. class TransparentGroupInfoPartData extends GroupInfoPartData {
  2279. constructor(stride: number, zoff: number);
  2280. }
  2281. class ModelRenderCache {
  2282. constructor(engine: Engine, modelKey: string);
  2283. dispose(): boolean;
  2284. readonly isDisposed: boolean;
  2285. addRef(): number;
  2286. readonly modelKey: string;
  2287. /**
  2288. * Render the model instances
  2289. * @param instanceInfo
  2290. * @param context
  2291. * @return must return true is the rendering succeed, false if the rendering couldn't be done (asset's not yet ready, like Effect)
  2292. */
  2293. render(instanceInfo: GroupInstanceInfo, context: Render2DContext): boolean;
  2294. protected getPartIndexFromId(partId: number): number;
  2295. protected loadInstancingAttributes(partId: number, effect: Effect): InstancingAttributeInfo[];
  2296. private static v2;
  2297. private static v3;
  2298. private static v4;
  2299. protected setupUniforms(effect: Effect, partIndex: number, data: DynamicFloatArray, elementCount: number): void;
  2300. protected _engine: Engine;
  2301. private _modelKey;
  2302. private _nextKey;
  2303. private _refCounter;
  2304. _partData: ModelRenderCachePartData[];
  2305. _partsClassInfo: ClassTreeInfo<InstanceClassInfo, InstancePropInfo>[];
  2306. }
  2307. class ModelRenderCachePartData {
  2308. _partId: number;
  2309. _zBiasOffset: number;
  2310. _partDataStride: number;
  2311. _partUsedCategories: string[];
  2312. _partJoinedUsedCategories: string;
  2313. }
  2314. }
  2315. declare module BABYLON {
  2316. class InstanceClassInfo {
  2317. constructor(base: InstanceClassInfo);
  2318. mapProperty(propInfo: InstancePropInfo, push: boolean): void;
  2319. getInstancingAttributeInfos(effect: Effect, categories: string[]): InstancingAttributeInfo[];
  2320. getShaderAttributes(categories: string[]): string[];
  2321. private _getBaseOffset(categories);
  2322. static _CurCategories: string;
  2323. private _baseInfo;
  2324. private _nextOffset;
  2325. private _attributes;
  2326. }
  2327. class InstancePropInfo {
  2328. attributeName: string;
  2329. category: string;
  2330. size: number;
  2331. shaderOffset: number;
  2332. instanceOffset: StringDictionary<number>;
  2333. dataType: ShaderDataType;
  2334. delimitedCategory: string;
  2335. constructor();
  2336. setSize(val: any): void;
  2337. writeData(array: Float32Array, offset: number, val: any): void;
  2338. }
  2339. function instanceData<T>(category?: string, shaderAttributeName?: string): (target: Object, propName: string | symbol, descriptor: TypedPropertyDescriptor<T>) => void;
  2340. class InstanceDataBase {
  2341. constructor(partId: number, dataElementCount: number);
  2342. id: number;
  2343. isVisible: boolean;
  2344. zBias: Vector2;
  2345. transformX: Vector4;
  2346. transformY: Vector4;
  2347. opacity: number;
  2348. getClassTreeInfo(): ClassTreeInfo<InstanceClassInfo, InstancePropInfo>;
  2349. allocElements(): void;
  2350. freeElements(): void;
  2351. dataElementCount: number;
  2352. groupInstanceInfo: GroupInstanceInfo;
  2353. arrayLengthChanged: boolean;
  2354. curElement: number;
  2355. renderMode: number;
  2356. dataElements: DynamicFloatArrayElementInfo[];
  2357. dataBuffer: DynamicFloatArray;
  2358. typeInfo: ClassTreeInfo<InstanceClassInfo, InstancePropInfo>;
  2359. private _dataElementCount;
  2360. }
  2361. abstract class RenderablePrim2D extends Prim2DBase {
  2362. static RENDERABLEPRIM2D_PROPCOUNT: number;
  2363. static isAlphaTestProperty: Prim2DPropInfo;
  2364. static isTransparentProperty: Prim2DPropInfo;
  2365. readonly isAlphaTest: boolean;
  2366. readonly isTransparent: boolean;
  2367. readonly renderMode: number;
  2368. constructor(settings?: {
  2369. parent?: Prim2DBase;
  2370. id?: string;
  2371. origin?: Vector2;
  2372. isVisible?: boolean;
  2373. });
  2374. /**
  2375. * Dispose the primitive and its resources, remove it from its parent
  2376. */
  2377. dispose(): boolean;
  2378. private _cleanupInstanceDataParts();
  2379. _prepareRenderPre(context: PrepareRender2DContext): void;
  2380. private _createModelRenderCache();
  2381. private _createModelDataParts();
  2382. private _setupModelRenderCache(parts);
  2383. protected onZOrderChanged(): void;
  2384. protected _mustUpdateInstance(): boolean;
  2385. protected _useTextureAlpha(): boolean;
  2386. protected _shouldUseAlphaFromTexture(): boolean;
  2387. protected _isPrimAlphaTest(): boolean;
  2388. protected _isPrimTransparent(): boolean;
  2389. private _updateInstanceDataParts(gii);
  2390. _updateTransparentSegmentIndices(ts: TransparentSegment): void;
  2391. _getNextPrimZOrder(): number;
  2392. _getPrevPrimZOrder(): number;
  2393. /**
  2394. * Transform a given point using the Primitive's origin setting.
  2395. * This method requires the Primitive's actualSize to be accurate
  2396. * @param p the point to transform
  2397. * @param originOffset an offset applied on the current origin before performing the transformation. Depending on which frame of reference your data is expressed you may have to apply a offset. (if you data is expressed from the bottom/left, no offset is required. If it's expressed from the center the a [-0.5;-0.5] offset has to be applied.
  2398. * @param res an allocated Vector2 that will receive the transformed content
  2399. */
  2400. protected transformPointWithOriginByRef(p: Vector2, originOffset: Vector2, res: Vector2): void;
  2401. protected transformPointWithOriginToRef(p: Vector2, originOffset: Vector2, res: Vector2): Vector2;
  2402. /**
  2403. * Get the info for a given effect based on the dataPart metadata
  2404. * @param dataPartId partId in part list to get the info
  2405. * @param vertexBufferAttributes vertex buffer attributes to manually add
  2406. * @param uniforms uniforms to manually add
  2407. * @param useInstanced specified if Instanced Array should be used, if null the engine caps will be used (so true if WebGL supports it, false otherwise), but you have the possibility to override the engine capability. However, if you manually set true but the engine does not support Instanced Array, this method will return null
  2408. */
  2409. protected getDataPartEffectInfo(dataPartId: number, vertexBufferAttributes: string[], uniforms?: string[], useInstanced?: boolean): {
  2410. attributes: string[];
  2411. uniforms: string[];
  2412. defines: string;
  2413. };
  2414. protected readonly modelRenderCache: ModelRenderCache;
  2415. protected createModelRenderCache(modelKey: string): ModelRenderCache;
  2416. protected setupModelRenderCache(modelRenderCache: ModelRenderCache): void;
  2417. protected createInstanceDataParts(): InstanceDataBase[];
  2418. protected getUsedShaderCategories(dataPart: InstanceDataBase): string[];
  2419. protected beforeRefreshForLayoutConstruction(part: InstanceDataBase): any;
  2420. protected afterRefreshForLayoutConstruction(part: InstanceDataBase, obj: any): void;
  2421. protected applyActualScaleOnTransform(): boolean;
  2422. protected refreshInstanceDataPart(part: InstanceDataBase): boolean;
  2423. private static _uV;
  2424. private static _s;
  2425. private static _r;
  2426. private static _t;
  2427. private static _uV3;
  2428. /**
  2429. * Update the instanceDataBase level properties of a part
  2430. * @param part the part to update
  2431. * @param positionOffset to use in multi part per primitive (e.g. the Text2D has N parts for N letter to display), this give the offset to apply (e.g. the position of the letter from the bottom/left corner of the text).
  2432. */
  2433. protected updateInstanceDataPart(part: InstanceDataBase, positionOffset?: Vector2): void;
  2434. protected _updateRenderMode(): void;
  2435. private _modelRenderCache;
  2436. private _transparentPrimitiveInfo;
  2437. protected _instanceDataParts: InstanceDataBase[];
  2438. private _renderMode;
  2439. }
  2440. }
  2441. declare module BABYLON {
  2442. abstract class Shape2D extends RenderablePrim2D {
  2443. static SHAPE2D_BORDERPARTID: number;
  2444. static SHAPE2D_FILLPARTID: number;
  2445. static SHAPE2D_CATEGORY_BORDER: string;
  2446. static SHAPE2D_CATEGORY_BORDERSOLID: string;
  2447. static SHAPE2D_CATEGORY_BORDERGRADIENT: string;
  2448. static SHAPE2D_CATEGORY_FILLSOLID: string;
  2449. static SHAPE2D_CATEGORY_FILLGRADIENT: string;
  2450. static SHAPE2D_PROPCOUNT: number;
  2451. static borderProperty: Prim2DPropInfo;
  2452. static fillProperty: Prim2DPropInfo;
  2453. static borderThicknessProperty: Prim2DPropInfo;
  2454. border: IBrush2D;
  2455. /**
  2456. * Get/set the brush to render the Fill part of the Primitive
  2457. */
  2458. fill: IBrush2D;
  2459. borderThickness: number;
  2460. constructor(settings?: {
  2461. fill?: IBrush2D | string;
  2462. border?: IBrush2D | string;
  2463. borderThickness?: number;
  2464. });
  2465. protected getUsedShaderCategories(dataPart: InstanceDataBase): string[];
  2466. protected applyActualScaleOnTransform(): boolean;
  2467. protected refreshInstanceDataPart(part: InstanceDataBase): boolean;
  2468. private _updateTransparencyStatus();
  2469. protected _mustUpdateInstance(): boolean;
  2470. protected _isPrimTransparent(): boolean;
  2471. private _oldTransparent;
  2472. private _isTransparent;
  2473. private _border;
  2474. private _borderThickness;
  2475. private _fill;
  2476. }
  2477. class Shape2DInstanceData extends InstanceDataBase {
  2478. fillSolidColor: Color4;
  2479. fillGradientColor1: Color4;
  2480. fillGradientColor2: Color4;
  2481. fillGradientTY: Vector4;
  2482. borderThickness: number;
  2483. borderSolidColor: Color4;
  2484. borderGradientColor1: Color4;
  2485. borderGradientColor2: Color4;
  2486. borderGradientTY: Vector4;
  2487. }
  2488. }
  2489. declare module BABYLON {
  2490. class Group2D extends Prim2DBase {
  2491. static GROUP2D_PROPCOUNT: number;
  2492. static sizeProperty: Prim2DPropInfo;
  2493. static actualSizeProperty: Prim2DPropInfo;
  2494. /**
  2495. * Default behavior, the group will use the caching strategy defined at the Canvas Level
  2496. */
  2497. static GROUPCACHEBEHAVIOR_FOLLOWCACHESTRATEGY: number;
  2498. /**
  2499. * When used, this group's content won't be cached, no matter which strategy used.
  2500. * If the group is part of a WorldSpace Canvas, its content will be drawn in the Canvas cache bitmap.
  2501. */
  2502. static GROUPCACHEBEHAVIOR_DONTCACHEOVERRIDE: number;
  2503. /**
  2504. * When used, the group's content will be cached in the nearest cached parent group/canvas
  2505. */
  2506. static GROUPCACHEBEHAVIOR_CACHEINPARENTGROUP: number;
  2507. /**
  2508. * You can specify this behavior to any cached Group2D to indicate that you don't want the cached content to be resized when the Group's actualScale is changing. It will draw the content stretched or shrink which is faster than a resize. This setting is obviously for performance consideration, don't use it if you want the best rendering quality
  2509. */
  2510. static GROUPCACHEBEHAVIOR_NORESIZEONSCALE: number;
  2511. private static GROUPCACHEBEHAVIOR_OPTIONMASK;
  2512. /**
  2513. * Create an Logical or Renderable Group.
  2514. * @param settings a combination of settings, possible ones are
  2515. * - parent: the parent primitive/canvas, must be specified if the primitive is not constructed as a child of another one (i.e. as part of the children array setting)
  2516. * - children: an array of direct children
  2517. * - id a text identifier, for information purpose
  2518. * - position: the X & Y positions relative to its parent. Alternatively the x and y properties can be set. Default is [0;0]
  2519. * - rotation: the initial rotation (in radian) of the primitive. default is 0
  2520. * - scale: the initial scale of the primitive. default is 1. You can alternatively use scaleX &| scaleY to apply non uniform scale
  2521. * - dontInheritParentScale: if set the parent's scale won't be taken into consideration to compute the actualScale property
  2522. * - opacity: set the overall opacity of the primitive, 1 to be opaque (default), less than 1 to be transparent.
  2523. * - zOrder: override the zOrder with the specified value
  2524. * - origin: define the normalized origin point location, default [0.5;0.5]
  2525. * - size: the size of the group. Alternatively the width and height properties can be set. If null the size will be computed from its content, default is null.
  2526. * - cacheBehavior: Define how the group should behave regarding the Canvas's cache strategy, default is Group2D.GROUPCACHEBEHAVIOR_FOLLOWCACHESTRATEGY
  2527. * - layoutEngine: either an instance of a layout engine based class (StackPanel.Vertical, StackPanel.Horizontal) or a string ('canvas' for Canvas layout, 'StackPanel' or 'HorizontalStackPanel' for horizontal Stack Panel layout, 'VerticalStackPanel' for vertical Stack Panel layout).
  2528. * - isVisible: true if the group must be visible, false for hidden. Default is true.
  2529. * - isPickable: if true the Primitive can be used with interaction mode and will issue Pointer Event. If false it will be ignored for interaction/intersection test. Default value is true.
  2530. * - isContainer: if true the Primitive acts as a container for interaction, if the primitive is not pickable or doesn't intersection, no further test will be perform on its children. If set to false, children will always be considered for intersection/interaction. Default value is true.
  2531. * - childrenFlatZOrder: if true all the children (direct and indirect) will share the same Z-Order. Use this when there's a lot of children which don't overlap. The drawing order IS NOT GUARANTED!
  2532. * - marginTop: top margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  2533. * - marginLeft: left margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  2534. * - marginRight: right margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  2535. * - marginBottom: bottom margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  2536. * - margin: top, left, right and bottom margin formatted as a single string (see PrimitiveThickness.fromString)
  2537. * - marginHAlignment: one value of the PrimitiveAlignment type's static properties
  2538. * - marginVAlignment: one value of the PrimitiveAlignment type's static properties
  2539. * - marginAlignment: a string defining the alignment, see PrimitiveAlignment.fromString
  2540. * - paddingTop: top padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  2541. * - paddingLeft: left padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  2542. * - paddingRight: right padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  2543. * - paddingBottom: bottom padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  2544. * - padding: top, left, right and bottom padding formatted as a single string (see PrimitiveThickness.fromString)
  2545. */
  2546. constructor(settings?: {
  2547. parent?: Prim2DBase;
  2548. children?: Array<Prim2DBase>;
  2549. id?: string;
  2550. position?: Vector2;
  2551. x?: number;
  2552. y?: number;
  2553. scale?: number;
  2554. scaleX?: number;
  2555. scaleY?: number;
  2556. dontInheritParentScale?: boolean;
  2557. trackNode?: Node;
  2558. opacity?: number;
  2559. zOrder?: number;
  2560. origin?: Vector2;
  2561. size?: Size;
  2562. width?: number;
  2563. height?: number;
  2564. cacheBehavior?: number;
  2565. layoutEngine?: LayoutEngineBase | string;
  2566. isVisible?: boolean;
  2567. isPickable?: boolean;
  2568. isContainer?: boolean;
  2569. childrenFlatZOrder?: boolean;
  2570. marginTop?: number | string;
  2571. marginLeft?: number | string;
  2572. marginRight?: number | string;
  2573. marginBottom?: number | string;
  2574. margin?: number | string;
  2575. marginHAlignment?: number;
  2576. marginVAlignment?: number;
  2577. marginAlignment?: string;
  2578. paddingTop?: number | string;
  2579. paddingLeft?: number | string;
  2580. paddingRight?: number | string;
  2581. paddingBottom?: number | string;
  2582. padding?: string;
  2583. });
  2584. static _createCachedCanvasGroup(owner: Canvas2D): Group2D;
  2585. protected applyCachedTexture(vertexData: VertexData, material: StandardMaterial): void;
  2586. /**
  2587. * Allow you to access the information regarding the cached rectangle of the Group2D into the MapTexture.
  2588. * If the `noWorldSpaceNode` options was used at the creation of a WorldSpaceCanvas, the rendering of the canvas must be made by the caller, so typically you want to bind the cacheTexture property to some material/mesh and you MUST use the Group2D.cachedUVs property to get the UV coordinates to use for your quad that will display the Canvas and NOT the PackedRect.UVs property which are incorrect because the allocated surface may be bigger (due to over-provisioning or shrinking without deallocating) than what the Group is actually using.
  2589. */
  2590. readonly cachedRect: PackedRect;
  2591. /**
  2592. * The UVs into the MapTexture that map the cached group
  2593. */
  2594. readonly cachedUVs: Vector2[];
  2595. readonly cachedUVsChanged: Observable<Vector2[]>;
  2596. /**
  2597. * Access the texture that maintains a cached version of the Group2D.
  2598. * This is useful only if you're not using a WorldSpaceNode for your WorldSpace Canvas and therefore need to perform the rendering yourself.
  2599. */
  2600. readonly cacheTexture: MapTexture;
  2601. /**
  2602. * Call this method to remove this Group and its children from the Canvas
  2603. */
  2604. dispose(): boolean;
  2605. /**
  2606. * @returns Returns true if the Group render content, false if it's a logical group only
  2607. */
  2608. readonly isRenderableGroup: boolean;
  2609. /**
  2610. * @returns only meaningful for isRenderableGroup, will be true if the content of the Group is cached into a texture, false if it's rendered every time
  2611. */
  2612. readonly isCachedGroup: boolean;
  2613. /**
  2614. * Get/Set the size of the group. If null the size of the group will be determine from its content.
  2615. * BEWARE: if the Group is a RenderableGroup and its content is cache the texture will be resized each time the group is getting bigger. For performance reason the opposite won't be true: the texture won't shrink if the group does.
  2616. */
  2617. size: Size;
  2618. readonly viewportSize: ISize;
  2619. actualSize: Size;
  2620. /**
  2621. * Get/set the Cache Behavior, used in case the Canvas Cache Strategy is set to CACHESTRATEGY_ALLGROUPS. Can be either GROUPCACHEBEHAVIOR_CACHEINPARENTGROUP, GROUPCACHEBEHAVIOR_DONTCACHEOVERRIDE or GROUPCACHEBEHAVIOR_FOLLOWCACHESTRATEGY. See their documentation for more information.
  2622. * GROUPCACHEBEHAVIOR_NORESIZEONSCALE can also be set if you set it at creation time.
  2623. * It is critical to understand than you HAVE TO play with this behavior in order to achieve a good performance/memory ratio. Caching all groups would certainly be the worst strategy of all.
  2624. */
  2625. readonly cacheBehavior: number;
  2626. _addPrimToDirtyList(prim: Prim2DBase): void;
  2627. _renderCachedCanvas(): void;
  2628. /**
  2629. * Get/set the Scene's Node that should be tracked, the group's position will follow the projected position of the Node.
  2630. */
  2631. trackedNode: Node;
  2632. protected levelIntersect(intersectInfo: IntersectInfo2D): boolean;
  2633. protected updateLevelBoundingInfo(): void;
  2634. protected _prepareGroupRender(context: PrepareRender2DContext): void;
  2635. protected _groupRender(): void;
  2636. _setCacheGroupDirty(): void;
  2637. private _updateTransparentData();
  2638. private _renderTransparentData();
  2639. private _prepareContext(engine, context, gii);
  2640. protected _setRenderingScale(scale: number): void;
  2641. private static _uV;
  2642. private static _s;
  2643. private _bindCacheTarget();
  2644. private _unbindCacheTarget();
  2645. protected _spreadActualScaleDirty(): void;
  2646. protected static _unS: Vector2;
  2647. protected handleGroupChanged(prop: Prim2DPropInfo): void;
  2648. private detectGroupStates();
  2649. private _trackedNode;
  2650. protected _isRenderableGroup: boolean;
  2651. protected _isCachedGroup: boolean;
  2652. private _cacheGroupDirty;
  2653. private _cacheBehavior;
  2654. private _viewportPosition;
  2655. private _viewportSize;
  2656. _renderableData: RenderableGroupData;
  2657. }
  2658. class RenderableGroupData {
  2659. constructor();
  2660. dispose(owner: Canvas2D): void;
  2661. addNewTransparentPrimitiveInfo(prim: RenderablePrim2D, gii: GroupInstanceInfo): TransparentPrimitiveInfo;
  2662. removeTransparentPrimitiveInfo(tpi: TransparentPrimitiveInfo): void;
  2663. transparentPrimitiveZChanged(tpi: TransparentPrimitiveInfo): void;
  2664. _primDirtyList: Array<Prim2DBase>;
  2665. _primNewDirtyList: Array<Prim2DBase>;
  2666. _childrenRenderableGroups: Array<Group2D>;
  2667. _renderGroupInstancesInfo: StringDictionary<GroupInstanceInfo>;
  2668. _cacheNode: PackedRect;
  2669. _cacheTexture: MapTexture;
  2670. _cacheRenderSprite: Sprite2D;
  2671. _cacheNodeUVs: Vector2[];
  2672. _cacheNodeUVsChangedObservable: Observable<Vector2[]>;
  2673. _cacheSize: Size;
  2674. _useMipMap: boolean;
  2675. _anisotropicLevel: number;
  2676. _noResizeOnScale: boolean;
  2677. _transparentListChanged: boolean;
  2678. _transparentPrimitives: Array<TransparentPrimitiveInfo>;
  2679. _transparentSegments: Array<TransparentSegment>;
  2680. _renderingScale: number;
  2681. }
  2682. class TransparentPrimitiveInfo {
  2683. _primitive: RenderablePrim2D;
  2684. _groupInstanceInfo: GroupInstanceInfo;
  2685. _transparentSegment: TransparentSegment;
  2686. }
  2687. }
  2688. declare module BABYLON {
  2689. class Rectangle2DRenderCache extends ModelRenderCache {
  2690. effectsReady: boolean;
  2691. fillVB: WebGLBuffer;
  2692. fillIB: WebGLBuffer;
  2693. fillIndicesCount: number;
  2694. instancingFillAttributes: InstancingAttributeInfo[];
  2695. effectFill: Effect;
  2696. effectFillInstanced: Effect;
  2697. borderVB: WebGLBuffer;
  2698. borderIB: WebGLBuffer;
  2699. borderIndicesCount: number;
  2700. instancingBorderAttributes: InstancingAttributeInfo[];
  2701. effectBorder: Effect;
  2702. effectBorderInstanced: Effect;
  2703. constructor(engine: Engine, modelKey: string);
  2704. render(instanceInfo: GroupInstanceInfo, context: Render2DContext): boolean;
  2705. dispose(): boolean;
  2706. }
  2707. class Rectangle2DInstanceData extends Shape2DInstanceData {
  2708. constructor(partId: number);
  2709. properties: Vector3;
  2710. }
  2711. class Rectangle2D extends Shape2D {
  2712. static actualSizeProperty: Prim2DPropInfo;
  2713. static notRoundedProperty: Prim2DPropInfo;
  2714. static roundRadiusProperty: Prim2DPropInfo;
  2715. actualSize: Size;
  2716. notRounded: boolean;
  2717. roundRadius: number;
  2718. private static _i0;
  2719. private static _i1;
  2720. private static _i2;
  2721. protected levelIntersect(intersectInfo: IntersectInfo2D): boolean;
  2722. protected updateLevelBoundingInfo(): void;
  2723. /**
  2724. * Create an Rectangle 2D Shape primitive. May be a sharp rectangle (with sharp corners), or a rounded one.
  2725. * @param settings a combination of settings, possible ones are
  2726. * - parent: the parent primitive/canvas, must be specified if the primitive is not constructed as a child of another one (i.e. as part of the children array setting)
  2727. * - children: an array of direct children
  2728. * - id a text identifier, for information purpose
  2729. * - position: the X & Y positions relative to its parent. Alternatively the x and y settings can be set. Default is [0;0]
  2730. * - rotation: the initial rotation (in radian) of the primitive. default is 0
  2731. * - scale: the initial scale of the primitive. default is 1. You can alternatively use scaleX &| scaleY to apply non uniform scale
  2732. * - dontInheritParentScale: if set the parent's scale won't be taken into consideration to compute the actualScale property
  2733. * - opacity: set the overall opacity of the primitive, 1 to be opaque (default), less than 1 to be transparent.
  2734. * - zOrder: override the zOrder with the specified value
  2735. * - origin: define the normalized origin point location, default [0.5;0.5]
  2736. * - size: the size of the group. Alternatively the width and height settings can be set. Default will be [10;10].
  2737. * - roundRadius: if the rectangle has rounded corner, set their radius, default is 0 (to get a sharp edges rectangle).
  2738. * - fill: the brush used to draw the fill content of the rectangle, you can set null to draw nothing (but you will have to set a border brush), default is a SolidColorBrush of plain white. can also be a string value (see Canvas2D.GetBrushFromString)
  2739. * - border: the brush used to draw the border of the rectangle, you can set null to draw nothing (but you will have to set a fill brush), default is null. can also be a string value (see Canvas2D.GetBrushFromString)
  2740. * - borderThickness: the thickness of the drawn border, default is 1.
  2741. * - isVisible: true if the primitive must be visible, false for hidden. Default is true.
  2742. * - isPickable: if true the Primitive can be used with interaction mode and will issue Pointer Event. If false it will be ignored for interaction/intersection test. Default value is true.
  2743. * - isContainer: if true the Primitive acts as a container for interaction, if the primitive is not pickable or doesn't intersection, no further test will be perform on its children. If set to false, children will always be considered for intersection/interaction. Default value is true.
  2744. * - childrenFlatZOrder: if true all the children (direct and indirect) will share the same Z-Order. Use this when there's a lot of children which don't overlap. The drawing order IS NOT GUARANTED!
  2745. * - marginTop: top margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  2746. * - marginLeft: left margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  2747. * - marginRight: right margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  2748. * - marginBottom: bottom margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  2749. * - margin: top, left, right and bottom margin formatted as a single string (see PrimitiveThickness.fromString)
  2750. * - marginHAlignment: one value of the PrimitiveAlignment type's static properties
  2751. * - marginVAlignment: one value of the PrimitiveAlignment type's static properties
  2752. * - marginAlignment: a string defining the alignment, see PrimitiveAlignment.fromString
  2753. * - paddingTop: top padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  2754. * - paddingLeft: left padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  2755. * - paddingRight: right padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  2756. * - paddingBottom: bottom padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  2757. * - padding: top, left, right and bottom padding formatted as a single string (see PrimitiveThickness.fromString)
  2758. */
  2759. constructor(settings?: {
  2760. parent?: Prim2DBase;
  2761. children?: Array<Prim2DBase>;
  2762. id?: string;
  2763. position?: Vector2;
  2764. x?: number;
  2765. y?: number;
  2766. rotation?: number;
  2767. scale?: number;
  2768. scaleX?: number;
  2769. scaleY?: number;
  2770. dontInheritParentScale?: boolean;
  2771. opacity?: number;
  2772. zOrder?: number;
  2773. origin?: Vector2;
  2774. size?: Size;
  2775. width?: number;
  2776. height?: number;
  2777. roundRadius?: number;
  2778. fill?: IBrush2D | string;
  2779. border?: IBrush2D | string;
  2780. borderThickness?: number;
  2781. isVisible?: boolean;
  2782. isPickable?: boolean;
  2783. isContainer?: boolean;
  2784. childrenFlatZOrder?: boolean;
  2785. marginTop?: number | string;
  2786. marginLeft?: number | string;
  2787. marginRight?: number | string;
  2788. marginBottom?: number | string;
  2789. margin?: number | string;
  2790. marginHAlignment?: number;
  2791. marginVAlignment?: number;
  2792. marginAlignment?: string;
  2793. paddingTop?: number | string;
  2794. paddingLeft?: number | string;
  2795. paddingRight?: number | string;
  2796. paddingBottom?: number | string;
  2797. padding?: string;
  2798. });
  2799. static roundSubdivisions: number;
  2800. protected createModelRenderCache(modelKey: string): ModelRenderCache;
  2801. protected setupModelRenderCache(modelRenderCache: ModelRenderCache): Rectangle2DRenderCache;
  2802. protected _getInitialContentAreaToRef(primSize: Size, initialContentPosition: Vector4, initialContentArea: Size): void;
  2803. protected _getActualSizeFromContentToRef(primSize: Size, newPrimSize: Size): void;
  2804. protected createInstanceDataParts(): InstanceDataBase[];
  2805. protected refreshInstanceDataPart(part: InstanceDataBase): boolean;
  2806. private _notRounded;
  2807. private _roundRadius;
  2808. }
  2809. }
  2810. declare module BABYLON {
  2811. class Ellipse2DRenderCache extends ModelRenderCache {
  2812. effectsReady: boolean;
  2813. fillVB: WebGLBuffer;
  2814. fillIB: WebGLBuffer;
  2815. fillIndicesCount: number;
  2816. instancingFillAttributes: InstancingAttributeInfo[];
  2817. effectFillInstanced: Effect;
  2818. effectFill: Effect;
  2819. borderVB: WebGLBuffer;
  2820. borderIB: WebGLBuffer;
  2821. borderIndicesCount: number;
  2822. instancingBorderAttributes: InstancingAttributeInfo[];
  2823. effectBorderInstanced: Effect;
  2824. effectBorder: Effect;
  2825. constructor(engine: Engine, modelKey: string);
  2826. render(instanceInfo: GroupInstanceInfo, context: Render2DContext): boolean;
  2827. dispose(): boolean;
  2828. }
  2829. class Ellipse2DInstanceData extends Shape2DInstanceData {
  2830. constructor(partId: number);
  2831. properties: Vector3;
  2832. }
  2833. class Ellipse2D extends Shape2D {
  2834. static acutalSizeProperty: Prim2DPropInfo;
  2835. static subdivisionsProperty: Prim2DPropInfo;
  2836. actualSize: Size;
  2837. subdivisions: number;
  2838. protected levelIntersect(intersectInfo: IntersectInfo2D): boolean;
  2839. protected updateLevelBoundingInfo(): void;
  2840. /**
  2841. * Create an Ellipse 2D Shape primitive
  2842. * @param settings a combination of settings, possible ones are
  2843. * - parent: the parent primitive/canvas, must be specified if the primitive is not constructed as a child of another one (i.e. as part of the children array setting)
  2844. * - children: an array of direct children
  2845. * - id: a text identifier, for information purpose
  2846. * - position: the X & Y positions relative to its parent. Alternatively the x and y properties can be set. Default is [0;0]
  2847. * - rotation: the initial rotation (in radian) of the primitive. default is 0
  2848. * - scale: the initial scale of the primitive. default is 1. You can alternatively use scaleX &| scaleY to apply non uniform scale
  2849. * - dontInheritParentScale: if set the parent's scale won't be taken into consideration to compute the actualScale property
  2850. * - opacity: set the overall opacity of the primitive, 1 to be opaque (default), less than 1 to be transparent.
  2851. * - zOrder: override the zOrder with the specified value
  2852. * - origin: define the normalized origin point location, default [0.5;0.5]
  2853. * - size: the size of the group. Alternatively the width and height properties can be set. Default will be [10;10].
  2854. * - subdivision: the number of subdivision to create the ellipse perimeter, default is 64.
  2855. * - fill: the brush used to draw the fill content of the ellipse, you can set null to draw nothing (but you will have to set a border brush), default is a SolidColorBrush of plain white. can also be a string value (see Canvas2D.GetBrushFromString)
  2856. * - border: the brush used to draw the border of the ellipse, you can set null to draw nothing (but you will have to set a fill brush), default is null. can be a string value (see Canvas2D.GetBrushFromString)
  2857. * - borderThickness: the thickness of the drawn border, default is 1.
  2858. * - isVisible: true if the group must be visible, false for hidden. Default is true.
  2859. * - isPickable: if true the Primitive can be used with interaction mode and will issue Pointer Event. If false it will be ignored for interaction/intersection test. Default value is true.
  2860. * - isContainer: if true the Primitive acts as a container for interaction, if the primitive is not pickable or doesn't intersection, no further test will be perform on its children. If set to false, children will always be considered for intersection/interaction. Default value is true.
  2861. * - childrenFlatZOrder: if true all the children (direct and indirect) will share the same Z-Order. Use this when there's a lot of children which don't overlap. The drawing order IS NOT GUARANTED!
  2862. * - marginTop: top margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  2863. * - marginLeft: left margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  2864. * - marginRight: right margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  2865. * - marginBottom: bottom margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  2866. * - margin: top, left, right and bottom margin formatted as a single string (see PrimitiveThickness.fromString)
  2867. * - marginHAlignment: one value of the PrimitiveAlignment type's static properties
  2868. * - marginVAlignment: one value of the PrimitiveAlignment type's static properties
  2869. * - marginAlignment: a string defining the alignment, see PrimitiveAlignment.fromString
  2870. * - paddingTop: top padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  2871. * - paddingLeft: left padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  2872. * - paddingRight: right padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  2873. * - paddingBottom: bottom padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  2874. * - padding: top, left, right and bottom padding formatted as a single string (see PrimitiveThickness.fromString)
  2875. */
  2876. constructor(settings?: {
  2877. parent?: Prim2DBase;
  2878. children?: Array<Prim2DBase>;
  2879. id?: string;
  2880. position?: Vector2;
  2881. x?: number;
  2882. y?: number;
  2883. rotation?: number;
  2884. scale?: number;
  2885. scaleX?: number;
  2886. scaleY?: number;
  2887. dontInheritParentScale?: boolean;
  2888. opacity?: number;
  2889. zOrder?: number;
  2890. origin?: Vector2;
  2891. size?: Size;
  2892. width?: number;
  2893. height?: number;
  2894. subdivisions?: number;
  2895. fill?: IBrush2D | string;
  2896. border?: IBrush2D | string;
  2897. borderThickness?: number;
  2898. isVisible?: boolean;
  2899. isPickable?: boolean;
  2900. isContainer?: boolean;
  2901. childrenFlatZOrder?: boolean;
  2902. marginTop?: number | string;
  2903. marginLeft?: number | string;
  2904. marginRight?: number | string;
  2905. marginBottom?: number | string;
  2906. margin?: number | string;
  2907. marginHAlignment?: number;
  2908. marginVAlignment?: number;
  2909. marginAlignment?: string;
  2910. paddingTop?: number | string;
  2911. paddingLeft?: number | string;
  2912. paddingRight?: number | string;
  2913. paddingBottom?: number | string;
  2914. padding?: string;
  2915. });
  2916. protected createModelRenderCache(modelKey: string): ModelRenderCache;
  2917. protected setupModelRenderCache(modelRenderCache: ModelRenderCache): Ellipse2DRenderCache;
  2918. protected createInstanceDataParts(): InstanceDataBase[];
  2919. protected refreshInstanceDataPart(part: InstanceDataBase): boolean;
  2920. private _subdivisions;
  2921. }
  2922. }
  2923. declare module BABYLON {
  2924. class Sprite2DRenderCache extends ModelRenderCache {
  2925. effectsReady: boolean;
  2926. vb: WebGLBuffer;
  2927. ib: WebGLBuffer;
  2928. instancingAttributes: InstancingAttributeInfo[];
  2929. texture: Texture;
  2930. effect: Effect;
  2931. effectInstanced: Effect;
  2932. render(instanceInfo: GroupInstanceInfo, context: Render2DContext): boolean;
  2933. dispose(): boolean;
  2934. }
  2935. class Sprite2D extends RenderablePrim2D {
  2936. static SPRITE2D_MAINPARTID: number;
  2937. static SHAPE2D_CATEGORY_SCALE9: string;
  2938. static textureProperty: Prim2DPropInfo;
  2939. static useAlphaFromTextureProperty: Prim2DPropInfo;
  2940. static actualSizeProperty: Prim2DPropInfo;
  2941. static spriteSizeProperty: Prim2DPropInfo;
  2942. static spriteLocationProperty: Prim2DPropInfo;
  2943. static spriteFrameProperty: Prim2DPropInfo;
  2944. static invertYProperty: Prim2DPropInfo;
  2945. static spriteScale9Property: Prim2DPropInfo;
  2946. texture: Texture;
  2947. useAlphaFromTexture: boolean;
  2948. size: Size;
  2949. actualSize: Size;
  2950. spriteSize: Size;
  2951. spriteLocation: Vector2;
  2952. spriteFrame: number;
  2953. invertY: boolean;
  2954. readonly isScale9: boolean;
  2955. /**
  2956. * Get/set if the sprite rendering should be aligned to the target rendering device pixel or not
  2957. */
  2958. alignToPixel: boolean;
  2959. protected updateLevelBoundingInfo(): void;
  2960. /**
  2961. * Get the animatable array (see http://doc.babylonjs.com/tutorials/Animations)
  2962. */
  2963. getAnimatables(): IAnimatable[];
  2964. protected levelIntersect(intersectInfo: IntersectInfo2D): boolean;
  2965. readonly isSizeAuto: boolean;
  2966. /**
  2967. * Create an 2D Sprite primitive
  2968. * @param texture the texture that stores the sprite to render
  2969. * @param settings a combination of settings, possible ones are
  2970. * - parent: the parent primitive/canvas, must be specified if the primitive is not constructed as a child of another one (i.e. as part of the children array setting)
  2971. * - children: an array of direct children
  2972. * - id a text identifier, for information purpose
  2973. * - position: the X & Y positions relative to its parent. Alternatively the x and y properties can be set. Default is [0;0]
  2974. * - rotation: the initial rotation (in radian) of the primitive. default is 0
  2975. * - scale: the initial scale of the primitive. default is 1. You can alternatively use scaleX &| scaleY to apply non uniform scale
  2976. * - size: the size of the sprite displayed in the canvas, if not specified the spriteSize will be used
  2977. * - dontInheritParentScale: if set the parent's scale won't be taken into consideration to compute the actualScale property
  2978. * - opacity: set the overall opacity of the primitive, 1 to be opaque (default), less than 1 to be transparent.
  2979. * - zOrder: override the zOrder with the specified value
  2980. * - origin: define the normalized origin point location, default [0.5;0.5]
  2981. * - spriteSize: the size of the sprite (in pixels) as it is stored in the texture, if null the size of the given texture will be used, default is null.
  2982. * - spriteLocation: the location (in pixels) in the texture of the top/left corner of the Sprite to display, default is null (0,0)
  2983. * - spriteScaleFactor: DEPRECATED. Old behavior: say you want to display a sprite twice as big as its bitmap which is 64,64, you set the spriteSize to 128,128 and have to set the spriteScaleFactory to 0.5,0.5 in order to address only the 64,64 pixels of the bitmaps. Default is 1,1.
  2984. * - scale9: draw the sprite as a Scale9 sprite, see http://yannickloriot.com/2013/03/9-patch-technique-in-cocos2d/ for more info. x, y, w, z are left, bottom, right, top coordinate of the resizable box
  2985. * - invertY: if true the texture Y will be inverted, default is false.
  2986. * - alignToPixel: if true the sprite's texels will be aligned to the rendering viewport pixels, ensuring the best rendering quality but slow animations won't be done as smooth as if you set false. If false a texel could lies between two pixels, being blended by the texture sampling mode you choose, the rendering result won't be as good, but very slow animation will be overall better looking. Default is true: content will be aligned.
  2987. * - isVisible: true if the sprite must be visible, false for hidden. Default is true.
  2988. * - isPickable: if true the Primitive can be used with interaction mode and will issue Pointer Event. If false it will be ignored for interaction/intersection test. Default value is true.
  2989. * - isContainer: if true the Primitive acts as a container for interaction, if the primitive is not pickable or doesn't intersection, no further test will be perform on its children. If set to false, children will always be considered for intersection/interaction. Default value is true.
  2990. * - childrenFlatZOrder: if true all the children (direct and indirect) will share the same Z-Order. Use this when there's a lot of children which don't overlap. The drawing order IS NOT GUARANTED!
  2991. * - marginTop: top margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  2992. * - marginLeft: left margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  2993. * - marginRight: right margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  2994. * - marginBottom: bottom margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  2995. * - margin: top, left, right and bottom margin formatted as a single string (see PrimitiveThickness.fromString)
  2996. * - marginHAlignment: one value of the PrimitiveAlignment type's static properties
  2997. * - marginVAlignment: one value of the PrimitiveAlignment type's static properties
  2998. * - marginAlignment: a string defining the alignment, see PrimitiveAlignment.fromString
  2999. * - paddingTop: top padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  3000. * - paddingLeft: left padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  3001. * - paddingRight: right padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  3002. * - paddingBottom: bottom padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  3003. * - padding: top, left, right and bottom padding formatted as a single string (see PrimitiveThickness.fromString)
  3004. */
  3005. constructor(texture: Texture, settings?: {
  3006. parent?: Prim2DBase;
  3007. children?: Array<Prim2DBase>;
  3008. id?: string;
  3009. position?: Vector2;
  3010. x?: number;
  3011. y?: number;
  3012. rotation?: number;
  3013. size?: Size;
  3014. scale?: number;
  3015. scaleX?: number;
  3016. scaleY?: number;
  3017. dontInheritParentScale?: boolean;
  3018. opacity?: number;
  3019. zOrder?: number;
  3020. origin?: Vector2;
  3021. spriteSize?: Size;
  3022. spriteLocation?: Vector2;
  3023. spriteScaleFactor?: Vector2;
  3024. scale9?: Vector4;
  3025. invertY?: boolean;
  3026. alignToPixel?: boolean;
  3027. isVisible?: boolean;
  3028. isPickable?: boolean;
  3029. isContainer?: boolean;
  3030. childrenFlatZOrder?: boolean;
  3031. marginTop?: number | string;
  3032. marginLeft?: number | string;
  3033. marginRight?: number | string;
  3034. marginBottom?: number | string;
  3035. margin?: number | string;
  3036. marginHAlignment?: number;
  3037. marginVAlignment?: number;
  3038. marginAlignment?: string;
  3039. paddingTop?: number | string;
  3040. paddingLeft?: number | string;
  3041. paddingRight?: number | string;
  3042. paddingBottom?: number | string;
  3043. padding?: string;
  3044. });
  3045. protected createModelRenderCache(modelKey: string): ModelRenderCache;
  3046. protected setupModelRenderCache(modelRenderCache: ModelRenderCache): Sprite2DRenderCache;
  3047. protected getUsedShaderCategories(dataPart: InstanceDataBase): string[];
  3048. protected createInstanceDataParts(): InstanceDataBase[];
  3049. private static _prop;
  3050. private static layoutConstructMode;
  3051. protected beforeRefreshForLayoutConstruction(part: InstanceDataBase): any;
  3052. protected afterRefreshForLayoutConstruction(part: InstanceDataBase, obj: any): void;
  3053. protected refreshInstanceDataPart(part: InstanceDataBase): boolean;
  3054. protected _mustUpdateInstance(): boolean;
  3055. protected _useTextureAlpha(): boolean;
  3056. protected _shouldUseAlphaFromTexture(): boolean;
  3057. private _updateSpriteScaleFactor();
  3058. private _texture;
  3059. private _oldTextureHasAlpha;
  3060. private _useAlphaFromTexture;
  3061. private _useSize;
  3062. private _spriteLocation;
  3063. private _spriteSize;
  3064. private _spriteFrame;
  3065. private _scale9;
  3066. private _invertY;
  3067. private _alignToPixel;
  3068. }
  3069. class Sprite2DInstanceData extends InstanceDataBase {
  3070. constructor(partId: number);
  3071. topLeftUV: Vector2;
  3072. sizeUV: Vector2;
  3073. scaleFactor: Vector2;
  3074. textureSize: Vector2;
  3075. properties: Vector3;
  3076. scale9: Vector4;
  3077. }
  3078. }
  3079. declare module BABYLON {
  3080. /**
  3081. * Interface to create your own Loader of Atlas Data file.
  3082. * Call the AtlasPictureInfoFactory.addLoader to addd your loader instance
  3083. */
  3084. interface IAtlasLoader {
  3085. loadFile(content: any): {
  3086. api: AtlasPictureInfo;
  3087. errorMsg: string;
  3088. errorCode: number;
  3089. };
  3090. }
  3091. /**
  3092. * This class will contains information about a sub picture present in an Atlas Picture.
  3093. */
  3094. class AtlasSubPictureInfo {
  3095. /**
  3096. * Name of the SubPicture, generally the filename of the initial picture file.
  3097. */
  3098. name: string;
  3099. /**
  3100. * Location of the bottom/left corner of the sub picture from the bottom/left corner the Atlas Picture
  3101. */
  3102. location: Vector2;
  3103. /**
  3104. * Size in pixel of the sub picture
  3105. */
  3106. size: Size;
  3107. }
  3108. /**
  3109. * This class represent an Atlas Picture, it contains the information of all the sub pictures and the Texture that stores the bitmap.
  3110. * You get an instance of this class using methods of the AtlasPictureInfoFactory
  3111. */
  3112. class AtlasPictureInfo {
  3113. /**
  3114. * Creates many sprite from the Atlas Picture
  3115. * @param filterCallback a predicate if true is returned then the corresponding sub picture will be used to create a sprite.
  3116. * The Predicate has many parameters:
  3117. * - index: just an index incremented at each sub picture submitted for Sprite creation
  3118. * - name: the sub picture's name
  3119. * - aspi: the AtlasSubPictureInfo corresponding to the submitted sub picture
  3120. * - settings: the Sprite2D creation settings, you can alter this JSON object but BEWARE, the alterations will be kept for subsequent Sprite2D creations!
  3121. * @param spriteSettings The Sprite2D settings to use for Sprite creation, this JSON object will be passed to the filterCallback for you to alter it, if needed.
  3122. */
  3123. createSprites(filterCallback: (index: number, name: string, aspi: AtlasSubPictureInfo, settings: any) => boolean, spriteSettings: {
  3124. parent?: Prim2DBase;
  3125. position?: Vector2;
  3126. x?: number;
  3127. y?: number;
  3128. rotation?: number;
  3129. size?: Size;
  3130. scale?: number;
  3131. scaleX?: number;
  3132. scaleY?: number;
  3133. dontInheritParentScale?: boolean;
  3134. opacity?: number;
  3135. zOrder?: number;
  3136. origin?: Vector2;
  3137. scale9?: Vector4;
  3138. invertY?: boolean;
  3139. alignToPixel?: boolean;
  3140. isVisible?: boolean;
  3141. isPickable?: boolean;
  3142. isContainer?: boolean;
  3143. childrenFlatZOrder?: boolean;
  3144. marginTop?: number | string;
  3145. marginLeft?: number | string;
  3146. marginRight?: number | string;
  3147. marginBottom?: number | string;
  3148. margin?: number | string;
  3149. marginHAlignment?: number;
  3150. marginVAlignment?: number;
  3151. marginAlignment?: string;
  3152. paddingTop?: number | string;
  3153. paddingLeft?: number | string;
  3154. paddingRight?: number | string;
  3155. paddingBottom?: number | string;
  3156. padding?: string;
  3157. }): Array<Sprite2D>;
  3158. /**
  3159. * Create one Sprite from a sub picture
  3160. * @param subPictureName the name of the sub picture to use
  3161. * @param spriteSettings the Sprite2D settings to use for the Sprite instance creation
  3162. */
  3163. createSprite(subPictureName: string, spriteSettings: {
  3164. parent?: Prim2DBase;
  3165. position?: Vector2;
  3166. x?: number;
  3167. y?: number;
  3168. rotation?: number;
  3169. size?: Size;
  3170. scale?: number;
  3171. scaleX?: number;
  3172. scaleY?: number;
  3173. dontInheritParentScale?: boolean;
  3174. opacity?: number;
  3175. zOrder?: number;
  3176. origin?: Vector2;
  3177. scale9?: Vector4;
  3178. invertY?: boolean;
  3179. alignToPixel?: boolean;
  3180. isVisible?: boolean;
  3181. isPickable?: boolean;
  3182. isContainer?: boolean;
  3183. childrenFlatZOrder?: boolean;
  3184. marginTop?: number | string;
  3185. marginLeft?: number | string;
  3186. marginRight?: number | string;
  3187. marginBottom?: number | string;
  3188. margin?: number | string;
  3189. marginHAlignment?: number;
  3190. marginVAlignment?: number;
  3191. marginAlignment?: string;
  3192. paddingTop?: number | string;
  3193. paddingLeft?: number | string;
  3194. paddingRight?: number | string;
  3195. paddingBottom?: number | string;
  3196. padding?: string;
  3197. }): Sprite2D;
  3198. /**
  3199. * Size of the Atlas Picture
  3200. */
  3201. atlasSize: Size;
  3202. /**
  3203. * String Dictionary of all the sub pictures, the key is the sub picture's name, the value is the info object
  3204. */
  3205. subPictures: StringDictionary<AtlasSubPictureInfo>;
  3206. /**
  3207. * The Texture associated to the Atlas Picture info
  3208. */
  3209. texture: Texture;
  3210. }
  3211. /**
  3212. * This if the Factory class containing static method to create Atlas Pictures Info objects or add new loaders
  3213. */
  3214. class AtlasPictureInfoFactory {
  3215. /**
  3216. * Add a custom loader
  3217. * @param fileExtension must be the file extension (without the dot) of the file that is loaded by this loader (e.g.: json)
  3218. * @param plugin the instance of the loader
  3219. */
  3220. static addLoader(fileExtension: string, plugin: IAtlasLoader): void;
  3221. /**
  3222. * Load an Atlas Picture Info object from a data file at a given url and with a given texture
  3223. * @param texture the texture containing the atlas bitmap
  3224. * @param url the URL of the Atlas Info data file
  3225. * @param onLoad a callback that will be called when the AtlasPictureInfo object will be loaded and ready
  3226. * @param onError a callback that will be called in case of error
  3227. */
  3228. static loadFromUrl(texture: Texture, url: string, onLoad: (api: AtlasPictureInfo) => void, onError?: (msg: string, code: number) => void): any;
  3229. private static plugins;
  3230. }
  3231. /**
  3232. * Use this decorator when you declare an Atlas Loader Class for the loader to register itself automatically.
  3233. * @param fileExtension the extension of the file that the plugin is loading (there can be many plugin for the same extension)
  3234. * @param plugin an instance of the plugin class to add to the AtlasPictureInfoFactory
  3235. */
  3236. function AtlasLoaderPlugin(fileExtension: string, plugin: IAtlasLoader): (target: Object) => void;
  3237. }
  3238. declare module BABYLON {
  3239. class Text2DRenderCache extends ModelRenderCache {
  3240. effectsReady: boolean;
  3241. vb: WebGLBuffer;
  3242. ib: WebGLBuffer;
  3243. instancingAttributes: InstancingAttributeInfo[];
  3244. fontTexture: BaseFontTexture;
  3245. effect: Effect;
  3246. effectInstanced: Effect;
  3247. render(instanceInfo: GroupInstanceInfo, context: Render2DContext): boolean;
  3248. dispose(): boolean;
  3249. }
  3250. class Text2DInstanceData extends InstanceDataBase {
  3251. constructor(partId: number, dataElementCount: number);
  3252. topLeftUV: Vector2;
  3253. sizeUV: Vector2;
  3254. textureSize: Vector2;
  3255. color: Color4;
  3256. superSampleFactor: number;
  3257. }
  3258. class Text2D extends RenderablePrim2D {
  3259. static TEXT2D_MAINPARTID: number;
  3260. static TEXT2D_CATEGORY_SDF: string;
  3261. static fontProperty: Prim2DPropInfo;
  3262. static defaultFontColorProperty: Prim2DPropInfo;
  3263. static textProperty: Prim2DPropInfo;
  3264. static sizeProperty: Prim2DPropInfo;
  3265. static fontSuperSampleProperty: Prim2DPropInfo;
  3266. static fontSignedDistanceFieldProperty: Prim2DPropInfo;
  3267. fontName: string;
  3268. defaultFontColor: Color4;
  3269. text: string;
  3270. size: Size;
  3271. readonly fontSuperSample: boolean;
  3272. readonly fontSignedDistanceField: boolean;
  3273. readonly isSizeAuto: boolean;
  3274. /**
  3275. * Get the actual size of the Text2D primitive
  3276. */
  3277. readonly actualSize: Size;
  3278. /**
  3279. * Get the area that bounds the text associated to the primitive
  3280. */
  3281. readonly textSize: Size;
  3282. protected readonly fontTexture: BaseFontTexture;
  3283. /**
  3284. * Dispose the primitive, remove it from its parent
  3285. */
  3286. dispose(): boolean;
  3287. protected updateLevelBoundingInfo(): void;
  3288. /**
  3289. * Create a Text primitive
  3290. * @param text the text to display
  3291. * @param settings a combination of settings, possible ones are
  3292. * - parent: the parent primitive/canvas, must be specified if the primitive is not constructed as a child of another one (i.e. as part of the children array setting)
  3293. * - children: an array of direct children
  3294. * - id a text identifier, for information purpose
  3295. * - position: the X & Y positions relative to its parent. Alternatively the x and y properties can be set. Default is [0;0]
  3296. * - rotation: the initial rotation (in radian) of the primitive. default is 0
  3297. * - scale: the initial scale of the primitive. default is 1. You can alternatively use scaleX &| scaleY to apply non uniform scale
  3298. * - dontInheritParentScale: if set the parent's scale won't be taken into consideration to compute the actualScale property
  3299. * - opacity: set the overall opacity of the primitive, 1 to be opaque (default), less than 1 to be transparent.
  3300. * - zOrder: override the zOrder with the specified value
  3301. * - origin: define the normalized origin point location, default [0.5;0.5]
  3302. * - fontName: the name/size/style of the font to use, following the CSS notation. Default is "12pt Arial".
  3303. * - fontSuperSample: if true the text will be rendered with a superSampled font (the font is twice the given size). Use this settings if the text lies in world space or if it's scaled in.
  3304. * - signedDistanceField: if true the text will be rendered using the SignedDistanceField technique. This technique has the advantage to be rendered order independent (then much less drawing calls), but only works on font that are a little more than one pixel wide on the screen but the rendering quality is excellent whatever the font size is on the screen (which is the purpose of this technique). Outlining/Shadow is not supported right now. If you can, you should use this mode, the quality and the performances are the best. Note that fontSuperSample has no effect when this mode is on.
  3305. * - defaultFontColor: the color by default to apply on each letter of the text to display, default is plain white.
  3306. * - areaSize: the size of the area in which to display the text, default is auto-fit from text content.
  3307. * - tabulationSize: number of space character to insert when a tabulation is encountered, default is 4
  3308. * - isVisible: true if the text must be visible, false for hidden. Default is true.
  3309. * - isPickable: if true the Primitive can be used with interaction mode and will issue Pointer Event. If false it will be ignored for interaction/intersection test. Default value is true.
  3310. * - isContainer: if true the Primitive acts as a container for interaction, if the primitive is not pickable or doesn't intersection, no further test will be perform on its children. If set to false, children will always be considered for intersection/interaction. Default value is true.
  3311. * - childrenFlatZOrder: if true all the children (direct and indirect) will share the same Z-Order. Use this when there's a lot of children which don't overlap. The drawing order IS NOT GUARANTED!
  3312. * - marginTop: top margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  3313. * - marginLeft: left margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  3314. * - marginRight: right margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  3315. * - marginBottom: bottom margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  3316. * - margin: top, left, right and bottom margin formatted as a single string (see PrimitiveThickness.fromString)
  3317. * - marginHAlignment: one value of the PrimitiveAlignment type's static properties
  3318. * - marginVAlignment: one value of the PrimitiveAlignment type's static properties
  3319. * - marginAlignment: a string defining the alignment, see PrimitiveAlignment.fromString
  3320. * - paddingTop: top padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  3321. * - paddingLeft: left padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  3322. * - paddingRight: right padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  3323. * - paddingBottom: bottom padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  3324. * - padding: top, left, right and bottom padding formatted as a single string (see PrimitiveThickness.fromString)
  3325. */
  3326. constructor(text: string, settings?: {
  3327. parent?: Prim2DBase;
  3328. children?: Array<Prim2DBase>;
  3329. id?: string;
  3330. position?: Vector2;
  3331. x?: number;
  3332. y?: number;
  3333. rotation?: number;
  3334. scale?: number;
  3335. scaleX?: number;
  3336. scaleY?: number;
  3337. dontInheritParentScale?: boolean;
  3338. opacity?: number;
  3339. zOrder?: number;
  3340. origin?: Vector2;
  3341. fontName?: string;
  3342. fontSuperSample?: boolean;
  3343. fontSignedDistanceField?: boolean;
  3344. bitmapFontTexture?: BitmapFontTexture;
  3345. defaultFontColor?: Color4;
  3346. size?: Size;
  3347. tabulationSize?: number;
  3348. isVisible?: boolean;
  3349. isPickable?: boolean;
  3350. isContainer?: boolean;
  3351. childrenFlatZOrder?: boolean;
  3352. marginTop?: number | string;
  3353. marginLeft?: number | string;
  3354. marginRight?: number | string;
  3355. marginBottom?: number | string;
  3356. margin?: number | string;
  3357. marginHAlignment?: number;
  3358. marginVAlignment?: number;
  3359. marginAlignment?: string;
  3360. paddingTop?: number | string;
  3361. paddingLeft?: number | string;
  3362. paddingRight?: number | string;
  3363. paddingBottom?: number | string;
  3364. padding?: string;
  3365. });
  3366. protected levelIntersect(intersectInfo: IntersectInfo2D): boolean;
  3367. protected createModelRenderCache(modelKey: string): ModelRenderCache;
  3368. protected setupModelRenderCache(modelRenderCache: ModelRenderCache): Text2DRenderCache;
  3369. protected createInstanceDataParts(): InstanceDataBase[];
  3370. protected beforeRefreshForLayoutConstruction(part: InstanceDataBase): any;
  3371. protected afterRefreshForLayoutConstruction(part: InstanceDataBase, obj: any): void;
  3372. protected getUsedShaderCategories(dataPart: InstanceDataBase): string[];
  3373. protected refreshInstanceDataPart(part: InstanceDataBase): boolean;
  3374. private _updateCharCount();
  3375. protected _useTextureAlpha(): boolean;
  3376. protected _shouldUseAlphaFromTexture(): boolean;
  3377. private _fontTexture;
  3378. private _tabulationSize;
  3379. private _charCount;
  3380. private _fontName;
  3381. private _fontSuperSample;
  3382. private _fontSDF;
  3383. private _defaultFontColor;
  3384. private _text;
  3385. private _textSize;
  3386. }
  3387. }
  3388. declare module BABYLON {
  3389. class Lines2DRenderCache extends ModelRenderCache {
  3390. effectsReady: boolean;
  3391. fillVB: WebGLBuffer;
  3392. fillIB: WebGLBuffer;
  3393. fillIndicesCount: number;
  3394. instancingFillAttributes: InstancingAttributeInfo[];
  3395. effectFill: Effect;
  3396. effectFillInstanced: Effect;
  3397. borderVB: WebGLBuffer;
  3398. borderIB: WebGLBuffer;
  3399. borderIndicesCount: number;
  3400. instancingBorderAttributes: InstancingAttributeInfo[];
  3401. effectBorder: Effect;
  3402. effectBorderInstanced: Effect;
  3403. constructor(engine: Engine, modelKey: string);
  3404. render(instanceInfo: GroupInstanceInfo, context: Render2DContext): boolean;
  3405. dispose(): boolean;
  3406. }
  3407. class Lines2DInstanceData extends Shape2DInstanceData {
  3408. constructor(partId: number);
  3409. boundingMin: Vector2;
  3410. boundingMax: Vector2;
  3411. }
  3412. class Lines2D extends Shape2D {
  3413. /**
  3414. * No Cap to apply on the extremity
  3415. */
  3416. static readonly NoCap: number;
  3417. /**
  3418. * A round cap, will use the line thickness as diameter
  3419. */
  3420. static readonly RoundCap: number;
  3421. /**
  3422. * Creates a triangle at the extremity.
  3423. */
  3424. static readonly TriangleCap: number;
  3425. /**
  3426. * Creates a Square anchor at the extremity, the square size is twice the thickness of the line
  3427. */
  3428. static readonly SquareAnchorCap: number;
  3429. /**
  3430. * Creates a round anchor at the extremity, the diameter is twice the thickness of the line
  3431. */
  3432. static readonly RoundAnchorCap: number;
  3433. /**
  3434. * Creates a diamond anchor at the extremity.
  3435. */
  3436. static readonly DiamondAnchorCap: number;
  3437. /**
  3438. * Creates an arrow anchor at the extremity. the arrow base size is twice the thickness of the line
  3439. */
  3440. static readonly ArrowCap: number;
  3441. static pointsProperty: Prim2DPropInfo;
  3442. static fillThicknessProperty: Prim2DPropInfo;
  3443. static closedProperty: Prim2DPropInfo;
  3444. static startCapProperty: Prim2DPropInfo;
  3445. static endCapProperty: Prim2DPropInfo;
  3446. points: Vector2[];
  3447. fillThickness: number;
  3448. closed: boolean;
  3449. startCap: number;
  3450. endCap: number;
  3451. private static _prevA;
  3452. private static _prevB;
  3453. private static _curA;
  3454. private static _curB;
  3455. protected levelIntersect(intersectInfo: IntersectInfo2D): boolean;
  3456. protected readonly boundingMin: Vector2;
  3457. protected readonly boundingMax: Vector2;
  3458. protected getUsedShaderCategories(dataPart: InstanceDataBase): string[];
  3459. protected updateLevelBoundingInfo(): void;
  3460. /**
  3461. * Create an 2D Lines Shape primitive. The defined lines may be opened or closed (see below)
  3462. * @param points an array that describe the points to use to draw the line, must contain at least two entries.
  3463. * @param settings a combination of settings, possible ones are
  3464. * - parent: the parent primitive/canvas, must be specified if the primitive is not constructed as a child of another one (i.e. as part of the children array setting)
  3465. * - children: an array of direct children
  3466. * - id a text identifier, for information purpose
  3467. * - position: the X & Y positions relative to its parent. Alternatively the x and y properties can be set. Default is [0;0]
  3468. * - rotation: the initial rotation (in radian) of the primitive. default is 0
  3469. * - scale: the initial scale of the primitive. default is 1. You can alternatively use scaleX &| scaleY to apply non uniform scale
  3470. * - dontInheritParentScale: if set the parent's scale won't be taken into consideration to compute the actualScale property
  3471. * - opacity: set the overall opacity of the primitive, 1 to be opaque (default), less than 1 to be transparent.
  3472. * - zOrder: override the zOrder with the specified value
  3473. * - origin: define the normalized origin point location, default [0.5;0.5]
  3474. * - fillThickness: the thickness of the fill part of the line, can be null to draw nothing (but a border brush must be given), default is 1.
  3475. * - closed: if false the lines are said to be opened, the first point and the latest DON'T connect. if true the lines are said to be closed, the first and last point will be connected by a line. For instance you can define the 4 points of a rectangle, if you set closed to true a 4 edges rectangle will be drawn. If you set false, only three edges will be drawn, the edge formed by the first and last point won't exist. Default is false.
  3476. * - startCap: Draw a cap of the given type at the start of the first line, you can't define a Cap if the Lines2D is closed. Default is Lines2D.NoCap.
  3477. * - endCap: Draw a cap of the given type at the end of the last line, you can't define a Cap if the Lines2D is closed. Default is Lines2D.NoCap.
  3478. * - fill: the brush used to draw the fill content of the lines, you can set null to draw nothing (but you will have to set a border brush), default is a SolidColorBrush of plain white. can be a string value (see Canvas2D.GetBrushFromString)
  3479. * - border: the brush used to draw the border of the lines, you can set null to draw nothing (but you will have to set a fill brush), default is null. can be a string value (see Canvas2D.GetBrushFromString)
  3480. * - borderThickness: the thickness of the drawn border, default is 1.
  3481. * - isVisible: true if the primitive must be visible, false for hidden. Default is true.
  3482. * - isPickable: if true the Primitive can be used with interaction mode and will issue Pointer Event. If false it will be ignored for interaction/intersection test. Default value is true.
  3483. * - isContainer: if true the Primitive acts as a container for interaction, if the primitive is not pickable or doesn't intersection, no further test will be perform on its children. If set to false, children will always be considered for intersection/interaction. Default value is true.
  3484. * - childrenFlatZOrder: if true all the children (direct and indirect) will share the same Z-Order. Use this when there's a lot of children which don't overlap. The drawing order IS NOT GUARANTED!
  3485. * - marginTop: top margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  3486. * - marginLeft: left margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  3487. * - marginRight: right margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  3488. * - marginBottom: bottom margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  3489. * - margin: top, left, right and bottom margin formatted as a single string (see PrimitiveThickness.fromString)
  3490. * - marginHAlignment: one value of the PrimitiveAlignment type's static properties
  3491. * - marginVAlignment: one value of the PrimitiveAlignment type's static properties
  3492. * - marginAlignment: a string defining the alignment, see PrimitiveAlignment.fromString
  3493. * - paddingTop: top padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  3494. * - paddingLeft: left padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  3495. * - paddingRight: right padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  3496. * - paddingBottom: bottom padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  3497. * - padding: top, left, right and bottom padding formatted as a single string (see PrimitiveThickness.fromString)
  3498. */
  3499. constructor(points: Vector2[], settings?: {
  3500. parent?: Prim2DBase;
  3501. children?: Array<Prim2DBase>;
  3502. id?: string;
  3503. position?: Vector2;
  3504. x?: number;
  3505. y?: number;
  3506. rotation?: number;
  3507. scale?: number;
  3508. scaleX?: number;
  3509. scaleY?: number;
  3510. dontInheritParentScale?: boolean;
  3511. opacity?: number;
  3512. zOrder?: number;
  3513. origin?: Vector2;
  3514. fillThickness?: number;
  3515. closed?: boolean;
  3516. startCap?: number;
  3517. endCap?: number;
  3518. fill?: IBrush2D | string;
  3519. border?: IBrush2D | string;
  3520. borderThickness?: number;
  3521. isVisible?: boolean;
  3522. isPickable?: boolean;
  3523. isContainer?: boolean;
  3524. childrenFlatZOrder?: boolean;
  3525. marginTop?: number | string;
  3526. marginLeft?: number | string;
  3527. marginRight?: number | string;
  3528. marginBottom?: number | string;
  3529. margin?: number | string;
  3530. marginHAlignment?: number;
  3531. marginVAlignment?: number;
  3532. marginAlignment?: string;
  3533. paddingTop?: number | string;
  3534. paddingLeft?: number | string;
  3535. paddingRight?: number | string;
  3536. paddingBottom?: number | string;
  3537. padding?: string;
  3538. });
  3539. protected createModelRenderCache(modelKey: string): ModelRenderCache;
  3540. private _perp(v, res);
  3541. private _direction(a, b, res);
  3542. private static _miterTps;
  3543. private _computeMiter(tangent, miter, a, b);
  3544. private _intersect(x1, y1, x2, y2, x3, y3, x4, y4);
  3545. private _updateMinMax(array, offset);
  3546. private static _startDir;
  3547. private static _endDir;
  3548. private _store(array, contour, index, max, p, n, halfThickness, borderThickness, detectFlip?);
  3549. private _getCapSize(type, border?);
  3550. private static _tpsV;
  3551. private _storeVertex(vb, baseOffset, index, basePos, rotation, vertex, contour);
  3552. private _storeIndex(ib, baseOffset, index, vertexIndex);
  3553. private _buildCap(vb, vbi, ib, ibi, pos, thickness, borderThickness, type, capDir, contour);
  3554. private _buildLine(vb, contour, ht, bt?);
  3555. protected setupModelRenderCache(modelRenderCache: ModelRenderCache): Lines2DRenderCache;
  3556. private _computeLines2D();
  3557. readonly size: Size;
  3558. protected createInstanceDataParts(): InstanceDataBase[];
  3559. protected applyActualScaleOnTransform(): boolean;
  3560. protected refreshInstanceDataPart(part: InstanceDataBase): boolean;
  3561. private static _noCap;
  3562. private static _roundCap;
  3563. private static _triangleCap;
  3564. private static _squareAnchorCap;
  3565. private static _roundAnchorCap;
  3566. private static _diamondAnchorCap;
  3567. private static _arrowCap;
  3568. private static _roundCapSubDiv;
  3569. private _fillVB;
  3570. private _fillIB;
  3571. private _borderVB;
  3572. private _borderIB;
  3573. private _boundingMin;
  3574. private _boundingMax;
  3575. private _contour;
  3576. private _startCapContour;
  3577. private _startCapTriIndices;
  3578. private _endCapContour;
  3579. private _endCapTriIndices;
  3580. private _closed;
  3581. private _startCap;
  3582. private _endCap;
  3583. private _fillThickness;
  3584. private _points;
  3585. }
  3586. }
  3587. declare module BABYLON {
  3588. class Canvas2DEngineBoundData {
  3589. GetOrAddModelCache<TInstData>(key: string, factory: (key: string) => ModelRenderCache): ModelRenderCache;
  3590. private _modelCache;
  3591. DisposeModelRenderCache(modelRenderCache: ModelRenderCache): boolean;
  3592. }
  3593. abstract class Canvas2D extends Group2D {
  3594. /**
  3595. * In this strategy only the direct children groups of the Canvas will be cached, their whole content (whatever the sub groups they have) into a single bitmap.
  3596. * This strategy doesn't allow primitives added directly as children of the Canvas.
  3597. * You typically want to use this strategy of a screenSpace fullscreen canvas: you don't want a bitmap cache taking the whole screen resolution but still want the main contents (say UI in the topLeft and rightBottom for instance) to be efficiently cached.
  3598. */
  3599. static CACHESTRATEGY_TOPLEVELGROUPS: number;
  3600. /**
  3601. * In this strategy each group will have its own cache bitmap (except if a given group explicitly defines the DONTCACHEOVERRIDE or CACHEINPARENTGROUP behaviors).
  3602. * This strategy is typically used if the canvas has some groups that are frequently animated. Unchanged ones will have a steady cache and the others will be refreshed when they change, reducing the redraw operation count to their content only.
  3603. * When using this strategy, group instances can rely on the DONTCACHEOVERRIDE or CACHEINPARENTGROUP behaviors to minimize the amount of cached bitmaps.
  3604. * Note that in this mode the Canvas itself is not cached, it only contains the sprites of its direct children group to render, there's no point to cache the whole canvas, sprites will be rendered pretty efficiently, the memory cost would be too great for the value of it.
  3605. */
  3606. static CACHESTRATEGY_ALLGROUPS: number;
  3607. /**
  3608. * In this strategy the whole canvas is cached into a single bitmap containing every primitives it owns, at the exception of the ones that are owned by a group having the DONTCACHEOVERRIDE behavior (these primitives will be directly drawn to the viewport at each render for screenSpace Canvas or be part of the Canvas cache bitmap for worldSpace Canvas).
  3609. */
  3610. static CACHESTRATEGY_CANVAS: number;
  3611. /**
  3612. * This strategy is used to recompose/redraw the canvas entirely at each viewport render.
  3613. * Use this strategy if memory is a concern above rendering performances and/or if the canvas is frequently animated (hence reducing the benefits of caching).
  3614. * Note that you can't use this strategy for WorldSpace Canvas, they need at least a top level group caching.
  3615. */
  3616. static CACHESTRATEGY_DONTCACHE: number;
  3617. /**
  3618. * Observable Mask to be notified before rendering is made
  3619. */
  3620. static RENDEROBSERVABLE_PRE: number;
  3621. /**
  3622. * Observable Mask to be notified after rendering is made
  3623. */
  3624. static RENDEROBSERVABLE_POST: number;
  3625. private static _INSTANCES;
  3626. constructor(scene: Scene, settings?: {
  3627. id?: string;
  3628. children?: Array<Prim2DBase>;
  3629. size?: Size;
  3630. renderingPhase?: {
  3631. camera: Camera;
  3632. renderingGroupID: number;
  3633. };
  3634. designSize?: Size;
  3635. designUseHorizAxis?: boolean;
  3636. isScreenSpace?: boolean;
  3637. cachingStrategy?: number;
  3638. enableInteraction?: boolean;
  3639. origin?: Vector2;
  3640. isVisible?: boolean;
  3641. backgroundRoundRadius?: number;
  3642. backgroundFill?: IBrush2D | string;
  3643. backgroundBorder?: IBrush2D | string;
  3644. backgroundBorderThickNess?: number;
  3645. });
  3646. readonly drawCallsOpaqueCounter: PerfCounter;
  3647. readonly drawCallsAlphaTestCounter: PerfCounter;
  3648. readonly drawCallsTransparentCounter: PerfCounter;
  3649. readonly groupRenderCounter: PerfCounter;
  3650. readonly updateTransparentDataCounter: PerfCounter;
  3651. readonly cachedGroupRenderCounter: PerfCounter;
  3652. readonly updateCachedStateCounter: PerfCounter;
  3653. readonly updateLayoutCounter: PerfCounter;
  3654. readonly updatePositioningCounter: PerfCounter;
  3655. readonly updateLocalTransformCounter: PerfCounter;
  3656. readonly updateGlobalTransformCounter: PerfCounter;
  3657. readonly boundingInfoRecomputeCounter: PerfCounter;
  3658. static readonly instances: Array<Canvas2D>;
  3659. protected _canvasPreInit(settings: any): void;
  3660. static _zMinDelta: number;
  3661. private _setupInteraction(enable);
  3662. /**
  3663. * If you set your own WorldSpaceNode to display the Canvas2D you have to provide your own implementation of this method which computes the local position in the Canvas based on the given 3D World one.
  3664. * Beware that you have to take under consideration the origin in your calculations! Good luck!
  3665. */
  3666. worldSpaceToNodeLocal: (worldPos: Vector3) => Vector2;
  3667. /**
  3668. * If you use a custom WorldSpaceCanvasNode you have to override this property to update the UV of your object to reflect the changes due to a resizing of the cached bitmap
  3669. */
  3670. worldSpaceCacheChanged: () => void;
  3671. /**
  3672. * Internal method, you should use the Prim2DBase version instead
  3673. */
  3674. _setPointerCapture(pointerId: number, primitive: Prim2DBase): boolean;
  3675. /**
  3676. * Internal method, you should use the Prim2DBase version instead
  3677. */
  3678. _releasePointerCapture(pointerId: number, primitive: Prim2DBase): boolean;
  3679. /**
  3680. * Determine if the given pointer is captured or not
  3681. * @param pointerId the Id of the pointer
  3682. * @return true if it's captured, false otherwise
  3683. */
  3684. isPointerCaptured(pointerId: number): boolean;
  3685. private getCapturedPrimitive(pointerId);
  3686. private static _interInfo;
  3687. private _handlePointerEventForInteraction(eventData, localPosition, eventState);
  3688. private _updatePointerInfo(eventData, localPosition);
  3689. private _updateIntersectionList(mouseLocalPos, isCapture, force);
  3690. private _updateOverStatus(force);
  3691. private _updatePrimPointerPos(prim);
  3692. private _notifDebugMode;
  3693. private _debugExecObserver(prim, mask);
  3694. private _bubbleNotifyPrimPointerObserver(prim, mask, eventData);
  3695. private _triggerActionManager(prim, ppi, mask, eventData);
  3696. /**
  3697. * Don't forget to call the dispose method when you're done with the Canvas instance.
  3698. * But don't worry, if you dispose its scene, the canvas will be automatically disposed too.
  3699. */
  3700. dispose(): boolean;
  3701. /**
  3702. * Accessor to the Scene that owns the Canvas
  3703. * @returns The instance of the Scene object
  3704. */
  3705. readonly scene: Scene;
  3706. /**
  3707. * Accessor to the Engine that drives the Scene used by this Canvas
  3708. * @returns The instance of the Engine object
  3709. */
  3710. readonly engine: Engine;
  3711. /**
  3712. * return a unique identifier for the Canvas2D
  3713. */
  3714. readonly uid: string;
  3715. /**
  3716. * And observable called during the Canvas rendering process.
  3717. * This observable is called twice per render, each time with a different mask:
  3718. * - 1: before render is executed
  3719. * - 2: after render is executed
  3720. */
  3721. readonly renderObservable: Observable<Canvas2D>;
  3722. /**
  3723. * Accessor of the Caching Strategy used by this Canvas.
  3724. * See Canvas2D.CACHESTRATEGY_xxxx static members for more information
  3725. * @returns the value corresponding to the used strategy.
  3726. */
  3727. readonly cachingStrategy: number;
  3728. /**
  3729. * Return true if the Canvas is a Screen Space one, false if it's a World Space one.
  3730. * @returns {}
  3731. */
  3732. readonly isScreenSpace: boolean;
  3733. /**
  3734. * Only valid for World Space Canvas, returns the scene node that displays the canvas
  3735. */
  3736. worldSpaceCanvasNode: Node;
  3737. /**
  3738. * Check if the WebGL Instanced Array extension is supported or not
  3739. */
  3740. readonly supportInstancedArray: boolean;
  3741. /**
  3742. * Property that defines the fill object used to draw the background of the Canvas.
  3743. * Note that Canvas with a Caching Strategy of
  3744. * @returns If the background is not set, null will be returned, otherwise a valid fill object is returned.
  3745. */
  3746. backgroundFill: IBrush2D;
  3747. /**
  3748. * Property that defines the border object used to draw the background of the Canvas.
  3749. * @returns If the background is not set, null will be returned, otherwise a valid border object is returned.
  3750. */
  3751. backgroundBorder: IBrush2D;
  3752. /**
  3753. * Property that defines the thickness of the border object used to draw the background of the Canvas.
  3754. * @returns If the background is not set, null will be returned, otherwise a valid number matching the thickness is returned.
  3755. */
  3756. backgroundBorderThickness: number;
  3757. /**
  3758. * You can set the roundRadius of the background
  3759. * @returns The current roundRadius
  3760. */
  3761. backgroundRoundRadius: number;
  3762. /**
  3763. * Enable/Disable interaction for this Canvas
  3764. * When enabled the Prim2DBase.pointerEventObservable property will notified when appropriate events occur
  3765. */
  3766. interactionEnabled: boolean;
  3767. readonly fitRenderingDevice: boolean;
  3768. readonly designSize: Size;
  3769. readonly designSizeUseHorizAxis: boolean;
  3770. /**
  3771. * Return
  3772. */
  3773. readonly overPrim: Prim2DBase;
  3774. /**
  3775. * Access the babylon.js' engine bound data, do not invoke this method, it's for internal purpose only
  3776. * @returns {}
  3777. */
  3778. readonly _engineData: Canvas2DEngineBoundData;
  3779. createCanvasProfileInfoCanvas(): Canvas2D;
  3780. /**
  3781. * Instanced Array will be create if there's at least this number of parts/prim that can fit into it
  3782. */
  3783. minPartCountToUseInstancedArray: number;
  3784. private checkBackgroundAvailability();
  3785. private _initPerfMetrics();
  3786. private _fetchPerfMetrics();
  3787. private _updateProfileCanvas();
  3788. _addDrawCallCount(count: number, renderMode: number): void;
  3789. _addGroupRenderCount(count: number): void;
  3790. _addUpdateTransparentDataCount(count: number): void;
  3791. addCachedGroupRenderCounter(count: number): void;
  3792. addUpdateCachedStateCounter(count: number): void;
  3793. addUpdateLayoutCounter(count: number): void;
  3794. addUpdatePositioningCounter(count: number): void;
  3795. addupdateLocalTransformCounter(count: number): void;
  3796. addUpdateGlobalTransformCounter(count: number): void;
  3797. private _uid;
  3798. private _renderObservable;
  3799. private __engineData;
  3800. private _interactionEnabled;
  3801. private _primPointerInfo;
  3802. private _updateRenderId;
  3803. private _intersectionRenderId;
  3804. private _hoverStatusRenderId;
  3805. private _pickStartingPosition;
  3806. private _pickedDownPrim;
  3807. private _pickStartingTime;
  3808. private _previousIntersectionList;
  3809. private _actualIntersectionList;
  3810. private _previousOverPrimitive;
  3811. private _actualOverPrimitive;
  3812. private _capturedPointers;
  3813. private _scenePrePointerObserver;
  3814. private _scenePointerObserver;
  3815. protected _worldSpaceNode: Node;
  3816. private _mapCounter;
  3817. private _background;
  3818. private _scene;
  3819. private _engine;
  3820. private _fitRenderingDevice;
  3821. private _isScreenSpace;
  3822. private _cachedCanvasGroup;
  3823. private _cachingStrategy;
  3824. private _hierarchyLevelMaxSiblingCount;
  3825. private _groupCacheMaps;
  3826. private _renderingGroupObserver;
  3827. private _beforeRenderObserver;
  3828. private _afterRenderObserver;
  3829. private _supprtInstancedArray;
  3830. private _trackedGroups;
  3831. protected _maxAdaptiveWorldSpaceCanvasSize: number;
  3832. private _designSize;
  3833. private _designUseHorizAxis;
  3834. _renderingSize: Size;
  3835. private _drawCallsOpaqueCounter;
  3836. private _drawCallsAlphaTestCounter;
  3837. private _drawCallsTransparentCounter;
  3838. private _groupRenderCounter;
  3839. private _updateTransparentDataCounter;
  3840. private _cachedGroupRenderCounter;
  3841. private _updateCachedStateCounter;
  3842. private _updateLayoutCounter;
  3843. private _updatePositioningCounter;
  3844. private _updateGlobalTransformCounter;
  3845. private _updateLocalTransformCounter;
  3846. private _boundingInfoRecomputeCounter;
  3847. private _profilingCanvas;
  3848. private _profileInfoText;
  3849. private static _v;
  3850. private static _m;
  3851. private static _mI;
  3852. private _updateTrackedNodes();
  3853. /**
  3854. * Call this method change you want to have layout related data computed and up to date (layout area, primitive area, local/global transformation matrices)
  3855. */
  3856. updateCanvasLayout(forceRecompute: boolean): void;
  3857. private _updateAdaptiveSizeWorldCanvas();
  3858. private _updateCanvasState(forceRecompute);
  3859. /**
  3860. * Method that renders the Canvas, you should not invoke
  3861. */
  3862. private _render();
  3863. /**
  3864. * Internal method that allocate a cache for the given group.
  3865. * Caching is made using a collection of MapTexture where many groups have their bitmap cache stored inside.
  3866. * @param group The group to allocate the cache of.
  3867. * @return custom type with the PackedRect instance giving information about the cache location into the texture and also the MapTexture instance that stores the cache.
  3868. */
  3869. _allocateGroupCache(group: Group2D, parent: Group2D, minSize?: Size, useMipMap?: boolean, anisotropicLevel?: number): {
  3870. node: PackedRect;
  3871. texture: MapTexture;
  3872. sprite: Sprite2D;
  3873. };
  3874. /**
  3875. * Define the default size used for both the width and height of a MapTexture to allocate.
  3876. * Note that some MapTexture might be bigger than this size if the first node to allocate is bigger in width or height
  3877. */
  3878. private static _groupTextureCacheSize;
  3879. /**
  3880. * Internal method used to register a Scene Node to track position for the given group
  3881. * Do not invoke this method, for internal purpose only.
  3882. * @param group the group to track its associated Scene Node
  3883. */
  3884. _registerTrackedNode(group: Group2D): void;
  3885. /**
  3886. * Internal method used to unregister a tracked Scene Node
  3887. * Do not invoke this method, it's for internal purpose only.
  3888. * @param group the group to unregister its tracked Scene Node from.
  3889. */
  3890. _unregisterTrackedNode(group: Group2D): void;
  3891. /**
  3892. * Get a Solid Color Brush instance matching the given color.
  3893. * @param color The color to retrieve
  3894. * @return A shared instance of the SolidColorBrush2D class that use the given color
  3895. */
  3896. static GetSolidColorBrush(color: Color4): IBrush2D;
  3897. /**
  3898. * Get a Solid Color Brush instance matching the given color expressed as a CSS formatted hexadecimal value.
  3899. * @param color The color to retrieve
  3900. * @return A shared instance of the SolidColorBrush2D class that uses the given color
  3901. */
  3902. static GetSolidColorBrushFromHex(hexValue: string): IBrush2D;
  3903. /**
  3904. * Get a Gradient Color Brush
  3905. * @param color1 starting color
  3906. * @param color2 engine color
  3907. * @param translation translation vector to apply. default is [0;0]
  3908. * @param rotation rotation in radian to apply to the brush, initial direction is top to bottom. rotation is counter clockwise. default is 0.
  3909. * @param scale scaling factor to apply. default is 1.
  3910. */
  3911. static GetGradientColorBrush(color1: Color4, color2: Color4, translation?: Vector2, rotation?: number, scale?: number): IBrush2D;
  3912. /**
  3913. * Create a solid or gradient brush from a string value.
  3914. * @param brushString should be either
  3915. * - "solid: #RRGGBBAA" or "#RRGGBBAA"
  3916. * - "gradient: #FF808080, #FFFFFFF[, [10:20], 180, 1]" for color1, color2, translation, rotation (degree), scale. The last three are optionals, but if specified must be is this order. "gradient:" can be omitted.
  3917. */
  3918. static GetBrushFromString(brushString: string): IBrush2D;
  3919. private static _solidColorBrushes;
  3920. private static _gradientColorBrushes;
  3921. }
  3922. class WorldSpaceCanvas2D extends Canvas2D {
  3923. /**
  3924. * Create a new 2D WorldSpace Rendering Canvas, it is a 2D rectangle that has a size (width/height) and a world transformation information to place it in the world space.
  3925. * This kind of canvas can't have its Primitives directly drawn in the Viewport, they need to be cached in a bitmap at some point, as a consequence the DONT_CACHE strategy is unavailable. For now only CACHESTRATEGY_CANVAS is supported, but the remaining strategies will be soon.
  3926. * @param scene the Scene that owns the Canvas
  3927. * @param size the dimension of the Canvas in World Space
  3928. * @param settings a combination of settings, possible ones are
  3929. * - children: an array of direct children primitives
  3930. * - id: a text identifier, for information purpose only, default is null.
  3931. * - worldPosition the position of the Canvas in World Space, default is [0,0,0]
  3932. * - worldRotation the rotation of the Canvas in World Space, default is Quaternion.Identity()
  3933. * - sideOrientation: Unexpected behavior occur if the value is different from Mesh.DEFAULTSIDE right now, so please use this one, which is the default.
  3934. * - cachingStrategy Must be CACHESTRATEGY_CANVAS for now, which is the default.
  3935. * - enableInteraction: if true the pointer events will be listened and rerouted to the appropriate primitives of the Canvas2D through the Prim2DBase.onPointerEventObservable observable property. Default is false (the opposite of ScreenSpace).
  3936. * - isVisible: true if the canvas must be visible, false for hidden. Default is true.
  3937. * - backgroundRoundRadius: the round radius of the background, either backgroundFill or backgroundBorder must be specified.
  3938. * - backgroundFill: the brush to use to create a background fill for the canvas. can be a string value (see Canvas2D.GetBrushFromString) or a IBrush2D instance.
  3939. * - backgroundBorder: the brush to use to create a background border for the canvas. can be a string value (see Canvas2D.GetBrushFromString) or a IBrush2D instance.
  3940. * - backgroundBorderThickness: if a backgroundBorder is specified, its thickness can be set using this property
  3941. * - customWorldSpaceNode: if specified the Canvas will be rendered in this given Node. But it's the responsibility of the caller to set the "worldSpaceToNodeLocal" property to compute the hit of the mouse ray into the node (in world coordinate system) as well as rendering the cached bitmap in the node itself. The properties cachedRect and cachedTexture of Group2D will give you what you need to do that.
  3942. * - maxAdaptiveCanvasSize: set the max size (width and height) of the bitmap that will contain the cached version of the WorldSpace Canvas. Default is 1024 or less if it's not supported. In any case the value you give will be clipped by the maximum that WebGL supports on the running device. You can set any size, more than 1024 if you want, but testing proved it's a good max value for non "retina" like screens.
  3943. * - paddingTop: top padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  3944. * - paddingLeft: left padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  3945. * - paddingRight: right padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  3946. * - paddingBottom: bottom padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  3947. * - padding: top, left, right and bottom padding formatted as a single string (see PrimitiveThickness.fromString)
  3948. */
  3949. constructor(scene: Scene, size: Size, settings?: {
  3950. children?: Array<Prim2DBase>;
  3951. id?: string;
  3952. worldPosition?: Vector3;
  3953. worldRotation?: Quaternion;
  3954. sideOrientation?: number;
  3955. cachingStrategy?: number;
  3956. enableInteraction?: boolean;
  3957. isVisible?: boolean;
  3958. backgroundRoundRadius?: number;
  3959. backgroundFill?: IBrush2D | string;
  3960. backgroundBorder?: IBrush2D | string;
  3961. backgroundBorderThickNess?: number;
  3962. customWorldSpaceNode?: Node;
  3963. maxAdaptiveCanvasSize?: number;
  3964. paddingTop?: number | string;
  3965. paddingLeft?: number | string;
  3966. paddingRight?: number | string;
  3967. paddingBottom?: number | string;
  3968. padding?: string;
  3969. });
  3970. dispose(): boolean;
  3971. private _customWorldSpaceNode;
  3972. }
  3973. class ScreenSpaceCanvas2D extends Canvas2D {
  3974. /**
  3975. * Create a new 2D ScreenSpace Rendering Canvas, it is a 2D rectangle that has a size (width/height) and a position relative to the bottom/left corner of the screen.
  3976. * ScreenSpace Canvas will be drawn in the Viewport as a 2D Layer lying to the top of the 3D Scene. Typically used for traditional UI.
  3977. * All caching strategies will be available.
  3978. * PLEASE NOTE: the origin of a Screen Space Canvas is set to [0;0] (bottom/left) which is different than the default origin of a Primitive which is centered [0.5;0.5]
  3979. * @param scene the Scene that owns the Canvas
  3980. * @param settings a combination of settings, possible ones are
  3981. * - children: an array of direct children primitives
  3982. * - id: a text identifier, for information purpose only
  3983. * - x: the position along the x axis (horizontal), relative to the left edge of the viewport. you can alternatively use the position setting.
  3984. * - y: the position along the y axis (vertically), relative to the bottom edge of the viewport. you can alternatively use the position setting.
  3985. * - position: the position of the canvas, relative from the bottom/left of the scene's viewport. Alternatively you can set the x and y properties directly. Default value is [0, 0]
  3986. * - width: the width of the Canvas. you can alternatively use the size setting.
  3987. * - height: the height of the Canvas. you can alternatively use the size setting.
  3988. * - size: the Size of the canvas. Alternatively the width and height properties can be set. If null two behaviors depend on the cachingStrategy: if it's CACHESTRATEGY_CACHECANVAS then it will always auto-fit the rendering device, in all the other modes it will fit the content of the Canvas
  3989. * - renderingPhase: you can specify for which camera and which renderGroup this canvas will render to enable interleaving of 3D/2D content through the use of renderinGroup. As a rendering Group is rendered for each camera, you have to specify in the scope of which camera you want the canvas' render to be made. Default behavior will render the Canvas at the very end of the render loop.
  3990. * - designSize: if you want to set the canvas content based on fixed coordinates whatever the final canvas dimension would be, set this. For instance a designSize of 360*640 will give you the possibility to specify all the children element in this frame. The Canvas' true size will be the HTMLCanvas' size: for instance it could be 720*1280, then a uniform scale of 2 will be applied on the Canvas to keep the absolute coordinates working as expecting. If the ratios of the designSize and the true Canvas size are not the same, then the scale is computed following the designUseHorizAxis member by using either the size of the horizontal axis or the vertical axis.
  3991. * - designUseHorizAxis: you can set this member if you use designSize to specify which axis is priority to compute the scale when the ratio of the canvas' size is different from the designSize's one.
  3992. * - cachingStrategy: either CACHESTRATEGY_TOPLEVELGROUPS, CACHESTRATEGY_ALLGROUPS, CACHESTRATEGY_CANVAS, CACHESTRATEGY_DONTCACHE. Please refer to their respective documentation for more information. Default is Canvas2D.CACHESTRATEGY_DONTCACHE
  3993. * - enableInteraction: if true the pointer events will be listened and rerouted to the appropriate primitives of the Canvas2D through the Prim2DBase.onPointerEventObservable observable property. Default is true.
  3994. * - isVisible: true if the canvas must be visible, false for hidden. Default is true.
  3995. * - backgroundRoundRadius: the round radius of the background, either backgroundFill or backgroundBorder must be specified.
  3996. * - backgroundFill: the brush to use to create a background fill for the canvas. can be a string value (see BABYLON.Canvas2D.GetBrushFromString) or a IBrush2D instance.
  3997. * - backgroundBorder: the brush to use to create a background border for the canvas. can be a string value (see BABYLON.Canvas2D.GetBrushFromString) or a IBrush2D instance.
  3998. * - backgroundBorderThickness: if a backgroundBorder is specified, its thickness can be set using this property
  3999. * - customWorldSpaceNode: if specified the Canvas will be rendered in this given Node. But it's the responsibility of the caller to set the "worldSpaceToNodeLocal" property to compute the hit of the mouse ray into the node (in world coordinate system) as well as rendering the cached bitmap in the node itself. The properties cachedRect and cachedTexture of Group2D will give you what you need to do that.
  4000. * - paddingTop: top padding, can be a number (will be pixels) or a string (see BABYLON.PrimitiveThickness.fromString)
  4001. * - paddingLeft: left padding, can be a number (will be pixels) or a string (see BABYLON.PrimitiveThickness.fromString)
  4002. * - paddingRight: right padding, can be a number (will be pixels) or a string (see BABYLON.PrimitiveThickness.fromString)
  4003. * - paddingBottom: bottom padding, can be a number (will be pixels) or a string (see BABYLON.PrimitiveThickness.fromString)
  4004. * - padding: top, left, right and bottom padding formatted as a single string (see BABYLON.PrimitiveThickness.fromString)
  4005. */
  4006. constructor(scene: Scene, settings?: {
  4007. children?: Array<Prim2DBase>;
  4008. id?: string;
  4009. x?: number;
  4010. y?: number;
  4011. position?: Vector2;
  4012. origin?: Vector2;
  4013. width?: number;
  4014. height?: number;
  4015. size?: Size;
  4016. renderingPhase?: {
  4017. camera: Camera;
  4018. renderingGroupID: number;
  4019. };
  4020. designSize?: Size;
  4021. designUseHorizAxis?: boolean;
  4022. cachingStrategy?: number;
  4023. cacheBehavior?: number;
  4024. enableInteraction?: boolean;
  4025. isVisible?: boolean;
  4026. backgroundRoundRadius?: number;
  4027. backgroundFill?: IBrush2D | string;
  4028. backgroundBorder?: IBrush2D | string;
  4029. backgroundBorderThickNess?: number;
  4030. paddingTop?: number | string;
  4031. paddingLeft?: number | string;
  4032. paddingRight?: number | string;
  4033. paddingBottom?: number | string;
  4034. padding?: string;
  4035. });
  4036. }
  4037. }
  4038. declare module BABYLON {
  4039. /**
  4040. * This is the class that is used to display a World Space Canvas into a 3D scene
  4041. */
  4042. class WorldSpaceCanvas2DNode extends Mesh {
  4043. constructor(name: string, scene: Scene, canvas: Canvas2D);
  4044. dispose(): void;
  4045. private _canvas;
  4046. }
  4047. }
  4048. declare module BABYLON {
  4049. interface ICommand {
  4050. canExecute(parameter: any): boolean;
  4051. execute(parameter: any): void;
  4052. canExecuteChanged: Observable<void>;
  4053. }
  4054. class Command implements ICommand {
  4055. constructor(execute: (p) => void, canExecute: (p) => boolean);
  4056. canExecute(parameter: any): boolean;
  4057. execute(parameter: any): void;
  4058. readonly canExecuteChanged: Observable<void>;
  4059. private _lastCanExecuteResult;
  4060. private _execute;
  4061. private _canExecute;
  4062. private _canExecuteChanged;
  4063. }
  4064. abstract class UIElement extends SmartPropertyBase {
  4065. static readonly enabledState: string;
  4066. static readonly disabledState: string;
  4067. static readonly mouseOverState: string;
  4068. static UIELEMENT_PROPCOUNT: number;
  4069. static parentProperty: Prim2DPropInfo;
  4070. static widthProperty: Prim2DPropInfo;
  4071. static heightProperty: Prim2DPropInfo;
  4072. static minWidthProperty: Prim2DPropInfo;
  4073. static minHeightProperty: Prim2DPropInfo;
  4074. static maxWidthProperty: Prim2DPropInfo;
  4075. static maxHeightProperty: Prim2DPropInfo;
  4076. static actualWidthProperty: Prim2DPropInfo;
  4077. static actualHeightProperty: Prim2DPropInfo;
  4078. static marginProperty: Prim2DPropInfo;
  4079. static paddingProperty: Prim2DPropInfo;
  4080. static marginAlignmentProperty: Prim2DPropInfo;
  4081. static paddingAlignmentProperty: Prim2DPropInfo;
  4082. static isEnabledProperty: Prim2DPropInfo;
  4083. static isFocusedProperty: Prim2DPropInfo;
  4084. static isMouseOverProperty: Prim2DPropInfo;
  4085. constructor(settings: {
  4086. id?: string;
  4087. parent?: UIElement;
  4088. templateName?: string;
  4089. styleName?: string;
  4090. minWidth?: number;
  4091. minHeight?: number;
  4092. maxWidth?: number;
  4093. maxHeight?: number;
  4094. width?: number;
  4095. height?: number;
  4096. marginTop?: number | string;
  4097. marginLeft?: number | string;
  4098. marginRight?: number | string;
  4099. marginBottom?: number | string;
  4100. margin?: number | string;
  4101. marginHAlignment?: number;
  4102. marginVAlignment?: number;
  4103. marginAlignment?: string;
  4104. paddingTop?: number | string;
  4105. paddingLeft?: number | string;
  4106. paddingRight?: number | string;
  4107. paddingBottom?: number | string;
  4108. padding?: string;
  4109. paddingHAlignment?: number;
  4110. paddingVAlignment?: number;
  4111. paddingAlignment?: string;
  4112. });
  4113. dispose(): boolean;
  4114. /**
  4115. * Animation array, more info: http://doc.babylonjs.com/tutorials/Animations
  4116. */
  4117. animations: Animation[];
  4118. /**
  4119. * Returns as a new array populated with the Animatable used by the primitive. Must be overloaded by derived primitives.
  4120. * Look at Sprite2D for more information
  4121. */
  4122. getAnimatables(): IAnimatable[];
  4123. findById(id: string): UIElement;
  4124. readonly ownerWindow: Window;
  4125. style: string;
  4126. /**
  4127. * A string that identifies the UIElement.
  4128. * The id is optional and there's possible collision with other UIElement's id as the uniqueness is not supported.
  4129. */
  4130. id: string;
  4131. /**
  4132. * Return a unique id automatically generated.
  4133. * This property is mainly used for serialization to ensure a perfect way of identifying a UIElement
  4134. */
  4135. readonly uid: string;
  4136. readonly hierarchyDepth: number;
  4137. parent: UIElement;
  4138. width: number;
  4139. height: number;
  4140. minWidth: number;
  4141. readonly minHheight: number;
  4142. minHeight: number;
  4143. maxWidth: number;
  4144. maxHeight: number;
  4145. actualWidth: number;
  4146. actualHeight: number;
  4147. margin: PrimitiveThickness;
  4148. readonly _hasMargin: boolean;
  4149. padding: PrimitiveThickness;
  4150. private readonly _hasPadding;
  4151. marginAlignment: PrimitiveAlignment;
  4152. /**
  4153. * Check if there a marginAlignment specified (non null and not default)
  4154. */
  4155. readonly _hasMarginAlignment: boolean;
  4156. paddingAlignment: PrimitiveAlignment;
  4157. /**
  4158. * Check if there a marginAlignment specified (non null and not default)
  4159. */
  4160. readonly _hasPaddingAlignment: boolean;
  4161. isVisible: boolean;
  4162. isEnabled: boolean;
  4163. isFocused: boolean;
  4164. isMouseOver: boolean;
  4165. isFocusScope: boolean;
  4166. isFocusable: boolean;
  4167. protected getFocusScope(): UIElement;
  4168. /**
  4169. * Check if a given flag is set
  4170. * @param flag the flag value
  4171. * @return true if set, false otherwise
  4172. */
  4173. _isFlagSet(flag: number): boolean;
  4174. /**
  4175. * Check if all given flags are set
  4176. * @param flags the flags ORed
  4177. * @return true if all the flags are set, false otherwise
  4178. */
  4179. _areAllFlagsSet(flags: number): boolean;
  4180. /**
  4181. * Check if at least one flag of the given flags is set
  4182. * @param flags the flags ORed
  4183. * @return true if at least one flag is set, false otherwise
  4184. */
  4185. _areSomeFlagsSet(flags: number): boolean;
  4186. /**
  4187. * Clear the given flags
  4188. * @param flags the flags to clear
  4189. */
  4190. _clearFlags(flags: number): void;
  4191. /**
  4192. * Set the given flags to true state
  4193. * @param flags the flags ORed to set
  4194. * @return the flags state before this call
  4195. */
  4196. _setFlags(flags: number): number;
  4197. /**
  4198. * Change the state of the given flags
  4199. * @param flags the flags ORed to change
  4200. * @param state true to set them, false to clear them
  4201. */
  4202. _changeFlags(flags: number, state: boolean): void;
  4203. private _assignTemplate(templateName);
  4204. _createVisualTree(): void;
  4205. _patchUIElement(ownerWindow: Window, parent: UIElement): void;
  4206. protected _getDataSource(): IPropertyChanged;
  4207. protected createVisualTree(): void;
  4208. protected readonly visualPlaceholder: Prim2DBase;
  4209. protected readonly visualTemplateRoot: Prim2DBase;
  4210. protected readonly visualChildrenPlaceholder: Prim2DBase;
  4211. protected readonly _position: Vector2;
  4212. protected abstract _getChildren(): Array<UIElement>;
  4213. static flagVisualToBuild: number;
  4214. static flagIsVisible: number;
  4215. static flagIsFocus: number;
  4216. static flagIsFocusScope: number;
  4217. static flagIsFocusable: number;
  4218. static flagIsEnabled: number;
  4219. static flagIsMouseOver: number;
  4220. protected _visualPlaceholder: Group2D;
  4221. protected _visualTemplateRoot: Prim2DBase;
  4222. protected _visualChildrenPlaceholder: Prim2DBase;
  4223. private _renderingTemplateName;
  4224. protected _renderingTemplate: UIElementRenderingTemplateBase;
  4225. private _parent;
  4226. private _hierarchyDepth;
  4227. private _flags;
  4228. private _style;
  4229. private _ownerWindow;
  4230. private _id;
  4231. private _uid;
  4232. private _actualWidth;
  4233. private _actualHeight;
  4234. private _minWidth;
  4235. private _minHeight;
  4236. private _maxWidth;
  4237. private _maxHeight;
  4238. private _width;
  4239. private _height;
  4240. private _margin;
  4241. private _padding;
  4242. private _marginAlignment;
  4243. private _paddingAlignment;
  4244. private static _enableState;
  4245. private static _disabledState;
  4246. private static _mouseOverState;
  4247. }
  4248. abstract class UIElementStyle {
  4249. abstract removeStyle(uiel: UIElement): any;
  4250. abstract applyStyle(uiel: UIElement): any;
  4251. readonly name: string;
  4252. }
  4253. class GUIManager {
  4254. static registerDataTemplate(className: string, factory: (parent: UIElement, dataObject: any) => UIElement): void;
  4255. static getStyle(uiElType: string, styleName: string): UIElementStyle;
  4256. static registerStyle(uiElType: string, templateName: string, style: UIElementStyle): void;
  4257. static stylesByUIElement: StringDictionary<StringDictionary<UIElementStyle>>;
  4258. static DefaultStyleName: string;
  4259. static getRenderingTemplate(uiElType: string, templateName: string): () => UIElementRenderingTemplateBase;
  4260. static registerRenderingTemplate(uiElType: string, templateName: string, factory: () => UIElementRenderingTemplateBase): void;
  4261. static renderingTemplatesByUIElement: StringDictionary<StringDictionary<() => UIElementRenderingTemplateBase>>;
  4262. static DefaultTemplateName: string;
  4263. private static _defaultTemplateName;
  4264. private static _defaultStyleName;
  4265. }
  4266. abstract class UIElementRenderingTemplateBase {
  4267. attach(owner: UIElement): void;
  4268. detach(): void;
  4269. readonly owner: UIElement;
  4270. abstract createVisualTree(owner: UIElement, visualPlaceholder: Group2D): {
  4271. root: Prim2DBase;
  4272. contentPlaceholder: Prim2DBase;
  4273. };
  4274. private _owner;
  4275. }
  4276. function registerWindowRenderingTemplate(uiElType: string, templateName: string, factory: () => UIElementRenderingTemplateBase): (target: Object) => void;
  4277. }
  4278. declare module BABYLON {
  4279. class StackPanel extends UIElement {
  4280. static STACKPANEL_PROPCOUNT: number;
  4281. static orientationHorizontalProperty: Prim2DPropInfo;
  4282. constructor(settings?: {
  4283. id?: string;
  4284. parent?: UIElement;
  4285. children?: Array<UIElement>;
  4286. templateName?: string;
  4287. styleName?: string;
  4288. isOrientationHorizontal?: any;
  4289. marginTop?: number | string;
  4290. marginLeft?: number | string;
  4291. marginRight?: number | string;
  4292. marginBottom?: number | string;
  4293. margin?: number | string;
  4294. marginHAlignment?: number;
  4295. marginVAlignment?: number;
  4296. marginAlignment?: string;
  4297. paddingTop?: number | string;
  4298. paddingLeft?: number | string;
  4299. paddingRight?: number | string;
  4300. paddingBottom?: number | string;
  4301. padding?: string;
  4302. paddingHAlignment?: number;
  4303. paddingVAlignment?: number;
  4304. paddingAlignment?: string;
  4305. });
  4306. isOrientationHorizontal: boolean;
  4307. protected createVisualTree(): void;
  4308. readonly children: Array<UIElement>;
  4309. protected _getChildren(): Array<UIElement>;
  4310. private _childrenPlaceholder;
  4311. private _children;
  4312. private _isOrientationHorizontal;
  4313. }
  4314. class DefaultStackPanelRenderingTemplate extends UIElementRenderingTemplateBase {
  4315. createVisualTree(owner: UIElement, visualPlaceholder: Group2D): {
  4316. root: Prim2DBase;
  4317. contentPlaceholder: Prim2DBase;
  4318. };
  4319. attach(owner: UIElement): void;
  4320. }
  4321. }
  4322. declare module BABYLON {
  4323. abstract class Control extends UIElement {
  4324. static CONTROL_PROPCOUNT: number;
  4325. static backgroundProperty: Prim2DPropInfo;
  4326. static borderProperty: Prim2DPropInfo;
  4327. static borderThicknessProperty: Prim2DPropInfo;
  4328. static fontNameProperty: Prim2DPropInfo;
  4329. static foregroundProperty: Prim2DPropInfo;
  4330. constructor(settings: {
  4331. id?: string;
  4332. templateName?: string;
  4333. styleName?: string;
  4334. });
  4335. background: StringDictionary<IBrush2D>;
  4336. border: IBrush2D;
  4337. borderThickness: number;
  4338. fontName: string;
  4339. foreground: IBrush2D;
  4340. private _background;
  4341. private _border;
  4342. private _borderThickness;
  4343. private _fontName;
  4344. private _foreground;
  4345. }
  4346. }
  4347. declare module BABYLON {
  4348. abstract class ContentControl extends Control {
  4349. static CONTENTCONTROL_PROPCOUNT: number;
  4350. static contentProperty: Prim2DPropInfo;
  4351. constructor(settings?: {
  4352. id?: string;
  4353. templateName?: string;
  4354. styleName?: string;
  4355. content?: any;
  4356. });
  4357. dispose(): boolean;
  4358. content: any;
  4359. protected readonly _contentUIElement: UIElement;
  4360. _createVisualTree(): void;
  4361. private _buildContentUIElement();
  4362. private _contentPlaceholder;
  4363. private _content;
  4364. private __contentUIElement;
  4365. protected _getChildren(): Array<UIElement>;
  4366. }
  4367. }
  4368. declare module BABYLON {
  4369. class FocusManager {
  4370. constructor();
  4371. setFocusOn(el: UIElement, focusScope: UIElement): void;
  4372. private _rootScope;
  4373. private _focusScopes;
  4374. private _activeScope;
  4375. }
  4376. class Window extends ContentControl {
  4377. static WINDOW_PROPCOUNT: number;
  4378. static leftProperty: Prim2DPropInfo;
  4379. static bottomProperty: Prim2DPropInfo;
  4380. static positionProperty: Prim2DPropInfo;
  4381. static isActiveProperty: Prim2DPropInfo;
  4382. constructor(scene: Scene, settings?: {
  4383. id?: string;
  4384. templateName?: string;
  4385. styleName?: string;
  4386. content?: any;
  4387. left?: number;
  4388. bottom?: number;
  4389. minWidth?: number;
  4390. minHeight?: number;
  4391. maxWidth?: number;
  4392. maxHeight?: number;
  4393. width?: number;
  4394. height?: number;
  4395. worldPosition?: Vector3;
  4396. worldRotation?: Quaternion;
  4397. marginTop?: number | string;
  4398. marginLeft?: number | string;
  4399. marginRight?: number | string;
  4400. marginBottom?: number | string;
  4401. margin?: number | string;
  4402. marginHAlignment?: number;
  4403. marginVAlignment?: number;
  4404. marginAlignment?: string;
  4405. paddingTop?: number | string;
  4406. paddingLeft?: number | string;
  4407. paddingRight?: number | string;
  4408. paddingBottom?: number | string;
  4409. padding?: string;
  4410. paddingHAlignment?: number;
  4411. paddingVAlignment?: number;
  4412. paddingAlignment?: string;
  4413. });
  4414. readonly canvas: Canvas2D;
  4415. left: number;
  4416. bottom: number;
  4417. position: Vector2;
  4418. isActive: boolean;
  4419. readonly focusManager: FocusManager;
  4420. protected readonly _position: Vector2;
  4421. protected createVisualTree(): void;
  4422. _registerVisualToBuild(uiel: UIElement): void;
  4423. private _overPrimChanged(oldPrim, newPrim);
  4424. private _canvasPreRender();
  4425. private _canvasDisposed();
  4426. private _sceneData;
  4427. private _canvas;
  4428. private _left;
  4429. private _bottom;
  4430. private _isActive;
  4431. private _isWorldSpaceCanvas;
  4432. private _renderObserver;
  4433. private _disposeObserver;
  4434. private _UIElementVisualToBuildList;
  4435. private _mouseOverUIElement;
  4436. private static getSceneData(scene);
  4437. private static _sceneData;
  4438. }
  4439. class DefaultWindowRenderingTemplate extends UIElementRenderingTemplateBase {
  4440. createVisualTree(owner: UIElement, visualPlaceholder: Group2D): {
  4441. root: Prim2DBase;
  4442. contentPlaceholder: Prim2DBase;
  4443. };
  4444. }
  4445. }
  4446. declare module BABYLON {
  4447. class Label extends Control {
  4448. static textProperty: Prim2DPropInfo;
  4449. constructor(settings?: {
  4450. id?: string;
  4451. parent?: UIElement;
  4452. templateName?: string;
  4453. styleName?: string;
  4454. text?: string;
  4455. marginTop?: number | string;
  4456. marginLeft?: number | string;
  4457. marginRight?: number | string;
  4458. marginBottom?: number | string;
  4459. margin?: number | string;
  4460. marginHAlignment?: number;
  4461. marginVAlignment?: number;
  4462. marginAlignment?: string;
  4463. paddingTop?: number | string;
  4464. paddingLeft?: number | string;
  4465. paddingRight?: number | string;
  4466. paddingBottom?: number | string;
  4467. padding?: string;
  4468. });
  4469. protected readonly _position: Vector2;
  4470. private static _emptyArray;
  4471. protected _getChildren(): UIElement[];
  4472. protected createVisualTree(): void;
  4473. text: string;
  4474. private _text;
  4475. }
  4476. class DefaultLabelRenderingTemplate extends UIElementRenderingTemplateBase {
  4477. createVisualTree(owner: UIElement, visualPlaceholder: Group2D): {
  4478. root: Prim2DBase;
  4479. contentPlaceholder: Prim2DBase;
  4480. };
  4481. }
  4482. }
  4483. declare module BABYLON {
  4484. class Button extends ContentControl {
  4485. static readonly pushedState: string;
  4486. static BUTTON_PROPCOUNT: number;
  4487. static isPushedProperty: Prim2DPropInfo;
  4488. static isDefaultProperty: Prim2DPropInfo;
  4489. static isOutlineProperty: Prim2DPropInfo;
  4490. constructor(settings?: {
  4491. id?: string;
  4492. parent?: UIElement;
  4493. templateName?: string;
  4494. styleName?: string;
  4495. content?: any;
  4496. marginTop?: number | string;
  4497. marginLeft?: number | string;
  4498. marginRight?: number | string;
  4499. marginBottom?: number | string;
  4500. margin?: number | string;
  4501. marginHAlignment?: number;
  4502. marginVAlignment?: number;
  4503. marginAlignment?: string;
  4504. paddingTop?: number | string;
  4505. paddingLeft?: number | string;
  4506. paddingRight?: number | string;
  4507. paddingBottom?: number | string;
  4508. padding?: string;
  4509. paddingHAlignment?: number;
  4510. paddingVAlignment?: number;
  4511. paddingAlignment?: string;
  4512. });
  4513. isPushed: boolean;
  4514. isDefault: boolean;
  4515. isOutline: boolean;
  4516. readonly clickObservable: Observable<Button>;
  4517. _raiseClick(): void;
  4518. protected createVisualTree(): void;
  4519. readonly normalStateBackground: ObservableStringDictionary<IBrush2D>;
  4520. readonly defaultStateBackground: ObservableStringDictionary<IBrush2D>;
  4521. readonly normalStateBorder: ObservableStringDictionary<IBrush2D>;
  4522. readonly defaultStateBorder: ObservableStringDictionary<IBrush2D>;
  4523. private _normalStateBackground;
  4524. private _normalStateBorder;
  4525. private _defaultStateBackground;
  4526. private _defaultStateBorder;
  4527. private _isPushed;
  4528. private _isDefault;
  4529. private _isOutline;
  4530. private _clickObservable;
  4531. private static _pushedState;
  4532. }
  4533. class DefaultButtonRenderingTemplate extends UIElementRenderingTemplateBase {
  4534. createVisualTree(owner: UIElement, visualPlaceholder: Group2D): {
  4535. root: Prim2DBase;
  4536. contentPlaceholder: Prim2DBase;
  4537. };
  4538. attach(owner: UIElement): void;
  4539. stateChange(): void;
  4540. private _rect;
  4541. }
  4542. }