Răsfoiți Sursa

UI HSlider fixes and UI Color picker

Ivan Safrin 14 ani în urmă
părinte
comite
027d9462f5
30 a modificat fișierele cu 840 adăugiri și 63 ștergeri
  1. 21 0
      Core/Contents/Include/PolyColor.h
  2. 4 1
      Core/Contents/Include/PolyGlobals.h
  3. 1 1
      Core/Contents/Include/PolyMesh.h
  4. 1 1
      Core/Contents/Include/PolyScreenMesh.h
  5. 52 0
      Core/Contents/Source/PolyColor.cpp
  6. 0 1
      Core/Contents/Source/PolyMesh.cpp
  7. 3 1
      IDE/Contents/Include/PolycodeProjectEditor.h
  8. BIN
      IDE/Contents/Resources/UIThemes/default/colorPickerHue.png
  9. BIN
      IDE/Contents/Resources/UIThemes/default/colorPickerHueSelector.png
  10. BIN
      IDE/Contents/Resources/UIThemes/default/colorPickerMainBg.png
  11. BIN
      IDE/Contents/Resources/UIThemes/default/colorPickerMainFrame.png
  12. BIN
      IDE/Contents/Resources/UIThemes/default/colorPickerTarget.png
  13. BIN
      IDE/Contents/Resources/UIThemes/default/colorboxBg.png
  14. BIN
      IDE/Contents/Resources/UIThemes/default/colorboxFrame.png
  15. BIN
      IDE/Contents/Resources/UIThemes/default/hsliderBg.png
  16. BIN
      IDE/Contents/Resources/UIThemes/default/hsliderHandle.png
  17. 29 6
      IDE/Contents/Resources/UIThemes/default/theme.xml
  18. BIN
      IDE/Contents/Resources/UIThemes/default/windowBg.png
  19. 84 10
      IDE/Contents/Source/PolycodeProjectEditor.cpp
  20. 2 0
      Modules/Contents/UI/CMakeLists.txt
  21. 105 0
      Modules/Contents/UI/Include/PolyUIColorBox.h
  22. 1 0
      Modules/Contents/UI/Include/PolyUIComboBox.h
  23. 5 6
      Modules/Contents/UI/Include/PolyUIHSlider.h
  24. 4 0
      Modules/Contents/UI/Include/PolyUITextInput.h
  25. 1 0
      Modules/Contents/UI/Include/PolycodeUI.h
  26. 444 0
      Modules/Contents/UI/Source/PolyUIColorBox.cpp
  27. 9 2
      Modules/Contents/UI/Source/PolyUIComboBox.cpp
  28. 53 26
      Modules/Contents/UI/Source/PolyUIHSlider.cpp
  29. 18 8
      Modules/Contents/UI/Source/PolyUITextInput.cpp
  30. 3 0
      Modules/Contents/UI/Source/PolyUIWindow.cpp

+ 21 - 0
Core/Contents/Include/PolyColor.h

