did some cleaning in CreditsMenu & ScrolledText

(1) CreditsMenu::CreditsMenu changed file-open-mode from "ra" to "r" 

(2) added fclose'ing file in CreditsMenu's ctor

(3) CreditsMenu::m_string_list removed since base-class ScrolledText already has that member,
    made it private in base-class to prevent confusion, since base-class has
    member-func setText to *set* that member ;)
    
    made all other member-vars of ScrolledText private too ..

(4) changed typedef of StringList from 
      typedef std::vector<char*> StringList;
    to 
      typedef std::vector<std::string> StringList;
      
    there was a memory-leak in class CreditsMenu, strings were pushed back
    into StringList via strdup, which (m)allocated memory for the string,
    so we should have freed it by calling free for each item in vector,
    so i choosed the all-inclusive std::string :)
    
    and moved typedef of StringList into class ScrolledText from global scope
    
(5) removed cleaning-up-code for m_string_list from CreditsMenu's dtor, nothing
    to clean for us, since vector's and string's dtor takes care of it
    
(6) changed ScrolledText::setText (StringList const &sl_) param to const reference
    for the sake of efficiency .. we dont want to copy here
    
hope we dont get problems with windows newline-style \r\n .. tried to take care of 
that ;)

git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/trunk/supertuxkart@1223 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
ikework 2007-08-24 07:09:34 +00:00
parent 96509dd941
commit 40799d02bd
4 changed files with 17 additions and 16 deletions

View File

@ -30,35 +30,34 @@ CreditsMenu::CreditsMenu()
{
std::string filename;
StringList credits_text_list;
try
{
filename = loader->getPath("data/CREDITS");
FILE *fd = fopen(filename.c_str(), "ra");
//FIXME: we should change to c++ - filestreams
FILE *fd = fopen(filename.c_str(), "r");
char s[1024];
char *p;
while(fgets(s, 1023, fd))
{
p = strdup(s);
m_string_list.push_back(p);
credits_text_list.push_back(std::string(s));
} // while
fclose(fd);
fd = NULL;
}
catch(std::runtime_error& e)
{
printf(_("Couldn't load '%s'\n"),filename.c_str());
m_string_list.push_back(_("CREDIT file was not installed properly!!"));
m_string_list.push_back(_("Please check 'data/CREDIT'!!"));
credits_text_list.push_back(_("CREDIT file was not installed properly!!"));
credits_text_list.push_back(_("Please check 'data/CREDIT'!!"));
}
setText(m_string_list);
setText(credits_text_list);
} // CreditsMenu
//-----------------------------------------------------------------------------
CreditsMenu::~CreditsMenu()
{
while(m_string_list.size()>0)
{
m_string_list.pop_back();
}
} // ~CreditsMenu
/* EOF */

View File

@ -29,12 +29,11 @@
class CreditsMenu: public ScrolledText
{
protected:
private:
int m_xLeft, m_xRight, m_yBottom, m_yTop;
float m_yPos, m_ySpeed;
int m_numberOfLines;
int m_fontSize;
StringList m_string_list;
public:
CreditsMenu();
~CreditsMenu();

View File

@ -46,7 +46,7 @@ ScrolledText::~ScrolledText()
} // ~ScrolledText
//-----------------------------------------------------------------------------
void ScrolledText::setText(StringList sl_)
void ScrolledText::setText(StringList const &sl_)
{
m_string_list=sl_;
if(m_rect) glDeleteLists(m_rect, 1);
@ -82,7 +82,7 @@ void ScrolledText::update(float dt)
{
if((m_y_pos-i*m_font_size < m_y_top + m_y_bottom ) && m_y_pos-i*m_font_size > -m_font_size)
font_gui->Print(m_string_list[i], 24,
font_gui->Print(m_string_list[i].c_str(), 24,
m_x_left,(int)m_y_pos-i*m_font_size);
}
glMatrixMode(GL_PROJECTION);

View File

@ -25,20 +25,23 @@
#include "base_gui.hpp"
#include "player.hpp"
typedef std::vector<char*> StringList;
class ScrolledText: public BaseGUI
{
protected:
typedef std::vector<std::string> StringList;
private:
int m_x_left, m_x_right, m_y_bottom, m_y_top;
float m_y_pos, m_y_speed;
int m_font_size;
StringList m_string_list;
int m_rect;
public:
ScrolledText();
~ScrolledText();
void setText (StringList sl_);
void setText (StringList const &sl_);
void select ();
void update (float dt);