Skip to content

Commit

Permalink
Made Console into a Currenton
Browse files Browse the repository at this point in the history
  • Loading branch information
Grumbel committed Aug 17, 2014
1 parent c946dc6 commit be53843
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 29 deletions.
30 changes: 15 additions & 15 deletions src/control/keyboard_manager.cpp
Expand Up @@ -69,10 +69,10 @@ KeyboardManager::process_key_event(const SDL_KeyboardEvent& event)
{
if (event.type == SDL_KEYDOWN)
{
Console::instance->toggle();
Console::current()->toggle();
}
}
else if (Console::instance->hasFocus())
else if (Console::current()->hasFocus())
{
// if console is open: send key there
process_console_key_event(event);
Expand Down Expand Up @@ -102,10 +102,10 @@ KeyboardManager::process_key_event(const SDL_KeyboardEvent& event)
void
KeyboardManager::process_text_input_event(const SDL_TextInputEvent& event)
{
if (Console::instance->hasFocus()) {
if (Console::current()->hasFocus()) {
for(int i = 0; event.text[i] != '\0'; ++i)
{
Console::instance->input(event.text[i]);
Console::current()->input(event.text[i]);
}
}
}
Expand All @@ -117,37 +117,37 @@ KeyboardManager::process_console_key_event(const SDL_KeyboardEvent& event)

switch (event.keysym.sym) {
case SDLK_RETURN:
Console::instance->enter();
Console::current()->enter();
break;
case SDLK_BACKSPACE:
Console::instance->backspace();
Console::current()->backspace();
break;
case SDLK_TAB:
Console::instance->autocomplete();
Console::current()->autocomplete();
break;
case SDLK_PAGEUP:
Console::instance->scroll(-1);
Console::current()->scroll(-1);
break;
case SDLK_PAGEDOWN:
Console::instance->scroll(+1);
Console::current()->scroll(+1);
break;
case SDLK_HOME:
Console::instance->move_cursor(-65535);
Console::current()->move_cursor(-65535);
break;
case SDLK_END:
Console::instance->move_cursor(+65535);
Console::current()->move_cursor(+65535);
break;
case SDLK_UP:
Console::instance->show_history(-1);
Console::current()->show_history(-1);
break;
case SDLK_DOWN:
Console::instance->show_history(+1);
Console::current()->show_history(+1);
break;
case SDLK_LEFT:
Console::instance->move_cursor(-1);
Console::current()->move_cursor(-1);
break;
case SDLK_RIGHT:
Console::instance->move_cursor(+1);
Console::current()->move_cursor(+1);
break;
default:
break;
Expand Down
1 change: 0 additions & 1 deletion src/supertux/console.cpp
Expand Up @@ -522,7 +522,6 @@ Console::draw(DrawingContext& context)
context.pop_transform();
}

Console* Console::instance = NULL;
int Console::inputBufferPosition = 0;
std::string Console::inputBuffer;
ConsoleStreamBuffer Console::outputBuffer;
Expand Down
9 changes: 4 additions & 5 deletions src/supertux/console.hpp
Expand Up @@ -23,6 +23,7 @@
#include <sstream>
#include <vector>

#include "util/currenton.hpp"
#include "video/font_ptr.hpp"
#include "video/surface_ptr.hpp"

Expand All @@ -31,14 +32,12 @@ class ConsoleStreamBuffer;
class ConsoleCommandReceiver;
class DrawingContext;

class Console
class Console : public Currenton<Console>
{
public:
Console();
~Console();

static Console* instance;

static std::ostream output; /**< stream of characters to output to the console. Do not forget to send std::endl or to flush the stream. */

void init_graphics();
Expand Down Expand Up @@ -113,8 +112,8 @@ class ConsoleStreamBuffer : public std::stringbuf
int sync()
{
int result = std::stringbuf::sync();
if(Console::instance != NULL)
Console::instance->flush(this);
if(Console::current())
Console::current()->flush(this);
return result;
}
};
Expand Down
6 changes: 2 additions & 4 deletions src/supertux/main.cpp
Expand Up @@ -328,7 +328,7 @@ Main::run(int argc, char** argv)
}

init_sdl();
Console::instance = new Console();
Console console;

timelog("controller");
g_input_manager = new InputManager();
Expand All @@ -345,7 +345,7 @@ Main::run(int argc, char** argv)
timelog("audio");
init_audio();

Console::instance->init_graphics();
Console::current()->init_graphics();

timelog("scripting");
scripting::init_squirrel(g_config->enable_script_debugger);
Expand Down Expand Up @@ -421,8 +421,6 @@ Main::run(int argc, char** argv)
g_config = NULL;
delete g_input_manager;
g_input_manager = NULL;
delete Console::instance;
Console::instance = NULL;
scripting::exit_squirrel();
delete texture_manager;
texture_manager = NULL;
Expand Down
6 changes: 3 additions & 3 deletions src/supertux/screen_manager.cpp
Expand Up @@ -137,7 +137,7 @@ ScreenManager::draw(DrawingContext& context)
m_screen_fade->draw(context);
}

Console::instance->draw(context);
Console::current()->draw(context);

if (g_config->show_fps)
{
Expand Down Expand Up @@ -184,7 +184,7 @@ ScreenManager::update_gamelogic(float elapsed_time)
m_screen_fade->update(elapsed_time);
}

Console::instance->update(elapsed_time);
Console::current()->update(elapsed_time);
}

void
Expand Down Expand Up @@ -234,7 +234,7 @@ ScreenManager::process_events()
else if (event.key.keysym.sym == SDLK_F1 &&
event.key.keysym.mod & KMOD_CTRL)
{
Console::instance->toggle();
Console::current()->toggle();
g_config->console_enabled = true;
g_config->save();
}
Expand Down
2 changes: 1 addition & 1 deletion src/util/log.cpp
Expand Up @@ -26,7 +26,7 @@ LogLevel g_log_level = LOG_WARNING;

static std::ostream& get_logging_instance (void)
{
if (Console::instance != NULL)
if (Console::current())
return (Console::output);
else
return (std::cerr);
Expand Down

0 comments on commit be53843

Please sign in to comment.