@@ -152,6 +152,27 @@ namespace Polycode {
 			*/
 			Number getBrightness() const;
 			
+			static void RGBtoHSV(const Number &r, const Number &g, const Number &b, Number &h, Number &s, Number &v);
+			
+			/**
+			* Returns the hue of the color's HSV component.
+			* @return HSV Hue.
+			*/
+			Number getHue() const;
+
+			/**
+			* Returns the saturation of the color's HSV component.
+			* @return HSV Saturation
+			*/
+			Number getSaturation() const;
+
+			/**
+			* Returns the value of the color's HSV component
+			* @return HSV Value
+			*/
+			Number getValue() const;
+
+			
 			/**
 			* Returns the color as a 32-bit usigned integer.
 			* @return Color as a single 32-bit unsigned integer.

+ 4 - 1
Core/Contents/Include/PolyGlobals.h

@@ -68,7 +68,10 @@ THE SOFTWARE.
 	#define PLATFORM PLATFORM_UNIX
 #endif
 
+typedef double Number;
+
+#define MIN(a, b)  (((a) < (b)) ? (a) : (b))
+#define MAX(a, b)  (((a) > (b)) ? (a) : (b))
 
 
-typedef double Number;
 

+ 1 - 1
Core/Contents/Include/PolyMesh.h

@@ -23,12 +23,12 @@ THE SOFTWARE.
 #pragma once
 #include "PolyGlobals.h"
 #include "PolyVertex.h"
+#include "PolyPolygon.h"
 
 class OSFILE;
 
 namespace Polycode {
 	
-	class Polygon;
 	class String;
 
 	class _PolyExport VertexSorter {

+ 1 - 1
Core/Contents/Include/PolyScreenMesh.h

@@ -23,11 +23,11 @@ THE SOFTWARE.
 #pragma once
 #include "PolyGlobals.h"
 #include "PolyScreenEntity.h"
+#include "PolyMesh.h"
 
 namespace Polycode {
 
 	class Image;
-	class Mesh;
 	class Texture;
 
 	/**

+ 52 - 0
Core/Contents/Source/PolyColor.cpp

@@ -75,6 +75,58 @@ Number Color::getBrightness() const {
 	return (r+g+b) / 3.0f;
 }
 
+void Color::RGBtoHSV(const Number &r, const Number &g, const Number &b, Number &h, Number &s, Number &v) {
+
+	double min, max;
+	double delta;
+
+	min = MIN(r, g);
+	min = MIN(min, b);
+	max = MAX(r, g);
+	max = MAX(max, b);
+
+    v = max;
+
+	s = (max != 0) ? (max - min) / max : 0;
+
+	if (s == 0) {
+                h = 0;
+	} else {
+		delta = max - min;
+		if (r == max) {
+			h = (g - b) / delta;
+		} else if (g == max) {
+			h = 2 + (b - r) / delta;
+		} else if (b == max) {
+			h = 4 + (r - g) / delta;
+		}
+
+		h *= 60;
+		if(h < 0) {
+			h += 360;
+		}
+	}
+}
+
+
+Number Color::getHue() const {
+	Number h,s,v;
+	Color::RGBtoHSV(r,g,b, h,s,v);
+	return h;
+}
+
+Number Color::getSaturation() const {
+	Number h,s,v;
+	Color::RGBtoHSV(r,g,b, h,s,v);
+	return s;
+}
+
+Number Color::getValue() const {
+	Number h,s,v;
+	Color::RGBtoHSV(r,g,b, h,s,v);
+	return v;
+}
+
 void Color::setColorHSV(Number H, Number S, Number V) {
 	Number r,g,b;
     

+ 0 - 1
Core/Contents/Source/PolyMesh.cpp

@@ -22,7 +22,6 @@
 
 #include "PolyMesh.h"
 #include "PolyLogger.h"
-#include "PolyPolygon.h"
 #include "OSBasics.h"
 
 using std::min;

+ 3 - 1
IDE/Contents/Include/PolycodeProjectEditor.h

@@ -44,10 +44,12 @@ class PolycodeProjectEditor : public PolycodeEditor {
 	UIWindow *mainSettingsWindow;	
 	UITextInput *defaultWidthInput;
 	UITextInput *defaultHeightInput;	
-	//UIHSlider *aaLevelInput;	
+	UITextInput *framerateInput;	
 	UIComboBox *aaLevelComboBox;
 	UIComboBox *afLevelComboBox;	
 	UITextInput *entryPointInput;	
+	UIColorBox *bgColorBox;
+	
 };
 
 class PolycodeProjectEditorFactory : public PolycodeEditorFactory {

BIN
IDE/Contents/Resources/UIThemes/default/colorPickerHue.png


BIN
IDE/Contents/Resources/UIThemes/default/colorPickerHueSelector.png


BIN
IDE/Contents/Resources/UIThemes/default/colorPickerMainBg.png


BIN
IDE/Contents/Resources/UIThemes/default/colorPickerMainFrame.png


BIN
IDE/Contents/Resources/UIThemes/default/colorPickerTarget.png


BIN
IDE/Contents/Resources/UIThemes/default/colorboxBg.png


BIN
IDE/Contents/Resources/UIThemes/default/colorboxFrame.png


BIN
IDE/Contents/Resources/UIThemes/default/hsliderBg.png


BIN
IDE/Contents/Resources/UIThemes/default/hsliderHandle.png


+ 29 - 6
IDE/Contents/Resources/UIThemes/default/theme.xml

@@ -44,16 +44,16 @@
 
 	<uiWindowSkin>windowBg.png</uiWindowSkin>
 	<uiWindowSkinT>29</uiWindowSkinT>
-	<uiWindowSkinR>3</uiWindowSkinR>
-	<uiWindowSkinB>3</uiWindowSkinB>
-	<uiWindowSkinL>3</uiWindowSkinL>
-	<uiWindowSkinPadding>10</uiWindowSkinPadding>		
+	<uiWindowSkinR>8</uiWindowSkinR>
+	<uiWindowSkinB>8</uiWindowSkinB>
+	<uiWindowSkinL>8</uiWindowSkinL>
+	<uiWindowSkinPadding>15</uiWindowSkinPadding>		
 	<uiWindowTitleFont>sans</uiWindowTitleFont>
 	<uiWindowTitleFontSize>12</uiWindowTitleFontSize>
-	<uiWindowTitleX>5</uiWindowTitleX>	
+	<uiWindowTitleX>10</uiWindowTitleX>	
 	<uiWindowTitleY>7</uiWindowTitleY>		
 	<uiWindowCloseIcon>closeIcon.png</uiWindowCloseIcon>
-	<uiCloseIconX>6</uiCloseIconX>	
+	<uiCloseIconX>11</uiCloseIconX>	
 	<uiCloseIconY>7</uiCloseIconY>		
 
 	<uiScrollBgSkin>scrollBg.png</uiScrollBgSkin>
@@ -107,4 +107,27 @@
 	<uiComboBoxSelectorBgL>3</uiComboBoxSelectorBgL>					
 	<uiComboBoxTextOffsetX>7</uiComboBoxTextOffsetX>
 	<uiComboBoxTextOffsetY>3</uiComboBoxTextOffsetY>		
+
+	<uiColorBoxFrameImage>colorboxFrame.png</uiColorBoxFrameImage>
+	<uiColorBoxFrameImageT>3</uiColorBoxFrameImageT>
+	<uiColorBoxFrameImageR>3</uiColorBoxFrameImageR>
+	<uiColorBoxFrameImageB>3</uiColorBoxFrameImageB>
+	<uiColorBoxFrameImageL>3</uiColorBoxFrameImageL>					
+	<uiColorBoxBgImage>colorboxBg.png</uiColorBoxBgImage>
+	<uiFrameInset>1</uiFrameInset>
+
+	<uiColorPickerMainBg>colorPickerMainBg.png</uiColorPickerMainBg>
+	<uiColorPickerMainFrame>colorPickerMainFrame.png</uiColorPickerMainFrame>
+	<uiColorPickerHueFrame>colorPickerHue.png</uiColorPickerHueFrame>
+	<uiColorPickerHueSelector>colorPickerHueSelector.png</uiColorPickerHueSelector>
+	<uiColorPickerMainSelector>colorPickerTarget.png</uiColorPickerMainSelector>
+
+	<uiHSliderGrip>hsliderHandle.png</uiHSliderGrip>
+	<uiHSliderBg>hsliderBg.png</uiHSliderBg>
+	<uiHSliderBgHeight>6</uiHSliderBgHeight>
+	<uiHSliderBgT>2</uiHSliderBgT>
+	<uiHSliderBgR>2</uiHSliderBgR>
+	<uiHSliderBgB>2</uiHSliderBgB>
+	<uiHSliderBgL>2</uiHSliderBgL>
+
 </PolyConfig>

BIN
IDE/Contents/Resources/UIThemes/default/windowBg.png


+ 84 - 10
IDE/Contents/Source/PolycodeProjectEditor.cpp

@@ -32,9 +32,15 @@ PolycodeProjectEditor::PolycodeProjectEditor() : PolycodeEditor(true){
 	int fontSize = conf->getNumericValue("Polycode", "uiDefaultFontSize");	
 	Number padding = conf->getNumericValue("Polycode", "uiWindowSkinPadding");	
 		
-	ScreenLabel *label2 = new ScreenLabel(L"Width:", fontSize, fontName, Label::ANTIALIAS_FULL);
+	ScreenLabel *label2 = new ScreenLabel(L"DEFAULT VIDEO OPTIONS", fontSize+2, fontName, Label::ANTIALIAS_FULL);	
+	label2->setColor(1.0, 1.0, 1.0, 0.5);
 	mainSettingsWindow->addChild(label2);
 	label2->setPosition(padding, 50);		
+
+		
+	label2 = new ScreenLabel(L"Width:", fontSize, fontName, Label::ANTIALIAS_FULL);
+	mainSettingsWindow->addChild(label2);
+	label2->setPosition(padding, 80);		
 	
 	defaultWidthInput = new UITextInput(false, 60, 12);	
 	mainSettingsWindow->addChild(defaultWidthInput);
@@ -43,7 +49,7 @@ PolycodeProjectEditor::PolycodeProjectEditor() : PolycodeEditor(true){
 
 	label2 = new ScreenLabel(L"Height:", fontSize, fontName, Label::ANTIALIAS_FULL);
 	mainSettingsWindow->addChild(label2);
-	label2->setPosition(padding + 80, 50);		
+	label2->setPosition(padding + 80, 80);		
 	
 	defaultHeightInput = new UITextInput(false, 60, 12);	
 	mainSettingsWindow->addChild(defaultHeightInput);
@@ -52,7 +58,7 @@ PolycodeProjectEditor::PolycodeProjectEditor() : PolycodeEditor(true){
 	
 	label2 = new ScreenLabel(L"Anti-aliasing:", fontSize, fontName, Label::ANTIALIAS_FULL);
 	mainSettingsWindow->addChild(label2);
-	label2->setPosition(padding + 160, 50);		
+	label2->setPosition(padding + 160, 80);		
 	
 	aaLevelComboBox = new UIComboBox(120);		
 	aaLevelComboBox->addComboItem("No AA");
@@ -74,26 +80,45 @@ PolycodeProjectEditor::PolycodeProjectEditor() : PolycodeEditor(true){
 	afLevelComboBox->addComboItem("16x Anisotropic Filtering");			
 	afLevelComboBox->setPosition(label2->getPosition().x, label2->getPosition().y+label2->getHeight());
 
+	label2 = new ScreenLabel(L"Framerate:", fontSize, fontName, Label::ANTIALIAS_FULL);
+	mainSettingsWindow->addChild(label2);
+	label2->setPosition(padding, afLevelComboBox->getPosition().y+afLevelComboBox->getHeight()+10);		
 	
-//	aaLevelInput = new UIHSlider(0,6, 100);
-//	mainSettingsWindow->addChild(aaLevelInput);
-//	aaLevelInput->setPosition(label2->getPosition().x, label2->getPosition().y+label2->getHeight());
-
+	framerateInput = new UITextInput(false, 60, 12);	
+	mainSettingsWindow->addChild(framerateInput);
+	framerateInput->setPosition(label2->getPosition().x, label2->getPosition().y+label2->getHeight());
 
 	vSyncCheckBox = new UICheckBox("V-Sync", false);
-	vSyncCheckBox->setPosition(padding, afLevelComboBox->getPosition().y+afLevelComboBox->getHeight()+10);
+	vSyncCheckBox->setPosition(padding, framerateInput->getPosition().y+framerateInput->getHeight()+10);
 	mainSettingsWindow->addChild(vSyncCheckBox);
 	
+	label2 = new ScreenLabel(L"STARTUP OPTIONS", fontSize+2, fontName, Label::ANTIALIAS_FULL);	
+	label2->setColor(1.0, 1.0, 1.0, 0.5);
+	mainSettingsWindow->addChild(label2);
+	label2->setPosition(padding, vSyncCheckBox->getPosition().y+vSyncCheckBox->getHeight()+30);		
+	
+	
 	label2 = new ScreenLabel(L"Entry point file:", fontSize, fontName, Label::ANTIALIAS_FULL);
 	mainSettingsWindow->addChild(label2);
-	label2->setPosition(padding, vSyncCheckBox->getPosition().y+vSyncCheckBox->getHeight()+10);		
+	label2->setPosition(padding, vSyncCheckBox->getPosition().y+vSyncCheckBox->getHeight()+60);		
 	
 	entryPointInput = new UITextInput(false, 200, 12);	
 	mainSettingsWindow->addChild(entryPointInput);
 	entryPointInput->setPosition(label2->getPosition().x, label2->getPosition().y+label2->getHeight());
 
+
 	mainSettingsWindow->addChild(afLevelComboBox);			
 	mainSettingsWindow->addChild(aaLevelComboBox);		
+
+
+	label2 = new ScreenLabel(L"Background color:", fontSize, fontName, Label::ANTIALIAS_FULL);
+	mainSettingsWindow->addChild(label2);
+	label2->setPosition(padding, entryPointInput->getPosition().y+entryPointInput->getHeight()+10);		
+
+	bgColorBox = new UIColorBox(Color(1.0, 0.5, 0.0, 0.9), 30,30);
+	bgColorBox->setPosition(label2->getPosition().x, label2->getPosition().y+label2->getHeight());
+	mainSettingsWindow->addChild(bgColorBox);
+
 }
 
 PolycodeProjectEditor::~PolycodeProjectEditor() {
@@ -101,7 +126,56 @@ PolycodeProjectEditor::~PolycodeProjectEditor() {
 }
 
 bool PolycodeProjectEditor::openFile(String filePath) {
-	PolycodeEditor::openFile(filePath);
+
+	Object configFile;
+	if(!configFile.loadFromXML(filePath)) {
+		return false;
+	}
+	
+	if(configFile.root["entryPoint"]) {	
+		entryPointInput->setText(configFile.root["entryPoint"]->stringVal);
+	}
+	
+	if(configFile.root["defaultWidth"]) {	
+		defaultWidthInput->setText(configFile.root["defaultWidth"]->stringVal);
+	}
+	if(configFile.root["defaultHeight"]) {		
+		defaultHeightInput->setText(configFile.root["defaultHeight"]->stringVal);
+	}
+
+	unsigned int aaMap[7] = {0,1,1,1,2,2,3};
+	if(configFile.root["antiAliasingLevel"]) {
+		aaLevelComboBox->setSelectedIndex(aaMap[configFile.root["antiAliasingLevel"]->intVal]);
+	} else {
+		aaLevelComboBox->setSelectedIndex(0);
+	}
+
+	unsigned int afMap[17] = {0,1,2,2,3,3,3,3,4,4,4,4,4,4,4,4,5};
+	if(configFile.root["anisotropyLevel"]) {
+		afLevelComboBox->setSelectedIndex(afMap[configFile.root["anisotropyLevel"]->intVal]);
+	} else {
+		afLevelComboBox->setSelectedIndex(0);
+	}
+
+
+	if(configFile.root["frameRate"]) {
+		framerateInput->setText(configFile.root["frameRate"]->stringVal);	
+	}
+/*
+	if(configFile.root["backgroundColor"]) {
+		ObjectEntry *color = configFile.root["backgroundColor"];
+		if((*color)["red"] && (*color)["green"] && (*color)["blue"]) {
+			backgroundColorR = (*color)["red"]->NumberVal;
+			backgroundColorG = (*color)["green"]->NumberVal;
+			backgroundColorB = (*color)["blue"]->NumberVal;
+			printf("Background color: %f %f %f\n", backgroundColorR, backgroundColorG, backgroundColorB);
+
+		} else {
+			printf("backgroundColor node specified, but missing all three color attributes (red,green,blue). Ignoring.\n");
+		}
+	}*/
+	
+	PolycodeEditor::openFile(filePath);	
 	return true;
 }
 

