Skip to content

Commit

Permalink
set up some dummy gui widgets to act as shortcut targets for switchin…
Browse files Browse the repository at this point in the history
…g cameras, avoiding constant repeats and further abuse of the Draw method. closes pioneerspacesim#949
  • Loading branch information
robn committed Feb 7, 2012
1 parent da5156d commit 457aa8a
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 15 deletions.
45 changes: 30 additions & 15 deletions src/ShipCpanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,23 @@
#include "Lang.h"
#include "Game.h"

class CameraSwitchWidget : public Gui::Widget {
public:
CameraSwitchWidget(ShipCpanel *panel, WorldView::CamType camType) : m_panel(panel), m_camType(camType) {}

virtual void Draw() {}
virtual void GetSizeRequested(float size[2]) { size[0] = size[1] = 0.0f; }

virtual void OnActivate() {
if (Pi::GetView() == Pi::worldView)
m_panel->SwitchToCamera(m_camType);
}

private:
ShipCpanel *m_panel;
WorldView::CamType m_camType;
};

ShipCpanel::ShipCpanel(): Gui::Fixed(float(Gui::Screen::GetWidth()), 80)
{
m_scanner = new ScannerWidget();
Expand Down Expand Up @@ -174,6 +191,19 @@ void ShipCpanel::InitObject()
Add(img, 780, 37);
m_alertLights[2] = img;

CameraSwitchWidget *camSwitcher = new CameraSwitchWidget(this, WorldView::CAM_FRONT);
camSwitcher->SetShortcut(SDLK_1, KMOD_LSHIFT);
Add(camSwitcher,0,0);
camSwitcher = new CameraSwitchWidget(this, WorldView::CAM_REAR);
camSwitcher->SetShortcut(SDLK_2, KMOD_LSHIFT);
Add(camSwitcher,0,0);
camSwitcher = new CameraSwitchWidget(this, WorldView::CAM_EXTERNAL);
camSwitcher->SetShortcut(SDLK_3, KMOD_LSHIFT);
Add(camSwitcher,0,0);
camSwitcher = new CameraSwitchWidget(this, WorldView::CAM_SIDEREAL);
camSwitcher->SetShortcut(SDLK_4, KMOD_LSHIFT);
Add(camSwitcher,0,0);

m_connOnDockingClearanceExpired =
Pi::onDockingClearanceExpired.connect(sigc::mem_fun(this, &ShipCpanel::OnDockingClearanceExpired));
}
Expand Down Expand Up @@ -260,21 +290,6 @@ void ShipCpanel::Draw()
HideMapviewButtons();
}

if (cur == Pi::worldView) {
// XXX committing this atrocity because we don't really have a good
// way to trap arbitrary keypresses and/or set multiple shortcut keys
if (Pi::KeyState(SDLK_LSHIFT) || Pi::KeyState(SDLK_RSHIFT)) {
if (Pi::KeyState(SDLK_1))
SwitchToCamera(WorldView::CAM_FRONT);
else if (Pi::KeyState(SDLK_2))
SwitchToCamera(WorldView::CAM_REAR);
else if (Pi::KeyState(SDLK_3))
SwitchToCamera(WorldView::CAM_EXTERNAL);
else if (Pi::KeyState(SDLK_4))
SwitchToCamera(WorldView::CAM_SIDEREAL);
}
}

Gui::Fixed::Draw();
}

Expand Down
3 changes: 3 additions & 0 deletions src/ShipCpanel.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,11 @@

class Body;
class SpaceStation;
class CameraSwitchWidget;

class ShipCpanel: public Gui::Fixed {
friend class CameraSwitchWidget;

public:
ShipCpanel();
ShipCpanel(Serializer::Reader &rd);
Expand Down

0 comments on commit 457aa8a

Please sign in to comment.