PolycodeMaterialEditor.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  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 "PolycodeEditor.h"
  21. #include <Polycode.h>
  22. #include "PolycodeUI.h"
  23. #include "PolycodeProps.h"
  24. using namespace Polycode;
  25. class MaterialBrowserData {
  26. public:
  27. MaterialBrowserData() {
  28. material = NULL;
  29. shader = NULL;
  30. }
  31. Material *material;
  32. Shader *shader;
  33. String name;
  34. };
  35. class MaterialBrowser : public UIElement {
  36. public:
  37. MaterialBrowser();
  38. ~MaterialBrowser();
  39. void Resize(Number width, Number height);
  40. UITree * addMaterial(Material *material);
  41. UITree * addShader(Shader *shader);
  42. void handleEvent(Event *event);
  43. MaterialBrowserData *selectedData;
  44. UIImageButton *newShaderButton;
  45. UIImageButton *newMaterialButton;
  46. UITree *selectedNode;
  47. protected:
  48. ScreenShape *headerBg;
  49. UITree *shadersNode;
  50. UITree *materialsNode;
  51. UITree *cubemapsNode;
  52. UITreeContainer *treeContainer;
  53. };
  54. class ShaderEditorPane : public UIElement {
  55. public:
  56. ShaderEditorPane();
  57. ~ShaderEditorPane();
  58. void Resize(Number width, Number height);
  59. void setShader(Shader *shader);
  60. void handleEvent(Event *event);
  61. void reloadPrograms();
  62. Shader *currentShader;
  63. PolycodeProject *parentProject;
  64. protected:
  65. bool changingShader;
  66. bool choosingVertexProgram;
  67. PropList *propList;
  68. ScreenShape *headerBg;
  69. ComboProp *vertexProgramProp;
  70. ComboProp *fragmentProgramProp;
  71. StringProp *nameProp;
  72. BoolProp *screenShaderProp;
  73. NumberProp *areaLightsProp;
  74. NumberProp *spotLightsProp;
  75. };
  76. class MaterialEditorPane : public UIElement {
  77. public:
  78. MaterialEditorPane();
  79. ~MaterialEditorPane();
  80. void setMaterial(Material *material);
  81. void handleEvent(Event *event);
  82. void reloadShaders();
  83. void Resize(Number width, Number height);
  84. void showPrimitive(unsigned int index);
  85. Material *currentMaterial;
  86. protected:
  87. bool changingMaterial;
  88. ScreenShape *headerBg;
  89. ScenePrimitive *previewPrimitive;
  90. Scene *previewScene;
  91. SceneLight *mainLight;
  92. SceneLight *secondLight;
  93. SceneRenderTexture *renderTexture;
  94. ScreenShape *previewShape;
  95. std::vector<UIImageButton*> shapeSwitches;
  96. std::vector<ScenePrimitive*> shapePrimitives;
  97. ScreenImage *shapeSelector;
  98. ScreenEntity *previewBase;
  99. PropList *propList;
  100. StringProp *nameProp;
  101. ComboProp *blendModeProp;
  102. ComboProp *shaderProp;
  103. ShaderTexturesSheet *shaderTextureSheet;
  104. ShaderOptionsSheet *shaderOptionsSheet;
  105. };
  106. class MaterialMainWindow : public UIElement {
  107. public:
  108. MaterialMainWindow();
  109. ~MaterialMainWindow(){}
  110. void Resize(Number width, Number height);
  111. MaterialEditorPane *materialPane;
  112. ShaderEditorPane *shaderPane;
  113. UIColorPicker *colorPicker;
  114. };
  115. class PolycodeMaterialEditor : public PolycodeEditor {
  116. public:
  117. PolycodeMaterialEditor();
  118. virtual ~PolycodeMaterialEditor();
  119. bool openFile(OSFileEntry filePath);
  120. void Resize(int x, int y);
  121. void handleEvent(Event *event);
  122. void saveFile();
  123. String createStringValue(unsigned int type, void *value);
  124. protected:
  125. ScreenImage *editorImage;
  126. MaterialBrowser *materialBrowser;
  127. UIHSizer *mainSizer;
  128. MaterialMainWindow *mainWindow;
  129. std::vector<Material*> materials;
  130. std::vector<Shader*> shaders;
  131. UITree *selectedMaterialNode;
  132. };
  133. class PolycodeMaterialEditorFactory : public PolycodeEditorFactory {
  134. public:
  135. PolycodeMaterialEditorFactory() : PolycodeEditorFactory() { extensions.push_back("mat"); }
  136. PolycodeEditor *createEditor() { return new PolycodeMaterialEditor(); }
  137. };