Adds baseX property for InputWindowElement.
This commit is contained in:
parent
a07c61675e
commit
bc56befc8e
@ -19,7 +19,7 @@ class Frame : public iDrawable, public iWritable {
|
||||
Frame& operator=(Frame&&) = delete;
|
||||
Frame& operator=(const Frame&) = delete;
|
||||
|
||||
Frame(size_t dres, size_t wres) {
|
||||
Frame(uint32_t w, uint32_t h, size_t dres, size_t wres) : w(w), h(h) {
|
||||
draw_.reserve(dres);
|
||||
write_.reserve(wres);
|
||||
}
|
||||
@ -49,6 +49,8 @@ class Frame : public iDrawable, public iWritable {
|
||||
|
||||
std::string input;
|
||||
|
||||
uint32_t w, h;
|
||||
|
||||
private:
|
||||
std::vector<const iDrawable*> draw_;
|
||||
std::vector<const iWritable*> write_;
|
||||
|
@ -7,7 +7,7 @@ gj::Game::Game(gj::Game::Param&& p) :
|
||||
clock_(p.clock),
|
||||
logger_(p.h),
|
||||
w_(p.w), h_(p.h),
|
||||
frame_(kReserveDrawable, kReserveWritable) {
|
||||
frame_(p.w, p.h, kReserveDrawable, kReserveWritable) {
|
||||
gj::PlayScene::Param param;
|
||||
param.alloc = alloc_;
|
||||
param.clock = &clock_;
|
||||
|
@ -32,9 +32,10 @@ class InputWindowElement : public iElement {
|
||||
InputWindowElement(Param&& p) :
|
||||
iElement(p.period),
|
||||
matcher_(std::move(p.matcher)), drv_(std::move(p.driver)),
|
||||
text_(p.text), guide_(matcher_->expects()) {
|
||||
param_["posX"] = 0;
|
||||
param_["posY"] = 0;
|
||||
text_(p.text), guide_(matcher_->expects()), width_(CountWstrBytes(p.text)) {
|
||||
param_["posX"] = 0.;
|
||||
param_["posY"] = 0.;
|
||||
param_["baseX"] = .5;
|
||||
}
|
||||
|
||||
void Update(Frame& frame, double t) override {
|
||||
@ -46,11 +47,16 @@ class InputWindowElement : public iElement {
|
||||
}
|
||||
drv_->Update(param_, t);
|
||||
|
||||
const auto posX = std::get<intmax_t>(param_["posX"]);
|
||||
const auto posY = std::get<intmax_t>(param_["posY"]);
|
||||
const auto posX = (std::get<double>(param_["posX"])+1)/2;
|
||||
const auto posY = (std::get<double>(param_["posY"])+1)/2;
|
||||
const auto baseX = std::get<double>(param_["baseX"]);
|
||||
|
||||
text_.SetPosition(posX, posY);
|
||||
guide_.SetPosition(posX, posY+1);
|
||||
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 baseXi = static_cast<int32_t>(baseX * width_);
|
||||
|
||||
text_.SetPosition(posXi-baseXi, posYi);
|
||||
guide_.SetPosition(posXi-baseXi, posYi+1);
|
||||
frame.Add(&text_);
|
||||
frame.Add(&guide_);
|
||||
}
|
||||
@ -66,6 +72,8 @@ class InputWindowElement : public iElement {
|
||||
Text text_;
|
||||
Text guide_;
|
||||
|
||||
size_t width_;
|
||||
|
||||
iElementDriver::Param param_;
|
||||
};
|
||||
|
||||
|
@ -1,5 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <cmath>
|
||||
|
||||
#include "iElement.h"
|
||||
#include "iElementDriver.h"
|
||||
#include "Texture.h"
|
||||
@ -22,6 +24,7 @@ public:
|
||||
param_["posY"] = 0.;
|
||||
param_["scaleX"] = 1.;
|
||||
param_["scaleY"] = 1.;
|
||||
param_["rota"] = 0.;
|
||||
param_["alpha"] = 1.;
|
||||
}
|
||||
|
||||
@ -32,13 +35,38 @@ public:
|
||||
const double posY = std::get<double>(param_["posY"]);
|
||||
const double scaleX = std::get<double>(param_["scaleX"]);
|
||||
const double scaleY = std::get<double>(param_["scaleY"]);
|
||||
const double rota = std::get<double>(param_["rota"]);
|
||||
const double alpha = std::get<double>(param_["alpha"]);
|
||||
|
||||
tex_.SetMatrix(mat3{
|
||||
{ scaleX, 0, 0 },
|
||||
{ 0, scaleY, 0 },
|
||||
{ posX, posY, 1},
|
||||
});
|
||||
const double c = std::cos(rota);
|
||||
const double s = std::sin(rota);
|
||||
|
||||
const double aspect = frame.w*1./frame.h;
|
||||
auto Ms = mat3{
|
||||
{ scaleX, 0, 0 },
|
||||
{ 0, scaleY, 0 },
|
||||
{ 0, 0, 1},
|
||||
};
|
||||
auto Mr = mat3{
|
||||
{ c, -s, 0, },
|
||||
{ s, c, 0, },
|
||||
{ 0, 0, 1, },
|
||||
};
|
||||
auto Mm = mat3{
|
||||
{ 1, 0, 0 },
|
||||
{ 0, 1, 0 },
|
||||
{ posX, posY, 1},
|
||||
};
|
||||
auto M = mat3{
|
||||
{ 1, 0, 0 },
|
||||
{ 0, aspect/2, 0 },
|
||||
{ 0, 0, 1},
|
||||
};
|
||||
M = ::linalg::mul(M, Mm);
|
||||
M = ::linalg::mul(M, Mr);
|
||||
M = ::linalg::mul(M, Ms);
|
||||
|
||||
tex_.SetMatrix(M);
|
||||
tex_.SetAlpha(static_cast<float>(alpha));
|
||||
|
||||
frame.Add(&tex_);
|
||||
|
@ -30,6 +30,14 @@ static inline std::wstring ConvertStrToWstr(const std::string& str) {
|
||||
}
|
||||
}
|
||||
|
||||
static inline size_t CountWstrBytes(const std::wstring& str) {
|
||||
size_t n = 0;
|
||||
for (const auto c : str) {
|
||||
n += c > UINT8_MAX? 2: 1;
|
||||
}
|
||||
return n;
|
||||
}
|
||||
|
||||
|
||||
[[noreturn]]
|
||||
static inline void Abort(const std::string& msg) {
|
||||
|
Reference in New Issue
Block a user