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

Use Rectangle's new Clipped() method for scissorBox

- Fix bug/oddity with scissor rects. What looked like it was
  clipping children by their parent's scissor rect was clipping
  the min but when clipping the max was using the new min edge
  to calculate the old max edge thus making the clipping rect
  too large. This seemed to work because we were having children
  clip themselves and the text editor was the only thing
  really using the scissor functionality.
- Set Renderer's initial scissor rect via the setter so that
  later calls to getScissorBox() will return the correct value.
- Make scroll containers clip their children rather than having
  them set their children to be clipped.
- Only make UITextInput's textContainer clip on single-line input
  because its size isn't set properly to be used to clip with.
Nur Monson 12 лет назад
Родитель
Сommit
5ae3bdcd10

+ 6 - 22
Core/Contents/Source/PolyEntity.cpp

@@ -405,31 +405,15 @@ void Entity::transformAndRender() {
 		isScissorEnabled = renderer->isScissorEnabled();
 		isScissorEnabled = renderer->isScissorEnabled();
 		oldScissorBox = renderer->getScissorBox();
 		oldScissorBox = renderer->getScissorBox();
 		renderer->enableScissor(true);
 		renderer->enableScissor(true);
-		
-		Polycode::Rectangle finalScrissorBox = scissorBox;		
-		
-		// make sure that our scissor box is constrained to the parent one if it exists
-		if(isScissorEnabled) {
-			if(finalScrissorBox.x < oldScissorBox.x)
-				finalScrissorBox.x = oldScissorBox.x;
-			if(finalScrissorBox.x > oldScissorBox.x + oldScissorBox.w)
-				finalScrissorBox.x = oldScissorBox.x + oldScissorBox.w;
-
-				
-			if(finalScrissorBox.x+finalScrissorBox.w > oldScissorBox.x + oldScissorBox.w)
-				finalScrissorBox.w = oldScissorBox.x + oldScissorBox.w - finalScrissorBox.x;
 
 
-			if(finalScrissorBox.y < oldScissorBox.y)
-				finalScrissorBox.y = oldScissorBox.y;
-			if(finalScrissorBox.y > oldScissorBox.y + oldScissorBox.h)
-				finalScrissorBox.y = oldScissorBox.y + oldScissorBox.h;
-
-			if(finalScrissorBox.y+finalScrissorBox.h > oldScissorBox.y + oldScissorBox.h)
-				finalScrissorBox.h = oldScissorBox.y + oldScissorBox.h - finalScrissorBox.y;
+		Rectangle finalScissorBox = scissorBox;
 
 
+		// make sure that our scissor box is constrained to the parent one if it exists
+		if(isScissorEnabled) {
+			finalScissorBox = finalScissorBox.Clipped(renderer->getScissorBox());
 		}
 		}
-		
-		renderer->setScissorBox(finalScrissorBox);
+
+		renderer->setScissorBox(finalScissorBox);
 	}
 	}
 		
 		
 	renderer->pushMatrix();
 	renderer->pushMatrix();

+ 2 - 2
Core/Contents/Source/PolyGLES1Renderer.cpp

