Browse Source

Make samples work (except Lua).

Michael Ragazzon 6 years ago
parent
commit
109252f67a

+ 1 - 5
Samples/basic/bitmapfont/src/main.cpp

@@ -106,12 +106,8 @@ int main(int RMLUI_UNUSED_PARAMETER(argc), char** RMLUI_UNUSED_PARAMETER(argv))
     Rml::Core::FontDatabase::LoadFontFace("assets/Arial.fnt");
 	
     // Load and show the demo document.
-	Rml::Core::ElementDocument* document = context->LoadDocument("assets/bitmapfont.rml");
-	if (document != NULL)
-	{
+	if(Rml::Core::ElementDocument* document = context->LoadDocument("assets/bitmapfont.rml"))
 		document->Show();
-		document->RemoveReference();
-	}
 
 	Shell::EventLoop(GameLoop);
 

+ 0 - 2
Samples/basic/customlog/src/main.cpp

@@ -112,7 +112,6 @@ int main(int RMLUI_UNUSED_PARAMETER(argc), char** RMLUI_UNUSED_PARAMETER(argv))
 	RMLUI_ASSERTMSG(invalid_document != NULL, "Testing ASSERT logging.");
 	if (invalid_document != NULL)
 	{
-		invalid_document->RemoveReference();
 		invalid_document->Close();
 	}
 
@@ -121,7 +120,6 @@ int main(int RMLUI_UNUSED_PARAMETER(argc), char** RMLUI_UNUSED_PARAMETER(argv))
 	if (document != NULL)
 	{
 		document->Show();
-		document->RemoveReference();
 	}
 
 	Shell::EventLoop(GameLoop);

+ 1 - 5
Samples/basic/loaddocument/src/main.cpp

@@ -105,12 +105,8 @@ int main(int RMLUI_UNUSED_PARAMETER(argc), char** RMLUI_UNUSED_PARAMETER(argv))
 	Shell::LoadFonts("assets/");
 
 	// Load and show the demo document.
-	Rml::Core::ElementDocument* document = context->LoadDocument("assets/demo.rml");
-	if (document != NULL)
-	{
+	if (Rml::Core::ElementDocument * document = context->LoadDocument("assets/demo.rml"))
 		document->Show();
-		document->RemoveReference();
-	}
 
 	Shell::EventLoop(GameLoop);
 

+ 1 - 4
Samples/basic/transform/src/main.cpp

