house.cpp

Go to the documentation of this file.
00001 
00002 #include "house.h"
00003 #include "desktop.h"
00004 
00005 const c_point body_left_bottom(0, 0);
00006 const c_point body_right_top(50, 50);
00007 const c_point roof_max(25, 75);
00008 const c_rectangle win1(10, 7, 15, 15);
00009 const c_rectangle win2(14, 30, 32, 45);
00010 const c_rectangle door_size(25, 3, 35, 22);
00011 
00012 house::house(const c_point &origin, canvas *draw_on)
00013    : left_roof(c_point(body_left_bottom.x - 5, body_right_top.y), roof_max),
00014      right_roof(c_point(body_right_top.x + 5, body_right_top.y), roof_max),
00015      roof_base(left_roof.location().end1, right_roof.location().end1),
00016      house_body(body_left_bottom, body_right_top), win_1(win1), win_2(win2),
00017      door(door_size), my_canvas(draw_on)
00018 {
00019   house_body.my_color.set_color(RED);
00020   left_roof.my_color.set_color(WHITE);
00021   right_roof.my_color.set_color(WHITE);
00022   roof_base.my_color.set_color(WHITE);
00023   door.my_color.set_color(LIGHT_MAGENTA);
00024   win_1.my_color.set_color(BLACK);
00025   win_2.my_color.set_color(BLACK);
00026 
00027   set_canvas(my_canvas);
00028   set_origin(origin);
00029 }
00030 
00031 void house::set_canvas(canvas *draw_on)
00032 {
00033   my_canvas = draw_on;
00034   house_body.set_canvas(my_canvas);
00035   left_roof.set_canvas(my_canvas);
00036   right_roof.set_canvas(my_canvas);
00037   roof_base.set_canvas(my_canvas);
00038   door.set_canvas(my_canvas);
00039   win_1.set_canvas(my_canvas);
00040   win_2.set_canvas(my_canvas);
00041 }
00042 
00043 void house::set_origin(const c_point &origin)
00044 {
00045   if (origin == my_origin) return;
00046   c_point diff = origin - my_origin;
00047   my_origin = origin;
00048   left_roof.set_origin(left_roof.origin() + diff);
00049   right_roof.set_origin(right_roof.origin() + diff);
00050   roof_base.set_origin(roof_base.origin() + diff);
00051   door.set_origin(door.origin() + diff);
00052   win_1.set_origin(win_1.origin() + diff);
00053   win_2.set_origin(win_2.origin() + diff);
00054   house_body.set_origin(origin);
00055 }
00056 
00057 c_rectangle house::dimensions()
00058 {
00059   return c_rectangle(roof_base.location().end1.x,
00060       house_body.location().left_bottom.y,
00061       roof_base.location().end2.x,
00062       left_roof.location().end2.y);
00063 }
00064 
00065 int house::width()
00066   { return dimensions().right_top.x - dimensions().left_bottom.x + 1; }
00067 
00068 int house::height()
00069   { return dimensions().right_top.y - dimensions().left_bottom.y + 1; }
00070 
00071 void house::draw()
00072 {
00073   house_body.draw();
00074   roof_base.draw();
00075   left_roof.draw();
00076   right_roof.draw();
00077   door.draw();
00078   win_1.draw();
00079   win_2.draw();
00080 }
00081 
00082 void house::erase()
00083 {
00084   house_body.erase();
00085   door.erase();
00086   win_1.erase();
00087   win_2.erase();
00088   roof_base.erase();
00089   left_roof.erase();
00090   right_roof.erase();
00091 }

Generated on Fri Nov 21 04:30:03 2008 for HOOPLE Libraries by  doxygen 1.5.1