21#include "kis_grid_drawer.h"
31#include "kis_config.h"
33#include "kis_perspective_grid.h"
34#include "kis_perspective_grid_manager.h"
36TQt::PenStyle GridDrawer::gs2style(TQ_UINT32 s)
45 return TQt::DashDotLine;
47 return TQt::DashDotDotLine;
49 return TQt::SolidLine;
53void GridDrawer::drawPerspectiveGrid(KisImageSP image,
const TQRect& ,
const KisSubPerspectiveGrid* grid)
57 TQPen mainPen = TQPen ( cfg.getGridMainColor(), 1, gs2style( cfg.getGridMainStyle() ) );
58 TQPen subdivisionPen = TQPen ( cfg.getGridSubdivisionColor(), 1, gs2style( cfg.getGridSubdivisionStyle() ) );
59 setPen(subdivisionPen );
66 KisPerspectiveMath::LineEquation d12 = KisPerspectiveMath::computeLineEquation( grid->topLeft(), grid->topRight() ) ;
67 KisPoint v12 = KisPoint(*grid->topLeft() - *grid->topRight());
68 v12.setX( v12.x() / grid->subdivisions()); v12.setY( v12.y() / grid->subdivisions() );
69 KisPerspectiveMath::LineEquation d23 = KisPerspectiveMath::computeLineEquation( grid->topRight(), grid->bottomRight() );
70 KisPoint v23 = KisPoint(*grid->topRight() - *grid->bottomRight());
71 v23.setX( v23.x() / grid->subdivisions()); v23.setY( v23.y() / grid->subdivisions() );
72 KisPerspectiveMath::LineEquation d34 = KisPerspectiveMath::computeLineEquation( grid->bottomRight(), grid->bottomLeft() );
73 KisPerspectiveMath::LineEquation d41 = KisPerspectiveMath::computeLineEquation( grid->bottomLeft(), grid->topLeft() );
75 KisPoint horizVanishingPoint = KisPerspectiveMath::computeIntersection(d12,d34);
76 KisPoint vertVanishingPoint = KisPerspectiveMath::computeIntersection(d23,d41);
78 for(uint i = 1; i < static_cast<uint>(grid->subdivisions()); i ++)
80 KisPoint pol1 = *grid->topRight() + i * v12;
81 KisPerspectiveMath::LineEquation d1 = KisPerspectiveMath::computeLineEquation( &pol1, &vertVanishingPoint );
82 KisPoint pol1b = KisPerspectiveMath::computeIntersection(d1,d34);
83 drawLine( pol1.roundTQPoint(), pol1b.roundTQPoint() );
85 KisPoint pol2 = *grid->bottomRight() + i * v23;
86 KisPerspectiveMath::LineEquation d2 = KisPerspectiveMath::computeLineEquation( &pol2, &horizVanishingPoint );
87 KisPoint pol2b = KisPerspectiveMath::computeIntersection(d2,d41);
88 drawLine( pol2.roundTQPoint(), pol2b.roundTQPoint() );
91 drawLine( grid->topLeft(), grid->topRight() );
92 drawLine( grid->topRight(), grid->bottomRight() );
93 drawLine( grid->bottomRight(), grid->bottomLeft() );
94 drawLine( grid->bottomLeft(), grid->topLeft() );
97void GridDrawer::drawGrid(KisImageSP image,
const TQRect& wr)
101 TQ_UINT32 offsetx = cfg.getGridOffsetX();
102 TQ_UINT32 offsety = cfg.getGridOffsetY();
103 TQ_UINT32 hspacing = cfg.getGridHSpacing();
104 TQ_UINT32 vspacing = cfg.getGridVSpacing();
105 TQ_UINT32 subdivision = cfg.getGridSubdivisions() - 1;
109 TQ_INT32 imageWidth = image->width();
110 TQ_INT32 imageHeight = image->height();
113 TQPen mainPen = TQPen ( cfg.getGridMainColor(), 1, gs2style( cfg.getGridMainStyle() ) );
114 TQPen subdivisionPen = TQPen ( cfg.getGridSubdivisionColor(), 1, gs2style( cfg.getGridSubdivisionStyle() ) );
116 for( TQ_INT32 x = offsetx; x <= wr.right(); x +=hspacing)
118 if( i == subdivision )
123 setPen(subdivisionPen);
130 drawLine(x, 0, x, imageHeight);
135 for( TQ_INT32 y = offsety; y <= wr.bottom(); y +=vspacing)
137 if( i == subdivision )
142 setPen(subdivisionPen);
147 drawLine(0, y, imageWidth, y);
152OpenGLGridDrawer::OpenGLGridDrawer()
155 glPushAttrib(GL_ALL_ATTRIB_BITS);
159OpenGLGridDrawer::~OpenGLGridDrawer()
166void OpenGLGridDrawer::setPen(
const TQPen& pen)
169 TQt::PenStyle penStyle = pen.style();
171 if (penStyle == TQt::SolidLine) {
172 glDisable(GL_LINE_STIPPLE);
174 GLushort lineStipple;
182 lineStipple = 0xffff;
185 lineStipple = 0x3fff;
188 lineStipple = 0x3333;
190 case TQt::DashDotLine:
191 lineStipple = 0x33ff;
193 case TQt::DashDotDotLine:
194 lineStipple = 0x333f;
198 glEnable(GL_LINE_STIPPLE);
199 glLineStipple(1, lineStipple);
202 TQColor penColor = pen.color();
204 glColor3ub(penColor.red(), penColor.green(), penColor.blue());
210void OpenGLGridDrawer::drawLine(TQ_INT32 x1, TQ_INT32 y1, TQ_INT32 x2, TQ_INT32 y2)