Просмотр исходного кода

Combo box widget for UI Module and IDE stuff

Ivan Safrin 14 лет назад
Родитель
Сommit
048474c3e2

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

@@ -45,7 +45,8 @@ class PolycodeProjectEditor : public PolycodeEditor {
 	UITextInput *defaultWidthInput;
 	UITextInput *defaultHeightInput;	
 	//UIHSlider *aaLevelInput;	
-//	UIComboBox *aaLevelComboBox;
+	UIComboBox *aaLevelComboBox;
+	UIComboBox *afLevelComboBox;	
 	UITextInput *entryPointInput;	
 };
 

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


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


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


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


+ 21 - 0
IDE/Contents/Resources/UIThemes/default/theme.xml

@@ -86,4 +86,25 @@
 	<uiCheckBoxUncheckedImage>checkbox_unchecked.png</uiCheckBoxUncheckedImage>
 	<uiCheckBoxLabelOffsetX>10</uiCheckBoxLabelOffsetX>
 	<uiCheckBoxLabelOffsetY>3</uiCheckBoxLabelOffsetY>
+		
+	<uiComboBoxFont>sans</uiComboBoxFont>
+	<uiComboBoxFontSize>11</uiComboBoxFontSize>
+	<uiComboBoxDropdownImage>combobox_drop.png</uiComboBoxDropdownImage>
+	<uiComboBoxBgImage>combobox_bg.png</uiComboBoxBgImage>
+	<uiComboBoxBgT>3</uiComboBoxBgT>
+	<uiComboBoxBgR>3</uiComboBoxBgR>
+	<uiComboBoxBgB>3</uiComboBoxBgB>
+	<uiComboBoxBgL>3</uiComboBoxBgL>				
+	<uiComboBoxItemsBgImage>combobox_items.png</uiComboBoxItemsBgImage>	
+	<uiComboBoxDropdownBgT>3</uiComboBoxDropdownBgT>
+	<uiComboBoxDropdownBgR>3</uiComboBoxDropdownBgR>
+	<uiComboBoxDropdownBgB>3</uiComboBoxDropdownBgB>
+	<uiComboBoxDropdownBgL>3</uiComboBoxDropdownBgL>			
+	<uiComboBoxSelectorBgImage>combobox_selector.png</uiComboBoxSelectorBgImage>	
+	<uiComboBoxSelectorBgT>3</uiComboBoxSelectorBgT>
+	<uiComboBoxSelectorBgR>3</uiComboBoxSelectorBgR>
+	<uiComboBoxSelectorBgB>3</uiComboBoxSelectorBgB>
+	<uiComboBoxSelectorBgL>3</uiComboBoxSelectorBgL>					
+	<uiComboBoxTextOffsetX>7</uiComboBoxTextOffsetX>
+	<uiComboBoxTextOffsetY>3</uiComboBoxTextOffsetY>		
 </PolyConfig>

+ 19 - 7
IDE/Contents/Source/PolycodeProjectEditor.cpp

