X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Fconsole.cpp;h=d636f67e86c50cb135affc44b3ecae67d26552ec;hb=3e86b3d0c8c9ed1137e8716fcecbcd0ca67bea7b;hp=ead91286e39e0ba75cab2e0933018a21f6264e06;hpb=9b0b95ef0c2411314176652d25ed9c25a2718577;p=supertux.git diff --git a/src/console.cpp b/src/console.cpp index ead91286e..d636f67e8 100644 --- a/src/console.cpp +++ b/src/console.cpp @@ -19,6 +19,8 @@ #include #include +#include +#include #include "console.hpp" #include "video/drawing_context.hpp" #include "video/surface.hpp" @@ -50,8 +52,9 @@ Console::~Console() void Console::init_graphics() { - font.reset(new Font("images/engine/fonts/white-small.png", - "images/engine/fonts/shadow-small.png", 8, 9, 1)); + font.reset(new Font(Font::FIXED, + "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")); @@ -72,9 +75,7 @@ Console::flush(ConsoleStreamBuffer* buffer) 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(); } } } @@ -157,6 +158,15 @@ Console::backspace() } void +Console::enter() +{ + std::string s = inputBuffer.str(); + addLines("> "+s); + parse(s); + inputBuffer.str(std::string()); +} + +void Console::scroll(int numLines) { offset += numLines; @@ -182,6 +192,14 @@ Console::show_history(int offset) } } +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 { @@ -312,8 +330,10 @@ Console::addLine(std::string s) // 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); @@ -325,7 +345,7 @@ Console::addLine(std::string s) if (height < 64) { if(height < 4) height = 4; - height += fontheight; + height += fontheight * line_count; } // reset console to full opacity @@ -456,17 +476,21 @@ Console::draw(DrawingContext& context) if (focused) { lineNo++; - float py = height-4-1*9; - context.draw_text(font.get(), "> "+inputBuffer.str()+"_", Vector(4, py), LEFT_ALLIGN, layer); + float py = height-4-1 * font->get_height(); + 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; for (std::list::iterator i = lines.begin(); i != lines.end(); i++) { if (skipLines-- > 0) continue; lineNo++; - float py = height-4-lineNo*9; - if (py < -9) break; - context.draw_text(font.get(), *i, Vector(4, py), LEFT_ALLIGN, layer); + float py = height - 4 - lineNo*font->get_height(); + if (py < -font->get_height()) break; + context.draw_text(font.get(), *i, Vector(4, py), ALIGN_LEFT, layer); } context.pop_transform(); }