@@ -47,7 +47,7 @@ void OpenGLES1Renderer::Resize(int xRes, int yRes) {
     glLoadIdentity();
     glLoadIdentity();
 	gluPerspective(fov,(GLfloat)xRes/(GLfloat)yRes,nearPlane,farPlane);
 	gluPerspective(fov,(GLfloat)xRes/(GLfloat)yRes,nearPlane,farPlane);
 	glViewport(0, 0, xRes, yRes);
 	glViewport(0, 0, xRes, yRes);
-	glScissor(0, 0, xRes, yRes);
+	setScissorBox(0, 0, xRex, yRes);
 	
 	
 	glMatrixMode(GL_MODELVIEW);
 	glMatrixMode(GL_MODELVIEW);
 	glLineWidth(1);
 	glLineWidth(1);
@@ -707,4 +707,4 @@ void OpenGLES1Renderer::EndRender() {
 
 
 OpenGLES1Renderer::~OpenGLES1Renderer() {
 OpenGLES1Renderer::~OpenGLES1Renderer() {
 	
 	
-}
+}

+ 2 - 2
Core/Contents/Source/PolyGLRenderer.cpp

@@ -160,7 +160,7 @@ void OpenGLRenderer::Resize(int xRes, int yRes) {
     glLoadIdentity();
     glLoadIdentity();
 	gluPerspective(fov,(GLfloat)xRes/(GLfloat)yRes,nearPlane,farPlane);
 	gluPerspective(fov,(GLfloat)xRes/(GLfloat)yRes,nearPlane,farPlane);
 	glViewport(0, 0, xRes, yRes);
 	glViewport(0, 0, xRes, yRes);
-	glScissor(0, 0, xRes, yRes);
+	setScissorBox(Rectangle(0, 0, xRes, yRes));
 	
 	
 	glMatrixMode(GL_MODELVIEW);
 	glMatrixMode(GL_MODELVIEW);
 	glLineWidth(1);
 	glLineWidth(1);
@@ -180,7 +180,7 @@ void OpenGLRenderer::Resize(int xRes, int yRes) {
 	GLint numBuffers;
 	GLint numBuffers;
 	glGetIntegerv(GL_MAX_DRAW_BUFFERS, &numBuffers);
 	glGetIntegerv(GL_MAX_DRAW_BUFFERS, &numBuffers);
 //	Logger::log("MAX_DRAW_BUFFERS: %d \n", numBuffers);
 //	Logger::log("MAX_DRAW_BUFFERS: %d \n", numBuffers);
-	
+
 }
 }
 
 
 void OpenGLRenderer::setDepthFunction(int depthFunction) {
 void OpenGLRenderer::setDepthFunction(int depthFunction) {

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

@@ -51,7 +51,7 @@ UIScrollContainer::UIScrollContainer(ScreenEntity *scrolledEntity, bool hScroll,
 	scrollChild = scrolledEntity;
 	scrollChild = scrolledEntity;
 	addChild(scrollChild);
 	addChild(scrollChild);
 	
 	
-	scrollChild->enableScissor = true;
+	enableScissor = true;
 	
 	
 	vScrollBar = new UIVScrollBar(defaultScrollSize, height, height / scrolledEntity->getHeight());
 	vScrollBar = new UIVScrollBar(defaultScrollSize, height, height / scrolledEntity->getHeight());
 	addChild(vScrollBar);
 	addChild(vScrollBar);
@@ -166,7 +166,7 @@ void UIScrollContainer::scrollHorizontal(Number amount) {
 
 
 void UIScrollContainer::Update() {
 void UIScrollContainer::Update() {
 	Vector2 pos = getScreenPosition();
 	Vector2 pos = getScreenPosition();
-	scrollChild->scissorBox.setRect(pos.x,pos.y, width, height);	
+	scissorBox.setRect(pos.x, pos.y, width, height);
 }
 }
 
 
 void UIScrollContainer::handleEvent(Event *event) {
 void UIScrollContainer::handleEvent(Event *event) {

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

@@ -93,7 +93,6 @@ UITextInput::UITextInput(bool multiLine, Number width, Number height) : UIElemen
 	
 	
 	textContainer = new UIElement();
 	textContainer = new UIElement();
 	textContainer->ownsChildren = true;
 	textContainer->ownsChildren = true;
-	textContainer->enableScissor = true;
 
 
 	linesContainer->addChild(textContainer);
 	linesContainer->addChild(textContainer);
 	if(multiLine) {
 	if(multiLine) {
@@ -177,6 +176,7 @@ UITextInput::UITextInput(bool multiLine, Number width, Number height) : UIElemen
 		addChild(scrollContainer);
 		addChild(scrollContainer);
 	} else {
 	} else {
 		addChild(linesContainer);
 		addChild(linesContainer);
+		textContainer->enableScissor = true;
 	}
 	}
 		
 		
 	undoStateIndex = 0;
 	undoStateIndex = 0;