projects
/
supertux.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
749b9fb
)
- turned some pointer-foo into a std::vector
author
Ingo Ruhnke
<grumbel@gmx.de>
Sun, 11 Apr 2004 17:48:12 +0000
(17:48 +0000)
committer
Ingo Ruhnke
<grumbel@gmx.de>
Sun, 11 Apr 2004 17:48:12 +0000
(17:48 +0000)
SVN-Revision: 488
src/menu.cpp
patch
|
blob
|
history
src/menu.h
patch
|
blob
|
history
diff --git
a/src/menu.cpp
b/src/menu.cpp
index
e2b2e51
..
c70b699
100644
(file)
--- a/
src/menu.cpp
+++ b/
src/menu.cpp
@@
-122,15
+122,14
@@
MenuItem::change_input(const char *text_)
/* Free a menu and all its items */
Menu::~Menu()
{
/* Free a menu and all its items */
Menu::~Menu()
{
- if(
num_items != 0 && item != NULL
)
+ if(
item.size() != 0
)
{
{
- for(
int i = 0; i < num_items
; ++i)
+ for(
unsigned int i = 0; i < item.size()
; ++i)
{
free(item[i].text);
free(item[i].input);
string_list_free(item[i].list);
}
{
free(item[i].text);
free(item[i].input);
string_list_free(item[i].list);
}
- free(item);
}
}
}
}
@@
-140,10
+139,8
@@
Menu::Menu()
pos_y = screen->h/2;
last_menu = 0;
arrange_left = 0;
pos_y = screen->h/2;
last_menu = 0;
arrange_left = 0;
- num_items = 0;
active_item = 0;
last_menu = 0;
active_item = 0;
last_menu = 0;
- item = NULL;
effect.init(false);
}
effect.init(false);
}
@@
-163,17
+160,15
@@
Menu::additem(MenuItemKind kind_, char *text_, int toggle_, Menu* menu_)
void
Menu::additem(MenuItem* pmenu_item)
{
void
Menu::additem(MenuItem* pmenu_item)
{
- ++num_items;
- item = (MenuItem*)realloc(item, sizeof(MenuItem) * num_items);
- memcpy(&item[num_items-1], pmenu_item, sizeof(MenuItem));
- free(pmenu_item);
+ item.push_back(*pmenu_item);
+ delete pmenu_item;
}
/* Process actions done on the menu */
void
Menu::action()
{
}
/* Process actions done on the menu */
void
Menu::action()
{
- if(
num_items != 0 && item != NULL
)
+ if(
item.size() != 0
)
{
switch(menuaction)
{
{
switch(menuaction)
{
@@
-181,11
+176,11
@@
Menu::action()
if (active_item > 0)
--active_item;
else
if (active_item > 0)
--active_item;
else
- active_item =
num_items
-1;
+ active_item =
int(item.size())
-1;
break;
case MENU_ACTION_DOWN:
break;
case MENU_ACTION_DOWN:
- if(active_item <
num_items
-1)
+ if(active_item <
int(item.size())
-1)
++active_item;
else
active_item = 0;
++active_item;
else
active_item = 0;
@@
-297,7
+292,7
@@
Menu::action()
if(menuaction != MENU_ACTION_UP && menuaction != MENU_ACTION_DOWN)
menuaction = MENU_ACTION_DOWN;
if(menuaction != MENU_ACTION_UP && menuaction != MENU_ACTION_DOWN)
menuaction = MENU_ACTION_DOWN;
- if(
num_items
> 1)
+ if(
item.size()
> 1)
action();
}
}
action();
}
}
@@
-305,7
+300,7
@@
Menu::action()
int
Menu::check()
{
int
Menu::check()
{
- if
(num_items != 0 && item != NULL
)
+ if
(item.size() != 0
)
{
if((item[active_item].kind == MN_ACTION
|| item[active_item].kind == MN_TEXTFIELD
{
if((item[active_item].kind == MN_ACTION
|| item[active_item].kind == MN_TEXTFIELD
@@
-477,7
+472,7
@@
int Menu::width()
/* The width of the menu has to be more than the width of the text
with the most characters */
int menu_width = 0;
/* The width of the menu has to be more than the width of the text
with the most characters */
int menu_width = 0;
- for(
int i = 0; i < num_items
; ++i)
+ for(
unsigned int i = 0; i < item.size()
; ++i)
{
int w = strlen(item[i].text) + (item[i].input ? strlen(item[i].input) + 1 : 0) + strlen(string_list_active(item[i].list));
if( w > menu_width )
{
int w = strlen(item[i].text) + (item[i].input ? strlen(item[i].input) + 1 : 0) + strlen(string_list_active(item[i].list));
if( w > menu_width )
@@
-493,7
+488,7
@@
int Menu::width()
int Menu::height()
{
int Menu::height()
{
- return
((num_items) * 24)
;
+ return
item.size() * 24
;
}
/* Draw the current menu. */
}
/* Draw the current menu. */
@@
-505,11
+500,11
@@
Menu::draw()
/* Draw a transparent background */
fillrect(pos_x - menu_width/2,
/* Draw a transparent background */
fillrect(pos_x - menu_width/2,
- pos_y - 24*
num_items
/2 - 10,
+ pos_y - 24*
item.size()
/2 - 10,
menu_width,menu_height + 20,
150,180,200,125);
menu_width,menu_height + 20,
150,180,200,125);
- for(
int i = 0; i < num_items
; ++i)
+ for(
unsigned int i = 0; i < item.size()
; ++i)
{
draw_item(i, menu_width, menu_height);
}
{
draw_item(i, menu_width, menu_height);
}
diff --git
a/src/menu.h
b/src/menu.h
index
46f41b5
..
cfecbee
100644
(file)
--- a/
src/menu.h
+++ b/
src/menu.h
@@
-14,6
+14,7
@@
#define SUPERTUX_MENU_H
#include <SDL.h>
#define SUPERTUX_MENU_H
#include <SDL.h>
+#include <vector>
#include "texture.h"
#include "timer.h"
#include "type.h"
#include "texture.h"
#include "timer.h"
#include "type.h"
@@
-59,7
+60,6
@@
private:
int pos_x;
int pos_y;
int pos_x;
int pos_y;
- int num_items;
Menu* last_menu;
int width();
int height();
Menu* last_menu;
int width();
int height();
@@
-68,7
+68,7
@@
public:
Timer effect;
int arrange_left;
int active_item;
Timer effect;
int arrange_left;
int active_item;
-
MenuItem*
item;
+
std::vector<MenuItem>
item;
static void set_current(Menu* pmenu);
static void set_current(Menu* pmenu);