Maelstrom: Signed/unsigned fixes in preparation for Visual Studio upgrade

https://github.com/libsdl-org/Maelstrom/commit/c8f16045ac68b1486329c4aacbb096d68e1fefde

From c8f16045ac68b1486329c4aacbb096d68e1fefde Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Wed, 24 Apr 2013 22:17:48 -0700
Subject: [PATCH] Signed/unsigned fixes in preparation for Visual Studio
 upgrade

---
 screenlib/UIArea.cpp              |  2 +-
 screenlib/UIBaseElement.cpp       | 12 ++++++------
 screenlib/UIBaseElement.h         | 10 +++++-----
 screenlib/UIContainer.cpp         |  2 +-
 screenlib/UIContainer.h           |  4 ++++
 screenlib/UIElementEditbox.cpp    |  2 +-
 screenlib/UIElementRadio.cpp      |  4 ++--
 screenlib/UIElementThumbstick.cpp |  6 +++---
 screenlib/UIManager.cpp           | 18 +++++++++---------
 screenlib/UIManager.h             |  2 +-
 screenlib/UIPanel.cpp             |  4 ++--
 screenlib/UITemplates.cpp         |  4 ++--
 screenlib/UITexture.cpp           |  2 +-
 utils/array.h                     |  2 +-
 utils/prefs.cpp                   |  2 +-
 15 files changed, 40 insertions(+), 36 deletions(-)

