2
0
Эх сурвалжийг харах

Refactor ElementDecoration to ElementEffects

Michael Ragazzon 1 жил өмнө
parent
commit
37cf4d3e7f

+ 2 - 2
CMake/FileList.cmake

@@ -21,8 +21,8 @@ set(Core_HDR_FILES
     ${PROJECT_SOURCE_DIR}/Source/Core/DocumentHeader.h
     ${PROJECT_SOURCE_DIR}/Source/Core/ElementAnimation.h
     ${PROJECT_SOURCE_DIR}/Source/Core/ElementBackgroundBorder.h
-    ${PROJECT_SOURCE_DIR}/Source/Core/ElementDecoration.h
     ${PROJECT_SOURCE_DIR}/Source/Core/ElementDefinition.h
+    ${PROJECT_SOURCE_DIR}/Source/Core/ElementEffects.h
     ${PROJECT_SOURCE_DIR}/Source/Core/ElementHandle.h
     ${PROJECT_SOURCE_DIR}/Source/Core/Elements/ElementImage.h
     ${PROJECT_SOURCE_DIR}/Source/Core/Elements/ElementLabel.h
@@ -277,9 +277,9 @@ set(Core_SRC_FILES
     ${PROJECT_SOURCE_DIR}/Source/Core/Element.cpp
     ${PROJECT_SOURCE_DIR}/Source/Core/ElementAnimation.cpp
     ${PROJECT_SOURCE_DIR}/Source/Core/ElementBackgroundBorder.cpp
-    ${PROJECT_SOURCE_DIR}/Source/Core/ElementDecoration.cpp
     ${PROJECT_SOURCE_DIR}/Source/Core/ElementDefinition.cpp
     ${PROJECT_SOURCE_DIR}/Source/Core/ElementDocument.cpp
+    ${PROJECT_SOURCE_DIR}/Source/Core/ElementEffects.cpp
     ${PROJECT_SOURCE_DIR}/Source/Core/ElementHandle.cpp
     ${PROJECT_SOURCE_DIR}/Source/Core/ElementInstancer.cpp
     ${PROJECT_SOURCE_DIR}/Source/Core/Elements/ElementForm.cpp

+ 6 - 5
Include/RmlUi/Core/EffectSpecification.h

@@ -47,18 +47,19 @@ public:
 protected:
 	~EffectSpecification();
 
-	/// Registers a property for the decorator.
+	/// Registers a property for the effect.
 	/// @param[in] property_name The name of the new property (how it is specified through RCSS).
 	/// @param[in] default_value The default value to be used.
 	/// @return The new property definition, ready to have parsers attached.
 	PropertyDefinition& RegisterProperty(const String& property_name, const String& default_value);
 
-	/// Registers a shorthand property definition. Specify a shorthand name of 'decorator' to parse anonymous decorators.
+	/// Registers a shorthand property definition. Specify a shorthand name of 'decorator' or 'filter' to parse
+	/// anonymous decorators or filters, respectively.
 	/// @param[in] shorthand_name The name to register the new shorthand property under.
-	/// @param[in] properties A comma-separated list of the properties this definition is shorthand for. The order in which they are specified here is
-	/// the order in which the values will be processed.
+	/// @param[in] properties A comma-separated list of the properties this definition is shorthand for. The order in
+	/// which they are specified here is the order in which the values will be processed.
 	/// @param[in] type The type of shorthand to declare.
-	/// @param True if all the property names exist, false otherwise.
+	/// @return An ID for the new shorthand, or 'Invalid' if the shorthand declaration is invalid.
 	ShorthandId RegisterShorthand(const String& shorthand_name, const String& property_names, ShorthandType type);
 
 private:

+ 0 - 3
Include/RmlUi/Core/Element.h

@@ -51,7 +51,6 @@ class ElementInstancer;
 class EventDispatcher;
 class EventListener;
 class ElementBackgroundBorder;
-class ElementDecoration;
 class ElementDefinition;
 class ElementDocument;
 class ElementScroll;
@@ -578,8 +577,6 @@ public:
 	String GetEventDispatcherSummary() const;
 	/// Access the element background and border.
 	ElementBackgroundBorder* GetElementBackgroundBorder() const;
-	/// Access the element decorators.
-	ElementDecoration* GetElementDecoration() const;
 	/// Returns the element's scrollbar functionality.
 	ElementScroll* GetElementScroll() const;
 	/// Returns the element's nearest scroll container that can be scrolled, if any.

+ 1 - 1
Include/RmlUi/Core/PropertySpecification.h

@@ -98,7 +98,7 @@ public:
 	/// the order in which the values will be processed.
 	/// @param[in] type The type of shorthand to declare.
 	/// @param[in] id If 'Invalid' then automatically assigns a new id, otherwise assigns the given id.
-	/// @param True if all the property names exist, false otherwise.
+	/// @return An ID for the new shorthand, or 'Invalid' if the shorthand declaration is invalid.
 	ShorthandId RegisterShorthand(const String& shorthand_name, const String& property_names, ShorthandType type,
 		ShorthandId id = ShorthandId::Invalid);
 	/// Returns a shorthand definition.

+ 15 - 20
Source/Core/Element.cpp

@@ -47,8 +47,8 @@
 #include "DataModel.h"
 #include "ElementAnimation.h"
 #include "ElementBackgroundBorder.h"
-#include "ElementDecoration.h"
 #include "ElementDefinition.h"
+#include "ElementEffects.h"
 #include "ElementStyle.h"
 #include "EventDispatcher.h"
 #include "EventSpecification.h"
@@ -92,12 +92,12 @@ static float GetScrollOffsetDelta(ScrollAlignment alignment, float begin_offset,
 
 // Meta objects for element collected in a single struct to reduce memory allocations
 struct ElementMeta {
-	ElementMeta(Element* el) : event_dispatcher(el), style(el), background_border(), decoration(el), scroll(el), computed_values(el) {}
+	ElementMeta(Element* el) : event_dispatcher(el), style(el), background_border(), effects(el), scroll(el), computed_values(el) {}
 	SmallUnorderedMap<EventId, EventListener*> attribute_event_listeners;
 	EventDispatcher event_dispatcher;
 	ElementStyle style;
 	ElementBackgroundBorder background_border;
-	ElementDecoration decoration;
+	ElementEffects effects;
 	ElementScroll scroll;
 	Style::ComputedValues computed_values;
 };
@@ -177,7 +177,7 @@ void Element::Update(float dp_ratio, Vector2f vp_dimensions)
 		UpdateProperties(dp_ratio, vp_dimensions);
 	}
 
-	meta->decoration.InstanceDecorators();
+	meta->effects.InstanceEffects();
 
 	for (size_t i = 0; i < children.size(); i++)
 		children[i]->Update(dp_ratio, vp_dimensions);
@@ -233,13 +233,13 @@ void Element::Render()
 	// Apply our transform
 	ElementUtilities::ApplyTransform(*this);
 
-	meta->decoration.RenderDecorators(RenderStage::Enter);
+	meta->effects.RenderEffects(RenderStage::Enter);
 
 	// Set up the clipping region for this element.
 	if (ElementUtilities::SetClippingRegion(this))
 	{
 		meta->background_border.Render(this);
-		meta->decoration.RenderDecorators(RenderStage::Decoration);
+		meta->effects.RenderEffects(RenderStage::Decoration);
 
 		{
 			RMLUI_ZoneScopedNC("OnRender", 0x228B22);
@@ -252,7 +252,7 @@ void Element::Render()
 	for (Element* element : stacking_context)
 		element->Render();
 
-	meta->decoration.RenderDecorators(RenderStage::Exit);
+	meta->effects.RenderEffects(RenderStage::Exit);
 }
 
 ElementPtr Element::Clone() const
@@ -452,7 +452,7 @@ void Element::SetBox(const Box& box)
 
 		meta->background_border.DirtyBackground();
 		meta->background_border.DirtyBorder();
-		meta->decoration.DirtyDecoratorsData();
+		meta->effects.DirtyEffectsData();
 	}
 }
 
@@ -464,7 +464,7 @@ void Element::AddBox(const Box& box, Vector2f offset)
 
 	meta->background_border.DirtyBackground();
 	meta->background_border.DirtyBorder();
-	meta->decoration.DirtyDecoratorsData();
+	meta->effects.DirtyEffectsData();
 }
 
 const Box& Element::GetBox()
