diff --git a/main.cpp b/main.cpp index f011bda..b36a9f3 100644 --- a/main.cpp +++ b/main.cpp @@ -44,6 +44,17 @@ void QTSGraph::PaintBox() SetPenStyle(5); SetFillStyle(1, clMagenta); Ellipse(250, 280, 350, 320); - + TPixel p; + while(ReadMouseButton() != 2) + { + p = ReadMousePosition(); + SetColor(clBlack); + SetPenStyle(1, 1); + SetFillStyle(1, clWhite); + Rectangle(10, 10, 100, 100); + SetTextStyle(16, 0, 0); + OutTextXY(30, 30, std::to_string(p.x)); + OutTextXY(30, 60, std::to_string(p.y)); + } // Конец рисования } diff --git a/qtsgraph.cpp b/qtsgraph.cpp index 90d1d88..b92b705 100644 --- a/qtsgraph.cpp +++ b/qtsgraph.cpp @@ -184,6 +184,15 @@ int QTSGraph::ReadMouseButton() return t; } +TPixel QTSGraph::ReadMousePosition() +{ + TPixel t; + t.x = LastMouseClickPosition.x(); + t.y = LastMouseClickPosition.y(); + t.color = GetPixel(t.x, t.y); + return t; +} + void QTSGraph::Rectangle(int x1, int y1, int x2, int y2) { QPainter painter(&Canvas); @@ -316,6 +325,7 @@ void QTSGraph::paintEvent(QPaintEvent *event) void QTSGraph::mousePressEvent(QMouseEvent *event) { ResetTimer->stop(); + LastMouseClickPosition = event->pos(); EventMouseClicked = true; if (event->buttons() & Qt::LeftButton) { diff --git a/qtsgraph.h b/qtsgraph.h index 340e499..ce2030d 100644 --- a/qtsgraph.h +++ b/qtsgraph.h @@ -61,6 +61,12 @@ along with Vesi. If not, see . #define clMagenta 0xFF00FF #define clCyan 0x00FFFF +struct TPixel +{ + int x, y; + unsigned int color; +}; + class QTSGraph : public QMainWindow { Q_OBJECT @@ -85,6 +91,7 @@ public: void PutPixel(int x, int y, QRgb c = 0x00000000, int PenWidth = 1); int ReadKey(); int ReadMouseButton(); + TPixel ReadMousePosition(); void Rectangle(int x1, int y1, int x2, int y2); void SetColor(const QColor &c = Qt::black); void SetColor(const QRgb c = 0x00000000); @@ -138,6 +145,7 @@ private: int IDMouseButton = -1; int ResetInterval; int TextDirection = 0; + QPoint LastMouseClickPosition; QBrush Brush; QPixmap Canvas;