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.h
|
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
|
|
|
//
|
|
|
|
|
2018-10-13 01:08:15 +00:00
|
|
|
#ifndef ES_CORE_COMPONENTS_DATE_TIME_EDIT_COMPONENT_H
|
|
|
|
#define ES_CORE_COMPONENTS_DATE_TIME_EDIT_COMPONENT_H
|
|
|
|
|
|
|
|
#include "GuiComponent.h"
|
2021-07-07 18:31:46 +00:00
|
|
|
#include "utils/TimeUtil.h"
|
2018-10-13 01:08:15 +00:00
|
|
|
|
|
|
|
class TextCache;
|
|
|
|
|
|
|
|
// Used to enter or display a specific point in time.
|
|
|
|
class DateTimeEditComponent : public GuiComponent
|
|
|
|
{
|
|
|
|
public:
|
2021-07-07 18:31:46 +00:00
|
|
|
enum DisplayMode {
|
|
|
|
DISP_DATE, // Replace with AllowShortEnumsOnASingleLine: false (clang-format >=11.0).
|
2020-06-21 12:25:28 +00:00
|
|
|
DISP_DATE_TIME,
|
|
|
|
DISP_RELATIVE_TO_NOW
|
|
|
|
};
|
|
|
|
|
2021-07-07 18:31:46 +00:00
|
|
|
DateTimeEditComponent(Window* window,
|
|
|
|
bool alignRight = false,
|
|
|
|
DisplayMode dispMode = DISP_DATE);
|
2020-06-21 12:25:28 +00:00
|
|
|
|
|
|
|
void setValue(const std::string& val) override;
|
2021-07-07 18:31:46 +00:00
|
|
|
std::string getValue() const override { return mTime; }
|
2020-06-21 12:25:28 +00:00
|
|
|
|
|
|
|
bool input(InputConfig* config, Input input) override;
|
|
|
|
void update(int deltaTime) override;
|
2021-07-07 18:31:46 +00:00
|
|
|
unsigned int getColor() const override { return mColor; }
|
2021-08-15 17:30:31 +00:00
|
|
|
void render(const glm::mat4& parentTrans) override;
|
2020-06-21 12:25:28 +00:00
|
|
|
void onSizeChanged() override;
|
|
|
|
|
|
|
|
// Set how the point in time will be displayed:
|
|
|
|
// * DISP_DATE - only display the date.
|
|
|
|
// * DISP_DATE_TIME - display both the date and the time on that date.
|
|
|
|
// * DISP_RELATIVE_TO_NOW - intelligently display the point in time relative to
|
|
|
|
// right now (e.g. "5 secs ago", "3 minutes ago", "1 day ago".
|
|
|
|
// Automatically updates as time marches on.
|
|
|
|
// The initial value is DISP_DATE.
|
|
|
|
void setDisplayMode(DisplayMode mode);
|
|
|
|
|
2021-07-07 18:31:46 +00:00
|
|
|
// Text color.
|
2020-06-25 17:52:38 +00:00
|
|
|
void setColor(unsigned int color) override;
|
2020-06-21 12:25:28 +00:00
|
|
|
// Font to use. Default is Font::get(FONT_SIZE_MEDIUM).
|
2020-07-15 15:44:27 +00:00
|
|
|
|
2021-07-07 18:31:46 +00:00
|
|
|
void setOriginalColor(unsigned int color) override { mColorOriginalValue = color; }
|
|
|
|
void setChangedColor(unsigned int color) override { mColorChangedValue = color; }
|
2020-07-15 15:44:27 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
void setFont(std::shared_ptr<Font> font);
|
|
|
|
// Force text to be uppercase when in DISP_RELATIVE_TO_NOW mode.
|
|
|
|
void setUppercase(bool uppercase);
|
|
|
|
|
2021-07-07 18:31:46 +00:00
|
|
|
virtual void applyTheme(const std::shared_ptr<ThemeData>& theme,
|
|
|
|
const std::string& view,
|
|
|
|
const std::string& element,
|
|
|
|
unsigned int properties) override;
|
2020-06-21 12:25:28 +00:00
|
|
|
|
|
|
|
virtual std::vector<HelpPrompt> getHelpPrompts() override;
|
2020-06-09 18:03:31 +00:00
|
|
|
|
2018-10-13 01:08:15 +00:00
|
|
|
private:
|
2021-01-18 23:11:02 +00:00
|
|
|
std::shared_ptr<Font> getFont() const override;
|
2018-10-13 01:08:15 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
std::string getDisplayString(DisplayMode mode) const;
|
2021-07-07 18:31:46 +00:00
|
|
|
DisplayMode getCurrentDisplayMode() const { return mDisplayMode; }
|
2019-08-25 15:23:02 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
void updateTextCache();
|
2018-10-13 01:08:15 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
Utils::Time::DateTime mTime;
|
|
|
|
Utils::Time::DateTime mTimeBeforeEdit;
|
2018-10-13 01:08:15 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
bool mEditing;
|
|
|
|
int mEditIndex;
|
|
|
|
DisplayMode mDisplayMode;
|
2018-10-13 01:08:15 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
int mRelativeUpdateAccumulator;
|
2018-10-13 01:08:15 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
std::unique_ptr<TextCache> mTextCache;
|
2021-08-15 20:03:17 +00:00
|
|
|
std::vector<glm::vec4> mCursorBoxes;
|
2018-10-13 01:08:15 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
unsigned int mColor;
|
2020-07-15 15:44:27 +00:00
|
|
|
Utils::Time::DateTime mOriginalValue;
|
|
|
|
unsigned int mColorOriginalValue;
|
|
|
|
unsigned int mColorChangedValue;
|
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
std::shared_ptr<Font> mFont;
|
2021-03-20 10:08:28 +00:00
|
|
|
bool mAlignRight;
|
2020-06-21 12:25:28 +00:00
|
|
|
bool mUppercase;
|
|
|
|
bool mAutoSize;
|
2018-10-13 01:08:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // ES_CORE_COMPONENTS_DATE_TIME_COMPONENT_H
|