GrayFrame.cpp
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 #include "nomlib/gui/GrayFrame.hpp"
30 
31 namespace nom {
32  namespace ui {
33 
34 GrayFrame::GrayFrame ( void ) : updated ( false ) {}
35 
36 GrayFrame::~GrayFrame ( void ) {}
37 
38 GrayFrame::GrayFrame ( int32 x, int32 y, int32 width, int32 height, int32 padding )
39 {
40  this->setPosition ( x, y );
41  this->setSize ( width, height, padding );
42 
43  this->updated = false;
44 }
45 
46 void GrayFrame::setPosition ( int32 x, int32 y )
47 {
48  this->frame_position.setPosition ( x, y );
49  this->updated = false;
50 }
51 
52 void GrayFrame::setSize ( int32 width, int32 height, int32 padding )
53 {
54  frame_position.setSize ( width, height );
55  this->padding = padding;
56  this->updated = false;
57 }
58 
59 void GrayFrame::update ( void )
60 {
61  if ( this->updated == true )
62  return;
63 
64  int32 x = this->frame_position.x;
65  int32 y = this->frame_position.y;
66  int32 width = this->frame_position.width;
67  int32 height = this->frame_position.height;
68 
69  int32 x_offset = x + width;
70  int32 y_offset = y + height;
71 
72  this->frame.clear();
73 
74  this->frame.push_back ( IDrawable::UniquePtr ( new Line ( x, y, x_offset - padding, y, Color( 41, 41, 41 ) ) ) ); // top0
75  this->frame.push_back ( IDrawable::UniquePtr ( new Line ( x, y + 1, x_offset - padding, y + 1, Color( 133, 133, 133 ) ) ) ); // top1
76 
77  this->frame.push_back ( IDrawable::UniquePtr ( new Line ( x, y + 1, x, y_offset - padding, Color( 41, 41, 41 ) ) ) ); // left0
78  this->frame.push_back ( IDrawable::UniquePtr ( new Line ( x + 1, y + 2, x + 1, y_offset - padding, Color( 133, 133, 133 ) ) ) ); // left1
79 
80  this->frame.push_back ( IDrawable::UniquePtr ( new Line ( x_offset, y, x_offset, y_offset - padding, Color( 57, 57, 57 ) ) ) ); // right0
81  this->frame.push_back ( IDrawable::UniquePtr ( new Line ( x_offset, y, x_offset, y_offset - padding, Color( 41, 41, 41 ) ) ) ); // right1
82 
83  this->frame.push_back ( IDrawable::UniquePtr ( new Line ( x, y_offset - padding, x_offset - padding, y_offset - padding, Color( 57, 57, 57 ) ) ) ); //bottom0
84  this->frame.push_back ( IDrawable::UniquePtr ( new Line ( x, y_offset - padding, x_offset - padding, y_offset - padding, Color ( 41, 41, 41 ) ) ) ); // bottom1
85 
86  this->updated = true;
87 }
88 
89 void GrayFrame::draw ( RenderTarget target ) const
90 {
91  for ( auto idx = 0; idx != this->frame.size(); ++idx )
92  {
93  this->frame[idx]->draw ( target );
94  }
95 }
96 
97 
98  } // namespace ui
99 } // namespace nom
int32 padding
Deprecated; this will be removed in a future version.
Definition: GrayFrame.hpp:81
IDrawable::UniqueDrawables frame
Holds our line objects used for rendering the object.
Definition: GrayFrame.hpp:72
Coords frame_position
Position &amp; Size.
Definition: GrayFrame.hpp:75
void draw(RenderTarget target) const
Render the object onto the primary video buffer – your visible screen.
Definition: GrayFrame.cpp:89
3D Line segment shape
Definition: Line.hpp:48
void update(void)
Definition: GrayFrame.cpp:59
std::unique_ptr< IDrawable > UniquePtr
std::unique_ptr definition type for your convenience, sir!
Definition: IDrawable.hpp:47
Utility class container for RGBA colors.
Definition: Color.hpp:43
bool updated
Track object logic changes for updating its rendering.
Definition: GrayFrame.hpp:78