Forráskód Böngészése

Fixed more input event and UI stuff

Ivan Safrin 12 éve
szülő
commit
e45e14f3a2
29 módosított fájl, 304 hozzáadás és 210 törlés
  1. 17 62
      Core/Contents/Include/PolyEntity.h
  2. 3 3
      Core/Contents/Include/PolyGLRenderer.h
  3. 3 4
      Core/Contents/Include/PolyRenderer.h
  4. 86 43
      Core/Contents/Source/PolyEntity.cpp
  5. 8 21
      Core/Contents/Source/PolyGLRenderer.cpp
  6. 0 6
      Core/Contents/Source/PolyRenderer.cpp
  7. 6 6
      Core/Contents/Source/PolyScene.cpp
  8. 0 6
      Core/Contents/Source/PolySceneImage.cpp
  9. 0 2
      Core/Contents/Source/PolySceneLabel.cpp
  10. 1 1
      Modules/Contents/2DPhysics/Source/PolyPhysicsScreen.cpp
  11. 2 2
      Modules/Contents/UI/Include/PolyUIColorBox.h
  12. 37 0
      Modules/Contents/UI/Include/PolyUIElement.h
  13. 1 1
      Modules/Contents/UI/Include/PolyUIHSlider.h
  14. 2 2
      Modules/Contents/UI/Include/PolyUIWindow.h
  15. 10 1
      Modules/Contents/UI/Source/PolyUIBox.cpp
  16. 6 5
      Modules/Contents/UI/Source/PolyUIButton.cpp
  17. 7 7
      Modules/Contents/UI/Source/PolyUIColorBox.cpp
  18. 80 2
      Modules/Contents/UI/Source/PolyUIElement.cpp
  19. 1 1
      Modules/Contents/UI/Source/PolyUIFileDialog.cpp
  20. 2 2
      Modules/Contents/UI/Source/PolyUIHSizer.cpp
  21. 3 3
      Modules/Contents/UI/Source/PolyUIHSlider.cpp
  22. 3 2
      Modules/Contents/UI/Source/PolyUIImageButton.cpp
  23. 2 2
      Modules/Contents/UI/Source/PolyUIMenuBar.cpp
  24. 1 1
      Modules/Contents/UI/Source/PolyUIScrollContainer.cpp
  25. 9 9
      Modules/Contents/UI/Source/PolyUITextInput.cpp
  26. 3 3
      Modules/Contents/UI/Source/PolyUITree.cpp
  27. 2 2
      Modules/Contents/UI/Source/PolyUITreeContainer.cpp
  28. 2 2
      Modules/Contents/UI/Source/PolyUIVSizer.cpp
  29. 7 9
      Modules/Contents/UI/Source/PolyUIWindow.cpp

+ 17 - 62
Core/Contents/Include/PolyEntity.h

