MessageBox.hpp
1 /******************************************************************************
2 
3  nomlib - C++11 cross-platform game engine
4 
5 Copyright (c) 2013, Jeffrey Carpenter <jeffrey.carp@gmail.com>
6 All rights reserved.
7 
8 Redistribution and use in source and binary forms, with or without
9 modification, are permitted provided that the following conditions are met:
10 
11 1. Redistributions of source code must retain the above copyright notice, this
12  list of conditions and the following disclaimer.
13 2. Redistributions in binary form must reproduce the above copyright notice,
14  this list of conditions and the following disclaimer in the documentation
15  and/or other materials provided with the distribution.
16 
17 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
21 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 
28 ******************************************************************************/
29 #ifndef NOMLIB_SDL2_MESSAGEBOX_HEADERS
30 #define NOMLIB_SDL2_MESSAGEBOX_HEADERS
31 
32 #include <iostream>
33 #include <string>
34 #include <memory>
35 #include <algorithm>
36 
37 #include "nomlib/config.hpp"
38 #include "nomlib/math/Color.hpp"
39 #include "nomlib/math/Coords.hpp"
40 #include "nomlib/graphics/IDrawable.hpp"
41 #include "nomlib/graphics/Gradient.hpp"
42 #include "nomlib/graphics/shapes/Line.hpp"
43 #include "nomlib/gui/GrayFrame.hpp"
44 #include "nomlib/graphics/IFont.hpp"
45 
46 namespace nom {
47  namespace ui {
48 
49 enum FrameStyle
50 {
51  None = 0,
52  Gray = 1
53 };
54 
56 class MessageBox:
57  public IDrawable
58 
59 {
60  public:
61  MessageBox ( void );
62 
63  MessageBox (
64  int32 x, int32 y, int32 width, int32 height,
65  enum FrameStyle style, const Gradient& background
66  );
67 
68  MessageBox (
69  int32 x, int32 y, int32 width, int32 height,
70  GrayFrame::SharedPtr style = nullptr,
71  Gradient::SharedPtr background = nullptr
72  );
73 
74  virtual ~MessageBox ( void );
75 
76  void initialize ( void );
77  //void initialize ( const Gradient& background );
78 
79  bool isEnabled ( void ) const;
80  const std::string getWindowTitle ( void );
81  const std::string getLabel ( void );
82 
83  void disable ( void );
84  void enable ( void );
85 
86  const Point2i size ( void ) const;
87  const Point2i position ( void ) const;
88 
89  void setWindowTitleFont ( const IFont::RawPtr font );
90  void setLabelFont ( const IFont::RawPtr font );
91 
92  void setLabelPosition ( const Coords& pos );
93  void setLabelTextAlignment ( IFont::TextAlignment alignment );
94  void setWindowTitle ( const std::string& text );
95  void setLabel ( const std::string& text );
96 
97  void update ( void );
98  void draw ( RenderTarget target ) const;
99 
100  private:
102 
103  IFont::SharedPtr window_title;
104  IFont::SharedPtr label;
105 
106  Coords coords;
107  enum IFont::TextAlignment label_alignment;
108  bool enabled;
109 };
110 
111 
112  } // namespace ui
113 } // namespace nom
114 
115 #endif // include guard defined
std::vector< std::shared_ptr< IDrawable > > SharedDrawables
Vector of std::shared_ptr definition type for the brotherhood, sir!
Definition: IDrawable.hpp:51
Base interface class for grouping objects under a united front.
Definition: IDrawable.hpp:43
Rectangle fill class with dithered, linear gradient colors.
Definition: Gradient.hpp:48
void draw(RenderTarget target) const
Render the object onto the primary video buffer – your visible screen.
Definition: MessageBox.cpp:235
Simple UI interface for drawing a styled message box.
Definition: MessageBox.hpp:56
Coordinate values (x, y, z, width, height ) wrapper.
Definition: Coords.hpp:44