[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Pingus-CVS] r2689 - in branches/pingus_sdl/src: . actions components ed
From: |
grumbel at BerliOS |
Subject: |
[Pingus-CVS] r2689 - in branches/pingus_sdl/src: . actions components editor gui worldobjs |
Date: |
Thu, 18 Jan 2007 13:31:00 +0100 |
Author: grumbel
Date: 2007-01-18 13:30:57 +0100 (Thu, 18 Jan 2007)
New Revision: 2689
Added:
branches/pingus_sdl/src/string_util.cpp
branches/pingus_sdl/src/string_util.hpp
Modified:
branches/pingus_sdl/src/SConscript
branches/pingus_sdl/src/actions/bridger.cpp
branches/pingus_sdl/src/blitter.cpp
branches/pingus_sdl/src/capture_rectangle.cpp
branches/pingus_sdl/src/components/action_button.cpp
branches/pingus_sdl/src/components/time_display.cpp
branches/pingus_sdl/src/editor/context_menu.cpp
branches/pingus_sdl/src/gui/cursor.cpp
branches/pingus_sdl/src/gui/display.cpp
branches/pingus_sdl/src/result_screen.cpp
branches/pingus_sdl/src/savegame.cpp
branches/pingus_sdl/src/server_event.cpp
branches/pingus_sdl/src/start_screen.cpp
branches/pingus_sdl/src/stat_manager.cpp
branches/pingus_sdl/src/worldobjs/exit.cpp
Log:
- added stringutil class
Modified: branches/pingus_sdl/src/SConscript
===================================================================
--- branches/pingus_sdl/src/SConscript 2007-01-18 03:52:35 UTC (rev 2688)
+++ branches/pingus_sdl/src/SConscript 2007-01-18 12:30:57 UTC (rev 2689)
@@ -244,6 +244,7 @@
'state_sprite.cpp',
'story_screen.cpp',
'string_format.cpp',
+'string_util.cpp',
'math/origin.cpp',
'math/rect.cpp',
'system.cpp',
Modified: branches/pingus_sdl/src/actions/bridger.cpp
===================================================================
--- branches/pingus_sdl/src/actions/bridger.cpp 2007-01-18 03:52:35 UTC (rev
2688)
+++ branches/pingus_sdl/src/actions/bridger.cpp 2007-01-18 12:30:57 UTC (rev
2689)
@@ -27,6 +27,7 @@
#include "../world.hpp"
#include "../worldobj.hpp"
#include "../gettext.h"
+#include "../string_util.hpp"
#include "bridger.hpp"
namespace Actions {
@@ -36,7 +37,7 @@
mode(B_BUILDING),
bricks(MAX_BRICKS),
block_build(false),
- name(_("Bridger") + std::string(" (")) ////+ CL_String::to(bricks) + ")")
+ name(_("Bridger") + std::string(" (" + StringUtil::to_string(bricks) +
")"))
{
walk_sprite.load (Direction::LEFT, Resource::load_sprite("pingus/player" +
pingu->get_owner_str() + "/bridger_walk/left"));
@@ -213,7 +214,7 @@
Bridger::place_a_brick()
{
bricks--;
- name = _("Bridger") + std::string(" (");//// + CL_String::to(bricks) + ")";
+ name = _("Bridger") + std::string(" (") + StringUtil::to_string(bricks) +
")";
if (bricks < 4)
Sound::PingusSound::play_sound("ting");
Modified: branches/pingus_sdl/src/blitter.cpp
===================================================================
--- branches/pingus_sdl/src/blitter.cpp 2007-01-18 03:52:35 UTC (rev 2688)
+++ branches/pingus_sdl/src/blitter.cpp 2007-01-18 12:30:57 UTC (rev 2689)
@@ -27,6 +27,7 @@
#include <ClanLib/Display/pixel_buffer.h>
#include <ClanLib/Display/pixel_format.h>
+#include "string_util.hpp"
#include "pingus_error.hpp"
#include "globals.hpp"
#include "math.hpp"
@@ -57,7 +58,7 @@
put_surface_32bit(canvas, provider, x, y);
break;
default:
- PingusError::raise("Blitter:put_surface:Unknown color depth: " +
CL_String::to(provider.get_format().get_depth()));
+ PingusError::raise("Blitter:put_surface:Unknown color depth: " +
StringUtil::to_string(provider.get_format().get_depth()));
break;
}
}
Modified: branches/pingus_sdl/src/capture_rectangle.cpp
===================================================================
--- branches/pingus_sdl/src/capture_rectangle.cpp 2007-01-18 03:52:35 UTC
(rev 2688)
+++ branches/pingus_sdl/src/capture_rectangle.cpp 2007-01-18 12:30:57 UTC
(rev 2689)
@@ -18,6 +18,7 @@
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "math/vector3f.hpp"
+#include "string_util.hpp"
#include "pingu.hpp"
#include "resource.hpp"
#include "capture_rectangle.hpp"
@@ -101,7 +102,7 @@
if (maintainer_mode)
{
action_str += " Id: ";
- ////action_str += CL_String::to(pingu->get_id());
+ action_str += StringUtil::to_string(pingu->get_id());
}
}
}
Modified: branches/pingus_sdl/src/components/action_button.cpp
===================================================================
--- branches/pingus_sdl/src/components/action_button.cpp 2007-01-18
03:52:35 UTC (rev 2688)
+++ branches/pingus_sdl/src/components/action_button.cpp 2007-01-18
12:30:57 UTC (rev 2689)
@@ -26,6 +26,7 @@
#include "../display/drawing_context.hpp"
#include "../gui/display.hpp"
#include "../fonts.hpp"
+#include "../string_util.hpp"
#include "../math/vector3f.hpp"
@@ -145,10 +146,8 @@
}
else
{
-#if 0
- std::string str = CL_String::to(action_holder->get_available(name));
+ std::string str =
StringUtil::to_string(action_holder->get_available(name));
gc.print_center(myfont, (float)x_pos + 46, (float)y_pos + 5, str);
-#endif
}
}
Modified: branches/pingus_sdl/src/components/time_display.cpp
===================================================================
--- branches/pingus_sdl/src/components/time_display.cpp 2007-01-18 03:52:35 UTC
(rev 2688)
+++ branches/pingus_sdl/src/components/time_display.cpp 2007-01-18 12:30:57 UTC
(rev 2689)
@@ -27,6 +27,7 @@
#include "../true_server.hpp"
#include "../client.hpp"
#include "../game_time.hpp"
+#include "../string_util.hpp"
#include "../fonts.hpp"
#include "time_display.hpp"
@@ -56,8 +57,8 @@
time_string = GameTime::ticks_to_realtime_string(time_value);
else
{
- //// time_value = server->get_world()->get_time_passed();
- //// time_string = CL_String::to(time_value);
+ time_value = server->get_world()->get_time_passed();
+ time_string = StringUtil::to_string(time_value);
}
gc.print_right(font, static_cast<float>(Display::get_width() - 30),
Modified: branches/pingus_sdl/src/editor/context_menu.cpp
===================================================================
--- branches/pingus_sdl/src/editor/context_menu.cpp 2007-01-18 03:52:35 UTC
(rev 2688)
+++ branches/pingus_sdl/src/editor/context_menu.cpp 2007-01-18 12:30:57 UTC
(rev 2689)
@@ -22,6 +22,7 @@
#include "editor_viewport.hpp"
#include "editor_screen.hpp"
#include "../gui/gui_manager.hpp"
+#include "../string_util.hpp"
#include "../fonts.hpp"
namespace Editor {
@@ -122,14 +123,14 @@
objs[i]->set_modifier(actions[selected_action_offset].parameter);
break;
case (SET_OWNER) :
-
////objs[i]->set_owner(CL_String::to_int(actions[selected_action_offset].parameter));
+
objs[i]->set_owner(StringUtil::to<int>(actions[selected_action_offset].parameter));
break;
case (SET_DIRECTION) :
objs[i]->set_direction(actions[selected_action_offset].parameter);
break;
case (SET_Z_POS) :
-
////objs[i]->set_pos(Vector3f(objs[i]->get_pos().x, objs[i]->get_pos().y,
- ////
(float)CL_String::to_int(actions[selected_action_offset].parameter)));
+
objs[i]->set_pos(Vector3f(objs[i]->get_pos().x, objs[i]->get_pos().y,
+
(float)StringUtil::to<int>(actions[selected_action_offset].parameter)));
objs[i]->set_orig_pos(objs[i]->get_pos());
break;
default :
Modified: branches/pingus_sdl/src/gui/cursor.cpp
===================================================================
--- branches/pingus_sdl/src/gui/cursor.cpp 2007-01-18 03:52:35 UTC (rev
2688)
+++ branches/pingus_sdl/src/gui/cursor.cpp 2007-01-18 12:30:57 UTC (rev
2689)
@@ -24,7 +24,7 @@
Cursor::Cursor(const std::string& ident)
-// : sprite(Resource::load_sprite(ident))
+ : sprite(Resource::load_sprite(ident))
{
}
@@ -41,9 +41,9 @@
void
Cursor::on_event()
{
- ////const Input::Pointer* pointer =
Input::Controller::get_current()->get_pointer();
- // sprite.draw(pointer->get_x_pos (),
- // pointer->get_y_pos ());
+ int x,y;
+ SDL_GetMouseState(&x, &y);
+ sprite.draw(x, y, Display::get_screen());
}
Modified: branches/pingus_sdl/src/gui/display.cpp
===================================================================
--- branches/pingus_sdl/src/gui/display.cpp 2007-01-18 03:52:35 UTC (rev
2688)
+++ branches/pingus_sdl/src/gui/display.cpp 2007-01-18 12:30:57 UTC (rev
2689)
@@ -64,7 +64,6 @@
(*i)->on_event();
}
- ////CL_Display::flip();
SDL_Flip(screen);
}
Modified: branches/pingus_sdl/src/result_screen.cpp
===================================================================
--- branches/pingus_sdl/src/result_screen.cpp 2007-01-18 03:52:35 UTC (rev
2688)
+++ branches/pingus_sdl/src/result_screen.cpp 2007-01-18 12:30:57 UTC (rev
2689)
@@ -29,6 +29,7 @@
#include "fonts.hpp"
#include "game_session.hpp"
#include "system.hpp"
+#include "string_util.hpp"
#include "sound/sound.hpp"
#include "game_time.hpp"
#include "result_screen.hpp"
@@ -238,22 +239,20 @@
}
#endif
-#if 0
int left_x = Display::get_width()/2 - 100;
int right_x = Display::get_width()/2 + 100;
int y = Display::get_height()/2 + 10;
gc.print_left(Fonts::chalk_normal, (float)left_x, (float)y, _("Saved: "));
- gc.print_right(Fonts::chalk_normal, (float)right_x, (float)y,
CL_String::to(result.saved)
- + "/" + CL_String::to(result.needed));;
+ gc.print_right(Fonts::chalk_normal, (float)right_x, (float)y,
StringUtil::to_string(result.saved)
+ + "/" + StringUtil::to_string(result.needed));;
gc.print_left(Fonts::chalk_normal, (float)left_x, (float)(y+=30), _("Died:
"));
- gc.print_right(Fonts::chalk_normal, (float)right_x, (float)y,
CL_String::to(result.killed));
+ gc.print_right(Fonts::chalk_normal, (float)right_x, (float)y,
StringUtil::to_string(result.killed));
gc.print_left(Fonts::chalk_normal, (float)left_x, (float)(y+=30), _("Time
left: "));
gc.print_right(Fonts::chalk_normal, (float)right_x, (float)y, time_str);
-#endif
}
ResultScreen::ResultScreen(Result arg_result)
Modified: branches/pingus_sdl/src/savegame.cpp
===================================================================
--- branches/pingus_sdl/src/savegame.cpp 2007-01-18 03:52:35 UTC (rev
2688)
+++ branches/pingus_sdl/src/savegame.cpp 2007-01-18 12:30:57 UTC (rev
2689)
@@ -20,8 +20,8 @@
#include <iostream>
///#include "sexpr_file_writer.hpp"
#include "savegame.hpp"
+#include "string_util.hpp"
-
std::string
Savegame::status_to_string(S_Status status)
{
@@ -42,8 +42,7 @@
Savegame::S_Status
Savegame::string_to_status (std::string str)
{
-#if 0
- str = CL_String::to_lower(str);
+ str = StringUtil::to_lower(str);
if (str == "accessible")
return ACCESSIBLE;
else if (str == "finished")
@@ -51,7 +50,6 @@
else if (str == "none")
return NONE;
else
-#endif
return NONE;
}
Modified: branches/pingus_sdl/src/server_event.cpp
===================================================================
--- branches/pingus_sdl/src/server_event.cpp 2007-01-18 03:52:35 UTC (rev
2688)
+++ branches/pingus_sdl/src/server_event.cpp 2007-01-18 12:30:57 UTC (rev
2689)
@@ -23,8 +23,8 @@
#include "server.hpp"
#include "world.hpp"
#include "pingu_holder.hpp"
+#include "string_util.hpp"
-
ServerEvent::ServerEvent() :
type(PINGU_ACTION_EVENT),
time_stamp(0),
@@ -57,20 +57,18 @@
void
ServerEvent::write_xml(std::ostream& xml) const
{
-#if 0
switch(type)
{
case ARMAGEDDON_EVENT:
- xml << " <armageddon time=\"" << CL_String::to(time_stamp) << "\"/>" <<
std::endl;
+ xml << " <armageddon time=\"" << StringUtil::to_string(time_stamp) <<
"\"/>" << std::endl;
break;
case PINGU_ACTION_EVENT:
- xml << " <pingu-action time=\"" << CL_String::to(time_stamp) << "\"
id=\"" << pingu_id
+ xml << " <pingu-action time=\"" << StringUtil::to_string(time_stamp) <<
"\" id=\"" << pingu_id
<< "\" action=\"" << Actions::action_to_string(pingu_action) <<
"\"/>" << std::endl;
break;
default:
assert(!"Unknown type");
}
-#endif
}
ServerEvent
Modified: branches/pingus_sdl/src/start_screen.cpp
===================================================================
--- branches/pingus_sdl/src/start_screen.cpp 2007-01-18 03:52:35 UTC (rev
2688)
+++ branches/pingus_sdl/src/start_screen.cpp 2007-01-18 12:30:57 UTC (rev
2689)
@@ -35,6 +35,7 @@
#include "pingus_level.hpp"
#include "string_format.hpp"
#include "gui/display.hpp"
+#include "string_util.hpp"
class StartScreenComponent : public GUI::Component
{
@@ -151,7 +152,6 @@
{
gc.draw(background, Display::get_width()/2, Display::get_height()/2);
-#if 0
int left_x = Display::get_width()/2 - 120;
int right_x = Display::get_width()/2 + 120;
int y = Display::get_height()/2 + 40;
@@ -167,16 +167,16 @@
format_description(800 - 230));
gc.print_left (Fonts::chalk_normal, (float)left_x, (float)y, _("Number of
Pingus: "));
- gc.print_right(Fonts::chalk_normal, (float)right_x, (float)y,
CL_String::to(plf.get_number_of_pingus()));
+ gc.print_right(Fonts::chalk_normal, (float)right_x, (float)y,
StringUtil::to_string(plf.get_number_of_pingus()));
gc.print_left (Fonts::chalk_normal, (float)left_x, float(y += 30),
_("Number to Save: "));
- gc.print_right(Fonts::chalk_normal, (float)right_x, (float)y,
CL_String::to(plf.get_number_to_save()));
+ gc.print_right(Fonts::chalk_normal, (float)right_x, (float)y,
StringUtil::to_string(plf.get_number_to_save()));
gc.print_left (Fonts::chalk_normal, (float)left_x, float(y += 30), _("Time:
"));
gc.print_right(Fonts::chalk_normal, (float)right_x, (float)y, time_str);
gc.print_left (Fonts::chalk_normal, (float)left_x, float(y += 30),
_("Difficulty:"));
- gc.print_right(Fonts::chalk_normal, (float)right_x, (float)y,
CL_String::to(plf.get_difficulty()) + "/100");
+ gc.print_right(Fonts::chalk_normal, (float)right_x, (float)y,
StringUtil::to_string(plf.get_difficulty()) + "/100");
gc.print_center(Fonts::chalk_small, (float)Display::get_width()/2,
(float)Display::get_height()/2 + 270, _("Author: ") +
plf.get_author());
@@ -184,8 +184,7 @@
if (maintainer_mode)
gc.print_left(Fonts::chalk_small, 110, 430, _("Filename: ") +
plf.get_resname());
- CL_System::sleep(30);
-#endif
+ SDL_Delay(30);
}
const std::string&
Modified: branches/pingus_sdl/src/stat_manager.cpp
===================================================================
--- branches/pingus_sdl/src/stat_manager.cpp 2007-01-18 03:52:35 UTC (rev
2688)
+++ branches/pingus_sdl/src/stat_manager.cpp 2007-01-18 12:30:57 UTC (rev
2689)
@@ -22,7 +22,7 @@
#include <fstream>
#include "system.hpp"
#include "pingus_error.hpp"
-////#include "xml_file_reader.hpp"
+#include "string_util.hpp"
#include "stat_manager.hpp"
@@ -133,24 +133,20 @@
bool
StatManager::get_int(const std::string& name, int& value)
{
-#if 0
std::string str;
if (get_string(name, str))
- return CL_String::from(str, value);
+ return StringUtil::from_string(str, value);
else
-#endif
return false;
}
bool
StatManager::get_bool(const std::string& name, bool& value)
{
-#if 0
std::string str;
if (get_string(name, str))
- return CL_String::from(str, value);
+ return StringUtil::from_string(str, value);
else
-#endif
return false;
}
@@ -179,18 +175,14 @@
void
StatManager::set_int(const std::string& name, int value)
{
-#if 0
- stats[name] = CL_String::to(value);
-#endif
+ stats[name] = StringUtil::to_string(value);
flush();
}
void
StatManager::set_bool(const std::string& name, bool value)
{
-#if 0
- stats[name] = CL_String::to(value);
-#endif
+ stats[name] = StringUtil::to_string(value);
flush();
}
Added: branches/pingus_sdl/src/string_util.cpp
===================================================================
--- branches/pingus_sdl/src/string_util.cpp 2007-01-18 03:52:35 UTC (rev
2688)
+++ branches/pingus_sdl/src/string_util.cpp 2007-01-18 12:30:57 UTC (rev
2689)
@@ -0,0 +1,60 @@
+/* $Id$
+** __ __ __ ___ __ __ __ __
+** / \ / \__| ____ __| _/_______/ |_|__| | | | ____
+** \ \/\/ / |/ \ / __ |/ ___/\ __\ | | | | _/ __ \
+** \ /| | | \/ /_/ |\___ \ | | | | |_| |_\ ___/
+** \__/\ / |__|___| /\____ /____ > |__| |__|____/____/\___ >
+** \/ \/ \/ \/ \/
+** Copyright (C) 2005 Ingo Ruhnke <address@hidden>
+**
+** This program is free software; you can redistribute it and/or
+** modify it under the terms of the GNU General Public License
+** as published by the Free Software Foundation; either version 2
+** of the License, or (at your option) any later version.
+**
+** This program is distributed in the hope that it will be useful,
+** but WITHOUT ANY WARRANTY; without even the implied warranty of
+** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+** GNU General Public License for more details.
+**
+** You should have received a copy of the GNU General Public License
+** along with this program; if not, write to the Free Software
+** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+** 02111-1307, USA.
+*/
+
+#include "string_util.hpp"
+
+// Code based on clanstring.cpp from ClanLib 0.8
+
+std::string
+StringUtil::to_lower(const std::string &str)
+{
+ std::string lower_impl = str;
+
+ for( std::string::iterator i = lower_impl.begin();
+ i != lower_impl.end();
+ ++i )
+ {
+ *i = tolower(*i);
+ }
+
+ return lower_impl;
+}
+
+std::string
+StringUtil::to_upper(const std::string &str)
+{
+ std::string upper_impl = str;
+
+ for( std::string::iterator i = upper_impl.begin();
+ i != upper_impl.end();
+ ++i )
+ {
+ *i = toupper(*i);
+ }
+
+ return upper_impl;
+}
+
+/* EOF */
Added: branches/pingus_sdl/src/string_util.hpp
===================================================================
--- branches/pingus_sdl/src/string_util.hpp 2007-01-18 03:52:35 UTC (rev
2688)
+++ branches/pingus_sdl/src/string_util.hpp 2007-01-18 12:30:57 UTC (rev
2689)
@@ -0,0 +1,82 @@
+/* $Id$
+** __ __ __ ___ __ __ __ __
+** / \ / \__| ____ __| _/_______/ |_|__| | | | ____
+** \ \/\/ / |/ \ / __ |/ ___/\ __\ | | | | _/ __ \
+** \ /| | | \/ /_/ |\___ \ | | | | |_| |_\ ___/
+** \__/\ / |__|___| /\____ /____ > |__| |__|____/____/\___ >
+** \/ \/ \/ \/ \/
+** Copyright (C) 2005 Ingo Ruhnke <address@hidden>
+**
+** This program is free software; you can redistribute it and/or
+** modify it under the terms of the GNU General Public License
+** as published by the Free Software Foundation; either version 2
+** of the License, or (at your option) any later version.
+**
+** This program is distributed in the hope that it will be useful,
+** but WITHOUT ANY WARRANTY; without even the implied warranty of
+** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+** GNU General Public License for more details.
+**
+** You should have received a copy of the GNU General Public License
+** along with this program; if not, write to the Free Software
+** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+** 02111-1307, USA.
+*/
+
+#ifndef HEADER_STRING_UTIL_HPP
+#define HEADER_STRING_UTIL_HPP
+
+#include <sstream>
+
+/** */
+class StringUtil
+{
+private:
+public:
+ static std::string to_lower(const std::string &str);
+ static std::string to_upper(const std::string &str);
+
+ template<class T>
+ static T to(const std::string& s)
+ {
+ T tmp;
+ std::istringstream str(s);
+ str >> tmp;
+ return tmp;
+ }
+
+ template<class T>
+ static bool from_string(const std::string& s, T& t)
+ {
+ std::istringstream str(s);
+ T tmp;
+ str >> tmp;
+ if (str.fail())
+ {
+ return false;
+ }
+ else
+ {
+ t = tmp;
+ return true;
+ }
+ return tmp;
+ }
+
+ template<class T>
+ static std::string to_string(const T& t)
+ {
+ std::ostringstream str;
+ str << t;
+ return str.str();
+ }
+
+private:
+ StringUtil ();
+ StringUtil (const StringUtil&);
+ StringUtil& operator= (const StringUtil&);
+};
+
+#endif
+
+/* EOF */
Modified: branches/pingus_sdl/src/worldobjs/exit.cpp
===================================================================
--- branches/pingus_sdl/src/worldobjs/exit.cpp 2007-01-18 03:52:35 UTC (rev
2688)
+++ branches/pingus_sdl/src/worldobjs/exit.cpp 2007-01-18 12:30:57 UTC (rev
2689)
@@ -26,6 +26,7 @@
#include "../pingu.hpp"
#include "../components/smallmap.hpp"
#include "../resource.hpp"
+#include "../string_util.hpp"
#include "exit.hpp"
namespace WorldObjs {
@@ -42,7 +43,7 @@
// Set default owner ID to 0
if (owner_id < 0 || owner_id > 3) owner_id = 0;
- flag = Resource::load_sprite("core/misc/flag"); ////+
CL_String::to(owner_id));
+ flag = Resource::load_sprite("core/misc/flag" +
StringUtil::to_string(owner_id));
sprite = Resource::load_sprite(desc);
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Pingus-CVS] r2689 - in branches/pingus_sdl/src: . actions components editor gui worldobjs,
grumbel at BerliOS <=