Improves InputWin to make chars more visible.
This commit is contained in:
parent
82442ecf9d
commit
7688f38dab
@ -15,10 +15,12 @@ namespace gj {
|
||||
class InputWindowElement : public iElement {
|
||||
public:
|
||||
struct Param {
|
||||
iAllocator* alloc;
|
||||
|
||||
UniqPtr<iInputMatcher> matcher;
|
||||
UniqPtr<iElementDriver> driver;
|
||||
|
||||
Scoreboard* scoreboard = nullptr;
|
||||
Scoreboard* scoreboard;
|
||||
|
||||
Period period;
|
||||
|
||||
@ -35,13 +37,14 @@ class InputWindowElement : public iElement {
|
||||
InputWindowElement(Param&& p) :
|
||||
iElement(p.period),
|
||||
matcher_(std::move(p.matcher)), drv_(std::move(p.driver)), sb_(p.scoreboard),
|
||||
text_(p.text), expects_(matcher_->expects()) {
|
||||
bg_(CreateEmptySquare_(p.alloc)), text_(p.text), expects_(matcher_->expects()) {
|
||||
param_["posX"] = 0.;
|
||||
param_["posY"] = 0.;
|
||||
param_["baseX"] = .5;
|
||||
}
|
||||
|
||||
void Update(Frame& frame, double t) override {
|
||||
/* consumes all input */
|
||||
for (auto c : frame.input) {
|
||||
if (matcher_->done()) break;
|
||||
if (matcher_->Input(c)) {
|
||||
@ -50,18 +53,40 @@ class InputWindowElement : public iElement {
|
||||
}
|
||||
++sb_->input;
|
||||
}
|
||||
|
||||
/* executes the driver to update parameters and takes them with cast */
|
||||
drv_->Update(param_, t);
|
||||
|
||||
const auto posX = (std::get<double>(param_["posX"])+1)/2;
|
||||
const auto posY = (std::get<double>(param_["posY"])+1)/2;
|
||||
const auto posX = std::get<double>(param_["posX"]);
|
||||
const auto posY = std::get<double>(param_["posY"]);
|
||||
const auto baseX = std::get<double>(param_["baseX"]);
|
||||
|
||||
const uint32_t posXi = static_cast<int32_t>(posX * frame.w);
|
||||
const uint32_t posYi = static_cast<int32_t>(posY * frame.h);
|
||||
const uint32_t posXi = static_cast<int32_t>((posX+1)/2 * frame.w);
|
||||
const uint32_t posYi = static_cast<int32_t>((posY+1)/2 * frame.h);
|
||||
|
||||
const uint32_t tbaseXi = static_cast<int32_t>(baseX * text_.width());
|
||||
const uint32_t ebaseXi = static_cast<int32_t>(baseX * expects_.width());
|
||||
|
||||
const double w = (4+std::max(text_.width(), expects_.width()))*1. / frame.w;
|
||||
const double h = 4. / frame.h;
|
||||
|
||||
/* calculates geometry of background rect
|
||||
* and sets alpha to negative to decrease colors of pixels surrounding the text */
|
||||
auto M = mat3{
|
||||
{w, 0, 0},
|
||||
{0, h, 0},
|
||||
{0, 0, 1},
|
||||
};
|
||||
M = ::linalg::mul(mat3{
|
||||
{1, 0, 0},
|
||||
{0, 1, 0},
|
||||
{posX, posY, 1},
|
||||
}, M);
|
||||
bg_.SetMatrix(M);
|
||||
bg_.SetAlpha(-.8f);
|
||||
frame.Add(&bg_);
|
||||
|
||||
/* calculates geometry of foreground text */
|
||||
text_.SetPosition(posXi-tbaseXi, posYi);
|
||||
expects_.SetPosition(posXi-ebaseXi, posYi+1);
|
||||
frame.Add(&text_);
|
||||
@ -85,10 +110,17 @@ class InputWindowElement : public iElement {
|
||||
|
||||
Scoreboard* sb_;
|
||||
|
||||
Text text_;
|
||||
Text expects_;
|
||||
Texture bg_;
|
||||
Text text_;
|
||||
Text expects_;
|
||||
|
||||
iElementDriver::Param param_;
|
||||
|
||||
static Colorbuffer CreateEmptySquare_(iAllocator* alloc) {
|
||||
auto buf = Colorbuffer(alloc, 1, 1);
|
||||
buf.ptr()[0] = 1;
|
||||
return std::move(buf);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
@ -29,6 +29,7 @@ class InputWindowElementFactory : public iElementFactory {
|
||||
const std::string kana = std::get<std::string>(param.custom[1]);
|
||||
|
||||
InputWindowElement::Param p;
|
||||
p.alloc = alloc_;
|
||||
p.period = param.period;
|
||||
p.scoreboard = sb_;
|
||||
p.driver = std::move(param.driver);
|
||||
|
Reference in New Issue
Block a user