don't adjust aspect-ratio in non-fullscreen modes, removed a few unneeded headers
[supertux.git] / src / console.cpp
index a605702..d636f67 100644 (file)
@@ -19,6 +19,8 @@
 #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"
@@ -51,8 +53,8 @@ void
 Console::init_graphics()
 {
   font.reset(new Font(Font::FIXED,
-                      "images/engine/fonts/white-small.png",
-                      "images/engine/fonts/shadow-small.png", 8, 9, 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"));
@@ -73,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();
     }
   }
 }
@@ -158,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;
@@ -183,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 {
@@ -313,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);
 
@@ -326,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
@@ -457,16 +476,20 @@ Console::draw(DrawingContext& context)
 
   if (focused) {
     lineNo++;
-    float py = height-4-1*9;
-    context.draw_text(font.get(), "> "+inputBuffer.str()+"_", Vector(4, py), ALIGN_LEFT, 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<std::string>::iterator i = lines.begin(); i != lines.end(); i++) {
     if (skipLines-- > 0) continue;
     lineNo++;
-    float py = height-4-lineNo*9;
-    if (py < -9) break;
+    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();