#include <config.h>
#include <iostream>
+#include <SDL_timer.h>
+#include <SDL_keyboard.h>
#include "console.hpp"
#include "video/drawing_context.hpp"
#include "video/surface.hpp"
Console::init_graphics()
{
font.reset(new Font(Font::FIXED,
- "images/engine/fonts/console2.png",
- "images/engine/fonts/console2-shadow.png", 8, 14, 1));
+ "images/engine/fonts/andale12.png",
+ "images/engine/fonts/andale12-shadow.png", 7, 14, 1));
fontheight = font->get_height();
background.reset(new Surface("images/engine/console.png"));
background2.reset(new Surface("images/engine/console2.png"));
std::string s = inputBuffer.str();
if ((s.length() > 0) && ((s[s.length()-1] == '\n') || (s[s.length()-1] == '\r'))) {
while ((s[s.length()-1] == '\n') || (s[s.length()-1] == '\r')) s.erase(s.length()-1);
- addLines("> "+s);
- parse(s);
- inputBuffer.str(std::string());
+ enter();
}
}
}
}
void
+Console::enter()
+{
+ std::string s = inputBuffer.str();
+ addLines("> "+s);
+ parse(s);
+ inputBuffer.str(std::string());
+}
+
+void
Console::scroll(int numLines)
{
offset += numLines;
}
}
+void
+Console::move_cursor(int offset)
+{
+ if (offset == -65535) inputBuffer.pubseekoff(0, std::ios_base::beg, std::ios_base::out);
+ if (offset == +65535) inputBuffer.pubseekoff(0, std::ios_base::end, std::ios_base::out);
+ inputBuffer.pubseekoff(offset, std::ios_base::cur, std::ios_base::out);
+}
+
// Helper functions for Console::autocomplete
// TODO: Fix rough documentation
namespace {
// wrap long lines
std::string overflow;
+ unsigned int line_count = 0;
do {
lines.push_front(Font::wrap_to_chars(s, 99, &overflow));
+ line_count++;
s = overflow;
} while (s.length() > 0);
if (height < 64) {
if(height < 4)
height = 4;
- height += fontheight;
+ height += fontheight * line_count;
}
// reset console to full opacity
if (focused) {
lineNo++;
float py = height-4-1 * font->get_height();
- context.draw_text(font.get(), "> "+inputBuffer.str()+"_", Vector(4, py), ALIGN_LEFT, layer);
+ context.draw_text(font.get(), "> "+inputBuffer.str(), Vector(4, py), ALIGN_LEFT, layer);
+ if (SDL_GetTicks() % 1000 < 750) {
+ int cursor_px = 2 + inputBuffer.pubseekoff(0, std::ios_base::cur, std::ios_base::out);
+ context.draw_text(font.get(), "_", Vector(4 + (cursor_px * font->get_text_width("X")), py), ALIGN_LEFT, layer);
+ }
}
int skipLines = -offset;