2016-06-19 17:10:52 +00:00
|
|
|
//
|
|
|
|
// Typer.hpp
|
|
|
|
// Clock Signal
|
|
|
|
//
|
|
|
|
// Created by Thomas Harte on 19/06/2016.
|
|
|
|
// Copyright © 2016 Thomas Harte. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
#ifndef Typer_hpp
|
|
|
|
#define Typer_hpp
|
|
|
|
|
|
|
|
#include <memory>
|
|
|
|
|
|
|
|
namespace Utility {
|
|
|
|
|
|
|
|
class Typer {
|
|
|
|
public:
|
|
|
|
class Delegate {
|
|
|
|
public:
|
2016-06-19 17:46:53 +00:00
|
|
|
virtual bool typer_set_next_character(Typer *typer, char character, int phase) = 0;
|
2016-06-19 17:10:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
Typer(const char *string, int delay, int frequency, Delegate *delegate);
|
|
|
|
~Typer();
|
|
|
|
void update(int duration);
|
|
|
|
|
|
|
|
private:
|
|
|
|
char *_string;
|
|
|
|
int _frequency;
|
|
|
|
int _counter;
|
2016-06-19 17:46:53 +00:00
|
|
|
int _phase;
|
2016-06-19 17:10:52 +00:00
|
|
|
Delegate *_delegate;
|
|
|
|
size_t _string_pointer;
|
2016-06-19 17:46:53 +00:00
|
|
|
|
|
|
|
void type_next_character();
|
2016-06-19 17:10:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class TypeRecipient: public Typer::Delegate {
|
|
|
|
public:
|
|
|
|
void set_typer_for_string(const char *string)
|
|
|
|
{
|
2016-06-24 00:52:44 +00:00
|
|
|
_typer.reset(new Typer(string, get_typer_delay(), get_typer_frequency(), this));
|
2016-06-19 17:10:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual int get_typer_delay() = 0;
|
|
|
|
virtual int get_typer_frequency() = 0;
|
|
|
|
std::unique_ptr<Typer> _typer;
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* Typer_hpp */
|