From 3b75614be6d9f6e84a1b5818c5827dbc0ab5d516 Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Sun, 28 Aug 2011 18:17:56 +0000 Subject: Improved chat window layout, added title and close button. --- src/client/chat.cc | 53 +++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 43 insertions(+), 10 deletions(-) (limited to 'src/client/chat.cc') diff --git a/src/client/chat.cc b/src/client/chat.cc index cf995cb..8a09883 100644 --- a/src/client/chat.cc +++ b/src/client/chat.cc @@ -24,7 +24,19 @@ Chat::Chat(ui::Widget *parent) : ui::Window(parent) history.clear(); history.push_back(""); history_pos = history.rbegin(); - + + // window title + chat_titlelabel = new ui::Label(this); + chat_titlelabel->set_label("title"); + chat_titlelabel->set_background(false); + chat_titlelabel->set_border(false); + chat_titlelabel->set_font(ui::root()->font_large()); + chat_titlelabel->set_alignment(ui::AlignCenter); + chat_titlelabel->set_text("CHAT"); + + // close button + chat_closebutton = new ui::IconButton(chat_titlelabel, "bitmaps/icons/window_close"); + chat_scrollpane = new ui::ScrollPane(this, chat_log); chat_scrollpane->set_border(false); chat_scrollpane->set_label("text"); @@ -106,6 +118,7 @@ bool Chat::on_keypress(const int key, const unsigned int modifier) } else { return false; } + case SDLK_RETURN: if (chat_input->text().size()) { // store input into history @@ -134,6 +147,16 @@ bool Chat::on_keypress(const int key, const unsigned int modifier) return true; break; + case SDLK_TAB: + if (chat_input->text().size() && chat_input->text()[0] == '/') { + // command mode + chat_input->complete(); + } else { + // TODO chat mode, switch channel + } + return true; + break; + case SDLK_UP: upit = history_pos; ++upit; @@ -202,28 +225,38 @@ void Chat::update_player_list() void Chat::resize() { - const float fontmargin = ui::root()->font_large()->height(); + const float padding = ui::root()->font_large()->height(); if (chat_small) { chat_playerlist->hide(); chat_scrollpane->hide(); + chat_titlelabel->hide(); } else { chat_playerlist->show(); chat_scrollpane->show(); + chat_titlelabel->show(); - // player names - chat_playerlist->set_size(ui::UI::elementsize.width(), height() - fontmargin * 3.0f); - chat_playerlist->set_location(width() - ui::UI::elementsize.width() - fontmargin, fontmargin); + // resize title label + chat_titlelabel->set_size(width() - padding * 2.0f, chat_titlelabel->font()->height()); + chat_titlelabel->set_location(padding, padding); - // chat text - chat_scrollpane->set_size(width() - ui::UI::elementsize.width() - fontmargin * 3.0f, height() - fontmargin * 3.0f); - chat_scrollpane->set_location(fontmargin, fontmargin); + // resize close button + chat_closebutton->set_size(chat_titlelabel->font()->height(), chat_titlelabel->font()->height()); + chat_closebutton->set_location(chat_titlelabel->width() - chat_closebutton->width(), 0); + + // resize player names listview + chat_playerlist->set_location(padding, chat_titlelabel->bottom() + padding); + chat_playerlist->set_size(ui::UI::elementsize.width() * 1.5f, height() - chat_playerlist->top() - padding * 2.0f); + + // resize chat text pane + chat_scrollpane->set_location(chat_playerlist->right() + padding, padding); + chat_scrollpane->set_size(width() - chat_scrollpane->left() - padding, chat_playerlist->height()); } // input bar - chat_input->set_location(fontmargin, height() - fontmargin); - chat_input->set_size(width() - 2.0f * fontmargin , fontmargin); + chat_input->set_location(padding, height() - padding); + chat_input->set_size(width() - 2.0f * padding , padding); } -- cgit v1.2.3