Michael Ragazzon пре 6 година
родитељ
комит
9c9b65f51d

+ 0 - 4
Include/Rocket/Core/StyleSheetKeywords.h

@@ -97,10 +97,6 @@ const int VERTICAL_ALIGN_TEXT_BOTTOM = 5;
 const int VERTICAL_ALIGN_TOP = 6;
 const int VERTICAL_ALIGN_BOTTOM = 7;
 
-const int Z_INDEX_AUTO = 0;
-const int Z_INDEX_TOP = 1;
-const int Z_INDEX_BOTTOM = 2;
-
 const int DRAG_NONE = 0;
 const int DRAG_DRAG = 1;
 const int DRAG_DRAG_DROP = 2;

+ 16 - 4
Samples/basic/benchmark/src/main.cpp

@@ -173,19 +173,31 @@ void GameLoop()
 		single_loop = false;
 	}
 
+	static constexpr int buffer_size = 100;
+	static float fps_buffer[buffer_size] = {};
+	static int buffer_index = 0;
+
 	static double t_prev = 0.0f;
 	double t = Shell::GetElapsedTime();
 	float dt = float(t - t_prev);
+	t_prev = t;
 	static int count_frames = 0;
 	count_frames += 1;
 
-	if (window && dt > 0.2f)
+	float fps = 1.0f / dt;
+	fps_buffer[buffer_index] = fps;
+	buffer_index = (++buffer_index % buffer_size);
+
+	if (window && count_frames > buffer_size / 8)
 	{
-		t_prev = t;
+		float fps_mean = 0;
+		for (int i = 0; i < buffer_size; i++)
+			fps_mean += fps_buffer[(buffer_index + i) % buffer_size];
+		fps_mean = fps_mean / (float)buffer_size;
+
 		auto el = window->GetDocument()->GetElementById("fps");
-		float fps = float(count_frames) / dt;
 		count_frames = 0;
-		el->SetInnerRML(Rocket::Core::CreateString( 20, "FPS: %f", fps ));
+		el->SetInnerRML(Rocket::Core::CreateString( 20, "FPS: %f", fps_mean ));
 	}
 }
 

+ 3 - 3
Source/Core/Context.cpp

@@ -30,6 +30,7 @@
 #include "EventDispatcher.h"
 #include "EventIterators.h"
 #include "PluginRegistry.h"
+#include "RCSS.h"
 #include "StreamFile.h"
 #include "../../Include/Rocket/Core/StreamMemory.h"
 #include <algorithm>
@@ -892,9 +893,8 @@ bool Context::OnFocusChange(Element* new_focus)
 	ElementDocument* document = focus->GetOwnerDocument();
 	if (document != NULL)
 	{
-		const Property* z_index_property = document->GetProperty(Z_INDEX);
-		if (z_index_property->unit == Property::KEYWORD &&
-			z_index_property->value.Get< int >() == Z_INDEX_AUTO)
+		NumberAuto z_index_property = document->GetComputedValues().z_index;
+		if (z_index_property.type == NumberAuto::Auto)
 			document->PullToFront();
 	}
 

+ 18 - 29
Source/Core/Element.cpp

@@ -229,7 +229,7 @@ void Element::Update()
 	}
 
 	// Right now we are assuming computed values are calculated before OnPropertyChange
-
+	// TODO: Any dirtied properties during the next function call will not have their values computed.
 	UpdateDirtyProperties();
 
 	if (box_dirty)
