PolycodeProps.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800
  1. /*
  2. Copyright (C) 2012 by Ivan Safrin
  3. Permission is hereby granted, free of charge, to any person obtaining a copy
  4. of this software and associated documentation files (the "Software"), to deal
  5. in the Software without restriction, including without limitation the rights
  6. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  7. copies of the Software, and to permit persons to whom the Software is
  8. furnished to do so, subject to the following conditions:
  9. The above copyright notice and this permission notice shall be included in
  10. all copies or substantial portions of the Software.
  11. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  12. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  13. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  14. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  15. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  16. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  17. THE SOFTWARE.
  18. */
  19. #pragma once
  20. #include "PolycodeGlobals.h"
  21. #include "PolycodeUI.h"
  22. #include "Polycode.h"
  23. #include "OSBasics.h"
  24. #include "PolycodeEditor.h"
  25. using namespace Polycode;
  26. #define PROP_PADDING 40
  27. class PolycodeEditorPropActionData;
  28. class PropProp : public UIElement {
  29. public:
  30. PropProp(String caption, String type);
  31. ~PropProp();
  32. virtual void setPropData(PolycodeEditorPropActionData* data) {}
  33. virtual void setPropWidth(Number width) {}
  34. String propType;
  35. ScreenLabel *label;
  36. ScreenEntity *propContents;
  37. bool suppressChangeEvent;
  38. bool settingFromData;
  39. };
  40. class Vector2Prop : public PropProp {
  41. public:
  42. Vector2Prop(String caption);
  43. ~Vector2Prop();
  44. void handleEvent(Event *event);
  45. void set(Vector2 position);
  46. Vector2 get();
  47. void setPropData(PolycodeEditorPropActionData* data);
  48. void setPropWidth(Number width);
  49. UITextInput *positionX;
  50. UITextInput *positionY;
  51. Vector2 lastData;
  52. Vector2 currentData;
  53. ScreenLabel *labelX;
  54. ScreenLabel *labelY;
  55. };
  56. class SliderProp : public PropProp {
  57. public:
  58. SliderProp(String caption, Number min, Number max);
  59. ~SliderProp();
  60. void handleEvent(Event *event);
  61. void set(Number number);
  62. Number get();
  63. void setPropWidth(Number width);
  64. void setPropData(PolycodeEditorPropActionData* data);
  65. UIHSlider *slider;
  66. ScreenLabel *valueLabel;
  67. Number lastValue;
  68. Number currentValue;
  69. };
  70. class NumberProp : public PropProp {
  71. public:
  72. NumberProp(String caption);
  73. ~NumberProp();
  74. void handleEvent(Event *event);
  75. void set(Number number);
  76. Number get();
  77. void setPropWidth(Number width);
  78. void setPropData(PolycodeEditorPropActionData* data);
  79. UITextInput *numberEntry;
  80. Number lastValue;
  81. Number currentValue;
  82. };
  83. class TargetBindingProp : public PropProp {
  84. public:
  85. TargetBindingProp(Shader *shader, Material *material, ShaderBinding *binding, RenderTargetBinding *targetBinding);
  86. ~TargetBindingProp();
  87. void handleEvent(Event *event);
  88. void setPropWidth(Number width);
  89. RenderTargetBinding *targetBinding;
  90. Material *material;
  91. Shader *shader;
  92. ShaderBinding *binding;
  93. UIComboBox *typeComboBox;
  94. UIComboBox *targetComboBox;
  95. UIComboBox *textureComboBox;
  96. UIImageButton *removeButton;
  97. };
  98. class RenderTargetProp : public PropProp {
  99. public:
  100. RenderTargetProp(ShaderRenderTarget *renderTarget, Material *material);
  101. ~RenderTargetProp();
  102. void handleEvent(Event *event);
  103. void setPropWidth(Number width);
  104. void recreateRenderTarget();
  105. Material *material;
  106. ShaderRenderTarget *renderTarget;
  107. UITextInput *nameInput;
  108. UIComboBox *typeComboBox;
  109. UITextInput *widthInput;
  110. UITextInput *heightInput;
  111. UIImageButton *removeButton;
  112. };
  113. class ShaderPassProp : public PropProp {
  114. public:
  115. ShaderPassProp(Material *material, int shaderIndex);
  116. ~ShaderPassProp();
  117. void handleEvent(Event *event);
  118. void setPropWidth(Number width);
  119. Material *material;
  120. Shader *shader;
  121. int shaderIndex;
  122. UIComboBox *shaderComboBox;
  123. UIImageButton *removeButton;
  124. UIButton *editButton;
  125. };
  126. class CustomProp : public PropProp {
  127. public:
  128. CustomProp(String key, String value);
  129. ~CustomProp();
  130. void handleEvent(Event *event);
  131. void set(String key, String val);
  132. String getValue();
  133. String getKey();
  134. UITextInput *keyEntry;
  135. UITextInput *valueEntry;
  136. UIImageButton *removeButton;
  137. };
  138. class StringProp : public PropProp {
  139. public:
  140. StringProp(String caption);
  141. ~StringProp();
  142. void handleEvent(Event *event);
  143. void set(String str);
  144. String get();
  145. void setPropWidth(Number width);
  146. void setPropData(PolycodeEditorPropActionData* data);
  147. UITextInput *stringEntry;
  148. String lastValue;
  149. String currentValue;
  150. };
  151. class ColorProp : public PropProp {
  152. public:
  153. ColorProp(String caption);
  154. ~ColorProp();
  155. void handleEvent(Event *event);
  156. virtual void setPropData(PolycodeEditorPropActionData* data);
  157. void set(Color color);
  158. Color get();
  159. Color currentColor;
  160. Color lastColor;
  161. UIColorBox *colorEntry;
  162. };
  163. class ComboProp : public PropProp {
  164. public:
  165. ComboProp(String caption);
  166. ~ComboProp();
  167. void handleEvent(Event *event);
  168. void setPropData(PolycodeEditorPropActionData* data);
  169. void setPropWidth(Number width);
  170. void set(unsigned int index);
  171. unsigned int get();
  172. UIComboBox *comboEntry;
  173. int lastValue;
  174. int currentValue;
  175. };
  176. class BoolProp : public PropProp {
  177. public:
  178. BoolProp(String caption);
  179. ~BoolProp();
  180. void handleEvent(Event *event);
  181. void setPropData(PolycodeEditorPropActionData* data);
  182. void set(bool val);
  183. bool get();
  184. UICheckBox *checkEntry;
  185. bool lastData;
  186. bool currentData;
  187. };
  188. class SoundProp : public PropProp {
  189. public:
  190. SoundProp(String caption);
  191. ~SoundProp();
  192. void handleEvent(Event *event);
  193. void set(String soundPath);
  194. String get();
  195. void setPropData(PolycodeEditorPropActionData* data);
  196. Sound *previewSound;
  197. ScreenLabel *soundFile;
  198. UIButton *changeButton;
  199. UIButton *playButton;
  200. String lastData;
  201. String currentData;
  202. };
  203. class BezierRGBACurveProp : public PropProp {
  204. public:
  205. BezierRGBACurveProp(String caption);
  206. ~BezierRGBACurveProp();
  207. void handleEvent(Event *event);
  208. BezierCurve *curveR;
  209. BezierCurve *curveG;
  210. BezierCurve *curveB;
  211. BezierCurve *curveA;
  212. UIButton *changeButton;
  213. };
  214. class BezierCurveProp : public PropProp {
  215. public:
  216. BezierCurveProp(String caption, String curveName);
  217. ~BezierCurveProp();
  218. void handleEvent(Event *event);
  219. String curveName;
  220. BezierCurve *curve;
  221. UIButton *changeButton;
  222. };
  223. class TextureProp : public PropProp {
  224. public:
  225. TextureProp(String caption);
  226. ~TextureProp();
  227. void handleEvent(Event *event);
  228. void setPropWidth(Number width);
  229. void set(Texture *texture);
  230. Texture* get();
  231. void setPropData(PolycodeEditorPropActionData* data);
  232. ScreenShape *previewShape;
  233. UIButton *changeButton;
  234. ScreenLabel *textureLabel;
  235. String lastData;
  236. String currentData;
  237. };
  238. class ScreenSpriteProp : public PropProp {
  239. public:
  240. ScreenSpriteProp(String caption);
  241. ~ScreenSpriteProp();
  242. void handleEvent(Event *event);
  243. void setPropData(PolycodeEditorPropActionData* data);
  244. void set(String fileName);
  245. String get();
  246. ScreenSprite *previewSprite;
  247. UIButton *changeButton;
  248. String lastData;
  249. String currentData;
  250. };
  251. class ScreenEntityInstanceProp : public PropProp {
  252. public:
  253. ScreenEntityInstanceProp(String caption);
  254. ~ScreenEntityInstanceProp();
  255. void handleEvent(Event *event);
  256. void setPropData(PolycodeEditorPropActionData* data);
  257. void set(String fileName);
  258. String get();
  259. ScreenEntityInstance *previewInstance;
  260. UIButton *changeButton;
  261. String lastData;
  262. String currentData;
  263. };
  264. class PropSheet : public UIElement {
  265. public:
  266. PropSheet(String caption, String type);
  267. ~PropSheet();
  268. void Resize(Number width, Number height);
  269. virtual void applyPropActionData(PolycodeEditorPropActionData *data);
  270. void handleEvent(Event *event);
  271. void setCollapsed(bool val);
  272. void addProp(PropProp *prop);
  273. String caption;
  274. String type;
  275. Number propHeight;
  276. ScreenEntity *contents;
  277. ScreenShape *bg;
  278. UIImageButton *collapseButton;
  279. UIImageButton *expandButton;
  280. bool collapsed;
  281. bool customUndoHandler;
  282. std::vector<PropProp*> props;
  283. };
  284. class ShaderOptionsSheet : public PropSheet {
  285. public:
  286. ShaderOptionsSheet();
  287. ~ShaderOptionsSheet();
  288. void handleEvent(Event *event);
  289. void Update();
  290. void clearShader();
  291. void setOptionsFromParams(std::vector<ProgramParam> &params);
  292. void setShader(Shader *shader, Material *material, ShaderBinding *binding);
  293. private:
  294. Shader *shader;
  295. Material *material;
  296. ShaderBinding *binding;
  297. };
  298. class ShaderTexturesSheet : public PropSheet {
  299. public:
  300. ShaderTexturesSheet();
  301. ~ShaderTexturesSheet();
  302. void handleEvent(Event *event);
  303. void Update();
  304. void clearShader();
  305. void setShader(Shader *shader, Material *material, ShaderBinding *binding);
  306. private:
  307. Shader *shader;
  308. Material *material;
  309. ShaderBinding *binding;
  310. std::vector<TextureProp*> textureProps;
  311. std::vector<ComboProp*> cubemapProps;
  312. };
  313. class EntitySheet : public PropSheet {
  314. public:
  315. EntitySheet();
  316. ~EntitySheet();
  317. void handleEvent(Event *event);
  318. void Update();
  319. Entity *entity;
  320. Entity *lastEntity;
  321. StringProp *idProp;
  322. StringProp *tagProp;
  323. ColorProp *colorProp;
  324. ComboProp *blendingProp;
  325. };
  326. class ShaderPassesSheet : public PropSheet {
  327. public:
  328. ShaderPassesSheet();
  329. ~ShaderPassesSheet();
  330. void handleEvent(Event *event);
  331. void refreshPasses();
  332. void Update();
  333. void setMaterial(Material *material);
  334. ShaderBinding *binding;
  335. Material *material;
  336. ShaderPassProp *selectedProp;
  337. UIButton *addButton;
  338. int removeIndex;
  339. };
  340. class TargetBindingsSheet : public PropSheet {
  341. public:
  342. TargetBindingsSheet();
  343. ~TargetBindingsSheet();
  344. void handleEvent(Event *event);
  345. void setShader(Shader *shader, Material *material, ShaderBinding *binding);
  346. void Update();
  347. void refreshTargets();
  348. ShaderBinding *binding;
  349. Material *material;
  350. Shader *shader;
  351. int shaderIndex;
  352. UIButton *addButton;
  353. RenderTargetBinding *bindingToRemove;
  354. };
  355. class RenderTargetsSheet : public PropSheet {
  356. public:
  357. RenderTargetsSheet();
  358. ~RenderTargetsSheet();
  359. void Update();
  360. void handleEvent(Event *event);
  361. void refreshTargets();
  362. ShaderBinding *binding;
  363. Material *material;
  364. Material *lastMaterial;
  365. Number normTextureWidth;
  366. Number normTextureHeight;
  367. UIButton *addButton;
  368. int removeIndex;
  369. };
  370. class EntityPropSheet : public PropSheet {
  371. public:
  372. EntityPropSheet();
  373. void handleEvent(Event *event);
  374. void Update();
  375. void refreshProps();
  376. void applyPropActionData(PolycodeEditorPropActionData *data);
  377. UIButton *addButton;
  378. Entity *entity;
  379. Entity *lastEntity;
  380. int lastNumProps;
  381. int removeIndex;
  382. };
  383. class ShapeSheet : public PropSheet {
  384. public:
  385. ShapeSheet();
  386. ~ShapeSheet();
  387. void handleEvent(Event *event);
  388. void Update();
  389. ScreenShape *shape;
  390. ComboProp *typeProp;
  391. Vector2Prop *shapeSize;
  392. BoolProp *strokeProp;
  393. ColorProp *strokeColorProp;
  394. NumberProp *strokeSize;
  395. bool lastStrokeVal;
  396. int lastShapeType;
  397. Vector2 lastShapeSize;
  398. Color lastStrokeColor;
  399. Number lastStrokeSize;
  400. };
  401. class ScreenLabelSheet : public PropSheet {
  402. public:
  403. ScreenLabelSheet();
  404. ~ScreenLabelSheet();
  405. void refreshFonts();
  406. void handleEvent(Event *event);
  407. void Update();
  408. ScreenLabel *label;
  409. ScreenLabel *lastLabel;
  410. int lastSize;
  411. String lastFont;
  412. StringProp *caption;
  413. NumberProp *size;
  414. ComboProp *font;
  415. BoolProp *enableAA;
  416. };
  417. class ScreenImageSheet : public PropSheet {
  418. public:
  419. ScreenImageSheet();
  420. ~ScreenImageSheet();
  421. void handleEvent(Event *event);
  422. void Update();
  423. ScreenImage *image;
  424. TextureProp *texture;
  425. };
  426. class ScreenSpriteSheet : public PropSheet {
  427. public:
  428. ScreenSpriteSheet();
  429. ~ScreenSpriteSheet();
  430. void handleEvent(Event *event);
  431. void Update();
  432. ScreenSprite *sprite;
  433. ScreenSpriteProp *spriteProp;
  434. ComboProp *defaultAnimationProp;
  435. ScreenSprite *lastAnimationCheck;
  436. };
  437. class ScreenEntityInstanceSheet : public PropSheet {
  438. public:
  439. ScreenEntityInstanceSheet();
  440. ~ScreenEntityInstanceSheet();
  441. void handleEvent(Event *event);
  442. void Update();
  443. ScreenEntityInstance *instance;
  444. ScreenEntityInstanceProp *instanceProp;
  445. };
  446. class ScreenEntitySheet : public PropSheet {
  447. public:
  448. ScreenEntitySheet();
  449. ~ScreenEntitySheet();
  450. void handleEvent(Event *event);
  451. void Update();
  452. NumberProp *widthProp;
  453. NumberProp *heightProp;
  454. ScreenEntity *entity;
  455. ScreenEntity *lastEntity;
  456. };
  457. class SoundSheet : public PropSheet {
  458. public:
  459. SoundSheet();
  460. ~SoundSheet();
  461. void handleEvent(Event *event);
  462. void Update();
  463. ScreenSound *sound;
  464. SoundProp *soundProp;
  465. NumberProp *referenceDistance;
  466. NumberProp *maxDistance;
  467. NumberProp *volume;
  468. NumberProp *pitch;
  469. String lastSoundPath;
  470. Number lastReferenceDistance;
  471. Number lastMaxDistance;
  472. Number lastVolume;
  473. Number lastPitch;
  474. };
  475. class ScreenParticleSheet : public PropSheet {
  476. public:
  477. ScreenParticleSheet();
  478. ~ScreenParticleSheet();
  479. void handleEvent(Event *event);
  480. void Update();
  481. TextureProp *textureProp;
  482. ComboProp *blendingProp;
  483. BoolProp *ignoreParentMatrixProp;
  484. NumberProp *numParticlesProp;
  485. NumberProp *lifespanProp;
  486. NumberProp *particleScaleProp;
  487. Vector2Prop *sizeProp;
  488. Vector2Prop *dirProp;
  489. Vector2Prop *gravProp;
  490. Vector2Prop *deviationProp;
  491. SliderProp *brightnessDeviationProp;
  492. BoolProp *perlinEnableProp;
  493. NumberProp *perlinModSizeProp;
  494. SliderProp *speedModProp;
  495. NumberProp *rotationSpeedProp;
  496. BoolProp *rotationFollowsPathProp;
  497. BoolProp *useScaleCurvesProp;
  498. BezierCurveProp *scaleCurveProp;
  499. BoolProp *useColorCurvesProp;
  500. BezierRGBACurveProp *colorCurveProp;
  501. Number lastParticleScale;
  502. Number lastRotationSpeed;
  503. Number lastNumParticles;
  504. Number lastLifespan;
  505. Vector3 lastSize;
  506. Vector3 lastDeviation;
  507. Vector3 lastDir;
  508. Vector3 lastGrav;
  509. Number lastBrightnessDeviation;
  510. bool lastEnableProp;
  511. Number lastPerlinSize;
  512. Number lastSpeedMod;
  513. bool lastIgnoreParentMatrix;
  514. bool lastRotationFollowsPath;
  515. bool lastUseScaleCurves;
  516. bool lastUseColorCurves;
  517. BezierCurve *lastScaleCurve;
  518. ScreenParticleEmitter *emitter;
  519. };
  520. class Transform2DSheet : public PropSheet {
  521. public:
  522. Transform2DSheet();
  523. ~Transform2DSheet();
  524. void handleEvent(Event *event);
  525. void Update();
  526. Vector2Prop *positionProp;
  527. Vector2Prop *scaleProp;
  528. NumberProp *rotationProp;
  529. BoolProp *topLeftProp;
  530. Vector2 lastPositon;
  531. Vector2 lastScale;
  532. Number lastRotation;
  533. int lastPositionMode;
  534. ScreenEntity *entity;
  535. };
  536. class PropList : public UIElement {
  537. public:
  538. PropList(String caption="PROPERTIES");
  539. ~PropList();
  540. void updateProps();
  541. void updateSize();
  542. void addPropSheet(PropSheet *sheet);
  543. void handleEvent(Event *event);
  544. void Resize(Number width, Number height);
  545. UIScrollContainer *scrollContainer;
  546. protected:
  547. ScreenEntity *propContents;
  548. std::vector<PropSheet*> props;
  549. ScreenShape *bg;
  550. ScreenShape *bg2;
  551. };
  552. class PolycodeEditorPropActionData : public PolycodeEditorActionData {
  553. public:
  554. PolycodeEditorPropActionData(){ entity = NULL; }
  555. virtual ~PolycodeEditorPropActionData(){
  556. delete entity;
  557. }
  558. bool boolVal;
  559. String stringVal;
  560. int intVal;
  561. Number numVal;
  562. Color colorVal;
  563. Vector3 vector3Val;
  564. Vector2 vector2Val;
  565. Entity *entity;
  566. PropSheet *sheet;
  567. PropProp *prop;
  568. };
  569. PolycodeEditorPropActionData *PropDataBool(bool val);
  570. PolycodeEditorPropActionData *PropDataInt(int val);
  571. PolycodeEditorPropActionData *PropDataNumber(Number val);
  572. PolycodeEditorPropActionData *PropDataString(String val);
  573. PolycodeEditorPropActionData *PropDataColor(Color val);
  574. PolycodeEditorPropActionData *PropDataVector3(Vector3 val);
  575. PolycodeEditorPropActionData *PropDataVector2(Vector2 val);
  576. PolycodeEditorPropActionData *PropDataEntity(Entity *entity);
  577. class PropEvent : public Event {
  578. public:
  579. PropEvent(PropProp *prop, PropSheet *sheet, PolycodeEditorPropActionData *beforeData, PolycodeEditorPropActionData *afterData);
  580. virtual ~PropEvent();
  581. void setSheet(PropSheet *sheet);
  582. PropProp *prop;
  583. PropSheet *sheet;
  584. PolycodeEditorPropActionData *beforeData;
  585. PolycodeEditorPropActionData *afterData;
  586. static const int EVENTBASE_PROPEVENT = 0xC00;
  587. static const int EVENT_PROP_CHANGE = EVENTBASE_PROPEVENT+0;
  588. };