Files
eepp/include/eepp/graphics/drawable.hpp
Martín Lucas Golini b5efd6d709 Graphics: refine drawable cloning and icon source rendering:
Rename Drawable::createInstance() to clone() and update drawable implementations,
typed helpers, consumers, tests, tools, and external modules.

Avoid retaining private icon clones for immediate single-threaded rendering in the
code editor and ecode plugins. Borrow cached per-size icon sources instead, restoring
temporary color changes after drawing, while preserving owned clones for widgets,
menus, models, and other stateful consumers.

Reduce common drawable allocation overhead by lazily creating DrawableResource
callback state, using inline callback storage and notification snapshots, and safely
supporting callback disconnection during notification.

Lazily allocate UIImage and UINodeDrawable asynchronous lifetime tokens only when
an uncached asynchronous load is actually scheduled.

Document the distinction between borrowed immediate rendering and independently
owned drawable state.
2026-07-21 21:16:32 -03:00

113 lines
2.2 KiB
C++

#ifndef EE_GRAPHICS_DRAWABLE_HPP
#define EE_GRAPHICS_DRAWABLE_HPP
#include <eepp/graphics/blendmode.hpp>
#include <eepp/graphics/resource.hpp>
#include <eepp/graphics/rendermode.hpp>
#include <eepp/math/size.hpp>
#include <eepp/system/color.hpp>
using namespace EE::Math;
using namespace EE::System;
namespace EE { namespace Graphics {
class Drawable;
class StatefulDrawable;
using DrawablePtr = ResourcePtr<Drawable>;
using DrawableWeakPtr = ResourceWeakPtr<Drawable>;
class EE_API Drawable {
public:
enum Type {
TEXTURE,
TEXTUREDRAWABLE,
TEXTUREREGION,
SPRITE,
ARC,
RECTANGLE,
TRIANGLE,
CONVEXSHAPE,
GROUP,
NINEPATCH,
STATELIST,
SKIN,
GLYPH,
UINODEDRAWABLE,
UINODEDRAWABLE_LAYERDRAWABLE,
UIBORDERDRAWABLE,
UIBACKGROUNDDRAWABLE,
RICHTEXT,
LINEARGRADIENT,
REPEATINGLINEARGRADIENT,
RADIALGRADIENT,
REPEATINGRADIALGRADIENT,
CUSTOM
};
virtual ~Drawable();
virtual Sizef getSize() = 0;
virtual Sizef getPixelsSize() = 0;
virtual Float getMinIntrinsicWidth() { return getPixelsSize().getWidth(); }
virtual Float getMaxIntrinsicWidth() { return getPixelsSize().getWidth(); }
virtual void draw() = 0;
virtual void draw( const Vector2f& position ) = 0;
virtual void draw( const Vector2f& position, const Sizef& size ) = 0;
virtual bool isStateful() = 0;
/** Creates an independently mutable instance backed by the same immutable resource data.
* This is an ownership/setup operation; rendering loops must retain and reuse the result. */
virtual DrawablePtr clone() const;
void setAlpha( Uint8 alpha );
const Uint8& getAlpha();
void setColor( const Color& color );
const Color& getColor() const;
void setColorFilter( const Color& color );
RGB getColorFilter();
void clearColor();
void clearColorFilter();
void resetAlpha();
Type getDrawableType() const;
const Vector2f& getPosition() const;
void setPosition( const Vector2f& position );
virtual bool isDrawableResource() const;
protected:
Type mDrawableType;
Color mColor;
Vector2f mPosition;
Drawable( Type drawableType );
virtual void onAlphaChange();
virtual void onColorFilterChange();
virtual void onPositionChange();
};
}} // namespace EE::Graphics
#endif