Browse Source

Initial Lottie support, refactored from #134.

The lottie element has been refactored into a separate sample, injected as a plugin.

Co-authored-by: Michael R. P. Ragazzon <[email protected]>
Paweł 5 years ago
parent
commit
83171860bb

+ 11 - 0
CMake/SampleFileList.cmake

@@ -103,6 +103,17 @@ set(transform_SRC_FILES
     ${PROJECT_SOURCE_DIR}/Samples/basic/transform/src/main.cpp
 )
 
+set(lottie_HDR_FILES
+    ${PROJECT_SOURCE_DIR}/Samples/basic/lottie/src/ElementLottie.h
+    ${PROJECT_SOURCE_DIR}/Samples/basic/lottie/src/LottiePlugin.h
+)
+
+set(lottie_SRC_FILES
+    ${PROJECT_SOURCE_DIR}/Samples/basic/lottie/src/ElementLottie.cpp
+    ${PROJECT_SOURCE_DIR}/Samples/basic/lottie/src/LottiePlugin.cpp
+    ${PROJECT_SOURCE_DIR}/Samples/basic/lottie/src/main.cpp
+)
+
 set(sdl2_HDR_FILES
     ${PROJECT_SOURCE_DIR}/Samples/basic/sdl2/src/RenderInterfaceSDL2.h
     ${PROJECT_SOURCE_DIR}/Samples/basic/sdl2/src/SystemInterfaceSDL2.h

+ 1 - 1
CMake/gen_samplelists.sh

@@ -8,7 +8,7 @@ srcdir='${PROJECT_SOURCE_DIR}'
 srcpath=Samples
 samples=( 'shell'
 	'basic/animation' 'basic/benchmark' 'basic/bitmapfont' 'basic/customlog' 'basic/databinding' 'basic/demo' 'basic/drag' 'basic/loaddocument' 'basic/treeview' 'basic/transform'
-	'basic/sdl2' 'basic/sfml2'
+	'basic/lottie' 'basic/sdl2' 'basic/sfml2'
 	'tutorial/template' 'tutorial/datagrid' 'tutorial/datagrid_tree' 'tutorial/drag'
 	'invaders' 'luainvaders'
 )

+ 40 - 1
CMakeLists.txt

@@ -120,6 +120,10 @@ if(NOT DEFINED ENV{TRACY_DIR})
 	set(ENV{TRACY_DIR} "${PROJECT_SOURCE_DIR}/Dependencies")
 endif()
 
+if(NOT DEFINED ENV{RLOTTIE_DIR})
+	set(ENV{RLOTTIE_DIR} "${PROJECT_SOURCE_DIR}/Dependencies/rlottie")
+endif()
+
 #===================================
 # Plaform specific global hacks ====
 #===================================
@@ -256,7 +260,6 @@ elseif (ENABLE_PRECOMPILED_HEADERS)
 	set(PRECOMPILED_HEADERS_ENABLED ON)
 endif()
 
-
 option(WARNINGS_AS_ERRORS "Treat compiler warnings as errors." OFF)
 mark_as_advanced(WARNINGS_AS_ERRORS)
 
@@ -675,6 +678,36 @@ endif(NOT BUILD_FRAMEWORK)
 				RUNTIME DESTINATION ${SAMPLES_DIR}/sfml2
 				BUNDLE DESTINATION ${SAMPLES_DIR})
 	endif()
