Selaa lähdekoodia

processInputEvents=true NOW REQUIRED for ScreenEntities to hand mouse events down to their children, fixed mouse event blocking settings, UI tweaks

Ivan Safrin 13 vuotta sitten
vanhempi
sitoutus
c21ab8e6bb

+ 11 - 19
Core/Contents/Source/PolyScreenEntity.cpp

@@ -372,16 +372,14 @@ void ScreenEntity::_onMouseMove(Number x, Number y, int timestamp, Vector2 paren
 			mouseOver = false;
 		}		
 	}	
-	}
-	
-	if(enabled) {
+
 		for(int i=children.size()-1;i>=0;i--) {			
 			Vector2 adjust = parentAdjust;
 			if(positionMode == POSITION_TOPLEFT)
 			adjust += Vector2(width/2.0, height/2.0);
 			((ScreenEntity*)children[i])->_onMouseMove(x,y, timestamp, adjust);
 			if(((ScreenEntity*)children[i])->blockMouseInput && ((ScreenEntity*)children[i])->enabled) {
-				if(((ScreenEntity*)children[i])->hitTest(x,y))
+				if(((ScreenEntity*)children[i])->hitTest(x+adjust.x,y+adjust.y))
 				   break;
 			}
 		}
@@ -434,15 +432,14 @@ bool ScreenEntity::_onMouseUp(Number x, Number y, int mouseButton, int timestamp
 		inputEvent->mouseButton = mouseButton;
 		dispatchEvent(inputEvent, InputEvent::EVENT_MOUSEUP_OUTSIDE);	
 	}
-	}
-	if(enabled) {
+
 		for(int i=children.size()-1;i>=0;i--) {			
 			Vector2 adjust = parentAdjust;
 			if(positionMode == POSITION_TOPLEFT)
 				adjust += Vector2(width/2.0, height/2.0);
 			((ScreenEntity*)children[i])->_onMouseUp(x,y, mouseButton, timestamp, adjust);;
 			if(((ScreenEntity*)children[i])->blockMouseInput && ((ScreenEntity*)children[i])->enabled) {
-				if(((ScreenEntity*)children[i])->hitTest(x,y))
+				if(((ScreenEntity*)children[i])->hitTest(x+adjust.x,y+adjust.y))
 				   break;
 			}
 		}
@@ -483,16 +480,14 @@ void ScreenEntity::_onMouseWheelUp(Number x, Number y, int timestamp, Vector2 pa
 		
 		retVal = true;
 	}
-	}
-	
-	if(enabled) {
+
 		for(int i=children.size()-1;i>=0;i--) {			
 			Vector2 adjust = parentAdjust;
 			if(positionMode == POSITION_TOPLEFT)
 				adjust += Vector2(width/2.0, height/2.0);
 			((ScreenEntity*)children[i])->_onMouseWheelUp(x,y, timestamp, adjust);;
 			if(((ScreenEntity*)children[i])->blockMouseInput && ((ScreenEntity*)children[i])->enabled) {
-				if(((ScreenEntity*)children[i])->hitTest(x,y))
+				if(((ScreenEntity*)children[i])->hitTest(x+adjust.x,y+adjust.y))
 				   break;
 			}
 		}
@@ -531,16 +526,14 @@ void ScreenEntity::_onMouseWheelDown(Number x, Number y, int timestamp, Vector2
 		
 		retVal = true;
 	}
-	}
-	
-	if(enabled) {
+
 		for(int i=children.size()-1;i>=0;i--) {			
 			Vector2 adjust = parentAdjust;
 			if(positionMode == POSITION_TOPLEFT)
 				adjust += Vector2(width/2.0, height/2.0);
 			((ScreenEntity*)children[i])->_onMouseWheelDown(x,y, timestamp, adjust);;
 			if(((ScreenEntity*)children[i])->blockMouseInput && ((ScreenEntity*)children[i])->enabled) {
-				if(((ScreenEntity*)children[i])->hitTest(x,y))
+				if(((ScreenEntity*)children[i])->hitTest(x+adjust.x,y+adjust.y))
 				   break;
 			}
 		}
@@ -589,15 +582,14 @@ bool ScreenEntity::_onMouseDown(Number x, Number y, int mouseButton, int timesta
 		lastClickTicks = timestamp;		
 		retVal = true;
 	}
-	}
-	if(enabled) {
-		for(int i=children.size()-1;i>=0;i--) {			
+
+	for(int i=children.size()-1;i>=0;i--) {			
 			Vector2 adjust = parentAdjust;
 			if(positionMode == POSITION_TOPLEFT)
 				adjust += Vector2(width/2.0, height/2.0);
 			((ScreenEntity*)children[i])->_onMouseDown(x,y, mouseButton, timestamp, adjust);;
 			if(((ScreenEntity*)children[i])->blockMouseInput && ((ScreenEntity*)children[i])->enabled) {
-				if(((ScreenEntity*)children[i])->hitTest(x,y))
+				if(((ScreenEntity*)children[i])->hitTest(x+adjust.x,y+adjust.y))
 				   break;
 			}
 		}

+ 1 - 0
IDE/Contents/Source/PolycodeEditor.cpp

@@ -45,6 +45,7 @@ void PolycodeEditor::setFilePath(String newPath) {
 PolycodeEditor::PolycodeEditor(bool _isReadOnly) : ScreenEntity() {
 	this->_isReadOnly = _isReadOnly;
 	enableScissor = true;	
+	processInputEvents = true;
 }
 
 void PolycodeEditor::Resize(int x, int y) {

+ 3 - 0
IDE/Contents/Source/PolycodeFrame.cpp

@@ -39,9 +39,12 @@ void EditorHolder::Resize(Number width, Number height) {
 
 PolycodeFrame::PolycodeFrame() : ScreenEntity() {
 
+	processInputEvents = true;
+
 	modalChild = NULL;
 	
 	welcomeEntity = new ScreenEntity();
+	welcomeEntity->processInputEvents = true;
 	addChild(welcomeEntity);
 	welcomeImage = new ScreenImage("welcome.png");
 	welcomeEntity->addChild(welcomeImage);

+ 0 - 2
IDE/Contents/Source/PolycodeProjectBrowser.cpp

@@ -27,7 +27,6 @@ PolycodeProjectBrowser::PolycodeProjectBrowser() : UIElement() {
 	treeContainer->getRootNode()->toggleCollapsed();
 	treeContainer->getRootNode()->addEventListener(this, UITreeEvent::SELECTED_EVENT);
 	treeContainer->addEventListener(this, InputEvent::EVENT_MOUSEDOWN);
-	treeContainer->processInputEvents = true;
 	
 	BrowserUserData *data = new BrowserUserData();
 	data->type = 0;
@@ -35,7 +34,6 @@ PolycodeProjectBrowser::PolycodeProjectBrowser() : UIElement() {
 	treeContainer->getRootNode()->setUserData((void*) data)	;
 	
 	addChild(treeContainer);		
-	
 	selectedData = NULL;
 }
 

+ 2 - 1
Modules/Contents/UI/Include/PolyUIHSlider.h

@@ -27,12 +27,13 @@
 #include "PolyScreenEntity.h"
 #include "PolyUIEvent.h"
 #include "PolyUIBox.h"
+#include "PolyUIElement.h"
 #include "PolyInputEvent.h"
 #include "PolyFont.h"
 
 namespace Polycode {
 
-	class _PolyExport UIHSlider : public ScreenEntity {
+	class _PolyExport UIHSlider : public UIElement {
 		public:
 			UIHSlider(Number start, Number end, Number width);
 			~UIHSlider();		

+ 4 - 2
Modules/Contents/UI/Include/PolyUIScrollContainer.h

@@ -46,10 +46,12 @@ namespace Polycode {
 		Vector2 getContentSize();
 		
 		void onMouseWheelDown(Number x, Number y);
-		void onMouseWheelUp(Number x, Number y);		
-		
+		void onMouseWheelUp(Number x, Number y);	
+				
 		void handleEvent(Event *event);
 		
+		Number getVScrollWidth();
+		
 	private:		
 		
 		Number defaultScrollSize;

+ 3 - 0
Modules/Contents/UI/Include/PolyUIVScrollBar.h

@@ -40,6 +40,9 @@ namespace Polycode {
 		void scrollTo(Number scrollValue);
 		void Scroll(Number amount);
 		
+		void onMouseDown(Number x, Number y) { printf("SHIT: %f,%f\n", x,y); }
+		
+		
 		void onMouseWheelDown(Number x, Number y);
 		void onMouseWheelUp(Number x, Number y);
 		

+ 1 - 0
Modules/Contents/UI/Source/PolyUIElement.cpp

@@ -26,6 +26,7 @@ using namespace Polycode;
 
 UIElement::UIElement() : ScreenEntity() {
 	setPositionMode(ScreenEntity::POSITION_TOPLEFT);
+	processInputEvents = true;
 }
 
 UIElement::~UIElement() {

+ 6 - 0
Modules/Contents/UI/Source/PolyUIHScrollBar.cpp

@@ -70,6 +70,7 @@ UIHScrollBar::UIHScrollBar(Number width, Number height, Number initialRatio) : S
 	addChild(handleBox);
 	
 	bgBox->addEventListener(this, InputEvent::EVENT_MOUSEDOWN);
+	bgBox->blockMouseInput = true;
 	
 	handleBox->addEventListener(this, InputEvent::EVENT_MOUSEUP);
 	handleBox->addEventListener(this, InputEvent::EVENT_MOUSEUP_OUTSIDE);	
@@ -115,6 +116,11 @@ void UIHScrollBar::setHandleRatio(Number newRatio) {
 	
 	handleBox->resizeBox(scrollHandleWidth, handleBox->getHeight());
 	handleBox->setDragLimits(Rectangle(padding,padding,dragRectWidth, height-(padding*2)-(height-(padding*2))));	
+	
+	if(enabled && handleBox->getPosition().x > dragRectWidth) {
+		handleBox->setPositionX(dragRectWidth);
+	}
+	
 }
 
 Number UIHScrollBar::getScrollValue() {

+ 9 - 7
Modules/Contents/UI/Source/PolyUIHSizer.cpp

@@ -40,16 +40,19 @@ UIHSizer::UIHSizer(Number width, Number height, Number mainWidth, bool leftSizer
 	separatorBgShape->setPositionMode(ScreenEntity::POSITION_TOPLEFT);
 	separatorBgShape->setColor(0.0, 0.0, 0.0, 1.0);	
 	addChild(separatorBgShape);
+	
 
 	childElements = new ScreenEntity();
+	childElements->processInputEvents = true;
 	addChild(childElements);
 	
 	firstElement = NULL;
 	secondElement = NULL;
 	
-	separatorHitShape = new ScreenShape(ScreenShape::SHAPE_RECT, 6,height);
+	separatorHitShape = new ScreenShape(ScreenShape::SHAPE_RECT, 8,height);
 	separatorHitShape->setPositionMode(ScreenEntity::POSITION_TOPLEFT);
 	separatorHitShape->setColor(1.0, 0.0, 0.0, 0.5);	
+	separatorHitShape->blockMouseInput = true;	
 	addChild(separatorHitShape);
 	
 	separatorHitShape->addEventListener(this, InputEvent::EVENT_MOUSEDOWN);
@@ -60,8 +63,7 @@ UIHSizer::UIHSizer(Number width, Number height, Number mainWidth, bool leftSizer
 	separatorHitShape->addEventListener(this, InputEvent::EVENT_MOUSEMOVE);			
 	separatorHitShape->visible = false;
 	
-	coreInput = CoreServices::getInstance()->getCore()->getInput();
-	
+	coreInput = CoreServices::getInstance()->getCore()->getInput();	
 	coreInput->addEventListener(this, InputEvent::EVENT_MOUSEMOVE);	
 	
 	separatorHitShape->processInputEvents = true;
@@ -156,8 +158,8 @@ void UIHSizer::updateSizer() {
 
 		separatorBgShape->setShapeSize(1, height);
 		separatorBgShape->setPosition(mainWidth,0);
-		separatorHitShape->setShapeSize(6, height);
-		separatorHitShape->setPosition(mainWidth-3,0);
+		separatorHitShape->setShapeSize(8, height);
+		separatorHitShape->setPosition(mainWidth-4,0);
 		
 	} else {
 	
@@ -172,8 +174,8 @@ void UIHSizer::updateSizer() {
 
 		separatorBgShape->setShapeSize(1, height);
 		separatorBgShape->setPosition(width-mainWidth,0);
-		separatorHitShape->setShapeSize(6, height);
-		separatorHitShape->setPosition(width-mainWidth-3,0);
+		separatorHitShape->setShapeSize(8, height);
+		separatorHitShape->setPosition(width-mainWidth-4,0);
 	
 	}
 }

+ 1 - 1
Modules/Contents/UI/Source/PolyUIHSlider.cpp

@@ -27,7 +27,7 @@
 
 using namespace Polycode;
 
-UIHSlider::UIHSlider(Number start, Number end, Number width) {
+UIHSlider::UIHSlider(Number start, Number end, Number width) : UIElement() {
 
 	Config *conf = CoreServices::getInstance()->getConfig();	
 	

+ 10 - 0
Modules/Contents/UI/Source/PolyUIScrollContainer.cpp

@@ -57,6 +57,8 @@ UIScrollContainer::UIScrollContainer(ScreenEntity *scrolledEntity, bool hScroll,
 	addChild(vScrollBar);
 	vScrollBar->setPosition(width+uiScrollPanePadding,0);	
 	vScrollBar->addEventListener(this, Event::CHANGE_EVENT);
+	vScrollBar->blockMouseInput = true;
+	vScrollBar->processInputEvents = true;
 	
 	if(!vScroll)
 		vScrollBar->enabled = false;
@@ -102,6 +104,14 @@ Vector2 UIScrollContainer::getContentSize() {
 	return Vector2(contentWidth, contentHeight);
 }
 
+Number UIScrollContainer::getVScrollWidth() {
+	if(vScrollBar->enabled) {
+		return vScrollBar->getWidth();
+	} else {
+		return 0;
+	}
+}
+
 void UIScrollContainer::setContentSize(Number newContentWidth, Number newContentHeight) {
 	
 	contentHeight = newContentHeight;

+ 11 - 5
Modules/Contents/UI/Source/PolyUITextInput.cpp

@@ -32,7 +32,7 @@ using namespace Polycode;
 
 UITextInput::UITextInput(bool multiLine, Number width, Number height) : UIElement() {
 	this->multiLine = multiLine;
-	
+	processInputEvents = true;
 	isNumberOnly = false;
 	
 	draggingSelection = false;
@@ -67,6 +67,7 @@ UITextInput::UITextInput(bool multiLine, Number width, Number height) : UIElemen
 	} 
 	
 	linesContainer = new ScreenEntity();	
+	linesContainer->processInputEvents = true;
 	
 	lineSpacing = conf->getNumericValue("Polycode", "textEditLineSpacing");
 	
@@ -81,10 +82,7 @@ UITextInput::UITextInput(bool multiLine, Number width, Number height) : UIElemen
 						  st,sr,sb,sl,
 						  width+(padding*2), height+(padding*2));	
 	
-	addChild(inputRect);
-	
-
-	
+	addChild(inputRect);		
 	
 	inputRect->addEventListener(this, InputEvent::EVENT_MOUSEDOWN);
 	inputRect->addEventListener(this, InputEvent::EVENT_MOUSEUP);	
@@ -312,6 +310,10 @@ void UITextInput::Resize(Number width, Number height) {
 	this->height = height;	
 	matrixDirty = true;	
 	setHitbox(width,height);
+	
+	if(multiLine) {
+		inputRect->setHitbox(width - scrollContainer->getVScrollWidth(), height);
+	}
 
 	if(scrollContainer) {
 		scrollContainer->Resize(width, height);
@@ -368,6 +370,10 @@ void UITextInput::restructLines() {
 		scrollContainer->setContentSize(width,  (((lines.size()+1) * ((lineHeight+lineSpacing)))) - padding);
 	}	
 	
+	if(multiLine) {
+		inputRect->setHitbox(width - scrollContainer->getVScrollWidth(), height);
+	}	
+	
 }
 
 void UITextInput::setText(String text) {

+ 1 - 1
Modules/Contents/UI/Source/PolyUITree.cpp

@@ -31,7 +31,7 @@ using namespace Polycode;
 
 UITree::UITree(String icon, String text, Number treeWidth, Number treeOffset) : ScreenEntity() {
 		
-		
+	processInputEvents = true;
 	willDrag = false;
 	isDragging = false;
 	

+ 1 - 1
Modules/Contents/UI/Source/PolyUITreeContainer.cpp

@@ -48,6 +48,7 @@ UITreeContainer::UITreeContainer(String icon, String text, Number treeWidth, Num
 	//bgBox->setPosition(-padding, -padding);
 	
 	scrollChild = new ScreenEntity();
+	scrollChild->processInputEvents = true;
 	
 	rootNode = new UITree(icon, text, treeWidth,0);		
 	rootNode->addEventListener(this, UITreeEvent::NEED_REFRESH_EVENT);	
@@ -68,7 +69,6 @@ void UITreeContainer::Resize(Number width, Number height) {
 	bgBox->resizeBox(width, height);
 	mainContainer->setPositionY(0);
 
-
 	rootNode->Resize(width);
 //	width = x;
 	//	height = y;

+ 6 - 1
Modules/Contents/UI/Source/PolyUIVScrollBar.cpp

@@ -74,7 +74,6 @@ UIVScrollBar::UIVScrollBar(Number width, Number height, Number initialRatio) : S
 	handleBox->addEventListener(this, InputEvent::EVENT_MOUSEUP_OUTSIDE);	
 	handleBox->addEventListener(this, InputEvent::EVENT_MOUSEDOWN);			
 	handleBox->processInputEvents = true;
-	handleBox->blockMouseInput = true;
 	
 	dragRectHeight = height-(padding*2)-scrollHandleHeight;
 	handleBox->setDragLimits(Rectangle(padding,padding,width-(padding*2)-(width-(padding*2)), dragRectHeight));
@@ -89,6 +88,7 @@ UIVScrollBar::UIVScrollBar(Number width, Number height, Number initialRatio) : S
 
 void UIVScrollBar::Resize(int newHeight) {
 	bgBox->resizeBox(width, newHeight);
+	setHitbox(width, newHeight);	
 	setHeight(newHeight);
 	dragRectHeight = height-(padding*2)-scrollHandleHeight;	
 	handleBox->setDragLimits(Rectangle(padding,padding,width-(padding*2)-(width-(padding*2)), dragRectHeight));	
@@ -129,6 +129,11 @@ void UIVScrollBar::setHandleRatio(Number newRatio) {
 	dragRectHeight = height-(padding*2)-scrollHandleHeight;	
 	handleBox->resizeBox(handleBox->getWidth(), scrollHandleHeight);
 	handleBox->setDragLimits(Rectangle(padding,padding,width-(padding*2)-(width-(padding*2)), dragRectHeight));	
+	
+	if(enabled && handleBox->getPosition().y > dragRectHeight) {
+		handleBox->setPositionY(dragRectHeight);
+	}
+	
 }
 
 void UIVScrollBar::onMouseWheelUp(Number x, Number y) {

+ 7 - 5
Modules/Contents/UI/Source/PolyUIVSizer.cpp

@@ -42,15 +42,17 @@ UIVSizer::UIVSizer(Number width, Number height, Number mainHeight, bool topSizer
 	addChild(separatorBgShape);
 
 	childElements = new ScreenEntity();
+	childElements->processInputEvents = true;
 	addChild(childElements);
 	
 	firstElement = NULL;
 	secondElement = NULL;
 	
-	separatorHitShape = new ScreenShape(ScreenShape::SHAPE_RECT, width,6);
+	separatorHitShape = new ScreenShape(ScreenShape::SHAPE_RECT, width,8);
 	separatorHitShape->setPositionMode(ScreenEntity::POSITION_TOPLEFT);
 	separatorHitShape->setColor(1.0, 0.0, 0.0, 0.5);	
 	addChild(separatorHitShape);
+	separatorHitShape->blockMouseInput = true;
 	
 	separatorHitShape->addEventListener(this, InputEvent::EVENT_MOUSEDOWN);
 	separatorHitShape->addEventListener(this, InputEvent::EVENT_MOUSEUP);
@@ -157,8 +159,8 @@ void UIVSizer::updateSizer() {
 
 		separatorBgShape->setShapeSize(width, 1);
 		separatorBgShape->setPosition(0,mainHeight);
-		separatorHitShape->setShapeSize(width, 6);
-		separatorHitShape->setPosition(0, mainHeight-3);
+		separatorHitShape->setShapeSize(width, 8);
+		separatorHitShape->setPosition(0, mainHeight-4);
 		
 	} else {
 
@@ -174,8 +176,8 @@ void UIVSizer::updateSizer() {
 
 		separatorBgShape->setShapeSize(width, 1);
 		separatorBgShape->setPosition(0,height-mainHeight);
-		separatorHitShape->setShapeSize(width, 6);
-		separatorHitShape->setPosition(0, height-mainHeight-3);
+		separatorHitShape->setShapeSize(width, 8);
+		separatorHitShape->setPosition(0, height-mainHeight-4);
 
 	}
 }