00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifdef HAVE_CONFIG_H
00020 #include <config.h>
00021 #endif
00022
00023 #ifdef HAVE_GL
00024
00025 #include <kdebug.h>
00026
00027 #include "kis_canvas.h"
00028 #include "kis_canvas_painter.h"
00029 #include "kis_opengl_canvas_painter.h"
00030
00031 KisOpenGLCanvasPainter::KisOpenGLCanvasPainter()
00032 : m_active(false), m_widget(0)
00033 {
00034 }
00035
00036 KisOpenGLCanvasPainter::KisOpenGLCanvasPainter(QGLWidget *widget)
00037 : m_active(true), m_widget(widget)
00038 {
00039 prepareForDrawing();
00040 }
00041
00042 KisOpenGLCanvasPainter::~KisOpenGLCanvasPainter()
00043 {
00044 if (m_widget) {
00045 if (m_active) {
00046 end();
00047 }
00048 m_widget->doneCurrent();
00049 }
00050 }
00051
00052 bool KisOpenGLCanvasPainter::begin(KisCanvasWidget *canvasWidget, bool )
00053 {
00054 m_widget = dynamic_cast<QGLWidget *>(canvasWidget);
00055
00056 if (m_widget != 0) {
00057 prepareForDrawing();
00058 return true;
00059 } else {
00060 return false;
00061 }
00062 return false;
00063 }
00064
00065 void KisOpenGLCanvasPainter::prepareForDrawing()
00066 {
00067 if (m_widget != 0) {
00068 m_widget->makeCurrent();
00069 m_active = true;
00070 save();
00071 glDrawBuffer(GL_FRONT);
00072 glBlendFunc(GL_ONE_MINUS_DST_COLOR, GL_ZERO);
00073 glEnable(GL_BLEND);
00074
00075 glMatrixMode(GL_TEXTURE);
00076 glLoadIdentity();
00077
00078 m_window = QRect(0, 0, m_widget->width(), m_widget->height());
00079 m_viewport = m_window;
00080 updateViewTransformation();
00081
00082 glMatrixMode(GL_MODELVIEW);
00083 glLoadIdentity();
00084
00085 setPen(m_defaultPen);
00086 }
00087 }
00088
00089 void KisOpenGLCanvasPainter::updateViewTransformation()
00090 {
00091 glMatrixMode(GL_PROJECTION);
00092 glLoadIdentity();
00093
00094
00095
00096 glViewport(0, 0, m_widget->width(), m_widget->height());
00097 glOrtho(0, m_widget->width(), m_widget->height(), 0, -1, 1);
00098
00099 glTranslatef(m_viewport.x(), m_viewport.y(), 0.0);
00100 glScalef(static_cast<float>(m_viewport.width()) / m_window.width(),
00101 static_cast<float>(m_viewport.height()) / m_window.height(),
00102 1.0);
00103 glTranslatef(-m_window.x(), -m_window.y(), 0.0);
00104 }
00105
00106 bool KisOpenGLCanvasPainter::end()
00107 {
00108 if (m_active) {
00109 restore();
00110 m_active = false;
00111 return true;
00112 } else {
00113 return false;
00114 }
00115 }
00116
00117 void KisOpenGLCanvasPainter::save()
00118 {
00119 glPushAttrib(GL_ALL_ATTRIB_BITS);
00120 glMatrixMode(GL_PROJECTION);
00121 glPushMatrix();
00122 glMatrixMode(GL_MODELVIEW);
00123 glPushMatrix();
00124 glMatrixMode(GL_TEXTURE);
00125 glPushMatrix();
00126 }
00127
00128 void KisOpenGLCanvasPainter::restore()
00129 {
00130 glPopAttrib();
00131 glMatrixMode(GL_PROJECTION);
00132 glPopMatrix();
00133 glMatrixMode(GL_MODELVIEW);
00134 glPopMatrix();
00135 glMatrixMode(GL_TEXTURE);
00136 glPopMatrix();
00137 }
00138
00139 void KisOpenGLCanvasPainter::setPenStyle(Qt::PenStyle penStyle)
00140 {
00141 if (penStyle == Qt::SolidLine) {
00142 glDisable(GL_LINE_STIPPLE);
00143 } else {
00144 GLushort lineStipple;
00145
00146 switch (penStyle) {
00147 case Qt::NoPen:
00148 lineStipple = 0;
00149 break;
00150 default:
00151 case Qt::DashLine:
00152 lineStipple = 0x3fff;
00153 break;
00154 case Qt::DotLine:
00155 lineStipple = 0x3333;
00156 break;
00157 case Qt::DashDotLine:
00158 lineStipple = 0x33ff;
00159 break;
00160 case Qt::DashDotDotLine:
00161 lineStipple = 0x333f;
00162 break;
00163 }
00164
00165 glEnable(GL_LINE_STIPPLE);
00166 glLineStipple(1, lineStipple);
00167 }
00168 }
00169
00170 QFontMetrics KisOpenGLCanvasPainter::fontMetrics() const
00171 {
00172 return QFontMetrics(QFont());
00173 }
00174
00175 QFontInfo KisOpenGLCanvasPainter::fontInfo() const
00176 {
00177 return QFontInfo(QFont());
00178 }
00179
00180 const QFont& KisOpenGLCanvasPainter::font() const
00181 {
00182 return m_defaultFont;
00183 }
00184
00185 void KisOpenGLCanvasPainter::setFont(const QFont& )
00186 {
00187 }
00188
00189 const QPen& KisOpenGLCanvasPainter::pen() const
00190 {
00191 return m_defaultPen;
00192 }
00193
00194 void KisOpenGLCanvasPainter::setPen(const QPen& pen)
00195 {
00196 setPenStyle(pen.style());
00197 }
00198
00199 void KisOpenGLCanvasPainter::setPen(Qt::PenStyle penStyle)
00200 {
00201 setPenStyle(penStyle);
00202 }
00203
00204 void KisOpenGLCanvasPainter::setPen(const QColor& )
00205 {
00206 }
00207
00208 const QBrush& KisOpenGLCanvasPainter::brush() const
00209 {
00210 return m_defaultBrush;
00211 }
00212
00213 void KisOpenGLCanvasPainter::setBrush(const QBrush& )
00214 {
00215 }
00216
00217 void KisOpenGLCanvasPainter::setBrush(Qt::BrushStyle )
00218 {
00219 }
00220
00221 void KisOpenGLCanvasPainter::setBrush(const QColor& )
00222 {
00223 }
00224
00225 QPoint KisOpenGLCanvasPainter::pos() const
00226 {
00227 return QPoint();
00228 }
00229
00230 const QColor& KisOpenGLCanvasPainter::backgroundColor() const
00231 {
00232 return m_defaultColor;
00233 }
00234
00235 void KisOpenGLCanvasPainter::setBackgroundColor(const QColor& )
00236 {
00237 }
00238
00239 Qt::Qt::BGMode KisOpenGLCanvasPainter::backgroundMode() const
00240 {
00241 return Qt::TransparentMode;
00242 }
00243
00244 void KisOpenGLCanvasPainter::setBackgroundMode(Qt::Qt::BGMode )
00245 {
00246 }
00247
00248 Qt::Qt::RasterOp KisOpenGLCanvasPainter::rasterOp() const
00249 {
00250 return Qt::CopyROP;
00251 }
00252
00253 void KisOpenGLCanvasPainter::setRasterOp(Qt::RasterOp )
00254 {
00255 }
00256
00257 const QPoint& KisOpenGLCanvasPainter::brushOrigin() const
00258 {
00259 return m_defaultBrushOrigin;
00260 }
00261
00262 void KisOpenGLCanvasPainter::setBrushOrigin(int , int )
00263 {
00264 }
00265
00266 void KisOpenGLCanvasPainter::setBrushOrigin(const QPoint& )
00267 {
00268 }
00269
00270 bool KisOpenGLCanvasPainter::hasViewXForm() const
00271 {
00272 return false;
00273 }
00274
00275 bool KisOpenGLCanvasPainter::hasWorldXForm() const
00276 {
00277 return false;
00278 }
00279
00280 void KisOpenGLCanvasPainter::setViewXForm(bool )
00281 {
00282 }
00283
00284 QRect KisOpenGLCanvasPainter::window() const
00285 {
00286 return m_window;
00287 }
00288
00289 void KisOpenGLCanvasPainter::setWindow(const QRect& r)
00290 {
00291 m_window = r;
00292 updateViewTransformation();
00293 }
00294
00295 void KisOpenGLCanvasPainter::setWindow(int x, int y, int w, int h)
00296 {
00297 setWindow(QRect(x, y, w, h));
00298 }
00299
00300 QRect KisOpenGLCanvasPainter::viewport() const
00301 {
00302 return m_viewport;
00303 }
00304
00305 void KisOpenGLCanvasPainter::setViewport(const QRect& r)
00306 {
00307 m_viewport = r;
00308 updateViewTransformation();
00309 }
00310
00311 void KisOpenGLCanvasPainter::setViewport(int x, int y, int w, int h)
00312 {
00313 setViewport(QRect(x, y, w, h));
00314 }
00315
00316 void KisOpenGLCanvasPainter::setWorldXForm(bool )
00317 {
00318 }
00319
00320 const QWMatrix& KisOpenGLCanvasPainter::worldMatrix() const
00321 {
00322 return m_defaultWorldMatrix;
00323 }
00324
00325 void KisOpenGLCanvasPainter::setWorldMatrix(const QWMatrix& , bool )
00326 {
00327 }
00328
00329 void KisOpenGLCanvasPainter::saveWorldMatrix()
00330 {
00331 }
00332
00333 void KisOpenGLCanvasPainter::restoreWorldMatrix()
00334 {
00335 }
00336
00337 void KisOpenGLCanvasPainter::scale(double , double )
00338 {
00339 }
00340
00341 void KisOpenGLCanvasPainter::shear(double , double )
00342 {
00343 }
00344
00345 void KisOpenGLCanvasPainter::rotate(double )
00346 {
00347 }
00348
00349 void KisOpenGLCanvasPainter::translate(double dx, double dy)
00350 {
00351 glMatrixMode(GL_MODELVIEW);
00352 glTranslated(dx, dy, 0.0);
00353 }
00354
00355 void KisOpenGLCanvasPainter::resetXForm()
00356 {
00357 }
00358
00359 double KisOpenGLCanvasPainter::translationX() const
00360 {
00361 return 0;
00362 }
00363
00364 double KisOpenGLCanvasPainter::translationY() const
00365 {
00366 return 0;
00367 }
00368
00369 QPoint KisOpenGLCanvasPainter::xForm(const QPoint& point) const
00370 {
00371 return point;
00372 }
00373
00374 QRect KisOpenGLCanvasPainter::xForm(const QRect& r) const
00375 {
00376 return r;
00377 }
00378
00379 QPointArray KisOpenGLCanvasPainter::xForm(const QPointArray& pointArray) const
00380 {
00381 return pointArray;
00382 }
00383
00384 QPointArray KisOpenGLCanvasPainter::xForm(const QPointArray& pointArray, int , int ) const
00385 {
00386 return pointArray;
00387 }
00388
00389 QPoint KisOpenGLCanvasPainter::xFormDev(const QPoint& point) const
00390 {
00391 return point;
00392 }
00393
00394 QRect KisOpenGLCanvasPainter::xFormDev(const QRect& r) const
00395 {
00396 return r;
00397 }
00398
00399 QPointArray KisOpenGLCanvasPainter::xFormDev(const QPointArray& pointArray) const
00400 {
00401 return pointArray;
00402 }
00403
00404 QPointArray KisOpenGLCanvasPainter::xFormDev(const QPointArray& pointArray, int , int ) const
00405 {
00406 return pointArray;
00407 }
00408
00409 void KisOpenGLCanvasPainter::setClipping(bool )
00410 {
00411 }
00412
00413 bool KisOpenGLCanvasPainter::hasClipping() const
00414 {
00415 return true;
00416 }
00417
00418 QRegion KisOpenGLCanvasPainter::clipRegion(QPainter::CoordinateMode ) const
00419 {
00420 return QRegion();
00421 }
00422
00423 void KisOpenGLCanvasPainter::setClipRect(const QRect& , QPainter::CoordinateMode )
00424 {
00425 }
00426
00427 void KisOpenGLCanvasPainter::setClipRect(int , int , int , int , QPainter::CoordinateMode )
00428 {
00429 }
00430
00431 void KisOpenGLCanvasPainter::setClipRegion(const QRegion& , QPainter::CoordinateMode )
00432 {
00433 }
00434
00435 void KisOpenGLCanvasPainter::drawPoint(int x, int y)
00436 {
00437 glBegin(GL_POINTS);
00438 glVertex2i(x, y);
00439 glEnd();
00440 }
00441
00442 void KisOpenGLCanvasPainter::drawPoint(const QPoint& point)
00443 {
00444 drawPoint(point.x(), point.y());
00445 }
00446
00447 void KisOpenGLCanvasPainter::drawPoints(const QPointArray& pointArray, int index, int npoints)
00448 {
00449 int firstPointIndex = index;
00450
00451 if (firstPointIndex < 0) {
00452 firstPointIndex = 0;
00453 }
00454 if (firstPointIndex > (int)pointArray.count() - 1) {
00455 return;
00456 }
00457
00458 int lastPointIndex;
00459
00460 if (npoints < 0) {
00461 lastPointIndex = pointArray.count() - 1;
00462 } else {
00463 lastPointIndex = firstPointIndex + npoints;
00464 if (lastPointIndex > (int)pointArray.count() - 1) {
00465 lastPointIndex = pointArray.count() - 1;
00466 }
00467 }
00468
00469 glBegin(GL_POINTS);
00470
00471 for (int pointIndex = firstPointIndex; pointIndex <= lastPointIndex; pointIndex++) {
00472 QPoint point = pointArray.point(pointIndex);
00473 glVertex2i(point.x(), point.y());
00474 }
00475
00476 glEnd();
00477 }
00478
00479 void KisOpenGLCanvasPainter::moveTo(int , int )
00480 {
00481 }
00482
00483 void KisOpenGLCanvasPainter::moveTo(const QPoint& )
00484 {
00485 }
00486
00487 void KisOpenGLCanvasPainter::lineTo(int , int )
00488 {
00489 }
00490
00491 void KisOpenGLCanvasPainter::lineTo(const QPoint& )
00492 {
00493 }
00494
00495 void KisOpenGLCanvasPainter::drawLine(int x1, int y1, int x2, int y2)
00496 {
00497 glBegin(GL_LINES);
00498 glVertex2i(x1, y1);
00499 glVertex2i(x2, y2);
00500 glEnd();
00501 }
00502
00503 void KisOpenGLCanvasPainter::drawLine(const QPoint& start, const QPoint& end)
00504 {
00505 drawLine(start.x(), start.y(), end.x(), end.y());
00506 }
00507
00508 void KisOpenGLCanvasPainter::drawRect(int x, int y, int w, int h)
00509 {
00510 glBegin(GL_LINES);
00511
00512 glVertex2i(x, y);
00513 glVertex2i(x + w - 1, y);
00514
00515 glVertex2i(x + w - 1, y);
00516 glVertex2i(x + w - 1, y + h - 1);
00517
00518 glVertex2i(x + w - 1, y + h - 1);
00519 glVertex2i(x, y + h - 1);
00520
00521 glVertex2i(x, y + h - 1);
00522 glVertex2i(x, y);
00523
00524 glEnd();
00525 }
00526
00527 void KisOpenGLCanvasPainter::drawRect(const QRect& r)
00528 {
00529 drawRect(r.x(), r.y(), r.width(), r.height());
00530 }
00531
00532 void KisOpenGLCanvasPainter::drawWinFocusRect(int , int , int , int )
00533 {
00534 }
00535
00536 void KisOpenGLCanvasPainter::drawWinFocusRect(int , int , int , int , const QColor& )
00537 {
00538 }
00539
00540 void KisOpenGLCanvasPainter::drawWinFocusRect(const QRect& )
00541 {
00542 }
00543
00544 void KisOpenGLCanvasPainter::drawWinFocusRect(const QRect& , const QColor& )
00545 {
00546 }
00547
00548 void KisOpenGLCanvasPainter::drawRoundRect(int , int , int , int , int , int )
00549 {
00550 }
00551
00552 void KisOpenGLCanvasPainter::drawRoundRect(const QRect& , int , int )
00553 {
00554 }
00555
00556 void KisOpenGLCanvasPainter::drawEllipse(int x, int y, int w, int h)
00557 {
00558 QRect r(x, y, w, h);
00559 r = r.normalize();
00560
00561 QPointArray points;
00562
00563 points.makeEllipse(r.x(), r.y(), r.width(), r.height());
00564 drawPoints(points);
00565 }
00566
00567 void KisOpenGLCanvasPainter::drawEllipse(const QRect& r)
00568 {
00569 drawEllipse(r.x(), r.y(), r.width(), r.height());
00570 }
00571
00572 void KisOpenGLCanvasPainter::drawArc(int , int , int , int , int , int )
00573 {
00574 }
00575
00576 void KisOpenGLCanvasPainter::drawArc(const QRect& , int , int )
00577 {
00578 }
00579
00580 void KisOpenGLCanvasPainter::drawPie(int , int , int , int , int , int )
00581 {
00582 }
00583
00584 void KisOpenGLCanvasPainter::drawPie(const QRect& , int , int )
00585 {
00586 }
00587
00588 void KisOpenGLCanvasPainter::drawChord(int , int , int , int , int , int )
00589 {
00590 }
00591
00592 void KisOpenGLCanvasPainter::drawChord(const QRect& , int , int )
00593 {
00594 }
00595
00596 void KisOpenGLCanvasPainter::drawLineSegments(const QPointArray& , int , int )
00597 {
00598 }
00599
00600 void KisOpenGLCanvasPainter::drawPolyline(const QPointArray& pointArray, int index, int npoints)
00601 {
00602 int firstPointIndex = index;
00603
00604 if (firstPointIndex < 0) {
00605 firstPointIndex = 0;
00606 }
00607 if (firstPointIndex > (int)pointArray.count() - 2) {
00608 return;
00609 }
00610
00611 int lastPointIndex;
00612
00613 if (npoints < 0) {
00614 lastPointIndex = pointArray.count() - 1;
00615 } else {
00616 lastPointIndex = firstPointIndex + npoints - 1;
00617 if (lastPointIndex > (int)pointArray.count() - 1) {
00618 lastPointIndex = pointArray.count() - 1;
00619 }
00620 }
00621
00622 if (firstPointIndex >= lastPointIndex) {
00623 return;
00624 }
00625
00626 glBegin(GL_LINES);
00627
00628 for (int pointIndex = firstPointIndex; pointIndex <= lastPointIndex; pointIndex++) {
00629 QPoint point = pointArray.point(pointIndex);
00630 glVertex2i(point.x(), point.y());
00631 }
00632
00633 glEnd();
00634 }
00635
00636 void KisOpenGLCanvasPainter::drawPolygon(const QPointArray& , bool , int , int )
00637 {
00638 }
00639
00640 void KisOpenGLCanvasPainter::drawConvexPolygon(const QPointArray& , int , int )
00641 {
00642 }
00643
00644 void KisOpenGLCanvasPainter::drawCubicBezier(const QPointArray& , int )
00645 {
00646 }
00647
00648 void KisOpenGLCanvasPainter::drawPixmap(int , int , const QPixmap& , int , int , int , int )
00649 {
00650 }
00651
00652 void KisOpenGLCanvasPainter::drawPixmap(const QPoint& , const QPixmap& , const QRect& )
00653 {
00654 }
00655
00656 void KisOpenGLCanvasPainter::drawPixmap(const QPoint& , const QPixmap& )
00657 {
00658 }
00659
00660 void KisOpenGLCanvasPainter::drawPixmap(const QRect& , const QPixmap& )
00661 {
00662 }
00663
00664 void KisOpenGLCanvasPainter::drawImage(int , int , const QImage& , int , int , int , int , int )
00665 {
00666 }
00667
00668 void KisOpenGLCanvasPainter::drawImage(const QPoint& , const QImage& , const QRect& , int )
00669 {
00670 }
00671
00672 void KisOpenGLCanvasPainter::drawImage(const QPoint& , const QImage& , int )
00673 {
00674 }
00675
00676 void KisOpenGLCanvasPainter::drawImage(const QRect& , const QImage& )
00677 {
00678 }
00679
00680 void KisOpenGLCanvasPainter::drawTiledPixmap(int , int , int , int , const QPixmap& , int , int )
00681 {
00682 }
00683
00684 void KisOpenGLCanvasPainter::drawTiledPixmap(const QRect& , const QPixmap& , const QPoint& )
00685 {
00686 }
00687
00688 void KisOpenGLCanvasPainter::drawTiledPixmap(const QRect& , const QPixmap& )
00689 {
00690 }
00691
00692 void KisOpenGLCanvasPainter::fillRect(int x, int y, int w, int h, const QBrush& )
00693 {
00694
00695 glRecti(x, y, x + w, y + h);
00696 }
00697
00698 void KisOpenGLCanvasPainter::fillRect(const QRect& r, const QBrush& brush)
00699 {
00700 fillRect(r.x(), r.y(), r.width(), r.height(), brush);
00701 }
00702
00703 void KisOpenGLCanvasPainter::eraseRect(int , int , int , int )
00704 {
00705 }
00706
00707 void KisOpenGLCanvasPainter::eraseRect(const QRect& )
00708 {
00709 }
00710
00711 void KisOpenGLCanvasPainter::drawText(int , int , const QString& , int , QPainter::TextDirection )
00712 {
00713 }
00714
00715 void KisOpenGLCanvasPainter::drawText(const QPoint& , const QString& , int , QPainter::TextDirection )
00716 {
00717 }
00718
00719 void KisOpenGLCanvasPainter::drawText(int , int , const QString& , int , int , QPainter::TextDirection )
00720 {
00721 }
00722
00723 void KisOpenGLCanvasPainter::drawText(const QPoint& , const QString& , int , int , QPainter::TextDirection )
00724 {
00725 }
00726
00727 void KisOpenGLCanvasPainter::drawText(int , int , int , int , int , const QString& , int , QRect *, QTextParag **)
00728 {
00729 }
00730
00731 void KisOpenGLCanvasPainter::drawText(const QRect& , int , const QString& , int , QRect *, QTextParag **)
00732 {
00733 }
00734
00735 void KisOpenGLCanvasPainter::drawTextItem(int , int , const QTextItem& , int )
00736 {
00737 }
00738
00739 void KisOpenGLCanvasPainter::drawTextItem(const QPoint& , const QTextItem& , int )
00740 {
00741 }
00742
00743 QRect KisOpenGLCanvasPainter::boundingRect(int , int , int , int , int , const QString& , int , QTextParag **)
00744 {
00745 return QRect();
00746 }
00747
00748 QRect KisOpenGLCanvasPainter::boundingRect(const QRect& , int , const QString& , int , QTextParag **)
00749 {
00750 return QRect();
00751 }
00752
00753 int KisOpenGLCanvasPainter::tabStops() const
00754 {
00755 return 0;
00756 }
00757
00758 void KisOpenGLCanvasPainter::setTabStops(int )
00759 {
00760 }
00761
00762 int *KisOpenGLCanvasPainter::tabArray() const
00763 {
00764 return 0;
00765 }
00766
00767 void KisOpenGLCanvasPainter::setTabArray(int *)
00768 {
00769 }
00770
00771 #endif // HAVE_GL
00772