Cleanup image and entity references.
This commit is contained in:
@@ -8,65 +8,13 @@
|
|||||||
namespace rl {
|
namespace rl {
|
||||||
namespace entity {
|
namespace entity {
|
||||||
|
|
||||||
Entity::Entity(core::Name identifier, UpdateCallback updateCallback)
|
Entity::Entity()
|
||||||
: _identifier(identifier),
|
: _anchorPoint(geom::Point(0.5, 0.5)), _opacity(1.0), _strokeSize(1.0) {}
|
||||||
_anchorPoint(geom::Point(0.5, 0.5)),
|
|
||||||
_opacity(1.0),
|
|
||||||
_strokeSize(1.0),
|
|
||||||
_updateCallback(updateCallback) {}
|
|
||||||
|
|
||||||
Entity::Entity(Entity&&) = default;
|
Entity::Entity(Entity&&) = default;
|
||||||
|
|
||||||
Entity::~Entity() = default;
|
Entity::~Entity() = default;
|
||||||
|
|
||||||
void Entity::mergeProperties(const Entity& entity, PropertyMaskType only) {
|
|
||||||
RL_ASSERT(_identifier == entity._identifier);
|
|
||||||
|
|
||||||
if (only & PropertyMask::BoundsMask) {
|
|
||||||
_bounds = entity._bounds;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (only & PropertyMask::PositionMask) {
|
|
||||||
_position = entity._position;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (only & PropertyMask::AnchorPointMask) {
|
|
||||||
_anchorPoint = entity._anchorPoint;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (only & PropertyMask::TransformationMask) {
|
|
||||||
_transformation = entity._transformation;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (only & PropertyMask::BackgroundColorMask) {
|
|
||||||
_backgroundColor = entity._backgroundColor;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (only & PropertyMask::OpacityMask) {
|
|
||||||
_opacity = entity._opacity;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (only & PropertyMask::StrokeSizeMask) {
|
|
||||||
_strokeSize = entity._strokeSize;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (only & PropertyMask::StrokeColorMask) {
|
|
||||||
_strokeColor = entity._strokeColor;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (only & PropertyMask::ContentsMask) {
|
|
||||||
_contents = entity._contents;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (only & PropertyMask::PathMask) {
|
|
||||||
_path = entity._path;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
core::Name Entity::identifier() const {
|
|
||||||
return _identifier;
|
|
||||||
}
|
|
||||||
|
|
||||||
geom::Rect Entity::frame() const {
|
geom::Rect Entity::frame() const {
|
||||||
geom::Point origin(_position.x - (_bounds.size.width * _anchorPoint.x),
|
geom::Point origin(_position.x - (_bounds.size.width * _anchorPoint.x),
|
||||||
_position.y - (_bounds.size.height * _anchorPoint.y));
|
_position.y - (_bounds.size.height * _anchorPoint.y));
|
||||||
@@ -87,7 +35,6 @@ const geom::Rect& Entity::bounds() const {
|
|||||||
|
|
||||||
void Entity::setBounds(const geom::Rect& bounds) {
|
void Entity::setBounds(const geom::Rect& bounds) {
|
||||||
_bounds = bounds;
|
_bounds = bounds;
|
||||||
notifyInterfaceIfNecessary(Property::Bounds);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const geom::Point& Entity::position() const {
|
const geom::Point& Entity::position() const {
|
||||||
@@ -96,7 +43,6 @@ const geom::Point& Entity::position() const {
|
|||||||
|
|
||||||
void Entity::setPosition(const geom::Point& position) {
|
void Entity::setPosition(const geom::Point& position) {
|
||||||
_position = position;
|
_position = position;
|
||||||
notifyInterfaceIfNecessary(Property::Position);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const geom::Point& Entity::anchorPoint() const {
|
const geom::Point& Entity::anchorPoint() const {
|
||||||
@@ -105,7 +51,6 @@ const geom::Point& Entity::anchorPoint() const {
|
|||||||
|
|
||||||
void Entity::setAnchorPoint(const geom::Point& anchorPoint) {
|
void Entity::setAnchorPoint(const geom::Point& anchorPoint) {
|
||||||
_anchorPoint = anchorPoint;
|
_anchorPoint = anchorPoint;
|
||||||
notifyInterfaceIfNecessary(Property::AnchorPoint);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const geom::Matrix& Entity::transformation() const {
|
const geom::Matrix& Entity::transformation() const {
|
||||||
@@ -114,7 +59,6 @@ const geom::Matrix& Entity::transformation() const {
|
|||||||
|
|
||||||
void Entity::setTransformation(const geom::Matrix& transformation) {
|
void Entity::setTransformation(const geom::Matrix& transformation) {
|
||||||
_transformation = transformation;
|
_transformation = transformation;
|
||||||
notifyInterfaceIfNecessary(Property::Transformation);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
geom::Matrix Entity::modelMatrix() const {
|
geom::Matrix Entity::modelMatrix() const {
|
||||||
@@ -151,7 +95,6 @@ const Color& Entity::backgroundColor() const {
|
|||||||
|
|
||||||
void Entity::setBackgroundColor(const Color& backgroundColor) {
|
void Entity::setBackgroundColor(const Color& backgroundColor) {
|
||||||
_backgroundColor = backgroundColor;
|
_backgroundColor = backgroundColor;
|
||||||
notifyInterfaceIfNecessary(Property::BackgroundColor);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const double& Entity::opacity() const {
|
const double& Entity::opacity() const {
|
||||||
@@ -160,7 +103,6 @@ const double& Entity::opacity() const {
|
|||||||
|
|
||||||
void Entity::setOpacity(double opacity) {
|
void Entity::setOpacity(double opacity) {
|
||||||
_opacity = opacity;
|
_opacity = opacity;
|
||||||
notifyInterfaceIfNecessary(Property::Opacity);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const Color& Entity::strokeColor() const {
|
const Color& Entity::strokeColor() const {
|
||||||
@@ -169,7 +111,6 @@ const Color& Entity::strokeColor() const {
|
|||||||
|
|
||||||
void Entity::setStrokeColor(const Color& strokeColor) {
|
void Entity::setStrokeColor(const Color& strokeColor) {
|
||||||
_strokeColor = strokeColor;
|
_strokeColor = strokeColor;
|
||||||
notifyInterfaceIfNecessary(Property::StrokeColor);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
double Entity::strokeSize() const {
|
double Entity::strokeSize() const {
|
||||||
@@ -178,7 +119,6 @@ double Entity::strokeSize() const {
|
|||||||
|
|
||||||
void Entity::setStrokeSize(double strokeSize) {
|
void Entity::setStrokeSize(double strokeSize) {
|
||||||
_strokeSize = strokeSize;
|
_strokeSize = strokeSize;
|
||||||
notifyInterfaceIfNecessary(Property::StrokeSize);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const image::Image& Entity::contents() const {
|
const image::Image& Entity::contents() const {
|
||||||
@@ -187,7 +127,6 @@ const image::Image& Entity::contents() const {
|
|||||||
|
|
||||||
void Entity::setContents(image::Image image) {
|
void Entity::setContents(image::Image image) {
|
||||||
_contents = std::move(image);
|
_contents = std::move(image);
|
||||||
notifyInterfaceIfNecessary(Property::Contents);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const geom::Path& Entity::path() const {
|
const geom::Path& Entity::path() const {
|
||||||
@@ -196,104 +135,6 @@ const geom::Path& Entity::path() const {
|
|||||||
|
|
||||||
void Entity::setPath(geom::Path path) {
|
void Entity::setPath(geom::Path path) {
|
||||||
_path = std::move(path);
|
_path = std::move(path);
|
||||||
notifyInterfaceIfNecessary(Property::Path);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Entity::notifyInterfaceIfNecessary(Property property,
|
|
||||||
core::Name other) const {
|
|
||||||
if (_updateCallback) {
|
|
||||||
_updateCallback(*this, property, other);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
enum ArchiveKey {
|
|
||||||
Identifier,
|
|
||||||
Bounds,
|
|
||||||
Position,
|
|
||||||
AnchorPoint,
|
|
||||||
Transformation,
|
|
||||||
BackgroundColor,
|
|
||||||
Opacity,
|
|
||||||
StrokeColor,
|
|
||||||
StrokeSize,
|
|
||||||
};
|
|
||||||
|
|
||||||
const core::ArchiveDef Entity::ArchiveDefinition = {
|
|
||||||
/* .superClass = */ nullptr,
|
|
||||||
/* .className = */ "Entity",
|
|
||||||
/* .autoAssignName = */ false,
|
|
||||||
/* .members = */
|
|
||||||
{
|
|
||||||
ArchiveKey::Identifier, //
|
|
||||||
ArchiveKey::Bounds, //
|
|
||||||
ArchiveKey::Position, //
|
|
||||||
ArchiveKey::AnchorPoint, //
|
|
||||||
ArchiveKey::Transformation, //
|
|
||||||
ArchiveKey::BackgroundColor, //
|
|
||||||
ArchiveKey::Opacity, //
|
|
||||||
ArchiveKey::StrokeColor, //
|
|
||||||
ArchiveKey::StrokeSize, //
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
Entity::ArchiveName Entity::archiveName() const {
|
|
||||||
return *_identifier.handle();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Entity::serialize(core::ArchiveItem& item) const {
|
|
||||||
RL_RETURN_IF_FALSE(item.encode(ArchiveKey::Identifier, _identifier));
|
|
||||||
|
|
||||||
RL_RETURN_IF_FALSE(item.encode(ArchiveKey::Bounds, _bounds.toString()));
|
|
||||||
|
|
||||||
RL_RETURN_IF_FALSE(item.encode(ArchiveKey::Position, _position.toString()));
|
|
||||||
|
|
||||||
RL_RETURN_IF_FALSE(
|
|
||||||
item.encode(ArchiveKey::AnchorPoint, _anchorPoint.toString()));
|
|
||||||
|
|
||||||
RL_RETURN_IF_FALSE(
|
|
||||||
item.encode(ArchiveKey::Transformation, _transformation.toString()));
|
|
||||||
|
|
||||||
RL_RETURN_IF_FALSE(
|
|
||||||
item.encode(ArchiveKey::BackgroundColor, _backgroundColor.toString()));
|
|
||||||
|
|
||||||
RL_RETURN_IF_FALSE(item.encode(ArchiveKey::Opacity, _opacity));
|
|
||||||
|
|
||||||
RL_RETURN_IF_FALSE(
|
|
||||||
item.encode(ArchiveKey::StrokeColor, _strokeColor.toString()));
|
|
||||||
|
|
||||||
RL_RETURN_IF_FALSE(item.encode(ArchiveKey::StrokeSize, _strokeSize));
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Entity::deserialize(core::ArchiveItem& item, core::Namespace* ns) {
|
|
||||||
std::string decoded;
|
|
||||||
|
|
||||||
RL_RETURN_IF_FALSE(item.decode(ArchiveKey::Identifier, _identifier, ns));
|
|
||||||
|
|
||||||
RL_RETURN_IF_FALSE(item.decode(ArchiveKey::Bounds, decoded));
|
|
||||||
_bounds.fromString(decoded);
|
|
||||||
|
|
||||||
RL_RETURN_IF_FALSE(item.decode(ArchiveKey::Position, decoded));
|
|
||||||
_position.fromString(decoded);
|
|
||||||
|
|
||||||
RL_RETURN_IF_FALSE(item.decode(ArchiveKey::AnchorPoint, decoded));
|
|
||||||
_anchorPoint.fromString(decoded);
|
|
||||||
|
|
||||||
RL_RETURN_IF_FALSE(item.decode(ArchiveKey::Transformation, decoded));
|
|
||||||
_transformation.fromString(decoded);
|
|
||||||
|
|
||||||
RL_RETURN_IF_FALSE(item.decode(ArchiveKey::BackgroundColor, decoded));
|
|
||||||
_backgroundColor.fromString(decoded);
|
|
||||||
|
|
||||||
RL_RETURN_IF_FALSE(item.decode(ArchiveKey::Opacity, _opacity));
|
|
||||||
|
|
||||||
RL_RETURN_IF_FALSE(item.decode(ArchiveKey::StrokeColor, decoded));
|
|
||||||
_strokeColor.fromString(decoded);
|
|
||||||
|
|
||||||
RL_RETURN_IF_FALSE(item.decode(ArchiveKey::StrokeSize, _strokeSize));
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace entity
|
} // namespace entity
|
||||||
|
|||||||
@@ -14,7 +14,7 @@
|
|||||||
namespace rl {
|
namespace rl {
|
||||||
namespace entity {
|
namespace entity {
|
||||||
|
|
||||||
class Entity : public core::ArchiveSerializable {
|
class Entity {
|
||||||
public:
|
public:
|
||||||
using PropertyMaskType = uint16_t;
|
using PropertyMaskType = uint16_t;
|
||||||
|
|
||||||
@@ -56,17 +56,11 @@ class Entity : public core::ArchiveSerializable {
|
|||||||
};
|
};
|
||||||
#undef RL_MASK
|
#undef RL_MASK
|
||||||
|
|
||||||
using UpdateCallback = std::function<void(const Entity& /*entity*/,
|
Entity();
|
||||||
Entity::Property /*property*/,
|
|
||||||
core::Name /*otherIdentifier*/)>;
|
|
||||||
|
|
||||||
Entity(core::Name identifier, UpdateCallback updateCallback = nullptr);
|
|
||||||
|
|
||||||
Entity(Entity&& entity);
|
Entity(Entity&& entity);
|
||||||
|
|
||||||
virtual ~Entity();
|
~Entity();
|
||||||
|
|
||||||
core::Name identifier() const;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The frame specifies the origin and size of the entity in the coordinate
|
* The frame specifies the origin and size of the entity in the coordinate
|
||||||
@@ -194,18 +188,7 @@ class Entity : public core::ArchiveSerializable {
|
|||||||
|
|
||||||
void setPath(geom::Path path);
|
void setPath(geom::Path path);
|
||||||
|
|
||||||
void mergeProperties(const Entity& entity, PropertyMaskType only);
|
private:
|
||||||
|
|
||||||
static const core::ArchiveDef ArchiveDefinition;
|
|
||||||
|
|
||||||
ArchiveName archiveName() const override;
|
|
||||||
|
|
||||||
bool serialize(core::ArchiveItem& item) const override;
|
|
||||||
|
|
||||||
bool deserialize(core::ArchiveItem& item, core::Namespace* ns) override;
|
|
||||||
|
|
||||||
protected:
|
|
||||||
core::Name _identifier;
|
|
||||||
geom::Rect _bounds;
|
geom::Rect _bounds;
|
||||||
geom::Point _position;
|
geom::Point _position;
|
||||||
geom::Point _anchorPoint;
|
geom::Point _anchorPoint;
|
||||||
@@ -217,13 +200,6 @@ class Entity : public core::ArchiveSerializable {
|
|||||||
Color _strokeColor;
|
Color _strokeColor;
|
||||||
double _strokeSize;
|
double _strokeSize;
|
||||||
|
|
||||||
void notifyInterfaceIfNecessary(
|
|
||||||
Property property,
|
|
||||||
core::Name identifier = core::Name() /* dead name */) const;
|
|
||||||
|
|
||||||
private:
|
|
||||||
UpdateCallback _updateCallback;
|
|
||||||
|
|
||||||
FML_DISALLOW_COPY_AND_ASSIGN(Entity);
|
FML_DISALLOW_COPY_AND_ASSIGN(Entity);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ namespace image {
|
|||||||
|
|
||||||
Image::Image() = default;
|
Image::Image() = default;
|
||||||
|
|
||||||
Image::Image(core::Allocation sourceAllocation)
|
Image::Image(fml::RefPtr<const fml::Mapping> sourceAllocation)
|
||||||
: _source(ImageSource::Create(std::move(sourceAllocation))) {}
|
: _source(ImageSource::Create(std::move(sourceAllocation))) {}
|
||||||
|
|
||||||
Image::Image(core::FileHandle sourceFile)
|
Image::Image(core::FileHandle sourceFile)
|
||||||
@@ -20,45 +20,6 @@ Image::Image(core::FileHandle sourceFile)
|
|||||||
|
|
||||||
Image::~Image() = default;
|
Image::~Image() = default;
|
||||||
|
|
||||||
bool Image::serialize(core::Message& message) const {
|
|
||||||
if (_source == nullptr) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Encode the type.
|
|
||||||
*/
|
|
||||||
RL_RETURN_IF_FALSE(message.encode(_source->type()));
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Encode the image source.
|
|
||||||
*/
|
|
||||||
RL_RETURN_IF_FALSE(_source->serialize(message));
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Image::deserialize(core::Message& message, core::Namespace* ns) {
|
|
||||||
auto type = ImageSource::Type::Unknown;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Decode the type.
|
|
||||||
*/
|
|
||||||
RL_RETURN_IF_FALSE(message.decode(type, ns))
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Create and decode the image source of that type.
|
|
||||||
*/
|
|
||||||
auto source = ImageSource::ImageSourceForType(type);
|
|
||||||
if (source == nullptr) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
RL_RETURN_IF_FALSE(source->deserialize(message, ns));
|
|
||||||
_source = source;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
ImageResult Image::decode() const {
|
ImageResult Image::decode() const {
|
||||||
if (_source == nullptr) {
|
if (_source == nullptr) {
|
||||||
return {};
|
return {};
|
||||||
@@ -83,8 +44,8 @@ ImageResult Image::decode() const {
|
|||||||
&comps, // Out: Components
|
&comps, // Out: Components
|
||||||
STBI_default);
|
STBI_default);
|
||||||
|
|
||||||
auto destinationAllocation =
|
auto destinationAllocation = fml::RefPtr<const fml::Mapping>{
|
||||||
core::Allocation{decoded, width * height * comps * sizeof(stbi_uc)};
|
decoded, width * height * comps * sizeof(stbi_uc)};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If either the decoded allocation is null or the size works out to be zero,
|
* If either the decoded allocation is null or the size works out to be zero,
|
||||||
|
|||||||
@@ -7,6 +7,8 @@
|
|||||||
|
|
||||||
#include "ImageResult.h"
|
#include "ImageResult.h"
|
||||||
#include "Size.h"
|
#include "Size.h"
|
||||||
|
#include "flutter/fml/macros.h"
|
||||||
|
#include "flutter/fml/mapping.h"
|
||||||
|
|
||||||
namespace rl {
|
namespace rl {
|
||||||
namespace image {
|
namespace image {
|
||||||
@@ -17,9 +19,7 @@ class Image {
|
|||||||
public:
|
public:
|
||||||
Image();
|
Image();
|
||||||
|
|
||||||
Image(core::Allocation sourceAllocation);
|
Image(fml::RefPtr<const fml::Mapping> sourceAllocation);
|
||||||
|
|
||||||
Image(core::FileHandle sourceFile);
|
|
||||||
|
|
||||||
~Image();
|
~Image();
|
||||||
|
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ namespace image {
|
|||||||
|
|
||||||
ImageResult::ImageResult(geom::Size size,
|
ImageResult::ImageResult(geom::Size size,
|
||||||
Components components,
|
Components components,
|
||||||
core::Allocation allocation)
|
fml::RefPtr<const fml::Mapping> allocation)
|
||||||
: _success(true),
|
: _success(true),
|
||||||
_size(size),
|
_size(size),
|
||||||
_components(components),
|
_components(components),
|
||||||
@@ -47,7 +47,7 @@ ImageResult::Components ImageResult::components() const {
|
|||||||
return _components;
|
return _components;
|
||||||
}
|
}
|
||||||
|
|
||||||
const core::Allocation& ImageResult::allocation() const {
|
const fml::RefPtr<const fml::Mapping>& ImageResult::allocation() const {
|
||||||
return _allocation;
|
return _allocation;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,6 +6,9 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "Size.h"
|
#include "Size.h"
|
||||||
|
#include "flutter/fml/macros.h"
|
||||||
|
#include "flutter/fml/mapping.h"
|
||||||
|
#include "flutter/fml/memory/ref_counted.h"
|
||||||
|
|
||||||
namespace rl {
|
namespace rl {
|
||||||
namespace image {
|
namespace image {
|
||||||
@@ -24,7 +27,7 @@ class ImageResult {
|
|||||||
|
|
||||||
ImageResult(geom::Size size,
|
ImageResult(geom::Size size,
|
||||||
Components components,
|
Components components,
|
||||||
core::Allocation allocation);
|
fml::RefPtr<const fml::Mapping> allocation);
|
||||||
|
|
||||||
ImageResult(ImageResult&&);
|
ImageResult(ImageResult&&);
|
||||||
|
|
||||||
@@ -38,13 +41,13 @@ class ImageResult {
|
|||||||
|
|
||||||
Components components() const;
|
Components components() const;
|
||||||
|
|
||||||
const core::Allocation& allocation() const;
|
const fml::RefPtr<const fml::Mapping>& allocation() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool _success;
|
bool _success;
|
||||||
geom::Size _size;
|
geom::Size _size;
|
||||||
Components _components;
|
Components _components;
|
||||||
core::Allocation _allocation;
|
fml::RefPtr<const fml::Mapping> _allocation;
|
||||||
|
|
||||||
FML_DISALLOW_COPY_AND_ASSIGN(ImageResult);
|
FML_DISALLOW_COPY_AND_ASSIGN(ImageResult);
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user