Răsfoiți Sursa

Fixed UI theme, added UI Lua example, fixed binding issue in UIComboBox

Ivan Safrin 13 ani în urmă
părinte
comite
4de209a0ef

+ 2 - 0
.gitignore

@@ -39,6 +39,8 @@
 UserInterfaceState.*
 Player/Build/Mac OS X/Polycode Player.xcodeproj/project.xcworkspace/xcuserdata/ivansafrin.xcuserdatad/UserInterfaceState.xcuserstate
 
+.substance
+
 /Bindings/Contents/LUA/API/Polycode/*.lua
 !/Bindings/Contents/LUA/API/Polycode/EventDispatcher.lua
 /Bindings/Contents/LUA/API/Polycode.lua

BIN
Assets/UIThemes.pak


+ 2 - 2
Assets/UIThemes/default/theme.xml

@@ -91,8 +91,8 @@
 		
 	<uiComboBoxFont>sans</uiComboBoxFont>
 	<uiComboBoxFontSize>11</uiComboBoxFontSize>
-	<uiComboBoxDropdownImage>combobox_drop.png</uiComboBoxDropdownImage>
-	<uiComboBoxBgImage>combobox_bg.png</uiComboBoxBgImage>
+	<uiComboBoxDropdownImage>UIThemes/default/combobox_drop.png</uiComboBoxDropdownImage>
+	<uiComboBoxBgImage>UIThemes/default/combobox_bg.png</uiComboBoxBgImage>
 	<uiComboBoxBgT>6</uiComboBoxBgT>
 	<uiComboBoxBgR>6</uiComboBoxBgR>
 	<uiComboBoxBgB>6</uiComboBoxBgB>

+ 144 - 0
Examples/Lua/UI/UIDemo/Scripts/Main.lua

@@ -0,0 +1,144 @@
+-- **********************************************************************
+-- This demo shows various UI controls you can use in your code
+-- **********************************************************************
+
+screen = Screen()
+screen.rootEntity.snapToPixels = true
+demoShape = ScreenLabel("DEMO", 64, "mono")
+demoShape.positionAtBaseline = false
+demoShape:setPositionMode(ScreenEntity.POSITION_CENTER)
+screen:addChild(demoShape)
+demoShape.position.x = 600
+demoShape.position.y = 200
+
+-- **********************************************************************
+-- UIWindow is a draggable window container
+-- **********************************************************************
+
+window = UIWindow("Demo window", 300, 400)
+window.position.x = 50
+window.position.y = 50
+screen:addChild(window)
+
+-- **********************************************************************
+-- UIButton lets you create a simple text button
+-- and listen to its click event
+-- **********************************************************************
+
+button = UIButton("Rotate me", 100, 30)
+window:addChild(button)
+button.position.x = 20
+button.position.y = 40
+
+function onRotateButton(t, event)
+	demoShape.rotation.roll = demoShape.rotation.roll + 30
+end
+
+button:addEventListener(nil, onRotateButton, UIEvent.CLICK_EVENT)
+
+-- **********************************************************************
+-- UITextInput is a text input field
+-- **********************************************************************
+
+input = UITextInput(false, 100, 24)
+input:setText("DEMO")
+window:addChild(input)
+input.position.x = 140
+input.position.y = 40
+
+function onTextChange(t, event)
+	demoShape:setText(input:getText())
+end
+
+input:addEventListener(nil, onTextChange, UIEvent.CHANGE_EVENT)
+
+-- **********************************************************************
+-- UICheckBox is a simple check box
+-- **********************************************************************
+
+checkBox = UICheckBox("Auto rotate", false)
+window:addChild(checkBox)
+checkBox.position.x = 20
+checkBox.position.y = 80
+
+function Update(elapsed)
+	if checkBox:isChecked() then
+		demoShape.rotation.roll = demoShape.rotation.roll + (elapsed * 100)
+	end
+end
+
+-- **********************************************************************
+-- UIHSlider is a horizontal value slider that changes
+-- a value between two preset values
+-- **********************************************************************
+
+label = ScreenLabel("Scale me", 12, "sans")
+window:addChild(label)
+label.position.x = 20
+label.position.y = 110
+
+slider = UIHSlider(1.0, 3.0, 100)
+window:addChild(slider)
+slider.position.x = 115
+slider.position.y = 116
+
+function onSliderChange(t, event)
+	demoShape.scale.x = slider:getSliderValue()
+end
+
+slider:addEventListener(nil, onSliderChange, UIEvent.CHANGE_EVENT)
+
+-- **********************************************************************
+-- UIColorBox is a box that lets you pick colors
+-- to use it, you must also create a UIColorPicker that should be
+-- shared between all UIColorBox instances
+-- **********************************************************************
+
+colorPicker = UIColorPicker()
+screen:addChild(colorPicker)
+colorPicker.position.x = 300
+colorPicker.position.y = 300
+
+colorBox = UIColorBox(colorPicker, Color(1.0, 1.0, 1.0, 1.0), 50, 30)
+window:addChild(colorBox)
+colorBox.position.x = 20
+colorBox.position.y = 130
+
+function onColorChange(t, event)
+	demoShape.color = colorBox:getSelectedColor()
+end
+
+colorBox:addEventListener(nil, onColorChange, UIEvent.CHANGE_EVENT)
+
+-- **********************************************************************
+-- UIComboBox lets you create a drop down combo box
+-- UIComboBox uses a UIGlobalMenu, which should be shared between all
+-- controls that require a menu.
+-- **********************************************************************
+
+globalMenu = UIGlobalMenu()
+screen:addChild(globalMenu)
+
+comboBox = UIComboBox(globalMenu, 200)
+window:addChild(comboBox)
+comboBox.position.x = 20
+comboBox.position.y = 180
+
+comboBox:addComboItem("No Border")
+comboBox:addComboItem("Thin Border")
+comboBox:addComboItem("Thick Border")
+comboBox:setSelectedIndex(0)
+
+function onBlendingChange(t, event)
+	if comboBox:getSelectedIndex() == 0 then
+		demoShape.strokeEnabled = false
+	elseif comboBox:getSelectedIndex() == 1 then
+		demoShape.strokeEnabled = true
+		demoShape.strokeWidth = 1.0
+	else
+		demoShape.strokeEnabled = true
+		demoShape.strokeWidth = 3.0
+	end
+end
+
+comboBox:addEventListener(nil, onBlendingChange, UIEvent.CHANGE_EVENT)

+ 8 - 0
Examples/Lua/UI/UIDemo/UIDemo.polyproject

@@ -0,0 +1,8 @@
+<?xml version="1.0" ?>
+<PolycodeProject defaultWidth="800" defaultHeight="600" antiAliasingLevel="0" entryPoint="Scripts/Main.lua" textureFiltering="nearest" vSync="false" anisotropyLevel="0" frameRate="60">
+    <backgroundColor red="0.25" green="0.25" blue="0.25" />
+    <polyarray:packedItems>
+        <item type="folder" path="Scripts" />
+    </polyarray:packedItems>
+    <polyarray:modules />
+</PolycodeProject>

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

@@ -52,7 +52,9 @@ namespace Polycode {
 		
 			void clearItems();
 			
-			int addComboItem(String itemName, void *data=NULL);
+			int addComboItem(String itemName);			
+			int addComboItem(String itemName, void *data);
+						
 			int getSelectedIndex();
 			UIComboBoxItem *getSelectedItem();
 			void setSelectedIndex(unsigned int newIndex);

+ 4 - 0
Modules/Contents/UI/Source/PolyUIComboBox.cpp

@@ -110,6 +110,10 @@ int UIComboBox::addComboItem(String itemName, void *data) {
 	return items.size()-1;
 }
 
+int UIComboBox::addComboItem(String itemName) {
+	return addComboItem(itemName, NULL);
+}
+
 UIComboBoxItem *UIComboBox::getSelectedItem() {
 	if(selectedIndex < items.size()) {
 		return items[selectedIndex];