@@ -138,6 +138,8 @@ namespace Polycode {
 			
 			Matrix4 getConcatenatedMatrixRelativeTo(Entity *relativeEntity);
 			
+			Matrix4 getAnchorAdjustedMatrix();
+			
 			/** 
 			* Returns Same as getConcatenatedMatrix(), but contains only roll information for rotation. Used internally for billboards.
 			@return Entity's concatenated roll matrix.
@@ -508,19 +510,22 @@ namespace Polycode {
 			*/						
 			Number getCompoundBBoxRadius() const;
 			
+			
+			void setAnchorPoint(const Vector3 &anchorPoint);
+			void setAnchorPoint(Number x, Number y, Number z);			
+			Vector3 getAnchorPoint() const;
+			
 			/**
 			* Sets the bounding box radius.
 			* @param rad New bounding box radius.
 			*/
 			void setBBoxRadius(Number rad);		
 			
-			MouseEventResult _onMouseDown(const Ray &ray, int mouseButton, int timestamp);
-			MouseEventResult _onMouseUp(const Ray &ray, int mouseButton, int timestamp);
-			MouseEventResult _onMouseMove(const Ray &ray, int timestamp);
-			MouseEventResult _onMouseWheelUp(const Ray &ray, int timestamp);
-			MouseEventResult _onMouseWheelDown(const Ray &ray, int timestamp);
-
-			virtual bool hitTest() { return false; }
+			virtual MouseEventResult onMouseDown(const Ray &ray, int mouseButton, int timestamp);
+			virtual MouseEventResult onMouseUp(const Ray &ray, int mouseButton, int timestamp);
+			virtual MouseEventResult onMouseMove(const Ray &ray, int timestamp);
+			virtual MouseEventResult onMouseWheelUp(const Ray &ray, int timestamp);
+			virtual MouseEventResult onMouseWheelDown(const Ray &ray, int timestamp);
 
 			//@}			
 			// ----------------------------------------------------------------------------------------------------------------
@@ -689,72 +694,21 @@ namespace Polycode {
 			bool castShadows;
 			
 			int collisionShapeType;	
-
-			int positionMode;
-
-			/** 
-			* Changes the positioning mode of the screen entity.		
-			
-			If the positioning mode is Entity::POSITION_TOPLEFT, the entity is translated by half its width and half its height when it's rendered, making all other transformations relative to its top-left corner instead of the center.		
-			If the mode is Entity::POSITION_CENTER, the entity is rendered as is.
-			Set to POSITION_CENTER by default.
-			@param newPositionMode The new positioning mode.
-			*/
-			void setPositionMode(int newPositionMode);
-
-			/**
-			 * Get the position mode.
-			 * @see setPositionMode()
-			 */
-			int getPositionMode() const;
-		
-			/**
-			* Positioning mode in which you specify an entity's topleft corner
-			* as coordinate for placement.
-			*/
-		
-			static const int POSITION_TOPLEFT = 0;
-
-			/**
-			* Positioning mode in which you specify an entity's center as
-			* coordinate for placement.
-			*/
-			static const int POSITION_CENTER = 1;
-
-			bool processInputEvents;
-			
+			bool processInputEvents;			
 			bool blockMouseInput;
-			
-			bool hasFocus;
-			bool focusable;
-			
-			void setDragLimits(Rectangle rect) {}
-			void clearDragLimits() {}
-			bool isDragged() { return dragged; }
-			bool dragged;
-			void startDrag(Number xOffset, Number yOffset) {}
-			void stopDrag() {}
-			
+																					
 			void setHitbox(Number width, Number height) {}
-			
-			void focusChild(Entity *child) {}
-			void focusNextChild() {}
-			bool isFocusable() {}
-			
 			Vector2 getScreenPosition() const { return Vector2(); }
 
 			bool hitTest(Number x, Number y) const { return false; }
 			bool hitTest(Vector2 v) const { return false; }
 
-			bool snapToPixels;
-			
+			bool snapToPixels;			
 			bool mouseOver;
 			
 			//@}		
 		protected:
 		
-			void adjustMatrixForChildren();
-		
 			Number yAdjust;
 			std::vector<String> *tags;
 		
@@ -764,7 +718,8 @@ namespace Polycode {
 		
 			std::vector<Entity*> children;
 
-			Vector3 childCenter;
+			Vector3 anchorPoint;
+			
 			Number bBoxRadius;		
 		
 			Vector3 _position;

+ 3 - 3
Core/Contents/Include/PolyGLRenderer.h

@@ -147,7 +147,7 @@ namespace Polycode {
 		
 		void translate2D(Number x, Number y);
 		void rotate2D(Number angle);
-		void scale2D(Vector2 *scale);
+		void scale2D(const Vector2 &scale);
 		
 		void enableScissor(bool val);
 		void setScissorBox(Polycode::Rectangle box);		
@@ -165,9 +165,9 @@ namespace Polycode {
 		void enableFog(bool enable);
 		void setFogProperties(int fogMode, Color color, Number density, Number startDepth, Number endDepth);		
 				
-		void translate3D(Vector3 *position);
+		void translate3D(const Vector3 &position);
 		void translate3D(Number x, Number y, Number z);
-		void scale3D(Vector3 *scale);
+		void scale3D(const Vector3 &scale);
 		
 		Matrix4 getProjectionMatrix();
 		Matrix4 getModelviewMatrix();		

+ 3 - 4
Core/Contents/Include/PolyRenderer.h

@@ -130,7 +130,7 @@ namespace Polycode {
 		
 		virtual void translate2D(Number x, Number y) = 0;
 		virtual void rotate2D(Number angle) = 0;
-		virtual void scale2D(Vector2 *scale) = 0;
+		virtual void scale2D(const Vector2 &scale) = 0;
 			
 		
 		virtual void setVertexColor(Number r, Number g, Number b, Number a) = 0;
@@ -143,9 +143,9 @@ namespace Polycode {
 		virtual void setRenderArrayData(RenderDataArray *array, Number *arrayData) = 0;
 		virtual void drawArrays(int drawType) = 0;
 		
-		virtual void translate3D(Vector3 *position) = 0;
+		virtual void translate3D(const Vector3 &position) = 0;
 		virtual void translate3D(Number x, Number y, Number z) = 0;
-		virtual void scale3D(Vector3 *scale) = 0;
+		virtual void scale3D(const Vector3 &scale) = 0;
 		
 		virtual void pushMatrix() = 0;
 		virtual void popMatrix() = 0;
@@ -216,7 +216,6 @@ namespace Polycode {
 		
 		const Matrix4& getCameraMatrix() const;
 		void setCameraMatrix(const Matrix4& matrix);
-		void setCameraPosition(Vector3 pos);
 		
 		virtual void drawScreenQuad(Number qx, Number qy) = 0;
 		

+ 86 - 43
Core/Contents/Source/PolyEntity.cpp

@@ -60,12 +60,11 @@ Entity::Entity() : EventDispatcher() {
 	processInputEvents = false;
 	blockMouseInput = false;
 	editorOnly = false; 
-	hasFocus = false;
 	snapToPixels = false;
 	tags = NULL;
+	bBox.z = 0.001;
 	mouseOver = false;
 	yAdjust = 1.0;
-	positionMode = POSITION_CENTER;
 }
 
 Entity *Entity::getEntityById(String id, bool recursive) const {
@@ -302,10 +301,6 @@ Entity::~Entity() {
 	if(tags) delete tags;
 }
 
-Vector3 Entity::getChildCenter() const {
-	return childCenter;
-}
-
 void Entity::setInverseY(bool val) {
 	if(val) {
 		yAdjust = -1.0;
@@ -323,19 +318,10 @@ bool Entity::getInverseY() {
 
 Matrix4 Entity::buildPositionMatrix() {
 	Matrix4 posMatrix;
-	switch(positionMode) {
-		case POSITION_TOPLEFT:
-			posMatrix.m[3][0] = (position.x+(bBox.x/2.0f)*scale.x);
-			posMatrix.m[3][1] = (position.y+(bBox.y/2.0f)*scale.y) * yAdjust;
-			posMatrix.m[3][2] = position.z;			
-		break;
-		case POSITION_CENTER:
-			posMatrix.m[3][0] = position.x;
-			posMatrix.m[3][1] = position.y * yAdjust;
-			posMatrix.m[3][2] = position.z;
-		break;
-	}
-
+	
+	posMatrix.m[3][0] = position.x;
+	posMatrix.m[3][1] = position.y * yAdjust;
+	posMatrix.m[3][2] = position.z;
 
 	if(snapToPixels) {
 		posMatrix.m[3][0] = round(posMatrix.m[3][0]);
@@ -346,16 +332,6 @@ Matrix4 Entity::buildPositionMatrix() {
 	return posMatrix;
 }
 
-void Entity::adjustMatrixForChildren() {
-	if(positionMode == POSITION_TOPLEFT) {
-		if(snapToPixels) {
-			renderer->translate2D(-floor(bBox.x/2.0f), floor(bBox.y/2.0f));			
-		} else {
-			renderer->translate2D(-bBox.x/2.0f, bBox.y/2.0f);	
-		}
-	}
-}
-
 void Entity::rebuildTransformMatrix() {
 	if(lockMatrix)
 		return;
@@ -507,12 +483,15 @@ void Entity::transformAndRender() {
 		renderer->setRenderMode(Renderer::RENDER_MODE_WIREFRAME);
 	else
 		renderer->setRenderMode(Renderer::RENDER_MODE_NORMAL);	
+				
 	if(visible) {
+		renderer->pushMatrix();		
+		renderer->translate3D(-anchorPoint.x * bBox.x * 0.5, -anchorPoint.y * bBox.y * 0.5 * yAdjust, -anchorPoint.z * bBox.z * 0.5);
 		Render();
+		renderer->popMatrix();
 	}
 		
 	if(visible || (!visible && !visibilityAffectsChildren)) {
-		adjustMatrixForChildren();
 		renderChildren();	
 	}
 		
@@ -587,6 +566,13 @@ Matrix4 Entity::getConcatenatedMatrixRelativeTo(Entity *relativeEntity) {
 		return transformMatrix;
 }
 
+Matrix4 Entity::getAnchorAdjustedMatrix() {
+	Matrix4 mat = getConcatenatedMatrix();
+	Matrix4 adjust;
+	adjust.setPosition(-anchorPoint.x * bBox.x * 0.5, -anchorPoint.y * bBox.y * 0.5 * yAdjust, -anchorPoint.z * bBox.z * 0.5);
+	return mat * adjust;
+}
+
 Matrix4 Entity::getConcatenatedMatrix() {
 	checkTransformSetters();
 	if(matrixDirty)
@@ -850,31 +836,88 @@ void Entity::addTag(String tag) {
 	}
 }
 
-void Entity::setPositionMode(int newPositionMode) {
-	positionMode = newPositionMode;
+void Entity::setAnchorPoint(const Vector3 &anchorPoint) {
+	this->anchorPoint = anchorPoint;	
 }
 
-int Entity::getPositionMode() const {
-	return positionMode;
+void Entity::setAnchorPoint(Number x, Number y, Number z) {
+	anchorPoint.set(x,y,z);
 }
 
-MouseEventResult Entity::_onMouseDown(const Ray &ray, int mouseButton, int timestamp) {
-	MouseEventResult ret;
-	return ret;
+Vector3 Entity::getAnchorPoint() const {
+	return anchorPoint;
 }
 
-MouseEventResult Entity::_onMouseUp(const Ray &ray, int mouseButton, int timestamp) {
+
+MouseEventResult Entity::onMouseDown(const Ray &ray, int mouseButton, int timestamp) {
 	MouseEventResult ret;
+	ret.hit = false;
+	ret.blocked = false;
+	
+	if(processInputEvents && enabled) {
+		if(ray.boxIntersect(bBox, getAnchorAdjustedMatrix())) {
+			ret.hit = true;	
+			
+			Vector3 localCoordinate = Vector3(ray.origin.x,ray.origin.y,0);
+			Matrix4 inverse = getConcatenatedMatrix().Inverse();
+			localCoordinate = inverse * localCoordinate;			
+			
+			dispatchEvent(new InputEvent(Vector2(localCoordinate.x, localCoordinate.y), timestamp), InputEvent::EVENT_MOUSEDOWN);
+						
+			if(blockMouseInput) {
+				ret.blocked = true;
+			}
+		}
+		
+		for(int i=0; i < children.size(); i++) {
+			MouseEventResult childRes = children[i]->onMouseDown(ray, mouseButton, timestamp);
+				if(childRes.hit)
+					ret.hit = true;
+				
+				if(childRes.blocked) {
+					ret.blocked = true;
+					break;
+				}			
+		}
+	}
 	return ret;
 }
 
-MouseEventResult Entity::_onMouseMove(const Ray &ray, int timestamp) {
+MouseEventResult Entity::onMouseUp(const Ray &ray, int mouseButton, int timestamp) {
+	MouseEventResult ret;
+	ret.hit = false;
+	ret.blocked = false;
+	
+	if(processInputEvents && enabled) {
+		if(ray.boxIntersect(bBox, getAnchorAdjustedMatrix())) {
+			ret.hit = true;			
+			dispatchEvent(new InputEvent(Vector2(), timestamp), InputEvent::EVENT_MOUSEUP);
+						
+			if(blockMouseInput) {
+				ret.blocked = true;
+			}
+		}
+		
+		for(int i=0; i < children.size(); i++) {
+			MouseEventResult childRes = children[i]->onMouseUp(ray, mouseButton, timestamp);
+				if(childRes.hit)
+					ret.hit = true;
+				
+				if(childRes.blocked) {
+					ret.blocked = true;
+					break;
+				}			
+		}
+	}
+	return ret;}
+
+MouseEventResult Entity::onMouseMove(const Ray &ray, int timestamp) {
 	MouseEventResult ret;
 	ret.hit = false;
 	ret.blocked = false;
 	
 	if(processInputEvents && enabled) {
-		if(ray.boxIntersect(bBox, getConcatenatedMatrix())) {
+		if(ray.boxIntersect(bBox, getAnchorAdjustedMatrix())) {	
 			ret.hit = true;			
 			dispatchEvent(new InputEvent(Vector2(), timestamp), InputEvent::EVENT_MOUSEMOVE);
 			
@@ -894,7 +937,7 @@ MouseEventResult Entity::_onMouseMove(const Ray &ray, int timestamp) {
 		}
 		
 		for(int i=0; i < children.size(); i++) {
-			MouseEventResult childRes = children[i]->_onMouseMove(ray, timestamp);
+			MouseEventResult childRes = children[i]->onMouseMove(ray, timestamp);
 				if(childRes.hit)
 					ret.hit = true;
 				
@@ -907,12 +950,12 @@ MouseEventResult Entity::_onMouseMove(const Ray &ray, int timestamp) {
 	return ret;
 }
 
-MouseEventResult Entity::_onMouseWheelUp(const Ray &ray, int timestamp) {
+MouseEventResult Entity::onMouseWheelUp(const Ray &ray, int timestamp) {
 	MouseEventResult ret;
 	return ret;
 }
 
-MouseEventResult Entity::_onMouseWheelDown(const Ray &ray, int timestamp) {
+MouseEventResult Entity::onMouseWheelDown(const Ray &ray, int timestamp) {
 	MouseEventResult ret;
 	return ret;
 }

+ 8 - 21
Core/Contents/Source/PolyGLRenderer.cpp

@@ -561,16 +561,16 @@ void OpenGLRenderer::BeginRender() {
 	currentTexture = NULL;
 }
 
-void OpenGLRenderer::translate3D(Vector3 *position) {
-	glTranslatef(position->x, position->y, position->z);
+void OpenGLRenderer::translate3D(const Vector3 &position) {
+	glTranslatef(position.x, position.y, position.z);
 }
 
 void OpenGLRenderer::translate3D(Number x, Number y, Number z) {
 	glTranslatef(x, y, z);
 }
 
-void OpenGLRenderer::scale3D(Vector3 *scale) {
-	glScalef(scale->x, scale->y, scale->z);
+void OpenGLRenderer::scale3D(const Vector3 &scale) {
+	glScalef(scale.x, scale.y, scale.z);
 }
 
 void OpenGLRenderer::bindFrameBufferTextureDepth(Texture *texture) {
@@ -802,10 +802,12 @@ void OpenGLRenderer::setTexture(Texture *texture) {
 }
 
 void OpenGLRenderer::pushMatrix() {
+	glMatrixMode(GL_MODELVIEW);
 	glPushMatrix();
 }
 
 void OpenGLRenderer::popMatrix() {
+	glMatrixMode(GL_MODELVIEW);
 	glPopMatrix();
 }
 
@@ -1039,21 +1041,6 @@ void OpenGLRenderer::drawArrays(int drawType) {
 	glDisableClientState( GL_COLOR_ARRAY );		
 }
 
-/*
-void OpenGLRenderer::draw3DVertex2UV(Vertex *vertex, Vector2 *faceUV1, Vector2 *faceUV2) {
-	if(vertex->useVertexColor)
-		glColor4f(vertex->vertexColor.r, vertex->vertexColor.g, vertex->vertexColor.b, vertex->vertexColor.a);
-
-	if(currentTexture || currentMaterial) {
-		glMultiTexCoord2f(GL_TEXTURE0, faceUV1->x, faceUV1->y);
-		glMultiTexCoord2f(GL_TEXTURE1, faceUV2->x, faceUV2->y);
-	}
-
-//	glNormal3f(vertex->normal->x, vertex->normal->y, vertex->normal->z);
-	glVertex3f(vertex->x, vertex->y, vertex->z);
-}
-*/
-
 void OpenGLRenderer::drawScreenQuad(Number qx, Number qy) {
 	setOrthoMode();
 	
@@ -1083,8 +1070,8 @@ void OpenGLRenderer::translate2D(Number x, Number y) {
 	glTranslatef(x, y, 0.0f);
 }
 
-void OpenGLRenderer::scale2D(Vector2 *scale) {
-	glScalef(scale->x, scale->y, 1.0f);
+void OpenGLRenderer::scale2D(const Vector2 &scale) {
+	glScalef(scale.x, scale.y, 1.0f);
 }
 
 void OpenGLRenderer::loadIdentity() {

+ 0 - 6
Core/Contents/Source/PolyRenderer.cpp

@@ -139,12 +139,6 @@ const Matrix4& Renderer::getCameraMatrix() const {
 	return cameraMatrix;
 }
 
-void Renderer::setCameraPosition(Vector3 pos) {
-	cameraPosition = pos;
-	pos = pos * -1;
-	this->translate3D(&pos);
-}
-
 void Renderer::enableScissor(bool val) {
 	scissorEnabled = val;
 }

+ 6 - 6
Core/Contents/Source/PolyScene.cpp

@@ -292,7 +292,7 @@ void Scene::handleEvent(Event *event) {
 				pos = activeCamera->getConcatenatedMatrix() * pos;			
 			break;
 			case SCENE_3D:
-				Vector3 pos = activeCamera->getConcatenatedMatrix().getPosition();
+				pos = activeCamera->getConcatenatedMatrix().getPosition();
 			break;		
 		}
 				
@@ -300,19 +300,19 @@ void Scene::handleEvent(Event *event) {
 		
 		switch(inputEvent->getEventCode()) {
 			case InputEvent::EVENT_MOUSEDOWN:
-				rootEntity._onMouseDown(ray, inputEvent->mouseButton, inputEvent->timestamp);
+				rootEntity.onMouseDown(ray, inputEvent->mouseButton, inputEvent->timestamp);
 			break;
 			case InputEvent::EVENT_MOUSEMOVE:
-				rootEntity._onMouseMove(ray, inputEvent->timestamp);
+				rootEntity.onMouseMove(ray, inputEvent->timestamp);
 			break;
 			case InputEvent::EVENT_MOUSEUP:
-				rootEntity._onMouseUp(ray, inputEvent->mouseButton, inputEvent->timestamp);
+				rootEntity.onMouseUp(ray, inputEvent->mouseButton, inputEvent->timestamp);
 			break;
 			case InputEvent::EVENT_MOUSEWHEEL_UP:
-				rootEntity._onMouseWheelUp(ray, inputEvent->timestamp);
+				rootEntity.onMouseWheelUp(ray, inputEvent->timestamp);
 			break;
 			case InputEvent::EVENT_MOUSEWHEEL_DOWN:
-				rootEntity._onMouseWheelDown(ray,inputEvent->timestamp);	
+				rootEntity.onMouseWheelDown(ray,inputEvent->timestamp);	
 			break;	
 		}
 	}

+ 0 - 6
Core/Contents/Source/PolySceneImage.cpp

@@ -45,8 +45,6 @@ SceneImage::SceneImage(const String& fileName) : ScenePrimitive(ScenePrimitive::
 	setWidth(texture->getWidth());
 	setHeight(texture->getHeight());
 	setPrimitiveOptions(ScenePrimitive::TYPE_VPLANE, getWidth(), getHeight());
-
-	setPositionMode(POSITION_TOPLEFT);
 }
 
 SceneImage::SceneImage(Image *image) : ScenePrimitive(ScenePrimitive::TYPE_VPLANE, 1, 1) {
@@ -58,8 +56,6 @@ SceneImage::SceneImage(Image *image) : ScenePrimitive(ScenePrimitive::TYPE_VPLAN
 	setWidth(texture->getWidth());
 	setHeight(texture->getHeight());	
 	setPrimitiveOptions(ScenePrimitive::TYPE_VPLANE, getWidth(), getHeight());
-
-	setPositionMode(POSITION_TOPLEFT);	
 }
 
 SceneImage::SceneImage(Texture *texture) : ScenePrimitive(ScenePrimitive::TYPE_VPLANE, 1, 1)  {
@@ -71,8 +67,6 @@ SceneImage::SceneImage(Texture *texture) : ScenePrimitive(ScenePrimitive::TYPE_V
 	setWidth(texture->getWidth());
 	setHeight(texture->getHeight());	
 	setPrimitiveOptions(ScenePrimitive::TYPE_VPLANE, getWidth(), getHeight());
-
-	setPositionMode(POSITION_TOPLEFT);
 }
 
 SceneImage::~SceneImage() {

+ 0 - 2
Core/Contents/Source/PolySceneLabel.cpp

@@ -35,7 +35,6 @@ SceneLabel::SceneLabel(const String& fontName, const String& text, int size, Num
 	label = new Label(CoreServices::getInstance()->getFontManager()->getFontByName(fontName), text, size, amode, premultiplyAlpha);
 	this->labelScale = scale;
 	positionAtBaseline = false;
-	setPositionMode(Entity::POSITION_TOPLEFT);	
 	updateFromLabel();
 }
 
@@ -44,7 +43,6 @@ SceneLabel::SceneLabel(const String& text, int size, const String& fontName, int
 	label = new Label(CoreServices::getInstance()->getFontManager()->getFontByName(fontName), text, size, amode, premultiplyAlpha);
 	this->labelScale = 1.0;
 	positionAtBaseline = false;
-	setPositionMode(Entity::POSITION_TOPLEFT);		
 	updateFromLabel();
 }
 			

+ 1 - 1
Modules/Contents/2DPhysics/Source/PolyPhysicsScreen.cpp

@@ -474,7 +474,7 @@ PhysicsScene2DEntity *PhysicsScene2D::addPhysicsChild(Entity *newEntity, int ent
 }
 
 PhysicsScene2DEntity *PhysicsScene2D::trackPhysicsChild(Entity *newEntity, int entType, bool isStatic, Number friction, Number density, Number restitution, bool isSensor, bool fixedRotation, int groupIndex) {
-	newEntity->setPositionMode(Entity::POSITION_CENTER);
+
 	PhysicsScene2DEntity *newPhysicsEntity = new PhysicsScene2DEntity(newEntity, world, worldScale, entType, isStatic, friction, density, restitution, isSensor,fixedRotation, groupIndex);
 	physicsChildren.push_back(newPhysicsEntity);
 	newPhysicsEntity->body->SetAwake(true);

+ 2 - 2
Modules/Contents/UI/Include/PolyUIColorBox.h

@@ -86,8 +86,8 @@ namespace Polycode {
 			SceneImage *mainFrame;
 			SceneImage *mainBg;			
 			SceneImage *hueFrame;
-			SceneImage *hueSelector;
-			SceneImage *mainSelector;	
+			UIImage *hueSelector;
+			UIImage *mainSelector;	
 			
 			UIHSlider *alphaSlider;
 			

+ 37 - 0
Modules/Contents/UI/Include/PolyUIElement.h

@@ -23,6 +23,7 @@
 #pragma once
 #include "PolyGlobals.h"
 #include "PolyEntity.h"
+#include "PolySceneImage.h"
 
 namespace Polycode {
 	/*
@@ -37,9 +38,45 @@ namespace Polycode {
 			~UIElement();
 			
 			virtual void Resize(Number width, Number height);
+						
+			bool hasFocus;
+			bool focusable;
 			
+			void setDragLimits(Rectangle rect);
+			void clearDragLimits();
+			bool isDragged();
+			void startDrag(Number xOffset, Number yOffset);
+			void stopDrag();
+			
+			void focusChild(Entity *child) {}
+			void focusNextChild() {}
+			bool isFocusable();
+			
+			void addFocusChild(UIElement *element);			
+			void setFocusParent(UIElement *element);
+
+			MouseEventResult onMouseMove(const Ray &ray, int timestamp);
+
+			bool dragged;
+
 		protected:
+		
+			Polycode::Rectangle dragLimits;
+			bool hasDragLimits;
+		
+			Number dragOffsetX;
+			Number dragOffsetY;
 			
+			std::vector<UIElement*> focusChildren;
+			UIElement *focusParent;
+			
+	};
+	
+	class _PolyExport UIImage : public UIElement {
+		public:
+			UIImage(String imagePath);
+		protected:
+			SceneImage *image;
 	};
 	
 }

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

@@ -58,7 +58,7 @@ namespace Polycode {
 			Number bgHeight;
 			
 			UIBox *bgRect;
-			SceneImage *gripRect;
+			UIImage *gripRect;
 			
 			Number sliderValue;
 			Number startValue;

+ 2 - 2
Modules/Contents/UI/Include/PolyUIWindow.h

@@ -25,7 +25,7 @@
 #include "PolyGlobals.h"
 #include "PolyScenePrimitive.h"
 #include "PolySceneLabel.h"
-#include "PolyEntity.h"
+#include "PolyUIElement.h"
 #include "PolyUIEvent.h"
 #include "PolyUIImageButton.h"
 #include "PolyFont.h"
@@ -35,7 +35,7 @@
 
 namespace Polycode {
 
-	class _PolyExport UIWindow : public Entity {
+	class _PolyExport UIWindow : public UIElement {
 		public:
 			UIWindow(String windowName, Number width, Number height);
 			virtual ~UIWindow();

+ 10 - 1
Modules/Contents/UI/Source/PolyUIBox.cpp

@@ -26,52 +26,61 @@ using namespace Polycode;
 
 UIBox::UIBox(String imageFile, Number t, Number r, Number b, Number l, Number boxWidth, Number boxHeight) : UIElement() {
 	
-	setPositionMode(Entity::POSITION_TOPLEFT);	
+	setAnchorPoint(-1.0, -1.0, 0.0);	
 	
 	setWidth(boxWidth);
 	setHeight(boxHeight);
 	
 	tlImage = new SceneImage(imageFile);
+	tlImage->setAnchorPoint(-1.0, -1.0, 0.0);
 	tlImage->setImageCoordinates(0,0,l,t);
 	addChild(tlImage);
 	tlImage->setPosition(0, 0);
 	
 	trImage = new SceneImage(imageFile);
+	trImage->setAnchorPoint(-1.0, -1.0, 0.0);
 	trImage->setImageCoordinates(trImage->getWidth()-r,0,r,t);
 	addChild(trImage);	
 	trImage->setPosition(boxWidth-r, 0);
 
 	blImage = new SceneImage(imageFile);
+	blImage->setAnchorPoint(-1.0, -1.0, 0.0);	
 	blImage->setImageCoordinates(0,blImage->getHeight()-b,l,b);
 	addChild(blImage);	
 	blImage->setPosition(0, boxHeight-b);
 
 	brImage = new SceneImage(imageFile);
+	brImage->setAnchorPoint(-1.0, -1.0, 0.0);
 	brImage->setImageCoordinates(brImage->getWidth()-r,brImage->getHeight()-b,r,b);
 	addChild(brImage);	
 	brImage->setPosition(boxWidth-r, boxHeight-b);	
 	
 	centerImage = new SceneImage(imageFile);
+	centerImage->setAnchorPoint(-1.0, -1.0, 0.0);
 	centerImage->setImageCoordinates(l,t,centerImage->getWidth()-l-r, centerImage->getHeight()-t-b, boxWidth-l-r, boxHeight-t-b);
 	addChild(centerImage);	
 	centerImage->setPosition(l,t);	
 	
 	tImage = new SceneImage(imageFile);
+	tImage->setAnchorPoint(-1.0, -1.0, 0.0);
 	tImage->setImageCoordinates(l,0,tImage->getWidth()-l-r,t, boxWidth-l-r, t);
 	addChild(tImage);
 	tImage->setPosition(l,0);	
 
 	bImage = new SceneImage(imageFile);
+	bImage->setAnchorPoint(-1.0, -1.0, 0.0);	
 	bImage->setImageCoordinates(l,bImage->getHeight()-b,bImage->getWidth()-l-r,b, boxWidth-l-r, b);
 	addChild(bImage);
 	bImage->setPosition(l,boxHeight-b);	
 
 	lImage = new SceneImage(imageFile);
+	lImage->setAnchorPoint(-1.0, -1.0, 0.0);		
 	lImage->setImageCoordinates(0,t,l,lImage->getHeight()-t-b, l, boxHeight-t-b);
 	addChild(lImage);
 	lImage->setPosition(0,t);	
 
 	rImage = new SceneImage(imageFile);
+	rImage->setAnchorPoint(-1.0, -1.0, 0.0);		
 	rImage->setImageCoordinates(rImage->getWidth()-r,t,r,rImage->getHeight()-t-b, r, boxHeight-t-b);
 	addChild(rImage);
 	rImage->setPosition(boxWidth-r,t);	

+ 6 - 5
Modules/Contents/UI/Source/PolyUIButton.cpp

@@ -74,9 +74,10 @@ UIButton::UIButton(String text, Number width, Number height) : UIElement() {
 	buttonLabel->color.setColorHexFromString(conf->getStringValue("Polycode", "uiButtonFontColor"));
 	addChild(buttonLabel);
 	labelXPos = floor((width-buttonLabel->getWidth())/2.0f) + labelOffsetX;
-	labelYPos = labelOffsetY;
+	labelYPos = floor(height/2.0) + labelOffsetY;
 	buttonLabel->setPosition(labelXPos,labelYPos);
-	
+	buttonLabel->positionAtBaseline = true;
+	buttonLabel->setAnchorPoint(-1.0, -1.0, 0.0);
 	setWidth(width);
 	setHeight(height);
 	focusable = true;
@@ -93,7 +94,7 @@ void UIButton::Resize(Number width, Number height) {
 	matrixDirty = true;	
 	
 	labelXPos = floor((width-buttonLabel->getWidth())/2.0f) + labelOffsetX;
-	labelYPos = labelOffsetY;
+	labelYPos = floor(height/2.0) + labelOffsetY;
 	buttonLabel->setPosition(labelXPos,labelYPos);
 	
 	UIElement::Resize(width, height);
@@ -155,8 +156,8 @@ void UIButton::handleEvent(Event *event) {
 			break;
 			case InputEvent::EVENT_MOUSEDOWN:
 				pressedDown = true;
-				if(parentEntity)
-					((Entity*)parentEntity)->focusChild(this);
+				if(focusParent)
+					focusParent->focusChild(this);
 				buttonLabel->setPosition(labelXPos+1,labelYPos+1);
 				buttonRect->setPosition(1,1);
 			break;

+ 7 - 7
Modules/Contents/UI/Source/PolyUIColorBox.cpp

@@ -60,7 +60,7 @@ UIColorPicker::UIColorPicker() : UIWindow(L"", 300, 240) {
 	alphaSlider->addEventListener(this, UIEvent::CHANGE_EVENT);
 	
 	mainColorRect = new ScenePrimitive(ScenePrimitive::TYPE_VPLANE, mainFrame->getWidth(), mainFrame->getHeight());
-	mainColorRect->setPositionMode(Entity::POSITION_TOPLEFT);
+	mainColorRect->setAnchorPoint(-1.0, -1.0, 0.0);
 	mainColorRect->setPosition(padding+1, topPadding+padding+1);
 	addChild(mainColorRect);
 	addChild(mainFrame);
@@ -69,15 +69,15 @@ UIColorPicker::UIColorPicker() : UIWindow(L"", 300, 240) {
 	hueFrame->setPosition(mainFrame->getPosition().x + mainFrame->getWidth()+10, topPadding+padding);
 	addChild(hueFrame);
 	
-	hueSelector = new SceneImage(hueSelectorImage);
-	hueSelector->setPositionMode(Entity::POSITION_CENTER);
+	hueSelector = new UIImage(hueSelectorImage);
+	hueSelector->setAnchorPoint(0.0, 0.0, 0.0);
 	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 SceneImage(mainSelectorImage);
-	mainSelector->setPositionMode(Entity::POSITION_CENTER);	
+	mainSelector = new UIImage(mainSelectorImage);
+	mainSelector->setAnchorPoint(0.0, 0.0, 0.0);
 	mainSelector->setPosition(mainFrame->getPosition());
 	addChild(mainSelector);	
 	
@@ -434,7 +434,7 @@ UIColorBox::UIColorBox(UIColorPicker *colorPicker, Color initialColor, Number wi
 
 
 	bgImage = new ScenePrimitive(ScenePrimitive::TYPE_VPLANE, width-(frameInset*2), height-(frameInset*2));
-	bgImage->setPositionMode(Entity::POSITION_TOPLEFT);
+	bgImage->setAnchorPoint(-1.0, -1.0, 0.0);
 	bgImage->loadTexture(bgImageFile);
 	bgImage->setPosition(frameInset, frameInset);	
 	addChild(bgImage);
@@ -443,7 +443,7 @@ UIColorBox::UIColorBox(UIColorPicker *colorPicker, Color initialColor, Number wi
 	bgImage->processInputEvents = true;
 
 	colorShape = new ScenePrimitive(ScenePrimitive::TYPE_VPLANE, width-(frameInset*2), height-(frameInset*2));
-	colorShape->setPositionMode(Entity::POSITION_TOPLEFT);
+	colorShape->setAnchorPoint(-1.0, -1.0, 0.0);
 	colorShape->setPosition(frameInset, frameInset);
 	addChild(colorShape);
 

+ 80 - 2
Modules/Contents/UI/Source/PolyUIElement.cpp

@@ -24,23 +24,101 @@
 
 using namespace Polycode;
 
+UIImage::UIImage(String imagePath) : UIElement() {
+	image = new SceneImage(imagePath);
+	addChild(image);
+	setWidth(image->bBox.x);
+	setHeight(image->bBox.y);	
+}
+
 UIElement::UIElement() : Entity() {
-	setPositionMode(Entity::POSITION_TOPLEFT);
+	setAnchorPoint(-1.0, -1.0, 0.0);
 	processInputEvents = true;
 	depthTest = false;	
+	hasFocus = false;
+	focusable = false;
+	focusParent = NULL;
+	hasDragLimits = false;
+	dragged = false;	
 }
 
 UIElement::UIElement(Number width, Number height) : Entity() {
-	setPositionMode(Entity::POSITION_TOPLEFT);
+	setAnchorPoint(-1.0, -1.0, 0.0);
 	processInputEvents = true;
+	focusParent = NULL;
+	hasDragLimits = false;	
+	dragged = false;	
 	setWidth(width);
 	setHeight(height);
 }
 
+void UIElement::setDragLimits(Rectangle rect) {
+	dragLimits.x = rect.x;
+	dragLimits.y = rect.y;
+	dragLimits.w = rect.w;
+	dragLimits.h = rect.h;
+	hasDragLimits = true;
+}
+
+void UIElement::clearDragLimits() {
+	hasDragLimits = false;
+}
+
+bool UIElement::isDragged() {
+	return dragged;
+}
+
+void UIElement::startDrag(Number xOffset, Number yOffset) {
+	dragged = true;
+	dragOffsetX = xOffset;
+	dragOffsetY = yOffset;
+}
+
+void UIElement::stopDrag() {
+	dragged = false;
+}
+
+bool UIElement::isFocusable() {
+	return focusable;
+}
+
+MouseEventResult UIElement::onMouseMove(const Ray &ray, int timestamp) {
+	if(dragged) {	
+		Vector3 localCoordinate = Vector3(ray.origin.x, ray.origin.y,0);
+
+		if(parentEntity) {
+			Matrix4 inverse = parentEntity->getConcatenatedMatrix().Inverse();
+			localCoordinate = inverse * localCoordinate;		
+		}
+		setPosition(localCoordinate.x-dragOffsetX,-localCoordinate.y+dragOffsetY);
+		if(hasDragLimits) {
+			if(position.x < dragLimits.x)
+				position.x = dragLimits.x;
+			if(position.x > dragLimits.x + dragLimits.w)
+				position.x = dragLimits.x + dragLimits.w;
+			if(position.y < dragLimits.y)
+				position.y = dragLimits.y;
+			if(position.y > dragLimits.y + dragLimits.h)
+				position.y = dragLimits.y + dragLimits.h;
+		}		
+		
+	}
+	return Entity::onMouseMove(ray, timestamp);
+}
+
 UIElement::~UIElement() {
 
 }
 
+void UIElement::addFocusChild(UIElement *element) {
+	element->setFocusParent(element);
+	focusChildren.push_back(element);
+}
+
+void UIElement::setFocusParent(UIElement *element) {
+	focusParent = element;	
+}
+
 void UIElement::Resize(Number width, Number height) {
 	setWidth(width);
 	setHeight(height);

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

@@ -14,7 +14,7 @@ UIFileDialogEntry::UIFileDialogEntry(OSFileEntry entry, bool canSelect, int widt
 	String placeIconName = conf->getStringValue("Polycode", "uiFileBrowserPlaceIcon");
 
 	bg = new ScenePrimitive(ScenePrimitive::TYPE_VPLANE, width, 18);
-	bg->setPositionMode(Entity::POSITION_TOPLEFT);
+	bg->setAnchorPoint(-1.0, -1.0, 0.0);
 	addChild(bg);
 	bg->setColor(0.0, 0.0, 0.0, 0.1);
 	bg->processInputEvents = true;

+ 2 - 2
Modules/Contents/UI/Source/PolyUIHSizer.cpp

@@ -37,7 +37,7 @@ UIHSizer::UIHSizer(Number width, Number height, Number mainWidth, bool leftSizer
 	this->mainWidth = mainWidth;
 	
 	separatorBgShape = new ScenePrimitive(ScenePrimitive::TYPE_VPLANE, 1,height);
-	separatorBgShape->setPositionMode(Entity::POSITION_TOPLEFT);
+	separatorBgShape->setAnchorPoint(-1.0, -1.0, 0.0);
 	separatorBgShape->setColor(0.0, 0.0, 0.0, 1.0);	
 	addChild(separatorBgShape);
 	
@@ -50,7 +50,7 @@ UIHSizer::UIHSizer(Number width, Number height, Number mainWidth, bool leftSizer
 	secondElement = NULL;
 	
 	separatorHitShape = new ScenePrimitive(ScenePrimitive::TYPE_VPLANE, 8,height);
-	separatorHitShape->setPositionMode(Entity::POSITION_TOPLEFT);
+	separatorHitShape->setAnchorPoint(-1.0, -1.0, 0.0);
 	separatorHitShape->setColor(1.0, 0.0, 0.0, 0.5);	
 	separatorHitShape->blockMouseInput = true;	
 	addChild(separatorHitShape);

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

@@ -52,12 +52,12 @@ UIHSlider::UIHSlider(Number start, Number end, Number width) : UIElement() {
 	startValue = start;
 	endValue = end;
 		
-	gripRect = new SceneImage(gripImage);
-	gripRect->setPositionMode(Entity::POSITION_CENTER);
+	gripRect = new UIImage(gripImage);
+	gripRect->setAnchorPoint(0.0, 0.0, 0.0);
 	gripRect->setPosition(0, floor(bgHeight/2.0));
 
 	bgHitBox = new ScenePrimitive(ScenePrimitive::TYPE_VPLANE, width, gripRect->getHeight());
-	bgHitBox->setPositionMode(Entity::POSITION_TOPLEFT);
+	bgHitBox->setAnchorPoint(-1.0, -1.0, 0.0);
 	bgHitBox->setPosition(0, gripRect->getPosition().y - (gripRect->getHeight()/2.0));
 	addChild(bgHitBox);
 	bgHitBox->setColor(1.0,0.0,0.0,0.0);

+ 3 - 2
Modules/Contents/UI/Source/PolyUIImageButton.cpp

@@ -29,15 +29,16 @@
 using namespace Polycode;
 
 UIImageButton::UIImageButton(String imageName) : UIElement() {
-	setPositionMode(Entity::POSITION_TOPLEFT);
+	setAnchorPoint(-1.0, -1.0, 0.0);
 	
 	buttonImage = new SceneImage(imageName.c_str());
 	addChild(buttonImage);
 	buttonImage->depthTest = false;
+	buttonImage->setAnchorPoint(-1.0, -1.0, 0.0);
 	
 	buttonRect = new ScenePrimitive(ScenePrimitive::TYPE_VPLANE, buttonImage->getWidth(),buttonImage->getHeight(),0,0);
 	buttonRect->setColor(1,1,1,0);
-	buttonRect->setPositionMode(Entity::POSITION_TOPLEFT);
+	buttonRect->setAnchorPoint(-1.0, -1.0, 0.0);
 	addChild(buttonRect);
 	
 	buttonRect->addEventListener(this, InputEvent::EVENT_MOUSEOVER);

+ 2 - 2
Modules/Contents/UI/Source/PolyUIMenuBar.cpp

@@ -40,7 +40,7 @@ UIMenuBarEntry::UIMenuBarEntry(String name): UIElement() {
 	label = new SceneLabel(name, 14, "sans");
 	setWidth(label->getLabel()->getTextWidth() + 20);
 	bg = new ScenePrimitive(ScenePrimitive::TYPE_VPLANE, getWidth(), 25);
-	bg->setPositionMode(Entity::POSITION_TOPLEFT);
+	bg->setAnchorPoint(-1.0, -1.0, 0.0);
 	addChild(bg);
 	bg->color.setColorHex(0xce5a1600);
 	bg->processInputEvents = true;
@@ -72,7 +72,7 @@ UIMenuBar::UIMenuBar(int width, UIGlobalMenu *globalMenu) : UIElement() {
 	bgShape = new ScenePrimitive(ScenePrimitive::TYPE_VPLANE, width, 25);
 	addChild(bgShape);
 	bgShape->setColor(0.0, 0.0, 0.0, 1.0);
-	bgShape->setPositionMode(Entity::POSITION_TOPLEFT);
+	bgShape->setAnchorPoint(-1.0, -1.0, 0.0);
 	entryOffset = 0;
 
 	currentEntry = NULL;

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

@@ -31,7 +31,7 @@ using namespace Polycode;
 
 UIScrollContainer::UIScrollContainer(Entity *scrolledEntity, bool hScroll, bool vScroll, Number width, Number height) : UIElement() {
 	
-	scrolledEntity->setPositionMode(Entity::POSITION_TOPLEFT);
+	scrolledEntity->setAnchorPoint(-1.0, -1.0, 0.0);
 	
 	scrolledEntity->rebuildTransformMatrix();
 	Config *conf = CoreServices::getInstance()->getConfig();

+ 9 - 9
Modules/Contents/UI/Source/PolyUITextInput.cpp

@@ -68,7 +68,7 @@ UITextInput::UITextInput(bool multiLine, Number width, Number height) : UIElemen
 	
 	numLines = 0;
 	
-	setPositionMode(POSITION_TOPLEFT);
+	setAnchorPoint(0.0, 0.0, 0.0);
 	Config *conf = CoreServices::getInstance()->getConfig();	
 	
 	if(multiLine)
@@ -117,7 +117,7 @@ UITextInput::UITextInput(bool multiLine, Number width, Number height) : UIElemen
 	
 	if(multiLine) {
 		lineNumberBg = new ScenePrimitive(ScenePrimitive::TYPE_VPLANE, 1,1);
-		lineNumberBg->setPositionMode(Entity::POSITION_TOPLEFT);
+		lineNumberBg->setAnchorPoint(-1.0, -1.0, 0.0);
 		lineNumberBg->setColor(0.0, 0.0, 0.0, 0.3);
 		addChild(lineNumberBg);
 		lineNumberBg->visible = false;
@@ -143,31 +143,31 @@ UITextInput::UITextInput(bool multiLine, Number width, Number height) : UIElemen
 	inputRect->addEventListener(this, InputEvent::EVENT_MOUSEOVER);
 	inputRect->addEventListener(this, InputEvent::EVENT_MOUSEOUT);
 	inputRect->processInputEvents = true;
-	inputRect->setPositionMode(Entity::POSITION_TOPLEFT);
+	inputRect->setAnchorPoint(-1.0, -1.0, 0.0);
 	
 	selectionColor = Color(181.0f/255.0f, 213.0f/255.0f, 255.0f/255.0f, 1.0f);
 	
 	selectorRectTop = new ScenePrimitive(ScenePrimitive::TYPE_VPLANE, 1,1);
-	selectorRectTop->setPositionMode(Entity::POSITION_TOPLEFT);
+	selectorRectTop->setAnchorPoint(-1.0, -1.0, 0.0);
 	selectorRectTop->setColor(181.0f/255.0f, 213.0f/255.0f, 255.0f/255.0f, 1);
 	selectorRectTop->visible = false;
 	textContainer->addChild(selectorRectTop);
 
 	selectorRectMiddle = new ScenePrimitive(ScenePrimitive::TYPE_VPLANE, 1,1);
-	selectorRectMiddle->setPositionMode(Entity::POSITION_TOPLEFT);	
+	selectorRectMiddle->setAnchorPoint(-1.0, -1.0, 0.0);	
 	selectorRectMiddle->setColor(181.0f/255.0f, 213.0f/255.0f, 255.0f/255.0f, 1);
 	selectorRectMiddle->visible = false;
 	textContainer->addChild(selectorRectMiddle);
 
 	selectorRectBottom = new ScenePrimitive(ScenePrimitive::TYPE_VPLANE, 1,1);
-	selectorRectBottom->setPositionMode(Entity::POSITION_TOPLEFT);	
+	selectorRectBottom->setAnchorPoint(-1.0, -1.0, 0.0);	
 	selectorRectBottom->setColor(181.0f/255.0f, 213.0f/255.0f, 255.0f/255.0f, 1);
 	selectorRectBottom->visible = false;
 	textContainer->addChild(selectorRectBottom);
 		
 	
 	blinkerRect = new ScenePrimitive(ScenePrimitive::TYPE_VPLANE, 1, fontSize+2,0,0);
-	blinkerRect->setPositionMode(Entity::POSITION_TOPLEFT);
+	blinkerRect->setAnchorPoint(-1.0, -1.0, 0.0);
 	blinkerRect->setColor(0,0,0,1);
 	textContainer->addChild(blinkerRect);
 	blinkerRect->visible = false;
@@ -2512,8 +2512,8 @@ void UITextInput::handleEvent(Event *event) {
 						return;						
 					}
 				} else {
-					if(parentEntity) {
-						((Entity*)parentEntity)->focusChild(this);
+					if(focusParent) {
+						focusParent->focusChild(this);
 					} else {
 						hasFocus = true;
 					}

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

@@ -56,7 +56,7 @@ UITree::UITree(String icon, String text, Number treeWidth, Number treeOffset) :
 	textLabel->color.setColorHexFromString(conf->getStringValue("Polycode", "uiTreeFontColor"));
 	
 	bgBox = new ScenePrimitive(ScenePrimitive::TYPE_VPLANE, treeWidth, cellHeight);	
-	bgBox->setPositionMode(Entity::POSITION_TOPLEFT);
+	bgBox->setAnchorPoint(-1.0, -1.0, 0.0);
 	bgBox->setPosition(-treeOffset,0);	
 	bgBox->setColor(1, 1, 1, 0);
 	addChild(bgBox);
@@ -74,7 +74,7 @@ UITree::UITree(String icon, String text, Number treeWidth, Number treeOffset) :
 						  st,sr,sb,sl,
 						  treeWidth+(padding*2), cellHeight+(padding*2));
 	
-	selection->setPositionMode(Entity::POSITION_TOPLEFT);
+	selection->setAnchorPoint(-1.0, -1.0, 0.0);
 	selection->setPosition(-treeOffset-padding,-padding);
 	selection->visible = false;
 	addChild(selection);
@@ -105,7 +105,7 @@ UITree::UITree(String icon, String text, Number treeWidth, Number treeOffset) :
 	bgBox->addEventListener(this, InputEvent::EVENT_DOUBLECLICK);	
 	bgBox->processInputEvents = true;
 		
-	setPositionMode(Entity::POSITION_CENTER);
+	setAnchorPoint(0.0, 0.0, 0.0);
 	
 	refreshTree();
 }

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

@@ -99,8 +99,8 @@ void UITreeContainer::handleEvent(Event *event) {
 		
 		if (!hasFocus) {
 			if (event->getEventCode() == InputEvent::EVENT_MOUSEDOWN) {
-				if (parentEntity && isFocusable())
-					((Entity*)parentEntity)->focusChild(this);
+				if (focusParent && isFocusable())
+					focusParent->focusChild(this);
 			} else if (event->getEventCode() == InputEvent::EVENT_MOUSEOVER) {
 				CoreServices::getInstance()->getCore()->setCursor(Core::CURSOR_ARROW);
 			}

+ 2 - 2
Modules/Contents/UI/Source/PolyUIVSizer.cpp

@@ -38,7 +38,7 @@ UIVSizer::UIVSizer(Number width, Number height, Number mainHeight, bool topSizer
 	this->mainHeight = mainHeight;
 	
 	separatorBgShape = new ScenePrimitive(ScenePrimitive::TYPE_VPLANE, width,1);
-	separatorBgShape->setPositionMode(Entity::POSITION_TOPLEFT);
+	separatorBgShape->setAnchorPoint(-1.0, -1.0, 0.0);
 	separatorBgShape->setColor(0.0, 0.0, 0.0, 1.0);	
 	addChild(separatorBgShape);
 
@@ -50,7 +50,7 @@ UIVSizer::UIVSizer(Number width, Number height, Number mainHeight, bool topSizer
 	secondElement = NULL;
 	
 	separatorHitShape = new ScenePrimitive(ScenePrimitive::TYPE_VPLANE, width,8);
-	separatorHitShape->setPositionMode(Entity::POSITION_TOPLEFT);
+	separatorHitShape->setAnchorPoint(-1.0, -1.0, 0.0);
 	separatorHitShape->setColor(1.0, 0.0, 0.0, 0.5);	
 	addChild(separatorHitShape);
 	separatorHitShape->blockMouseInput = true;

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

@@ -30,7 +30,7 @@
 using namespace Polycode;
 
 
-UIWindow::UIWindow(String windowName, Number width, Number height) : Entity(), windowTween(NULL) {
+UIWindow::UIWindow(String windowName, Number width, Number height) : UIElement(), windowTween(NULL) {
 	closeOnEscape = false;
 	
 	snapToPixels = true;
@@ -64,7 +64,7 @@ UIWindow::UIWindow(String windowName, Number width, Number height) : Entity(), w
 	titlebarRect = new ScenePrimitive(ScenePrimitive::TYPE_VPLANE, width, titleBarHeight);
 	titlebarRect->setPosition(0, titleBarOffset);
 	titlebarRect->setColor(0,0,0,0);
-	titlebarRect->setPositionMode(Entity::POSITION_TOPLEFT);
+	titlebarRect->setAnchorPoint(-1.0, -1.0, 0.0);
 	titlebarRect->processInputEvents = true;
 	addChild(titlebarRect);
 	
@@ -73,7 +73,8 @@ UIWindow::UIWindow(String windowName, Number width, Number height) : Entity(), w
 	addChild(titleLabel);
 	titleLabel->color.setColorHexFromString(conf->getStringValue("Polycode", "uiWindowFontColor"));
 	titleLabel->positionAtBaseline = false;
-		
+	titleLabel->setAnchorPoint(-1.0, -1.0, 0.0);
+			
 	closeBtn = new UIImageButton(conf->getStringValue("Polycode", "uiWindowCloseIcon"));
 	addChild(closeBtn);
 	closeIconX = conf->getNumericValue("Polycode", "uiCloseIconX");
@@ -147,12 +148,9 @@ void UIWindow::onMouseDown(Number x, Number y) {
 	if(hasFocus)
 		return;
 	hasFocus = true;
-	//dispatchEvent(new ScreenEvent(), ScreenEvent::ENTITY_MOVE_TOP);
-	for(int i=0; i < children.size(); i++) {
-		if(((Entity*)children[i])->isFocusable()) {
-			focusChild(((Entity*)children[i]));
-			return;
-		}
+
+	if(focusChildren.size() > 0) {
+		focusChild(focusChildren[0]);
 	}
 }