29 #include "nomlib/gui/MessageBox.hpp"
34 void MessageBox::initialize (
void )
36 NOM_LOG_TRACE ( NOM );
39 this->label_alignment = IFont::TextAlignment::MiddleLeft;
42 MessageBox::MessageBox (
void )
47 MessageBox::MessageBox (
48 int32 x, int32 y, int32 width, int32 height,
49 enum FrameStyle style,
50 const Gradient& background
57 this->coords = Coords ( x, y, width, height );
59 Color gradient_color[2];
60 gradient_color[0] = background.getStartColor();
61 gradient_color[1] = background.getEndColor();
63 this->drawable.push_back ( Gradient::SharedPtr (
new Gradient ( gradient_color, Coords ( this->coords.x, this->coords.y, this->coords.width, this->coords.height ), 0, 0, background.getFillDirection() ) ) );
65 if ( style == FrameStyle::Gray )
67 this->drawable.push_back ( GrayFrame::SharedPtr (
new GrayFrame ( x, y, width, height, padding ) ) );
71 MessageBox::MessageBox (
72 int32 x, int32 y, int32 width, int32 height,
73 GrayFrame::SharedPtr style,
74 Gradient::SharedPtr background
82 this->coords = Coords ( x, y, width, height );
84 Color gradient_color[2];
85 gradient_color[0] = background->getStartColor();
86 gradient_color[1] = background->getEndColor();
87 this->drawable.push_back ( Gradient::SharedPtr (
new Gradient ( gradient_color, Coords ( this->coords.x, this->coords.y, this->coords.width, this->coords.height ), 0, 0, background->getFillDirection() ) ) );
89 if ( style !=
nullptr )
91 style->setPosition ( x, y );
92 style->setSize ( width, height, padding );
93 this->drawable.push_back ( style );
97 this->drawable.push_back ( GrayFrame::SharedPtr (
new GrayFrame ( x, y, width, height, padding ) ) );
101 MessageBox::~MessageBox (
void )
103 NOM_LOG_TRACE ( NOM );
106 bool MessageBox::isEnabled (
void )
const
108 if ( ! this->enabled )
return false;
113 const std::string MessageBox::getWindowTitle (
void )
115 if ( this->label )
return this->window_title->getText();
120 const std::string MessageBox::getLabel (
void )
122 if ( this->label )
return this->label->getText();
127 void MessageBox::disable (
void )
129 this->enabled =
false;
132 void MessageBox::enable (
void )
134 this->enabled =
true;
137 const Point2i MessageBox::size (
void )
const
139 return Point2i ( this->coords.
w, this->coords.h );
142 const Point2i MessageBox::position (
void )
const
144 return Point2i ( this->coords.x, this->coords.y );
147 void MessageBox::setWindowTitleFont (
const IFont::RawPtr font )
149 this->window_title = IFont::SharedPtr ( font->clone() );
155 this->window_title->setPosition ( Coords ( this->coords.x + 4, this->coords.y, this->coords.width, this->coords.height ) );
157 this->window_title->setText (
"INFO." );
158 this->window_title->setTextJustification ( IFont::TextAlignment::MiddleLeft );
163 void MessageBox::setLabelFont (
const IFont::RawPtr font )
165 this->label = IFont::SharedPtr ( font->clone() );
166 this->label->setPosition ( this->coords );
171 void MessageBox::setLabelPosition (
const Coords& pos )
173 if ( ! this->label )
return;
175 this->label->setPosition ( pos );
178 void MessageBox::setLabelTextAlignment ( IFont::TextAlignment alignment )
180 this->label_alignment = alignment;
183 void MessageBox::setWindowTitle (
const std::string& text )
185 std::string text_buffer = text;
187 if ( ! this->window_title )
return;
190 std::transform ( text_buffer.begin(), text_buffer.end(), text_buffer.begin(), ::toupper);
192 this->window_title->setText ( text_buffer );
195 void MessageBox::setLabel (
const std::string& text )
197 if ( ! this->label )
return;
199 this->label->setText ( text );
204 for (
auto it = this->drawable.begin(); it != this->drawable.end(); ++it )
210 if ( ! this->label )
return;
212 switch ( this->label_alignment )
215 case IFont::TextAlignment::MiddleLeft:
217 this->label->setTextJustification ( IFont::TextAlignment::MiddleLeft );
221 case IFont::TextAlignment::MiddleCenter:
223 this->label->setTextJustification ( IFont::TextAlignment::MiddleCenter );
227 case IFont::TextAlignment::MiddleRight:
229 this->label->setTextJustification ( IFont::TextAlignment::MiddleRight );
237 if ( this->isEnabled() ==
false )
return;
239 for (
auto it = this->drawable.begin(); it != this->drawable.end(); ++it )
242 obj->draw ( target );
std::shared_ptr< IDrawable > SharedPtr
std::shared_ptr definition type at your leisure, sir!
void draw(RenderTarget target) const
Render the object onto the primary video buffer – your visible screen.
int32 & w
Reference alias for width instance variable.