00001
00002
00003
00004
00005 #include "t_passive.h"
00006
00007 #include <basis/guards.h>
00008 #include <basis/portable.h>
00009 #include <opsystem/application_shell.h>
00010 #include <loggers/console_logger.h>
00011 #include <data_struct/static_memory_gremlin.h>
00012 #include <wp_passive/argument_list.h>
00013 #include <wp_passive/box.h>
00014 #include <wp_passive/canvas.h>
00015 #include <wp_passive/dot.h>
00016 #include <wp_passive/label.h>
00017 #include <wp_passive/manager.h>
00018 #include <wp_passive/oval.h>
00019 #include <wp_passive/ring.h>
00020 #include <wp_passive/visible_line.h>
00021
00022 #include <stdio.h>
00023
00024 #undef LOG
00025 #define LOG(s) program_wide_logger().log(s)
00026
00027 void getkey(manager &root)
00028 {
00029 XFlush(root.display());
00030 LOG("please enter a word now.");
00031
00032 getchar();
00033 }
00034
00035 template <class content>
00036 void random_reposition(content &target, chaos &randomizer)
00037 {
00038
00039 for (int ijiji = 0; ijiji < 20000; ijiji++) {
00040 c_rectangle r
00041 (randomizer.inclusive(0, 1000),
00042 randomizer.inclusive(0, 1000),
00043 randomizer.inclusive(0, 1000),
00044 randomizer.inclusive(0, 1000));
00045 target.dimensions(r);
00046 XFlush(target.display());
00047 }
00048 }
00049
00050 void four_corner_root(manager &root)
00051 {
00052
00053 root.dimensions(c_rectangle(0, 0, 50, 50));
00054 getkey(root);
00055 root.dimensions(c_rectangle(50, 0, 100, 50));
00056 getkey(root);
00057 root.dimensions(c_rectangle(50, 50, 100, 100));
00058 getkey(root);
00059 root.dimensions(c_rectangle(0, 50, 50, 100));
00060 getkey(root);
00061 root.dimensions(default_manager_size);
00062 }
00063
00064 void four_corner_canvas(canvas &testwin, manager &root)
00065 {
00066
00067 testwin.dimensions(c_rectangle(0, 0, 50, 50));
00068 getkey(root);
00069 testwin.dimensions(c_rectangle(950, 0, 1000, 50));
00070 getkey(root);
00071 testwin.dimensions(c_rectangle(950, 950, 1000, 1000));
00072 getkey(root);
00073 testwin.dimensions(c_rectangle(0, 950, 50, 1000));
00074 getkey(root);
00075 testwin.dimensions(c_rectangle(100, 100, 900, 900));
00076 }
00077
00078 void query_desktop(manager &root)
00079 {
00080 LOG(istring("desktop reports device size as ")
00081 + root.device_coordinate_system().text_form()
00082 + " and the view is "
00083 + root.view_coordinate_system().text_form());
00084 if ( (root.device_to_view(root.device_coordinate_system())
00085 != root.view_coordinate_system())
00086 || (root.view_to_device(root.view_coordinate_system())
00087 != root.device_coordinate_system()) )
00088 deadly_error("t_passive", "desktop test:",
00089 "systems or transformations incorrect");
00090 if ( root.view_to_device(root.device_to_view(c_point(-23, -590)))
00091 != c_point(-23, -590))
00092 deadly_error("t_passive", "desktop test:",
00093 "point conversion is not invertible");
00094 }
00095
00096 void query_manager(manager &root)
00097 {
00098 LOG(istring("manager universal coordinates ") + root.universe().text_form()
00099 + " and its position in the view coordinates is "
00100 + root.dimensions().text_form());
00101 c_rectangle relative_device_location
00102 (root.view_to_device(root.dimensions())
00103 - root.view_to_device(root.dimensions()).vertex_1());
00104 if ( (root.device_to_universe(relative_device_location)
00105 != root.universe())
00106 || (root.universe_to_device(root.universe())
00107 != relative_device_location) )
00108 deadly_error("t_passive", "manager test:",
00109 "systems or transformations incorrect");
00110 if ( root.universe_to_device(root.device_to_universe(c_point(-23, -590)))
00111 != c_point(-23, -590))
00112 deadly_error("t_passive", "manager test:",
00113 "point conversion is not invertible");
00114 }
00115
00116 void query_canvas(canvas &testwin, manager &root)
00117 {
00118 LOG(istring("canvas posn in universal coordinates ")
00119 + testwin.dimensions().text_form()
00120 + " and its world is "
00121 + testwin.world().text_form());
00122 c_rectangle relative_device_location
00123 (root.universe_to_device(testwin.dimensions())
00124 - root.universe_to_device(testwin.dimensions()).vertex_1());
00125 if ( (testwin.device_to_world(relative_device_location)
00126 != testwin.world())
00127 || (testwin.world_to_device(testwin.world())
00128 != relative_device_location) )
00129 deadly_error("t_passive", "canvas test:",
00130 "systems or transformations incorrect");
00131 if ( root.universe_to_device(root.device_to_universe(c_point(-23, -590)))
00132 != c_point(-23, -590))
00133 deadly_error("t_passive", "canvas test:",
00134 "point conversion is not invertible");
00135 }
00136
00138
00139 class passive_tester : public application_shell
00140 {
00141 public:
00142 passive_tester() : application_shell(class_name()) {}
00143 IMPLEMENT_CLASS_NAME("t_passive");
00144 virtual int execute();
00145 };
00146
00148
00149 int passive_tester::execute()
00150 {
00151 manager root("A Frisky Test Program for the Passive Parts");
00152
00153
00154 query_desktop(root);
00155 query_manager(root);
00156
00157 root.install_gray_colormap(64);
00158
00159
00160
00161
00162
00163 const color orange = root.lookup("orange");
00164 const color brown = root.lookup("brown");
00165 const color wheat = root.lookup("wheat");
00166 const color gray = root.lookup("gray");
00167 const color blue(root.lookup("blue"));
00168 const color gold(root.lookup("gold"));
00169 const color red(root.lookup("red"));
00170 const color green(root.lookup("green"));
00171 const color magenta(root.lookup("MAGENTA"));
00172
00173 LOG("color scheme:");
00174 LOG(isprintf("name is orange, values=%s", orange.text_form().s()));
00175 LOG(isprintf("name is brown, values=%s", brown.text_form().s()));
00176 LOG(isprintf("name is wheat, values=%s", wheat.text_form().s()));
00177 LOG(isprintf("name is gray, values=%s", gray.text_form().s()));
00178 LOG(isprintf("name is blue, values=%s", blue.text_form().s()));
00179 LOG(isprintf("name is gold, values=%s", gold.text_form().s()));
00180 LOG(isprintf("name is red, values=%s", red.text_form().s()));
00181 LOG(isprintf("name is green, values=%s", green.text_form().s()));
00182 LOG(isprintf("name is magenta, values=%s", magenta.text_form().s()));
00183
00184 label continue_message
00185 (root, c_point(20, 10), "Type Ctrl-C to exit please.", orange, brown);
00186 continue_message.draw();
00187
00188
00189
00190 label changed_message
00191 (root, c_point(20, 30), "If you see this, reset doesn't work.", red, blue);
00192 changed_message.draw();
00193
00194 chaos randomizer;
00195
00196
00197
00198 c_rectangle initdim(100, 100, 450, 900);
00199 canvas testwin(root, initdim, default_world, wheat, gray);
00200 query_canvas(testwin, root);
00201 testwin.draw();
00202
00203 canvas test2
00204 (root, c_rectangle(550, 100, 900, 450), default_world, blue, wheat);
00205 test2.draw();
00206 canvas test3
00207 (root, c_rectangle(550, 550, 900, 900), default_world, gold, red);
00208 test3.draw();
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218 LOG("a");
00219
00220 visible_line red_line(testwin,
00221 c_line(testwin.world().vertex_1(), testwin.world().vertex_2()));
00222 LOG("b");
00223 c_line fredo(1, 2, 3, 4);
00224 LOG("b.1");
00225 LOG(istring("testwin world: ") + testwin.world().text_form());
00226 LOG(isprintf("%f\n", testwin.world().vertex_2().x()));
00227 LOG(isprintf("%f\n", testwin.world().vertex_1().y()));
00228 LOG(isprintf("%f\n", testwin.world().vertex_1().x()));
00229 LOG(isprintf("%f\n", testwin.world().vertex_2().y()));
00230 c_line jello(testwin.world().vertex_2().x(), testwin.world().vertex_1().y(), testwin.world().vertex_1().x(), testwin.world().vertex_2().y());
00231 LOG(istring("jello is ") + jello.text_form());
00232 LOG("b.1.1");
00233 visible_line red_line2(testwin,
00234 c_line(testwin.world().vertex_2().x(), testwin.world().vertex_1().y(),
00235 testwin.world().vertex_1().x(), testwin.world().vertex_2().y()));
00236 LOG("b.2");
00237 red_line.foreground(red); red_line2.foreground(red);
00238 LOG("b.3");
00239 red_line.draw(); red_line2.draw();
00240 LOG("b.4");
00241
00242 LOG("c");
00243 c_line tedlo(test2.world().vertex_1(), test2.world().vertex_2());
00244 printf((istring("newline ") + tedlo.text_form() + "\n").s());
00245 LOG("d");
00246 visible_line blue_line(test2, c_line(test2.world().vertex_1(),
00247 test2.world().vertex_2()), blue);
00248 LOG("e");
00249 visible_line blue_line2(test2,
00250 c_line(test2.world().vertex_2().x(), test2.world().vertex_1().y(),
00251 test2.world().vertex_1().x(), test2.world().vertex_2().y()), blue);
00252 LOG("f");
00253 blue_line.draw();
00254 LOG("g");
00255 blue_line2.draw();
00256 LOG("h");
00257
00258 visible_line green_line(test3, c_line(test3.world().vertex_1(),
00259 test3.world().vertex_2()), green);
00260 LOG("i");
00261 visible_line green_line2(test3,
00262 c_line(test3.world().vertex_2().x(), test3.world().vertex_1().y(),
00263 test3.world().vertex_1().x(), test3.world().vertex_2().y()), green);
00264 green_line.draw();
00265 green_line2.draw();
00266
00267 ring my_ring(testwin, geometric::circle(450, testwin.world().center()));
00268 my_ring.draw();
00269 LOG("e");
00270
00271
00272
00273
00274
00275 box full_box(testwin, c_rectangle(c_point(150, 200), c_point(480, 420)));
00276 full_box.set_filled(true);
00277 full_box.foreground(magenta);
00278 full_box.layer(2);
00279 full_box.draw();
00280
00281 box full_box2(testwin, c_rectangle(c_point(200, 230), c_point(250, 650)));
00282 full_box2.set_filled(true);
00283 full_box2.foreground(green);
00284 full_box2.layer(4);
00285 full_box2.draw();
00286
00287 box full_box3(testwin, c_rectangle(c_point(100, 180), c_point(220, 320)));
00288 full_box3.set_filled(true);
00289 full_box3.foreground(blue);
00290 full_box3.layer(3);
00291 full_box3.draw();
00292
00293 testwin.update();
00294 testwin.draw();
00295
00296 c_rectangle quart_world(testwin.world());
00297 c_point new_2(quart_world.vertex_2().x() / 2, quart_world.vertex_2().y() / 2);
00298 quart_world.vertex_2(new_2);
00299 oval my_oval(testwin, geometric::ellipse(quart_world.center(), quart_world.width() / 2,
00300 quart_world.height() / 2), gold);
00301 my_oval.draw();
00302
00303 guards::alert_message("hey, now going to draw over the oval; hit a key.");
00304
00305 box bo(my_oval.target(), my_oval.dimensions(), colors::WHITE);
00306 bo.set_filled();
00307 bo.draw();
00308
00310
00311 int i;
00312 for (i = 0; i < 360; i += 20) {
00313 c_point place_on_oval(my_oval.base().location(c_angle(i, c_angle::DEGREES)));
00314 box *little_box = new box
00315 (testwin,
00316 c_rectangle(place_on_oval - c_point(5, 5), place_on_oval + c_point(5, 5)),
00317 orange, true);
00318 little_box->set_filled(true);
00319 little_box->draw();
00320 }
00321
00322 const int number_of_stars = 70;
00323
00324 LOG(isprintf("about to draw point using world size: %d %d",
00325 int(testwin.world().width()), int(testwin.world().height())));
00326 LOG(istring("world region: ") + testwin.world().text_form());
00327
00328 box *temp = new box(testwin, c_rectangle(0, 0, 20, 20), orange, true);
00329 temp->draw();
00330
00331 for (i = 0; i < number_of_stars; i++) {
00332 color randcol = color
00333 (randomizer.inclusive(1, MAXIMUM_COLOR_INTENSITY),
00334 randomizer.inclusive(1, MAXIMUM_COLOR_INTENSITY),
00335 randomizer.inclusive(1, MAXIMUM_COLOR_INTENSITY));
00336 int x = randomizer.inclusive(0, int(testwin.world().width()));
00337 int y = randomizer.inclusive(0, int(testwin.world().height()));
00338 ring *star = new ring(testwin, geometric::circle(5, c_point(x, y)), randcol);
00339
00340
00341
00342
00343 star->draw();
00344 }
00345
00346
00347
00348 LOG("before name change");
00349
00350
00351 root.name("A different name now!");
00352
00353
00354
00355
00356
00357
00358
00359
00360
00361
00362
00363
00364
00365
00366
00367
00368
00369
00370
00371
00372
00373
00374
00375
00376
00377
00378
00379
00380
00381
00382
00383
00384
00385
00386
00387
00388
00389
00390
00391
00392
00393
00394
00395
00396
00397
00398
00399
00400
00401
00402
00403
00404
00405
00406
00407
00408
00409
00410
00411
00412
00413
00414
00415
00416
00417
00418
00419
00420
00421
00422
00423
00425
00426 changed_message.reset("This is the right message to see.");
00427
00428 root.poll();
00429
00430
00431
00432 return 0;
00433 }
00434
00436
00437 HOOPLE_MAIN(passive_tester, )
00438