2013-09-28 22:35:38 +00:00
# pragma once
2017-10-31 17:12:50 +00:00
# ifndef ES_CORE_COMPONENTS_DATE_TIME_COMPONENT_H
# define ES_CORE_COMPONENTS_DATE_TIME_COMPONENT_H
2013-09-28 22:35:38 +00:00
2014-06-20 01:30:09 +00:00
# include "GuiComponent.h"
2017-11-01 22:21:10 +00:00
# include <boost/date_time/posix_time/ptime.hpp>
class TextCache ;
2013-09-28 22:35:38 +00:00
2014-01-24 22:21:10 +00:00
// Used to enter or display a specific point in time.
2013-09-28 22:35:38 +00:00
class DateTimeComponent : public GuiComponent
{
public :
2014-03-21 16:10:19 +00:00
enum DisplayMode
{
DISP_DATE ,
DISP_DATE_TIME ,
DISP_RELATIVE_TO_NOW
} ;
DateTimeComponent ( Window * window , DisplayMode dispMode = DISP_DATE ) ;
2013-09-28 22:35:38 +00:00
void setValue ( const std : : string & val ) override ;
std : : string getValue ( ) const override ;
bool input ( InputConfig * config , Input input ) override ;
void update ( int deltaTime ) override ;
2017-10-28 20:24:35 +00:00
void render ( const Transform4x4f & parentTrans ) override ;
2014-03-25 19:14:09 +00:00
void onSizeChanged ( ) override ;
2013-09-28 22:35:38 +00:00
2014-01-24 22:21:10 +00:00
// 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.
2013-09-28 22:35:38 +00:00
void setDisplayMode ( DisplayMode mode ) ;
2014-01-24 22:21:10 +00:00
void setColor ( unsigned int color ) ; // Text color.
void setFont ( std : : shared_ptr < Font > font ) ; // Font to display with. Default is Font::get(FONT_SIZE_MEDIUM).
2014-05-03 19:51:50 +00:00
void setUppercase ( bool uppercase ) ; // Force text to be uppercase when in DISP_RELATIVE_TO_NOW mode.
2013-10-16 23:11:43 +00:00
2014-01-19 22:06:13 +00:00
virtual void applyTheme ( const std : : shared_ptr < ThemeData > & theme , const std : : string & view , const std : : string & element , unsigned int properties ) override ;
2013-09-28 22:35:38 +00:00
private :
std : : shared_ptr < Font > getFont ( ) const ;
std : : string getDisplayString ( DisplayMode mode ) const ;
DisplayMode getCurrentDisplayMode ( ) const ;
void updateTextCache ( ) ;
boost : : posix_time : : ptime mTime ;
boost : : posix_time : : ptime mTimeBeforeEdit ;
bool mEditing ;
int mEditIndex ;
DisplayMode mDisplayMode ;
int mRelativeUpdateAccumulator ;
std : : unique_ptr < TextCache > mTextCache ;
2017-10-28 20:24:35 +00:00
std : : vector < Vector4f > mCursorBoxes ;
2013-10-16 23:11:43 +00:00
unsigned int mColor ;
std : : shared_ptr < Font > mFont ;
2014-05-03 19:51:50 +00:00
bool mUppercase ;
2014-03-25 19:14:09 +00:00
2015-03-05 23:43:38 +00:00
bool mAutoSize ;
2013-09-28 22:35:38 +00:00
} ;
2017-10-31 17:12:50 +00:00
# endif // ES_CORE_COMPONENTS_DATE_TIME_COMPONENT_H