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-10 16:41:38 +0000
committerStijn Buys <ingar@osirion.org>2008-10-10 16:41:38 +0000
commit02fcd22d8cde355aa898a8c6bb4773d9434b8e9a (patch)
tree9397f1f5b61a0978acadc4c15fd330ee7138c59b /src/client
parent4331f5c17901f46693dcb5c2df96276f6851be25 (diff)
adds KeyPress, DevInfo and Stats widgets
Diffstat (limited to 'src/client')
-rw-r--r--src/client/client.cc5
-rw-r--r--src/client/console.cc4
-rw-r--r--src/client/input.cc6
-rw-r--r--src/client/view.cc308
-rw-r--r--src/client/view.h69
5 files changed, 256 insertions, 136 deletions
diff --git a/src/client/client.cc b/src/client/client.cc
index e9bfba8..81aba9d 100644
--- a/src/client/client.cc
+++ b/src/client/client.cc
@@ -108,6 +108,7 @@ void Client::init(int count, char **arguments)
// initialize user interface
ui::init();
+ new View(ui::root());
// Initialize the video subsystem
if (!video::init()) {
@@ -191,14 +192,14 @@ void Client::frame(float seconds)
if (core::application()->load("intro")) {
core::application()->connect("");
}
- // if all fails, show the console
+ // show the console if everything fails
if (!core::application()->connected() && !console()->visible()) {
console()->toggle();
}
} else {
// show the main menu on non-interactive modules
if (!core::game()->interactive() && !ui::root()->active()) {
- ui::root()->show_window("main");
+ ui::root()->show_window("main");
}
}
diff --git a/src/client/console.cc b/src/client/console.cc
index e3c4288..96da900 100644
--- a/src/client/console.cc
+++ b/src/client/console.cc
@@ -32,14 +32,12 @@ Console *console() {
void Console::init()
{
con_print << "^BInitializing console..." << std::endl;
-
console()->load_history();
}
void Console::shutdown()
{
con_print << "^BShutting down console..." << std::endl;
-
console()->save_history();
}
@@ -192,7 +190,6 @@ void Console::keypressed(unsigned int key)
void Console::save_history()
{
-
if (history.size() <= 1)
return;
@@ -539,3 +536,4 @@ void Console::notify(std::string const & message)
}
} // namespace client
+
diff --git a/src/client/input.cc b/src/client/input.cc
index 0020a1f..31d514f 100644
--- a/src/client/input.cc
+++ b/src/client/input.cc
@@ -528,7 +528,7 @@ void key_pressed(Key *key)
console()->keypressed(translate_keysym(key->sym(), keyboard_modifiers));
} else if (ui::root()->active()) {
- ui::root()->event_keypress(key->sym(), keyboard_modifiers);
+ ui::root()->input_key(true, key->sym(), keyboard_modifiers);
} else if (chat::visible()) {
// send key events to the chat box
@@ -559,7 +559,7 @@ void key_pressed(Key *key)
void key_released(Key *key)
{
if (ui::root()->active()) {
- ui::root()->event_keyrelease(key->sym(), keyboard_modifiers);
+ ui::root()->input_key(false, key->sym(), keyboard_modifiers);
}
if (core::application()->connected() && core::localcontrol()) {
@@ -714,7 +714,7 @@ void frame(float seconds)
mouse_x = event.motion.x;
mouse_y = event.motion.y;
mouse_lastmoved = client()->time();
- ui::root()->event_mousemove((float) mouse_x, (float) mouse_y);
+ ui::root()->input_mouse((float) mouse_x, (float) mouse_y);
break;
case SDL_MOUSEBUTTONDOWN:
diff --git a/src/client/view.cc b/src/client/view.cc
index 50b5b61..38d22d4 100644
--- a/src/client/view.cc
+++ b/src/client/view.cc
@@ -18,11 +18,14 @@
#include "client/input.h"
#include "client/targets.h"
#include "client/video.h"
+#include "client/view.h"
#include "render/render.h"
#include "core/core.h"
#include "math/mathlib.h"
#include "sys/sys.h"
+#include "ui/paint.h"
#include "ui/ui.h"
+#include "ui/widget.h"
namespace client
{
@@ -35,35 +38,196 @@ core::Cvar *draw_keypress = 0;
core::Cvar *ui_pointercolor = 0;
core::Cvar *ui_pointerhovercolor =0;
-namespace view
+/* -- DevInfo------------------------------------------------------- */
+DevInfo::DevInfo(ui::Widget *parent) : ui::Widget(parent)
{
+ set_label("devinfo");
+ set_border(true);
+}
-const size_t fps_counter_size = 32; // fps is the average of 32 frames
-float fps_counter_time[fps_counter_size];
-size_t fps_counter_index = 0;
+void DevInfo::draw()
+{
+ draw_border();
-const size_t net_counter_size = 128;
-float net_counter_time[net_counter_size];
-size_t net_counter_traffic[net_counter_size];
-size_t net_counter_index;
+ std::stringstream textstream;
+ core::Entity *target = targets::current();
+ float d = 0;
-core::Zone *current_zone = 0;
+ textstream << "^Ntime: ^B" << std::fixed << std::setprecision(4) << client()->time() << '\n';
+ if (core::game()) {
+ textstream << "^Ngame: ^B" << core::game()->time();
+ }
+ textstream << '\n';
-void init()
+ if (core::localcontrol()) {
+ textstream << std::fixed << std::setprecision(2)
+ << "^Nx:^B" << core::localcontrol()->location().x << " "
+ << "^Ny:^B" << core::localcontrol()->location().y << " "
+ << "^Nz:^B" << core::localcontrol()->location().z << '\n';
+
+ textstream << "^Nthurst:^B " << core::localcontrol()->thrust() << " "
+ << "^Nspeed:^B " << core::localcontrol()->speed() << '\n';
+
+ if (target) {
+ d = math::distance(core::localcontrol()->location(), target->state()->location()) - target->radius() - core::localcontrol()->radius();
+ textstream << "^Ndist:^B " << d << '\n';
+ }
+ }
+
+ ui::paint::color(palette()->foreground());
+ ui::paint::text(global_location(), font(), textstream);
+}
+
+/* -- Stats -------------------------------------------------------- */
+
+Stats::Stats(ui::Widget *parent) : ui::Widget(parent)
{
- draw_stats = core::Cvar::get("draw_stats", "0", core::Cvar::Archive);
- draw_stats->set_info("[bool] draw network and render statistics");
+ set_label("stats");
+ set_border(true);
+
+ // clear counters
+ for (size_t i =0; i < fps_counter_size; i++)
+ fps_counter_time[i] = 0.0f;
+
+ for (size_t i = 0; i < net_counter_size; i++)
+ net_counter_traffic[i] = 0;
+}
+
+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;
+ float min_time = core::application()->time();
+ for (size_t i=0; i < fps_counter_size; i++)
+ if (fps_counter_time[i] < min_time)
+ min_time = fps_counter_time[i];
+ float fps = 0.0f;
+ float t = (core::application()->time() - min_time);
+ if (t > 0) {
+ fps = roundf(((float) fps_counter_size - 1.0f) / t);
+ }
+
+ std::stringstream textstream;
+
+ if (core::game()) {
+ int minutes = (int) floorf(core::game()->clientframetime() / 60.0f);
+ int seconds = (int) floorf( core::game()->clientframetime() - (float) minutes* 60.0f);
+
+ textstream << "^Ntime ^B" << std::setfill(' ') << std::setw(3) << minutes << ":" << std::setfill('0') << std::setw(2) << seconds;
+ }
+
+ textstream << std::setfill(' ') << "\n";
+ textstream << "^Nfps ^B" << std::setw(6) << fps << "\n";
+ if (core::application()->connected()) {
+ textstream << "^Ntris ^B" << std::setw(5) << render::Stats::tris << "\n";
+ textstream << "^Nquads ^B" << std::setw(5) << render::Stats::quads << "\n";
+
+ if (core::Stats::network_bytes_sent + core::Stats::network_bytes_received) {
+ net_counter_traffic[net_counter_index] = core::Stats::network_bytes_sent + core::Stats::network_bytes_received;
+ net_counter_time[net_counter_index] = core::application()->time();
+ size_t index_max = net_counter_index;
+
+ net_counter_index = (net_counter_index + 1) % net_counter_size;
+ size_t index_min = net_counter_index;
+
+ float d = net_counter_time[index_max] - net_counter_time[index_min];
+ if (d > 0) {
+ float traffic = net_counter_traffic[index_max] - net_counter_traffic[index_min];
+ textstream << "^Nnet ^B" << std::setw(6) << roundf( (float) traffic / d ) << "\n";
+ }
+ }
+ }
+
+ ui::paint::color(palette()->foreground());
+ ui::paint::text(global_location(), font(), textstream);
+}
+
+/* -- KeyPress ----------------------------------------------------- */
+
+KeyPress::KeyPress(ui::Widget *parent) : Widget(parent)
+{
+ set_label("keypress");
+ set_border(true);
+}
+
+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);
+ }
+}
+
+/* -- View --------------------------------------------------------- */
+
+View::View(ui::Widget *parent) : ui::Widget(parent)
+{
+ set_label("view");
+ set_border(false);
+
+ // initialize client variables
draw_devinfo = core::Cvar::get("draw_devinfo", "0", core::Cvar::Archive);
draw_devinfo->set_info("[bool] draw developer information");
- // FIXME integrate with libui
- draw_ui = core::Cvar::get("draw_ui", "1", core::Cvar::Archive);
- draw_ui->set_info("[bool] draw the user interface");
+ draw_stats = core::Cvar::get("draw_stats", "0", core::Cvar::Archive);
+ draw_stats->set_info("[bool] draw network and render statistics");
draw_keypress = core::Cvar::get("draw_keypress", "0", core::Cvar::Archive);
draw_keypress->set_info("[bool] draw keypress key names");
+ // add child widgets
+ view_devinfo = new DevInfo(this);
+ view_stats = new Stats(this);
+ view_keypress = new KeyPress(this);
+
+ // make sure the view is at the bottom of the draw stack
+ lower();
+}
+
+void View::resize()
+{
+ set_size(parent()->size());
+
+ // reposition devinfo widget
+ view_devinfo->set_size(font()->width()*32, font()->height()*5);
+ view_devinfo->set_location(font()->width() * 0.5f, font()->height() * 0.5f);
+
+ // reposition stats widget
+ view_stats->set_size(font()->width()*12, font()->height()*5);
+ view_stats->set_location(width() - view_stats->width() - font()->width() * 0.5, font()->height() * 0.5f);
+
+ // reposition keypress widget
+ view_keypress->set_size(font()->width()*12, font()->height()*1);
+ view_keypress->set_location(width() - view_keypress->width() - font()->width() * 0.5,
+ height() - view_keypress->height() - font()->height() * 0.5f);
+}
+
+void View::draw()
+{
+ view_devinfo->set_visible(draw_devinfo->value() ? true : false);
+ view_stats->set_visible(draw_stats->value() ? true : false);
+ view_keypress->set_visible(draw_keypress->value() ? true : false);
+}
+
+/* -- namespace view ----------------------------------------------- */
+
+namespace view
+{
+
+core::Zone *current_zone = 0;
+
+void init()
+{
+ // FIXME integrate with libui
+ draw_ui = core::Cvar::get("draw_ui", "1", core::Cvar::Archive);
+ draw_ui->set_info("[bool] draw the user interface");
+
ui_pointercolor = core::Cvar::get("ui_pointercolor", "0 .5 0", core::Cvar::Archive);
ui_pointercolor->set_info("[r g b] mouse pointer color");
@@ -71,12 +235,6 @@ void init()
ui_pointerhovercolor->set_info("[r g b] mouse pointer hover color");
targets::init();
-
- for (size_t i =0; i < fps_counter_size; i++)
- fps_counter_time[i] = 0.0f;
-
- for (size_t i = 0; i < net_counter_size; i++)
- net_counter_traffic[i] = 0;
}
void shutdown()
@@ -108,53 +266,7 @@ void clear_zone(core::Zone *zone)
zone->set_sky_texture(0);
}
}
-/*
-void draw_loader()
-{
- using namespace render;
-
- render::Textures::bind("bitmaps/loader");
-
- gl::begin(gl::Quads);
-
- glTexCoord2f(0.0f, 0.0f);
- gl::vertex(0,0, 0);
-
- glTexCoord2f(1.0f, 0.0f);
- gl::vertex(video::width,0,0);
-
- glTexCoord2f(1.0f, 1.0f);
- gl::vertex(video::width,video::height,0);
-
- glTexCoord2f(0.0f, 1.0f);
- gl::vertex(0,video::height,0);
-
- gl::end();
-}
-
-void draw_banner()
-{
- using namespace render;
- render::Textures::bind("bitmaps/banner");
-
- gl::begin(gl::Quads);
-
- glTexCoord2f(0.0f, 0.0f);
- gl::vertex(0,0, 0);
-
- glTexCoord2f(1.0f, 0.0f);
- gl::vertex(video::width,0,0);
-
- glTexCoord2f(1.0f, 1.0f);
- gl::vertex(video::width,video::height,0);
-
- glTexCoord2f(0.0f, 1.0f);
- gl::vertex(0,video::height,0);
-
- gl::end();
-}
-*/
/*
FIXME should be merged with the render passes
and in the bbox pass
@@ -168,7 +280,6 @@ void draw_entity_world_target(core::Entity *entity)
if (!model)
return;
-
if (!model->docks().size())
return;
@@ -375,65 +486,8 @@ void draw_entity_target(core::Entity *entity, bool is_active_target)
void draw_status()
{
using namespace render;
-
std::stringstream status;
- if (core::game() && core::game()->interactive()) {
- int minutes = (int) floorf(core::game()->clientframetime() / 60.0f);
- int seconds = (int) floorf( core::game()->clientframetime() - (float) minutes* 60.0f);
-
- status << "^Ntime ^B" << std::setfill(' ') << std::setw(3) << minutes << ":" << std::setfill('0') << std::setw(2) << seconds;
- Text::draw(video::width-Text::fontwidth()*12-4, Text::fontheight()+ 4, status);
- }
-
- // print stats if desired
- if (draw_stats && draw_stats->value()) {
- // average fps
- fps_counter_time[fps_counter_index] = core::application()->time();
- fps_counter_index = (fps_counter_index + 1 ) % fps_counter_size;
- float min_time = core::application()->time();
- for (size_t i=0; i < fps_counter_size; i++)
- if (fps_counter_time[i] < min_time)
- min_time = fps_counter_time[i];
- float fps = 0.0f;
- float t = (core::application()->time() - min_time);
- if (t > 0) {
- fps = roundf(((float) fps_counter_size - 1.0f) / t);
- }
-
- std::stringstream stats;
- stats << "^Nfps ^B" << std::setw(6) << fps << "\n";
-
- if (core::application()->connected()) {
- stats << "^Ntris ^B" << std::setw(5) << render::Stats::tris << "\n";
- stats << "^Nquads ^B" << std::setw(5) << render::Stats::quads << "\n";
-
- if (core::Stats::network_bytes_sent + core::Stats::network_bytes_received) {
- net_counter_traffic[net_counter_index] = core::Stats::network_bytes_sent + core::Stats::network_bytes_received;
- net_counter_time[net_counter_index] = core::application()->time();
- size_t index_max = net_counter_index;
-
- net_counter_index = (net_counter_index + 1) % net_counter_size;
- size_t index_min = net_counter_index;
-
- float d = net_counter_time[index_max] - net_counter_time[index_min];
- if (d > 0) {
- float traffic = net_counter_traffic[index_max] - net_counter_traffic[index_min];
-
- stats << "^Nnet ^B" << std::setw(6) << roundf( (float) traffic / d ) << "\n";
- }
- }
- }
-
- Text::draw(video::width-Text::fontwidth()*12-4, 4 + Text::fontheight()*2, stats);
- }
-
- // draw keypress
- if (draw_keypress->value() && input::last_key_pressed()) {
- Text::setcolor('F'); //set fancy color
- Text::draw(video::width-4-Text::fontwidth()*6, video::height-Text::fontheight()-4, input::last_key_pressed()->name());
- }
-
// draw a basic HUD
if (core::localcontrol() && core::localcontrol()->zone()) {
core::Zone *zone = core::localcontrol()->zone();
@@ -477,7 +531,7 @@ void draw_status()
if (target) {
d = math::distance(core::localcontrol()->location(), target->state()->location()) - target->radius() - core::localcontrol()->radius();
}
-
+/*
if (draw_devinfo->value()) {
std::stringstream devinfo;
devinfo << std::fixed << std::setprecision(2)
@@ -491,7 +545,7 @@ void draw_status()
devinfo << "^Ndist:^B " << d << '\n';
Text::draw(4, 4 + Text::fontheight(), devinfo);
}
-
+*/
float y = 1.0f;
if (target) {
std::stringstream strtarget;
diff --git a/src/client/view.h b/src/client/view.h
index 1f81597..e5e42bc 100644
--- a/src/client/view.h
+++ b/src/client/view.h
@@ -7,12 +7,79 @@
#define __INCLUDED_CLIENT_VIEW_H__
#include "core/zone.h"
+#include "ui/widget.h"
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
+class DevInfo : public ui::Widget
+{
+public:
+ // default constructor
+ DevInfo(ui::Widget *parent = 0);
+
+protected:
+ // draw developer info
+ void draw();
+};
+
+// a widget that shows engine statistics
+class Stats : public ui::Widget
+{
+public:
+ // default constructor
+ Stats(ui::Widget *parent=0);
+
+protected:
+ // draw engine statistics
+ virtual void draw();
+
+private:
+ float fps_counter_time[fps_counter_size];
+ size_t fps_counter_index;
+
+ float net_counter_time[net_counter_size];
+ size_t net_counter_traffic[net_counter_size];
+ size_t net_counter_index;
+};
+
+/// a widget to show keypress events
+class KeyPress : public ui::Widget
+{
+public:
+ // default constructor
+ KeyPress(ui::Widget *parent=0);
+
+protected:
+ // draw keypress events
+ virtual void draw();
+};
+
+/// the client view widget
+/**
+* the client view renders the world and contains the main user interface widgets
+*/
+class View : public ui::Widget
+{
+public:
+ View(ui::Widget *parent=0);
+
+protected:
+ virtual void draw();
+ virtual void resize();
+
+private:
+ DevInfo *view_devinfo;
+ Stats *view_stats;
+ KeyPress *view_keypress;
+};
+
/// functions to draw the client view
-namespace view
+namespace view
{
/// intialize the view
void init();