Transformable.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/math/Transformable.hpp"
30 
31 namespace nom {
32 
33 Transformable::Transformable ( void ) : coords ( 0, 0, 0, 0 ),
34  color ( 0, 0, 0, 255 )
35 {
36  // Nothing to initialize
37 }
38 
39 Transformable::Transformable ( const Coords& coords ): coords ( coords ) {}
40 
41 Transformable::Transformable ( const Coords& coords, const Color& color )
42 {
43  this->coords = coords;
44  this->color = color;
45 }
46 
47 Transformable::~Transformable ( void ) {}
48 
49 const Coords Transformable::getPosition ( void ) const
50 {
51  return Coords ( this->coords.x, this->coords.y );
52 }
53 
54 const Coords Transformable::getSize ( void ) const
55 {
56  return Coords ( this->coords.width, this->coords.height );
57 }
58 
59 // Variant #1 setter for position coordinates
60 void Transformable::setPosition ( int32 x, int32 y )
61 {
62  this->coords.setPosition ( x, y );
63 }
64 
65 // Variant #2 setter for position coordinates
66 void Transformable::setPosition ( int32 x, int32 y, int32 width, int32 height )
67 {
68  this->coords = Coords ( x, y, width, height );
69 }
70 
71 // Variant #3 setter for position coordinates; do we have enough options yet???
72 void Transformable::setPosition ( const Coords& coords )
73 {
74  this->setPosition ( coords.x, coords.y, coords.width, coords.height );
75 }
76 
77 void Transformable::setSize ( int32 width, int32 height )
78 {
79  this->coords.setSize ( width, height );
80 }
81 
82 void Transformable::setSize ( const Coords& size )
83 {
84  this->setSize ( size.width, size.height );
85 }
86 
87 void Transformable::move ( uint32 x, uint32 y )
88 {
89  this->coords.x += x;
90  this->coords.y += y;
91 }
92 
93 void Transformable::move ( const Coords& offsets )
94 {
95  this->coords.x += offsets.x;
96  this->coords.y += offsets.y;
97 }
98 
99 const Color& Transformable::getColor ( void ) const
100 {
101  return this->color;
102 }
103 
104 void Transformable::setColor ( uint8 red, uint8 green, uint8 blue, uint8 alpha )
105 {
106  this->color = Color ( red, green, blue, alpha );
107 }
108 
109 void Transformable::setColor ( const Color& color )
110 {
111  this->setColor ( color.red, color.green, color.blue, color.alpha );
112 }
113 
114 
115 } // namespace nom