Created
April 26, 2014 07:54
-
-
Save thetooth/11314391 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #pragma once | |
| #include <kami.h> | |
| class Dialog { | |
| public: | |
| float time, duration; | |
| std::wstring buffer, target; | |
| klib::Point<int> pos; | |
| klib::Font font; | |
| Dialog() = default; | |
| ~Dialog() = default; | |
| void Create(int x, int y, const char* fontName){ | |
| pos.x = x; | |
| pos.y = y; | |
| font.Load(fontName); | |
| } | |
| void SetText(std::wstring str, float duration_){ | |
| time = 0.0f; | |
| duration = duration_; | |
| target = std::move(str); | |
| buffer.clear(); | |
| buffer.resize(target.size()); | |
| } | |
| void Draw(glm::mat4 projection, double dt){ | |
| auto tNormal = time / duration; | |
| if (tNormal < 1.0){ | |
| buffer = target.substr(0, std::floor(tNormal*target.size())); | |
| time += dt; | |
| } | |
| font.Draw(projection, pos.x, pos.y, buffer.c_str()); | |
| } | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment