]> git.vomp.tv Git - vompclient-marten.git/commitdiff
Got rid of 500 entry limit by converting options to a vector
authorChris Tallon <chris@vomp.tv>
Fri, 19 Aug 2005 18:35:50 +0000 (18:35 +0000)
committerChris Tallon <chris@vomp.tv>
Fri, 19 Aug 2005 18:35:50 +0000 (18:35 +0000)
wselectlist.cc
wselectlist.h

index 101658c7b8fdcba33d1ca529e0af285a2b683c30..a0734f9108e5bb1ec9a836870499bad23ca60faa 100644 (file)
@@ -22,7 +22,6 @@
 
 WSelectList::WSelectList()
 {
-  numOptions = 0;
   selectedOption = 0;
   topOption = 0;
   numOptionsDisplayable = 0;
@@ -36,12 +35,13 @@ WSelectList::~WSelectList()
 
 void WSelectList::clear()
 {
-  for (int i = 0; i < numOptions; i++)
+  int vsize = options.size();
+  for (int i = 0; i < vsize; i++)
   {
     delete[] options[i];
   }
+  options.clear();
 
-  numOptions = 0;
   selectedOption = 0;
   topOption = 0;
   numOptionsDisplayable = 0;
@@ -51,7 +51,7 @@ void WSelectList::clear()
 void WSelectList::hintSetCurrent(int index)
 {
   selectedOption = index;
-  if (selectedOption >= numOptions) selectedOption = numOptions - 1;
+  if (selectedOption >= options.size()) selectedOption = options.size() - 1;
 }
 
 void WSelectList::hintSetTop(int index)
@@ -61,12 +61,11 @@ void WSelectList::hintSetTop(int index)
 
 int WSelectList::addOption(char* text, int selected)
 {
-  int thisNewOption = numOptions;
+  int thisNewOption = options.size();
   int length = strlen(text);
-  options[thisNewOption] = new char[length + 1];
+  options.push_back(new char[length + 1]);
   strcpy(options[thisNewOption], text);
   if (selected) selectedOption = thisNewOption;
-  numOptions++;
   return thisNewOption;
 }
 
@@ -92,9 +91,9 @@ void WSelectList::draw()
   fillColour(Colour::VIEWBACKGROUND);
 
   int ypos = 5;
-  for (int i = topOption; i < (topOption + numOptionsDisplayable); i++)
+  for (UINT i = topOption; i < (topOption + numOptionsDisplayable); i++)
   {
-    if (i == numOptions) return;
+    if (i == options.size()) return;
     if ((ypos + ySeperation) > height) break;
 
     if (i == selectedOption)
@@ -149,13 +148,13 @@ void WSelectList::up()
   }
   else
   {
-    selectedOption = numOptions - 1;
+    selectedOption = options.size() - 1;
   }
 }
 
 void WSelectList::down()
 {
-  if (selectedOption < numOptions - 1)
+  if (selectedOption < options.size() - 1)
   {
     selectedOption++;
   }
@@ -175,7 +174,7 @@ void WSelectList::pageUp()
 
 void WSelectList::pageDown()
 {
-  if ((topOption + numOptionsDisplayable) >= numOptions) return;
+  if ((topOption + numOptionsDisplayable) >= options.size()) return;
 
   topOption += numOptionsDisplayable;
   selectedOption = topOption;
@@ -188,13 +187,13 @@ int WSelectList::getTopOption()
 
 int WSelectList::getNumOptions()
 {
-  return numOptions;
+  return options.size();
 }
 
 int WSelectList::getBottomOption()
 {
-  int retval = topOption + numOptionsDisplayable;
-  if (retval > numOptions) return numOptions;
+  UINT retval = topOption + numOptionsDisplayable;
+  if (retval > options.size()) return options.size();
   else return retval;
 }
 
index 23c6caebeb0d21a7a2b4044e5528504a56f03f85..7c48e6a601faf0bf7bfd10416b5b7fe67b5a0d07 100644 (file)
 #include <stdio.h>
 #include <string.h>
 
+#include <vector>
+
+#include "defines.h"
 #include "box.h"
 #include "colour.h"
 
+using namespace std;
+
 class WSelectList : public Box
 {
   public:
@@ -54,13 +59,13 @@ class WSelectList : public Box
   private:
     void drawOptionLine(char* text, int xpos, int ypos, Colour& colour);
 
-    char* options[500];
-    int numOptions;
-    int selectedOption;
-    int topOption;
-    int numOptionsDisplayable;
+    vector<char*> options;
+    UINT selectedOption;
+    UINT topOption;
+    UINT numOptionsDisplayable;
     int columns[10];
     int numColumns;
+
 };
 
 #endif