From cfd6b6e1f472fb7fdd8a34ac182a7dbb8e005481 Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Sat, 10 Dec 2016 14:28:09 +0100 Subject: Add texture offset support. --- plugingui/texturedbox.cc | 24 ++++++++++++------------ plugingui/texturedbox.h | 4 ++-- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/plugingui/texturedbox.cc b/plugingui/texturedbox.cc index 02f695c..f274e21 100644 --- a/plugingui/texturedbox.cc +++ b/plugingui/texturedbox.cc @@ -44,8 +44,8 @@ TexturedBox::TexturedBox(ImageCache& image_cache, const std::string& filename, , seg_g(image_cache, filename, x0 , y0 + dy1 + dy2, dx1, dy3) , seg_h(image_cache, filename, x0 + dx1 , y0 + dy1 + dy2, dx2, dy3) , seg_i(image_cache, filename, x0 + dx1 + dx2, y0 + dy1 + dy2, dx3, dy3) - , _x(x0) - , _y(y0) + , x0(x0) + , y0(y0) , dx1(dx1) , dx2(dx2) , dx3(dx3) @@ -86,11 +86,11 @@ const Colour& TexturedBox::getPixel(std::size_t x, std::size_t y) const { float scale = (float)(x - dx1) / (float)(_width - dx1 - dx3); assert(seg_b.width() == dx2); - return seg_b.getPixel(scale * dx2, y); + return seg_b.getPixel(scale * dx2 + x0, y + y0); } else // col 3 { - return seg_c.getPixel(x - (_width - dx3), y); + return seg_c.getPixel(x - (_width - dx3) + x0, y + y0); } } else if(y < (_height - dy3)) // row 2 @@ -99,34 +99,34 @@ const Colour& TexturedBox::getPixel(std::size_t x, std::size_t y) const { // TODO: Apply vertical scale float scale = (float)(y - dy1) / (float)(_height - dy1 - dy3); - return seg_d.getPixel(x, scale * dy2); + return seg_d.getPixel(x + x0, scale * dy2 + y0); } else if(x < (_width - dx3)) // col 2 { - float scale_x = (float)(x - dx1) / (float)(_width - dx1 - dx3); - float scale_y = (float)(y - dy1) / (float)(_height - dy1 - dy3); - return seg_e.getPixel(scale_x * dx2, scale_y * dy2); + float scalex0 = (float)(x - dx1) / (float)(_width - dx1 - dx3); + float scaley0 = (float)(y - dy1) / (float)(_height - dy1 - dy3); + return seg_e.getPixel(scalex0 * dx2 + x0, scaley0 * dy2 + y0); } else // col 3 { float scale = (float)(y - dy1) / (float)(_height - dy1 - dy3); - return seg_f.getPixel(x - (_width - dx3), scale * dy2); + return seg_f.getPixel(x - (_width - dx3) + x0, scale * dy2 + y0); } } else // row 3 { if(x < dx1) // col 1 { - return seg_g.getPixel(x, y - (_height - dy3)); + return seg_g.getPixel(x + x0, y - (_height - dy3) + y0); } else if(x < (_width - dx3)) // col 2 { float scale = (float)(x - dx1) / (float)(_width - dx1 - dx3); - return seg_h.getPixel(scale * dx2, y - (_height - dy3)); + return seg_h.getPixel(scale * dx2 + x0, y - (_height - dy3) + y0); } else // col 3 { - return seg_i.getPixel(x - (_width - dx3), y - (_height - dy3)); + return seg_i.getPixel(x - (_width - dx3) + x0, y - (_height - dy3) + y0); } } diff --git a/plugingui/texturedbox.h b/plugingui/texturedbox.h index 51aead5..01c1bed 100644 --- a/plugingui/texturedbox.h +++ b/plugingui/texturedbox.h @@ -101,8 +101,8 @@ private: Texture seg_h; Texture seg_i; - std::size_t _x; - std::size_t _y; + std::size_t x0; + std::size_t y0; std::size_t _width{100}; std::size_t _height{100}; std::size_t dx1; -- cgit v1.2.3