Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/ui/console.cc102
-rw-r--r--src/ui/console.h11
2 files changed, 87 insertions, 26 deletions
diff --git a/src/ui/console.cc b/src/ui/console.cc
index df7d2f9..3799392 100644
--- a/src/ui/console.cc
+++ b/src/ui/console.cc
@@ -16,6 +16,7 @@
#include "filesystem/filesystem.h"
#include "render/gl.h"
#include "ui/console.h"
+#include "ui/definitions.h"
#include "ui/paint.h"
#include "ui/ui.h"
@@ -53,11 +54,21 @@ Console::Console(ui::Widget *parent) : ui::Window(parent)
history.push_back("");
history_pos = history.rbegin();
- console_scrollpane = new ui::ScrollPane(this, con_buffer.log());
+ std::string version("^F" + core::name() + ' ' + core::version());
+ console_versionlabel = new Label(this, version.c_str());
+ console_versionlabel->set_border(false);
+ console_versionlabel->set_background(false);
+
+ console_scrollpane = new ScrollPane(this, con_buffer.log());
console_scrollpane->set_border(false);
+ console_scrollpane->set_background(false);
console_scrollpane->set_scroll(0);
+
+ console_scrollbar = new ScrollBar(this);
+ console_scrollbar->set_border(false);
+ console_scrollbar->set_background(false);
- console_input = new ui::InputBox(this);
+ console_input = new InputBox(this);
console_input->set_focus();
console_input->set_border(false);
console_input->set_background(false);
@@ -114,6 +125,18 @@ void Console::toggle()
show();
}
+bool Console::on_emit(Widget *sender, const Event event, void *data)
+{
+ if (sender == console_scrollbar) {
+ if (event == ui::Widget::EventScrollBarChanged) {
+ console_scrollpane->set_scroll( (con_buffer.log().size() - console_scrollbar->value()) );
+ return true;
+ }
+ }
+
+ return false;
+}
+
bool Console::on_keypress(const int key, const unsigned int modifier)
{
// number of lines to scroll
@@ -122,7 +145,6 @@ bool Console::on_keypress(const int key, const unsigned int modifier)
ui::Text::reverse_iterator upit;
switch (key) {
-
case SDLK_ESCAPE:
if (visible()) {
hide();
@@ -186,36 +208,64 @@ bool Console::on_keypress(const int key, const unsigned int modifier)
void Console::draw()
{
+ console_scrollbar->set_range(0, (float) con_buffer.log().size());
+ console_scrollbar->set_value( (float) (con_buffer.log().size() - console_scrollpane->scroll()));
+
+ // disable mouse cursor
+ if (has_mouse_focus()) {
+ ui::root()->set_pointer();
+ }
+}
+
+void Console::resize()
+{
+ const float padding = font()->width();
+
if (core::application()->connected()) {
set_size(parent()->size().width(), parent()->size().height() * DEFAULT_CONSOLE_HEIGHT);
} else {
set_size(parent()->size());
}
- math::Vector2f s(size());
- s[0] -= 8;
- s[1] -= 8;
-
- console_scrollpane->set_location(4, 4);
- console_scrollpane->set_size(s.width(), s.height() - font()->height());
-
- console_input->set_location(4, height() - font()->height() - 4);
- console_input->set_size(s.width(), font()->height());
-
- math::Color fancy(palette()->fancy());
- fancy.a = 0.5f;
- Paint::set_color(fancy);
- std::string version(core::name() + ' ' + core::version());
- s.assign(version.size() * font()->width(), font()->height());
- math::Vector2f l(global_location());
- l[0] += width() - s.width() - 4;
- l[1] += height() - s.height() - 4;
- Paint::draw_text(l, font(), version);
+ // resize scrollbar
+ console_scrollbar->set_size(
+ font()->height(),
+ height()
+ );
+ console_scrollbar->set_location(
+ width() - console_scrollbar->width(),
+ 0.0f
+ );
- // disable mouse cursor
- if (has_mouse_focus()) {
- ui::root()->set_pointer();
- }
+ // resize version label
+ console_versionlabel->set_size(
+ width() - console_scrollbar->width() - padding,
+ font()->height() * 1.5f
+ );
+ console_versionlabel->set_location(
+ padding,
+ 0.0f
+ );
+
+ // resize input bar
+ console_input->set_size(
+ console_versionlabel->width(),
+ font()->height()
+ );
+ console_input->set_location(
+ console_versionlabel ->left(),
+ bottom() - console_input->height()
+ );
+
+ // resize scroll pane
+ console_scrollpane->set_size(
+ console_versionlabel->width(),
+ console_input->top() - console_versionlabel->bottom()
+ );
+ console_scrollpane->set_location(
+ console_versionlabel->left(),
+ console_versionlabel->bottom()
+ );
}
void Console::save_history()
diff --git a/src/ui/console.h b/src/ui/console.h
index 1baa42d..93b6934 100644
--- a/src/ui/console.h
+++ b/src/ui/console.h
@@ -9,8 +9,10 @@
#include "sys/consoleinterface.h"
#include "ui/inputbox.h"
+#include "ui/scrollbar.h"
#include "ui/scrollpane.h"
#include "ui/window.h"
+#include "ui/label.h"
namespace ui
{
@@ -54,9 +56,16 @@ protected:
/// draw the client console
virtual void draw();
+
+ /// resize event handler
+ virtual void resize();
/// handle keypress events
virtual bool on_keypress(const int key, const unsigned int modifier);
+
+ /// handle emit events
+ virtual bool on_emit(Widget *sender, const Event event, void *data);
+
private:
// input history
@@ -65,7 +74,9 @@ private:
// console widget
InputBox *console_input;
+ ScrollBar *console_scrollbar;
ScrollPane *console_scrollpane;
+ Label *console_versionlabel;
// console buffer
static ConsoleBuffer con_buffer;