diff options
| author | Simon Robertshaw <simon@hardwired.org.uk> | 2012-01-17 20:46:06 (GMT) |
|---|---|---|
| committer | Simon Robertshaw <simon@hardwired.org.uk> | 2012-01-17 20:46:06 (GMT) |
| commit | 4a60b97c700c2f1843b7e99313554cb89fb5da4e (patch) | |
| tree | 3b33ef6f74a4e8a4ff5968a81b9c4c429ccaa7c6 /src/game/GameView.cpp | |
| parent | 6273089bf486bf46ad325d72c7290ebb272bd3d8 (diff) | |
| download | powder-4a60b97c700c2f1843b7e99313554cb89fb5da4e.zip powder-4a60b97c700c2f1843b7e99313554cb89fb5da4e.tar.gz | |
Some minor changes
Diffstat (limited to 'src/game/GameView.cpp')
| -rw-r--r-- | src/game/GameView.cpp | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/src/game/GameView.cpp b/src/game/GameView.cpp new file mode 100644 index 0000000..2576527 --- /dev/null +++ b/src/game/GameView.cpp @@ -0,0 +1,83 @@ +#include "Config.h" +#include "GameView.h" +#include "interface/Window.h" +#include "interface/Button.h" + +GameView::GameView(): + ui::Window(ui::Point(0, 0), ui::Point(XRES+BARSIZE, YRES+MENUSIZE)), + pointQueue(queue<ui::Point*>()), + isMouseDown(false), + ren(NULL) +{ + //Set up UI + class PauseAction : public ui::ButtonAction + { + GameView * v; + public: + PauseAction(GameView * _v) { v = _v; } + void ActionCallback(ui::Button * sender) + { + v->c->SetPaused(sender->GetToggleState()); + } + }; + pauseButton = new ui::Button(ui::Point(Size.X-18, Size.Y-18), ui::Point(16, 16), "\x90"); //Pause + pauseButton->SetTogglable(true); + pauseButton->SetActionCallback(new PauseAction(this)); + AddComponent(pauseButton); +} + +void GameView::NotifyRendererChanged(GameModel * sender) +{ + ren = sender->GetRenderer(); +} + +void GameView::NotifySimulationChanged(GameModel * sender) +{ + +} + +void GameView::NotifyPausedChanged(GameModel * sender) +{ + pauseButton->SetToggleState(sender->GetPaused()); +} + +void GameView::OnMouseMove(int x, int y, int dx, int dy) +{ + if(isMouseDown) + { + pointQueue.push(new ui::Point(x-dx, y-dy)); + pointQueue.push(new ui::Point(x, y)); + } +} + +void GameView::OnMouseDown(int x, int y, unsigned button) +{ + isMouseDown = true; + pointQueue.push(new ui::Point(x, y)); +} + +void GameView::OnMouseUp(int x, int y, unsigned button) +{ + if(isMouseDown) + { + isMouseDown = false; + pointQueue.push(new ui::Point(x, y)); + } +} + +void GameView::OnTick(float dt) +{ + if(!pointQueue.empty()) + { + c->DrawPoints(pointQueue); + } + c->Tick(); +} + +void GameView::OnDraw() +{ + if(ren) + { + ren->render_parts(); + } +} |