+	
+	# Try to find rlottie for the lottie sample.
+	if(NOT DEFINED rlottie_DIR)
+		set(rlottie_DIR $ENV{RLOTTIE_DIR})
+	endif()
+
+	list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/Dependencies/rlottie/build)
+	find_package(rlottie CONFIG)
+	find_path(rlottie_INCLUDE_DIR rlottie.h HINTS ${rlottie_DIR} $ENV{rlottie_DIR} PATH_SUFFIXES inc rlottie/inc )
+	
+	if(rlottie_FOUND AND rlottie_INCLUDE_DIR)
+		message("-- Can lottie sample be built - yes")
+		bl_sample(lottie ${sample_LIBRARIES} rlottie::rlottie)
+		target_include_directories(lottie PRIVATE ${rlottie_INCLUDE_DIR})
+		
+		# The samples always set this as their current working directory
+		install(DIRECTORY DESTINATION ${SAMPLES_DIR}/basic/lottie)
+		install(TARGETS lottie
+			RUNTIME DESTINATION ${SAMPLES_DIR}/lottie
+			BUNDLE DESTINATION ${SAMPLES_DIR}
+		)
+	else()
+		if(rlottie_FOUND)
+			message("-- Can lottie sample be built - no - rlottie library found - rlotty include directory not found")
+		elseif(rlottie_INCLUDE_DIR)
+			message("-- Can lottie sample be built - no - rlottie library not found - rlotty include directory found at ${rlottie_INCLUDE_DIR}")
+		else()
+			message("-- Can lottie sample be built - no - rlottie not found")
+		endif()
+	endif()
 
 	# Build and install the tutorials
 	foreach(tutorial ${tutorials})
@@ -771,6 +804,12 @@ if(BUILD_SAMPLES)
 	install(DIRECTORY ${PROJECT_SOURCE_DIR}/Samples/invaders/data
 			DESTINATION ${SAMPLES_DIR}/invaders
 	)
