Ivan Safrin 13 лет назад
Родитель
Сommit
9cf5dadca6

+ 6 - 1
Core/Contents/Include/PolyScreenEntity.h

@@ -99,6 +99,8 @@ class _PolyExport ScreenEntity : public Entity, public EventDispatcher {
 		void _onKeyDown(PolyKEY key, wchar_t charCode);	
 		void _onKeyUp(PolyKEY key, wchar_t charCode);	
 		
+		Matrix4 getScreenConcatenatedMatrix();
+		
 		virtual void onKeyDown(PolyKEY key, wchar_t charCode){}
 		virtual void onKeyUp(PolyKEY key, wchar_t charCode){}
 		
@@ -148,6 +150,8 @@ class _PolyExport ScreenEntity : public Entity, public EventDispatcher {
 		*/
 		void setPositionMode(int newPositionMode);
 		
+		int getPositionMode();
+		
 		void setDragLimits(Rectangle rect);
 		void clearDragLimits();
 		
@@ -169,9 +173,10 @@ class _PolyExport ScreenEntity : public Entity, public EventDispatcher {
 		* If this option is true, the screen entity's positions will be roudnded to whole pixels. This only works if the screen is using pixel coordinates.
 		*/
 		bool snapToPixels;
-
 		bool processInputEvents;
 
+		Vector2 getHitbox();
+
 	protected:
 	
 		bool focusable;

+ 25 - 3
Core/Contents/Source/PolyScreenEntity.cpp

@@ -231,6 +231,10 @@ void ScreenEntity::_onKeyUp(PolyKEY key, wchar_t charCode) {
 	}
 }
 
+int ScreenEntity::getPositionMode() {
+	return positionMode;
+}
+
 void ScreenEntity::setDragLimits(Polycode::Rectangle rect) {
 	if(!dragLimits)
 		dragLimits = new Polycode::Rectangle();
@@ -245,6 +249,24 @@ void ScreenEntity::clearDragLimits() {
 	dragLimits = NULL;
 }
 
+Vector2 ScreenEntity::getHitbox() {
+	return Vector2(hitwidth, hitheight);
+}
+
+Matrix4 ScreenEntity::getScreenConcatenatedMatrix() {
+	Matrix4 retMatrix = transformMatrix;
+	if(positionMode == POSITION_TOPLEFT) {
+		Vector3 pos = retMatrix.getPosition();
+		retMatrix.setPosition(pos.x + width/2.0, pos.y + height/2.0, 0);
+	}
+	
+	if(parentEntity) {
+		return retMatrix * ((ScreenEntity*)parentEntity)->getScreenConcatenatedMatrix();		
+	} else {
+		return retMatrix;	
+	}	
+}
+
 void ScreenEntity::_onMouseMove(Number x, Number y, int timestamp, Vector2 parentAdjust) {
 
 	if(isDragged) {
@@ -252,8 +274,8 @@ void ScreenEntity::_onMouseMove(Number x, Number y, int timestamp, Vector2 paren
 		Vector3 localCoordinate = Vector3(x+(parentAdjust.x*2.0),y+(parentAdjust.y*2.0),0);				
 				
 		if(parentEntity) {
-			Matrix4 inverse = parentEntity->getConcatenatedMatrix().inverse();
-			localCoordinate = inverse * localCoordinate;
+			Matrix4 inverse = ((ScreenEntity*)parentEntity)->getScreenConcatenatedMatrix().inverse();
+			localCoordinate = inverse * localCoordinate;		
 		}
 	
 		setPosition(localCoordinate.x-dragOffsetX,localCoordinate.y-dragOffsetY);
@@ -326,7 +348,7 @@ void ScreenEntity::_onMouseMove(Number x, Number y, int timestamp, Vector2 paren
 		for(int i=children.size()-1;i>=0;i--) {			
 			Vector2 adjust = parentAdjust;
 			if(positionMode == POSITION_TOPLEFT)
-				adjust += Vector2(width/2.0, height/2.0);
+			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))

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

@@ -99,6 +99,7 @@ void PolycodeScreenEditor::handleDroppedFile(OSFileEntry file, Number x, Number
 		baseEntity->addChild(newImage);
 		newImage->setPosition(x-baseEntity->getPosition2D().x,y-baseEntity->getPosition2D().y);
 		newEntity = newImage;
+		newImage->processInputEvents = true;
 	}
 	
 	if(newEntity) {

+ 2 - 0
Modules/Contents/UI/Source/PolyUICheckBox.cpp

@@ -58,7 +58,9 @@ UICheckBox::UICheckBox(String caption, bool checked) : ScreenEntity() {
 	buttonImageUnchecked->addEventListener(this, InputEvent::EVENT_MOUSEOUT);
 	buttonImageUnchecked->addEventListener(this, InputEvent::EVENT_MOUSEUP);
 	buttonImageUnchecked->addEventListener(this, InputEvent::EVENT_MOUSEDOWN);
+	buttonImageUnchecked->processInputEvents = true;
 	captionLabel->addEventListener(this, InputEvent::EVENT_MOUSEDOWN);
+	captionLabel->processInputEvents = true;
 	
 	height = buttonImageUnchecked->getHeight();
 	width = buttonImageUnchecked->getWidth() + captionLabel->getWidth() + checkboxTextOffsetX;

+ 3 - 1
Modules/Contents/UI/Source/PolyUIColorBox.cpp

@@ -84,12 +84,13 @@ UIColorPicker::UIColorPicker() : UIWindow(L"Pick a color!", 300, 240) {
 	mainColorRect->addEventListener(this, InputEvent::EVENT_MOUSEDOWN);
 	mainColorRect->addEventListener(this, InputEvent::EVENT_MOUSEUP);
 	mainColorRect->addEventListener(this, InputEvent::EVENT_MOUSEUP_OUTSIDE);
+	mainColorRect->processInputEvents = true;
 	
 	
 	hueFrame->addEventListener(this, InputEvent::EVENT_MOUSEDOWN);
 	hueFrame->addEventListener(this, InputEvent::EVENT_MOUSEUP);
 	hueFrame->addEventListener(this, InputEvent::EVENT_MOUSEUP_OUTSIDE);
-	
+	hueFrame->processInputEvents = true;	
 	
 	ScreenLabel *label = new ScreenLabel(L"R:", fontSize, fontName);
 	label->setPosition(hueFrame->getPosition().x+hueFrame->getWidth() + 15, topPadding+padding + 3);
@@ -387,6 +388,7 @@ UIColorBox::UIColorBox(Color initialColor, Number width, Number height) : Screen
 	addChild(bgImage);
 
 	bgImage->addEventListener(this, InputEvent::EVENT_MOUSEDOWN);
+	bgImage->processInputEvents = true;
 
 	colorShape = new ScreenShape(ScreenShape::SHAPE_RECT, width-(frameInset*2), height-(frameInset*2));
 	colorShape->setPositionMode(ScreenEntity::POSITION_TOPLEFT);

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

@@ -112,10 +112,13 @@ UIComboBox::UIComboBox(Number comboWidth) : ScreenEntity() {
 	selectedOffset = 0;
 	dropDownBox->addEventListener(this, InputEvent::EVENT_MOUSEMOVE);
 	dropDownBox->addEventListener(this, InputEvent::EVENT_MOUSEDOWN);	
+	dropDownBox->processInputEvents = true;
 
 	dropDownImage->addEventListener(this, InputEvent::EVENT_MOUSEDOWN);	
+	dropDownImage->processInputEvents = true;	
 	bgBox->addEventListener(this, InputEvent::EVENT_MOUSEDOWN);	
-		
+	bgBox->processInputEvents = true;	
+			
 	isDroppedDown = false;
 	updateVis();
 	
@@ -165,7 +168,10 @@ void UIComboBox::handleEvent(Event *event) {
 			case InputEvent::EVENT_MOUSEMOVE:
 			{
 				InputEvent *inputEvent = (InputEvent*) event;
-				selectedOffset = floor(inputEvent->getMousePosition().y/comboHeight)- 1;
+				selectedOffset = floor(inputEvent->getMousePosition().y/comboHeight);
+				if(selectedOffset < 0)
+					selectedOffset = 0;
+					
 				if(selectedOffset >= 0 && selectedOffset < items.size())
 					selectorBox->setPosition(0,selectedOffset*comboHeight);
 			}				

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

@@ -74,7 +74,7 @@ UIHScrollBar::UIHScrollBar(Number width, Number height, Number initialRatio) : S
 	handleBox->addEventListener(this, InputEvent::EVENT_MOUSEUP);
 	handleBox->addEventListener(this, InputEvent::EVENT_MOUSEUP_OUTSIDE);	
 	handleBox->addEventListener(this, InputEvent::EVENT_MOUSEDOWN);		
-	
+	handleBox->processInputEvents = true;
 	handleBox->blockMouseInput = true;
 	
 	dragRectWidth = width-(padding*2)-scrollHandleWidth;

+ 4 - 3
Modules/Contents/UI/Source/PolyUIHSlider.cpp

@@ -65,12 +65,13 @@ UIHSlider::UIHSlider(Number start, Number end, Number width) {
 	bgHitBox->addEventListener(this, InputEvent::EVENT_MOUSEUP);
 	bgHitBox->addEventListener(this, InputEvent::EVENT_MOUSEUP_OUTSIDE);
 	bgHitBox->addEventListener(this, InputEvent::EVENT_MOUSEDOWN);
-
+	bgHitBox->processInputEvents = true;
 
 	gripRect->addEventListener(this, InputEvent::EVENT_MOUSEUP);
 	gripRect->addEventListener(this, InputEvent::EVENT_MOUSEUP_OUTSIDE);
 	gripRect->addEventListener(this, InputEvent::EVENT_MOUSEDOWN);
-	
+	gripRect->processInputEvents = true;
+		
 	gripRect->setDragLimits(Rectangle(0,floor(bgHeight/2.0),width,0));
 	
 	gripPos = 0;
@@ -117,7 +118,7 @@ void UIHSlider::handleEvent(Event *event) {
 				gripRect->startDrag(inputEvent->mousePosition.x-gripRect->getPosition().x,inputEvent->mousePosition.y-gripRect->getPosition().y);
 			break;
 			case InputEvent::EVENT_MOUSEUP:
-			case InputEvent::EVENT_MOUSEUP_OUTSIDE:
+			case InputEvent::EVENT_MOUSEUP_OUTSIDE:		
 				gripRect->stopDrag();
 			break;
 		}	

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

@@ -89,6 +89,7 @@ UITextInput::UITextInput(bool multiLine, Number width, Number height) : ScreenEn
 	inputRect->addEventListener(this, InputEvent::EVENT_MOUSEMOVE);		
 	inputRect->addEventListener(this, InputEvent::EVENT_MOUSEOVER);
 	inputRect->addEventListener(this, InputEvent::EVENT_MOUSEOUT);
+	inputRect->processInputEvents = true;
 	
 	selectorRectTop = new ScreenShape(ScreenShape::SHAPE_RECT, 1,1);
 	selectorRectTop->setPositionMode(ScreenEntity::POSITION_TOPLEFT);

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

@@ -73,7 +73,7 @@ UIVScrollBar::UIVScrollBar(Number width, Number height, Number initialRatio) : S
 	handleBox->addEventListener(this, InputEvent::EVENT_MOUSEUP);
 	handleBox->addEventListener(this, InputEvent::EVENT_MOUSEUP_OUTSIDE);	
 	handleBox->addEventListener(this, InputEvent::EVENT_MOUSEDOWN);			
-	
+	handleBox->processInputEvents = true;
 	handleBox->blockMouseInput = true;
 	
 	dragRectHeight = height-(padding*2)-scrollHandleHeight;

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

@@ -157,7 +157,6 @@ void UIWindow::handleEvent(Event *event) {
 				stopDrag();
 			break;
 			case InputEvent::EVENT_MOUSEDOWN:
-				printf("DRAG OFFSET: %f, %f\n", inputEvent->mousePosition.x,inputEvent->mousePosition.y);
 				startDrag(inputEvent->mousePosition.x,inputEvent->mousePosition.y);
 			break;
 		}