2020-09-21 17:17:34 +00:00
|
|
|
// SPDX-License-Identifier: MIT
|
2020-06-06 14:48:05 +00:00
|
|
|
//
|
2020-09-21 17:17:34 +00:00
|
|
|
// EmulationStation Desktop Edition
|
2020-06-21 12:25:28 +00:00
|
|
|
// DateTimeEditComponent.cpp
|
2020-06-06 14:48:05 +00:00
|
|
|
//
|
2020-06-21 12:25:28 +00:00
|
|
|
// Date and time edit component.
|
2020-06-06 14:48:05 +00:00
|
|
|
//
|
|
|
|
|
2021-10-08 17:38:14 +00:00
|
|
|
#define KEY_REPEAT_START_DELAY 600
|
|
|
|
#define KEY_REPEAT_SPEED 150 // Lower is faster.
|
|
|
|
|
2018-10-13 01:08:15 +00:00
|
|
|
#include "components/DateTimeEditComponent.h"
|
|
|
|
|
2021-07-07 18:31:46 +00:00
|
|
|
#include "Settings.h"
|
2018-10-13 01:08:15 +00:00
|
|
|
#include "resources/Font.h"
|
|
|
|
#include "utils/StringUtil.h"
|
|
|
|
|
2022-01-19 17:01:54 +00:00
|
|
|
DateTimeEditComponent::DateTimeEditComponent(bool alignRight, DisplayMode dispMode)
|
|
|
|
: mEditing {false}
|
2022-01-16 11:09:55 +00:00
|
|
|
, mEditIndex {0}
|
|
|
|
, mDisplayMode {dispMode}
|
|
|
|
, mKeyRepeatDir {0}
|
|
|
|
, mKeyRepeatTimer {0}
|
|
|
|
, mRelativeUpdateAccumulator {0}
|
|
|
|
, mColor {0x777777FF}
|
|
|
|
, mFont {Font::get(FONT_SIZE_SMALL, FONT_PATH_LIGHT)}
|
|
|
|
, mAlignRight {alignRight}
|
|
|
|
, mUppercase {false}
|
|
|
|
, mAutoSize {true}
|
2018-10-13 01:08:15 +00:00
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
updateTextCache();
|
2018-10-13 01:08:15 +00:00
|
|
|
}
|
|
|
|
|
2021-10-08 17:38:14 +00:00
|
|
|
void DateTimeEditComponent::onSizeChanged()
|
2018-10-13 01:08:15 +00:00
|
|
|
{
|
2021-10-08 17:38:14 +00:00
|
|
|
mAutoSize = false;
|
2020-06-21 12:25:28 +00:00
|
|
|
updateTextCache();
|
2018-10-13 01:08:15 +00:00
|
|
|
}
|
|
|
|
|
2021-10-08 17:38:14 +00:00
|
|
|
void DateTimeEditComponent::setValue(const std::string& val)
|
2018-10-13 01:08:15 +00:00
|
|
|
{
|
2021-10-08 17:38:14 +00:00
|
|
|
mTime = val;
|
|
|
|
mOriginalValue = val;
|
|
|
|
updateTextCache();
|
|
|
|
}
|
2020-06-21 12:25:28 +00:00
|
|
|
|
2021-10-08 17:38:14 +00:00
|
|
|
bool DateTimeEditComponent::input(InputConfig* config, Input input)
|
|
|
|
{
|
|
|
|
if (config->isMappedTo("a", input) && input.value) {
|
2020-06-21 12:25:28 +00:00
|
|
|
if (mDisplayMode != DISP_RELATIVE_TO_NOW) // Don't allow editing for relative times.
|
|
|
|
mEditing = !mEditing;
|
|
|
|
|
2021-10-08 17:38:14 +00:00
|
|
|
mKeyRepeatDir = 0;
|
|
|
|
|
2020-08-02 13:56:32 +00:00
|
|
|
// Change the color of the text to reflect the changes.
|
|
|
|
if (mTime == mOriginalValue)
|
|
|
|
setColor(mColorOriginalValue);
|
|
|
|
else
|
|
|
|
setColor(mColorChangedValue);
|
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
if (mEditing) {
|
|
|
|
// Started editing.
|
|
|
|
mTimeBeforeEdit = mTime;
|
|
|
|
|
2021-11-26 19:55:54 +00:00
|
|
|
// Initialize to the arbitrary value 1999-01-01 if unset.
|
|
|
|
if (mTime == 0) {
|
|
|
|
mTime = Utils::Time::stringToTime("19990101T000000");
|
2020-06-21 12:25:28 +00:00
|
|
|
updateTextCache();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-08 17:38:14 +00:00
|
|
|
updateHelpPrompts();
|
2020-06-21 12:25:28 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mEditing) {
|
2020-08-02 13:56:32 +00:00
|
|
|
|
2021-10-08 17:38:14 +00:00
|
|
|
if ((config->isMappedLike("lefttrigger", input) ||
|
|
|
|
config->isMappedLike("righttrigger", input))) {
|
|
|
|
mKeyRepeatDir = 0;
|
2020-08-02 13:56:32 +00:00
|
|
|
return true;
|
2021-07-07 18:31:46 +00:00
|
|
|
}
|
2020-08-02 13:56:32 +00:00
|
|
|
|
2021-10-08 17:38:14 +00:00
|
|
|
if (config->isMappedTo("y", input) && input.value) {
|
2020-06-21 12:25:28 +00:00
|
|
|
mEditing = false;
|
|
|
|
mTime = mTimeBeforeEdit;
|
2021-10-08 17:38:14 +00:00
|
|
|
mKeyRepeatDir = 0;
|
2020-06-21 12:25:28 +00:00
|
|
|
updateTextCache();
|
2021-10-08 17:38:14 +00:00
|
|
|
return false;
|
2020-06-21 12:25:28 +00:00
|
|
|
}
|
|
|
|
|
2021-10-08 17:38:14 +00:00
|
|
|
if (config->isMappedTo("b", input) && input.value) {
|
|
|
|
mEditing = false;
|
|
|
|
mTime = mTimeBeforeEdit;
|
|
|
|
mKeyRepeatDir = 0;
|
|
|
|
updateTextCache();
|
|
|
|
updateHelpPrompts();
|
|
|
|
return true;
|
|
|
|
}
|
2020-06-21 12:25:28 +00:00
|
|
|
|
2021-10-08 17:38:14 +00:00
|
|
|
if (config->isMappedLike("up", input) || config->isMappedLike("rightshoulder", input)) {
|
|
|
|
if (input.value) {
|
|
|
|
mKeyRepeatDir = 1;
|
|
|
|
mKeyRepeatTimer = -(KEY_REPEAT_START_DELAY - KEY_REPEAT_SPEED);
|
|
|
|
changeDate();
|
|
|
|
return true;
|
2020-06-21 12:25:28 +00:00
|
|
|
}
|
2021-10-08 17:38:14 +00:00
|
|
|
else {
|
|
|
|
mKeyRepeatDir = 0;
|
2020-06-21 12:25:28 +00:00
|
|
|
}
|
2021-10-08 17:38:14 +00:00
|
|
|
}
|
|
|
|
else if (config->isMappedLike("down", input) ||
|
|
|
|
config->isMappedLike("leftshoulder", input)) {
|
|
|
|
if (input.value) {
|
|
|
|
mKeyRepeatDir = -1;
|
|
|
|
mKeyRepeatTimer = -(KEY_REPEAT_START_DELAY - KEY_REPEAT_SPEED);
|
|
|
|
changeDate();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
mKeyRepeatDir = 0;
|
2020-06-21 12:25:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-08 17:38:14 +00:00
|
|
|
if (mTime != 0 && config->isMappedLike("right", input) && input.value) {
|
2021-11-17 16:48:49 +00:00
|
|
|
++mEditIndex;
|
2020-11-17 22:06:54 +00:00
|
|
|
if (mEditIndex >= static_cast<int>(mCursorBoxes.size()))
|
2021-11-17 16:48:49 +00:00
|
|
|
--mEditIndex;
|
2021-10-08 17:38:14 +00:00
|
|
|
mKeyRepeatDir = 0;
|
2020-06-21 12:25:28 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2021-10-08 17:38:14 +00:00
|
|
|
if (mTime != 0 && config->isMappedLike("left", input) && input.value) {
|
2021-11-17 16:48:49 +00:00
|
|
|
--mEditIndex;
|
2020-06-21 12:25:28 +00:00
|
|
|
if (mEditIndex < 0)
|
2021-11-17 16:48:49 +00:00
|
|
|
++mEditIndex;
|
2021-10-08 17:38:14 +00:00
|
|
|
mKeyRepeatDir = 0;
|
2020-06-21 12:25:28 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return GuiComponent::input(config, input);
|
2018-10-13 01:08:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DateTimeEditComponent::update(int deltaTime)
|
|
|
|
{
|
2021-10-08 17:38:14 +00:00
|
|
|
if (mKeyRepeatDir != 0) {
|
|
|
|
mKeyRepeatTimer += deltaTime;
|
|
|
|
while (mKeyRepeatTimer >= KEY_REPEAT_SPEED) {
|
|
|
|
mKeyRepeatTimer -= KEY_REPEAT_SPEED;
|
|
|
|
changeDate();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
if (mDisplayMode == DISP_RELATIVE_TO_NOW) {
|
|
|
|
mRelativeUpdateAccumulator += deltaTime;
|
|
|
|
if (mRelativeUpdateAccumulator > 1000) {
|
|
|
|
mRelativeUpdateAccumulator = 0;
|
|
|
|
updateTextCache();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
GuiComponent::update(deltaTime);
|
2018-10-13 01:08:15 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 17:30:31 +00:00
|
|
|
void DateTimeEditComponent::render(const glm::mat4& parentTrans)
|
2018-10-13 01:08:15 +00:00
|
|
|
{
|
2022-01-16 11:09:55 +00:00
|
|
|
glm::mat4 trans {parentTrans * getTransform()};
|
2018-10-13 01:08:15 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
if (mTextCache) {
|
2021-03-20 09:26:18 +00:00
|
|
|
std::shared_ptr<Font> font = getFont();
|
2022-01-16 11:09:55 +00:00
|
|
|
float referenceSize {0.0f};
|
2021-03-20 09:26:18 +00:00
|
|
|
|
2021-10-08 17:38:14 +00:00
|
|
|
if (mAlignRight)
|
|
|
|
referenceSize = std::round(mParent->getSize().x * 0.1045f);
|
2021-03-20 09:26:18 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
// Vertically center.
|
2022-01-16 11:09:55 +00:00
|
|
|
glm::vec3 off {0.0f, (mSize.y - mTextCache->metrics.size.y) / 2.0f, 0.0f};
|
2021-03-22 17:07:15 +00:00
|
|
|
|
2021-03-20 10:08:28 +00:00
|
|
|
if (mAlignRight)
|
2021-08-16 16:25:01 +00:00
|
|
|
off.x += referenceSize - mTextCache->metrics.size.x;
|
2021-08-15 17:30:31 +00:00
|
|
|
trans = glm::translate(trans, off);
|
2018-10-13 01:08:15 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
Renderer::setMatrix(trans);
|
2018-10-13 01:08:15 +00:00
|
|
|
|
2021-03-22 17:07:15 +00:00
|
|
|
if (Settings::getInstance()->getBool("DebugText")) {
|
|
|
|
Renderer::setMatrix(trans);
|
2021-08-16 16:25:01 +00:00
|
|
|
if (mTextCache->metrics.size.x > 0.0f) {
|
|
|
|
Renderer::drawRect(0.0f, 0.0f - off.y, mSize.x - off.x, mSize.y, 0x0000FF33,
|
2021-07-07 18:31:46 +00:00
|
|
|
0x0000FF33);
|
2021-03-22 17:07:15 +00:00
|
|
|
}
|
2021-08-16 16:25:01 +00:00
|
|
|
Renderer::drawRect(0.0f, 0.0f, mTextCache->metrics.size.x, mTextCache->metrics.size.y,
|
|
|
|
0x00000033, 0x00000033);
|
2021-03-22 17:07:15 +00:00
|
|
|
}
|
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
mTextCache->setColor((mColor & 0xFFFFFF00) | getOpacity());
|
|
|
|
font->renderTextCache(mTextCache.get());
|
2018-10-13 01:08:15 +00:00
|
|
|
|
2021-10-08 17:38:14 +00:00
|
|
|
if (mEditing && mTime != 0) {
|
2020-11-17 22:06:54 +00:00
|
|
|
if (mEditIndex >= 0 && static_cast<unsigned int>(mEditIndex) < mCursorBoxes.size())
|
2020-06-21 12:25:28 +00:00
|
|
|
Renderer::drawRect(mCursorBoxes[mEditIndex][0], mCursorBoxes[mEditIndex][1],
|
2021-07-07 18:31:46 +00:00
|
|
|
mCursorBoxes[mEditIndex][2], mCursorBoxes[mEditIndex][3],
|
|
|
|
0x00000022, 0x00000022);
|
2020-06-21 12:25:28 +00:00
|
|
|
}
|
|
|
|
}
|
2018-10-13 01:08:15 +00:00
|
|
|
}
|
|
|
|
|
2021-10-08 17:38:14 +00:00
|
|
|
void DateTimeEditComponent::setDisplayMode(DisplayMode mode)
|
2018-10-13 01:08:15 +00:00
|
|
|
{
|
2021-10-08 17:38:14 +00:00
|
|
|
mDisplayMode = mode;
|
2020-06-21 12:25:28 +00:00
|
|
|
updateTextCache();
|
2018-10-13 01:08:15 +00:00
|
|
|
}
|
|
|
|
|
2021-10-08 17:38:14 +00:00
|
|
|
void DateTimeEditComponent::setColor(unsigned int color)
|
|
|
|
{
|
|
|
|
mColor = color;
|
|
|
|
if (mTextCache)
|
|
|
|
mTextCache->setColor(color);
|
|
|
|
}
|
|
|
|
|
|
|
|
void DateTimeEditComponent::setFont(std::shared_ptr<Font> font)
|
|
|
|
{
|
|
|
|
mFont = font;
|
|
|
|
updateTextCache();
|
|
|
|
}
|
|
|
|
|
|
|
|
void DateTimeEditComponent::setUppercase(bool uppercase)
|
|
|
|
{
|
|
|
|
mUppercase = uppercase;
|
|
|
|
updateTextCache();
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<HelpPrompt> DateTimeEditComponent::getHelpPrompts()
|
|
|
|
{
|
|
|
|
std::vector<HelpPrompt> prompts;
|
|
|
|
if (!mEditing) {
|
|
|
|
prompts.push_back(HelpPrompt("a", "edit date"));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
prompts.push_back(HelpPrompt("b", "cancel"));
|
|
|
|
prompts.push_back(HelpPrompt("a", "apply"));
|
|
|
|
prompts.push_back(HelpPrompt("left/right", "Y-M-D"));
|
|
|
|
prompts.push_back(HelpPrompt("up/down", "modify"));
|
|
|
|
}
|
|
|
|
return prompts;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::shared_ptr<Font> DateTimeEditComponent::getFont() const
|
|
|
|
{
|
|
|
|
if (mFont)
|
|
|
|
return mFont;
|
|
|
|
|
|
|
|
return Font::get(FONT_SIZE_MEDIUM);
|
|
|
|
}
|
|
|
|
|
2018-10-13 01:08:15 +00:00
|
|
|
std::string DateTimeEditComponent::getDisplayString(DisplayMode mode) const
|
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
// ISO 8601 date format.
|
|
|
|
std::string fmt;
|
|
|
|
switch (mode) {
|
2021-07-07 18:31:46 +00:00
|
|
|
case DISP_DATE: {
|
|
|
|
if (mTime.getTime() == 0)
|
|
|
|
return "unknown";
|
|
|
|
fmt = "%Y-%m-%d";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case DISP_DATE_TIME: {
|
|
|
|
if (mTime.getTime() == 0)
|
|
|
|
return "unknown";
|
|
|
|
fmt = "%Y-%m-%d %H:%M:%S";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case DISP_RELATIVE_TO_NOW: {
|
2020-06-21 12:25:28 +00:00
|
|
|
// Relative time.
|
|
|
|
if (mTime.getTime() == 0)
|
|
|
|
return "never";
|
|
|
|
|
|
|
|
Utils::Time::DateTime now(Utils::Time::now());
|
|
|
|
Utils::Time::Duration dur(now.getTime() - mTime.getTime());
|
|
|
|
|
2020-12-17 19:43:52 +00:00
|
|
|
std::string buf;
|
2020-06-21 12:25:28 +00:00
|
|
|
|
|
|
|
if (dur.getDays() > 0)
|
2021-07-07 18:31:46 +00:00
|
|
|
buf = std::to_string(dur.getDays()) + // Line break.
|
|
|
|
" day" + (dur.getDays() > 1 ? "s" : "") + " ago";
|
2020-06-21 12:25:28 +00:00
|
|
|
else if (dur.getHours() > 0)
|
2021-07-07 18:31:46 +00:00
|
|
|
buf = std::to_string(dur.getHours()) + // Line break.
|
|
|
|
" hour" + (dur.getHours() > 1 ? "s" : "") + " ago";
|
2020-06-21 12:25:28 +00:00
|
|
|
else if (dur.getMinutes() > 0)
|
2021-07-07 18:31:46 +00:00
|
|
|
buf = std::to_string(dur.getMinutes()) + // Line break.
|
|
|
|
" minute" + (dur.getMinutes() > 1 ? "s" : "") + " ago";
|
2020-06-21 12:25:28 +00:00
|
|
|
else
|
2021-07-07 18:31:46 +00:00
|
|
|
buf = std::to_string(dur.getSeconds()) + // Line break.
|
|
|
|
" second" + (dur.getSeconds() > 1 || dur.getSeconds() == 0 ? "s" : "") +
|
|
|
|
" ago";
|
2020-06-21 12:25:28 +00:00
|
|
|
|
|
|
|
return std::string(buf);
|
2021-07-07 18:31:46 +00:00
|
|
|
break;
|
2020-06-21 12:25:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return Utils::Time::timeToString(mTime, fmt);
|
2018-10-13 01:08:15 +00:00
|
|
|
}
|
|
|
|
|
2021-10-08 17:38:14 +00:00
|
|
|
void DateTimeEditComponent::changeDate()
|
2018-10-13 01:08:15 +00:00
|
|
|
{
|
2021-10-08 17:38:14 +00:00
|
|
|
tm new_tm = mTime;
|
2018-10-13 01:08:15 +00:00
|
|
|
|
2021-11-26 19:55:54 +00:00
|
|
|
if (mTime.getIsoString() == "19700101T000000")
|
|
|
|
#if defined(_WIN64)
|
|
|
|
new_tm = {0, 0, 0, 1, 0, 70, 0, 0, -1};
|
|
|
|
#else
|
|
|
|
new_tm = {0, 0, 0, 1, 0, 70, 0, 0, -1, 0, 0};
|
|
|
|
#endif
|
|
|
|
|
2021-10-08 17:38:14 +00:00
|
|
|
// ISO 8601 date format.
|
|
|
|
if (mEditIndex == 0) {
|
|
|
|
new_tm.tm_year += mKeyRepeatDir;
|
|
|
|
|
|
|
|
if (new_tm.tm_year < 0)
|
|
|
|
new_tm.tm_year = 0;
|
|
|
|
}
|
|
|
|
else if (mEditIndex == 1) {
|
|
|
|
new_tm.tm_mon += mKeyRepeatDir;
|
|
|
|
|
|
|
|
if (new_tm.tm_mon > 11)
|
|
|
|
new_tm.tm_mon = 0;
|
|
|
|
else if (new_tm.tm_mon < 0)
|
|
|
|
new_tm.tm_mon = 11;
|
|
|
|
}
|
|
|
|
else if (mEditIndex == 2) {
|
|
|
|
const int days_in_month =
|
|
|
|
Utils::Time::daysInMonth(new_tm.tm_year + 1900, new_tm.tm_mon + 1);
|
|
|
|
new_tm.tm_mday += mKeyRepeatDir;
|
|
|
|
|
|
|
|
if (new_tm.tm_mday > days_in_month)
|
|
|
|
new_tm.tm_mday = 1;
|
|
|
|
else if (new_tm.tm_mday < 1)
|
|
|
|
new_tm.tm_mday = days_in_month;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Validate day.
|
|
|
|
const int days_in_month = Utils::Time::daysInMonth(new_tm.tm_year + 1900, new_tm.tm_mon + 1);
|
|
|
|
if (new_tm.tm_mday > days_in_month)
|
|
|
|
new_tm.tm_mday = days_in_month;
|
|
|
|
|
2021-11-26 19:55:54 +00:00
|
|
|
if (mktime(&new_tm) <= 0)
|
|
|
|
mTime = 0;
|
|
|
|
else
|
|
|
|
mTime = new_tm;
|
2021-10-08 17:38:14 +00:00
|
|
|
|
|
|
|
updateTextCache();
|
2018-10-13 01:08:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DateTimeEditComponent::updateTextCache()
|
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
DisplayMode mode = getCurrentDisplayMode();
|
|
|
|
|
|
|
|
std::string dispString;
|
|
|
|
|
|
|
|
// Hack to set date string to blank instead of 'unknown'.
|
|
|
|
// The calling function simply needs to set this string using setValue().
|
2021-11-26 19:55:54 +00:00
|
|
|
if (mTime.getIsoString() == "19710101T010101") {
|
2020-06-21 12:25:28 +00:00
|
|
|
dispString = "";
|
|
|
|
}
|
|
|
|
else {
|
2021-07-07 18:31:46 +00:00
|
|
|
dispString =
|
|
|
|
mUppercase ? Utils::String::toUpper(getDisplayString(mode)) : getDisplayString(mode);
|
2020-06-21 12:25:28 +00:00
|
|
|
}
|
|
|
|
std::shared_ptr<Font> font = getFont();
|
|
|
|
mTextCache = std::unique_ptr<TextCache>(font->buildTextCache(dispString, 0, 0, mColor));
|
|
|
|
|
|
|
|
if (mAutoSize) {
|
|
|
|
mSize = mTextCache->metrics.size;
|
|
|
|
mAutoSize = false;
|
2021-07-07 18:31:46 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
if (getParent())
|
|
|
|
getParent()->onSizeChanged();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dispString == "unknown " || dispString == "")
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Set up cursor positions.
|
|
|
|
mCursorBoxes.clear();
|
|
|
|
|
|
|
|
if (dispString.empty() || mode == DISP_RELATIVE_TO_NOW)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Year.
|
2022-01-16 11:09:55 +00:00
|
|
|
glm::vec2 start {};
|
|
|
|
glm::vec2 end {font->sizeText(dispString.substr(0, 4))};
|
|
|
|
glm::vec2 diff {end - start};
|
|
|
|
mCursorBoxes.push_back(glm::vec4 {start[0], start[1], diff[0], diff[1]});
|
2020-06-21 12:25:28 +00:00
|
|
|
|
|
|
|
// Month.
|
2021-08-16 16:25:01 +00:00
|
|
|
start[0] = font->sizeText(dispString.substr(0, 5)).x;
|
2020-06-21 12:25:28 +00:00
|
|
|
end = font->sizeText(dispString.substr(0, 7));
|
|
|
|
diff = end - start;
|
2022-01-16 11:09:55 +00:00
|
|
|
mCursorBoxes.push_back(glm::vec4 {start[0], start[1], diff[0], diff[1]});
|
2020-06-21 12:25:28 +00:00
|
|
|
|
|
|
|
// Day.
|
2021-08-16 16:25:01 +00:00
|
|
|
start[0] = font->sizeText(dispString.substr(0, 8)).x;
|
2020-06-21 12:25:28 +00:00
|
|
|
end = font->sizeText(dispString.substr(0, 10));
|
|
|
|
diff = end - start;
|
2022-01-16 11:09:55 +00:00
|
|
|
mCursorBoxes.push_back(glm::vec4 {start[0], start[1], diff[0], diff[1]});
|
2020-06-21 12:25:28 +00:00
|
|
|
|
|
|
|
// The logic for handling time for 'mode = DISP_DATE_TIME' is missing, but
|
|
|
|
// nobody will use it anyway so it's not worthwhile implementing.
|
2018-10-13 01:08:15 +00:00
|
|
|
}
|