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 /src/client/infowidget.cc
parent60749486f978b8220b707541cf478fc87d8d0b36 (diff)
new widgets to replace the "View" class
Diffstat (limited to 'src/client/infowidget.cc')
-rw-r--r--src/client/infowidget.cc179
1 files changed, 179 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);
+}
+
+}
+