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>2009-01-26 20:18:22 +0000
committerStijn Buys <ingar@osirion.org>2009-01-26 20:18:22 +0000
commit597b3e0921dd24fa5e224377da4754da93a782c1 (patch)
treea096cf3ade876d09dcdf5501908fe24efc50539f
parent60749486f978b8220b707541cf478fc87d8d0b36 (diff)
new widgets to replace the "View" class
-rw-r--r--src/client/infowidget.cc179
-rw-r--r--src/client/infowidget.h65
-rw-r--r--src/client/playerview.cc104
-rw-r--r--src/client/playerview.h51
-rw-r--r--src/client/worldview.cc85
-rw-r--r--src/client/worldview.h43
6 files changed, 527 insertions, 0 deletions
diff --git a/src/client/infowidget.cc b/src/client/infowidget.cc
new file mode 100644
index 0000000..433ee64
--- /dev/null
+++ b/src/client/infowidget.cc
@@ -0,0 +1,179 @@
+/*
+ client/infowidget.cc
+ This file is part of the Osirion project and is distributed under
+ the terms and conditions of the GNU General Public License version 2
+*/
+
+#include <iostream>
+#include <string>
+#include <sstream>
+#include <iomanip>
+
+#include "auxiliary/functions.h"
+#include "client/infowidget.h"
+#include "client/client.h"
+#include "client/input.h"
+#include "client/targets.h"
+#include "render/render.h"
+#include "core/stats.h"
+#include "math/mathlib.h"
+#include "sys/sys.h"
+#include "ui/paint.h"
+#include "ui/ui.h"
+#include "ui/widget.h"
+
+namespace client
+{
+
+void time_to_stream(std::stringstream &str, float time)
+{
+ int minutes = (int) floorf(time / 60.0f);
+ int seconds = (int) floorf( time - (float) minutes* 60.0f);
+ str << std::setfill(' ') << std::setw(4) << minutes << ":" << std::setfill('0') << std::setw(2) << seconds;
+}
+
+/* -- DevInfoWidget ------------------------------------------------ */
+
+DevInfoWidget::DevInfoWidget(ui::Widget *parent) : ui::Widget(parent)
+{
+ set_label("devinfo");
+ set_border(false);
+ set_background(false);
+}
+
+void DevInfoWidget::draw()
+{
+ std::stringstream textstream;
+ core::Entity *target = targets::current();
+ float d = 0;
+
+ textstream << "^Ncore ^B";
+ time_to_stream(textstream, core::application()->time());
+ textstream << '\n';
+ if (core::game()) {
+ textstream << "^Ntime ^B";
+ time_to_stream(textstream, core::game()->time());
+ }
+ textstream << '\n';
+
+ 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->location()) - target->radius() - core::localcontrol()->radius();
+ textstream << "^Ndist ^B" << d << '\n';
+ }
+ }
+
+ ui::paint::color(palette()->foreground());
+ ui::paint::text(global_location(), size(), font(), textstream);
+}
+
+/* -- StatsInfoWidget ---------------------------------------------- */
+
+StatsInfoWidget::StatsInfoWidget(ui::Widget *parent) : ui::Widget(parent)
+{
+ set_label("stats");
+ set_border(false);
+ set_background(false);
+
+ // 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;
+
+ net_counter_index = 0;
+ fps_counter_index = 0;
+}
+
+void StatsInfoWidget::draw()
+{
+ // 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()) {
+ textstream << "^Ntime ^B";
+ time_to_stream(textstream, core::game()->time());
+ }
+
+ 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(), size(), font(), textstream);
+}
+
+/* -- KeyInfoWidget ------------------------------------------------ */
+
+KeyInfoWidget::KeyInfoWidget(ui::Widget *parent) : Widget(parent)
+{
+ set_label("keypress");
+ set_border(false);
+ set_background(false);
+}
+
+void KeyInfoWidget::draw()
+{
+ std::string label;
+ ui::paint::color(palette()->highlight());
+
+ Key::Modifier mod = input::modifier();
+ if (mod != Key::None) {
+ if (mod == Key::Shift)
+ label.assign("shift+");
+ else if (mod == Key::Ctrl)
+ label.assign("ctrl+");
+ else if (mod == Key::Alt)
+ label.assign("alt+");
+ }
+
+ if(input::last_key_pressed()) {
+ label.append(input::last_key_pressed()->name());
+ }
+
+ if (label.size())
+ ui::paint::label(global_location(), size(), font(), label , ui::AlignCenter);
+}
+
+}
+
diff --git a/src/client/infowidget.h b/src/client/infowidget.h
new file mode 100644
index 0000000..2cea366
--- /dev/null
+++ b/src/client/infowidget.h
@@ -0,0 +1,65 @@
+/*
+ client/infowidget.h
+ This file is part of the Osirion project and is distributed under
+ the terms and conditions of the GNU General Public License version 2
+*/
+
+#ifndef __INCLUDED_CLIENT_INFOWIDGET_H__
+#define __INCLUDED_CLIENT_INFOWIDGET_H__
+
+#include "ui/widget.h"
+#include "ui/bitmap.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 DevInfoWidget : public ui::Widget
+{
+public:
+ /// default constructor
+ DevInfoWidget(ui::Widget *parent = 0);
+
+protected:
+ /// draw developer info
+ virtual void draw();
+};
+
+/// a widget that shows engine statistics
+class StatsInfoWidget : public ui::Widget
+{
+public:
+ /// default constructor
+ StatsInfoWidget(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 KeyInfoWidget : public ui::Widget
+{
+public:
+ // default constructor
+ KeyInfoWidget(ui::Widget *parent=0);
+
+protected:
+ // draw keypress events
+ virtual void draw();
+};
+
+}
+
+#endif // __INCLUDED_CLIENT_INFOWIDGET_H__
diff --git a/src/client/playerview.cc b/src/client/playerview.cc
new file mode 100644
index 0000000..586a836
--- /dev/null
+++ b/src/client/playerview.cc
@@ -0,0 +1,104 @@
+/*
+ client/playerview.cc
+ This file is part of the Osirion project and is distributed under
+ the terms and conditions of the GNU General Public License version 2
+*/
+
+#include "client/playerview.h"
+#include "ui/ui.h"
+
+namespace client {
+
+PlayerView::PlayerView(ui::Widget *parent)
+{
+ set_label("playerview");
+ set_border(false);
+ set_background(false);
+
+ label_zonename = new ui::Label(this);
+ label_zonename->set_alignment(ui::AlignCenter);
+ label_zonename->set_background(true);
+
+ label_viewname = new ui::Label(this);
+ label_viewname->set_alignment(ui::AlignCenter);
+ label_viewname->set_background(true);
+
+ view_notify = new Notifications(this);
+ view_chat = new Chat(this);
+ view_map = new Map(this);
+ view_hud = new HUD(this);
+ view_hud->lower();
+}
+
+PlayerView::~PlayerView()
+{
+}
+
+void PlayerView::clear()
+{
+ view_chat->clear();
+ view_notify->clear();
+
+ view_chat->hide();
+ view_map->hide();
+}
+
+void PlayerView::event_text(const std::string & text)
+{
+ view_chat->event_text(text);
+ view_notify->event_text(text);
+}
+
+void PlayerView::resize()
+{
+ //const float largemargin = ui::UI::elementsize.width() * 0.25;
+ const float smallmargin = ui::UI::elementsize.height();
+
+ set_size(parent()->size());
+
+ // set hud geometry
+ view_hud->set_geometry(0,0, width(), height());
+ view_hud->event_resize();
+
+ // reposition map
+ view_map->set_size(width() - smallmargin * 2, height() - smallmargin * 4);
+ view_map->set_location(smallmargin, smallmargin * 2);
+
+ // reposition notifications
+ view_notify->set_geometry(view_map->location(), view_map->size());
+
+ // reposition labels
+ label_viewname->set_size(ui::UI::elementsize.width(), ui::UI::elementsize.height());
+ label_viewname->set_location(smallmargin, smallmargin * 0.5f);
+
+ label_zonename->set_size(ui::UI::elementsize.width(), ui::UI::elementsize.height());
+ label_zonename->set_location(width() - label_zonename->width() - smallmargin, height() - label_zonename->height() - smallmargin * 0.5f);
+}
+
+void PlayerView::draw()
+{
+ //const float largemargin = ui::UI::elementsize.width() * 0.25;
+ const float smallmargin = ui::UI::elementsize.height();
+
+ // reposition chat widget
+ if (view_chat->small_view()) {
+ view_chat->set_size(width() - smallmargin * 2, font()->height() * 2);
+ view_chat->set_location(smallmargin, height() - smallmargin *2 - view_chat->height());
+ } else {
+ view_chat->set_geometry(view_map->location(), view_map->size());
+ }
+ view_chat->event_resize();
+
+ if (core::localplayer()->view()) {
+ label_viewname->show();
+ label_zonename->show();
+ } else {
+ label_viewname->hide();
+ label_zonename->set_visible(view_map->visible());
+ }
+
+ if (label_zonename->visible())
+ label_zonename->set_text(core::localplayer()->zone()->name());
+}
+
+}
diff --git a/src/client/playerview.h b/src/client/playerview.h
new file mode 100644
index 0000000..e5cb238
--- /dev/null
+++ b/src/client/playerview.h
@@ -0,0 +1,51 @@
+/*
+ client/playerview.h
+ This file is part of the Osirion project and is distributed under
+ the terms and conditions of the GNU General Public License version 2
+*/
+
+#ifndef __INCLUDED_CLIENT_PLAYERVIEW_H__
+#define __INCLUDED_CLIENT_PLAYERVIEW_H__
+
+#include "client/chat.h"
+#include "client/hud.h"
+#include "client/map.h"
+#include "client/notifications.h"
+#include "ui/widget.h"
+#include "ui/label.h"
+
+namespace client {
+
+/// the player's view when joined
+class PlayerView : public ui::Widget
+{
+public:
+ PlayerView(ui::Widget *parent = 0);
+ virtual ~PlayerView();
+
+ void clear();
+
+ void event_text(const std::string & text);
+
+ inline Map *map() { return view_map; }
+ inline Chat *chat() { return view_chat; }
+ inline Notifications *notify() { return view_notify; }
+
+protected:
+ virtual void draw();
+ virtual void resize();
+private:
+ Notifications *view_notify;
+ HUD *view_hud;
+ Chat *view_chat;
+ Map *view_map;
+
+ ui::Label *label_zonename;
+ ui::Label *label_viewname;
+
+};
+
+}
+
+
+#endif // __INCLUDED_CLIENT_PLAYERVIEW_H__ \ No newline at end of file
diff --git a/src/client/worldview.cc b/src/client/worldview.cc
new file mode 100644
index 0000000..ae16e33
--- /dev/null
+++ b/src/client/worldview.cc
@@ -0,0 +1,85 @@
+/*
+ client/worldview.cc
+ This file is part of the Osirion project and is distributed under
+ the terms and conditions of the GNU General Public License version 2
+*/
+
+#include "core/application.h"
+#include "client/worldview.h"
+#include "client/video.h"
+#include "ui/ui.h"
+
+namespace client {
+
+WorldView::WorldView(ui::Widget *parent)
+{
+ set_label("worldview");
+ set_border(false);
+ set_background(false);
+
+ // add child widgets
+ view_devinfo = new DevInfoWidget(this);
+ view_statsinfo = new StatsInfoWidget(this);
+ view_keyinfo = new KeyInfoWidget(this);
+
+ view_playerview = new PlayerView(this);
+ view_playerview->raise();
+ view_playerview->hide();
+}
+
+WorldView::~WorldView()
+{
+
+}
+
+void WorldView::resize()
+{
+ set_size(parent()->size());
+
+ //const float largemargin = ui::UI::elementsize.width() * 0.25
+ const float smallmargin = ui::UI::elementsize.height();
+
+ // resize player view
+ view_playerview->set_size(size());
+
+ // reposition devinfo widget
+ view_devinfo->set_size(font()->width()*32, font()->height()*5);
+ view_devinfo->set_location(smallmargin, smallmargin);
+
+ // reposition stats widget
+ view_statsinfo->set_size(font()->width()*12, font()->height()*5);
+ view_statsinfo->set_location(width() - view_statsinfo->width() - smallmargin, smallmargin);
+
+ // reposition keypress widget
+ view_keyinfo->set_size(font()->width()*12, font()->height()*1);
+ view_keyinfo->set_location(width() - view_keyinfo->width() - smallmargin,
+ height() - view_keyinfo->height() - smallmargin);
+}
+
+void WorldView::clear()
+{
+ view_playerview->clear();
+}
+
+void WorldView::event_text(const std::string & text)
+{
+ view_playerview->event_text(text);
+}
+
+void WorldView::draw()
+{
+ // worldview is only drawn when the application is connected
+ // and the loader screen is not shown
+
+ view_devinfo->set_visible(draw_devinfo->value() ? true : false);
+ view_statsinfo->set_visible(draw_stats->value() ? true : false);
+ view_keyinfo->set_visible(draw_keypress->value() ? true : false);
+
+ if (ui::root()->active() || !core::game()->interactive() || !core::localcontrol()) {
+ view_playerview->hide();
+ } else {
+ view_playerview->show();
+ }
+}
+
+}
diff --git a/src/client/worldview.h b/src/client/worldview.h
new file mode 100644
index 0000000..a83fb81
--- /dev/null
+++ b/src/client/worldview.h
@@ -0,0 +1,43 @@
+/*
+ client/worldview.h
+ This file is part of the Osirion project and is distributed under
+ the terms and conditions of the GNU General Public License version 2
+*/
+
+#ifndef __INCLUDED_CLIENT_WORLDVIEW_H__
+#define __INCLUDED_CLIENT_WORLDVIEW_H__
+
+#include "ui/widget.h"
+#include "client/playerview.h"
+#include "client/infowidget.h"
+
+namespace client {
+
+/// the world view when connected
+class WorldView : public ui::Widget
+{
+public:
+ WorldView(ui::Widget *parent = 0);
+ virtual ~WorldView();
+
+ void clear();
+
+ void event_text(const std::string & text);
+
+ inline PlayerView *playerview() { return view_playerview; }
+
+protected:
+ virtual void draw();
+ virtual void resize();
+
+private:
+ DevInfoWidget *view_devinfo;
+ StatsInfoWidget *view_statsinfo;
+ KeyInfoWidget *view_keyinfo;
+ Notifications *view_notify;
+ PlayerView *view_playerview;
+};
+
+}
+
+#endif // __INCLUDED_CLIENT_PLAYERVIEW_H__ \ No newline at end of file