about summary refs log tree commit diff
diff options
context:
space:
mode:
authorxalduin <xalduin@gmail.com>2010-06-01 21:36:10 -0400
committerxalduin <xalduin@gmail.com>2010-06-01 21:36:10 -0400
commit4d35f63174a8304ad2b4c1178f1fe10e3f84ae14 (patch)
treec9cd2baab752dabf0c396921e06be97c117de14d
parent7454cec57e5de0983464991145979dc3c885d39e (diff)
downloadzcatch-4d35f63174a8304ad2b4c1178f1fe10e3f84ae14.tar.gz
zcatch-4d35f63174a8304ad2b4c1178f1fe10e3f84ae14.zip
Images are now sorted in the editor
-rw-r--r--src/game/editor/ed_editor.cpp40
1 files changed, 33 insertions, 7 deletions
diff --git a/src/game/editor/ed_editor.cpp b/src/game/editor/ed_editor.cpp
index 0a5c22d3..76fd1096 100644
--- a/src/game/editor/ed_editor.cpp
+++ b/src/game/editor/ed_editor.cpp
@@ -1820,7 +1820,33 @@ static int CompareImageName(const void *Object1, const void *Object2)
 
 void CEditor::RenderImages(CUIRect ToolBox, CUIRect ToolBar, CUIRect View)
 {
-	qsort(m_Map.m_lImages.base_ptr(), m_Map.m_lImages.size(), sizeof(CEditorImage*), CompareImageName);
+	array<CEditorImage*> lImages = array<CEditorImage*>(m_Map.m_lImages);
+	int aIndexes[lImages.size()];
+
+	bool Sorted = true;
+	for(int i = 1; i < lImages.size(); i++)
+		if( str_comp(lImages[i]->m_aName, lImages[i-1]->m_aName) < 0 )
+		{
+			Sorted = false;
+			break;
+		}
+
+	if(!Sorted)
+	{
+		qsort(lImages.base_ptr(), lImages.size(), sizeof(CEditorImage*), CompareImageName);
+
+		// lImages now contains a sorted version of m_Map.m_lImages
+		// Now updating aIndex such that
+		// aIndex[SortedIndexOf_lImages] = UnsortedIndexOf_m_Map.m_lImages
+
+		for(int NewRef = 0; NewRef < lImages.size(); NewRef++)
+			for(int OldRef = 0; OldRef < m_Map.m_lImages.size(); OldRef++)
+				if( m_Map.m_lImages[OldRef] == lImages[NewRef] )
+				{
+					aIndexes[NewRef] = OldRef;
+					break;
+				}
+	}
 
 	for(int e = 0; e < 2; e++) // two passes, first embedded, then external
 	{
@@ -1831,19 +1857,19 @@ void CEditor::RenderImages(CUIRect ToolBox, CUIRect ToolBar, CUIRect View)
 		else
 			UI()->DoLabel(&Slot, "External", 12.0f, 0);
 
-		for(int i = 0; i < m_Map.m_lImages.size(); i++)
+		for(int i = 0; i < lImages.size(); i++)
 		{
-			if((e && !m_Map.m_lImages[i]->m_External) ||
-				(!e && m_Map.m_lImages[i]->m_External))
+			if((e && !lImages[i]->m_External) ||
+				(!e && lImages[i]->m_External))
 			{
 				continue;
 			}
 
 			char aBuf[128];
-			str_copy(aBuf, m_Map.m_lImages[i]->m_aName, sizeof(aBuf));
+			str_copy(aBuf, lImages[i]->m_aName, sizeof(aBuf));
 			ToolBox.HSplitTop(12.0f, &Slot, &ToolBox);
 
-			if(int Result = DoButton_Editor(&m_Map.m_lImages[i], aBuf, m_SelectedImage == i, &Slot,
+			if(int Result = DoButton_Editor(&m_Map.m_lImages[aIndexes[i]], aBuf, m_SelectedImage == i, &Slot,
 				BUTTON_CONTEXT, "Select image"))
 			{
 				m_SelectedImage = i;
@@ -1864,7 +1890,7 @@ void CEditor::RenderImages(CUIRect ToolBox, CUIRect ToolBar, CUIRect View)
 					r.w = r.h;
 				else
 					r.h = r.w;
-				Graphics()->TextureSet(m_Map.m_lImages[i]->m_TexId);
+				Graphics()->TextureSet(m_Map.m_lImages[aIndexes[i]]->m_TexId);
 				Graphics()->BlendNormal();
 				Graphics()->QuadsBegin();
 				IGraphics::CQuadItem QuadItem(r.x, r.y, r.w, r.h);