From e5d6b2ef604f59637913fa7dba7ad54ffdc63bcc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D1=80=D1=82=D1=91=D0=BC=20=D0=9F=D1=80=D0=BE=D1=81?= =?UTF-8?q?=D0=BA=D1=83=D1=80=D0=BD=D1=91=D0=B2?= Date: Tue, 30 Mar 2021 03:08:36 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9F=D0=BE=D0=BB=D1=83=D1=87=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D0=B5=20=D0=BA=D0=BE=D0=BE=D1=80=D0=B4=D0=B8=D0=BD=D0=B0?= =?UTF-8?q?=D1=82=20=D0=BA=D0=BB=D0=B8=D0=BA=D0=B0=20=D0=BC=D1=8B=D1=88?= =?UTF-8?q?=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.cpp | 13 ++++++++++++- qtsgraph.cpp | 10 ++++++++++ qtsgraph.h | 8 ++++++++ 3 files changed, 30 insertions(+), 1 deletion(-) 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;