diff --git a/screenlib/UIArea.cpp b/screenlib/UIArea.cpp
index f44c0deb..0f3ec425 100644
--- a/screenlib/UIArea.cpp
+++ b/screenlib/UIArea.cpp
@@ -400,7 +400,7 @@ UIArea::CalculateAnchor(bool triggerRectChanged)
 void
 UIArea::OnRectChanged()
 {
-	for (int i = 0; i < m_anchoredAreas.length(); ++i) {
+	for (unsigned int i = 0; i < m_anchoredAreas.length(); ++i) {
 		m_anchoredAreas[i]->CalculateAnchor(true);
 	}
 }
diff --git a/screenlib/UIBaseElement.cpp b/screenlib/UIBaseElement.cpp
index 2bf3f3cb..095e2faf 100644
--- a/screenlib/UIBaseElement.cpp
+++ b/screenlib/UIBaseElement.cpp
@@ -62,7 +62,7 @@ UIBaseElement::~UIBaseElement()
 {
 	SDL_free(m_name);
 
-	for (int i = 0; i < m_elements.length(); ++i) {
+	for (unsigned int i = 0; i < m_elements.length(); ++i) {
 		delete m_elements[i];
 	}
 }
@@ -108,7 +108,7 @@ UIBaseElement::Load(rapidxml::xml_node<> *node, const UITemplates *templates)
 void
 UIBaseElement::LoadData(Prefs *prefs)
 {
-	for (int i = 0; i < m_elements.length(); ++i) {
+	for (unsigned int i = 0; i < m_elements.length(); ++i) {
 		m_elements[i]->LoadData(prefs);
 	}
 }
@@ -116,7 +116,7 @@ UIBaseElement::LoadData(Prefs *prefs)
 void
 UIBaseElement::SaveData(Prefs *prefs)
 {
-	for (int i = 0; i < m_elements.length(); ++i) {
+	for (unsigned int i = 0; i < m_elements.length(); ++i) {
 		m_elements[i]->SaveData(prefs);
 	}
 }
@@ -174,7 +174,7 @@ UIBaseElement::SetParentDisabled(bool disabled)
 void
 UIBaseElement::UpdateDisabledState()
 {
-	for (int i = 0; i < m_elements.length(); ++i) {
+	for (unsigned int i = 0; i < m_elements.length(); ++i) {
 		m_elements[i]->SetParentDisabled(IsDisabled());
 	}
 }
@@ -184,7 +184,7 @@ UIBaseElement::SetDrawLevel(DRAWLEVEL drawLevel)
 {
 	m_drawLevel = drawLevel;
 
-	for (int i = 0; i < m_elements.length(); ++i) {
+	for (unsigned int i = 0; i < m_elements.length(); ++i) {
 		m_elements[i]->SetDrawLevel(drawLevel);
 	}
 }
@@ -192,7 +192,7 @@ UIBaseElement::SetDrawLevel(DRAWLEVEL drawLevel)
 void
 UIBaseElement::Draw(DRAWLEVEL drawLevel)
 {
-	for (int i = 0; i < m_elements.length(); ++i) {
+	for (unsigned int i = 0; i < m_elements.length(); ++i) {
 		if (m_elements[i]->IsShown()) {
 			m_elements[i]->Draw(drawLevel);
 		}
diff --git a/screenlib/UIBaseElement.h b/screenlib/UIBaseElement.h
index 9c61c3ee..692b3aca 100644
--- a/screenlib/UIBaseElement.h
+++ b/screenlib/UIBaseElement.h
@@ -91,7 +91,7 @@ class UIBaseElement : public UIArea
 		m_elements.add(element);
 	}
 	void GetElements(array<UIBaseElement*> &elements) {
-		for (int i = 0; i < m_elements.length(); ++i) {
+		for (unsigned int i = 0; i < m_elements.length(); ++i) {
 			elements.add(m_elements[i]);
 		}
 	}
@@ -99,7 +99,7 @@ class UIBaseElement : public UIArea
 	T *GetElement(const char *name) {
 		// Do a breadth first search
 		array<UIBaseElement*> lists[2];
-		int i, current = 0;
+		unsigned int i, current = 0;
 
 		GetElements(lists[current]);
 		while (lists[current].length() > 0) {
@@ -127,7 +127,7 @@ class UIBaseElement : public UIArea
 	}
 	template <typename T>
 	T *FindElement(UIBaseElement *start = NULL) {
-		int i, j;
+		unsigned int i, j;
 		if (start) {
 			// Find the starting element
 			for (i = 0; i < m_elements.length(); ++i) {
@@ -158,7 +158,7 @@ class UIBaseElement : public UIArea
 	}
 	template <typename T>
 	void FindElements(array<T*> &elements) {
-		for (int i = 0; i < m_elements.length(); ++i) {
+		for (unsigned int i = 0; i < m_elements.length(); ++i) {
 			UIBaseElement *element = m_elements[i];
 			if (element->IsA(T::GetType())) {
 				elements.add((T*)element);
@@ -187,7 +187,7 @@ class UIBaseElement : public UIArea
 	virtual void OnRectChanged() {
 		UIArea::OnRectChanged();
 
-		for (int i = 0; i < m_elements.length(); ++i) {
+		for (unsigned int i = 0; i < m_elements.length(); ++i) {
 			UIBaseElement *element = m_elements[i];
 			element->AutoSize(Width(), Height(), true);
 		}
diff --git a/screenlib/UIContainer.cpp b/screenlib/UIContainer.cpp
index 44d5b290..bb228b60 100644
--- a/screenlib/UIContainer.cpp
+++ b/screenlib/UIContainer.cpp
@@ -66,7 +66,7 @@ UIContainer::LayoutChildren()
 	AnchorLocation anchorLocation;
 	int offsetX = 0;
 	int offsetY = 0;
-	int i;
+	unsigned int i;
 
 	if (m_layoutInProgress) {
 		return;
diff --git a/screenlib/UIContainer.h b/screenlib/UIContainer.h
index 381c4630..7e5c2f24 100644
--- a/screenlib/UIContainer.h
+++ b/screenlib/UIContainer.h
@@ -51,6 +51,10 @@ DECLARE_TYPESAFE_CLASS(UIElement)
 	override void OnChildRectChanged(UIBaseElement *child) {
 		LayoutChildren();
 	}
+    
+    int Spacing() { return m_spacing; }
+    int BorderSpacing() { return m_borderSpacing; }
+    
 
 protected:
 	LAYOUT_TYPE m_layoutType;
diff --git a/screenlib/UIElementEditbox.cpp b/screenlib/UIElementEditbox.cpp
index 2d8a6a10..c9c072ba 100644
--- a/screenlib/UIElementEditbox.cpp
+++ b/screenlib/UIElementEditbox.cpp
@@ -142,7 +142,7 @@ UIElementEditbox::SetFocus(bool focus)
 
 		// Take focus away from other editboxes
 		m_parent->FindElements<UIElementEditbox>(editboxes);
-		for (int i = 0; i < editboxes.length(); ++i) {
+		for (unsigned int i = 0; i < editboxes.length(); ++i) {
 			if (editboxes[i] != this) {
 				editboxes[i]->SetFocus(false);
 			}
diff --git a/screenlib/UIElementRadio.cpp b/screenlib/UIElementRadio.cpp
index a94d4029..ff21f4c4 100644
--- a/screenlib/UIElementRadio.cpp
+++ b/screenlib/UIElementRadio.cpp
@@ -77,7 +77,7 @@ UIElementRadioGroup::GetRadioButton(int id)
 {
 	UIElementRadioButton *button;
 
-	for (int i = 0; i < m_elements.length(); ++i) {
+	for (unsigned int i = 0; i < m_elements.length(); ++i) {
 		if (!m_elements[i]->IsA(UIElementRadioButton::GetType())) {
 			continue;
 		}
@@ -104,7 +104,7 @@ UIElementRadioGroup::SetValue(int value)
 	m_value = value;
 
 	FindElements<UIElementRadioButton>(buttons);
-	for (int i = 0; i < buttons.length(); ++i) {
+	for (unsigned int i = 0; i < buttons.length(); ++i) {
 		if (buttons[i]->GetID() == value) {
 			buttons[i]->SetChecked(true);
 		} else {
diff --git a/screenlib/UIElementThumbstick.cpp b/screenlib/UIElementThumbstick.cpp
index 9ba15c09..acd48e4e 100644
--- a/screenlib/UIElementThumbstick.cpp
+++ b/screenlib/UIElementThumbstick.cpp
@@ -40,7 +40,7 @@ UIElementThumbstick::UIElementThumbstick(UIBaseElement *parent, const char *name
 
 UIElementThumbstick::~UIElementThumbstick()
 {
-	for (int i = 0; i < m_actions.length(); ++i) {
+	for (unsigned int i = 0; i < m_actions.length(); ++i) {
 		if (m_actions[i].action_enter) {
 			SDL_free(m_actions[i].action_enter);
 		}
@@ -148,7 +148,7 @@ UIElementThumbstick::HandleEvent(const SDL_Event &event)
 			    GetTouchPosition(event, x, y)) {
 				MoveCenter(x, y);
 			}
-			for (int i = 0; i < m_actions.length(); ++i) {
+			for (unsigned int i = 0; i < m_actions.length(); ++i) {
 				SetActionActive(i, false);
 			}
 			m_finger = 0;
@@ -168,7 +168,7 @@ UIElementThumbstick::MoveCenter(int x, int y)
 void
 UIElementThumbstick::HandleFinger(float angle, float distance)
 {
-	for (int i = 0; i < m_actions.length(); ++i) {
+	for (unsigned int i = 0; i < m_actions.length(); ++i) {
 		SetActionActive(i, ShouldActivateAction(i, angle, distance));
 	}
 }
diff --git a/screenlib/UIManager.cpp b/screenlib/UIManager.cpp
index 8801cf09..42b40933 100644
--- a/screenlib/UIManager.cpp
+++ b/screenlib/UIManager.cpp
@@ -64,7 +64,7 @@ UIManager::Shutdown()
 void
 UIManager::ClearLoadPath()
 {
-	for (int i = 0; i < m_loadPath.length(); ++i) {
+	for (unsigned int i = 0; i < m_loadPath.length(); ++i) {
 		SDL_free(m_loadPath[i]);
 	}
 	m_loadPath.clear();
@@ -81,7 +81,7 @@ UIManager::LoadTemplates(const char *file)
 {
 	char path[1024];
 
-	for (int i = 0; i < m_loadPath.length(); ++i) {
+	for (unsigned int i = 0; i < m_loadPath.length(); ++i) {
 		SDL_snprintf(path, sizeof(path), "%s/%s", m_loadPath[i], file);
 		if (m_templates.Load(path)) {
 			return true;
@@ -103,7 +103,7 @@ UIManager::LoadPanel(const char *name)
 		rapidxml::xml_document<> doc;
 
 		bool loaded = false;
-		for (int i = 0; i < m_loadPath.length(); ++i) {
+		for (unsigned int i = 0; i < m_loadPath.length(); ++i) {
 			SDL_snprintf(file, sizeof(file), "%s/%s.xml", m_loadPath[i], name);
 			if (LoadXML(file, buffer, doc)) {
 				loaded = true;
@@ -156,7 +156,7 @@ UIManager::LoadPanel(const char *name)
 UIPanel *
 UIManager::GetPanel(const char *name, bool allowLoad)
 {
-	for (int i = 0; i < m_panels.length(); ++i) {
+	for (unsigned int i = 0; i < m_panels.length(); ++i) {
 		if (strcmp(name, m_panels[i]->GetName()) == 0) {
 			return m_panels[i];
 		}
@@ -182,7 +182,7 @@ UIManager::GetFullscreenPanel()
 UIPanel *
 UIManager::GetNextPanel(UIPanel *panel)
 {
-	for (int i = 0; i < m_visible.length(); ++i) {
+	for (unsigned int i = 0; i < m_visible.length(); ++i) {
 		if (m_visible[i] == panel) {
 			if (i+1 < m_visible.length()) {
 				return m_visible[i+1];
@@ -197,7 +197,7 @@ UIManager::GetNextPanel(UIPanel *panel)
 UIPanel *
 UIManager::GetPrevPanel(UIPanel *panel)
 {
-	for (int i = 0; i < m_visible.length(); ++i) {
+	for (unsigned int i = 0; i < m_visible.length(); ++i) {
 		if (m_visible[i] == panel) {
 			if (i > 0) {
 				return m_visible[i-1];
@@ -221,7 +221,7 @@ UIManager::GetCurrentPanel()
 bool
 UIManager::IsShown(const char *name) const
 {
-	for (int i = 0; i < m_panels.length(); ++i) {
+	for (unsigned int i = 0; i < m_panels.length(); ++i) {
 		if (strcmp(name, m_panels[i]->GetName()) == 0) {
 			return m_visible.find(m_panels[i]);
 		}
@@ -363,7 +363,7 @@ UIManager::CheckCondition(const char *condition)
 void
 UIManager::Poll()
 {
-	int i;
+	unsigned int i;
 
 	for (i = 0; i < m_visible.length(); ++i) {
 		UIPanel *panel = m_visible[i];
@@ -383,7 +383,7 @@ UIManager::Poll()
 void
 UIManager::Draw(bool fullUpdate)
 {
-	int i;
+	unsigned int i;
 
 	// Run the tick before we draw in case it changes drawing state
 	for (i = 0; i < m_visible.length(); ++i) {
diff --git a/screenlib/UIManager.h b/screenlib/UIManager.h
index 8d52fd11..c00f06f1 100644
--- a/screenlib/UIManager.h
+++ b/screenlib/UIManager.h
@@ -127,7 +127,7 @@ class UIManager : public UIArea, public UIFontInterface, public UIImageInterface
 	virtual void OnRectChanged() {
 		UIArea::OnRectChanged();
 
-		for (int i = 0; i < m_panels.length(); ++i) {
+		for (unsigned int i = 0; i < m_panels.length(); ++i) {
 			UIPanel *panel = m_panels[i];
 			panel->AutoSize(Width(), Height(), true);
 		}
diff --git a/screenlib/UIPanel.cpp b/screenlib/UIPanel.cpp
index b687d62b..f023e28b 100644
--- a/screenlib/UIPanel.cpp
+++ b/screenlib/UIPanel.cpp
@@ -130,7 +130,7 @@ UIPanel::Hide()
 	// Clear focus on editboxes
 	array<UIElementEditbox*> editboxes;
 	FindElements<UIElementEditbox>(editboxes);
-	for (int i = 0; i < editboxes.length(); ++i) {
+	for (unsigned int i = 0; i < editboxes.length(); ++i) {
 		editboxes[i]->SetFocus(false);
 	}
 
@@ -153,7 +153,7 @@ UIPanel::Hide()
 void
 UIPanel::HideAll()
 {
-	for (int i = 0; i < m_elements.length(); ++i) {
+	for (unsigned int i = 0; i < m_elements.length(); ++i) {
 		m_elements[i]->Hide();
 	}
 }
diff --git a/screenlib/UITemplates.cpp b/screenlib/UITemplates.cpp
index 15270990..af1d3633 100644
--- a/screenlib/UITemplates.cpp
+++ b/screenlib/UITemplates.cpp
@@ -37,7 +37,7 @@ UITemplates::~UITemplates()
 	if (m_hashTable) {
 		hash_destroy(m_hashTable);
 	}
-	for (int i = 0; i < m_data.length(); ++i) {
+	for (unsigned int i = 0; i < m_data.length(); ++i) {
 		SDL_free(m_data[i]);
 	}
 }
@@ -120,7 +120,7 @@ UITemplates::HashTable_Hash(const void *_key, void *data)
 	register unsigned hash = 5381;
 
 	while (*key) {
-		hash = ((hash << 5) + hash) ^ toupper(*key);
+		hash = ((hash << 5) + hash) ^ SDL_toupper(*key);
 		++key;
 	}
 	return hash;
diff --git a/screenlib/UITexture.cpp b/screenlib/UITexture.cpp
index a2549876..9307a3a2 100644
--- a/screenlib/UITexture.cpp
+++ b/screenlib/UITexture.cpp
@@ -109,7 +109,7 @@ UITexture::Draw(FrameBuf *screen, int x, int y, int w, int h)
 	if (m_stretch) {
 		SDL_Rect dstAreas[NUM_STRETCH_AREAS];
 
-		CalculateStretchAreas(m_stretchCornerSize / m_scale, x, y, w, h, dstAreas);
+		CalculateStretchAreas((int)(m_stretchCornerSize / m_scale), x, y, w, h, dstAreas);
 		// Draw the grid
 		for (int i = 0; i < NUM_STRETCH_AREAS; ++i) {
 			const SDL_Rect *src, *dst;
diff --git a/utils/array.h b/utils/array.h
index b7fe9050..67a2fd37 100644
--- a/utils/array.h
+++ b/utils/array.h
@@ -73,7 +73,7 @@ class array
 	bool empty() const {
 		return length() == 0;
 	}
-	int length() const {
+	unsigned int length() const {
 		return m_len;
 	}
 	const T& operator[](unsigned index) const {
diff --git a/utils/prefs.cpp b/utils/prefs.cpp
index 9898a53c..85f3748b 100644
--- a/utils/prefs.cpp
+++ b/utils/prefs.cpp
@@ -124,7 +124,7 @@ Prefs::Save()
 	}
 	qsort(&keys[0], keys.length(), sizeof(key), sort_keys);
 	
-	for (int i = 0; i < keys.length(); ++i) {
+	for (unsigned int i = 0; i < keys.length(); ++i) {
 		hash_find(m_values, keys[i], (const void **)&value);
 		if (!writeString(fp, keys[i]) ||
 		    !writeString(fp, "=") ||