diff options
Diffstat (limited to 'src/client')
-rw-r--r-- | src/client/chat.cc | 61 | ||||
-rw-r--r-- | src/client/chat.h | 7 | ||||
-rw-r--r-- | src/client/client.cc | 1 | ||||
-rw-r--r-- | src/client/console.cc | 64 | ||||
-rw-r--r-- | src/client/console.h | 25 | ||||
-rw-r--r-- | src/client/view.cc | 25 | ||||
-rw-r--r-- | src/client/view.h | 2 |
7 files changed, 110 insertions, 75 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 diff --git a/src/client/chat.h b/src/client/chat.h index c7232a9..1ea1765 100644 --- a/src/client/chat.h +++ b/src/client/chat.h @@ -11,7 +11,7 @@ #include <deque> #include "ui/inputbox.h" -#include "ui/label.h" +#include "ui/scrollpane.h" #include "ui/window.h" namespace client { @@ -25,6 +25,8 @@ public: virtual void show(); void toggle(); + void event_text(const std::string & text); + protected: virtual void event_draw(); virtual void resize(); @@ -33,7 +35,8 @@ protected: private: - ui::Label *chat_label; + ui::Text chat_log; + ui::ScrollPane *chat_scrollpane; ui::InputBox *chat_input; typedef std::deque<std::string> History; diff --git a/src/client/client.cc b/src/client/client.cc index 13c6214..45cc47a 100644 --- a/src/client/client.cc +++ b/src/client/client.cc @@ -294,6 +294,7 @@ void Client::notify_message(core::Message::Channel const channel, std::string co } con_print << message << std::endl; + view()->chat()->event_text(message); //console()->notify(message); } diff --git a/src/client/console.cc b/src/client/console.cc index 3b94b4d..f4f66c1 100644 --- a/src/client/console.cc +++ b/src/client/console.cc @@ -16,8 +16,8 @@ #include "client/keyboard.h" #include "core/core.h" #include "filesystem/filesystem.h" -#include "render/render.h" -#include "render/textures.h" +#include "render/gl.h" +#include "ui/paint.h" namespace client { @@ -48,15 +48,19 @@ Console::Console(ui::Widget *parent) : ui::Window(parent) set_background(true); set_label("console"); - console_scroll = 0; history.clear(); history.push_back(""); history_pos = history.rbegin(); + console_scrollpane = new ui::ScrollPane(this, con_buffer.log()); + console_scrollpane->set_border(false); + console_scrollpane->set_scroll(0); + console_input = new ui::InputBox(this); console_input->set_focus(); console_input->set_border(false); console_input->set_background(false); + console_input->set_prompt("^N>"); load_history(); } @@ -73,7 +77,8 @@ void Console::show() SDL_WM_GrabInput(SDL_GRAB_OFF); SDL_ShowCursor(SDL_ENABLE); - console_scroll = 0; + console_scrollpane->set_scroll(0); + history_pos = history.rbegin(); (*history_pos).clear(); console_input->set_text((*history_pos)); @@ -103,7 +108,7 @@ bool Console::on_keypress(const int key, const unsigned int modifier) // number of lines to scroll const size_t scroll_offset = 3; - Text::reverse_iterator upit; + ui::Text::reverse_iterator upit; switch( key ) { @@ -154,17 +159,12 @@ bool Console::on_keypress(const int key, const unsigned int modifier) return true; break; case SDLK_PAGEUP: - console_scroll += scroll_offset; - if (console_scroll > log().size()) - console_scroll = log().size(); + console_scrollpane->inc_scroll(scroll_offset); return true; break; case SDLK_PAGEDOWN: - if (console_scroll > scroll_offset) - console_scroll -= scroll_offset; - else - console_scroll = 0; + console_scrollpane->dec_scroll(scroll_offset); return true; break; } @@ -172,7 +172,7 @@ bool Console::on_keypress(const int key, const unsigned int modifier) return false; } -void Console::event_draw() +void Console::draw() { if (core::application()->connected()) { set_size(parent()->size().width(), parent()->size().height() * DEFAULT_CONSOLE_HEIGHT); @@ -180,17 +180,29 @@ void Console::event_draw() set_size(parent()->size()); } - ui::Window::event_draw(); -} + math::Vector2f s(size()); + s.x -= 8; + s.y -= 8; -void Console::draw() -{ - console_input->set_size(this->width(), font()->height()); - console_input->set_location(0, this->height()-font()->height()); + console_scrollpane->set_location(4, 4); + console_scrollpane->set_size(s.x, s.y - font()->height()); + + console_input->set_location(4, height() - font()->height() -4); + console_input->set_size(s.x, font()->height()); - draw_background(); - draw_border(); + std::string version(core::name()); + version += ' '; + version.append(core::version()); + render::gl::color(0.0f, 1.0f, 0.0f, 0.5f); + + s.assign(version.size() * font()->width(), font()->height()); + math::Vector2f l(global_location()); + l.x += width() - s.width() -4; + l.y += height() - s.height() -4; + ui::paint::text(l, s, font(), version); + +/* render::Text::setfont(font()->name().c_str(), font()->width(), font()->height()); render::gl::enable(GL_TEXTURE_2D); @@ -210,8 +222,8 @@ void Console::draw() int bottom = (int) log().size() - console_scroll; int current_line = 0; - Text lines; - for (Text::iterator it = log().begin(); it != log().end() && current_line < bottom; it++) { + ui::Text lines; + for (ui::Text::iterator it = log().begin(); it != log().end() && current_line < bottom; it++) { if (current_line >= bottom - height) { std::string linedata(*it); linedata += '\n'; @@ -300,13 +312,13 @@ void Console::draw() float y = this->height()-2*font()->height()-4; render::Text::setcolor('N'); - for (Text::reverse_iterator rit = lines.rbegin(); (y >= 4) && (rit != lines.rend()); ++rit) { + for (ui::Text::reverse_iterator rit = lines.rbegin(); (y >= 4) && (rit != lines.rend()); ++rit) { render::Text::draw(4, y, (*rit)); y -= font()->height(); } render::gl::disable(GL_TEXTURE_2D); - +*/ } void Console::save_history() @@ -322,7 +334,7 @@ void Console::save_history() con_warn << "Could not write " << filename << std::endl; return; } - Text::iterator it; + ui::Text::iterator it; size_t l = 1; for (it = history.begin(); it != history.end(); it++) { if (l < history.size()) diff --git a/src/client/console.h b/src/client/console.h index c567d70..40bf4c1 100644 --- a/src/client/console.h +++ b/src/client/console.h @@ -8,8 +8,9 @@ #define __INCLUDED_CLIENT_CONSOLE_H__ #include "sys/consoleinterface.h" -#include "ui/window.h" #include "ui/inputbox.h" +#include "ui/scrollpane.h" +#include "ui/window.h" namespace client { @@ -29,8 +30,6 @@ public: /// client system console widget class Console : public ui::Window { public: - typedef std::deque<std::string> Text; - Console(Widget *parent); virtual ~Console(); @@ -49,30 +48,24 @@ public: void toggle(); protected: - /// draw event - virtual void event_draw(); - /// draw the client console text + /// draw the client console virtual void draw(); /// handle keypress events virtual bool on_keypress(const int key, const unsigned int modifier); private: - inline Text & log() { return con_buffer.log(); } - // input history - Text history; - Text::reverse_iterator history_pos; - - // scroll position - size_t console_scroll; + ui::Text history; + ui::Text::reverse_iterator history_pos; - // input widget - ui::InputBox *console_input; + // console widget + ui::InputBox *console_input; + ui::ScrollPane *console_scrollpane; // console buffer - static ConsoleBuffer con_buffer; + static ConsoleBuffer con_buffer; }; } diff --git a/src/client/view.cc b/src/client/view.cc index 13feade..a5da7d4 100644 --- a/src/client/view.cc +++ b/src/client/view.cc @@ -52,13 +52,12 @@ void time_to_stream(std::stringstream &str, float time) DevInfo::DevInfo(ui::Widget *parent) : ui::Widget(parent) { set_label("devinfo"); - set_border(true); + set_border(false); + set_background(false); } void DevInfo::draw() { - draw_border(); - std::stringstream textstream; core::Entity *target = targets::current(); float d = 0; @@ -88,7 +87,7 @@ void DevInfo::draw() } ui::paint::color(palette()->foreground()); - ui::paint::text(global_location(), font(), textstream); + ui::paint::text(global_location(), size(), font(), textstream); } /* -- Stats -------------------------------------------------------- */ @@ -96,7 +95,8 @@ void DevInfo::draw() Stats::Stats(ui::Widget *parent) : ui::Widget(parent) { set_label("stats"); - set_border(true); + set_border(false); + set_background(false); // clear counters for (size_t i =0; i < fps_counter_size; i++) @@ -111,8 +111,6 @@ Stats::Stats(ui::Widget *parent) : ui::Widget(parent) void Stats::draw() { - draw_border(); - // average fps fps_counter_time[fps_counter_index] = core::application()->time(); fps_counter_index = (fps_counter_index + 1 ) % fps_counter_size; @@ -157,7 +155,7 @@ void Stats::draw() } ui::paint::color(palette()->foreground()); - ui::paint::text(global_location(), font(), textstream); + ui::paint::text(global_location(), size(), font(), textstream); } /* -- KeyPress ----------------------------------------------------- */ @@ -165,16 +163,15 @@ void Stats::draw() KeyPress::KeyPress(ui::Widget *parent) : Widget(parent) { set_label("keypress"); - set_border(true); + set_border(false); + set_background(false); } void KeyPress::draw() { - draw_border(); - if(input::last_key_pressed()) { ui::paint::color(palette()->highlight()); - ui::paint::text(global_location(), size(), font(), input::last_key_pressed()->name(), ui::AlignCenter); + ui::paint::label(global_location(), size(), font(), input::last_key_pressed()->name(), ui::AlignCenter); } } @@ -212,8 +209,8 @@ void View::resize() set_size(parent()->size()); // reposition chat widget - view_chat->set_size(font()->width()*64, font()->height()*5); - view_chat->set_location(font()->width() * 0.5f, height() *0.5f); + view_chat->set_size(font()->width()*64, height() * 0.5f); + view_chat->set_location(font()->width(), height() - view_chat->height() - font()->height() * 4); // reposition devinfo widget view_devinfo->set_size(font()->width()*32, font()->height()*5); diff --git a/src/client/view.h b/src/client/view.h index dbbd7be..960e633 100644 --- a/src/client/view.h +++ b/src/client/view.h @@ -17,7 +17,7 @@ namespace client const size_t fps_counter_size = 32; // fps is the average of 32 frames const size_t net_counter_size = 128; // net is the average of 128 frames -//// a widget to show developer info +/// a widget to show developer info class DevInfo : public ui::Widget { public: |