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