Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStijn Buys <ingar@osirion.org>2008-10-19 13:45:07 +0000
committerStijn Buys <ingar@osirion.org>2008-10-19 13:45:07 +0000
commit56cdfd3822d2800abdd2f912ab7f76a5764793a7 (patch)
tree2656c7ef694117e0554ae4a47bb09629c78ed8af /src/client/chat.cc
parente6f1fad441a7737549f463ebac1c9de062b5173d (diff)
scrollpane widget, updated chatbox
Diffstat (limited to 'src/client/chat.cc')
-rw-r--r--src/client/chat.cc61
1 files changed, 45 insertions, 16 deletions
diff --git a/src/client/chat.cc b/src/client/chat.cc
index 9d51adc..af50dff 100644
--- a/src/client/chat.cc
+++ b/src/client/chat.cc
@@ -12,7 +12,8 @@
namespace client {
-const size_t DEFAULT_MAX_HISTO_LINES = 512;
+const size_t DEFAULT_CHAT_LOG_SIZE = 256;
+const size_t DEFAULT_CHAT_HISTO_SIZE = 512;
Chat::Chat(ui::Widget *parent) : ui::Window(parent)
{
@@ -21,12 +22,12 @@ Chat::Chat(ui::Widget *parent) : ui::Window(parent)
history.push_back("");
history_pos = history.rbegin();
- chat_label = new ui::Label(this, "^BSay^F:^B");
- chat_label->set_alignment(ui::AlignLeft | ui::AlignVCenter);
- chat_label->set_border(false);
+ chat_scrollpane = new ui::ScrollPane(this, chat_log);
+ chat_scrollpane->set_border(false);
chat_input = new ui::InputBox(this);
chat_input->set_border(false);
+ chat_input->set_prompt("^BSay^F:^B ");
chat_input->set_focus();
@@ -39,6 +40,13 @@ Chat::~Chat()
history.clear();
}
+void Chat::event_text(const std::string & text)
+{
+ while (chat_log.size() >= DEFAULT_CHAT_LOG_SIZE) {
+ chat_log.pop_front();
+ }
+ chat_log.push_back(text);
+}
void Chat::show()
{
@@ -47,6 +55,8 @@ void Chat::show()
history_pos = history.rbegin();
(*history_pos).clear();
chat_input->set_text((*history_pos));
+
+ chat_scrollpane->set_scroll(0);
}
void Chat::toggle()
@@ -57,17 +67,11 @@ void Chat::toggle()
show();
}
-void Chat::resize()
-{
- chat_label->set_location(font()->width(), height() / 5.0f);
- chat_label->set_size(width() - font()->width() * 2, height() / 5.0f);
-
- chat_input->set_location(font()->width(), height() / 5.0f * 3.0f);
- chat_input->set_size(width() - font()->width() * 2, height() / 5.0f);
-}
-
bool Chat::on_keypress(const int key, const unsigned int modifier)
{
+ // number of lines to scroll
+ const size_t scroll_offset = 3;
+
History::reverse_iterator upit;
switch( key ) {
@@ -81,7 +85,7 @@ bool Chat::on_keypress(const int key, const unsigned int modifier)
case SDLK_RETURN:
if (chat_input->text().size()) {
// store input into history
- while (history.size() >= DEFAULT_MAX_HISTO_LINES) {
+ while (history.size() >= DEFAULT_CHAT_HISTO_SIZE) {
history.pop_front();
}
@@ -95,9 +99,9 @@ bool Chat::on_keypress(const int key, const unsigned int modifier)
history.push_back("");
history_pos = history.rbegin();
chat_input->set_text((*history_pos));
+ } else {
+ hide();
}
-
- hide();
return true;
break;
@@ -118,6 +122,16 @@ bool Chat::on_keypress(const int key, const unsigned int modifier)
}
return true;
break;
+
+ case SDLK_PAGEUP:
+ chat_scrollpane->inc_scroll(scroll_offset);
+ return true;
+ break;
+
+ case SDLK_PAGEDOWN:
+ chat_scrollpane->dec_scroll(scroll_offset);
+ return true;
+ break;
}
return false;
@@ -136,4 +150,19 @@ void Chat::event_draw()
Widget::event_draw();
}
+void Chat::resize()
+{
+ const float margin = 8.0f;
+ math::Vector2f s(size());
+ s.x -= margin*2;
+ s.y -= margin*2;
+
+ chat_scrollpane->set_location(margin, margin);
+ chat_scrollpane->set_size(s.x, s.y - font()->height() *1.5f);
+
+ chat_input->set_location(margin, height() - font()->height() - margin);
+ chat_input->set_size(s.x, font()->height());
+}
+
+
} // namespace client