Draw a green selection box around the current nav target in SystemView.

master
John Bartholomew 2011-10-18 21:19:29 +01:00
parent 54eeed9c3a
commit d200e7c9cc
2 changed files with 62 additions and 3 deletions

View File

@ -8,6 +8,8 @@
#include "Player.h"
#include "FloatComparison.h"
const double SystemView::PICK_OBJECT_RECT_SIZE = 12.0;
SystemView::SystemView()
{
m_system = 0;
@ -148,7 +150,7 @@ void SystemView::OnClickObject(SBody *b)
void SystemView::PutLabel(SBody *b, vector3d offset)
{
Gui::Screen::EnterOrtho();
vector3d pos;
if (Gui::Screen::Project(offset, pos)) {
// libsigc++ is a beautiful thing
@ -200,6 +202,53 @@ void SystemView::PutBody(SBody *b, vector3d offset)
}
}
void SystemView::PutSelectionBox(const SBody *b, const vector3d &rootPos, const Color &col)
{
// surface starports just show the planet as being selected,
// because SystemView doesn't render terrains anyway
if (b->type == SBody::TYPE_STARPORT_SURFACE)
b = b->parent;
assert(b);
vector3d pos = rootPos;
int i = 0;
// while (b->parent), not while (b) because the root SBody is defined to be at (0,0,0)
while (b->parent) {
pos += b->orbit.OrbitalPosAtTime(m_time) * double(m_zoom);
b = b->parent;
}
PutSelectionBox(pos, col);
}
void SystemView::PutSelectionBox(const vector3d &worldPos, const Color &col)
{
Gui::Screen::EnterOrtho();
vector3d screenPos;
if (Gui::Screen::Project(worldPos, screenPos)) {
// XXX copied from WorldView::DrawTargetSquare -- these should be unified
const float x1 = float(screenPos.x - SystemView::PICK_OBJECT_RECT_SIZE * 0.5);
const float x2 = float(x1 + SystemView::PICK_OBJECT_RECT_SIZE);
const float y1 = float(screenPos.y - SystemView::PICK_OBJECT_RECT_SIZE * 0.5);
const float y2 = float(y1 + SystemView::PICK_OBJECT_RECT_SIZE);
const GLfloat vtx[8] = {
x1, y1,
x2, y1,
x2, y2,
x1, y2
};
glColor4f(col.r, col.g, col.b, col.a);
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(2, GL_FLOAT, 0, vtx);
glDrawArrays(GL_LINE_LOOP, 0, 4);
glDisableClientState(GL_VERTEX_ARRAY);
}
Gui::Screen::LeaveOrtho();
}
static const GLfloat fogDensity = 0.1;
static const GLfloat fogColor[4] = { 0,0,0,1.0 };
@ -252,9 +301,16 @@ void SystemView::Draw3D()
m_objectLabels->Clear();
if (m_system->m_unexplored)
m_infoLabel->SetText(Lang::UNEXPLORED_SYSTEM_NO_SYSTEM_VIEW);
else if (m_system->rootBody)
else if (m_system->rootBody) {
PutBody(m_system->rootBody, pos);
if (Pi::currentSystem == m_system) {
const Body *navTarget = Pi::player->GetNavTarget();
const SBody *navTargetSBody = navTarget ? navTarget->GetSBody() : 0;
if (navTargetSBody)
PutSelectionBox(navTargetSBody, pos, Color(0.0, 1.0, 0.0, 1.0));
}
}
glEnable(GL_LIGHTING);
glDisable(GL_FOG);
}

View File

@ -16,9 +16,12 @@ public:
virtual void Draw3D();
virtual void OnSwitchTo() {}
private:
static const double PICK_OBJECT_RECT_SIZE;
void PutOrbit(SBody *b, vector3d offset);
void PutBody(SBody *b, vector3d offset);
void PutLabel(SBody *b, vector3d offset);
void PutSelectionBox(const SBody *b, const vector3d &rootPos, const Color &col);
void PutSelectionBox(const vector3d &worldPos, const Color &col);
void GetTransformTo(SBody *b, vector3d &pos);
void OnClickObject(SBody *b);
void OnClickAccel(float step);