@@ -42,7 +42,7 @@ public:
 	DemoWindow(const Rml::Core::String &title, const Rml::Core::Vector2f &position, Rml::Core::Context *context)
 	{
 		document = context->LoadDocument("basic/transform/data/transform.rml");
-		if (document != NULL)
+		if (document)
 		{
 			document->GetElementById("title")->SetInnerRML(title);
 			document->SetProperty(Rml::Core::PropertyId::Left, Rml::Core::Property(position.x, Rml::Core::Property::PX));
@@ -54,10 +54,7 @@ public:
 	~DemoWindow()
 	{
 		if (document)
-		{
-			document->RemoveReference();
 			document->Close();
-		}
 	}
 
 	void SetPerspective(float distance)

+ 1 - 2
Samples/basic/treeview/src/main.cpp

@@ -115,11 +115,10 @@ int main(int RMLUI_UNUSED_PARAMETER(argc), char** RMLUI_UNUSED_PARAMETER(argv))
 
 	// Load and show the demo document.
 	Rml::Core::ElementDocument* document = context->LoadDocument("basic/treeview/data/treeview.rml");
-	if (document != NULL)
+	if (document)
 	{
 		document->GetElementById("title")->SetInnerRML(document->GetTitle());
 		document->Show();
-		document->RemoveReference();
 	}
 
 	Shell::EventLoop(GameLoop);

+ 2 - 3
Samples/tutorial/datagrid/src/main.cpp

@@ -96,11 +96,10 @@ int main(int RMLUI_UNUSED_PARAMETER(argc), char** RMLUI_UNUSED_PARAMETER(argv))
 
 	// Load and show the tutorial document.
 	Rml::Core::ElementDocument* document = context->LoadDocument("tutorial/datagrid/data/tutorial.rml");
-	document->GetElementById("title")->SetInnerRML(document->GetTitle());
-	if (document != NULL)
+	if (document)
 	{
+		document->GetElementById("title")->SetInnerRML(document->GetTitle());
 		document->Show();
-		document->RemoveReference();
 	}
 
 	Shell::EventLoop(GameLoop);

+ 2 - 3
Samples/tutorial/datagrid_tree/src/main.cpp

@@ -103,11 +103,10 @@ int main(int RMLUI_UNUSED_PARAMETER(argc), char** RMLUI_UNUSED_PARAMETER(argv))
 
 	// Load and show the tutorial document.
 	Rml::Core::ElementDocument* document = context->LoadDocument("tutorial/datagrid_tree/data/tutorial.rml");
-	document->GetElementById("title")->SetInnerRML(document->GetTitle());
-	if (document != NULL)
+	if (document)
 	{
+		document->GetElementById("title")->SetInnerRML(document->GetTitle());
 		document->Show();
-		document->RemoveReference();
 	}
 
 	Shell::EventLoop(GameLoop);

+ 6 - 12
Samples/tutorial/drag/src/Inventory.cpp

@@ -5,7 +5,7 @@
 Inventory::Inventory(const Rml::Core::String& title, const Rml::Core::Vector2f& position, Rml::Core::Context* context)
 {
 	document = context->LoadDocument("tutorial/drag/data/inventory.rml");
-	if (document != NULL)
+	if (document)
 	{
 		document->GetElementById("title")->SetInnerRML(title);
 		document->SetProperty(Rml::Core::PropertyId::Left, Rml::Core::Property(position.x, Rml::Core::Property::PX));
@@ -17,28 +17,22 @@ Inventory::Inventory(const Rml::Core::String& title, const Rml::Core::Vector2f&
 // Destroys the inventory and closes its window.
 Inventory::~Inventory()
 {
-	if (document != NULL)
-	{
-		document->RemoveReference();
+	if (document)
 		document->Close();
-	}
 }
 
 // Adds a brand-new item into this inventory.
 void Inventory::AddItem(const Rml::Core::String& name)
 {
-	if (document == NULL)
+	if (!document)
 		return;
 
 	Rml::Core::Element* content = document->GetElementById("content");
-	if (content == NULL)
+	if (!content)
 		return;
 
 	// Create the new 'icon' element.
-	Rml::Core::Element* icon = Rml::Core::Factory::InstanceElement(content, "icon", "icon", Rml::Core::XMLAttributes());
+	Rml::Core::ElementPtr icon = Rml::Core::Factory::InstanceElement(content, "icon", "icon", Rml::Core::XMLAttributes());
 	icon->SetInnerRML(name);
-	content->AppendChild(icon);
-
-	// Release the initial reference on the element now that the document has it.
-	icon->RemoveReference();
+	content->AppendChild(std::move(icon));
 }

+ 1 - 5
Samples/tutorial/template/src/main.cpp

@@ -88,12 +88,8 @@ int main(int RMLUI_UNUSED_PARAMETER(argc), char** RMLUI_UNUSED_PARAMETER(argv))
 	Shell::LoadFonts("assets/");
 
 	// Load and show the tutorial document.
-	Rml::Core::ElementDocument* document = context->LoadDocument("tutorial/template/data/tutorial.rml");
-	if (document != NULL)
-	{
+	if (Rml::Core::ElementDocument * document = context->LoadDocument("tutorial/template/data/tutorial.rml"))
 		document->Show();
-		document->RemoveReference();
-	}
 
 	Shell::EventLoop(GameLoop);