void NinePatch::updateTexCoords() { TexturePtr tex = material->textures[0]; float tw = (float)std::min(tex->dataWidth, tex->width); float th = (float)std::min(tex->dataHeight, tex->height); if(flip) { this->setTexCoord(0, tex->normalisedCoord(Vec2(0,0))); this->setTexCoord(1, tex->normalisedCoord(Vec2(left, 0))); this->setTexCoord(2, tex->normalisedCoord(Vec2(tw-right, 0))); this->setTexCoord(3, tex->normalisedCoord(Vec2(tw, 0))); this->setTexCoord(4, tex->normalisedCoord(Vec2(0,bottom))); this->setTexCoord(5, tex->normalisedCoord(Vec2(left,bottom))); this->setTexCoord(6, tex->normalisedCoord(Vec2(tw-right,bottom))); this->setTexCoord(7, tex->normalisedCoord(Vec2(tw,bottom))); this->setTexCoord(8, tex->normalisedCoord(Vec2(0,th-top))); this->setTexCoord(9, tex->normalisedCoord(Vec2(left,th-top))); this->setTexCoord(10, tex->normalisedCoord(Vec2(tw-right, th-top))); this->setTexCoord(11, tex->normalisedCoord(Vec2(tw, th-top))); this->setTexCoord(12, tex->normalisedCoord(Vec2(0,th))); this->setTexCoord(13, tex->normalisedCoord(Vec2(left,th))); this->setTexCoord(14, tex->normalisedCoord(Vec2(tw-right,th))); this->setTexCoord(15, tex->normalisedCoord(Vec2(tw, th))); } else { this->setTexCoord(0, tex->normalisedCoord(Vec2(0,th))); this->setTexCoord(1, tex->normalisedCoord(Vec2(left, th))); this->setTexCoord(2, tex->normalisedCoord(Vec2(tw-right, th))); this->setTexCoord(3, tex->normalisedCoord(Vec2(tw, th))); this->setTexCoord(4, tex->normalisedCoord(Vec2(0,th-top))); this->setTexCoord(5, tex->normalisedCoord(Vec2(left,th-top))); this->setTexCoord(6, tex->normalisedCoord(Vec2(tw-right, th-top))); this->setTexCoord(7, tex->normalisedCoord(Vec2(tw, th-top))); this->setTexCoord(8, tex->normalisedCoord(Vec2(0,bottom))); this->setTexCoord(9, tex->normalisedCoord(Vec2(left,bottom))); this->setTexCoord(10, tex->normalisedCoord(Vec2(tw-right, bottom))); this->setTexCoord(11, tex->normalisedCoord(Vec2(tw, bottom))); this->setTexCoord(12, tex->normalisedCoord(Vec2(0,0))); this->setTexCoord(13, tex->normalisedCoord(Vec2(left,0))); this->setTexCoord(14, tex->normalisedCoord(Vec2(tw-right,0))); this->setTexCoord(15, tex->normalisedCoord(Vec2(tw, 0))); } }