2
0
Эх сурвалжийг харах

Rewrote material editor to use IDE property sheets

Ivan Safrin 12 жил өмнө
parent
commit
6c406f325a

+ 18 - 62
IDE/Contents/Include/PolycodeMaterialEditor.h

@@ -25,6 +25,7 @@
 #include "PolycodeEditor.h"
 #include <Polycode.h>
 #include "PolycodeUI.h"
+#include "PolycodeProps.h"
 
 using namespace Polycode;
 
@@ -54,11 +55,10 @@ class MaterialBrowser : public UIElement {
 		UIImageButton *newMaterialButton;
 		
 		UITree *selectedNode;
-												
+														
 	protected:
 	
 		ScreenShape *headerBg;
-	
 		UITree *shadersNode;
 		UITree *materialsNode;
 		UITree *cubemapsNode;			
@@ -66,87 +66,45 @@ class MaterialBrowser : public UIElement {
 		UITreeContainer *treeContainer;	
 };
 
-class MaterialTextureSlot : public UIElement {
-	public:
-		MaterialTextureSlot(String textureNameString);
-		~MaterialTextureSlot();
-		
-		ScreenShape *bgShape;
-		ScreenShape *imageShape;
-		
-		ScreenLabel *textureName;
-		ScreenLabel *textureFileName;	
-		
-		String textureString;
-};
-
-class MaterialPropertySlot : public UIElement {
-	public:
-		MaterialPropertySlot(ShaderBinding *binding, ProgramParam param);
-		~MaterialPropertySlot();
-		
-		void handleEvent(Event *event);
-		
-		ScreenLabel *propertyName;	
-		
-		ScreenLabel *minLabel;
-		ScreenLabel *maxLabel;
-							
-		UIHSlider *numberSlider;
-		UIColorBox *colorBox;
-					
-		ShaderBinding *binding;		
-		ProgramParam param;
-		
-		String finalName;
-		
-};
 
-class MaterialEditorPane : public UIWindow {
+class MaterialEditorPane : public UIElement {
 	public:
 		MaterialEditorPane();
 		~MaterialEditorPane();
 		
-		void setMaterial(Material *material);
-		
-		void clearAll();
-		
+		void setMaterial(Material *material);		
 		void handleEvent(Event *event);
 		
-		void handleDroppedFile(OSFileEntry file, Number x, Number y);	
-		
+		void reloadShaders();
+		void Resize(Number width, Number height);		
 		void showPrimitive(unsigned int index);
 		
-		Material *currentMaterial;
-				
+		Material *currentMaterial;			
 	protected:
 	
-	
-		std::vector<MaterialTextureSlot*> textureSlots;
-		std::vector<MaterialPropertySlot*> fragmentPropertySlots;
-	
-		ScreenEntity *textureSlotBase;
-	
+		ScreenShape *headerBg;			
 		ScenePrimitive *previewPrimitive;
 		
-		UIElement *paramsEntity;
-		
 		Scene *previewScene;
 		SceneLight *mainLight;
 		SceneLight *secondLight;		
 		SceneRenderTexture *renderTexture;
 		ScreenShape *previewShape;
 		
-		UIComboBox *shaderSelector;
-
-		UIComboBox *blendSelector;
-		
-		UITextInput *nameInput;
-		
 		std::vector<UIImageButton*> shapeSwitches;
 		std::vector<ScenePrimitive*> shapePrimitives;
 		ScreenImage *shapeSelector;
 		
+		ScreenEntity *previewBase;		
+		PropList *propList;
+		
+		StringProp *nameProp;
+		ComboProp *blendModeProp;
+		ComboProp *shaderProp;
+		
+		ShaderTexturesSheet *shaderTextureSheet;
+		ShaderOptionsSheet *vertexOptionsSheet;	
+		ShaderOptionsSheet *fragmentOptionsSheet;
 };
 
 class MaterialMainWindow : public UIElement {
@@ -168,7 +126,6 @@ class PolycodeMaterialEditor : public PolycodeEditor {
 	bool openFile(OSFileEntry filePath);
 	void Resize(int x, int y);
 	
-	void handleDroppedFile(OSFileEntry file, Number x, Number y);
 	
 	void handleEvent(Event *event);	
 	void saveFile();
@@ -176,7 +133,6 @@ class PolycodeMaterialEditor : public PolycodeEditor {
 	String createStringValue(unsigned int type, void *value);
 	
 	protected:
-		ScreenImage *grid;	
 		ScreenImage *editorImage;
 		
 		MaterialBrowser *materialBrowser;

+ 43 - 2
IDE/Contents/Include/PolycodeProps.h

@@ -32,9 +32,10 @@ using namespace Polycode;
 
 class PropProp : public UIElement {
 	public:
-		PropProp(String caption);
+		PropProp(String caption, String type);
 		~PropProp();
-		
+	
+		String propType;
 		ScreenLabel *label;
 		ScreenEntity *propContents;
 };
@@ -247,6 +248,46 @@ class PropSheet : public UIElement {
 		std::vector<PropProp*> props;
 };
 
+class ShaderOptionsSheet : public PropSheet {
+	public:
+		ShaderOptionsSheet(String title, String name, bool fragmentParams);
+		~ShaderOptionsSheet();
+		
+		void handleEvent(Event *event);
+		void Update();
+		
+		void clearShader();
+		void setOptionsFromParams(std::vector<ProgramParam> &params);
+		void setShader(Shader *shader, Material *material);
+				
+	private:
+		bool fragmentParams;
+		Shader *shader;
+		Material *material;
+		ShaderBinding *binding;
+		
+};
+
+
+class ShaderTexturesSheet : public PropSheet {
+	public:
+		ShaderTexturesSheet();
+		~ShaderTexturesSheet();
+		
+		void handleEvent(Event *event);
+		void Update();
+		
+		void clearShader();
+		void setShader(Shader *shader, Material *material);
+				
+	private:
+		Shader *shader;
+		Material *material;
+		ShaderBinding *binding;
+						
+		std::vector<TextureProp*> textureProps;
+};
+
 class EntitySheet : public PropSheet {
 	public:
 		EntitySheet();

+ 119 - 409
IDE/Contents/Source/PolycodeMaterialEditor.cpp

@@ -25,12 +25,56 @@
 extern UIColorPicker *globalColorPicker;
 extern UIGlobalMenu *globalMenu;
 
-MaterialEditorPane::MaterialEditorPane() : UIWindow("Material", 670, 250) {
+MaterialEditorPane::MaterialEditorPane() : UIElement() {	
+	
+	headerBg = new ScreenShape(ScreenShape::SHAPE_RECT,10,10);
+	addChild(headerBg);
+	headerBg->setPositionMode(ScreenEntity::POSITION_TOPLEFT);
+	headerBg->color.setColorHexFromString(CoreServices::getInstance()->getConfig()->getStringValue("Polycode", "uiHeaderBgColor"));	
+	
+	propList = new PropList("MATERIAL EDITOR");
+	addChild(propList);
+	propList->setPosition(0, 0);
 
+	PropSheet *baseProps = new PropSheet("MATERIAL SETTINGS", "");
+	propList->addPropSheet(baseProps);
+	
+	nameProp = new StringProp("Name");
+	baseProps->addProp(nameProp);	
+	nameProp->addEventListener(this, Event::CHANGE_EVENT);
+		
+	shaderProp = new ComboProp("Shader");
+	baseProps->addProp(shaderProp);
+	shaderProp->addEventListener(this, Event::CHANGE_EVENT);
+	
+	blendModeProp = new ComboProp("Blend mode");
+	baseProps->addProp(blendModeProp);
+	blendModeProp->addEventListener(this, Event::CHANGE_EVENT);
+		
+	blendModeProp->comboEntry->addComboItem("Normal");
+	blendModeProp->comboEntry->addComboItem("Lighten");
+	blendModeProp->comboEntry->addComboItem("Color");
+	blendModeProp->comboEntry->addComboItem("Premultiplied");
+	blendModeProp->comboEntry->addComboItem("Multiply");	
+	
+	baseProps->propHeight = 130;	
+	
+	shaderTextureSheet = new ShaderTexturesSheet();
+	propList->addPropSheet(shaderTextureSheet);			
+	
+	vertexOptionsSheet = new ShaderOptionsSheet("VERTEX SHADER OPTIONS", "vertex_options", false);
+	propList->addPropSheet(vertexOptionsSheet);
+
+	fragmentOptionsSheet = new ShaderOptionsSheet("FRAGMENT SHADER OPTIONS", "fragment_options", true);
+	propList->addPropSheet(fragmentOptionsSheet);
+	
+	propList->updateProps();
+						
+	// TODO: Move the preview widget to its own class
 	
 	previewScene = new Scene(true);	
 	
-	renderTexture = new SceneRenderTexture(previewScene, previewScene->getDefaultCamera(), 256, 256);
+	renderTexture = new SceneRenderTexture(previewScene, previewScene->getDefaultCamera(), 512, 512);
 	
 	ScenePrimitive *previewBg = new ScenePrimitive(ScenePrimitive::TYPE_BOX, 15.0, 15.0, 15.0);
 	previewBg->Yaw(45.0);
@@ -77,98 +121,27 @@ MaterialEditorPane::MaterialEditorPane() : UIWindow("Material", 670, 250) {
 	previewScene->getDefaultCamera()->setPosition(0,7,9);
 	previewScene->getDefaultCamera()->lookAt(Vector3());
 	
-	previewShape = new ScreenShape(ScreenShape::SHAPE_RECT, 128, 128);
+	previewBase = new ScreenEntity();
+	previewBase->processInputEvents = true;
+	previewBase->setPosition(400, 0);
+	addChild(previewBase);
+	
+	previewShape = new ScreenShape(ScreenShape::SHAPE_RECT, 256, 256);
 	previewShape->setPositionMode(ScreenEntity::POSITION_TOPLEFT);	
 	previewShape->setTexture(renderTexture->getTargetTexture());
 	previewShape->setPosition(20,40);
 	previewShape->strokeEnabled = true;
 	previewShape->strokeColor = Color(1.0, 1.0, 1.0, 0.2);
 	previewShape->setStrokeWidth(1.0);
-	addChild(previewShape);
+	previewBase->addChild(previewShape);
 	
 	Config *conf = CoreServices::getInstance()->getConfig();	
 	String fontName = conf->getStringValue("Polycode", "uiDefaultFontName");
 	int fontSize = conf->getNumericValue("Polycode", "uiDefaultFontSize");	
 	Number padding = conf->getNumericValue("Polycode", "uiWindowSkinPadding");	
 	
-	Number xPos = 165;
-	
-	ScreenLabel *label = new ScreenLabel("SHADER", 22, "section", Label::ANTIALIAS_FULL);
-	label->color.a = 0.4;
-	addChild(label);
-	label->setPosition(xPos,90);
-
-	label = new ScreenLabel("BLEND MODE", 22, "section", Label::ANTIALIAS_FULL);
-	label->color.a = 0.4;
-	addChild(label);
-	label->setPosition(xPos,150);
-
-
-	label = new ScreenLabel("NAME", 22, "section", Label::ANTIALIAS_FULL);
-	label->color.a = 0.4;		
-	addChild(label);
-	label->setPosition(xPos,30);
-
-	nameInput = new UITextInput(false, 210, 30);
-	nameInput->addEventListener(this, UIEvent::CHANGE_EVENT);
-	addChild(nameInput);
-	nameInput->setPosition(xPos, 60);
-	
-	Number yPos = 145;
-	
-	
-	yPos += 50;
-	label = new ScreenLabel("TEXTURES", 22, "section", Label::ANTIALIAS_FULL);
-	addChild(label);
-	label->color.a = 0.4;	
-	label->setPosition(xPos+230, 30);
-	label->getLabel()->setColorForRange(Color(), 0, 8);
-	label->getLabel()->setColorForRange(Color(0.5,0.5,0.5,1.0), 8, 35);
-	label->setText("TEXTURES (DRAG FROM PROJECT TO SET)");
-
-	paramsEntity = new UIElement();
-	addChild(paramsEntity);
-
-	label = new ScreenLabel("SHADER PROPERTIES", 22, "section", Label::ANTIALIAS_FULL);
-	label->color.a = 0.4;
-	paramsEntity->addChild(label);
-	paramsEntity->setPositionX(xPos+230);
-
-	textureSlotBase = new ScreenEntity();
-	addChild(textureSlotBase);
-	
-	textureSlotBase->setPosition(xPos+230, 60);
-
-	shaderSelector = new UIComboBox(globalMenu, 210);	
-	shaderSelector->addEventListener(this, UIEvent::CHANGE_EVENT);
-
-	
-	blendSelector = new UIComboBox(globalMenu, 210);	
-	blendSelector->addEventListener(this, UIEvent::CHANGE_EVENT);
-	
-	addChild(blendSelector);
-	blendSelector->setPosition(xPos, 180);
-		
-	blendSelector->addComboItem("Normal");
-	blendSelector->addComboItem("Lighten");
-	blendSelector->addComboItem("Color");
-	blendSelector->addComboItem("Premultiplied");
-	blendSelector->addComboItem("Multiply");
-	
-//	blendSelector->setSelectedIndex(0);
-							
-	MaterialManager *materialManager = CoreServices::getInstance()->getMaterialManager();
-	for(int i=0; i < materialManager->getNumShaders(); i++) {
-		if(!materialManager->getShaderByIndex(i)->screenShader) {
-			shaderSelector->addComboItem(materialManager->getShaderByIndex(i)->getName(), (void*)materialManager->getShaderByIndex(i));
-		}
-	}
-	
-	shaderSelector->setPosition(xPos, 120);
-	addChild(shaderSelector);
-	
 	shapeSelector = new ScreenImage("Images/small_selector.png");
-	addChild(shapeSelector);
+	previewBase->addChild(shapeSelector);
 	shapeSelector->color.a = 0.4;
 	
 	shapeSwitches.push_back(new UIImageButton("Images/torus_icon.png"));
@@ -177,24 +150,43 @@ MaterialEditorPane::MaterialEditorPane() : UIWindow("Material", 670, 250) {
 	shapeSwitches.push_back(new UIImageButton("Images/plane_icon.png"));
 
 	for(int i=0; i < shapeSwitches.size(); i++) {
-		addChild(shapeSwitches[i]);
-		shapeSwitches[i]->setPosition(40 + (25 * i), 180);
+		previewBase->addChild(shapeSwitches[i]);
+		shapeSwitches[i]->setPosition(105 + (25 * i), 300);
 		shapeSwitches[i]->addEventListener(this, UIEvent::CLICK_EVENT);
 	}
 				
-	currentMaterial = NULL;
-	
+	currentMaterial = NULL;	
 	showPrimitive(0);
 	
+	reloadShaders();
+	
 	enabled = false;
 }
 
+void MaterialEditorPane::reloadShaders() {
+
+	shaderProp->comboEntry->clearItems();
+
+	MaterialManager *materialManager = CoreServices::getInstance()->getMaterialManager();
+	for(int i=0; i < materialManager->getNumShaders(); i++) {
+		if(!materialManager->getShaderByIndex(i)->screenShader) {
+			shaderProp->comboEntry->addComboItem(materialManager->getShaderByIndex(i)->getName(), (void*)materialManager->getShaderByIndex(i));
+		}
+	}	
+}
+
+void MaterialEditorPane::Resize(Number width, Number height) {
+	headerBg->setShapeSize(width, 30);	
+	propList->Resize(370, height);
+	propList->updateProps();
+}
+
 void MaterialEditorPane::showPrimitive(unsigned int index) {
 	for(int i=0; i < shapePrimitives.size(); i++) {
 		shapePrimitives[i]->visible = false;	
 	}
 	shapePrimitives[index]->visible = true;	
-	shapeSelector->setPosition(38 + (25 * index), 178);
+	shapeSelector->setPosition(105 - 2 + (25 * index), 298);
 	if(currentMaterial) {
 		shapePrimitives[index]->setMaterial(currentMaterial);
 	}
@@ -202,334 +194,66 @@ void MaterialEditorPane::showPrimitive(unsigned int index) {
 }
 
 void MaterialEditorPane::handleEvent(Event *event) {
-	
-	for(int i=0; i < shapeSwitches.size(); i++) {
-		if(event->getDispatcher() == shapeSwitches[i]) {
-			if(event->getEventType() == "UIEvent" && event->getEventCode() == UIEvent::CLICK_EVENT) {
-				showPrimitive(i);
-			}
-		}
-	}
-	
-	if(event->getEventType() == "UIEvent" && event->getEventCode() == UIEvent::CHANGE_EVENT && currentMaterial) {		
-	
-		if(event->getDispatcher() == nameInput) {
-			currentMaterial->setName(nameInput->getText());
-			dispatchEvent(new Event(), Event::CHANGE_EVENT);
-		}
-	
-		if(event->getDispatcher() ==blendSelector) {			
-			currentMaterial->blendingMode = blendSelector->getSelectedIndex();
-		}
-		if(event->getDispatcher() == shaderSelector) {
-			Shader *selectedShader = (Shader*)shaderSelector->getSelectedItem()->data;
-			
-			clearAll();
-			if(selectedShader) {	
-				for(int i=0; i < selectedShader->expectedTextures.size(); i++) {
-					MaterialTextureSlot *textureSlot = new MaterialTextureSlot(selectedShader->expectedTextures[i]);
-					textureSlotBase->addChild(textureSlot);
-					textureSlot->setPosition(0, (40*i));
-					textureSlots.push_back(textureSlot);
-					
-					if(currentMaterial->getShaderBinding(0)) {
-						Texture *currentTexture = currentMaterial->getShaderBinding(0)->getTexture(selectedShader->expectedTextures[i]);
-						if(currentTexture) {
-							textureSlot->imageShape->setTexture(currentTexture);
-							std::vector<String> parts = currentTexture->getResourcePath().split("/");
-							if(parts.size() > 1) {
-								textureSlot->textureFileName->setText(parts[parts.size()-1]);
-							} else {
-								textureSlot->textureFileName->setText(currentTexture->getResourcePath());			
-							}
-						}
-					}
-				}
 
-			}
-			
-			paramsEntity->setPositionY(70 + (selectedShader->expectedTextures.size()*40));
-
-			bool replacingShader = false;
+	if(event->getDispatcher() == blendModeProp) {
+		currentMaterial->blendingMode = blendModeProp->get();
+	} else if(event->getDispatcher() == nameProp) {
+		currentMaterial->setName(nameProp->get());
+		dispatchEvent(new Event(), Event::CHANGE_EVENT);
+	} else if(event->getDispatcher() == shaderProp) {
+		Shader *selectedShader = (Shader*)shaderProp->comboEntry->getSelectedItem()->data;
+		if(selectedShader) {			
 			if(currentMaterial->getShader(0) != selectedShader) {
 				currentMaterial->clearShaders();
 				previewPrimitive->clearMaterial();
-				replacingShader = true;
-			}
-			
-			if(selectedShader) {
-				if(replacingShader) {			
-					ShaderBinding *newShaderBinding = selectedShader->createBinding();				
-					currentMaterial->addShader(selectedShader, newShaderBinding);
-					previewPrimitive->setMaterial(currentMaterial);	
-				}
 				
-				for(int i=0; i < textureSlots.size(); i++) {
-					if(textureSlots[i]->textureFileName->getText() != "None") {
-						currentMaterial->getShaderBinding(0)->clearTexture(textureSlots[i]->textureString);			
-						currentMaterial->getShaderBinding(0)->addTexture(textureSlots[i]->textureString, textureSlots[i]->imageShape->getTexture());
-					}
-				}								
-					
-				if(currentMaterial->getShaderBinding(0)) {
-				
-				int yOffset = 30;
-				
-				for(int i=0; i < selectedShader->expectedFragmentParams.size(); i++) {
-					if(!selectedShader->expectedFragmentParams[i].isAuto) {
-					MaterialPropertySlot *propertySlot = new MaterialPropertySlot(currentMaterial->getShaderBinding(0), selectedShader->expectedFragmentParams[i]);
-					paramsEntity->addChild(propertySlot);
-					propertySlot->setPosition(0, yOffset);
-					fragmentPropertySlots.push_back(propertySlot);					
-					yOffset += 45;
-				}
-				}
-								
-				for(int i=0; i < selectedShader->expectedVertexParams.size(); i++) {
-					if(!selectedShader->expectedVertexParams[i].isAuto) {
-					MaterialPropertySlot *propertySlot = new MaterialPropertySlot(currentMaterial->getShaderBinding(0), selectedShader->expectedVertexParams[i]);
-					paramsEntity->addChild(propertySlot);
-					propertySlot->setPosition(0, yOffset);
-					fragmentPropertySlots.push_back(propertySlot);					
-					yOffset += 45;					
-				}
-				}
-								
-
-				}
+				ShaderBinding *newShaderBinding = selectedShader->createBinding();				
+				currentMaterial->addShader(selectedShader, newShaderBinding);
+				previewPrimitive->setMaterial(currentMaterial);					
 			}
 			
-			int winHeight = (fragmentPropertySlots.size() * 45) + (textureSlots.size() * 40) + 100;
-
-			if(winHeight < 250)
-				winHeight = 250;
-	
-			setWindowSize(670, winHeight);			
-		}			
-	}
-	
-	
-	UIWindow::handleEvent(event);
-}
-
-void MaterialEditorPane::clearAll() {
-	for(int i=0; i < textureSlots.size(); i++) {
-		textureSlotBase->removeChild(textureSlots[i]);
-		delete textureSlots[i];
-	}
-	textureSlots.clear();
-	
-	for(int i=0; i < fragmentPropertySlots.size(); i++) {
-		paramsEntity->removeChild(fragmentPropertySlots[i]);
-		delete fragmentPropertySlots[i];
+			shaderTextureSheet->setShader(selectedShader, currentMaterial);
+			vertexOptionsSheet->setShader(selectedShader, currentMaterial);
+			fragmentOptionsSheet->setShader(selectedShader, currentMaterial);						
+		}
 	}
-	fragmentPropertySlots.clear();									
-}
-
-void MaterialEditorPane::handleDroppedFile(OSFileEntry file, Number x, Number y) {
-	Vector2 screenPos = textureSlotBase->getScreenPosition();
 	
-	x = x - screenPos.x;
-	y = y - screenPos.y;
-		
-	for(int i=0; i < textureSlots.size(); i++) {
-		if(x > textureSlots[i]->getPosition().x && x < textureSlots[i]->getPosition().x + textureSlots[i]->getWidth() && 
-		y > textureSlots[i]->getPosition().y && y < textureSlots[i]->getPosition().y + textureSlots[i]->getHeight()) {
-			Texture *newTexture = CoreServices::getInstance()->getMaterialManager()->createTextureFromFile(file.fullPath);
-			textureSlots[i]->imageShape->setTexture(newTexture);
-			textureSlots[i]->textureFileName->setText(file.name);
-			currentMaterial->getShaderBinding(0)->clearTexture(textureSlots[i]->textureString);			
-			currentMaterial->getShaderBinding(0)->addTexture(textureSlots[i]->textureString, newTexture);
-			
+	for(int i=0; i < shapeSwitches.size(); i++) {
+		if(event->getDispatcher() == shapeSwitches[i]) {
+			if(event->getEventType() == "UIEvent" && event->getEventCode() == UIEvent::CLICK_EVENT) {
+				showPrimitive(i);
+			}
 		}
-	}	
+	}
 }
 
 void MaterialEditorPane::setMaterial(Material *material) {
 	currentMaterial = material;
-	previewPrimitive->setMaterial(material);
-		
-	clearAll();	
+	previewPrimitive->setMaterial(material);		
 	
-	if(!currentMaterial) // ???
-		return;		
+	if(!currentMaterial)
+		return;
 	
-	enabled = true;
-	
-	blendSelector->setSelectedIndex(currentMaterial->blendingMode);
-					
-	if(currentMaterial->getShader(0)) {		
+	blendModeProp->set(currentMaterial->blendingMode);
 	
-	for(int i=0; i < shaderSelector->getNumItems(); i++) {
-		Shader *shader = (Shader*)shaderSelector->getItemAtIndex(i)->data;
+	if(currentMaterial->getShader(0)) {	
+	for(int i=0; i < shaderProp->comboEntry->getNumItems(); i++) {
+		Shader *shader = (Shader*)shaderProp->comboEntry->getItemAtIndex(i)->data;
 		if(shader) {
 			if(currentMaterial->getShader(0)->getName() == shader->getName()) {
-				shaderSelector->setSelectedIndex(i);
+				shaderProp->set(i);
 				break;
 			}
 		}
 	}
 	} else {
-		shaderSelector->setSelectedIndex(0);	
-	}
-	
-	nameInput->setText(currentMaterial->getName());
-}
-
-MaterialPropertySlot::MaterialPropertySlot(ShaderBinding *binding, ProgramParam param) : UIElement() {
-
-	setWidth(280);
-	setHeight(43);
-
-	this->param = param;
-	this->binding = binding;
-	
-	std::vector<String> stringParts = param.name.split("_");
-	
-	if(stringParts.size() > 0) {
-		for(int i=0; i < stringParts.size(); i++) {
-			finalName += stringParts[i].substr(0,1).toUpperCase() + stringParts[i].substr(1) + " ";	
-		}
-	} else {
-		finalName = param.name.substr(0,1).toUpperCase() + param.name.substr(1);
-	}
-	
-	Config *conf = CoreServices::getInstance()->getConfig();	
-	String fontName = conf->getStringValue("Polycode", "uiDefaultFontName");
-	int fontSize = conf->getNumericValue("Polycode", "uiDefaultFontSize");	
-	Number padding = conf->getNumericValue("Polycode", "uiWindowSkinPadding");		
-
-	propertyName = new ScreenLabel(finalName, fontSize, fontName, Label::ANTIALIAS_FULL);
-	propertyName->setColor(1.0, 1.0, 1.0, 0.7);		
-	addChild(propertyName);
-	
-	numberSlider = NULL;	
-	colorBox = NULL;
+		shaderProp->set(0);
+	}	
 	
-	minLabel = NULL;
-	maxLabel = NULL;
+	nameProp->set(currentMaterial->getName());
 	
-	switch(param.paramType) {
-		case ProgramParam::PARAM_Number:
-		{
-			
-			Number minVal = (*(Number*)param.minValue);
-			minLabel = new ScreenLabel(String::NumberToString(minVal), fontSize, fontName, Label::ANTIALIAS_FULL);
-			minLabel->setColor(1.0, 1.0, 1.0, 0.3);		
-			addChild(minLabel);			
-			minLabel->setPosition(0.0, 18);
-
-			Number maxVal = (*(Number*)param.maxValue);
-			maxLabel = new ScreenLabel(String::NumberToString(maxVal), fontSize, fontName, Label::ANTIALIAS_FULL);
-			maxLabel->setColor(1.0, 1.0, 1.0, 0.3);		
-			addChild(maxLabel);			
-			maxLabel->setPosition(240, 18);
-
-			numberSlider = new UIHSlider(minVal, maxVal, 180);
-			addChild(numberSlider);
-			numberSlider->setPosition(50, 23);
-			numberSlider->addEventListener(this, UIEvent::CHANGE_EVENT);
-//			binding->addLocalParam(param.name, &numberValue);
-
-			Number numberValue = (*(Number*)binding->getLocalParamByName(param.name)->data);
-			numberSlider->setSliderValue(numberValue);
+	enabled = true;
 					
-			propertyName->setText(finalName+"("+String::NumberToString(numberValue)+")");
-
-		}
-		break;
-		case ProgramParam::PARAM_Color:
-			Color colorValue = ((*(Color*)binding->getLocalParamByName(param.name)->data));
-			colorBox = new UIColorBox(globalColorPicker, colorValue, 30, 23);
-			colorBox->addEventListener(this, UIEvent::CHANGE_EVENT);			
-			colorBox->setPosition(0.0, 18);
-//			binding->addLocalParam(param.name, &colorValue);			
-			addChild(colorBox);
-		break;
-	}
-}
-
-void MaterialPropertySlot::handleEvent(Event *event) {
-	if(event->getEventType() == "UIEvent" && event->getEventCode() == UIEvent::CHANGE_EVENT) {
-		if(event->getDispatcher() == numberSlider) {
-			propertyName->setText(finalName+"("+String::NumberToString(numberSlider->getSliderValue())+")");
-			(*(Number*)binding->getLocalParamByName(param.name)->data) = numberSlider->getSliderValue();
-		}
-		
-		if(event->getDispatcher() == colorBox) {
-			(*(Color*)binding->getLocalParamByName(param.name)->data) = colorBox->getSelectedColor();
-		}
-	}
-}
-
-MaterialPropertySlot::~MaterialPropertySlot() {
-	
-	delete propertyName;
-	
-	if(minLabel)
-		delete minLabel;
-	if(maxLabel)
-		delete maxLabel;
-
-	if(colorBox) {
-		delete colorBox;
-	}
-	
-	if(numberSlider)
-		delete numberSlider;
-}
-
-MaterialTextureSlot::MaterialTextureSlot(String textureNameString) : UIElement() {
-
-	setWidth(280);
-	setHeight(38);
-	
-	textureString = textureNameString;
-	
-	bgShape  = new ScreenShape(ScreenShape::SHAPE_RECT, 280,38);
-	bgShape->setColor(0.0, 0.0, 0.0, 0.4);
-	bgShape->setPositionMode(ScreenEntity::POSITION_TOPLEFT);
-	addChild(bgShape);
-
-	imageShape = new ScreenShape(ScreenShape::SHAPE_RECT, 32,32);
-	imageShape->setPositionMode(ScreenEntity::POSITION_TOPLEFT);
-	imageShape->setPosition(3,3);
-	addChild(imageShape);
-	
-	Config *conf = CoreServices::getInstance()->getConfig();	
-	String fontName = conf->getStringValue("Polycode", "uiDefaultFontName");
-	int fontSize = conf->getNumericValue("Polycode", "uiDefaultFontSize");	
-	Number padding = conf->getNumericValue("Polycode", "uiWindowSkinPadding");	
-	
-	std::vector<String> stringParts = textureNameString.split("_");
-	
-	String finalName;
-	if(stringParts.size() > 0) {
-		for(int i=0; i < stringParts.size(); i++) {
-			finalName += stringParts[i].substr(0,1).toUpperCase() + stringParts[i].substr(1) + " ";	
-		}
-	} else {
-		finalName = textureNameString.substr(0,1).toUpperCase() + textureNameString.substr(1);
-	}
-	
-	textureName = new ScreenLabel(finalName, fontSize, fontName, Label::ANTIALIAS_FULL);
-	textureName->setPosition(40, 3);
-	textureName->setColor(1.0, 1.0, 1.0, 0.5);		
-	addChild(textureName);
-
-	textureFileName = new ScreenLabel("None", fontSize, fontName, Label::ANTIALIAS_FULL);
-	textureFileName->setPosition(40, 20);
-	textureFileName->setColor(1.0, 1.0, 1.0, 0.8);		
-	addChild(textureFileName);
-
-}
-
-MaterialTextureSlot::~MaterialTextureSlot() {
-	delete bgShape;
-	delete imageShape;
-		
-	delete textureName;
-	delete textureFileName;		
 }
 
 MaterialEditorPane::~MaterialEditorPane() {
@@ -540,15 +264,13 @@ MaterialMainWindow::MaterialMainWindow() : UIElement() {
 
 	materialPane = new MaterialEditorPane();
 	addChild(materialPane);
-	
 	enableScissor = true;
 }
 	
-void MaterialMainWindow::Resize(Number width, Number height) {
-	materialPane->setPosition((width-materialPane->getWidth())/2.0, (height-materialPane->getHeight())/2.0);
-	
+void MaterialMainWindow::Resize(Number width, Number height) {	
 	Vector2 pos = getScreenPosition();	
 	scissorBox.setRect(pos.x,pos.y,width, height);
+	materialPane->Resize(width, height);
 }
 
 MaterialBrowser::MaterialBrowser() : UIElement() {
@@ -568,7 +290,8 @@ MaterialBrowser::MaterialBrowser() : UIElement() {
 	headerBg = new ScreenShape(ScreenShape::SHAPE_RECT,10,10);
 	addChild(headerBg);
 	headerBg->setPositionMode(ScreenEntity::POSITION_TOPLEFT);
-	headerBg->setColor(0.1, 0.1, 0.1, 1.0);
+	headerBg->color.setColorHexFromString(CoreServices::getInstance()->getConfig()->getStringValue("Polycode", "uiHeaderBgColor"));	
+
 	
 	newMaterialButton = new UIImageButton("Images/new_material.png");
 	addChild(newMaterialButton);
@@ -605,10 +328,9 @@ MaterialBrowser::~MaterialBrowser() {
 }
 
 void MaterialBrowser::Resize(Number width, Number height) {
-	treeContainer->Resize(width, height-32);
-	treeContainer->setPosition(0, 32);
-	
-	headerBg->setShapeSize(width, 32);	
+	treeContainer->Resize(width, height-30);
+	treeContainer->setPosition(0, 30);	
+	headerBg->setShapeSize(width, 30);	
 }
 
 PolycodeMaterialEditor::PolycodeMaterialEditor() : PolycodeEditor(true){
@@ -621,14 +343,7 @@ PolycodeMaterialEditor::~PolycodeMaterialEditor() {
 
 bool PolycodeMaterialEditor::openFile(OSFileEntry filePath) {
 	
-	
-	grid = new ScreenImage("Images/editorGrid.png");
-	
-	addChild(grid);
-	grid->snapToPixels = true;	
-	grid->getTexture()->clamp = false;
-	grid->getTexture()->recreateFromImageData();	
-	
+		
 	mainSizer = new UIHSizer(100,100,200,false);
 	addChild(mainSizer);	
 	
@@ -654,10 +369,6 @@ bool PolycodeMaterialEditor::openFile(OSFileEntry filePath) {
 	return true;
 }
 
-void PolycodeMaterialEditor::handleDroppedFile(OSFileEntry file, Number x, Number y) {		
-	mainWindow->materialPane->handleDroppedFile(file, x,y);
-}
-
 String PolycodeMaterialEditor::createStringValue(unsigned int type, void *value) {
 	String retString;
 	
@@ -779,7 +490,6 @@ void PolycodeMaterialEditor::handleEvent(Event *event) {
 }
 
 void PolycodeMaterialEditor::Resize(int x, int y) {
-	grid->setImageCoordinates(0,0,x,y);	
 	mainSizer->Resize(x,y);
 	PolycodeEditor::Resize(x,y);
 }

+ 187 - 15
IDE/Contents/Source/PolycodeProps.cpp

@@ -206,7 +206,9 @@ void PropSheet::addProp(PropProp *prop) {
 	Resize(width, height);
 }
 
-PropProp::PropProp(String caption) : UIElement() {
+PropProp::PropProp(String caption, String type) : UIElement() {
+
+	propType = type;
 	label = new ScreenLabel(caption, 12);
 	label->color.a = 0.4;
 	label->setPosition(0, 5);
@@ -224,7 +226,7 @@ PropProp::~PropProp() {
 
 }
 
-Vector2Prop::Vector2Prop(String caption) : PropProp(caption) {
+Vector2Prop::Vector2Prop(String caption) : PropProp(caption, "Vector2") {
 
 	ScreenLabel *label = new ScreenLabel("X:", 11);
 	label->color.a = 0.4;
@@ -275,7 +277,7 @@ Vector2Prop::~Vector2Prop() {
 
 }
 
-CustomProp::CustomProp(String key, String value) : PropProp("") {
+CustomProp::CustomProp(String key, String value) : PropProp("", "Custom") {
 	keyEntry = new UITextInput(false, 120, 12);
 	keyEntry->setText(key);
 	keyEntry->addEventListener(this, UIEvent::CHANGE_EVENT);
@@ -327,7 +329,7 @@ String CustomProp::getKey() {
 }
 
 
-StringProp::StringProp(String caption) : PropProp(caption) {
+StringProp::StringProp(String caption) : PropProp(caption, "String") {
 
 	stringEntry = new UITextInput(false, 150, 12);
 	stringEntry->addEventListener(this, UIEvent::CHANGE_EVENT);
@@ -359,7 +361,7 @@ StringProp::~StringProp() {
 
 }
 
-SliderProp::SliderProp(String caption, Number min, Number max) : PropProp(caption) {
+SliderProp::SliderProp(String caption, Number min, Number max) : PropProp(caption, "Slider") {
 
 	slider = new UIHSlider(min, max, 100);
 	slider->addEventListener(this, UIEvent::CHANGE_EVENT);
@@ -398,7 +400,7 @@ SliderProp::~SliderProp() {
 
 }
 
-NumberProp::NumberProp(String caption) : PropProp(caption) {
+NumberProp::NumberProp(String caption) : PropProp(caption, "Number") {
 
 	numberEntry = new UITextInput(false, 50, 12);
 	numberEntry->addEventListener(this, UIEvent::CHANGE_EVENT);
@@ -432,7 +434,7 @@ NumberProp::~NumberProp() {
 
 }
 
-ColorProp::ColorProp(String caption) : PropProp(caption) {
+ColorProp::ColorProp(String caption) : PropProp(caption, "Color") {
 
 	colorEntry = new UIColorBox(globalColorPicker, Color(), 45, 25);
 	colorEntry->addEventListener(this, UIEvent::CHANGE_EVENT);
@@ -463,7 +465,7 @@ ColorProp::~ColorProp() {
 
 }
 
-ComboProp::ComboProp(String caption) : PropProp(caption) {
+ComboProp::ComboProp(String caption) : PropProp(caption, "Combo") {
 
 	comboEntry = new UIComboBox(globalMenu, 150);
 	comboEntry->addEventListener(this, UIEvent::CHANGE_EVENT);
@@ -494,7 +496,7 @@ ComboProp::~ComboProp() {
 
 }
 
-BoolProp::BoolProp(String caption) : PropProp(caption) {
+BoolProp::BoolProp(String caption) : PropProp(caption, "Bool") {
 
 	checkEntry = new UICheckBox("", false);
 	checkEntry->addEventListener(this, UIEvent::CHANGE_EVENT);
@@ -526,7 +528,7 @@ BoolProp::~BoolProp() {
 }
 
 
-SoundProp::SoundProp(String caption) : PropProp(caption){
+SoundProp::SoundProp(String caption) : PropProp(caption, "Sound"){
 
 	soundFile = new ScreenLabel("", 11);
 	soundFile->setPosition(0, 5);
@@ -599,7 +601,7 @@ String SoundProp::get() {
 	return "";
 }
 
-BezierRGBACurveProp::BezierRGBACurveProp(String caption) : PropProp(caption) {
+BezierRGBACurveProp::BezierRGBACurveProp(String caption) : PropProp(caption, "BezierRGBA") {
 
 
 	changeButton = new UIButton("Edit", 120);
@@ -632,7 +634,7 @@ void BezierRGBACurveProp::handleEvent(Event *event) {
 	}
 }
 
-BezierCurveProp::BezierCurveProp(String caption, String curveName) : PropProp(caption) {
+BezierCurveProp::BezierCurveProp(String caption, String curveName) : PropProp(caption, "BezierCurve") {
 
 	this->curveName = curveName;
 
@@ -660,7 +662,7 @@ void BezierCurveProp::handleEvent(Event *event) {
 	}
 }
 
-TextureProp::TextureProp(String caption) : PropProp(caption){
+TextureProp::TextureProp(String caption) : PropProp(caption, "Texture"){
 	previewShape = new ScreenShape(ScreenShape::SHAPE_RECT, 48, 48);
 	previewShape->setPositionMode(ScreenEntity::POSITION_TOPLEFT);
 	previewShape->setPosition(2, 1);
@@ -708,7 +710,7 @@ void TextureProp::set(Texture *texture) {
 Texture* TextureProp::get() {
 	return previewShape->getTexture();
 }
-ScreenSpriteProp::ScreenSpriteProp(String caption) : PropProp(caption){
+ScreenSpriteProp::ScreenSpriteProp(String caption) : PropProp(caption, "ScreenSprite"){
 
 		previewSprite = new ScreenSprite("default/default.sprite");
 		previewSprite->setPositionMode(ScreenEntity::POSITION_TOPLEFT);
@@ -780,7 +782,7 @@ String ScreenSpriteProp::get() {
 	return previewSprite->getFileName();
 }
 
-ScreenEntityInstanceProp::ScreenEntityInstanceProp(String caption) : PropProp(caption){
+ScreenEntityInstanceProp::ScreenEntityInstanceProp(String caption) : PropProp(caption, "ScreenEntityInstance"){
 	previewInstance = new ScreenEntityInstance("default/default.entity2d");
 	previewInstance->setPositionMode(ScreenEntity::POSITION_TOPLEFT);
 	previewInstance->setPosition(2, 1);
@@ -1046,6 +1048,176 @@ void EntityPropSheet::Update() {
 	}
 }
 
+ShaderOptionsSheet::ShaderOptionsSheet(String title, String name, bool fragmentParams) : PropSheet(title, name){
+	shader = NULL;
+	this->fragmentParams = fragmentParams;
+	propHeight = 40;
+}
+
+ShaderOptionsSheet::~ShaderOptionsSheet() {
+
+}
+
+void ShaderOptionsSheet::handleEvent(Event *event) {
+
+	if(event->getEventCode() == Event::CHANGE_EVENT) {
+		for(int i=0 ; i < props.size(); i++) {
+			if(event->getDispatcher() == props[i]) {
+				if(props[i]->propType == "Slider") {
+					(*(Number*)binding->getLocalParamByName(props[i]->label->getText())->data) = ((SliderProp*)props[i])->get();
+				} else if(props[i]->propType == "Color") {
+					(*(Color*)binding->getLocalParamByName(props[i]->label->getText())->data) = ((ColorProp*)props[i])->get();
+				
+				}
+				return;
+			}
+		}
+	}
+
+	PropSheet::handleEvent(event);
+}
+
+void ShaderOptionsSheet::Update() {
+
+}
+
+void ShaderOptionsSheet::clearShader() {
+	for(int i=0; i < props.size(); i++) {
+		contents->removeChild(props[i]);
+		props[i]->removeAllHandlersForListener(this);
+		delete props[i];
+	}
+	props.clear();
+	propHeight = 30;
+}
+
+void ShaderOptionsSheet::setOptionsFromParams(std::vector<ProgramParam> &params) {
+
+	for(int i=0; i < params.size(); i++) {
+			if(!params[i].isAuto) {
+				switch (params[i].paramType) {
+				
+					case ProgramParam::PARAM_Number:
+					{
+						String paramName = params[i].name;
+						Number paramMin = (*(Number*) params[i].minValue);
+						Number paramMax = (*(Number*) params[i].maxValue);						
+						SliderProp *sliderProp = new SliderProp(paramName, paramMin, paramMax);
+						addProp(sliderProp);
+						
+						Number numberValue = (*(Number*)binding->getLocalParamByName(params[i].name)->data);
+						sliderProp->set(numberValue);
+						propHeight += 30;						
+					}
+					break;					
+					case ProgramParam::PARAM_Color:
+					{
+						String paramName = params[i].name;
+						
+						ColorProp *colorProp = new ColorProp(paramName);
+						addProp(colorProp);
+						
+						Color colorValue = (*(Color*)binding->getLocalParamByName(params[i].name)->data);
+						colorProp->set(colorValue);
+						
+						propHeight += 40;						
+					}
+					break;
+					
+				}				
+														
+			}
+		}	
+}
+
+void ShaderOptionsSheet::setShader(Shader *shader, Material *material) {
+	clearShader();
+	this->shader = shader;
+	this->material = material;
+	
+	if(!shader || !material)
+		return;
+		
+	binding = material->getShaderBinding(0);
+	
+	if(fragmentParams) {	
+		setOptionsFromParams(shader->expectedFragmentParams);
+	} else {
+		setOptionsFromParams(shader->expectedVertexParams);
+	}
+	
+	dispatchEvent(new Event(), Event::COMPLETE_EVENT);	
+	Resize(width, height);
+}
+
+ShaderTexturesSheet::ShaderTexturesSheet() : PropSheet("SHADER TEXTURES", "shader_textures"){
+	shader = NULL;
+	propHeight = 40;
+}
+
+ShaderTexturesSheet::~ShaderTexturesSheet() {
+
+}
+
+void ShaderTexturesSheet::handleEvent(Event *event) {
+
+	if(event->getEventCode() == Event::CHANGE_EVENT) {
+		for(int i=0; i < textureProps.size(); i++) {
+			if(event->getDispatcher() == textureProps[i]) {
+				binding->clearTexture(textureProps[i]->label->getText());
+				binding->addTexture(textureProps[i]->label->getText(), textureProps[i]->get());
+			}
+		}	
+	}
+	PropSheet::handleEvent(event);
+}
+
+void ShaderTexturesSheet::Update() {
+
+}
+
+void ShaderTexturesSheet::clearShader() {
+	for(int i=0; i < props.size(); i++) {
+		contents->removeChild(props[i]);
+		props[i]->removeAllHandlersForListener(this);
+		delete props[i];
+	}
+	props.clear();
+	textureProps.clear();
+	
+	propHeight = 30;
+}
+
+void ShaderTexturesSheet::setShader(Shader *shader, Material *material) {
+	clearShader();
+	this->shader = shader;
+	this->material = material;
+	
+	if(!shader || !material)
+		return;
+		
+	binding = material->getShaderBinding(0);	
+	
+	for(int i=0; i < shader->expectedTextures.size(); i++) {
+		TextureProp *textureProp = new TextureProp(shader->expectedTextures[i]);
+		
+		if(material) {
+			if(material->getShaderBinding(0)) {
+				Texture *currentTexture = material->getShaderBinding(0)->getTexture(shader->expectedTextures[i]);
+				if(currentTexture) {
+					textureProp->set(currentTexture);
+				}
+			}
+		}
+		
+		addProp(textureProp);
+		textureProps.push_back(textureProp);
+		propHeight += 65;
+	}
+
+	dispatchEvent(new Event(), Event::COMPLETE_EVENT);	
+	Resize(width, height);
+}
 
 EntitySheet::EntitySheet() : PropSheet("ENTITY", "entity"){
 	idProp = new StringProp("ID");