mirror of
https://github.com/rive-app/rive-cpp.git
synced 2026-01-18 21:21:17 +01:00
Runtime fix for image scale with mesh
This resolves an issue found by @lancesnider where replacing an image at runtime that is a different size that the image used at design time would not work properly when the image has a mesh applied. This does not fix a similar issue experienced when images have n-slicing applied. Image 1 at runtime: <img width="798" alt="Screenshot 2025-01-08 at 2 47 28 PM" src="https://github.com/user-attachments/assets/aae66c2d-40ef-42ef-9509-4a092277bc15" /> Image 2 at runtime: <img width="797" alt="Screenshot 2025-01-08 at 2 47 43 PM" src="https://github.com/user-attachments/assets/861713de-2d8d-4bd7-b497-c84c85ac4cf4" /> Diffs= eca00184b8 Runtime fix for image scale with mesh (#8840) Co-authored-by: Philip Chung <philterdesign@gmail.com> Co-authored-by: Susan Wang <susan@rive.app>
This commit is contained in:
@@ -1 +1 @@
|
||||
7c018ff174dc69f841e6b5011d995d8b0653ca01
|
||||
eca00184b8fb096243a60594f94f91f39607a15e
|
||||
|
||||
@@ -7,6 +7,11 @@
|
||||
namespace rive
|
||||
{
|
||||
class RenderImage;
|
||||
enum class MeshType : uint8_t
|
||||
{
|
||||
vertex = 0,
|
||||
nslice = 1,
|
||||
};
|
||||
class MeshDrawable
|
||||
{
|
||||
protected:
|
||||
@@ -17,6 +22,7 @@ protected:
|
||||
rcp<RenderBuffer> m_UVRenderBuffer;
|
||||
|
||||
public:
|
||||
MeshType type = MeshType::vertex;
|
||||
virtual ~MeshDrawable() = default;
|
||||
virtual void onAssetLoaded(RenderImage* image) = 0;
|
||||
virtual void draw(Renderer* renderer,
|
||||
|
||||
@@ -54,6 +54,7 @@ private:
|
||||
protected:
|
||||
public:
|
||||
SliceMesh(NSlicer* nslicer);
|
||||
MeshType type = MeshType::nslice;
|
||||
void draw(Renderer* renderer,
|
||||
const RenderImage* image,
|
||||
BlendMode blendMode,
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include "rive/importers/backboard_importer.hpp"
|
||||
#include "rive/assets/file_asset.hpp"
|
||||
#include "rive/assets/image_asset.hpp"
|
||||
#include "rive/layout/n_slicer.hpp"
|
||||
#include "rive/shapes/mesh_drawable.hpp"
|
||||
#include "rive/artboard.hpp"
|
||||
#include "rive/clip_result.hpp"
|
||||
@@ -211,6 +212,11 @@ void Image::controlSize(Vec2D size,
|
||||
|
||||
void Image::updateImageScale()
|
||||
{
|
||||
// User-created meshes are not affected by scale
|
||||
if (m_Mesh != nullptr && m_Mesh->type == MeshType::vertex)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (imageAsset() != nullptr && imageAsset()->renderImage() != nullptr &&
|
||||
!std::isnan(m_layoutWidth) && !std::isnan(m_layoutHeight))
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user