From ed22df12aa1df8edb503f54b1b7fc64fce1437cb Mon Sep 17 00:00:00 2001
From: jsalmon3 <>
Date: Mon, 17 Jun 2002 21:39:54 +0000
Subject: [PATCH] Changed left and right unit scrolling

---
 src/editor/editloop.cpp      | 10 ++++++----
 src/editor/script_editor.cpp |  1 +
 src/include/editor.h         |  2 ++
 3 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/src/editor/editloop.cpp b/src/editor/editloop.cpp
index d4edf316f..af4520fc0 100644
--- a/src/editor/editloop.cpp
+++ b/src/editor/editloop.cpp
@@ -100,6 +100,7 @@ enum _mode_buttons_ {
 global char** EditorUnitTypes;		/// Sorted editor unit-type table
 
 local int UnitIndex;			/// Unit icon draw index
+global int MaxUnitIndex;		/// Max unit icon draw index
 local int CursorUnitIndex;		/// Unit icon under cursor
 local int SelectedUnitIndex;		/// Unit type to draw
 
@@ -956,8 +957,8 @@ local void EditorCallbackButtonDown(unsigned button __attribute__ ((unused)))
 		&& TheUI.ButtonPanelY + 4 < CursorY
 		&& CursorY < TheUI.ButtonPanelY + 24) {
 
-	    for (i = 9; i-- && UnitIndex;) {
-		--UnitIndex;
+	    if (UnitIndex - 9 >= 0) {
+		UnitIndex -= 9;
 	    }
 	    return;
 	}
@@ -966,8 +967,8 @@ local void EditorCallbackButtonDown(unsigned button __attribute__ ((unused)))
 		&& TheUI.ButtonPanelY + 4 < CursorY
 		&& CursorY < TheUI.ButtonPanelY + 24) {
 
-	    for (i = 9; i-- && EditorUnitTypes[UnitIndex + 1];) {
-		++UnitIndex;
+	    if (UnitIndex + 9 <= MaxUnitIndex) {
+		UnitIndex += 9;
 	    }
 	    return;
 	}
@@ -1552,6 +1553,7 @@ local void CreateEditor(void)
 	for (i = 0; i < n; ++i) {
 	    EditorUnitTypes[i] = UnitTypeWcNames[i];
 	}
+	MaxUnitIndex = n-1;
     }
 
     if( 1 ) {
diff --git a/src/editor/script_editor.cpp b/src/editor/script_editor.cpp
index 37798ee84..56c1098be 100644
--- a/src/editor/script_editor.cpp
+++ b/src/editor/script_editor.cpp
@@ -70,6 +70,7 @@ local SCM CclDefineEditorUnitTypes(SCM list)
     //
     i=gh_length(list);
     EditorUnitTypes=cp=malloc((i+1)*sizeof(char*));
+    MaxUnitIndex = i;
     while( i-- ) {
 	*cp++=gh_scm2newstr(gh_car(list),NULL);
 	list=gh_cdr(list);
diff --git a/src/include/editor.h b/src/include/editor.h
index 09f108fd9..27fa18b62 100644
--- a/src/include/editor.h
+++ b/src/include/editor.h
@@ -40,6 +40,8 @@ extern const char* EditorStartFile;
 
 extern char** EditorUnitTypes;		/// Sorted editor unit-type table
 
+extern int MaxUnitIndex;		/// Max unit icon draw index
+
 /*----------------------------------------------------------------------------
 --	Functions
 ----------------------------------------------------------------------------*/