Skip to content

Instantly share code, notes, and snippets.

@thetooth
Created April 26, 2014 07:54
Show Gist options
  • Select an option

  • Save thetooth/11314391 to your computer and use it in GitHub Desktop.

Select an option

Save thetooth/11314391 to your computer and use it in GitHub Desktop.
#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