@@ -54,15 +54,26 @@ PolycodeProjectEditor::PolycodeProjectEditor() : PolycodeEditor(true){
 	mainSettingsWindow->addChild(label2);
 	label2->setPosition(padding + 160, 50);		
 	
-/*
-	aaLevelComboBox = new UIComboBox(100);		
-	mainSettingsWindow->addChild(aaLevelComboBox);	
+	aaLevelComboBox = new UIComboBox(120);		
 	aaLevelComboBox->addComboItem("No AA");
 	aaLevelComboBox->addComboItem("2x MSAA");
 	aaLevelComboBox->addComboItem("4x MSAA");
 	aaLevelComboBox->addComboItem("6x MSAA");			
 	aaLevelComboBox->setPosition(label2->getPosition().x, label2->getPosition().y+label2->getHeight());
-*/
+
+	label2 = new ScreenLabel(L"Anisotropic filtering:", fontSize, fontName, Label::ANTIALIAS_FULL);
+	mainSettingsWindow->addChild(label2);
+	label2->setPosition(padding, defaultHeightInput->getPosition().y+defaultHeightInput->getHeight()+10);		
+	
+	afLevelComboBox = new UIComboBox(250);		
+	afLevelComboBox->addComboItem("No Anisotropic Filtering");
+	afLevelComboBox->addComboItem("1x Anisotropic Filtering");
+	afLevelComboBox->addComboItem("2x Anisotropic Filtering");
+	afLevelComboBox->addComboItem("4x Anisotropic Filtering");
+	afLevelComboBox->addComboItem("8x Anisotropic Filtering");
+	afLevelComboBox->addComboItem("16x Anisotropic Filtering");			
+	afLevelComboBox->setPosition(label2->getPosition().x, label2->getPosition().y+label2->getHeight());
+
 	
 //	aaLevelInput = new UIHSlider(0,6, 100);
 //	mainSettingsWindow->addChild(aaLevelInput);
@@ -70,7 +81,7 @@ PolycodeProjectEditor::PolycodeProjectEditor() : PolycodeEditor(true){
 
 
 	vSyncCheckBox = new UICheckBox("V-Sync", false);
-	vSyncCheckBox->setPosition(padding, defaultHeightInput->getPosition().y+defaultHeightInput->getHeight()+10);
+	vSyncCheckBox->setPosition(padding, afLevelComboBox->getPosition().y+afLevelComboBox->getHeight()+10);
 	mainSettingsWindow->addChild(vSyncCheckBox);
 	
 	label2 = new ScreenLabel(L"Entry point file:", fontSize, fontName, Label::ANTIALIAS_FULL);
@@ -80,8 +91,9 @@ PolycodeProjectEditor::PolycodeProjectEditor() : PolycodeEditor(true){
 	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);		
 }
 
 PolycodeProjectEditor::~PolycodeProjectEditor() {

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

@@ -4,6 +4,7 @@ SET(polycodeUI_SRCS
     Source/PolyUIBox.cpp
     Source/PolyUIButton.cpp
     Source/PolyUICheckBox.cpp
+    Source/PolyUIComboBox.cpp
     Source/PolyUIEvent.cpp
     Source/PolyUIHScrollBar.cpp
     Source/PolyUIHSlider.cpp
@@ -22,6 +23,7 @@ SET(polycodeUI_HDRS
     Include/PolyUIBox.h
     Include/PolyUIButton.h
     Include/PolyUICheckBox.h
+    Include/PolyUIComboBox.h
     Include/PolyUIEvent.h
     Include/PolyUIHScrollBar.h
     Include/PolyUIHSlider.h

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

@@ -0,0 +1,75 @@
+/*
+ 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 "PolyUIBox.h"
+#include "PolyFont.h"
+
+namespace Polycode {
+
+	class _PolyExport UIComboBoxItem : public ScreenEntity {
+		public:
+			UIComboBoxItem(String label, Number comboWidth, Number comboHeight);
+			~UIComboBoxItem();
+			
+			String label;
+			ScreenLabel *itemLabel;
+	};
+
+	class _PolyExport UIComboBox : public ScreenEntity {
+		public:
+			UIComboBox(Number comboWidth);
+			~UIComboBox();
+			
+			void toggleDropDown();
+		
+			void updateVis();
+		
+			int addComboItem(String itemName);
+			int getSelectedIndex();
+			void handleEvent(Event *event);
+				
+		private:
+		
+			std::vector<UIComboBoxItem*> items;
+			int selectedIndex;
+			
+			ScreenLabel *selectedLabel;
+			Number comboHeight;
+			Number comboWidth;
+			
+			int selectedOffset;
+						
+			Number nextItemHeight;
+			bool isDroppedDown;
+			UIBox *dropDownBox;
+			UIBox *bgBox;
+			UIBox *selectorBox;			
+			ScreenImage *dropDownImage;
+	};
+}

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

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

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

@@ -0,0 +1,184 @@
+/*
+ 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 "PolyUIComboBox.h"
+#include "PolyInputEvent.h"
+#include "PolyLabel.h"
+#include "PolyCoreServices.h"
+#include "PolyConfig.h"
+
+using namespace Polycode;
+
+UIComboBoxItem::UIComboBoxItem(String label, Number comboWidth, Number comboHeight) : ScreenEntity() {
+	this->label = label;
+	Config *conf = CoreServices::getInstance()->getConfig();	
+	
+	String fontName = conf->getStringValue("Polycode", "uiComboBoxFont");
+	int fontSize = conf->getNumericValue("Polycode", "uiComboBoxFontSize");	
+
+	Number paddingX = conf->getNumericValue("Polycode", "uiComboBoxTextOffsetX");	
+	Number paddingY = conf->getNumericValue("Polycode", "uiComboBoxTextOffsetY");	
+
+	itemLabel = new ScreenLabel(label, fontSize, fontName);
+	itemLabel->setPosition(paddingX, floor(((comboHeight/2.0) - itemLabel->getHeight()/2.0) + paddingY));	
+	addChild(itemLabel);
+	
+}
+
+UIComboBoxItem::~UIComboBoxItem() {
+
+}
+
+
+UIComboBox::UIComboBox(Number comboWidth) : ScreenEntity() {
+
+	isDroppedDown = false;
+	selectedIndex = -1;
+
+	Config *conf = CoreServices::getInstance()->getConfig();	
+	
+	String fontName = conf->getStringValue("Polycode", "uiComboBoxFont");
+	int fontSize = conf->getNumericValue("Polycode", "uiComboBoxFontSize");	
+	String dropDownImageFile = conf->getStringValue("Polycode", "uiComboBoxDropdownImage");
+	String bgImage = conf->getStringValue("Polycode", "uiComboBoxBgImage");	
+
+	Number st = conf->getNumericValue("Polycode", "uiComboBoxBgT");
+	Number sr = conf->getNumericValue("Polycode", "uiComboBoxBgR");
+	Number sb = conf->getNumericValue("Polycode", "uiComboBoxBgB");
+	Number sl = conf->getNumericValue("Polycode", "uiComboBoxBgL");
+	
+	Number paddingX = conf->getNumericValue("Polycode", "uiComboBoxTextOffsetX");	
+	Number paddingY = conf->getNumericValue("Polycode", "uiComboBoxTextOffsetY");	
+		
+	dropDownImage = new ScreenImage(dropDownImageFile);
+	dropDownImage->setPosition(comboWidth - dropDownImage->getWidth(),0);
+	
+	this->comboHeight = dropDownImage->getHeight();
+	this->comboWidth = comboWidth;
+	nextItemHeight = 0;
+	
+	bgBox = new UIBox(bgImage, st,sr,sb,sl, comboWidth, comboHeight);	
+	
+	addChild(bgBox);
+	addChild(dropDownImage);	
+	
+	selectedLabel = new ScreenLabel("<None>", fontSize, fontName);
+	selectedLabel->setPosition(paddingX, floor(((dropDownImage->getHeight()/2.0) - selectedLabel->getHeight()/2.0) + paddingY));
+	addChild(selectedLabel);
+	
+	String dropdownBgImage = conf->getStringValue("Polycode", "uiComboBoxItemsBgImage");	
+	
+	st = conf->getNumericValue("Polycode", "uiComboBoxDropdownBgT");
+	sr = conf->getNumericValue("Polycode", "uiComboBoxDropdownBgR");
+	sb = conf->getNumericValue("Polycode", "uiComboBoxDropdownBgB");
+	sl = conf->getNumericValue("Polycode", "uiComboBoxDropdownBgL");
+	
+	dropDownBox = new UIBox(dropdownBgImage, st,sr,sb,sl, comboWidth, comboHeight);
+	dropDownBox->setPosition(0,comboHeight);	
+	addChild(dropDownBox);
+	
+	String selectorBgImage = conf->getStringValue("Polycode", "uiComboBoxSelectorBgImage");	
+	
+	st = conf->getNumericValue("Polycode", "uiComboBoxSelectorBgT");
+	sr = conf->getNumericValue("Polycode", "uiComboBoxSelectorBgR");
+	sb = conf->getNumericValue("Polycode", "uiComboBoxSelectorBgB");
+	sl = conf->getNumericValue("Polycode", "uiComboBoxSelectorBgL");
+	
+	dropDownBox->blockMouseInput = true;
+	
+	selectorBox = new UIBox(selectorBgImage, st,sr,sb,sl, comboWidth, comboHeight);
+	dropDownBox->addChild(selectorBox);
+	selectorBox->blockMouseInput = true;
+	
+	selectedOffset = 0;
+	dropDownBox->addEventListener(this, InputEvent::EVENT_MOUSEMOVE);
+	dropDownBox->addEventListener(this, InputEvent::EVENT_MOUSEDOWN);	
+
+	dropDownImage->addEventListener(this, InputEvent::EVENT_MOUSEDOWN);	
+	bgBox->addEventListener(this, InputEvent::EVENT_MOUSEDOWN);	
+		
+	isDroppedDown = false;
+	updateVis();
+	
+	this->width = comboWidth;
+	this->height = comboHeight;
+}
+
+UIComboBox::~UIComboBox() {
+
+}
+
+int UIComboBox::addComboItem(String itemName) {
+	UIComboBoxItem *newItem = new UIComboBoxItem(itemName, comboWidth, comboHeight);
+	items.push_back(newItem);
+	dropDownBox->addChild(newItem);
+	newItem->setPosition(0,nextItemHeight);
+	nextItemHeight += comboHeight;
+	dropDownBox->resizeBox(comboWidth, nextItemHeight);
+	return items.size()-1;
+}
+
+void UIComboBox::toggleDropDown() {
+	isDroppedDown = !isDroppedDown;
+	updateVis();
+}
+
+void UIComboBox::updateVis() {
+	dropDownBox->visible = isDroppedDown;
+	dropDownBox->enabled = isDroppedDown;	
+}
+
+int UIComboBox::getSelectedIndex() {
+	return selectedIndex;
+}
+				
+void UIComboBox::handleEvent(Event *event) {
+
+	if(event->getDispatcher() == dropDownBox) {
+		switch(event->getEventCode()) {
+			case InputEvent::EVENT_MOUSEMOVE:
+			{
+				InputEvent *inputEvent = (InputEvent*) event;
+				selectedOffset = floor(inputEvent->getMousePosition().y/comboHeight)- 1;
+				if(selectedOffset >= 0 && selectedOffset < items.size())
+					selectorBox->setPosition(0,selectedOffset*comboHeight);
+			}				
+			break;
+			case InputEvent::EVENT_MOUSEDOWN:
+			{
+				selectedIndex = selectedOffset;				
+				selectedLabel->setText(items[selectedIndex]->label);				
+				isDroppedDown = false;
+				updateVis();				
+			}
+			break;
+		}	
+	}
+	
+	if(event->getDispatcher() == dropDownImage || event->getDispatcher() == bgBox) {
+		switch(event->getEventCode()) {
+			case InputEvent::EVENT_MOUSEDOWN:
+				toggleDropDown();
+			break;
+		}
+	}
+}