Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'src/client/console.cc')
-rw-r--r--src/client/console.cc77
1 files changed, 73 insertions, 4 deletions
diff --git a/src/client/console.cc b/src/client/console.cc
index 6a3dfaa..50093f9 100644
--- a/src/client/console.cc
+++ b/src/client/console.cc
@@ -4,24 +4,93 @@
the terms and conditions of the GNU General Public License version 2
*/
+#include "client/client.h"
#include "client/console.h"
+#include "core/core.h"
+#include "render/render.h"
+
+#include <iostream>
namespace client {
+Console::Console() {
+ visible = false;
+}
+
std::ostream & Console::messagestream()
{
- return (std::cout << ". ");
+ return (buffer << ". ");
}
std::ostream & Console::warningstream()
{
- return (std::cout << "! ");
+ return (buffer << "* ");
+}
+
+std::ostream & Console::errorstream()
+{
+ return (buffer << "! ");
}
std::ostream & Console::debugstream()
{
- return (std::cout << "? ");
+ return (buffer << "? ");
}
-} // namespace client
+void Console::draw()
+{
+ using namespace render;
+
+ flush();
+
+ float height;
+ if (core::game()) {
+ if (!core::game()->ready())
+ height = 0.6f;
+ else if (visible)
+ height = 0.6f;
+ else
+ return;
+ } else
+ height = 1.0f;
+
+ // console background rectangle
+ gl::enable(GL_BLEND);
+ gl::begin(gl::Quads);
+ gl::color(1, 1, 1, .1);
+ gl::vertex(-0.5f*video.ratio , 0.5, -1.0f);
+ gl::vertex(0.5f*video.ratio ,0.5, -1.0f);
+ gl::vertex(0.5f*video.ratio , 0.5-height, -1.0f);
+ gl::vertex(-0.5f*video.ratio , 0.5-height, -1.0f);
+ gl::end();
+ gl::disable(GL_BLEND);
+}
+
+void Console::flush()
+{
+ char line[MAXCMDSIZE];
+ while(this->buffer.getline(line, MAXCMDSIZE-1)) {
+
+ while (text.size() >= 32765 - MAXCMDSIZE) {
+ size_t i = 0;
+ while (i+1 < text.size() && text[i] != '\n')
+ i++;
+ text.erase(0, i+1);
+ }
+
+ text.append(line);
+ text.append("\n");
+
+ std::cout << line << std::endl;
+ }
+
+ buffer.clear();
+}
+
+void Console::toggle()
+{
+ visible = !visible;
+}
+
+} // namespace client