1 /* Copyright (C) 2014 The cluttermm Development Team
2 *
3 * This library is free software; you can redistribute it and/or
4 * modify it under the terms of the GNU Lesser General Public
5 * License as published by the Free Software Foundation; either
6 * version 2.1 of the License, or (at your option) any later version.
7 *
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public
14 * License along with this library; if not, write to the Free
15 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
16 */
17
18 #include <cluttermm.h>
19 #include <iostream>
20
main(int argc,char ** argv)21 int main(int argc, char** argv)
22 {
23 // initialize the C++ wrapper types
24 Clutter::init(&argc, &argv);
25
26 //a return value to allow make check to output a useful summary:
27 int errorval(0);
28
29 int int_a(1);
30 int int_b(2);
31 int int_c(400);
32 int int_d(500);
33 std::cout << "Creating Clutter::ActorBox with (int) values:"<< int_a << "/" << int_b << " and " << int_c << "/" << int_d << std::endl;
34
35 Clutter::ActorBox box1 = Clutter::ActorBox( int_a, int_b, int_c, int_d );
36
37 if( ( box1.get_x() != int_a ) || ( box1.get_y() != int_b ) )
38 {
39 errorval++;
40 std::cerr << "Getting incorrect values from Box1: " << box1.get_x() <<
41 " should be " << int_a << " , " << box1.get_y() << "should be " <<
42 int_b << std::endl;
43 }
44 if( ( box1.get_width() != ( int_c - int_a ) ) ||
45 ( box1.get_height() != (int_d - int_b ) ) )
46 {
47 errorval++;
48 std::cerr << "Getting incorrect values from Box1: " << box1.get_width() <<
49 " should be " << int_c - int_a << " , " << box1.get_height() << "should be " <<
50 int_d - int_b << std::endl;
51 }
52
53 // copy and (in)equality:
54 Clutter::ActorBox box2 = box1;
55
56 if(box1 != box2)
57 {
58 errorval+= 10;
59 std::cerr << " box1 and box2 not equal." << std::endl;
60 std::cerr << "box1: origin " << box1.get_x() << "/" << box1.get_y() <<
61 ", width = " << box1.get_width() << ", height = " << box1.get_height()
62 <<std::endl;
63 }
64
65 //get and set origin (and default constructor):
66 Clutter::ActorBox box3;
67 float new_origin_x(100);
68 float new_origin_y(101);
69
70 box3.set_origin( new_origin_x, new_origin_y );
71 float origin_x(0);
72 float origin_y(0);
73 box3.get_origin(origin_x, origin_y);
74
75 if( ( origin_x != new_origin_x ) || ( origin_y != new_origin_y ) )
76 {
77 errorval += 20;
78 std::cerr<< "get/set origin not correct: Set " << new_origin_x << "/ " <<
79 new_origin_y << "; returned " <<
80 origin_x << "/ " << origin_y <<std::endl;
81 }
82
83 //get and set size:
84 float new_size_x(200);
85 float new_size_y(201);
86 box3.set_size( new_size_x, new_size_y );
87
88 float size_x(0);
89 float size_y(0);
90 box3.get_size(size_x, size_y);
91
92 if( ( size_x != new_size_x ) || ( size_y != new_size_y ) )
93 {
94 errorval += 30;
95 std::cerr << "get/set size not correct: Set " << new_size_x << "/ " <<
96 new_size_y << "; returned " <<
97 size_x << "/ " << size_y <<std::endl;
98 }
99
100 //get_area:
101 if( box1.get_area() != ( (int_d - int_b ) * ( int_c - int_a ) ) )
102 {
103 errorval += 100;
104 std::cerr<< "get area incorrect for box1 " << box1.get_area() << " vs " <<
105 ( (int_d - int_b ) * ( int_c - int_a ) ) << std::endl;
106 }
107
108 if( box3.get_area() != ( new_size_x * new_size_y ) )
109 {
110 errorval += 200;
111 std::cerr<< "get area incorrect for box3 " << box3.get_area() << " vs " <<
112 new_size_x * new_size_y << std::endl;
113 }
114
115 // contains:
116 Clutter::ActorBox box4(30, 30, 100, 101);
117 // outside:
118 if( box4.contains(25, 50) )
119 {
120 errorval+= 1000;
121 std::cerr << "ActorBox::contains is wrong: box4 contains 25-50." << std::endl;
122 }
123 // inside:
124 if( box4.contains(50, 50) == false)
125 {
126 errorval += 2000;
127 std::cerr << " ActorBox::contains : 30, 30, 100, 101 doesn't contain 50-50." << std::endl;
128 }
129
130 // TODO: clamp_to_pixel, interpolate, unite.
131
132 return errorval;
133 }
134