diff --git a/changelog.txt b/changelog.txt index 66a972e09..53b693b00 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,5 +1,7 @@ October 7 --Fixed borders for GuiBox. Still need to flip the right border and bottom border. +-Fixed borders for GuiBox. The right and bottom borders are flipped, too. +-Added corners for GuiBox. +-Added setFlipX() and setFlipY() to the GuiImage class. October 5 -GuiFastSelect is working, but ugly. diff --git a/src/components/GuiBox.cpp b/src/components/GuiBox.cpp index d76c5f354..2f2db5602 100644 --- a/src/components/GuiBox.cpp +++ b/src/components/GuiBox.cpp @@ -39,7 +39,10 @@ void GuiBox::setBackgroundImage(std::string path, bool tiled) void GuiBox::setCornerImage(std::string path) { + mCornerImage.setOrigin(0, 0); mCornerImage.setResize(getHorizontalBorderWidth(), getVerticalBorderWidth(), true); + + mCornerImage.setImage(path); } void GuiBox::onRender() @@ -47,27 +50,53 @@ void GuiBox::onRender() //left border mHorizontalImage.setOffsetX(getOffsetX() - getHorizontalBorderWidth()); mHorizontalImage.setOffsetY(getOffsetY()); + mHorizontalImage.setFlipX(false); mHorizontalImage.render(); //Renderer::drawRect(getOffsetX() - getHorizontalBorderWidth(), getOffsetY(), getHorizontalBorderWidth(), mHeight, 0xFF0000); //right border mHorizontalImage.setOffsetX(getOffsetX() + mWidth); //same Y + mHorizontalImage.setFlipX(true); mHorizontalImage.render(); //Renderer::drawRect(getOffsetX() + mWidth, getOffsetY(), getHorizontalBorderWidth(), mHeight, 0xFF0000); //top border mVerticalImage.setOffsetX(getOffsetX()); mVerticalImage.setOffsetY(getOffsetY() - getVerticalBorderWidth()); + mVerticalImage.setFlipY(false); mVerticalImage.render(); //Renderer::drawRect(getOffsetX(), getOffsetY() - getVerticalBorderWidth(), mWidth, getVerticalBorderWidth(), 0x00FF00); //bottom border //same X mVerticalImage.setOffsetY(getOffsetY() + mHeight); + mVerticalImage.setFlipY(true); mVerticalImage.render(); //Renderer::drawRect(getOffsetX(), getOffsetY() + mHeight, mWidth, getVerticalBorderWidth(), 0x00FF00); + + //corner top left + mCornerImage.setOffsetX(getOffsetX() - getHorizontalBorderWidth()); + mCornerImage.setOffsetY(getOffsetY() - getVerticalBorderWidth()); + mCornerImage.setFlipX(false); + mCornerImage.setFlipY(false); + mCornerImage.render(); + + //top right + mCornerImage.setOffsetX(getOffsetX() + mWidth); + mCornerImage.setFlipX(true); + mCornerImage.render(); + + //bottom right + mCornerImage.setOffsetY(getOffsetY() + mHeight); + mCornerImage.setFlipY(true); + mCornerImage.render(); + + //bottom left + mCornerImage.setOffsetX(getOffsetX() - getHorizontalBorderWidth()); + mCornerImage.setFlipX(false); + mCornerImage.render(); } void GuiBox::onInit() diff --git a/src/components/GuiFastSelect.cpp b/src/components/GuiFastSelect.cpp index e00e0bf7b..ea9f6ef95 100644 --- a/src/components/GuiFastSelect.cpp +++ b/src/components/GuiFastSelect.cpp @@ -27,8 +27,9 @@ GuiFastSelect::GuiFastSelect(GuiComponent* parent, GuiList* list, cha addChild(mBox); //set test mBox info - //mBox->setHorizontalImage("test.jpg", false); - //mBox->setVerticalImage("test.jpg", false); + mBox->setHorizontalImage("left.jpg", false); + mBox->setVerticalImage("top.jpg", false); + mBox->setCornerImage("corner.jpg"); mParent->pause(); } diff --git a/src/components/GuiImage.cpp b/src/components/GuiImage.cpp index 54c262570..c155043cc 100644 --- a/src/components/GuiImage.cpp +++ b/src/components/GuiImage.cpp @@ -27,6 +27,9 @@ GuiImage::GuiImage(int offsetX, int offsetY, std::string path, unsigned int resi mResizeExact = resizeExact; + mFlipX = false; + mFlipY = false; + if(!path.empty()) setImage(path); } @@ -243,6 +246,16 @@ void GuiImage::setResize(unsigned int width, unsigned int height, bool resizeExa resize(); } +void GuiImage::setFlipX(bool flip) +{ + mFlipX = flip; +} + +void GuiImage::setFlipY(bool flip) +{ + mFlipY = flip; +} + void GuiImage::onRender() { if(mTextureID) @@ -293,6 +306,17 @@ void GuiImage::buildImageArray(int posX, int posY, GLfloat* points, GLfloat* tex texs[6] = 1; texs[7] = 1; texs[8] = 0; texs[9] = 0; texs[10] = 1; texs[11] = 0; + + if(mFlipX) + { + for(int i = 0; i < 11; i += 2) + texs[i] = !texs[i]; + } + if(mFlipY) + { + for(int i = 1; i < 12; i += 2) + texs[i] = !texs[i]; + } } void GuiImage::drawImageArray(GLfloat* points, GLfloat* texs, unsigned int numArrays) diff --git a/src/components/GuiImage.h b/src/components/GuiImage.h index cb8a38573..c96175367 100644 --- a/src/components/GuiImage.h +++ b/src/components/GuiImage.h @@ -21,6 +21,9 @@ public: void setTiling(bool tile); //Enables or disables tiling. Must be called before loading an image or resizing will be weird. void setResize(unsigned int width, unsigned int height, bool resizeExact); + void setFlipX(bool flip); + void setFlipY(bool flip); + unsigned int getWidth(); //Returns render width in pixels. May be different than actual texture width. unsigned int getHeight(); //Returns render height in pixels. May be different than actual texture height. @@ -33,7 +36,7 @@ public: private: unsigned int mResizeWidth, mResizeHeight; float mOriginX, mOriginY; - bool mResizeExact, mTiled; + bool mResizeExact, mTiled, mFlipX, mFlipY; void loadImage(std::string path); void resize();