@ -18,12 +18,34 @@ namespace guecs {
struct Label {
std : : string label ;
unsigned int size = GUECS_FONT_SIZE ;
sf : : Color color = GUECS_TEXT_COLOR ;
shared_ptr < sf : : Font > font = nullptr ;
shared_ptr < sf : : Text > text = nullptr ;
void init ( lel : : Cell & cell , shared_ptr < sf : : Font > font_ptr ) {
dbc : : check ( font_ptr ! = nullptr , " you failed to initialize this Label " ) ;
if ( font = = nullptr ) font = font_ptr ;
if ( text = = nullptr ) text = make_shared < sf : : Text > ( * font , label , size ) ;
text - > setFillColor ( color ) ;
auto bounds = text - > getLocalBounds ( ) ;
auto text_cell = lel : : center ( bounds . size . x , bounds . size . y , cell ) ;
// this stupid / 2 is because SFML renders from baseline rather than from the claimed bounding box
text - > setPosition ( { float ( text_cell . x ) , float ( text_cell . y ) - text_cell . h / 2 } ) ;
}
} ;
struct WideLabel {
std : : wstring label ;
unsigned int size = GUECS_FONT_SIZE ;
sf : : Color color = GUECS_TEXT_COLOR ;
shared_ptr < sf : : Font > font = nullptr ;
shared_ptr < sf : : Text > text = nullptr ;
void init ( lel : : Cell & cell , shared_ptr < sf : : Font > font_ptr ) {
dbc : : check ( font_ptr ! = nullptr , " you failed to initialize this WideLabel " ) ;
if ( font = = nullptr ) font = font_ptr ;
if ( text = = nullptr ) text = make_shared < sf : : Text > ( * font , label , size ) ;
text - > setFillColor ( color ) ;
auto bounds = text - > getLocalBounds ( ) ;
auto text_cell = lel : : center ( bounds . size . x , bounds . size . y , cell ) ;
// this stupid / 2 is because SFML renders from baseline rather than from the claimed bounding box
@ -34,13 +56,17 @@ namespace guecs {
struct Textual {
std : : string content ;
unsigned int size = GUECS_FONT_SIZE ;
sf : : Color color = GUECS_TEXT_COLOR ;
int padding = GUECS_PADDING ;
shared_ptr < sf : : Font > font = nullptr ;
shared_ptr < sf : : Text > text = nullptr ;
void init ( lel : : Cell & cell , shared_ptr < sf : : Font > font_ptr ) {
dbc : : check ( font_ptr ! = nullptr , " you failed to initialize this Text " ) ;
if ( font = = nullptr ) font = font_ptr ;
if ( text = = nullptr ) text = make_shared < sf : : Text > ( * font , content , size ) ;
text - > setPosition ( { float ( cell . x + GUECS_PADDING * 2 ) , float ( cell . y + GUECS_PADDING * 2 ) } ) ;
text - > setFillColor ( color ) ;
text - > setPosition ( { float ( cell . x + padding * 2 ) , float ( cell . y + padding * 2 ) } ) ;
text - > setCharacterSize ( size ) ;
}
@ -50,6 +76,29 @@ namespace guecs {
}
} ;
struct WideText {
std : : wstring content ;
unsigned int size = GUECS_FONT_SIZE ;
sf : : Color color = GUECS_TEXT_COLOR ;
int padding = GUECS_PADDING ;
shared_ptr < sf : : Font > font = nullptr ;
shared_ptr < sf : : Text > text = nullptr ;
void init ( lel : : Cell & cell , shared_ptr < sf : : Font > font_ptr ) {
dbc : : check ( font_ptr ! = nullptr , " you failed to initialize this WideText " ) ;
if ( font = = nullptr ) font = font_ptr ;
if ( text = = nullptr ) text = make_shared < sf : : Text > ( * font , content , size ) ;
text - > setFillColor ( color ) ;
text - > setPosition ( { float ( cell . x + padding * 2 ) , float ( cell . y + padding * 2 ) } ) ;
text - > setCharacterSize ( size ) ;
}
void update ( std : : wstring & new_content ) {
content = new_content ;
text - > setString ( content ) ;
}
} ;
struct Clickable {
/* This is actually called by UI::mouse and passed the entity ID of the
* button pressed so you can interact with it in the event handler .
@ -59,6 +108,7 @@ namespace guecs {
struct Sprite {
std : : string name ;
int padding = GUECS_PADDING ;
std : : shared_ptr < sf : : Sprite > sprite = nullptr ;
std : : shared_ptr < sf : : Texture > texture = nullptr ;
@ -67,26 +117,30 @@ namespace guecs {
texture = sprite_texture . texture ;
sprite = make_shared < sf : : Sprite > ( * texture ) ;
sprite - > setPosition ( {
float ( cell . x + GUECS_PADDING ) ,
float ( cell . y + GUECS_PADDING ) } ) ;
float ( cell . x + padding ) ,
float ( cell . y + padding ) } ) ;
auto size = texture - > getSize ( ) ;
sprite - > setScale ( {
float ( cell . w - GUECS_PADDING * 2 ) / size . x ,
float ( cell . h - GUECS_PADDING * 2 ) / size . y } ) ;
float ( cell . w - padding * 2 ) / size . x ,
float ( cell . h - padding * 2 ) / size . y } ) ;
}
} ;
struct Rectangle {
int padding = GUECS_PADDING ;
sf : : Color color = GUECS_FILL_COLOR ;
sf : : Color border_color = GUECS_BORDER_COLOR ;
int border_px = GUECS_BORDER_PX ;
shared_ptr < sf : : RectangleShape > shape = nullptr ;
void init ( lel : : Cell & cell ) {
sf : : Vector2f size { float ( cell . w ) - GUECS_PADDING * 2 , float ( cell . h ) - GUECS_PADDING * 2 } ;
sf : : Vector2f size { float ( cell . w ) - padding * 2 , float ( cell . h ) - padding * 2 } ;
if ( shape = = nullptr ) shape = make_shared < sf : : RectangleShape > ( size ) ;
shape - > setPosition ( { float ( cell . x + GUECS_PADDING ) , float ( cell . y + GUECS_PADDING ) } ) ;
shape - > setFillColor ( GUECS_FILL_COLOR ) ;
shape - > setOutlineColor ( GUECS_BORDER_COLOR ) ;
shape - > setOutlineThickness ( GUECS_BORDER_PX ) ;
shape - > setPosition ( { float ( cell . x + padding ) , float ( cell . y + padding ) } ) ;
shape - > setFillColor ( color ) ;
shape - > setOutlineColor ( border_color ) ;
shape - > setOutlineThickness ( border_px ) ;
}
} ;
@ -112,6 +166,7 @@ namespace guecs {
float y = 0.0f ;
float w = 0.0f ;
float h = 0.0f ;
sf : : Color color = GUECS_BG_COLOR ;
shared_ptr < sf : : RectangleShape > shape = nullptr ;
@ -128,7 +183,7 @@ namespace guecs {
sf : : Vector2f size { float ( w ) , float ( h ) } ;
if ( shape = = nullptr ) shape = make_shared < sf : : RectangleShape > ( size ) ;
shape - > setPosition ( { float ( x ) , float ( y ) } ) ;
shape - > setFillColor ( GUECS_BG_COLOR ) ;
shape - > setFillColor ( color ) ;
}
} ;