File indexing completed on 2025-02-02 04:11:07
0001 /* 0002 * SPDX-FileCopyrightText: 2019-2023 Mattia Basaglia <dev@dragon.best> 0003 * 0004 * SPDX-License-Identifier: GPL-3.0-or-later 0005 */ 0006 0007 #pragma once 0008 0009 #include "model/property/reference_property.hpp" 0010 #include "model/stretchable_time.hpp" 0011 #include "model/shapes/shape.hpp" 0012 #include "model/assets/composition.hpp" 0013 0014 0015 namespace glaxnimate::model { 0016 0017 class PreCompLayer : public ShapeElement 0018 { 0019 GLAXNIMATE_OBJECT(PreCompLayer) 0020 0021 GLAXNIMATE_SUBOBJECT(StretchableTime, timing) 0022 GLAXNIMATE_PROPERTY_REFERENCE(Composition, composition, &PreCompLayer::valid_precomps, &PreCompLayer::is_valid_precomp, &PreCompLayer::composition_changed) 0023 GLAXNIMATE_PROPERTY(QSizeF, size, {}) 0024 GLAXNIMATE_SUBOBJECT(Transform, transform) 0025 GLAXNIMATE_ANIMATABLE(float, opacity, 1, &PreCompLayer::opacity_changed, 0, 1, false, PropertyTraits::Percent) 0026 0027 public: 0028 PreCompLayer(Document* document); 0029 0030 0031 QIcon tree_icon() const override; 0032 QString type_name_human() const override; 0033 void set_time(FrameTime t) override; 0034 0035 /** 0036 * \brief Returns the (frame) time relative to this layer 0037 * 0038 * Useful for stretching / remapping etc. 0039 * Always use this to get animated property values, 0040 * even if currently it doesn't do anything 0041 */ 0042 FrameTime relative_time(FrameTime time) const; 0043 0044 QRectF local_bounding_rect(FrameTime t) const override; 0045 QTransform local_transform_matrix(model::FrameTime t) const override; 0046 0047 void add_shapes(model::FrameTime t, math::bezier::MultiBezier & bez, const QTransform& transform) const override; 0048 0049 QPainterPath to_clip(model::FrameTime t) const override; 0050 0051 Q_SIGNALS: 0052 void opacity_changed(float op); 0053 void composition_changed(); 0054 0055 protected: 0056 QPainterPath to_painter_path_impl(model::FrameTime t) const override; 0057 void on_paint(QPainter*, FrameTime, PaintMode, model::Modifier*) const override; 0058 void on_composition_changed(model::Composition* old_comp, model::Composition* new_comp) override; 0059 0060 private Q_SLOTS: 0061 void on_transform_matrix_changed(); 0062 0063 0064 private: 0065 std::vector<DocumentNode*> valid_precomps() const; 0066 bool is_valid_precomp(DocumentNode* node) const; 0067 void refresh_owner_composition(); 0068 0069 }; 0070 0071 } // namespace glaxnimate::model