@@ -1553,11 +1553,6 @@ ElementBackgroundBorder* Element::GetElementBackgroundBorder() const
 	return &meta->background_border;
 }
 
-ElementDecoration* Element::GetElementDecoration() const
-{
-	return &meta->decoration;
-}
-
 ElementScroll* Element::GetElementScroll() const
 {
 	return &meta->scroll;
@@ -1795,18 +1790,18 @@ void Element::OnPropertyChange(const PropertyIdSet& changed_properties)
 		meta->background_border.DirtyBorder();
 	}
 
-	// Dirty the decoration if it's changed.
+	// Dirty the effects if they've changed.
 	if (border_radius_changed || filter_or_mask_changed || changed_properties.Contains(PropertyId::Decorator))
 	{
-		meta->decoration.DirtyDecorators();
+		meta->effects.DirtyEffects();
 	}
 
-	// Dirty the decoration data when its visual looks may have changed.
+	// Dirty the effects data when their visual looks may have changed.
 	if (border_radius_changed ||                            //
 		changed_properties.Contains(PropertyId::Opacity) || //
 		changed_properties.Contains(PropertyId::ImageColor))
 	{
-		meta->decoration.DirtyDecoratorsData();
+		meta->effects.DirtyEffectsData();
 	}
 
 	// Check for `perspective' and `perspective-origin' changes
