42 #include <QApplication>
44 #include <QDesktopWidget>
50 #include <qalgorithms.h>
52 #include <qpainterpath.h>
64 QList<QtCanvasView*> viewList;
65 QSet<QtCanvasItem*> itemDict;
66 QSet<QtCanvasItem*> animDict;
86 void add(
int x,
int y);
87 void add(
int x,
int y,
int w,
int h);
88 void add(
const QRect& rect);
95 const QRect& operator[](
int i)
const;
104 void include(QRect& r,
const QRect& rect)
106 if (rect.left() < r.left())
108 r.setLeft(rect.left());
111 if (rect.right() > r.right())
113 r.setRight(rect.right());
116 if (rect.top() < r.top())
118 r.setTop(rect.top());
121 if (rect.bottom() > r.bottom())
123 r.setBottom(rect.bottom());
132 cluster(new QRect[maxclusters]),
149 add(QRect(x, y, 1, 1));
154 add(QRect(x, y, w, h));
159 QRect biggerrect(rect.x() - 1, rect.y() - 1, rect.width() + 2, rect.height() + 2);
165 for (cursor = 0; cursor < count; cursor++)
174 int lowestcost = 9999999;
178 while (cursor < count)
182 QRect larger = cluster[cursor];
183 include(larger, rect);
184 int cost = larger.width() * larger.height() -
185 cluster[cursor].width() * cluster[cursor].height();
187 if (cost < lowestcost)
191 for (
int c = 0;
c < count && !bad;
c++)
193 bad = cluster[
c].intersects(larger) &&
c != cursor;
209 include(cluster[cheapest], rect);
215 cluster[count++] = rect;
223 lowestcost = 9999999;
227 while (cursor < count)
229 QRect larger = cluster[cursor];
230 include(larger, rect);
231 int cost = larger.width() * larger.height()
232 - cluster[cursor].width() * cluster[cursor].height();
234 if (cost < lowestcost)
238 for (
int c = 0;
c < count && !bad;
c++)
240 bad = cluster[
c].intersects(larger) &&
c != cursor;
257 int cheapestmerge1 = -1;
258 int cheapestmerge2 = -1;
262 while (merge1 < count)
266 while (merge2 < count)
268 if (merge1 != merge2)
270 QRect larger = cluster[merge1];
271 include(larger, cluster[merge2]);
272 int cost = larger.width() * larger.height()
273 - cluster[merge1].width() * cluster[merge1].height()
274 - cluster[merge2].width() * cluster[merge2].height();
276 if (cost < lowestcost)
280 for (
int c = 0;
c < count && !bad;
c++)
282 bad = cluster[
c].intersects(larger) &&
c != cursor;
287 cheapestmerge1 = merge1;
288 cheapestmerge2 = merge2;
300 if (cheapestmerge1 >= 0)
302 include(cluster[cheapestmerge1], cluster[cheapestmerge2]);
303 cluster[cheapestmerge2] = cluster[count--];
308 include(cluster[cheapest], rect);
335 if (i1->
z() == i2->
z())
340 return (i1->
z() > i2->
z());
364 m_list.prepend(item);
370 m_list.removeAll(item);
397 static int gcd(
int a,
int b)
410 static int scm(
int a,
int b)
572 void QtCanvas::init(
int w,
int h,
int chunksze,
int mxclusters)
577 chunksize = chunksze;
578 maxclusters = mxclusters;
579 chwidth = (w + chunksize - 1) / chunksize;
580 chheight = (h + chunksize - 1) / chunksize;
587 debug_redraw_areas =
false;
635 int h,
int v,
int tilewidth,
int tileheight)
637 init(h * tilewidth,
v * tileheight, scm(tilewidth, tileheight));
638 setTiles(p, h,
v, tilewidth, tileheight);
646 for (
int i = 0; i < d->
viewList.size(); ++i)
653 for (QtCanvasItemList::Iterator it =
all.begin(); it !=
all.end(); ++it)
669 return chunks[i + chwidth * j];
678 return chunk(x / chunksize, y / chunksize);
696 if (awidth == w && aheight == h)
701 QList<QtCanvasItem*> hidden;
703 for (QSet<QtCanvasItem*>::const_iterator it = d->
itemDict.begin(); it != d->
itemDict.end(); ++it)
705 if ((*it)->isVisible())
712 int nchwidth = (w + chunksize - 1) / chunksize;
713 int nchheight = (h + chunksize - 1) / chunksize;
722 chheight = nchheight;
726 for (
int i = 0; i < hidden.size(); ++i)
728 hidden.at(i)->show();
778 maxclusters = mxclusters;
780 if (chunksize != chunksze)
782 QList<QtCanvasItem*> hidden;
784 for (QSet<QtCanvasItem*>::const_iterator it = d->
itemDict.begin(); it != d->
itemDict.end(); ++it)
786 if ((*it)->isVisible())
793 chunksize = chunksze;
795 int nchwidth = (awidth + chunksize - 1) / chunksize;
796 int nchheight = (aheight + chunksize - 1) / chunksize;
803 chheight = nchheight;
807 for (
int i = 0; i < hidden.size(); ++i)
809 hidden.at(i)->show();
940 if (htiles > 1 || vtiles > 1 || pm.isNull())
942 QPalette::ColorRole role = view->widget()->backgroundRole();
943 QPalette viewPalette = view->widget()->palette();
945 view->widget()->setPalette(viewPalette);
972 update_timer->stop();
982 update_timer =
new QTimer(
this);
983 connect(update_timer, SIGNAL(timeout()),
this, SLOT(
advance()));
984 update_timer->start(ms);
1001 update_timer->stop();
1008 delete update_timer;
1011 update_timer =
new QTimer(
this);
1012 connect(update_timer, SIGNAL(timeout()),
this, SLOT(
update()));
1013 update_timer->start(ms);
1041 QSetIterator<QtCanvasItem*> it = d->
animDict;
1043 while (it.hasNext())
1057 while (it.hasNext())
1078 QMatrix iwm = wm.inverted();
1080 QRect ivr = iwm.mapRect(vr);
1093 QRect r = changeBounds();
1095 for (
int i = 0; i < d->
viewList.size(); ++i)
1102 view->widget()->update(tr);
1126 QRect thearea = area.intersected(QRect(0, 0,
width(),
height()));
1128 int mx = (thearea.x() + thearea.width() + chunksize) / chunksize;
1129 int my = (thearea.y() + thearea.height() + chunksize) / chunksize;
1141 int x = thearea.x() / chunksize;
1145 int y = thearea.y() / chunksize;
1164 QRect thearea = area.intersected(QRect(0, 0,
width(),
height()));
1166 int mx = (thearea.x() + thearea.width() + chunksize) / chunksize;
1167 int my = (thearea.y() + thearea.height() + chunksize) / chunksize;
1179 int x = thearea.x() / chunksize;
1183 int y = thearea.y() / chunksize;
1199 QRect QtCanvas::changeBounds()
1203 int mx = (area.x() + area.width() + chunksize) / chunksize;
1204 int my = (area.y() + area.height() + chunksize) / chunksize;
1218 int x = area.x() / chunksize;
1222 int y = area.y() / chunksize;
1230 result |= QRect(x * chunksize, y * chunksize, chunksize + 1, chunksize + 1);
1269 QRect area = inarea.intersected(QRect(0, 0,
width(),
height()));
1276 int lx = area.x() / chunksize;
1277 int ly = area.y() / chunksize;
1278 int mx = area.right() / chunksize;
1279 int my = area.bottom() / chunksize;
1297 for (
int x = lx; x <= mx; x++)
1299 for (
int y = ly; y <= my; y++)
1308 if (chunk(x, y).takeChange())
1311 rgn |= QRegion(x * chunksize - area.x(), y * chunksize - area.y(),
1312 chunksize, chunksize);
1313 allvisible += chunk(x, y).
list();
1318 allvisible += chunk(x, y).
list();
1327 if (!allvisible.isEmpty())
1331 for (
int i = allvisible.size() - 1; i >= 0; --i)
1377 if (x >= 0 && x <
width() && y >= 0 && y <
height())
1424 if (x >= 0 && x <
width() && y >= 0 && y <
height())
1426 chunkContaining(x, y).
add(g);
1439 if (x >= 0 && x <
width() && y >= 0 && y <
height())
1441 chunkContaining(x, y).
remove(g);
1472 for (
int i = 0; i < d->
viewList.size(); ++i)
1475 QPalette::ColorRole role = view->widget()->backgroundRole();
1476 QPalette viewPalette = view->widget()->palette();
1477 viewPalette.setColor(role, bgcolor);
1478 view->widget()->setPalette(viewPalette);
1504 setTiles(p, 1, 1, p.width(), p.height());
1506 for (
int i = 0; i < d->
viewList.size(); ++i)
1509 view->widget()->update();
1530 painter.fillRect(clip, bgcolor);
1534 for (
int x = clip.x() / pm.width();
1535 x < (clip.x() + clip.width() + pm.width() - 1) / pm.width(); x++)
1537 for (
int y = clip.y() / pm.height();
1538 y < (clip.y() + clip.height() + pm.height() - 1) / pm.height(); y++)
1540 painter.drawPixmap(x * pm.width(), y * pm.height(), pm);
1546 const int x1 = clip.left() / tilew;
1547 int x2 = clip.right() / tilew;
1548 const int y1 = clip.top() / tileh;
1549 int y2 = clip.bottom() / tileh;
1551 const int roww = pm.width() / tilew;
1553 for (
int j = y1; j <= y2; j++)
1557 for (
int i = x1; i <= x2; i++)
1562 painter.drawPixmap(i * tilew, j * tileh, pm,
1563 tx * tilew, ty * tileh, tilew, tileh);
1582 if (debug_redraw_areas)
1584 painter.setPen(
red);
1585 painter.setBrush(NoBrush);
1586 painter.drawRect(clip);
1617 int h,
int v,
int tilewidth,
int tileheight)
1619 if (!p.isNull() && (!tilewidth || !tileheight ||
1620 p.width() % tilewidth != 0 || p.height() % tileheight != 0))
1630 if (h &&
v && !p.isNull())
1632 grid =
new ushort[h *
v];
1633 memset(grid, 0, h *
v *
sizeof(ushort));
1644 int s = scm(tilewidth, tileheight);
1645 retune(
s < 128 ?
s : qMax(tilewidth, tileheight));
1708 ushort& t = grid[x + y * htiles];
1714 if (tilew == tileh && tilew == chunksize)
1720 setChanged(QRect(x * tilew, y * tileh, tilew, tileh));
1826 myx(0), myy(0), myz(0)
1998 if (ext || vx != 0.0 || vy != 0.0)
2015 return ext ? ext->vx : 0;
2023 return ext ? ext->vy : 0;
2039 if (ext && phase == 1)
2041 moveBy(ext->vx, ext->vy);
2111 if ((
bool)vis != yes)
2170 if ((
bool)sel != yes)
2201 if (ena != (uint)yes)
2232 if (act != (uint)yes)
2241 const QImage* s2image = s2->
imageAdvanced()->collision_mask;
2244 QRect cyourarea(s2area.x(), s2area.y(),
2245 s2area.width(), s2area.height());
2251 QRect ourarea = s1area.intersected(cyourarea);
2253 if (ourarea.isEmpty())
2258 int x2 = ourarea.x() - cyourarea.x();
2259 int y2 = ourarea.y() - cyourarea.y();
2260 int x1 = ourarea.x() - s1area.x();
2261 int y1 = ourarea.y() - s1area.y();
2262 int w = ourarea.width();
2263 int h = ourarea.height();
2269 return w > 0 && h > 0;
2297 if (s1image->format() == QImage::Format_MonoLSB)
2299 for (
int j = 0; j < h; j++)
2301 uchar* ml = s1image->scanLine(y1 + j);
2302 const uchar* yl = s2image->scanLine(y2 + j);
2304 for (
int i = 0; i < w; i++)
2306 if (*(yl + ((x2 + i) >> 3)) & (1 << ((x2 + i) & 7))
2307 && *(ml + ((x1 + i) >> 3)) & (1 << ((x1 + i) & 7)))
2316 for (
int j = 0; j < h; j++)
2318 uchar* ml = s1image->scanLine(y1 + j);
2319 const uchar* yl = s2image->scanLine(y2 + j);
2321 for (
int i = 0; i < w; i++)
2323 if (*(yl + ((x2 + i) >> 3)) & (1 << (7 - ((x2 + i) & 7)))
2324 && *(ml + ((x1 + i) >> 3)) & (1 << (7 - ((x1 + i) & 7))))
2334 if (s2image->format() == QImage::Format_MonoLSB)
2336 for (
int j = 0; j < h; j++)
2338 const uchar* yl = s2image->scanLine(y2 + j);
2340 for (
int i = 0; i < w; i++)
2342 if (*(yl + ((x2 + i) >> 3)) & (1 << ((x2 + i) & 7)))
2351 for (
int j = 0; j < h; j++)
2353 const uchar* yl = s2image->scanLine(y2 + j);
2355 for (
int i = 0; i < w; i++)
2357 if (*(yl + ((x2 + i) >> 3)) & (1 << (7 - ((x2 + i) & 7))))
2396 else if ((r1 || t1 || s1) && (r2 || t2 || s2))
2401 return rc1.intersects(rc2);
2412 return xd * xd + yd * yd <= rd * rd;
2414 else if (p1 && (p2 || s2 || t2))
2420 bool col = !(QRegion(pa1) & QRegion(pa2, Qt::WindingFill)).isEmpty();
2426 return collision_double_dispatch(s2, p2, r2, e2, t2,
2427 s1, p1, r1, e1, t1);
2507 return collision_double_dispatch(
s, p, r, e, t,
this, 0, 0, 0, 0);
2524 return collision_double_dispatch(
s, p, r, e, t, 0,
this, 0, 0, 0);
2541 return collision_double_dispatch(
s, p, r, e, t, 0,
this,
this, 0, 0);
2559 return collision_double_dispatch(
s, p, r, e, t, 0,
this, 0,
this, 0);
2576 return collision_double_dispatch(
s, p, r, e, t, 0, 0, 0, 0,
this);
2664 QSet<QtCanvasItem*> seen;
2667 for (
int i = 0; i < (int)chunklist.count(); i++)
2669 int x = chunklist[i].x();
2670 int y = chunklist[i].y();
2676 for (
int i = 0; i < l.size(); ++i)
2682 if (!seen.contains(g))
2703 void QtCanvasItem::addToChunks()
2707 QPolygon pa = chunks();
2709 for (
int i = 0; i < (int)pa.count(); i++)
2722 void QtCanvasItem::removeFromChunks()
2726 QPolygon pa = chunks();
2728 for (
int i = 0; i < (int)pa.count(); i++)
2740 void QtCanvasItem::changeChunks()
2749 QPolygon pa = chunks();
2751 for (
int i = 0; i < (int)pa.count(); i++)
2777 r.translate(dx, dy);
2822 QImage image(datafilename);
2840 init(pm, offset.x(), offset.y());
2843 void QtCanvasPixmap::init(
const QImage& image)
2845 this->QPixmap::operator = (QPixmap::fromImage(image));
2846 hotx = image.offset().x();
2847 hoty = image.offset().y();
2848 #ifndef QT_NO_IMAGE_DITHER_TO_1
2850 if (image.hasAlphaChannel())
2852 QImage i = image.createAlphaMask();
2853 collision_mask =
new QImage(i);
2860 void QtCanvasPixmap::init(
const QPixmap& pixmap,
int hx,
int hy)
2862 (QPixmap&)*
this = pixmap;
2866 if (pixmap.hasAlphaChannel())
2868 QImage i = mask().toImage();
2869 collision_mask =
new QImage(i);
2882 delete collision_mask;
2939 : framecount(0), img(0)
2965 : framecount(0), img(0)
2967 readPixmaps(datafilenamepattern, fc);
2979 : framecount(
list.count()),
2982 if (
list.count() != hotspots.count())
2984 qWarning(
"QtCanvasPixmapArray: lists have different lengths");
2990 for (
int i = 0; i < framecount; i++)
3006 void QtCanvasPixmapArray::reset()
3008 for (
int i = 0; i < framecount; i++)
3072 int fc,
bool maskonly)
3100 for (
int i = 0; i < framecount; i++)
3103 r.sprintf(
"%04d", i);
3107 if (!img[i]->collision_mask)
3109 img[i]->collision_mask =
new QImage();
3112 img[i]->collision_mask->load(
3113 arg ? datafilenamepattern.arg(r) : datafilenamepattern);
3115 && !img[i]->collision_mask->isNull()
3116 && img[i]->collision_mask->depth() == 1;
3121 arg ? datafilenamepattern.arg(r) : datafilenamepattern);
3122 ok =
ok && !img[i]->isNull();
3176 if (i >= framecount)
3180 memset(newimg + framecount, 0,
sizeof(
QtCanvasPixmap*) * (i + 1 - framecount));
3205 return int(
x()) -
image()->hotx;
3219 return nx -
image()->hotx;
3231 return int(
y()) -
image()->hoty;
3245 return ny -
image()->hoty;
3339 QPolygon QtCanvasItem::chunks()
const
3348 br &= QRect(0, 0,
canvas()->width(),
canvas()->height());
3352 r.resize((br.width() / chunksize + 2) * (br.height() / chunksize + 2));
3354 for (
int j = br.top() / chunksize; j <= br.bottom() / chunksize; j++)
3356 for (
int i = br.left() / chunksize; i <= br.right() / chunksize; i++)
3358 r[n++] = QPoint(i, j);
3373 void QtCanvasSprite::addToChunks()
3395 void QtCanvasSprite::removeFromChunks()
3420 return image()->width();
3430 return image()->height();
3561 p.setRenderHint(QPainter::Antialiasing);
3562 p.setRenderHint(QPainter::SmoothPixmapTransform);
3565 m_view->
drawContents(&p, e->rect().x(), e->rect().y(), e->rect().width(), e->rect().height());
3574 : QScrollArea(parent)
3578 d->highQuality =
false;
3590 : QScrollArea(parent)
3699 disconnect(viewing);
3707 connect(viewing, SIGNAL(resized()),
this, SLOT(updateContentsSize()));
3713 updateContentsSize();
3755 bool ok = wm.isInvertible();
3760 d->
ixform = wm.inverted();
3761 updateContentsSize();
3768 void QtCanvasView::updateContentsSize()
3775 widget()->resize(br.size());
3779 widget()->resize(size());
3795 QPainterPath clipPath;
3796 clipPath.addRect(viewing->
rect());
3797 p->setClipPath(d->
xform.map(clipPath), Qt::IntersectClip);
3798 viewing->
drawViewArea(
this, p, QRect(cx, cy, cw, ch),
false);
3808 return QScrollArea::sizeHint();
3812 return (
canvas()->size() + 2 * QSize(frameWidth(), frameWidth()))
3813 .boundedTo(3 * QApplication::desktop()->size() / 4);
3873 static const QPen& defaultPolygonPen()
3875 static QPen* dp = 0;
3885 static const QBrush& defaultPolygonBrush()
3887 static QBrush* db = 0;
3902 br(defaultPolygonBrush()),
3903 pn(defaultPolygonPen())
3980 r.translate(dx, dy);
3987 #ifdef QCANVAS_POLYGONS_DEBUG
3988 static QWidget* dbg_wid = 0;
3989 static QPainter* dbg_ptr = 0;
3998 QRect pixelbounds = pa.boundingRect();
4000 QRect canvasbounds = pixelbounds.intersected(
canvas->
rect());
4001 bounds.setLeft(canvasbounds.left() / cs);
4002 bounds.setRight(canvasbounds.right() / cs);
4003 bounds.setTop(canvasbounds.top() / cs);
4004 bounds.setBottom(canvasbounds.bottom() / cs);
4008 #ifdef QCANVAS_POLYGONS_DEBUG
4021 #ifdef QCANVAS_POLYGONS_DEBUG
4026 QRect r(x * cs +
bounds.x()*cs, y * cs +
bounds.y()*cs, cs - 1, cs - 1);
4027 dbg_ptr->setPen(Qt::blue);
4028 dbg_ptr->drawRect(r);
4034 inline void addBits(
int x1,
int x2, uchar newbits,
int xo,
int yo)
4036 for (
int i = x1; i <= x2; i++)
4037 if (newbits & (1 << i))
4043 #ifdef QCANVAS_POLYGONS_DEBUG
4048 dbg_wid =
new QWidget;
4049 dbg_wid->resize(800, 600);
4051 dbg_ptr =
new QPainter(dbg_wid);
4052 dbg_ptr->setBrush(Qt::NoBrush);
4055 dbg_ptr->fillRect(dbg_wid->rect(), Qt::white);
4063 for (
int j = 0; j < n; j++)
4065 int y = pt[j].y() / cs -
bounds.y();
4067 if (y >=
bitmap.height() || y < 0)
4072 uchar* l =
bitmap.scanLine(y);
4074 int x1 = x / cs -
bounds.x();
4082 int x2 = (x + w[j]) / cs -
bounds.x();
4089 x2 = qMin(
bounds.width(), x2);
4094 #ifdef QCANVAS_POLYGONS_DEBUG
4098 dbg_ptr->setPen(Qt::yellow);
4105 uchar newbits = (~l[x1q]) & (((2 << (x2r - x1r)) - 1) << x1r);
4109 #ifdef QCANVAS_POLYGONS_DEBUG
4113 dbg_ptr->setPen(Qt::darkGreen);
4117 addBits(x1r, x2r, newbits, x1q * 8, y);
4123 #ifdef QCANVAS_POLYGONS_DEBUG
4127 dbg_ptr->setPen(Qt::blue);
4131 uchar newbits1 = (~l[x1q]) & (0xff << x1r);
4135 #ifdef QCANVAS_POLYGONS_DEBUG
4143 addBits(x1r, 7, newbits1, x1q * 8, y);
4147 for (
int i = x1q + 1; i < x2q; i++)
4151 addBits(0, 7, ~l[i], i * 8, y);
4156 uchar newbits2 = (~l[x2q]) & (0xff >> (7 - x2r));
4160 #ifdef QCANVAS_POLYGONS_DEBUG
4168 addBits(0, x2r, newbits2, x2q * 8, y);
4173 #ifdef QCANVAS_POLYGONS_DEBUG
4177 dbg_ptr->drawLine(pt[j], pt[j] + QPoint(w[j], 0));
4194 QPolygon QtCanvasPolygonalItem::chunks()
const
4206 scanPolygon(pa, wind, processor);
4208 return processor.result;
4216 return QtCanvasItem::chunks();
4345 p.drawPolygon(
poly);
4358 poly.translate((
int)
x(), (
int)
y());
4370 int idx = int(
x() + dx) - int(
x());
4371 int idy = int(
y() + dy) - int(
y());
4376 poly.translate(idx, idy);
4446 if ((
int)ctrl.count() % 3 != (close ? 0 : 1))
4448 qWarning(
"QtCanvasSpline::setControlPoints(): Number of points doesn't fit.");
4449 int numCurves = (ctrl.count() - (close ? 0 : 1)) / 3;
4450 ctrl.resize(numCurves * 3 + (close ? 0 : 1));
4477 void QtCanvasSpline::recalcPoly()
4479 if (bez.count() == 0)
4485 path.moveTo(bez[0]);
4487 for (
int i = 1; i < (int)bez.count() - 1; i += 3)
4489 path.cubicTo(bez[i], bez[i + 1], cl ? bez[(i + 2) % bez.size()] : bez[i + 2]);
4492 QPolygon p = path.toFillPolygon().toPolygon();
4514 pa.translate(
int(-
x()),
int(-
y()));
4551 x1 = y1 = x2 = y2 = 0;
4592 if (x1 != xa || x2 != xb || y1 != ya || y2 != yb)
4608 p.drawLine((
int)(
x() + x1), (
int)(
y() + y1), (
int)(
x() + x2), (
int)(
y() + y2));
4622 int pw =
pen().width();
4623 int dx = qAbs(x1 - x2);
4624 int dy = qAbs(y1 - y2);
4625 pw = pw * 4 / 3 + 2;
4626 int px = x1 < x2 ? -pw : pw ;
4627 int py = y1 < y2 ? -pw : pw ;
4629 if (dx && dy && (dx > dy ? (dx * 2 / dy <= 2) : (dy * 2 / dx <= 2)))
4634 p[0] = QPoint(x1 + xi, y1 + yi + py);
4635 p[1] = QPoint(x2 + xi - px, y2 + yi);
4636 p[2] = QPoint(x2 + xi, y2 + yi - py);
4637 p[3] = QPoint(x1 + xi + px, y1 + yi);
4641 p[0] = QPoint(x1 + xi + px, y1 + yi);
4642 p[1] = QPoint(x2 + xi, y2 + yi - py);
4643 p[2] = QPoint(x2 + xi - px, y2 + yi);
4644 p[3] = QPoint(x1 + xi, y1 + yi + py);
4650 p[0] = QPoint(x1 + xi + px, y1 + yi + py);
4651 p[1] = QPoint(x2 + xi - px, y2 + yi + py);
4652 p[2] = QPoint(x2 + xi - px, y2 + yi - py);
4653 p[3] = QPoint(x1 + xi + px, y1 + yi - py);
4658 p[0] = QPoint(x1 + xi + px, y1 + yi + py);
4659 p[1] = QPoint(x2 + xi + px, y2 + yi - py);
4660 p[2] = QPoint(x2 + xi - px, y2 + yi - py);
4661 p[3] = QPoint(x1 + xi - px, y1 + yi + py);
4713 w(r.width()), h(r.height())
4790 int pw = (
pen().width() + 1) / 2;
4802 pa[0] = QPoint((
int)
x() - pw, (
int)
y() - pw);
4803 pa[1] = pa[0] + QPoint(w + pw * 2, 0);
4804 pa[2] = pa[1] + QPoint(0, h + pw * 2);
4805 pa[3] = pa[0] + QPoint(0, h + pw * 2);
4814 p.drawRect((
int)
x(), (
int)
y(), w, h);
4866 w(width), h(height),
4885 w(width), h(height),
4886 a1(startangle), a2(
angle)
4958 if (a1 != start || a2 != length)
4973 path.arcTo(QRectF(
x() - w / 2.0 + 0.5 - 1,
y() - h / 2.0 + 0.5 - 1, w + 3, h + 3), a1 / 16., a2 / 16.);
4974 return path.toFillPolygon().toPolygon();
4987 if (!a1 && a2 == 360 * 16)
4989 p.drawEllipse(
int(
x() - w / 2.0 + 0.5),
int(
y() - h / 2.0 + 0.5), w, h);
4993 p.drawPie(
int(
x() - w / 2.0 + 0.5),
int(
y() - h / 2.0 + 0.5), w, h, a1, a2);
5021 txt(
"<text>"), flags(0)
5066 void QtCanvasText::setRect()
5068 brect = QFontMetrics(fnt).boundingRect(
int(
x()),
int(
y()), 0, 0, flags, txt);
5178 int idx = int(
x() + dx) - int(
x());
5179 int idy = int(
y() + dy) - int(
y());
5191 brect.translate(idx, idy);
5201 painter.setFont(fnt);
5202 painter.setPen(col);
5203 painter.drawText(painter.fontMetrics().boundingRect(
int(
x()),
int(
y()), 0, 0, flags, txt), flags, txt);
5209 void QtCanvasText::changeChunks()
5215 for (
int j = brect.top() / chunksize; j <= brect.bottom() / chunksize; j++)
5217 for (
int i = brect.left() / chunksize; i <= brect.right() / chunksize; i++)
5228 void QtCanvasText::addToChunks()
5234 for (
int j = brect.top() / chunksize; j <= brect.bottom() / chunksize; j++)
5236 for (
int i = brect.left() / chunksize; i <= brect.right() / chunksize; i++)
5247 void QtCanvasText::removeFromChunks()
5253 for (
int j = brect.top() / chunksize; j <= brect.bottom() / chunksize; j++)
5255 for (
int i = brect.left() / chunksize; i <= brect.right() / chunksize; i++)
5415 if (isvisible && images)
5422 if (frm >= (
int)images->
count())
5438 void QtCanvasSprite::changeChunks()
5537 anim_state = !anim_state;
5542 anim_state = !anim_state;
5619 void scan(
const QPolygon& pa,
bool winding,
int index = 0,
int npoints = -1);
5620 void scan(
const QPolygon& pa,
bool winding,
int index,
int npoints,
bool stitchable);
5622 void scan(
const QPolygon& pa,
bool winding,
int index,
int npoints,
Edge edges);
5623 virtual void processSpans(
int n, QPoint* point,
int* width) = 0;
5754 #define BRESINITPGON(dy, x1, x2, xStart, d, m, m1, incr1, incr2) { \
5763 dx = (x2) - xStart; \
5767 incr1 = -2 * dx + 2 * (dy) * m1; \
5768 incr2 = -2 * dx + 2 * (dy) * m; \
5769 d = 2 * m * (dy) - 2 * dx - 2 * (dy); \
5773 incr1 = 2 * dx - 2 * (dy) * m1; \
5774 incr2 = 2 * dx - 2 * (dy) * m; \
5775 d = -2 * m * (dy) + 2 * dx; \
5780 #define BRESINCRPGON(d, minval, m, m1, incr1, incr2) { \
5819 #define BRESINITPGONSTRUCT(dmaj, min1, min2, bres) \
5820 BRESINITPGON(dmaj, min1, min2, bres.minor, bres.d, \
5821 bres.m, bres.m1, bres.incr1, bres.incr2)
5823 #define BRESINCRPGONSTRUCT(bres) \
5824 BRESINCRPGON(bres.d, bres.minor, bres.m, bres.m1, bres.incr1, bres.incr2)
5859 #define SLLSPERBLOCK 25
5871 #define NUMPTSTOBUFFER 200
5886 #define EVALUATEEDGEWINDING(pAET, pPrevAET, y, fixWAET) { \
5887 if (pAET->ymax == y) { \
5888 pPrevAET->next = pAET->next; \
5889 pAET = pPrevAET->next; \
5892 pAET->back = pPrevAET; \
5895 BRESINCRPGONSTRUCT(pAET->bres); \
5897 pAET = pAET->next; \
5909 #define EVALUATEEDGEEVENODD(pAET, pPrevAET, y) { \
5910 if (pAET->ymax == y) { \
5911 pPrevAET->next = pAET->next; \
5912 pAET = pPrevAET->next; \
5914 pAET->back = pPrevAET; \
5917 BRESINCRPGONSTRUCT(pAET->bres) \
5919 pAET = pAET->next; \
5971 #define MAXINT 0x7fffffff
5972 #define MININT -MAXINT
6004 pSLL = pPrevSLL->
next;
6006 while (pSLL && (pSLL->
scanline < scanline))
6015 if ((!pSLL) || (pSLL->
scanline > scanline))
6027 (*SLLBlock)->
next = tmpSLLBlock;
6028 tmpSLLBlock->
next = 0;
6029 *SLLBlock = tmpSLLBlock;
6033 pSLL = &((*SLLBlock)->SLLs[(*iSLLBlock)++]);
6037 pPrevSLL->
next = pSLL;
6051 start = start->
next;
6095 #if defined(Q_OS_MAC)
6113 tmpSLLBlock = pSLLBlock->
next;
6115 pSLLBlock = tmpSLLBlock;
6148 pSLLBlock->
next = 0;
6150 PrevPt = &pts[count - 1];
6164 if (PrevPt->
y > CurrPt->
y)
6166 bottom = PrevPt, top = CurrPt;
6171 bottom = CurrPt, top = PrevPt;
6178 if (bottom->
y != top->
y)
6180 pETEs->
ymax = bottom->
y - 1;
6185 dy = bottom->
y - top->
y;
6188 if (!miInsertEdgeInET(ET, pETEs, top->y, &pSLLBlock, &iSLLBlock))
6190 miFreeStorage(pSLLBlock->next);
6239 ETEs->
back = pPrevAET;
6240 pPrevAET->
next = ETEs;
6271 register int inside = 1;
6272 register int isInside = 0;
6289 if ((!inside && !isInside) ||
6290 (inside && isInside))
6318 register int changed = 0;
6329 pETEchase = pETEchase->
back;
6334 if (pETEchase != pETEinsert)
6336 pETEchaseBackTMP = pETEchase->
back;
6344 pETEinsert->
next = pETEchase;
6345 pETEchase->
back->
next = pETEinsert;
6346 pETEchase->
back = pETEinsert;
6347 pETEinsert->
back = pETEchaseBackTMP;
6360 scan(pa, winding,
index, npoints,
true);
6402 register int nPts = 0;
6415 int edge_l = (edges &
Left) ? 1 : 0;
6416 int edge_r = (edges &
Right) ? 1 : 0;
6418 int edge_b = (edges &
Bottom) ? 1 : 0;
6422 npoints = pa.size();
6436 ptsOut = FirstPoint;
6439 if (!miCreateETandAET(npoints, ptsIn, &ET, &AET, pETEs, &SLLBlock))
6452 for (y = ET.
ymin + 1 - edge_t; y < ET.
ymax + edge_b; y++)
6475 - 1 + edge_l + edge_r;
6484 ptsOut = FirstPoint;
6493 miInsertionSort(&AET);
6501 for (y = ET.
ymin + 1 - edge_t; y < ET.
ymax + edge_b; y++)
6510 micomputeWAET(&AET);
6541 ptsOut = FirstPoint;
6548 while (pWETE != pAET)
6563 if (miInsertionSort(&AET) || fixWAET)
6565 micomputeWAET(&AET);
6578 miFreeStorage(SLLBlock.
next);
6596 processor.
doSpans(n, point, width);
6600 void QtCanvasPolygonalItem::scanPolygon(
const QPolygon& pa,
int winding,
QPolygonalProcessor& process)
const