@@ -1325,8 +1325,8 @@ void Element::SetInnerRML(const String& rml)
 bool Element::Focus()
 {
 	// Are we allowed focus?
-	int focus_property = GetProperty< int >(FOCUS);
-	if (focus_property == FOCUS_NONE)
+	Style::Focus focus_property = element_meta->computed_values.focus;
+	if (focus_property == Style::Focus::None)
 		return false;
 
 	// Ask our context if we can switch focus.
@@ -1412,12 +1412,12 @@ void Element::ScrollIntoView(bool align_with_top)
 	Element* scroll_parent = parent;
 	while (scroll_parent != NULL)
 	{
-		int overflow_x_property = scroll_parent->GetProperty< int >(OVERFLOW_X);
-		int overflow_y_property = scroll_parent->GetProperty< int >(OVERFLOW_Y);
+		Style::Overflow overflow_x_property = scroll_parent->GetComputedValues().overflow_x;
+		Style::Overflow overflow_y_property = scroll_parent->GetComputedValues().overflow_y;
 
-		if ((overflow_x_property != OVERFLOW_VISIBLE &&
+		if ((overflow_x_property != Style::Overflow::Visible &&
 			 scroll_parent->GetScrollWidth() > scroll_parent->GetClientWidth()) ||
-			(overflow_y_property != OVERFLOW_VISIBLE &&
+			(overflow_y_property != Style::Overflow::Visible &&
 			 scroll_parent->GetScrollHeight() > scroll_parent->GetClientHeight()))
 		{
 			Vector2f offset = scroll_parent->GetAbsoluteOffset(Box::BORDER) - GetAbsoluteOffset(Box::BORDER);
@@ -1429,9 +1429,9 @@ void Element::ScrollIntoView(bool align_with_top)
 			if (!align_with_top)
 				scroll_offset.y -= (scroll_parent->GetClientHeight() - size.y);
 
-			if (overflow_x_property != OVERFLOW_VISIBLE)
+			if (overflow_x_property != Style::Overflow::Visible)
 				scroll_parent->SetScrollLeft(scroll_offset.x);
-			if (overflow_y_property != OVERFLOW_VISIBLE)
+			if (overflow_y_property != Style::Overflow::Visible)
 				scroll_parent->SetScrollTop(scroll_offset.y);
 		}
 
@@ -1828,9 +1828,8 @@ void Element::OnPropertyChange(const PropertyNameList& changed_properties)
 	if (all_dirty || changed_properties.find(VISIBILITY) != changed_properties.end() ||
 		changed_properties.find(DISPLAY) != changed_properties.end())
 	{
-		bool new_visibility = GetDisplay() != DISPLAY_NONE &&
-							  GetProperty< int >(VISIBILITY) == VISIBILITY_VISIBLE;
-
+		bool new_visibility = (element_meta->computed_values.display != Style::Display::None && element_meta->computed_values.visibility == Style::Visibility::Visible);
+			
 		if (visible != new_visibility)
 		{
 			visible = new_visibility;
@@ -1905,10 +1904,9 @@ void Element::OnPropertyChange(const PropertyNameList& changed_properties)
 	if (all_dirty || 
 		changed_properties.find(Z_INDEX) != changed_properties.end())
 	{
-		const Property* z_index_property = GetProperty(Z_INDEX);
+		NumberAuto z_index_property = element_meta->computed_values.z_index;
 
-		if (z_index_property->unit == Property::KEYWORD &&
-			z_index_property->value.Get< int >() == Z_INDEX_AUTO)
+		if (z_index_property.type == NumberAuto::Auto)
 		{
 			if (local_stacking_context &&
 				!local_stacking_context_forced)
@@ -1929,16 +1927,7 @@ void Element::OnPropertyChange(const PropertyNameList& changed_properties)
 		}
 		else
 		{
-			float new_z_index;
-			if (z_index_property->unit == Property::KEYWORD)
-			{
-				if (z_index_property->value.Get< int >() == Z_INDEX_TOP)
-					new_z_index = FLT_MAX;
-				else
-					new_z_index = -FLT_MAX;
-			}
-			else
-				new_z_index = z_index_property->value.Get< float >();
+			float new_z_index = z_index_property.value;
 
 			if (new_z_index != z_index)
 			{
@@ -2105,9 +2094,9 @@ void Element::ProcessEvent(Event& event)
 	{
 		if (GetScrollHeight() > GetClientHeight())
 		{
-			int overflow_property = GetProperty< int >(OVERFLOW_Y);
-			if (overflow_property == OVERFLOW_AUTO ||
-				overflow_property == OVERFLOW_SCROLL)
+			Style::Overflow overflow_property = element_meta->computed_values.overflow_y;
+			if (overflow_property == Style::Overflow::Auto ||
+				overflow_property == Style::Overflow::Scroll)
 			{
 				// Stop the propagation if the current element has scrollbars.
 				// This prevents scrolling in parent elements, which is often unintended. If instead desired behavior is
@@ -2118,7 +2107,7 @@ void Element::ProcessEvent(Event& event)
 				if ((wheel_delta < 0 && GetScrollTop() > 0) ||
 					(wheel_delta > 0 && GetScrollHeight() > GetScrollTop() + GetClientHeight()))
 				{
-					SetScrollTop(GetScrollTop() + wheel_delta * (GetFontFaceHandle() ? ElementUtilities::GetLineHeight(this) : (GetProperty(SCROLL_DEFAULT_STEP_SIZE) ? GetProperty< int >(SCROLL_DEFAULT_STEP_SIZE) : 0)));
+					SetScrollTop(GetScrollTop() + wheel_delta * (GetFontFaceHandle() ? ElementUtilities::GetLineHeight(this) : 0));
 				}
 			}
 		}

+ 10 - 6
Source/Core/ElementStyle.cpp

@@ -1237,6 +1237,7 @@ void ElementStyle::ComputeValues(Style::ComputedValues& values, const Style::Com
 		values.clip = parent_values->clip;
 		values.opacity = parent_values->opacity;
 		values.color = parent_values->color;
+		values.focus = parent_values->focus;
 	}
 
 
@@ -1246,6 +1247,7 @@ void ElementStyle::ComputeValues(Style::ComputedValues& values, const Style::Com
 
 	while (IterateProperties(index, name, p))
 	{
+		// @performance: Can use a switch-case with constexpr hashing function
 		if (name == FONT_FAMILY)
 			values.font_family = p->Get<String>();
 		else if (name == FONT_CHARSET)
@@ -1262,14 +1264,14 @@ void ElementStyle::ComputeValues(Style::ComputedValues& values, const Style::Com
 			values.overflow_x = (Style::Overflow)p->Get< int >();
 		else if (name == OVERFLOW_Y)
 			values.overflow_y = (Style::Overflow)p->Get< int >();
-
 		else if (name == CLIP)
-
 			values.clip = ComputeClip(p);
+		else if (name == VISIBILITY)
+			values.visibility = (Style::Visibility)p->Get< int >();
+
 		else if (name == OPACITY)
 			values.opacity = p->Get<float>();
 
-
 		else if (name == BACKGROUND_COLOR)
 			values.background_color = p->Get<Colourb>();
 		else if (name == IMAGE_COLOR)
@@ -1277,7 +1279,6 @@ void ElementStyle::ComputeValues(Style::ComputedValues& values, const Style::Com
 		else if (name == COLOR)
 			values.color = p->Get<Colourb>();
 
-
 		else if (name == MARGIN_TOP)
 			values.margin_top = ComputeLengthPercentageAuto(p, font_size, document_font_size, dp_ratio, pixels_per_inch);
 		else if (name == MARGIN_RIGHT)
@@ -1296,8 +1297,6 @@ void ElementStyle::ComputeValues(Style::ComputedValues& values, const Style::Com
 		else if (name == PADDING_LEFT)
 			values.padding_top = ComputeLengthPercentage(p, font_size, document_font_size, dp_ratio, pixels_per_inch);
 
-
-
 		else if (name == BORDER_TOP_WIDTH)
 			values.border_top_width = ComputeLength(p, font_size, document_font_size, dp_ratio, pixels_per_inch);
 		else if (name == BORDER_RIGHT_WIDTH)
@@ -1307,6 +1306,11 @@ void ElementStyle::ComputeValues(Style::ComputedValues& values, const Style::Com
 		else if (name == BORDER_LEFT_WIDTH)
 			values.border_top_width = ComputeLength(p, font_size, document_font_size, dp_ratio, pixels_per_inch);
 
+		else if (name == FOCUS)
+			values.focus = (Style::Focus)p->Get<int>();
+		else if (name == Z_INDEX)
+			values.z_index = (p->unit == Property::KEYWORD ? NumberAuto(NumberAuto::Auto) : NumberAuto(NumberAuto::Number, p->Get<float>()));
+
 	}
 
 

+ 0 - 1
Source/Core/StringCache.cpp

@@ -108,7 +108,6 @@ const String NONE = "none";
 const String TRANSITION = "transition";
 const String ANIMATION = "animation";
 const String KEYFRAMES = "keyframes";
-const String SCROLL_DEFAULT_STEP_SIZE = "scroll-default-step-size";
 const String OPACITY = "opacity";
 const String POINTER_EVENTS = "pointer-events";
 const String MOUSEDOWN = "mousedown";

+ 0 - 1
Source/Core/StringCache.h

@@ -114,7 +114,6 @@ extern const String TRANSITION;
 extern const String ANIMATION;
 extern const String KEYFRAMES;
 
-extern const String SCROLL_DEFAULT_STEP_SIZE;
 extern const String OPACITY;
 extern const String POINTER_EVENTS;
 

+ 1 - 1
Source/Core/StyleSheetSpecification.cpp

@@ -217,7 +217,7 @@ void StyleSheetSpecification::RegisterDefaultProperties()
 	RegisterProperty(CLEAR, "none", false, true).AddParser("keyword", "none, left, right, both");
 
 	RegisterProperty(Z_INDEX, "auto", false, false)
-		.AddParser("keyword", "auto, top, bottom")
+		.AddParser("keyword", "auto")
 		.AddParser("number");
 
 	RegisterProperty(WIDTH, "auto", false, true)