@@ -2813,7 +2808,7 @@ void Element::UpdateTransformState()
 
 void Element::OnStyleSheetChangeRecursive()
 {
-	GetElementDecoration()->DirtyDecorators();
+	meta->effects.DirtyEffects();
 
 	OnStyleSheetChange();
 
@@ -2825,7 +2820,7 @@ void Element::OnStyleSheetChangeRecursive()
 
 void Element::OnDpRatioChangeRecursive()
 {
-	GetElementDecoration()->DirtyDecorators();
+	meta->effects.DirtyEffects();
 	GetStyle()->DirtyPropertiesWithUnits(Unit::DP_SCALABLE_LENGTH);
 
 	OnDpRatioChange();

+ 21 - 21
Source/Core/ElementDecoration.cpp → Source/Core/ElementEffects.cpp

@@ -26,7 +26,7 @@
  *
  */
 
-#include "ElementDecoration.h"
+#include "ElementEffects.h"
 #include "../../Include/RmlUi/Core/ComputedValues.h"
 #include "../../Include/RmlUi/Core/Decorator.h"
 #include "../../Include/RmlUi/Core/Element.h"
@@ -38,23 +38,23 @@
 
 namespace Rml {
 
-ElementDecoration::ElementDecoration(Element* _element) : element(_element) {}
+ElementEffects::ElementEffects(Element* _element) : element(_element) {}
 
-ElementDecoration::~ElementDecoration()
+ElementEffects::~ElementEffects()
 {
-	ReleaseDecorators();
+	ReleaseEffects();
 }
 
-void ElementDecoration::InstanceDecorators()
+void ElementEffects::InstanceEffects()
 {
-	if (!decorators_dirty)
+	if (!effects_dirty)
 		return;
 
-	decorators_dirty = false;
-	decorators_data_dirty = true;
+	effects_dirty = false;
+	effects_data_dirty = true;
 
 	RMLUI_ZoneScopedC(0xB22222);
-	ReleaseDecorators();
+	ReleaseEffects();
 
 	RenderManager* render_manager = element->GetRenderManager();
 	if (!render_manager)
@@ -151,11 +151,11 @@ void ElementDecoration::InstanceDecorators()
 	}
 }
 
-void ElementDecoration::ReloadDecoratorsData()
+void ElementEffects::ReloadEffectsData()
 {
-	if (decorators_data_dirty)
+	if (effects_data_dirty)
 	{
-		decorators_data_dirty = false;
+		effects_data_dirty = false;
 
 		bool decorator_data_failed = false;
 		for (DecoratorEntryList* list : {&decorators, &mask_images})
@@ -190,7 +190,7 @@ void ElementDecoration::ReloadDecoratorsData()
 	}
 }
 
-void ElementDecoration::ReleaseDecorators()
+void ElementEffects::ReleaseEffects()
 {
 	for (DecoratorEntryList* list : {&decorators, &mask_images})
 	{
@@ -206,10 +206,10 @@ void ElementDecoration::ReleaseDecorators()
 	backdrop_filters.clear();
 }
 
-void ElementDecoration::RenderDecorators(RenderStage render_stage)
+void ElementEffects::RenderEffects(RenderStage render_stage)
 {
-	InstanceDecorators();
-	ReloadDecoratorsData();
+	InstanceEffects();
+	ReloadEffectsData();
 
 	if (!decorators.empty())
 	{
@@ -286,7 +286,7 @@ void ElementDecoration::RenderDecorators(RenderStage render_stage)
 			// boundaries, which currently only applies to blur and drop-shadow. Alternatively, we could avoid this
 			// completely if we introduced a render interface API concept of different input and output clipping. That
 			// is, we set a large input scissor to cover all input data, which can be used e.g. during blurring, and use
-			// our small border-area-only clipping region for the layers composite output.
+			// our small border-area-only clipping region for the composite layers output.
 			ApplyScissorRegionForBackdrop();
 			render_manager->PushLayer();
 			const LayerHandle backdrop_temp_layer = render_manager->GetTopLayer();
@@ -340,14 +340,14 @@ void ElementDecoration::RenderDecorators(RenderStage render_stage)
 	}
 }
 
-void ElementDecoration::DirtyDecorators()
+void ElementEffects::DirtyEffects()
 {
-	decorators_dirty = true;
+	effects_dirty = true;
 }
 
-void ElementDecoration::DirtyDecoratorsData()
+void ElementEffects::DirtyEffectsData()
 {
-	decorators_data_dirty = true;
+	effects_data_dirty = true;
 }
 
 } // namespace Rml

+ 19 - 25
Source/Core/ElementDecoration.h → Source/Core/ElementEffects.h

@@ -26,11 +26,10 @@
  *
  */
 
-#ifndef RMLUI_CORE_ELEMENTDECORATION_H
-#define RMLUI_CORE_ELEMENTDECORATION_H
+#ifndef RMLUI_CORE_ELEMENTEFFECTS_H
+#define RMLUI_CORE_ELEMENTEFFECTS_H
 
 #include "../../Include/RmlUi/Core/CompiledFilterShader.h"
-#include "../../Include/RmlUi/Core/Filter.h"
 #include "../../Include/RmlUi/Core/Types.h"
 
 namespace Rml {
@@ -38,37 +37,32 @@ namespace Rml {
 class Decorator;
 class Element;
 class Filter;
-class CompiledFilter;
 
 enum class RenderStage { Enter, Decoration, Exit };
 
 /**
-    Manages an elements decorator state
-
-    @author Lloyd Weehuizen
+    Manages and renders an element's effects: decorators, filters, backdrop filters, and mask images.
  */
 
-class ElementDecoration {
+class ElementEffects {
 public:
-	ElementDecoration(Element* element);
-	~ElementDecoration();
+	ElementEffects(Element* element);
+	~ElementEffects();
 
-	/// Instances decorators if necessary.
-	void InstanceDecorators();
+	void InstanceEffects();
 
-	/// Renders all appropriate decorators.
-	void RenderDecorators(RenderStage render_stage);
+	void RenderEffects(RenderStage render_stage);
 
-	/// Mark decorators as dirty and force them to reset themselves.
-	void DirtyDecorators();
-	/// Mark the element data of decorators as dirty.
-	void DirtyDecoratorsData();
+	// Mark effects as dirty and force them to reset themselves.
+	void DirtyEffects();
+	// Mark the element data of effects as dirty.
+	void DirtyEffectsData();
 
 private:
-	// Releases existing element data of decorators, and regenerates it.
-	void ReloadDecoratorsData();
-	// Releases all existing decorators and frees their data.
-	void ReleaseDecorators();
+	// Releases existing element data of effects, and regenerates it.
+	void ReloadEffectsData();
+	// Releases all existing effects and their element data.
+	void ReleaseEffects();
 
 	struct DecoratorEntry {
 		SharedPtr<const Decorator> decorator;
@@ -85,16 +79,16 @@ private:
 
 	Element* element;
 
-	// The list of decorators and filters used by this element from all style rules.
+	// The list of decorators and filters used by this element.
 	DecoratorEntryList decorators;
 	DecoratorEntryList mask_images;
 	FilterEntryList filters;
 	FilterEntryList backdrop_filters;
 
 	// If set, a full reload is necessary.
-	bool decorators_dirty = false;
+	bool effects_dirty = false;
 	// If set, element data of all decorators need to be regenerated.
-	bool decorators_data_dirty = false;
+	bool effects_data_dirty = false;
 };
 
 } // namespace Rml

+ 0 - 1
Source/Core/ElementStyle.cpp

@@ -44,7 +44,6 @@
 #include "../../Include/RmlUi/Core/StyleSheetSpecification.h"
 #include "../../Include/RmlUi/Core/TransformPrimitive.h"
 #include "ComputeProperty.h"
-#include "ElementDecoration.h"
 #include "ElementDefinition.h"
 #include "PropertiesIterator.h"
 #include <algorithm>

+ 1 - 1
Source/Core/ElementUtilities.cpp

@@ -290,7 +290,7 @@ bool ElementUtilities::GetBoundingBox(Rectanglef& out_rectangle, Element* elemen
 	if (box_area == BoxArea::Auto)
 	{
 		// 'Auto' acts like border box extended to encompass any ink overflow, including the element's box-shadow.
-		// Note: Does not currently include ink overflow due to filters, as that is handled manually in ElementDecoration.
+		// Note: Does not currently include ink overflow due to filters, as that is handled manually in ElementEffects.
 		box_area = BoxArea::Border;
 
 		if (const Property* p_box_shadow = element->GetLocalProperty(PropertyId::BoxShadow))