void CircleCreateOperation::on_drawEvent(const DrawEvent& event) { bool s = property("hasStartPoint").toBool(); bool e = property("hasEndPoint").toBool(); // For drawing we should create a interface to teh drawitems in the viewer so we always // draw something exactly like how the final drawing classes will draw entities if (s == true && e == false) { event.painter()->drawLine(_startPoint.pointF(), _lastSnapEvent.snapPoint().pointF()); double r = (lc::geo::Coordinate(_startPoint) - lc::geo::Coordinate(_lastSnapEvent.snapPoint())).magnitude(); event.painter()->drawEllipse(_startPoint.pointF(), r, r); } if (s == true && e == true) { double r = (lc::geo::Coordinate(_startPoint) - lc::geo::Coordinate(_endPoint)).magnitude(); event.painter()->drawEllipse(_startPoint.pointF(), r, r); } }
void DragPoints::onDraw(DrawEvent const &event) const { double x = _size; double y = _size; double zeroCornerX = 0.; double zeroCornerY = 0.; event.painter().device_to_user(&zeroCornerX, &zeroCornerY); event.painter().device_to_user(&x, &y); double size = (x - zeroCornerX); event.painter().source_rgb(255, 255, 255); for(auto point : _points) { event.painter().rectangle(point.x() - size / 2, point.y() - size / 2, size, size); } event.painter().stroke(); }
void Grid::draw(DrawEvent const & event) const { LcPainter &painter = event.painter(); const lc::geo::Area &updateRect = event.updateRect(); painter.save(); painter.disable_antialias(); double zeroCornerX = 0.; double zeroCornerY = 0.; painter.device_to_user(&zeroCornerX, &zeroCornerY); double gridSPacingX = _minimumGridSpacing; double gridSPacingY = _minimumGridSpacing; painter.device_to_user(&gridSPacingX, &gridSPacingY); // This brings the distance always between 10 and 100, need to have some math behind this double minDistancePoints = gridSPacingX - zeroCornerX; double factor = 1.0; while (minDistancePoints < 10.0 * (1/_convUnit)) { minDistancePoints *= 10.0 * (1/_convUnit); factor = factor * 10.0 * (1/_convUnit); } while (minDistancePoints > 100.0 * (1/_convUnit)) { minDistancePoints = minDistancePoints / 10.0 * (1/_convUnit); factor = factor / 10.0 * (1/_convUnit); } // determine the grid spacing double gridSize; if (minDistancePoints < 10.0 * (1/_convUnit)) { gridSize = (10.0 * (1/_convUnit) / factor); } else if (minDistancePoints < 20.0 * (1/_convUnit)) { gridSize = (20.0 * (1/_convUnit) / factor); } else if (minDistancePoints < 50.0 * (1/_convUnit)) { gridSize = (50.0 * (1/_convUnit) / factor); } else { gridSize = (100.0 * (1/_convUnit) / factor); } // TODO: THis assignedment doesn't make the grid thread save!!! // We have to fix that somehow or get rid of the snapPoints method // Risck might be very low because the mouse can snap to one display anyways assuming we use one mouse per computer :s _lastGridSize = gridSize; // Major lines double left = updateRect.minP().x() - fmod(updateRect.minP().x(), gridSize); double top = updateRect.maxP().y() - fmod(updateRect.maxP().y(), gridSize); painter.line_width(1); for (double x = left; x < updateRect.maxP().x(); x += gridSize) { painter.move_to(x, updateRect.maxP().y()); painter.line_to(x, updateRect.minP().y()); } for (double y = top; y > updateRect.minP().y(); y -= gridSize) { painter.move_to(updateRect.minP().x(), y); painter.line_to(updateRect.maxP().x(), y); } painter.source_rgba(_majorColor.red(), _majorColor.green(), _majorColor.blue(), _majorColor.alpha()); painter.stroke(); // Draw minor lines gridSize *= _numMinorLines; left = updateRect.minP().x() - fmod(updateRect.minP().x(), gridSize); top = updateRect.maxP().y() - fmod(updateRect.maxP().y(), gridSize); for (double x = left; x < updateRect.maxP().x(); x += gridSize) { painter.move_to(x, updateRect.maxP().y()); painter.line_to(x, updateRect.minP().y()); } for (double y = top; y > updateRect.minP().y(); y -= gridSize) { painter.move_to(updateRect.minP().x(), y); painter.line_to(updateRect.maxP().x(), y); } painter.source_rgba(_minorColor.red(), _minorColor.green(), _minorColor.blue(), _minorColor.alpha()); painter.stroke(); painter.restore(); }
void Cursor::on_Draw_Event(const DrawEvent& event) { double zeroCornerX = 0.; double zeroCornerY = 0.; event.painter()->device_to_user(&zeroCornerX, &zeroCornerY); double gridSPacingX = _cursorSize; double gridSPacingY = _cursorSize; event.painter()->device_to_user(&gridSPacingX, &gridSPacingY); double minDistancePoints = (gridSPacingX - zeroCornerX) / 2.0; double x, y; // If we had a snao point, move the mouse to that area if (_lastSnapEvent.status() == true) { x = _lastSnapEvent.snapPoint().x(); y = _lastSnapEvent.snapPoint().y(); } else { x = event.mousePosition().x(); y = event.mousePosition().y(); } event.painter()->save(); event.painter()->disable_antialias(); event.painter()->move_to(-minDistancePoints + x, y); event.painter()->line_to(minDistancePoints + x, y); event.painter()->source_rgba(_xAxisColor.redF(), _xAxisColor.greenF(), _xAxisColor.blueF(), _xAxisColor.alphaF()); event.painter()->stroke(); event.painter()->move_to(x, -minDistancePoints + y); event.painter()->line_to(x, minDistancePoints + y); event.painter()->source_rgba(_yAxisColor.redF(), _yAxisColor.greenF(), _yAxisColor.blueF(), _yAxisColor.alphaF()); event.painter()->stroke(); event.painter()->restore(); }