author | insilmaril |
Tue Jun 14 09:41:37 2005 +0000 (2005-06-14) | |
changeset 106 | 4083860dd82e |
parent 0 | 7a96bd401351 |
child 129 | 9b9c7e8b9147 |
permissions | -rw-r--r-- |
insilmaril@0 | 1 |
#include "mapobj.h" |
insilmaril@0 | 2 |
|
insilmaril@0 | 3 |
///////////////////////////////////////////////////////////////// |
insilmaril@0 | 4 |
// MapObj |
insilmaril@0 | 5 |
///////////////////////////////////////////////////////////////// |
insilmaril@0 | 6 |
MapObj::MapObj () |
insilmaril@0 | 7 |
{ |
insilmaril@0 | 8 |
// TODO not used any longer... |
insilmaril@0 | 9 |
cout << "Const MapObj (): Please set canvas somehow!!!\n"; |
insilmaril@0 | 10 |
// canvas=actMapEditor->getCanvas(); |
insilmaril@0 | 11 |
init (); |
insilmaril@0 | 12 |
} |
insilmaril@0 | 13 |
|
insilmaril@0 | 14 |
MapObj::MapObj (QCanvas* c) |
insilmaril@0 | 15 |
{ |
insilmaril@0 | 16 |
// cout << "Const MapObj\n"; |
insilmaril@0 | 17 |
canvas=c; |
insilmaril@0 | 18 |
init (); |
insilmaril@0 | 19 |
} |
insilmaril@0 | 20 |
|
insilmaril@0 | 21 |
|
insilmaril@0 | 22 |
MapObj::MapObj (MapObj* mo) |
insilmaril@0 | 23 |
{ |
insilmaril@0 | 24 |
// cout << "CopyConst MapObj\n"; |
insilmaril@0 | 25 |
copy (mo); |
insilmaril@0 | 26 |
} |
insilmaril@0 | 27 |
|
insilmaril@0 | 28 |
MapObj::~MapObj () |
insilmaril@0 | 29 |
{ |
insilmaril@0 | 30 |
// cout << "Destr MapObj\n"; |
insilmaril@0 | 31 |
} |
insilmaril@0 | 32 |
|
insilmaril@0 | 33 |
void MapObj::init () |
insilmaril@0 | 34 |
{ |
insilmaril@0 | 35 |
absPos=QPoint(0,0); |
insilmaril@0 | 36 |
visible=true; |
insilmaril@0 | 37 |
} |
insilmaril@0 | 38 |
|
insilmaril@0 | 39 |
void MapObj::copy(MapObj* other) |
insilmaril@0 | 40 |
{ |
insilmaril@0 | 41 |
// canvas=other->canvas; // already set in constr. of child, use that one... |
insilmaril@0 | 42 |
absPos=other->absPos; |
insilmaril@0 | 43 |
bbox.setX (other->bbox.x() ); |
insilmaril@0 | 44 |
bbox.setY (other->bbox.y() ); |
insilmaril@0 | 45 |
bbox.setSize (QSize(other->bbox.width(), other->bbox.height() ) ); |
insilmaril@0 | 46 |
} |
insilmaril@0 | 47 |
|
insilmaril@0 | 48 |
QCanvas* MapObj::getCanvas() |
insilmaril@0 | 49 |
{ |
insilmaril@0 | 50 |
return canvas; |
insilmaril@0 | 51 |
} |
insilmaril@0 | 52 |
|
insilmaril@0 | 53 |
int MapObj::x() |
insilmaril@0 | 54 |
{ |
insilmaril@0 | 55 |
return absPos.x(); |
insilmaril@0 | 56 |
} |
insilmaril@0 | 57 |
|
insilmaril@0 | 58 |
int MapObj::y() |
insilmaril@0 | 59 |
{ |
insilmaril@0 | 60 |
return absPos.y(); |
insilmaril@0 | 61 |
} |
insilmaril@0 | 62 |
|
insilmaril@0 | 63 |
int MapObj::width() |
insilmaril@0 | 64 |
{ |
insilmaril@0 | 65 |
return bbox.width(); |
insilmaril@0 | 66 |
} |
insilmaril@0 | 67 |
|
insilmaril@0 | 68 |
int MapObj::height() |
insilmaril@0 | 69 |
{ |
insilmaril@0 | 70 |
return bbox.height(); |
insilmaril@0 | 71 |
} |
insilmaril@0 | 72 |
|
insilmaril@0 | 73 |
void MapObj::move (double x, double y) |
insilmaril@0 | 74 |
{ |
insilmaril@0 | 75 |
int xi=static_cast <int> (x); |
insilmaril@0 | 76 |
int yi=static_cast <int> (y); |
insilmaril@0 | 77 |
absPos.setX( xi); |
insilmaril@0 | 78 |
absPos.setY( yi); |
insilmaril@0 | 79 |
bbox.moveTopLeft(QPoint(xi,yi)); |
insilmaril@0 | 80 |
} |
insilmaril@0 | 81 |
|
insilmaril@0 | 82 |
void MapObj::moveBy (double x, double y) |
insilmaril@0 | 83 |
{ |
insilmaril@0 | 84 |
move (x+absPos.x(),y+absPos.y() ); |
insilmaril@0 | 85 |
} |
insilmaril@0 | 86 |
|
insilmaril@0 | 87 |
bool MapObj::inBBox(QPoint p) |
insilmaril@0 | 88 |
{ |
insilmaril@0 | 89 |
if (p.x() >= bbox.left() && p.x() <= bbox.right() |
insilmaril@0 | 90 |
&& p.y() <= bbox.bottom() && p.y() >= bbox.top() ) |
insilmaril@0 | 91 |
return true; |
insilmaril@0 | 92 |
return false; |
insilmaril@0 | 93 |
} |
insilmaril@0 | 94 |
|
insilmaril@0 | 95 |
QRect MapObj::getBBox() |
insilmaril@0 | 96 |
{ |
insilmaril@0 | 97 |
return bbox; |
insilmaril@0 | 98 |
} |
insilmaril@0 | 99 |
|
insilmaril@0 | 100 |
QRect MapObj::addBBox(QRect r1, QRect r2) |
insilmaril@0 | 101 |
{ |
insilmaril@0 | 102 |
QRect n; |
insilmaril@0 | 103 |
// Set left border |
insilmaril@0 | 104 |
if (r1.left() <= r2.left() ) |
insilmaril@0 | 105 |
n.setLeft(r1.left() ); |
insilmaril@0 | 106 |
else |
insilmaril@0 | 107 |
n.setLeft(r2.left() ); |
insilmaril@0 | 108 |
|
insilmaril@0 | 109 |
// Set top border |
insilmaril@0 | 110 |
if (r1.top() <= r2.top() ) |
insilmaril@0 | 111 |
n.setTop(r1.top() ); |
insilmaril@0 | 112 |
else |
insilmaril@0 | 113 |
n.setTop(r2.top() ); |
insilmaril@0 | 114 |
|
insilmaril@0 | 115 |
// Set right border |
insilmaril@0 | 116 |
if (r1.right() <= r2.right() ) |
insilmaril@0 | 117 |
n.setRight(r2.right() ); |
insilmaril@0 | 118 |
else |
insilmaril@0 | 119 |
n.setRight(r1.right() ); |
insilmaril@0 | 120 |
|
insilmaril@0 | 121 |
// Set bottom |
insilmaril@0 | 122 |
if (r1.bottom() <= r2.bottom() ) |
insilmaril@0 | 123 |
n.setBottom(r2.bottom() ); |
insilmaril@0 | 124 |
else |
insilmaril@0 | 125 |
n.setBottom(r1.bottom() ); |
insilmaril@0 | 126 |
return n; |
insilmaril@0 | 127 |
} |
insilmaril@0 | 128 |
|
insilmaril@0 | 129 |
QSize MapObj::getSize() |
insilmaril@0 | 130 |
{ |
insilmaril@0 | 131 |
return bbox.size(); |
insilmaril@0 | 132 |
} |
insilmaril@0 | 133 |
|
insilmaril@0 | 134 |
|
insilmaril@0 | 135 |
bool MapObj::isVisibleObj() |
insilmaril@0 | 136 |
{ |
insilmaril@0 | 137 |
return visible; |
insilmaril@0 | 138 |
} |
insilmaril@0 | 139 |
|
insilmaril@0 | 140 |
void MapObj::setVisibility(bool v) |
insilmaril@0 | 141 |
{ |
insilmaril@0 | 142 |
visible=v; |
insilmaril@0 | 143 |
} |
insilmaril@93 | 144 |