+ 2 - 0
Modules/Contents/UI/CMakeLists.txt

@@ -5,6 +5,7 @@ SET(polycodeUI_SRCS
     Source/PolyUIButton.cpp
     Source/PolyUICheckBox.cpp
     Source/PolyUIComboBox.cpp
+    Source/PolyUIColorBox.cpp
     Source/PolyUIEvent.cpp
     Source/PolyUIHScrollBar.cpp
     Source/PolyUIHSlider.cpp
@@ -24,6 +25,7 @@ SET(polycodeUI_HDRS
     Include/PolyUIButton.h
     Include/PolyUICheckBox.h
     Include/PolyUIComboBox.h
+    Include/PolyUIColorBox.h
     Include/PolyUIEvent.h
     Include/PolyUIHScrollBar.h
     Include/PolyUIHSlider.h

+ 105 - 0
Modules/Contents/UI/Include/PolyUIColorBox.h

@@ -0,0 +1,105 @@
+/*
+ Copyright (C) 2012 by Ivan Safrin
+ 
+ Permission is hereby granted, free of charge, to any person obtaining a copy
+ of this software and associated documentation files (the "Software"), to deal
+ in the Software without restriction, including without limitation the rights
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ copies of the Software, and to permit persons to whom the Software is
+ furnished to do so, subject to the following conditions:
+ 
+ The above copyright notice and this permission notice shall be included in
+ all copies or substantial portions of the Software.
+ 
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ THE SOFTWARE.
+ */
+
+#pragma once
+#include "PolyGlobals.h"
+#include "PolyScreenImage.h"
+#include "PolyScreenLabel.h"
+#include "PolyScreenShape.h"
+#include "PolyScreenEntity.h"
+#include "PolyUIEvent.h"
+#include "PolyUITextInput.h"
+#include "PolyUIWindow.h"
+#include "PolyUIHSlider.h"
+#include "PolyUIBox.h"
+#include "PolyFont.h"
+
+namespace Polycode {
+
+
+	class _PolyExport UIColorPicker : public UIWindow {
+		public:
+			UIColorPicker();
+			~UIColorPicker();
+			
+			void updateSelectedColor(bool updateTextFields=true);
+			void setHue(Number hueNum);			
+			void handleEvent(Event *event);
+			void setSaturationAndValue(Number S, Number V);
+			
+			void rebuildFromTextInputs();
+			
+			void Update();			
+			void onClose();
+			
+			void setPickerColor(Color newColor);
+			
+			Color getSelectedColor();
+			
+		protected:
+		
+			Vector2 lastMainSelectorPosition;
+			Number lastHueSelectorPosition;
+		
+			Color selectedColor;
+		
+			Number colorAlpha;
+			
+			Number currentH;
+			Number currentS;
+			Number currentV;
+			
+			UITextInput *rTextInput;
+			UITextInput *gTextInput;
+			UITextInput *bTextInput;
+			UITextInput *aTextInput;						
+									
+			ScreenImage *mainFrame;
+			ScreenImage *mainBg;			
+			ScreenImage *hueFrame;
+			ScreenImage *hueSelector;
+			ScreenImage *mainSelector;	
+			
+			UIHSlider *alphaSlider;
+			
+			ScreenShape *mainColorRect;
+	};
+
+	class _PolyExport UIColorBox : public ScreenEntity {
+		public:
+			UIColorBox(Color initialColor, Number width, Number height);
+			~UIColorBox();
+			
+			void setBoxColor(Color newColor);
+			void showColorPicker();			
+			void handleEvent(Event *event);
+				
+		protected:
+		
+			UIColorPicker *colorPicker;
+				
+			UIBox *frameImage;
+			ScreenShape *bgImage;
+			ScreenShape *colorShape;			
+		
+	};
+}

+ 1 - 0
Modules/Contents/UI/Include/PolyUIComboBox.h

@@ -52,6 +52,7 @@ namespace Polycode {
 		
 			int addComboItem(String itemName);
 			int getSelectedIndex();
+			void setSelectedIndex(unsigned int newIndex);
 			void handleEvent(Event *event);
 				
 		private:

+ 5 - 6
Modules/Contents/UI/Include/PolyUIHSlider.h

@@ -26,6 +26,7 @@
 #include "PolyScreenShape.h"
 #include "PolyScreenEntity.h"
 #include "PolyUIEvent.h"
+#include "PolyUIBox.h"
 #include "PolyInputEvent.h"
 #include "PolyFont.h"
 
@@ -39,9 +40,7 @@ namespace Polycode {
 			void Update();
 			
 			void setSliderValue(Number val);
-			Number getSliderValue();
-			
-			ScreenShape *getBgRect();
+			Number getSliderValue();			
 			
 		private:
 		
@@ -49,15 +48,15 @@ namespace Polycode {
 			
 			Number labelXPos;
 			Number labelYPos;
-			ScreenShape *bgRect;
-			ScreenShape *gripRect;
-			ScreenShape *shadowRect;
+			UIBox *bgRect;
+			ScreenImage *gripRect;
 			
 			Number sliderValue;
 			Number startValue;
 			Number endValue;
 			Number sliderWidth;
 			
+			ScreenShape *bgHitBox;
 			ScreenLabel *buttonLabel;
 			bool pressedDown;
 	};

+ 4 - 0
Modules/Contents/UI/Include/PolyUITextInput.h

@@ -62,12 +62,16 @@ namespace Polycode {
 			void selectAll();
 		
 			void Resize(int x, int y);
+			
+			void setNumberOnly(bool val);
 		
 			String getSelectionText();
 			void insertText(String text);
 		
 		protected:
 		
+			bool isNumberOnly;
+		
 			int caretSkipWordBack(int caretLine, int caretPosition);
 			int caretSkipWordForward(int caretLine, int caretPosition);
 		

+ 1 - 0
Modules/Contents/UI/Include/PolycodeUI.h

@@ -24,6 +24,7 @@
 #include "PolyUIButton.h"
 #include "PolyUICheckBox.h"
 #include "PolyUIComboBox.h"
+#include "PolyUIColorBox.h"
 #include "PolyUIEvent.h"
 #include "PolyUIHScrollBar.h"
 #include "PolyUIHSlider.h"

+ 444 - 0
Modules/Contents/UI/Source/PolyUIColorBox.cpp

@@ -0,0 +1,444 @@
+/*
+ Copyright (C) 2012 by Ivan Safrin
+ 
+ Permission is hereby granted, free of charge, to any person obtaining a copy
+ of this software and associated documentation files (the "Software"), to deal
+ in the Software without restriction, including without limitation the rights
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ copies of the Software, and to permit persons to whom the Software is
+ furnished to do so, subject to the following conditions:
+ 
+ The above copyright notice and this permission notice shall be included in
+ all copies or substantial portions of the Software.
+ 
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ THE SOFTWARE.
+ */
+
+#include "PolyUIColorBox.h"
+#include "PolyInputEvent.h"
+#include "PolyLabel.h"
+#include "PolyCoreServices.h"
+#include "PolyConfig.h"
+
+
+using namespace Polycode;
+
+UIColorPicker::UIColorPicker() : UIWindow(L"Pick a color!", 300, 240) {
+	closeOnEscape = true;
+	
+//	topPadding
+	Config *conf = CoreServices::getInstance()->getConfig();	
+		
+		
+	String fontName = conf->getStringValue("Polycode", "uiDefaultFontName");
+	int fontSize = conf->getNumericValue("Polycode", "uiDefaultFontSize");
+
+	String mainBgImage = conf->getStringValue("Polycode", "uiColorPickerMainBg");		
+	String mainFrameImage = conf->getStringValue("Polycode", "uiColorPickerMainFrame");
+	String hueFrameImage = conf->getStringValue("Polycode", "uiColorPickerHueFrame");
+	String hueSelectorImage = conf->getStringValue("Polycode", "uiColorPickerHueSelector");
+	String mainSelectorImage = conf->getStringValue("Polycode", "uiColorPickerMainSelector");
+
+	mainBg = new ScreenImage(mainBgImage);
+	mainBg->setPosition(padding, topPadding+padding);
+	addChild(mainBg);
+
+	mainFrame = new ScreenImage(mainFrameImage);
+	mainFrame->setPosition(padding, topPadding+padding);
+	
+	alphaSlider = new UIHSlider(0, 1.0, mainFrame->getWidth());
+	alphaSlider->setPosition(padding, mainFrame->getHeight() + mainFrame->getPosition().y + 13);
+	addChild(alphaSlider);
+	alphaSlider->addEventListener(this, UIEvent::CHANGE_EVENT);
+	
+	mainColorRect = new ScreenShape(ScreenShape::SHAPE_RECT, mainFrame->getWidth(), mainFrame->getHeight());
+	mainColorRect->setPositionMode(ScreenEntity::POSITION_TOPLEFT);
+	mainColorRect->setPosition(padding+1, topPadding+padding+1);
+	addChild(mainColorRect);
+	addChild(mainFrame);
+
+	hueFrame = new ScreenImage(hueFrameImage);
+	hueFrame->setPosition(mainFrame->getPosition().x + mainFrame->getWidth()+10, topPadding+padding);
+	addChild(hueFrame);
+	
+	hueSelector = new ScreenImage(hueSelectorImage);
+	hueSelector->setPositionMode(ScreenEntity::POSITION_CENTER);
+	hueSelector->setPosition(hueFrame->getPosition().x + (hueFrame->getWidth()/2.0), hueFrame->getPosition().y);
+	addChild(hueSelector);	
+
+	hueSelector->setDragLimits(Polycode::Rectangle(hueSelector->getPosition().x,hueSelector->getPosition().y,0,hueFrame->getHeight()));
+				
+	mainSelector = new ScreenImage(mainSelectorImage);
+	mainSelector->setPositionMode(ScreenEntity::POSITION_CENTER);	
+	mainSelector->setPosition(mainFrame->getPosition());
+	addChild(mainSelector);	
+	
+	mainColorRect->getMesh()->useVertexColors = true;
+	
+	mainColorRect->addEventListener(this, InputEvent::EVENT_MOUSEDOWN);
+	mainColorRect->addEventListener(this, InputEvent::EVENT_MOUSEUP);
+	mainColorRect->addEventListener(this, InputEvent::EVENT_MOUSEUP_OUTSIDE);
+	
+	
+	hueFrame->addEventListener(this, InputEvent::EVENT_MOUSEDOWN);
+	hueFrame->addEventListener(this, InputEvent::EVENT_MOUSEUP);
+	hueFrame->addEventListener(this, InputEvent::EVENT_MOUSEUP_OUTSIDE);
+	
+	
+	ScreenLabel *label = new ScreenLabel(L"R:", fontSize, fontName);
+	label->setPosition(hueFrame->getPosition().x+hueFrame->getWidth() + 15, topPadding+padding + 3);
+	addChild(label);
+	
+	rTextInput = new UITextInput(false, 40, 12);
+	rTextInput->setPosition(hueFrame->getPosition().x+hueFrame->getWidth() + 30, topPadding+padding);
+	addChild(rTextInput);
+	rTextInput->addEventListener(this, UIEvent::CHANGE_EVENT);
+
+	label = new ScreenLabel(L"G:", fontSize, fontName);
+	label->setPosition(hueFrame->getPosition().x+hueFrame->getWidth() + 15, topPadding+padding + 33);
+	addChild(label);
+	
+	gTextInput = new UITextInput(false, 40, 12);
+	gTextInput->setPosition(hueFrame->getPosition().x+hueFrame->getWidth() + 30, topPadding+padding + 30);
+	addChild(gTextInput);
+	gTextInput->addEventListener(this, UIEvent::CHANGE_EVENT);
+	
+	label = new ScreenLabel(L"B:", fontSize, fontName);
+	label->setPosition(hueFrame->getPosition().x+hueFrame->getWidth() + 15, topPadding+padding + 63);
+	addChild(label);
+	
+	bTextInput = new UITextInput(false, 40, 12);
+	bTextInput->setPosition(hueFrame->getPosition().x+hueFrame->getWidth() + 30, topPadding+padding + 60);
+	addChild(bTextInput);
+	bTextInput->addEventListener(this, UIEvent::CHANGE_EVENT);
+	
+	label = new ScreenLabel(L"A:", fontSize, fontName);
+	label->setPosition(hueFrame->getPosition().x+hueFrame->getWidth() + 15, topPadding+padding + 93);
+	addChild(label);
+	
+	aTextInput = new UITextInput(false, 40, 12);
+	aTextInput->setPosition(hueFrame->getPosition().x+hueFrame->getWidth() + 30, topPadding+padding + 90);
+	addChild(aTextInput);
+	aTextInput->addEventListener(this, UIEvent::CHANGE_EVENT);
+	
+	setHue(0.0);
+	setSaturationAndValue(0.0, 0.0);
+	
+	rTextInput->setNumberOnly(true);
+	gTextInput->setNumberOnly(true);
+	bTextInput->setNumberOnly(true);
+	aTextInput->setNumberOnly(true);
+	
+	lastHueSelectorPosition = 0;
+	
+	mainSelector->setDragLimits(Polycode::Rectangle(mainColorRect->getPosition().x,mainColorRect->getPosition().y,mainColorRect->getWidth(), mainColorRect->getHeight()));
+				
+	colorAlpha = 1.0;
+}
+
+void UIColorPicker::onClose() {
+	visible = false;
+	enabled = false;
+}
+
+void UIColorPicker::rebuildFromTextInputs() {
+	int	newR = atoi(rTextInput->getText().c_str());
+	int	newG = atoi(gTextInput->getText().c_str());
+	int	newB = atoi(bTextInput->getText().c_str());
+	int	newA = atoi(aTextInput->getText().c_str());			
+	
+	
+	if(newR < 0)
+		newR = 0;
+	if(newR > 255)
+		newR = 255;
+
+	if(newG < 0)
+		newG = 0;
+	if(newG > 255)
+		newG = 255;
+
+	if(newB < 0)
+		newB = 0;
+	if(newB > 255)
+		newB = 255;
+
+	if(newA < 0)
+		newA = 0;
+	if(newA > 255)
+		newA = 255;	
+	
+	Color newColor;
+	newColor.setColorRGBA(newR, newG, newB, newA);
+
+	currentS = newColor.getSaturation();
+	currentV = newColor.getValue();
+	currentH = newColor.getHue();
+	colorAlpha = newColor.a;
+	
+	updateSelectedColor(false);
+
+
+}
+
+void UIColorPicker::setPickerColor(Color newColor) {
+	currentS = newColor.getSaturation();
+	currentV = newColor.getValue();
+	currentH = newColor.getHue();
+	colorAlpha = newColor.a;
+	updateSelectedColor();
+}
+
+void UIColorPicker::setSaturationAndValue(Number S, Number V) {
+	currentS = S;
+	currentV = V;	
+	updateSelectedColor();
+}
+
+void UIColorPicker::updateSelectedColor(bool updateTextFields) {
+	selectedColor.setColorHSV(currentH, currentS, currentV);
+	selectedColor.a = colorAlpha;
+	
+	int newR = floor(selectedColor.r*255.0);
+	int newG = floor(selectedColor.g*255.0);
+	int newB = floor(selectedColor.b*255.0);
+	int newA = floor(selectedColor.a*255.0);
+		
+	mainColorRect->color.a = colorAlpha;
+	
+	if(updateTextFields) {
+		rTextInput->setText(String::IntToString(newR));
+		gTextInput->setText(String::IntToString(newG));
+		bTextInput->setText(String::IntToString(newB));
+		aTextInput->setText(String::IntToString(newA));
+	}
+	
+	Color hueCol;
+	hueCol.setColorHSV(currentH, 1.0, 1.0);
+	hueCol.a = colorAlpha;
+
+	mainColorRect->getMesh()->getPolygon(0)->getVertex(0)->vertexColor = Color(1.0,1.0,1.0,colorAlpha);
+	mainColorRect->getMesh()->getPolygon(0)->getVertex(1)->vertexColor = hueCol;
+	mainColorRect->getMesh()->getPolygon(0)->getVertex(2)->vertexColor = Color(0.0,0.0,0.0,colorAlpha);
+	mainColorRect->getMesh()->getPolygon(0)->getVertex(3)->vertexColor = Color(0.0,0.0,0.0,colorAlpha);	
+	mainColorRect->getMesh()->arrayDirtyMap[RenderDataArray::COLOR_DATA_ARRAY] = true;				
+	
+		
+	hueSelector->setPositionY(hueFrame->getPosition().y + hueFrame->getHeight() - ((currentH/360.0) * hueFrame->getHeight()));
+	lastHueSelectorPosition = hueSelector->getPosition().y;
+	
+	mainSelector->setPosition(mainColorRect->getPosition().x + (currentS * mainColorRect->getWidth()), mainColorRect->getPosition().y + mainColorRect->getHeight() - (currentV * mainColorRect->getHeight()));					
+	lastMainSelectorPosition = mainSelector->getPosition2D();
+	
+	alphaSlider->setSliderValue(colorAlpha);
+
+	dispatchEvent(new Event(), Event::CHANGE_EVENT);
+}
+
+Color UIColorPicker::getSelectedColor() {
+	return selectedColor;
+}
+
+void UIColorPicker::handleEvent(Event *event) {
+
+	if((event->getDispatcher() == rTextInput || event->getDispatcher() == gTextInput || event->getDispatcher() == bTextInput || event->getDispatcher() == aTextInput) && event->getEventType() == "UIEvent") {
+		switch(event->getEventCode()) {
+			case UIEvent::CHANGE_EVENT:
+			{
+				rebuildFromTextInputs();
+			}
+			break;
+		}	
+	}
+
+	if(event->getDispatcher() == alphaSlider) {
+		switch(event->getEventCode()) {
+			case UIEvent::CHANGE_EVENT:
+			{
+				colorAlpha = alphaSlider->getSliderValue();
+				updateSelectedColor();
+			}
+			break;
+		}
+	}
+
+	if(event->getDispatcher() == hueFrame) {
+		switch(event->getEventCode()) {
+			case InputEvent::EVENT_MOUSEDOWN:
+			{
+				InputEvent *inputEvent = (InputEvent*) event;
+				hueSelector->setPositionY(inputEvent->getMousePosition().y);
+				hueSelector->startDrag(inputEvent->mousePosition.x-hueSelector->getPosition().x,inputEvent->mousePosition.y-hueSelector->getPosition().y);		
+				Number newHue = 360.0 - (((inputEvent->getMousePosition().y-hueFrame->getPosition().y)/((hueFrame->getPosition().y+hueFrame->getHeight())-hueFrame->getPosition().y)) * 360.0f);
+				setHue(newHue);
+						
+			}
+			break;
+			case InputEvent::EVENT_MOUSEUP:
+			case InputEvent::EVENT_MOUSEUP_OUTSIDE:			
+			{
+				hueSelector->stopDrag();
+			}
+			break;	
+		}
+	}
+
+
+
+	if(event->getDispatcher() == mainColorRect) {
+		switch(event->getEventCode()) {
+			case InputEvent::EVENT_MOUSEDOWN:
+			{
+				InputEvent *inputEvent = (InputEvent*) event;			
+				mainSelector->setPosition(inputEvent->getMousePosition().x, inputEvent->getMousePosition().y);			
+				mainSelector->startDrag(inputEvent->mousePosition.x-mainSelector->getPosition().x,inputEvent->mousePosition.y-mainSelector->getPosition().y);
+				
+				Number newV = 1.0 - ((inputEvent->getMousePosition().y-mainColorRect->getPosition().y)/((mainColorRect->getPosition().y+mainColorRect->getHeight())-mainColorRect->getPosition().y));
+
+				Number newS = ((inputEvent->getMousePosition().x-mainColorRect->getPosition().x)/((mainColorRect->getPosition().x+mainColorRect->getWidth())-mainColorRect->getPosition().x));
+					
+				setSaturationAndValue(newS, newV);
+			}
+			break;
+			case InputEvent::EVENT_MOUSEUP:
+			case InputEvent::EVENT_MOUSEUP_OUTSIDE:			
+			{
+				mainSelector->stopDrag();			
+			}
+			break;	
+		}
+	}
+	
+	UIWindow::handleEvent(event);
+}
+
+void UIColorPicker::setHue(Number hueNum) {
+	if(hueNum < 0.0)
+		hueNum = 0.0;
+	if(hueNum >= 360.0)
+		hueNum = 359.9999;		
+		
+	currentH = hueNum;
+	updateSelectedColor();
+}
+
+UIColorPicker::~UIColorPicker() {
+
+}
+
+void UIColorPicker::Update() {
+
+	if(mainSelector->getPosition2D() != lastMainSelectorPosition) {
+		lastMainSelectorPosition = mainSelector->getPosition2D();
+		
+		Number newPosX = lastMainSelectorPosition.x;
+		Number newPosY = lastMainSelectorPosition.y;		
+		
+		Number newV = 1.0 - ((newPosY-mainColorRect->getPosition().y)/((mainColorRect->getPosition().y+mainColorRect->getHeight())-mainColorRect->getPosition().y));
+
+		Number newS = ((newPosX-mainColorRect->getPosition().x)/((mainColorRect->getPosition().x+mainColorRect->getWidth())-mainColorRect->getPosition().x));
+					
+		setSaturationAndValue(newS, newV);		
+
+	}
+	
+	if(hueSelector->getPosition().y != lastHueSelectorPosition) {
+		lastHueSelectorPosition = hueSelector->getPosition().y;
+		
+		Number newPosY = lastHueSelectorPosition;
+									
+		if(newPosY < hueFrame->getPosition().y)
+			newPosY =  hueFrame->getPosition().y;
+		if(newPosY > hueFrame->getHeight() +  hueFrame->getPosition().y)
+			newPosY = hueFrame->getHeight() + hueFrame->getPosition().y;						
+						
+		hueSelector->setPositionY(newPosY);
+					
+		Number newHue = 360.0 - (((newPosY-hueFrame->getPosition().y)/((hueFrame->getPosition().y+hueFrame->getHeight())-hueFrame->getPosition().y)) * 360.0f);
+		setHue(newHue);
+	}	
+
+	UIWindow::Update();
+}
+
+UIColorBox::UIColorBox(Color initialColor, Number width, Number height) : ScreenEntity() {
+
+	Config *conf = CoreServices::getInstance()->getConfig();	
+
+	String frameImageFile = conf->getStringValue("Polycode", "uiColorBoxFrameImage");
+	String bgImageFile = conf->getStringValue("Polycode", "uiColorBoxBgImage");
+	Number frameInset = conf->getNumericValue("Polycode", "uiFrameInset");
+
+	Number st = conf->getNumericValue("Polycode", "uiColorBoxFrameImageT");
+	Number sr = conf->getNumericValue("Polycode", "uiColorBoxFrameImageR");
+	Number sb = conf->getNumericValue("Polycode", "uiColorBoxFrameImageB");
+	Number sl = conf->getNumericValue("Polycode", "uiColorBoxFrameImageL");
+
+
+	bgImage = new ScreenShape(ScreenShape::SHAPE_RECT, width-(frameInset*2), height-(frameInset*2));
+	bgImage->setPositionMode(ScreenEntity::POSITION_TOPLEFT);
+	bgImage->loadTexture(bgImageFile);
+	addChild(bgImage);
+
+	bgImage->addEventListener(this, InputEvent::EVENT_MOUSEDOWN);
+
+	colorShape = new ScreenShape(ScreenShape::SHAPE_RECT, width-(frameInset*2), height-(frameInset*2));
+	colorShape->setPositionMode(ScreenEntity::POSITION_TOPLEFT);
+	addChild(colorShape);
+
+		
+	frameImage = new UIBox(frameImageFile, st,sr,sb,sl, width, height);	
+	addChild(frameImage);
+	
+	colorPicker = new UIColorPicker();
+	colorPicker->setPosition(width + 20, -colorPicker->getHeight()/2.0);
+	
+	colorPicker->addEventListener(this, Event::CHANGE_EVENT);
+	
+	addChild(colorPicker);
+	colorPicker->visible = false;
+	colorPicker->enabled = false;
+
+	this->width = width;
+	this->height = height;
+	
+	setBoxColor(initialColor);
+}
+
+UIColorBox::~UIColorBox() {
+
+}
+
+void UIColorBox::setBoxColor(Color newColor) {
+	colorPicker->setPickerColor(newColor);
+}
+
+void UIColorBox::showColorPicker() {
+	colorPicker->visible = true;
+	colorPicker->enabled = true;
+}
+		
+void UIColorBox::handleEvent(Event *event) {
+
+	if(event->getDispatcher() == colorPicker) {
+		switch(event->getEventCode()) {
+			case Event::CHANGE_EVENT:
+				colorShape->color = colorPicker->getSelectedColor();
+			break;
+		}		
+	}
+
+	if(event->getDispatcher() == bgImage) {
+		switch(event->getEventCode()) {
+			case InputEvent::EVENT_MOUSEDOWN:
+				showColorPicker();
+			break;
+		}
+	}
+}

+ 9 - 2
Modules/Contents/UI/Source/PolyUIComboBox.cpp

@@ -77,9 +77,9 @@ UIComboBox::UIComboBox(Number comboWidth) : ScreenEntity() {
 	nextItemHeight = 0;
 	
 	bgBox = new UIBox(bgImage, st,sr,sb,sl, comboWidth, comboHeight);	
-	
+
 	addChild(bgBox);
-	addChild(dropDownImage);	
+	addChild(dropDownImage);
 	
 	selectedLabel = new ScreenLabel("<None>", fontSize, fontName);
 	selectedLabel->setPosition(paddingX, floor(((dropDownImage->getHeight()/2.0) - selectedLabel->getHeight()/2.0) + paddingY));
@@ -150,6 +150,13 @@ void UIComboBox::updateVis() {
 int UIComboBox::getSelectedIndex() {
 	return selectedIndex;
 }
+
+void UIComboBox::setSelectedIndex(unsigned int newIndex) {
+	if(newIndex < items.size()) {
+		selectedIndex = newIndex;				
+		selectedLabel->setText(items[selectedIndex]->label);		
+	}
+}
 				
 void UIComboBox::handleEvent(Event *event) {
 

+ 53 - 26
Modules/Contents/UI/Source/PolyUIHSlider.cpp

@@ -22,41 +22,56 @@
 
 
 #include "PolyUIHSlider.h"
+#include "PolyConfig.h"
+#include "PolyCoreServices.h"
 
 using namespace Polycode;
 
 UIHSlider::UIHSlider(Number start, Number end, Number width) {
-	bgRect = new ScreenShape(ScreenShape::SHAPE_RECT, width,8,0,0);
-	bgRect->setPosition(0,6);
-	bgRect->setColor(0.11f, 0.11f, 0.11f, 1.0f);
-//	bgRect->strokeEnabled = true;
-//	bgRect->setStrokeColor(1.0f, 1.0f, 1.0f, 0.1f);
+
+	Config *conf = CoreServices::getInstance()->getConfig();	
+	
+	String bgImage = conf->getStringValue("Polycode", "uiHSliderBg");
+	String gripImage = conf->getStringValue("Polycode", "uiHSliderGrip");	
+	Number bgHeight = conf->getNumericValue("Polycode", "uiHSliderBgHeight");
+
+	Number st = conf->getNumericValue("Polycode", "uiHSliderBgT");
+	Number sr = conf->getNumericValue("Polycode", "uiHSliderBgR");
+	Number sb = conf->getNumericValue("Polycode", "uiHSliderBgB");
+	Number sl = conf->getNumericValue("Polycode", "uiHSliderBgL");
+	
+
+	bgRect = new UIBox(bgImage, st, sr, sb, sl, width, bgHeight);
 	addChild(bgRect);
 	
-	sliderWidth = width-10;
+	sliderWidth = width;
 	
 	sliderValue = start;
 	startValue = start;
 	endValue = end;
-	
-	shadowRect = new ScreenShape(ScreenShape::SHAPE_RECT,10,18,0,0);
-	shadowRect->setColor(0.0f, 0.0f, 0.0f, 0.2f);
-	shadowRect->setPosition(2, 3);
-	addChild(shadowRect);
-	
-	gripRect = new ScreenShape(ScreenShape::SHAPE_RECT, 10,18,0,0);
-	gripRect->setColor(0.13f, 0.13f, 0.13f, 1.0f);
-	gripRect->strokeEnabled = true;
-	gripRect->lineSmooth = false;
-	gripRect->setStrokeColor(1.0f, 1.0f, 1.0f, 0.1f);
+		
+	gripRect = new ScreenImage(gripImage);
+	gripRect->setPositionMode(ScreenEntity::POSITION_CENTER);
+	gripRect->setPosition(0, floor(bgHeight/2.0));
+
+	bgHitBox = new ScreenShape(ScreenShape::SHAPE_RECT, width, gripRect->getHeight());
+	bgHitBox->setPositionMode(ScreenEntity::POSITION_TOPLEFT);
+	bgHitBox->setPosition(0, gripRect->getPosition().y - (gripRect->getHeight()/2.0));
+	addChild(bgHitBox);
+	bgHitBox->setColor(1.0,0.0,0.0,0.0);
+
 	addChild(gripRect);
 
+	bgHitBox->addEventListener(this, InputEvent::EVENT_MOUSEUP);
+	bgHitBox->addEventListener(this, InputEvent::EVENT_MOUSEUP_OUTSIDE);
+	bgHitBox->addEventListener(this, InputEvent::EVENT_MOUSEDOWN);
+
+
 	gripRect->addEventListener(this, InputEvent::EVENT_MOUSEUP);
 	gripRect->addEventListener(this, InputEvent::EVENT_MOUSEUP_OUTSIDE);
 	gripRect->addEventListener(this, InputEvent::EVENT_MOUSEDOWN);
 	
-	gripRect->setDragLimits(Rectangle(0,0,width-10,0));
-	shadowRect->setDragLimits(Rectangle(2,3,width-10,0));
+	gripRect->setDragLimits(Rectangle(0,floor(bgHeight/2.0),width,0));
 	
 	gripPos = 0;
 }
@@ -65,14 +80,11 @@ UIHSlider::~UIHSlider() {
 
 }
 
-ScreenShape *UIHSlider::getBgRect() {
-	return bgRect;
-}
-
 void UIHSlider::setSliderValue(Number val) {
 	if(val >= startValue && val <= endValue) {
 		gripRect->setPositionX(sliderWidth * ((val-startValue)/(endValue-startValue)));
-		shadowRect->setPositionX(gripRect->getPosition().x);
+		gripPos = gripRect->getPosition().x;
+		sliderValue = val;
 	}
 }
 
@@ -81,17 +93,32 @@ Number UIHSlider::getSliderValue() {
 }
 			
 void UIHSlider::handleEvent(Event *event) {
+
+	if(event->getDispatcher() == bgHitBox) {
+		InputEvent *inputEvent = (InputEvent*)event;	
+		switch(event->getEventCode()) {
+			case InputEvent::EVENT_MOUSEDOWN:
+				gripRect->setPositionX(inputEvent->mousePosition.x);
+				gripPos = gripRect->getPosition().x;				
+				sliderValue = startValue+((endValue - startValue) * (gripPos/sliderWidth));				
+				gripRect->startDrag(inputEvent->mousePosition.x-gripRect->getPosition().x,inputEvent->mousePosition.y-gripRect->getPosition().y);
+			break;
+			case InputEvent::EVENT_MOUSEUP:
+			case InputEvent::EVENT_MOUSEUP_OUTSIDE:
+				gripRect->stopDrag();
+			break;
+		}	
+	}
+
 	if(event->getDispatcher() == gripRect) {
 		InputEvent *inputEvent = (InputEvent*)event;
 		switch(event->getEventCode()) {
 			case InputEvent::EVENT_MOUSEDOWN:
 				gripRect->startDrag(inputEvent->mousePosition.x-gripRect->getPosition().x,inputEvent->mousePosition.y-gripRect->getPosition().y);
-				shadowRect->startDrag(inputEvent->mousePosition.x-2-gripRect->getPosition().x,inputEvent->mousePosition.y-3-gripRect->getPosition().y);		
 			break;
 			case InputEvent::EVENT_MOUSEUP:
 			case InputEvent::EVENT_MOUSEUP_OUTSIDE:
 				gripRect->stopDrag();
-				shadowRect->stopDrag();
 			break;
 		}	
 	}

+ 18 - 8
Modules/Contents/UI/Source/PolyUITextInput.cpp

@@ -33,6 +33,8 @@ using namespace Polycode;
 UITextInput::UITextInput(bool multiLine, Number width, Number height) : ScreenEntity() {
 	this->multiLine = multiLine;
 	
+	isNumberOnly = false;
+	
 	draggingSelection = false;
 	hasSelection = false;
 	doSelectToCaret = false;
@@ -127,6 +129,10 @@ UITextInput::UITextInput(bool multiLine, Number width, Number height) : ScreenEn
 	updateCaretPosition();
 }
 
+void UITextInput::setNumberOnly(bool val) {
+	isNumberOnly = val;
+}
+
 void UITextInput::clearSelection() {
 	hasSelection = false;
 	selectorRectTop->visible = false;	
@@ -275,7 +281,7 @@ void UITextInput::deleteSelection() {
 	clearSelection();
 	caretPosition = selectionL;
 	updateCaretPosition();
-	
+	dispatchEvent(new UIEvent(), UIEvent::CHANGE_EVENT);	
 }
 
 void UITextInput::Resize(int x, int y) {
@@ -319,6 +325,7 @@ int UITextInput::insertLine(bool after) {
 		// do we even need that? I don't think so.
 	}	
 	
+	dispatchEvent(new UIEvent(), UIEvent::CHANGE_EVENT);
 	return 1;	
 }
 
@@ -728,13 +735,15 @@ void UITextInput::onKeyDown(PolyKEY key, wchar_t charCode) {
 	
 //	if(1) {
 	if((charCode > 31 && charCode < 127) || charCode > 127) {	
-		if(hasSelection)
-			deleteSelection();
-		ctext = currentLine->getText();		
-		String text2 = ctext.substr(caretPosition, ctext.length()-caretPosition);
-		ctext = ctext.substr(0,caretPosition);
-		ctext += charCode + text2;
-		caretPosition++;
+		if(!isNumberOnly || (isNumberOnly && (charCode > 47 && charCode < 58))) {
+			if(hasSelection)
+				deleteSelection();
+			ctext = currentLine->getText();		
+			String text2 = ctext.substr(caretPosition, ctext.length()-caretPosition);
+			ctext = ctext.substr(0,caretPosition);
+			ctext += charCode + text2;
+			caretPosition++;
+		}
 	}
 	
 	if(key == KEY_TAB && multiLine) {
@@ -776,6 +785,7 @@ void UITextInput::onKeyDown(PolyKEY key, wchar_t charCode) {
 	}
 	
 	currentLine->setText(ctext);	
+	dispatchEvent(new UIEvent(), UIEvent::CHANGE_EVENT);	
 	updateCaretPosition();
 }
 

+ 3 - 0
Modules/Contents/UI/Source/PolyUIWindow.cpp

@@ -50,6 +50,9 @@ UIWindow::UIWindow(String windowName, Number width, Number height) : ScreenEntit
 	
 	padding = conf->getNumericValue("Polycode", "uiWindowSkinPadding");	
 	
+	width = width+(padding*2.0);
+	height = height+topPadding;
+	
 	windowRect = new UIBox(conf->getStringValue("Polycode", "uiWindowSkin"),
 						  st,sr,sb,sl,
 						  width, height);