diff options
| author | Simon Robertshaw <simon@hardwired.org.uk> | 2012-01-31 18:49:14 (GMT) |
|---|---|---|
| committer | Simon Robertshaw <simon@hardwired.org.uk> | 2012-01-31 18:49:14 (GMT) |
| commit | 857b0cc1fc58f066acd59404d16ee5e566e20f00 (patch) | |
| tree | 7607fc43f3bdd63687dff39209f44defa48e6a35 /src/interface | |
| parent | 1d297cb57a338f2a9e34d0f16642afc6a83c1041 (diff) | |
| download | powder-857b0cc1fc58f066acd59404d16ee5e566e20f00.zip powder-857b0cc1fc58f066acd59404d16ee5e566e20f00.tar.gz | |
Load user information from preferences, fps display for testing
Diffstat (limited to 'src/interface')
| -rw-r--r-- | src/interface/Engine.cpp | 15 | ||||
| -rw-r--r-- | src/interface/Engine.h | 6 | ||||
| -rw-r--r-- | src/interface/Textbox.cpp | 31 | ||||
| -rw-r--r-- | src/interface/Textbox.h | 1 |
4 files changed, 37 insertions, 16 deletions
diff --git a/src/interface/Engine.cpp b/src/interface/Engine.cpp index 01a3e72..c4833d1 100644 --- a/src/interface/Engine.cpp +++ b/src/interface/Engine.cpp @@ -124,7 +124,7 @@ void Engine::SetSize(int width, int height) height_ = height; } -void Engine::Tick(float dt) +void Engine::Tick() { if(state_ != NULL) state_->DoTick(dt); @@ -175,9 +175,22 @@ void Engine::Draw() } if(state_) state_->DoDraw(); + + char fpsText[512]; + sprintf(fpsText, "FPS: %.2f, Delta: %.3f", fps, dt); + ui::Engine::Ref().g->drawtext(10, 10, fpsText, 255, 255, 255, 255); g->Blit(); } +void Engine::SetFps(float fps) +{ + this->fps = fps; + if(FpsLimit > 2.0f) + this->dt = FpsLimit/fps; + else + this->dt = 1.0f; +} + void Engine::onKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool alt) { if(state_) diff --git a/src/interface/Engine.h b/src/interface/Engine.h index 09fc222..b8f6b73 100644 --- a/src/interface/Engine.h +++ b/src/interface/Engine.h @@ -38,9 +38,11 @@ namespace ui inline bool Running() { return running_; } void Exit(); - void Tick(float dt); + void Tick(); void Draw(); + void SetFps(float fps); + inline int GetMouseX() { return mousex_; } inline int GetMouseY() { return mousey_; } inline int GetWidth() { return width_; } @@ -54,6 +56,8 @@ namespace ui float FpsLimit; Graphics * g; private: + float dt; + float fps; pixel * lastBuffer; std::stack<pixel*> prevBuffers; std::stack<Window*> windows; diff --git a/src/interface/Textbox.cpp b/src/interface/Textbox.cpp index 1a54992..5985ce1 100644 --- a/src/interface/Textbox.cpp +++ b/src/interface/Textbox.cpp @@ -18,6 +18,7 @@ Textbox::Textbox(Point position, Point size, std::string textboxText): actionCallback(NULL), masked(false) { + SetText(textboxText); TextPosition(); cursor = text.length(); } @@ -30,7 +31,7 @@ Textbox::~Textbox() void Textbox::TextPosition() { - std::string tempText = text; + std::string tempText = displayText; if(tempText.length() && cursor) { tempText.erase(cursor, tempText.length()-cursor); @@ -60,16 +61,27 @@ void Textbox::TextPosition() textPosition.X = 3; break; case AlignCentre: - textPosition.X = (Size.X-Graphics::textwidth((char *)text.c_str()))/2; + textPosition.X = (Size.X-Graphics::textwidth((char *)displayText.c_str()))/2; break; case AlignRight: - textPosition.X = (Size.X-Graphics::textwidth((char *)text.c_str()))-2; + textPosition.X = (Size.X-Graphics::textwidth((char *)displayText.c_str()))-2; break; } } void Textbox::SetText(std::string text) { + if(masked) + { + char tempText[text.length()]; + memset(tempText, 0x8d, text.length()); + tempText[text.length()] = 0; + displayText = tempText; + } + else + { + displayText = text; + } this->text = text; TextPosition(); } @@ -151,6 +163,7 @@ void Textbox::OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool cursor = 0; text = ""; } + SetText(text); TextPosition(); } @@ -166,15 +179,5 @@ void Textbox::Draw(const Point& screenPos) { g->drawrect(screenPos.X, screenPos.Y, Size.X, Size.Y, 160, 160, 160, 255); } - if(masked) - { - char tempText[text.length()]; - memset(tempText, 'a', text.length()); - tempText[text.length()] = 0; - g->drawtext(screenPos.X+textPosition.X, screenPos.Y+textPosition.Y, tempText, 255, 255, 255, 255); - } - else - { - g->drawtext(screenPos.X+textPosition.X, screenPos.Y+textPosition.Y, text, 255, 255, 255, 255); - } + g->drawtext(screenPos.X+textPosition.X, screenPos.Y+textPosition.Y, displayText, 255, 255, 255, 255); } diff --git a/src/interface/Textbox.h b/src/interface/Textbox.h index ac138f4..889a4e8 100644 --- a/src/interface/Textbox.h +++ b/src/interface/Textbox.h @@ -19,6 +19,7 @@ class Textbox : public Component { protected: std::string text; + std::string displayText; ui::Point textPosition; HorizontalAlignment textHAlign; VerticalAlignment textVAlign; |
