From f7bcf7fa46a634653e50f9e580faf2a53ab50e88 Mon Sep 17 00:00:00 2001 From: Vincent Robinson Date: Sun, 3 Jul 2022 05:52:26 -0700 Subject: FormSpec: 9-slice images, animated_images, and fgimg_middle (#12453) * FormSpec: 9-slice images and animated_images * Add fgimg_middle; clean up code * Address issues, add tests * Fix stupid error; bump formspec version * Re-add image[] elements without a size --- src/client/guiscalingfilter.cpp | 49 ++++++++++++++++++++++++----------------- 1 file changed, 29 insertions(+), 20 deletions(-) (limited to 'src/client/guiscalingfilter.cpp') diff --git a/src/client/guiscalingfilter.cpp b/src/client/guiscalingfilter.cpp index de122becf..42508259f 100644 --- a/src/client/guiscalingfilter.cpp +++ b/src/client/guiscalingfilter.cpp @@ -176,52 +176,61 @@ void draw2DImageFilterScaled(video::IVideoDriver *driver, video::ITexture *txr, } void draw2DImage9Slice(video::IVideoDriver *driver, video::ITexture *texture, - const core::rect &rect, const core::rect &middle, - const core::rect *cliprect, const video::SColor *const colors) + const core::rect &destrect, const core::rect &srcrect, + const core::rect &middlerect, const core::rect *cliprect, + const video::SColor *const colors) { - auto originalSize = texture->getOriginalSize(); - core::vector2di lowerRightOffset = core::vector2di(originalSize.Width, originalSize.Height) - middle.LowerRightCorner; + // `-x` is interpreted as `w - x` + core::rect middle = middlerect; + + if (middlerect.LowerRightCorner.X < 0) + middle.LowerRightCorner.X += srcrect.getWidth(); + if (middlerect.LowerRightCorner.Y < 0) + middle.LowerRightCorner.Y += srcrect.getHeight(); + + core::vector2di lower_right_offset = core::vector2di(srcrect.getWidth(), + srcrect.getHeight()) - middle.LowerRightCorner; for (int y = 0; y < 3; ++y) { for (int x = 0; x < 3; ++x) { - core::rect src({0, 0}, originalSize); - core::rect dest = rect; + core::rect src = srcrect; + core::rect dest = destrect; switch (x) { case 0: - dest.LowerRightCorner.X = rect.UpperLeftCorner.X + middle.UpperLeftCorner.X; - src.LowerRightCorner.X = middle.UpperLeftCorner.X; + dest.LowerRightCorner.X = destrect.UpperLeftCorner.X + middle.UpperLeftCorner.X; + src.LowerRightCorner.X = srcrect.UpperLeftCorner.X + middle.UpperLeftCorner.X; break; case 1: dest.UpperLeftCorner.X += middle.UpperLeftCorner.X; - dest.LowerRightCorner.X -= lowerRightOffset.X; - src.UpperLeftCorner.X = middle.UpperLeftCorner.X; - src.LowerRightCorner.X = middle.LowerRightCorner.X; + dest.LowerRightCorner.X -= lower_right_offset.X; + src.UpperLeftCorner.X += middle.UpperLeftCorner.X; + src.LowerRightCorner.X -= lower_right_offset.X; break; case 2: - dest.UpperLeftCorner.X = rect.LowerRightCorner.X - lowerRightOffset.X; - src.UpperLeftCorner.X = middle.LowerRightCorner.X; + dest.UpperLeftCorner.X = destrect.LowerRightCorner.X - lower_right_offset.X; + src.UpperLeftCorner.X = srcrect.LowerRightCorner.X - lower_right_offset.X; break; } switch (y) { case 0: - dest.LowerRightCorner.Y = rect.UpperLeftCorner.Y + middle.UpperLeftCorner.Y; - src.LowerRightCorner.Y = middle.UpperLeftCorner.Y; + dest.LowerRightCorner.Y = destrect.UpperLeftCorner.Y + middle.UpperLeftCorner.Y; + src.LowerRightCorner.Y = srcrect.UpperLeftCorner.Y + middle.UpperLeftCorner.Y; break; case 1: dest.UpperLeftCorner.Y += middle.UpperLeftCorner.Y; - dest.LowerRightCorner.Y -= lowerRightOffset.Y; - src.UpperLeftCorner.Y = middle.UpperLeftCorner.Y; - src.LowerRightCorner.Y = middle.LowerRightCorner.Y; + dest.LowerRightCorner.Y -= lower_right_offset.Y; + src.UpperLeftCorner.Y += middle.UpperLeftCorner.Y; + src.LowerRightCorner.Y -= lower_right_offset.Y; break; case 2: - dest.UpperLeftCorner.Y = rect.LowerRightCorner.Y - lowerRightOffset.Y; - src.UpperLeftCorner.Y = middle.LowerRightCorner.Y; + dest.UpperLeftCorner.Y = destrect.LowerRightCorner.Y - lower_right_offset.Y; + src.UpperLeftCorner.Y = srcrect.LowerRightCorner.Y - lower_right_offset.Y; break; } -- cgit v1.2.3