+	
+	if(TARGET lottie)
+		install(DIRECTORY ${PROJECT_SOURCE_DIR}/Samples/basic/lottie/data
+				DESTINATION ${SAMPLES_DIR}/basic/lottie
+		)
+	endif()
 
 	if(BUILD_LUA_BINDINGS)
 		install(DIRECTORY ${PROJECT_SOURCE_DIR}/Samples/luainvaders/data 

File diff suppressed because it is too large
+ 0 - 0
Samples/basic/lottie/data/lottie.json


+ 28 - 0
Samples/basic/lottie/data/lottie.rml

@@ -0,0 +1,28 @@
+<rml>
+	<head>
+		<title>Demo</title>
+		<link type="text/template" href="/assets/window.rml" />
+		<style>
+			body
+			{
+				width: 300px;
+				height: 225px;
+				
+				margin: auto;
+			}
+			
+			div#title_bar div#icon
+			{
+				display: none;
+			}
+			
+			div#content
+			{
+				text-align: left;
+			}
+		</style>
+	</head>
+	<body template="window">
+		<lottie></lottie>
+	</body>
+</rml>

+ 251 - 0
Samples/basic/lottie/src/ElementLottie.cpp

@@ -0,0 +1,251 @@
+/*
+ * This source file is part of RmlUi, the HTML/CSS Interface Middleware
+ *
+ * For the latest information, see http://github.com/mikke89/RmlUi
+ *
+ * Copyright (c) 2008-2010 CodePoint Ltd, Shift Technology Ltd
+ * Copyright (c) 2019 The RmlUi Team, and contributors
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ */
+
+#include "ElementLottie.h"
+#include <RmlUi/Core/URL.h>
+#include <RmlUi/Core/PropertyIdSet.h>
+#include <RmlUi/Core/GeometryUtilities.h>
+#include <RmlUi/Core/ElementDocument.h>
+#include <RmlUi/Core/StyleSheet.h>
+#include <rlottie.h>
+
+namespace Rml
+{
+	ElementLottie::ElementLottie(const String& tag) : Element(tag), geometry(this), m_dimensions(200.0f, 200.0f), m_is_need_recreate_texture(true), m_is_need_recreate_geometry(true), m_p_raw_data(nullptr)
+	{
+	}
+
+	ElementLottie::~ElementLottie(void)
+	{
+	}
+
+	bool ElementLottie::GetIntrinsicDimensions(Vector2f& dimensions, float& ratio)
+	{
+		if (this->m_is_need_recreate_texture)
+			this->LoadTexture();
+
+		dimensions = this->m_dimensions;
+		
+		return true;
+	}
+
+	void ElementLottie::OnRender()
+	{
+
+		geometry.Render(GetAbsoluteOffset(Box::CONTENT).Round());
+		this->Play();
+	}
+
+	void ElementLottie::OnUpdate()
+	{
+
+	}
+
+	void ElementLottie::OnResize()
+	{
+		this->GenerateGeometry();
+	}
+
+	void ElementLottie::OnAttributeChange(const ElementAttributes& changed_attributes)
+	{
+	}
+
+	void ElementLottie::OnPropertyChange(const PropertyIdSet& changed_properties)
+	{
+	}
+
+	void ElementLottie::GenerateGeometry()
+	{
+		geometry.Release(true);
+
+		Vector< Vertex >& vertices = geometry.GetVertices();
+		Vector< int >& indices = geometry.GetIndices();
+
+		vertices.resize(4);
+		indices.resize(6);
+
+		// Generate the texture coordinates.
+		Vector2f texcoords[2];
+/*
+		if (rect_source != RectSource::None)
+		{
+			Vector2f texture_dimensions((float)texture.GetDimensions(GetRenderInterface()).x, (float)texture.GetDimensions(GetRenderInterface()).y);
+			if (texture_dimensions.x == 0.0f)
+				texture_dimensions.x = 1.0f;
+
+			if (texture_dimensions.y == 0.0f)
+				texture_dimensions.y = 1.0f;
+
+			texcoords[0].x = rect.x / texture_dimensions.x;
+			texcoords[0].y = rect.y / texture_dimensions.y;
+
+			texcoords[1].x = (rect.x + rect.width) / texture_dimensions.x;
+			texcoords[1].y = (rect.y + rect.height) / texture_dimensions.y;
+		}
+		else
+		{*/
+			texcoords[0] = Vector2f(0.0f, 0.0f);
+			texcoords[1] = Vector2f(1.0f, 1.0f);
+/*
+		}
+*/
+
+		const ComputedValues& computed = GetComputedValues();
+
+		float opacity = computed.opacity;
+		Colourb quad_colour = computed.image_color;
+		quad_colour.alpha = (byte)(opacity * (float)quad_colour.alpha);
+
+		Vector2f quad_size = GetBox().GetSize(Box::CONTENT).Round();
+
+		GeometryUtilities::GenerateQuad(&vertices[0], &indices[0], Vector2f(0, 0), quad_size, quad_colour, texcoords[0], texcoords[1]);
+
+		this->m_is_need_recreate_geometry = false;
+	}
+
+	bool ElementLottie::LoadTexture()
+	{
+		this->m_is_need_recreate_texture = false;
+
+		const String& attiribute_value_name = GetAttribute<String>("src", "C:\\Users\\lord\\RmlUi\\Samples\\assets\\lottie.json");
+
+		if (attiribute_value_name.empty())
+			return false;
+
+		this->m_file_name = attiribute_value_name;
+		this->m_p_lottie = rlottie::Animation::loadFromFile(attiribute_value_name.c_str());
+
+		if (this->m_p_lottie == nullptr)
+		{
+			Log::Message(Rml::Log::Type::LT_WARNING, "can't load lottie file properly");
+			return false;
+		}
+
+		auto p_callback = [this](const String& name, UniquePtr<const byte[]>& data, Vector2i& dimensions) -> bool {
+			size_t bytes_per_line = m_dimensions.x * sizeof(std::uint32_t);
+			std::uint32_t* p_data = new std::uint32_t[bytes_per_line * m_dimensions.y];
+			this->m_p_raw_data = p_data;
+/*			rlottie::Surface surface(p_data, m_dimensions.x, m_dimensions.y, bytes_per_line);*/
+/*			m_p_lottie->renderSync(m_p_lottie->frameAtPos(counter), surface);*/
+			const Rml::byte* p_result = reinterpret_cast<Rml::byte*>(p_data);
+			data.reset(p_result);
+
+			dimensions.x = m_dimensions.x;
+			dimensions.y = m_dimensions.y;
+
+
+			return true;
+		};
+
+		this->texture.Set(attiribute_value_name, p_callback);
+
+		this->geometry.SetTexture(&this->texture);
+
+		return true;
+	}
+
+	void ElementLottie::UpdateRect()
+	{
+	}
+
+	void ElementLottie::Play(void)
+	{
+		if (this->m_p_raw_data == nullptr)
+			return;
+
+		static std::uint32_t current_frame = 0;
+		++current_frame;
+		current_frame = current_frame % this->m_p_lottie->totalFrame();
+		static float pos = 0.0f;
+		pos += 0.1f / this->m_p_lottie->frameRate();
+		if (pos >= 1.0f)
+			pos = 0.0f;
+
+		auto p_callback = [this](const String& name, UniquePtr<const byte[]>& data, Vector2i& dimensions) -> bool {
+			size_t bytes_per_line = m_dimensions.x * sizeof(std::uint32_t);
+			std::uint32_t* p_data = new std::uint32_t[bytes_per_line * m_dimensions.y];
+			this->m_p_raw_data = p_data;
+			rlottie::Surface surface(p_data, m_dimensions.x, m_dimensions.y, bytes_per_line);
+			m_p_lottie->renderSync(this->m_p_lottie->frameAtPos(pos), surface);
+
+			size_t total_bytes = m_dimensions.x * m_dimensions.y * 4;
+
+/*
+
+			for (int i = 0; i < total_bytes; ++i)
+			{
+				p_data[i] = p_data[i] << 8 | p_data[i] >> 24;
+			}
+*/
+			// temporary convertation, but need future fixes
+			for (int i = 0; i < total_bytes; ++i)
+			{
+				p_data[i] = p_data[i] << 8 | p_data[i] >> 24;
+			}
+
+/* not working well
+			for (int i = 0; i < total_bytes; i += 4) {
+				auto a = p_data[i + 3];
+				// compute only if alpha is non zero
+				if (a) {
+					auto r = p_data[i + 2];
+					auto g = p_data[i + 1];
+					auto b = p_data[i];
+
+					if (a != 255) {  // un premultiply
+						r = (r * 255) / a;
+						g = (g * 255) / a;
+						b = (b * 255) / a;
+
+						p_data[i] = r;
+						p_data[i + 1] = g;
+						p_data[i + 2] = b;
+
+					}
+					else {
+						// only swizzle r and b
+						p_data[i] = r;
+						p_data[i + 2] = b;
+					}
+				}
+			}*/
+			const Rml::byte* p_result = reinterpret_cast<Rml::byte*>(p_data);
+			data.reset(p_result);
+
+			dimensions.x = m_dimensions.x;
+			dimensions.y = m_dimensions.y;
+
+
+			return true;
+		};
+
+		this->texture.Set(this->m_file_name, p_callback);
+
+		this->geometry.SetTexture(&this->texture);
+	}
+}

+ 98 - 0
Samples/basic/lottie/src/ElementLottie.h

@@ -0,0 +1,98 @@
+/*
+ * This source file is part of RmlUi, the HTML/CSS Interface Middleware
+ *
+ * For the latest information, see http://github.com/mikke89/RmlUi
+ *
+ * Copyright (c) 2008-2010 CodePoint Ltd, Shift Technology Ltd
+ * Copyright (c) 2019 The RmlUi Team, and contributors
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ * 
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ */
+
+#ifndef RMLUI_ELEMENT_LOTTIE_H
+#define RMLUI_ELEMENT_LOTTIE_H
+
+#include <RmlUi/Core/Header.h>
+#include <RmlUi/Core/Element.h>
+#include <RmlUi/Core/Geometry.h>
+#include <RmlUi/Core/Texture.h>
+
+#include <rlottie.h>
+
+namespace Rml
+{
+	class ElementLottie : public Element
+	{
+	public:
+		RMLUI_RTTI_DefineWithParent(ElementLottie, Element);
+		ElementLottie(const String& tag);
+
+		virtual ~ElementLottie(void);
+
+		/// Returns the element's inherent size.
+		bool GetIntrinsicDimensions(Vector2f& dimensions, float& ratio) override;
+
+	protected:
+		/// Renders the image.
+		void OnRender() override;
+		void OnUpdate() override;
+
+		/// Regenerates the element's geometry.
+		void OnResize() override;
+
+		/// Checks for changes to the image's source or dimensions.
+		/// @param[in] changed_attributes A list of attributes changed on the element.
+		void OnAttributeChange(const ElementAttributes& changed_attributes) override;
+
+		/// Called when properties on the element are changed.
+		/// @param[in] changed_properties The properties changed on the element.
+		void OnPropertyChange(const PropertyIdSet& changed_properties) override;
+
+	private:
+		// Generates the element's geometry.
+		void GenerateGeometry();
+		// Loads the element's texture, as specified by the 'src' attribute.
+		bool LoadTexture();
+		// Loads the rect value from the element's attribute, but only if we're not a sprite.
+		void UpdateRect();
+
+		void Play(void);
+
+	private:
+		bool m_is_need_recreate_texture;
+		bool m_is_need_recreate_geometry;
+		std::uint32_t* m_p_raw_data;
+		String m_file_name;
+		// The texture this element is rendering from.
+		Texture texture;
+ 
+		// The element's computed intrinsic dimensions. If either of these values are set to -1, then
+		// that dimension has not been computed yet.
+		Vector2f m_dimensions;
+
+		// The geometry used to render this element.
+		Geometry geometry;
+
+		std::unique_ptr<rlottie::Animation> m_p_lottie;
+	};
+}
+
+
+#endif

+ 74 - 0
Samples/basic/lottie/src/LottiePlugin.cpp

@@ -0,0 +1,74 @@
+/*
+ * This source file is part of RmlUi, the HTML/CSS Interface Middleware
+ *
+ * For the latest information, see http://github.com/mikke89/RmlUi
+ *
+ * Copyright (c) 2008-2010 CodePoint Ltd, Shift Technology Ltd
+ * Copyright (c) 2019 The RmlUi Team, and contributors
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ */
+
+
+#include "ElementLottie.h"
+#include <RmlUi/Core/ElementInstancer.h>
+#include <RmlUi/Core/Factory.h>
+#include <RmlUi/Core/StyleSheetSpecification.h>
+#include <RmlUi/Core/XMLParser.h>
+#include <RmlUi/Core/Plugin.h>
+#include <RmlUi/Core/Core.h>
+
+namespace Rml {
+namespace Lottie {
+
+static bool initialised = false;
+static UniquePtr<ElementInstancerGeneric<ElementLottie>> instancer;
+
+class LottiePlugin : public Plugin {
+public:
+	void OnShutdown() override
+	{
+		initialised = false;
+		instancer.reset();
+		delete this;
+	}
+
+	int GetEventClasses() override
+	{
+		return Plugin::EVT_BASIC;
+	}
+};
+
+void Initialise()
+{
+	if (!initialised)
+	{
+		instancer = MakeUnique<ElementInstancerGeneric<ElementLottie> >();
+
+		Factory::RegisterElementInstancer("lottie", instancer.get());
+
+		RegisterPlugin(new LottiePlugin());
+
+		initialised = true;
+	}
+}
+
+}
+}

+ 41 - 0
Samples/basic/lottie/src/LottiePlugin.h

@@ -0,0 +1,41 @@
+/*
+ * This source file is part of RmlUi, the HTML/CSS Interface Middleware
+ *
+ * For the latest information, see http://github.com/mikke89/RmlUi
+ *
+ * Copyright (c) 2008-2010 CodePoint Ltd, Shift Technology Ltd
+ * Copyright (c) 2019 The RmlUi Team, and contributors
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ */
+
+#ifndef RMLUI_LOTTIE_PLUGIN_H
+#define RMLUI_LOTTIE_PLUGIN_H
+
+
+namespace Rml {
+namespace Lottie {
+
+void Initialise();
+
+}
+}
+
+#endif

+ 122 - 0
Samples/basic/lottie/src/main.cpp

@@ -0,0 +1,122 @@
+/*
+ * This source file is part of RmlUi, the HTML/CSS Interface Middleware
+ *
+ * For the latest information, see http://github.com/mikke89/RmlUi
+ *
+ * Copyright (c) 2008-2010 CodePoint Ltd, Shift Technology Ltd
+ * Copyright (c) 2019 The RmlUi Team, and contributors
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ */
+
+#include <RmlUi/Core.h>
+#include <RmlUi/Debugger.h>
+#include <Input.h>
+#include <Shell.h>
+#include <ShellRenderInterfaceOpenGL.h>
+#include "LottiePlugin.h"
+
+Rml::Context* context = nullptr;
+
+ShellRenderInterfaceExtensions* shell_renderer;
+
+void GameLoop()
+{
+	context->Update();
+
+	shell_renderer->PrepareRenderBuffer();
+	context->Render();
+	shell_renderer->PresentRenderBuffer();
+}
+
+#if defined RMLUI_PLATFORM_WIN32
+#include <windows.h>
+int APIENTRY WinMain(HINSTANCE RMLUI_UNUSED_PARAMETER(instance_handle), HINSTANCE RMLUI_UNUSED_PARAMETER(previous_instance_handle), char* RMLUI_UNUSED_PARAMETER(command_line), int RMLUI_UNUSED_PARAMETER(command_show))
+#else
+int main(int RMLUI_UNUSED_PARAMETER(argc), char** RMLUI_UNUSED_PARAMETER(argv))
+#endif
+{
+#ifdef RMLUI_PLATFORM_WIN32
+	RMLUI_UNUSED(instance_handle);
+	RMLUI_UNUSED(previous_instance_handle);
+	RMLUI_UNUSED(command_line);
+	RMLUI_UNUSED(command_show);
+#else
+	RMLUI_UNUSED(argc);
+	RMLUI_UNUSED(argv);
+#endif
+
+#ifdef RMLUI_PLATFORM_WIN32
+	AllocConsole();
+#endif
+
+	int window_width = 1024;
+	int window_height = 768;
+
+	ShellRenderInterfaceOpenGL opengl_renderer;
+	shell_renderer = &opengl_renderer;
+
+	// Generic OS initialisation, creates a window and attaches OpenGL.
+	if (!Shell::Initialise() ||
+		!Shell::OpenWindow("Lottie sample", shell_renderer, window_width, window_height, true))
+	{
+		Shell::Shutdown();
+		return -1;
+	}
+
+	// RmlUi initialisation.
+	Rml::SetRenderInterface(&opengl_renderer);
+	shell_renderer->SetViewport(window_width, window_height);
+
+	ShellSystemInterface system_interface;
+	Rml::SetSystemInterface(&system_interface);
+
+	Rml::Initialise();
+
+	// Create the main RmlUi context and set it on the shell's input layer.
+	context = Rml::CreateContext("main", Rml::Vector2i(window_width, window_height));
+	if (context == nullptr)
+	{
+		Rml::Shutdown();
+		Shell::Shutdown();
+		return -1;
+	}
+
+	Rml::Lottie::Initialise();
+	Rml::Debugger::Initialise(context);
+	Input::SetContext(context);
+	shell_renderer->SetContext(context);
+
+	Shell::LoadFonts("assets/");
+
+	// Load and show the demo document.
+	if (Rml::ElementDocument* document = context->LoadDocument("basic/lottie/data/lottie.rml"))
+		document->Show();
+
+	Shell::EventLoop(GameLoop);
+
+	// Shutdown RmlUi.
+	Rml::Shutdown();
+
+	Shell::CloseWindow();
+	Shell::Shutdown();
+
+	return 0;
+}

Some files were not shown because too many files changed in this diff