From 86c4048c31991bd71ff42843838b302c7f9e568c Mon Sep 17 00:00:00 2001 From: Eugene Gagulin Date: Wed, 20 Nov 2019 17:31:50 +0300 Subject: [PATCH 01/14] Add drawLine() method --- src/ui/x11/x11_ui.cpp | 15 +++++++++++++++ src/ui/x11/x11_ui.h | 3 +++ 2 files changed, 18 insertions(+) diff --git a/src/ui/x11/x11_ui.cpp b/src/ui/x11/x11_ui.cpp index 6bac2563b..9c88a8f5d 100644 --- a/src/ui/x11/x11_ui.cpp +++ b/src/ui/x11/x11_ui.cpp @@ -55,6 +55,16 @@ void UiWindowX11::_display() XDrawLine( _uiDisplay, _window, defaultGC, static_cast(point.x - 1), static_cast(point.y - 1), static_cast(point.x + 1), static_cast(point.y + 1) ); } + + for ( size_t i = 0u; i < _lines.size(); ++i ) { + const Point2d & start = std::get<0>(_lines[i]); + const Point2d & end = std::get<1>(_lines[i]); + const uint32_t & foreground = std::get<2>(_lines[i]); + + XSetForeground( _uiDisplay, defaultGC, foreground ); + XDrawLine( _uiDisplay, _window, defaultGC, static_cast(start.x), static_cast(start.y), + static_cast(end.x), static_cast(end.y) ); + } } else if ( (e.type == ClientMessage) && (static_cast(e.xclient.data.l[0]) == _deleteWindowEvent) ) break; @@ -112,4 +122,9 @@ void UiWindowX11::drawPoint( const Point2d & point, const PaintColor & color ) _point.push_back( std::make_pair( point, (color.red << 16) + (color.green << 8) + color.blue ) ); } +void UiWindowX11::drawLine( const Point2d & start, const Point2d & end, const PaintColor & color ) +{ + _lines.push_back( std::make_tuple( start, end, (color.red << 16) + (color.green << 8) + color.blue ) ); +} + #endif diff --git a/src/ui/x11/x11_ui.h b/src/ui/x11/x11_ui.h index d088d5451..07611e377 100644 --- a/src/ui/x11/x11_ui.h +++ b/src/ui/x11/x11_ui.h @@ -3,6 +3,7 @@ #ifndef _WIN32 // Not for Windows #include +#include #include #include #include "../ui.h" @@ -14,6 +15,7 @@ class UiWindowX11 : public UiWindow virtual ~UiWindowX11(); virtual void drawPoint( const Point2d & point, const PaintColor & color ); + virtual void drawLine( const Point2d & start, const Point2d & end, const PaintColor & color ); protected: virtual void _display(); private: @@ -27,6 +29,7 @@ class UiWindowX11 : public UiWindow uint32_t _height; std::vector< std::pair > _point; + std::vector< std::tuple > _lines; void _setupImage( const penguinV::Image & image ); }; From e5d76d56b290c718e7ddc690dbc58390331bc010 Mon Sep 17 00:00:00 2001 From: Eugene Gagulin Date: Wed, 20 Nov 2019 17:57:03 +0300 Subject: [PATCH 02/14] Add drawEllipse() method --- src/ui/x11/x11_ui.cpp | 19 +++++++++++++++++++ src/ui/x11/x11_ui.h | 2 ++ 2 files changed, 21 insertions(+) diff --git a/src/ui/x11/x11_ui.cpp b/src/ui/x11/x11_ui.cpp index 9c88a8f5d..2910252d5 100644 --- a/src/ui/x11/x11_ui.cpp +++ b/src/ui/x11/x11_ui.cpp @@ -65,6 +65,17 @@ void UiWindowX11::_display() XDrawLine( _uiDisplay, _window, defaultGC, static_cast(start.x), static_cast(start.y), static_cast(end.x), static_cast(end.y) ); } + + for ( size_t i = 0u; i < _ellipses.size(); ++i ) { + const Point2d & position = std::get<0>( _ellipses[i] ); + const double & width = std::get<1>( _ellipses[i] ); + const double & height = std::get<2>( _ellipses[i] ); + const uint32_t & foreground = std::get<3>( _ellipses[i] ); + + + XSetForeground( _uiDisplay, defaultGC, foreground ); + XDrawArc( _uiDisplay, _window, defaultGC, position.x, position.y, width, height, 0, 360 * 64 ); + } } else if ( (e.type == ClientMessage) && (static_cast(e.xclient.data.l[0]) == _deleteWindowEvent) ) break; @@ -127,4 +138,12 @@ void UiWindowX11::drawLine( const Point2d & start, const Point2d & end, const Pa _lines.push_back( std::make_tuple( start, end, (color.red << 16) + (color.green << 8) + color.blue ) ); } +void UiWindowX11::drawEllipse( const Point2d & center, double xRadius, double yRadius, const PaintColor & color ) +{ + //XDrawArc needs x and y coordinates of the upper-left corner of the bounding rectangle but not the center of the ellipse. + Point2d position(center.x - xRadius, center.y - yRadius); + + _ellipses.push_back( std::make_tuple( position, xRadius * 2, yRadius * 2, (color.red << 16) + (color.green << 8) + color.blue ) ); +} + #endif diff --git a/src/ui/x11/x11_ui.h b/src/ui/x11/x11_ui.h index 07611e377..7ebad2bb8 100644 --- a/src/ui/x11/x11_ui.h +++ b/src/ui/x11/x11_ui.h @@ -16,6 +16,7 @@ class UiWindowX11 : public UiWindow virtual void drawPoint( const Point2d & point, const PaintColor & color ); virtual void drawLine( const Point2d & start, const Point2d & end, const PaintColor & color ); + virtual void drawEllipse( const Point2d & center, double xRadius, double yRadius, const PaintColor & color ); protected: virtual void _display(); private: @@ -30,6 +31,7 @@ class UiWindowX11 : public UiWindow std::vector< std::pair > _point; std::vector< std::tuple > _lines; + std::vector< std::tuple > _ellipses; void _setupImage( const penguinV::Image & image ); }; From abba91acca233462e9c0f7cf0aa116cecf76ffe3 Mon Sep 17 00:00:00 2001 From: Eugene Gagulin Date: Thu, 21 Nov 2019 10:17:13 +0300 Subject: [PATCH 03/14] Add drawRectangle() method. --- src/ui/x11/x11_ui.cpp | 16 +++++++++++++++- src/ui/x11/x11_ui.h | 2 ++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/ui/x11/x11_ui.cpp b/src/ui/x11/x11_ui.cpp index 2910252d5..944443d55 100644 --- a/src/ui/x11/x11_ui.cpp +++ b/src/ui/x11/x11_ui.cpp @@ -72,10 +72,19 @@ void UiWindowX11::_display() const double & height = std::get<2>( _ellipses[i] ); const uint32_t & foreground = std::get<3>( _ellipses[i] ); - XSetForeground( _uiDisplay, defaultGC, foreground ); XDrawArc( _uiDisplay, _window, defaultGC, position.x, position.y, width, height, 0, 360 * 64 ); } + + for ( size_t i = 0u; i < _rectangles.size(); ++i) { + const Point2d & topLeftCorner = std::get<0>( _rectangles[i] ); + const double & width = std::get<1>( _rectangles[i] ); + const double & height = std::get<2>( _rectangles[i] ); + const uint32_t & foreground = std::get<3>( _rectangles[i] ); + + XSetForeground(_uiDisplay, defaultGC, foreground); + XDrawRectangle(_uiDisplay, _window, defaultGC, topLeftCorner.x, topLeftCorner.y, width, height); + } } else if ( (e.type == ClientMessage) && (static_cast(e.xclient.data.l[0]) == _deleteWindowEvent) ) break; @@ -146,4 +155,9 @@ void UiWindowX11::drawEllipse( const Point2d & center, double xRadius, double yR _ellipses.push_back( std::make_tuple( position, xRadius * 2, yRadius * 2, (color.red << 16) + (color.green << 8) + color.blue ) ); } +void UiWindowX11::drawRectangle( const Point2d & topLeftCorner, double width, double height, const PaintColor & color ) +{ + _rectangles.push_back( std::make_tuple( topLeftCorner, width, height, (color.red << 16) + (color.green << 8) + color.blue ) ); +} + #endif diff --git a/src/ui/x11/x11_ui.h b/src/ui/x11/x11_ui.h index 7ebad2bb8..c415c8e3b 100644 --- a/src/ui/x11/x11_ui.h +++ b/src/ui/x11/x11_ui.h @@ -17,6 +17,7 @@ class UiWindowX11 : public UiWindow virtual void drawPoint( const Point2d & point, const PaintColor & color ); virtual void drawLine( const Point2d & start, const Point2d & end, const PaintColor & color ); virtual void drawEllipse( const Point2d & center, double xRadius, double yRadius, const PaintColor & color ); + virtual void drawRectangle( const Point2d & topLeftCorner, double width, double height, const PaintColor & color ); protected: virtual void _display(); private: @@ -32,6 +33,7 @@ class UiWindowX11 : public UiWindow std::vector< std::pair > _point; std::vector< std::tuple > _lines; std::vector< std::tuple > _ellipses; + std::vector< std::tuple > _rectangles; void _setupImage( const penguinV::Image & image ); }; From 079d528d3cc067d3ecb3419f49334ac51f11caa5 Mon Sep 17 00:00:00 2001 From: Eugene Gagulin Date: Thu, 21 Nov 2019 10:24:16 +0300 Subject: [PATCH 04/14] Change drawPoint() method to draw the cross (x). --- src/ui/x11/x11_ui.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/ui/x11/x11_ui.cpp b/src/ui/x11/x11_ui.cpp index 944443d55..8e8a124aa 100644 --- a/src/ui/x11/x11_ui.cpp +++ b/src/ui/x11/x11_ui.cpp @@ -54,6 +54,8 @@ void UiWindowX11::_display() XSetForeground( _uiDisplay, defaultGC, _point[i].second ); XDrawLine( _uiDisplay, _window, defaultGC, static_cast(point.x - 1), static_cast(point.y - 1), static_cast(point.x + 1), static_cast(point.y + 1) ); + XDrawLine( _uiDisplay, _window, defaultGC, static_cast(point.x - 1), static_cast(point.y + 1), + static_cast(point.x + 1), static_cast(point.y - 1) ); } for ( size_t i = 0u; i < _lines.size(); ++i ) { From 7e71f6b82a56ba366d50978cac7c98c2e57bf057 Mon Sep 17 00:00:00 2001 From: Eugene Gagulin Date: Thu, 21 Nov 2019 11:05:55 +0300 Subject: [PATCH 05/14] Code clean up. --- src/ui/x11/x11_ui.cpp | 38 ++++++++++++++++++++------------------ src/ui/x11/x11_ui.h | 9 +++++---- 2 files changed, 25 insertions(+), 22 deletions(-) diff --git a/src/ui/x11/x11_ui.cpp b/src/ui/x11/x11_ui.cpp index 8e8a124aa..273494d40 100644 --- a/src/ui/x11/x11_ui.cpp +++ b/src/ui/x11/x11_ui.cpp @@ -52,20 +52,20 @@ void UiWindowX11::_display() for ( size_t i = 0u; i < _point.size(); ++i ) { const Point2d & point = _point[i].first; XSetForeground( _uiDisplay, defaultGC, _point[i].second ); - XDrawLine( _uiDisplay, _window, defaultGC, static_cast(point.x - 1), static_cast(point.y - 1), - static_cast(point.x + 1), static_cast(point.y + 1) ); - XDrawLine( _uiDisplay, _window, defaultGC, static_cast(point.x - 1), static_cast(point.y + 1), - static_cast(point.x + 1), static_cast(point.y - 1) ); + XDrawLine( _uiDisplay, _window, defaultGC, static_cast( point.x - 1 ), static_cast( point.y - 1 ), static_cast( point.x + 1 ), + static_cast( point.y + 1 ) ); + XDrawLine( _uiDisplay, _window, defaultGC, static_cast( point.x - 1 ), static_cast( point.y + 1 ), static_cast( point.x + 1 ), + static_cast( point.y - 1 ) ); } for ( size_t i = 0u; i < _lines.size(); ++i ) { - const Point2d & start = std::get<0>(_lines[i]); - const Point2d & end = std::get<1>(_lines[i]); - const uint32_t & foreground = std::get<2>(_lines[i]); + const Point2d & start = std::get<0>( _lines[i] ); + const Point2d & end = std::get<1>( _lines[i] ); + const uint32_t & foreground = std::get<2>( _lines[i] ); XSetForeground( _uiDisplay, defaultGC, foreground ); - XDrawLine( _uiDisplay, _window, defaultGC, static_cast(start.x), static_cast(start.y), - static_cast(end.x), static_cast(end.y) ); + XDrawLine( _uiDisplay, _window, defaultGC, static_cast( start.x ), static_cast( start.y ), static_cast( end.x ), + static_cast( end.y ) ); } for ( size_t i = 0u; i < _ellipses.size(); ++i ) { @@ -75,17 +75,19 @@ void UiWindowX11::_display() const uint32_t & foreground = std::get<3>( _ellipses[i] ); XSetForeground( _uiDisplay, defaultGC, foreground ); - XDrawArc( _uiDisplay, _window, defaultGC, position.x, position.y, width, height, 0, 360 * 64 ); + XDrawArc( _uiDisplay, _window, defaultGC, static_cast( position.x ), static_cast( position.y ), static_cast( width ), + static_cast( height ), 0, 360 * 64 ); } - for ( size_t i = 0u; i < _rectangles.size(); ++i) { + for ( size_t i = 0u; i < _rectangles.size(); ++i ) { const Point2d & topLeftCorner = std::get<0>( _rectangles[i] ); const double & width = std::get<1>( _rectangles[i] ); const double & height = std::get<2>( _rectangles[i] ); const uint32_t & foreground = std::get<3>( _rectangles[i] ); - XSetForeground(_uiDisplay, defaultGC, foreground); - XDrawRectangle(_uiDisplay, _window, defaultGC, topLeftCorner.x, topLeftCorner.y, width, height); + XSetForeground( _uiDisplay, defaultGC, foreground ); + XDrawRectangle( _uiDisplay, _window, defaultGC, static_cast( topLeftCorner.x ), static_cast( topLeftCorner.y ), static_cast( width ), + static_cast( height ) ); } } else if ( (e.type == ClientMessage) && (static_cast(e.xclient.data.l[0]) == _deleteWindowEvent) ) @@ -146,20 +148,20 @@ void UiWindowX11::drawPoint( const Point2d & point, const PaintColor & color ) void UiWindowX11::drawLine( const Point2d & start, const Point2d & end, const PaintColor & color ) { - _lines.push_back( std::make_tuple( start, end, (color.red << 16) + (color.green << 8) + color.blue ) ); + _lines.push_back( std::make_tuple( start, end, ( color.red << 16 ) + ( color.green << 8 ) + color.blue ) ); } void UiWindowX11::drawEllipse( const Point2d & center, double xRadius, double yRadius, const PaintColor & color ) { - //XDrawArc needs x and y coordinates of the upper-left corner of the bounding rectangle but not the center of the ellipse. - Point2d position(center.x - xRadius, center.y - yRadius); + // XDrawArc needs x and y coordinates of the upper-left corner of the bounding rectangle but not the center of the ellipse. + Point2d position( center.x - xRadius, center.y - yRadius ); - _ellipses.push_back( std::make_tuple( position, xRadius * 2, yRadius * 2, (color.red << 16) + (color.green << 8) + color.blue ) ); + _ellipses.push_back( std::make_tuple( position, xRadius * 2, yRadius * 2, ( color.red << 16 ) + ( color.green << 8 ) + color.blue ) ); } void UiWindowX11::drawRectangle( const Point2d & topLeftCorner, double width, double height, const PaintColor & color ) { - _rectangles.push_back( std::make_tuple( topLeftCorner, width, height, (color.red << 16) + (color.green << 8) + color.blue ) ); + _rectangles.push_back( std::make_tuple( topLeftCorner, width, height, ( color.red << 16 ) + ( color.green << 8 ) + color.blue ) ); } #endif diff --git a/src/ui/x11/x11_ui.h b/src/ui/x11/x11_ui.h index c415c8e3b..5e537e0c4 100644 --- a/src/ui/x11/x11_ui.h +++ b/src/ui/x11/x11_ui.h @@ -18,6 +18,7 @@ class UiWindowX11 : public UiWindow virtual void drawLine( const Point2d & start, const Point2d & end, const PaintColor & color ); virtual void drawEllipse( const Point2d & center, double xRadius, double yRadius, const PaintColor & color ); virtual void drawRectangle( const Point2d & topLeftCorner, double width, double height, const PaintColor & color ); + protected: virtual void _display(); private: @@ -30,10 +31,10 @@ class UiWindowX11 : public UiWindow uint32_t _width; uint32_t _height; - std::vector< std::pair > _point; - std::vector< std::tuple > _lines; - std::vector< std::tuple > _ellipses; - std::vector< std::tuple > _rectangles; + std::vector> _point; + std::vector> _lines; + std::vector> _ellipses; + std::vector> _rectangles; void _setupImage( const penguinV::Image & image ); }; From 5dc24009f31058e46db0a3d679e856a5d992ec66 Mon Sep 17 00:00:00 2001 From: Eugene Date: Sun, 8 Dec 2019 15:43:20 +0300 Subject: [PATCH 06/14] Revert "Change drawPoint() method to draw the cross (x)." --- src/ui/x11/x11_ui.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/ui/x11/x11_ui.cpp b/src/ui/x11/x11_ui.cpp index 273494d40..0d696887b 100644 --- a/src/ui/x11/x11_ui.cpp +++ b/src/ui/x11/x11_ui.cpp @@ -54,8 +54,6 @@ void UiWindowX11::_display() XSetForeground( _uiDisplay, defaultGC, _point[i].second ); XDrawLine( _uiDisplay, _window, defaultGC, static_cast( point.x - 1 ), static_cast( point.y - 1 ), static_cast( point.x + 1 ), static_cast( point.y + 1 ) ); - XDrawLine( _uiDisplay, _window, defaultGC, static_cast( point.x - 1 ), static_cast( point.y + 1 ), static_cast( point.x + 1 ), - static_cast( point.y - 1 ) ); } for ( size_t i = 0u; i < _lines.size(); ++i ) { From bdea57f3ce19b53ac24b620a26ec71573327e96a Mon Sep 17 00:00:00 2001 From: Eugene Gagulin Date: Fri, 20 Dec 2019 15:41:42 +0300 Subject: [PATCH 07/14] Copy structures from win_ui.h. --- src/ui/x11/x11_ui.cpp | 36 +++++++++++------------ src/ui/x11/x11_ui.h | 67 +++++++++++++++++++++++++++++++++++++++---- 2 files changed, 80 insertions(+), 23 deletions(-) diff --git a/src/ui/x11/x11_ui.cpp b/src/ui/x11/x11_ui.cpp index 0d696887b..a5ac4116f 100644 --- a/src/ui/x11/x11_ui.cpp +++ b/src/ui/x11/x11_ui.cpp @@ -50,16 +50,16 @@ void UiWindowX11::_display() XPutImage( _uiDisplay, _window, defaultGC, _image, 0, 0, 0, 0, _width, _height ); for ( size_t i = 0u; i < _point.size(); ++i ) { - const Point2d & point = _point[i].first; - XSetForeground( _uiDisplay, defaultGC, _point[i].second ); + const Point2d & point = _point[i].point; + XSetForeground( _uiDisplay, defaultGC, _point[i].color ); XDrawLine( _uiDisplay, _window, defaultGC, static_cast( point.x - 1 ), static_cast( point.y - 1 ), static_cast( point.x + 1 ), static_cast( point.y + 1 ) ); } for ( size_t i = 0u; i < _lines.size(); ++i ) { - const Point2d & start = std::get<0>( _lines[i] ); - const Point2d & end = std::get<1>( _lines[i] ); - const uint32_t & foreground = std::get<2>( _lines[i] ); + const Point2d & start = _lines[i].start; + const Point2d & end = _lines[i].end; + const uint32_t & foreground = _lines[i].color; XSetForeground( _uiDisplay, defaultGC, foreground ); XDrawLine( _uiDisplay, _window, defaultGC, static_cast( start.x ), static_cast( start.y ), static_cast( end.x ), @@ -67,10 +67,10 @@ void UiWindowX11::_display() } for ( size_t i = 0u; i < _ellipses.size(); ++i ) { - const Point2d & position = std::get<0>( _ellipses[i] ); - const double & width = std::get<1>( _ellipses[i] ); - const double & height = std::get<2>( _ellipses[i] ); - const uint32_t & foreground = std::get<3>( _ellipses[i] ); + const Point2d & position = _ellipses[i].topLeft; + const double & width = _ellipses[i].width; + const double & height = _ellipses[i].height; + const uint32_t & foreground = _ellipses[i].color; XSetForeground( _uiDisplay, defaultGC, foreground ); XDrawArc( _uiDisplay, _window, defaultGC, static_cast( position.x ), static_cast( position.y ), static_cast( width ), @@ -78,13 +78,13 @@ void UiWindowX11::_display() } for ( size_t i = 0u; i < _rectangles.size(); ++i ) { - const Point2d & topLeftCorner = std::get<0>( _rectangles[i] ); - const double & width = std::get<1>( _rectangles[i] ); - const double & height = std::get<2>( _rectangles[i] ); - const uint32_t & foreground = std::get<3>( _rectangles[i] ); + const Point2d & topLeft = _rectangles[i].topLeft; + const double & width = _rectangles[i].width; + const double & height = _rectangles[i].height; + const uint32_t & foreground = _rectangles[i].color; XSetForeground( _uiDisplay, defaultGC, foreground ); - XDrawRectangle( _uiDisplay, _window, defaultGC, static_cast( topLeftCorner.x ), static_cast( topLeftCorner.y ), static_cast( width ), + XDrawRectangle( _uiDisplay, _window, defaultGC, static_cast( topLeft.x ), static_cast( topLeft.y ), static_cast( width ), static_cast( height ) ); } } @@ -141,12 +141,12 @@ void UiWindowX11::_setupImage( const penguinV::Image & image ) void UiWindowX11::drawPoint( const Point2d & point, const PaintColor & color ) { - _point.push_back( std::make_pair( point, (color.red << 16) + (color.green << 8) + color.blue ) ); + _point.push_back( PointToDraw( point, (color.red << 16) + (color.green << 8) + color.blue ) ); } void UiWindowX11::drawLine( const Point2d & start, const Point2d & end, const PaintColor & color ) { - _lines.push_back( std::make_tuple( start, end, ( color.red << 16 ) + ( color.green << 8 ) + color.blue ) ); + _lines.push_back( LineToDraw( start, end, ( color.red << 16 ) + ( color.green << 8 ) + color.blue ) ); } void UiWindowX11::drawEllipse( const Point2d & center, double xRadius, double yRadius, const PaintColor & color ) @@ -154,12 +154,12 @@ void UiWindowX11::drawEllipse( const Point2d & center, double xRadius, double yR // XDrawArc needs x and y coordinates of the upper-left corner of the bounding rectangle but not the center of the ellipse. Point2d position( center.x - xRadius, center.y - yRadius ); - _ellipses.push_back( std::make_tuple( position, xRadius * 2, yRadius * 2, ( color.red << 16 ) + ( color.green << 8 ) + color.blue ) ); + _ellipses.push_back( EllipseToDraw( position, xRadius * 2, yRadius * 2, ( color.red << 16 ) + ( color.green << 8 ) + color.blue ) ); } void UiWindowX11::drawRectangle( const Point2d & topLeftCorner, double width, double height, const PaintColor & color ) { - _rectangles.push_back( std::make_tuple( topLeftCorner, width, height, ( color.red << 16 ) + ( color.green << 8 ) + color.blue ) ); + _rectangles.push_back( RectangleToDraw( topLeftCorner, width, height, ( color.red << 16 ) + ( color.green << 8 ) + color.blue ) ); } #endif diff --git a/src/ui/x11/x11_ui.h b/src/ui/x11/x11_ui.h index 5e537e0c4..7453a1e1a 100644 --- a/src/ui/x11/x11_ui.h +++ b/src/ui/x11/x11_ui.h @@ -3,7 +3,6 @@ #ifndef _WIN32 // Not for Windows #include -#include #include #include #include "../ui.h" @@ -31,10 +30,68 @@ class UiWindowX11 : public UiWindow uint32_t _width; uint32_t _height; - std::vector> _point; - std::vector> _lines; - std::vector> _ellipses; - std::vector> _rectangles; + struct PointToDraw + { + PointToDraw( const Point2d & point_ = Point2d(), uint32_t color_ = 0 ) + : point( point_ ) + , color( color_ ) + { + } + + Point2d point; + uint32_t color; + }; + + struct LineToDraw + { + LineToDraw( const Point2d & start_ = Point2d(), const Point2d & end_ = Point2d(), uint32_t color_ = 0 ) + : start( start_ ) + , end ( end_ ) + , color( color_ ) + { + } + + Point2d start; + Point2d end; + uint32_t color; + }; + + struct EllipseToDraw + { + EllipseToDraw( const Point2d& topLeft_ = Point2d(), double width_ = 0.0, double height_ = 0.0, uint32_t color_ = 0 ) + : topLeft ( topLeft_ ) + , width ( width_ ) + , height ( height_ ) + , color ( color_ ) + { + } + + Point2d topLeft; + double width; + double height; + uint32_t color; + }; + + struct RectangleToDraw + { + RectangleToDraw( const Point2d& topLeft_ = Point2d(), double width_ = 0.0, double height_ = 0.0, uint32_t color_ = 0 ) + : topLeft ( topLeft_ ) + , width ( width_ ) + , height ( height_ ) + , color ( color_ ) + { + } + + Point2d topLeft; + double width; + double height; + uint32_t color; + }; + + std::vector < PointToDraw > _point; + std::vector < LineToDraw > _lines; + std::vector < EllipseToDraw > _ellipses; + std::vector < RectangleToDraw > _rectangles; void _setupImage( const penguinV::Image & image ); }; From 61df1326f18457c49f96f818ddb92111b78c4272 Mon Sep 17 00:00:00 2001 From: Eugene Gagulin Date: Fri, 20 Dec 2019 16:05:40 +0300 Subject: [PATCH 08/14] Fix format --- src/ui/x11/x11_ui.cpp | 4 ++-- src/ui/x11/x11_ui.h | 46 ++++++++++++++++++++----------------------- 2 files changed, 23 insertions(+), 27 deletions(-) diff --git a/src/ui/x11/x11_ui.cpp b/src/ui/x11/x11_ui.cpp index a5ac4116f..715466f89 100644 --- a/src/ui/x11/x11_ui.cpp +++ b/src/ui/x11/x11_ui.cpp @@ -57,7 +57,7 @@ void UiWindowX11::_display() } for ( size_t i = 0u; i < _lines.size(); ++i ) { - const Point2d & start = _lines[i].start; + const Point2d & start = _lines[i].start; const Point2d & end = _lines[i].end; const uint32_t & foreground = _lines[i].color; @@ -141,7 +141,7 @@ void UiWindowX11::_setupImage( const penguinV::Image & image ) void UiWindowX11::drawPoint( const Point2d & point, const PaintColor & color ) { - _point.push_back( PointToDraw( point, (color.red << 16) + (color.green << 8) + color.blue ) ); + _point.push_back( PointToDraw( point, ( color.red << 16 ) + ( color.green << 8 ) + color.blue ) ); } void UiWindowX11::drawLine( const Point2d & start, const Point2d & end, const PaintColor & color ) diff --git a/src/ui/x11/x11_ui.h b/src/ui/x11/x11_ui.h index 7453a1e1a..4c1eed4be 100644 --- a/src/ui/x11/x11_ui.h +++ b/src/ui/x11/x11_ui.h @@ -32,11 +32,10 @@ class UiWindowX11 : public UiWindow struct PointToDraw { - PointToDraw( const Point2d & point_ = Point2d(), uint32_t color_ = 0 ) + PointToDraw( const Point2d & point_ = Point2d(), uint32_t color_ = 0 ) : point( point_ ) , color( color_ ) - { - } + {} Point2d point; uint32_t color; @@ -44,12 +43,11 @@ class UiWindowX11 : public UiWindow struct LineToDraw { - LineToDraw( const Point2d & start_ = Point2d(), const Point2d & end_ = Point2d(), uint32_t color_ = 0 ) + LineToDraw( const Point2d & start_ = Point2d(), const Point2d & end_ = Point2d(), uint32_t color_ = 0 ) : start( start_ ) - , end ( end_ ) + , end( end_ ) , color( color_ ) - { - } + {} Point2d start; Point2d end; @@ -58,13 +56,12 @@ class UiWindowX11 : public UiWindow struct EllipseToDraw { - EllipseToDraw( const Point2d& topLeft_ = Point2d(), double width_ = 0.0, double height_ = 0.0, uint32_t color_ = 0 ) - : topLeft ( topLeft_ ) - , width ( width_ ) - , height ( height_ ) - , color ( color_ ) - { - } + EllipseToDraw( const Point2d & topLeft_ = Point2d(), double width_ = 0.0, double height_ = 0.0, uint32_t color_ = 0 ) + : topLeft( topLeft_ ) + , width( width_ ) + , height( height_ ) + , color( color_ ) + {} Point2d topLeft; double width; @@ -74,13 +71,12 @@ class UiWindowX11 : public UiWindow struct RectangleToDraw { - RectangleToDraw( const Point2d& topLeft_ = Point2d(), double width_ = 0.0, double height_ = 0.0, uint32_t color_ = 0 ) - : topLeft ( topLeft_ ) - , width ( width_ ) - , height ( height_ ) - , color ( color_ ) - { - } + RectangleToDraw( const Point2d & topLeft_ = Point2d(), double width_ = 0.0, double height_ = 0.0, uint32_t color_ = 0 ) + : topLeft( topLeft_ ) + , width( width_ ) + , height( height_ ) + , color( color_ ) + {} Point2d topLeft; double width; @@ -88,10 +84,10 @@ class UiWindowX11 : public UiWindow uint32_t color; }; - std::vector < PointToDraw > _point; - std::vector < LineToDraw > _lines; - std::vector < EllipseToDraw > _ellipses; - std::vector < RectangleToDraw > _rectangles; + std::vector _point; + std::vector _lines; + std::vector _ellipses; + std::vector _rectangles; void _setupImage( const penguinV::Image & image ); }; From 554a020dd526c69eda7866a64c4560908b0842c5 Mon Sep 17 00:00:00 2001 From: Eugene Date: Sat, 21 Dec 2019 16:07:09 +0300 Subject: [PATCH 09/14] Make 'position' variable const. --- src/ui/x11/x11_ui.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ui/x11/x11_ui.cpp b/src/ui/x11/x11_ui.cpp index 715466f89..d8df93d6a 100644 --- a/src/ui/x11/x11_ui.cpp +++ b/src/ui/x11/x11_ui.cpp @@ -152,7 +152,7 @@ void UiWindowX11::drawLine( const Point2d & start, const Point2d & end, const Pa void UiWindowX11::drawEllipse( const Point2d & center, double xRadius, double yRadius, const PaintColor & color ) { // XDrawArc needs x and y coordinates of the upper-left corner of the bounding rectangle but not the center of the ellipse. - Point2d position( center.x - xRadius, center.y - yRadius ); + const Point2d position( center.x - xRadius, center.y - yRadius ); _ellipses.push_back( EllipseToDraw( position, xRadius * 2, yRadius * 2, ( color.red << 16 ) + ( color.green << 8 ) + color.blue ) ); } From a087eb9c77f627ec5a054ea255acc19dd462c3d6 Mon Sep 17 00:00:00 2001 From: Eugene Gagulin Date: Tue, 24 Dec 2019 11:08:53 +0300 Subject: [PATCH 10/14] Move identical structures in a common location. --- src/ui/ui.h | 45 ++++++++++++++++++++++++++++++++++++++++ src/ui/win/win_ui.cpp | 11 +++++----- src/ui/win/win_ui.h | 48 ------------------------------------------- src/ui/x11/x11_ui.cpp | 30 ++++++++++++++++----------- src/ui/x11/x11_ui.h | 47 +++--------------------------------------- 5 files changed, 72 insertions(+), 109 deletions(-) diff --git a/src/ui/ui.h b/src/ui/ui.h index aae696f13..6d0793afd 100644 --- a/src/ui/ui.h +++ b/src/ui/ui.h @@ -33,6 +33,51 @@ class UiWindow protected: virtual void _display(); + struct PointToDraw + { + PointToDraw( const Point2d & point_ = Point2d(), const PaintColor & color_ = PaintColor() ) + : point( point_ ) + , color( color_ ) + { + } + + Point2d point; + PaintColor color; + }; + + struct LineToDraw + { + LineToDraw( const Point2d & start_ = Point2d(), const Point2d & end_ = Point2d(), const PaintColor & color_ = PaintColor() ) + : start( start_ ) + , end ( end_ ) + , color( color_ ) + { + } + + Point2d start; + Point2d end; + PaintColor color; + }; + + struct EllipseToDraw + { + EllipseToDraw( const Point2d & topLeft_ = Point2d(), double width_ = 0.0, double height_ = 0.0, const PaintColor & color_ = PaintColor() ) + : topLeft( topLeft_ ) + , width( width_ ) + , height( height_ ) + , color( color_ ) + {} + + Point2d topLeft; + double width; + double height; + PaintColor color; + }; + + std::vector _point; + std::vector _lines; + std::vector _ellipses; + penguinV::Image _image; // we store a copy of image std::string _title; bool _shown; diff --git a/src/ui/win/win_ui.cpp b/src/ui/win/win_ui.cpp index dbe29615c..c4b561ce4 100644 --- a/src/ui/win/win_ui.cpp +++ b/src/ui/win/win_ui.cpp @@ -68,10 +68,10 @@ namespace WindowsUi } for ( std::vector < UiWindowWin::EllipseToDraw >::const_iterator ellipse = _window->_ellipse.cbegin(); ellipse != _window->_ellipse.cend(); ++ellipse ) { - const int left = static_cast( ellipse->left * xFactor ); - const int top = static_cast( ellipse->top * yFactor ); - const int right = static_cast( ellipse->right * xFactor ); - const int bottom = static_cast( ellipse->bottom * yFactor ); + const int left = static_cast( ellipse->topLeft.x * xFactor ); + const int top = static_cast( ellipse->topLeft.y * yFactor ); + const int right = static_cast( ( ellipse->topLeft.x + width ) * xFactor ); + const int bottom = static_cast( ( ellipse->topLeft.y + height ) * yFactor ); HPEN hPen = CreatePen( PS_SOLID, 1, RGB( ellipse->color.red, ellipse->color.green, ellipse->color.blue ) ); HGDIOBJ hOldPen = SelectObject( hdc, hPen ); @@ -276,7 +276,8 @@ void UiWindowWin::drawLine( const Point2d & start, const Point2d & end, const Pa void UiWindowWin::drawEllipse( const Point2d & center, double xRadius, double yRadius, const PaintColor & color ) { - _ellipse.emplace_back( center.x - xRadius, center.y - yRadius, center.x + xRadius, center.y + yRadius, color ); + const Point topLeft( center.x - xRadius, center.y - yRadius ); + _ellipse.emplace_back( topLeft, xRadius * 2, yRadius * 2, color ); _display(); } diff --git a/src/ui/win/win_ui.h b/src/ui/win/win_ui.h index 2844b19b8..69977d408 100644 --- a/src/ui/win/win_ui.h +++ b/src/ui/win/win_ui.h @@ -28,54 +28,6 @@ class UiWindowWin : public UiWindow HWND _window; // Windows OS window handle (just an unique ID) BITMAPINFO * _bmpInfo; // bitmap structure needed for drawing - struct PointToDraw - { - PointToDraw( const Point2d & point_ = Point2d(), const PaintColor & color_ = PaintColor() ) - : point( point_ ) - , color( color_ ) - { - } - - Point2d point; - PaintColor color; - }; - - struct LineToDraw - { - LineToDraw( const Point2d & start_ = Point2d(), const Point2d & end_ = Point2d(), const PaintColor & color_ = PaintColor() ) - : start( start_ ) - , end ( end_ ) - , color( color_ ) - { - } - - Point2d start; - Point2d end; - PaintColor color; - }; - - struct EllipseToDraw - { - EllipseToDraw( double left_ = 0, double top_ = 0, double right_ = 0, double bottom_ = 0, const PaintColor & color_ = PaintColor() ) - : left ( left_ ) - , top ( top_ ) - , right ( right_ ) - , bottom( bottom_ ) - , color ( color_ ) - { - } - - double left; - double top; - double right; - double bottom; - PaintColor color; - }; - - std::vector < PointToDraw > _point; - std::vector < LineToDraw > _line; - std::vector < EllipseToDraw > _ellipse; - friend class WindowsUi::UiWindowWinInfo; void _free(); diff --git a/src/ui/x11/x11_ui.cpp b/src/ui/x11/x11_ui.cpp index d8df93d6a..1d5bfecd6 100644 --- a/src/ui/x11/x11_ui.cpp +++ b/src/ui/x11/x11_ui.cpp @@ -51,7 +51,8 @@ void UiWindowX11::_display() for ( size_t i = 0u; i < _point.size(); ++i ) { const Point2d & point = _point[i].point; - XSetForeground( _uiDisplay, defaultGC, _point[i].color ); + const uint32_t foreground = UiWindowX11::_convertColor( _point[i].color ); + XSetForeground( _uiDisplay, defaultGC, foreground ); XDrawLine( _uiDisplay, _window, defaultGC, static_cast( point.x - 1 ), static_cast( point.y - 1 ), static_cast( point.x + 1 ), static_cast( point.y + 1 ) ); } @@ -59,7 +60,7 @@ void UiWindowX11::_display() for ( size_t i = 0u; i < _lines.size(); ++i ) { const Point2d & start = _lines[i].start; const Point2d & end = _lines[i].end; - const uint32_t & foreground = _lines[i].color; + const uint32_t foreground = UiWindowX11::_convertColor( _lines[i].color ); XSetForeground( _uiDisplay, defaultGC, foreground ); XDrawLine( _uiDisplay, _window, defaultGC, static_cast( start.x ), static_cast( start.y ), static_cast( end.x ), @@ -70,22 +71,22 @@ void UiWindowX11::_display() const Point2d & position = _ellipses[i].topLeft; const double & width = _ellipses[i].width; const double & height = _ellipses[i].height; - const uint32_t & foreground = _ellipses[i].color; + const uint32_t foreground = UiWindowX11::_convertColor( _ellipses[i].color ); XSetForeground( _uiDisplay, defaultGC, foreground ); - XDrawArc( _uiDisplay, _window, defaultGC, static_cast( position.x ), static_cast( position.y ), static_cast( width ), - static_cast( height ), 0, 360 * 64 ); + XDrawArc( _uiDisplay, _window, defaultGC, static_cast( position.x ), static_cast( position.y ), static_cast( width ), + static_cast( height ), 0, 360 * 64 ); } for ( size_t i = 0u; i < _rectangles.size(); ++i ) { const Point2d & topLeft = _rectangles[i].topLeft; const double & width = _rectangles[i].width; const double & height = _rectangles[i].height; - const uint32_t & foreground = _rectangles[i].color; + const uint32_t foreground = UiWindowX11::_convertColor( _rectangles[i].color ); XSetForeground( _uiDisplay, defaultGC, foreground ); - XDrawRectangle( _uiDisplay, _window, defaultGC, static_cast( topLeft.x ), static_cast( topLeft.y ), static_cast( width ), - static_cast( height ) ); + XDrawRectangle( _uiDisplay, _window, defaultGC, static_cast( topLeft.x ), static_cast( topLeft.y ), static_cast( width ), + static_cast( height ) ); } } else if ( (e.type == ClientMessage) && (static_cast(e.xclient.data.l[0]) == _deleteWindowEvent) ) @@ -93,6 +94,11 @@ void UiWindowX11::_display() } } +uint32_t UiWindowX11::_convertColor(const PaintColor &color) +{ + return static_cast( ( color.red << 16 ) + ( color.green << 8 ) + color.blue ); +} + void UiWindowX11::_setupImage( const penguinV::Image & image ) { if ( image.empty() ) @@ -141,12 +147,12 @@ void UiWindowX11::_setupImage( const penguinV::Image & image ) void UiWindowX11::drawPoint( const Point2d & point, const PaintColor & color ) { - _point.push_back( PointToDraw( point, ( color.red << 16 ) + ( color.green << 8 ) + color.blue ) ); + _point.push_back( PointToDraw( point, color ) ); } void UiWindowX11::drawLine( const Point2d & start, const Point2d & end, const PaintColor & color ) { - _lines.push_back( LineToDraw( start, end, ( color.red << 16 ) + ( color.green << 8 ) + color.blue ) ); + _lines.push_back( LineToDraw( start, end, color ) ); } void UiWindowX11::drawEllipse( const Point2d & center, double xRadius, double yRadius, const PaintColor & color ) @@ -154,12 +160,12 @@ void UiWindowX11::drawEllipse( const Point2d & center, double xRadius, double yR // XDrawArc needs x and y coordinates of the upper-left corner of the bounding rectangle but not the center of the ellipse. const Point2d position( center.x - xRadius, center.y - yRadius ); - _ellipses.push_back( EllipseToDraw( position, xRadius * 2, yRadius * 2, ( color.red << 16 ) + ( color.green << 8 ) + color.blue ) ); + _ellipses.push_back( EllipseToDraw( position, xRadius * 2, yRadius * 2, color ) ); } void UiWindowX11::drawRectangle( const Point2d & topLeftCorner, double width, double height, const PaintColor & color ) { - _rectangles.push_back( RectangleToDraw( topLeftCorner, width, height, ( color.red << 16 ) + ( color.green << 8 ) + color.blue ) ); + _rectangles.push_back( RectangleToDraw( topLeftCorner, width, height, color ) ); } #endif diff --git a/src/ui/x11/x11_ui.h b/src/ui/x11/x11_ui.h index 4c1eed4be..e10034a58 100644 --- a/src/ui/x11/x11_ui.h +++ b/src/ui/x11/x11_ui.h @@ -30,48 +30,9 @@ class UiWindowX11 : public UiWindow uint32_t _width; uint32_t _height; - struct PointToDraw - { - PointToDraw( const Point2d & point_ = Point2d(), uint32_t color_ = 0 ) - : point( point_ ) - , color( color_ ) - {} - - Point2d point; - uint32_t color; - }; - - struct LineToDraw - { - LineToDraw( const Point2d & start_ = Point2d(), const Point2d & end_ = Point2d(), uint32_t color_ = 0 ) - : start( start_ ) - , end( end_ ) - , color( color_ ) - {} - - Point2d start; - Point2d end; - uint32_t color; - }; - - struct EllipseToDraw - { - EllipseToDraw( const Point2d & topLeft_ = Point2d(), double width_ = 0.0, double height_ = 0.0, uint32_t color_ = 0 ) - : topLeft( topLeft_ ) - , width( width_ ) - , height( height_ ) - , color( color_ ) - {} - - Point2d topLeft; - double width; - double height; - uint32_t color; - }; - struct RectangleToDraw { - RectangleToDraw( const Point2d & topLeft_ = Point2d(), double width_ = 0.0, double height_ = 0.0, uint32_t color_ = 0 ) + RectangleToDraw( const Point2d & topLeft_ = Point2d(), double width_ = 0.0, double height_ = 0.0, const PaintColor & color_ = PaintColor() ) : topLeft( topLeft_ ) , width( width_ ) , height( height_ ) @@ -81,15 +42,13 @@ class UiWindowX11 : public UiWindow Point2d topLeft; double width; double height; - uint32_t color; + PaintColor color; }; - std::vector _point; - std::vector _lines; - std::vector _ellipses; std::vector _rectangles; void _setupImage( const penguinV::Image & image ); + static uint32_t _convertColor(const PaintColor & color = PaintColor()); }; #endif From 28d23af3c6ac3fbdcf0d97e354813f42d2cf0ff4 Mon Sep 17 00:00:00 2001 From: Eugene Gagulin Date: Tue, 24 Dec 2019 11:33:44 +0300 Subject: [PATCH 11/14] Fix format. --- src/ui/ui.h | 8 +++----- src/ui/x11/x11_ui.cpp | 2 +- src/ui/x11/x11_ui.h | 2 +- 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/src/ui/ui.h b/src/ui/ui.h index 6d0793afd..84fd67405 100644 --- a/src/ui/ui.h +++ b/src/ui/ui.h @@ -38,8 +38,7 @@ class UiWindow PointToDraw( const Point2d & point_ = Point2d(), const PaintColor & color_ = PaintColor() ) : point( point_ ) , color( color_ ) - { - } + {} Point2d point; PaintColor color; @@ -49,10 +48,9 @@ class UiWindow { LineToDraw( const Point2d & start_ = Point2d(), const Point2d & end_ = Point2d(), const PaintColor & color_ = PaintColor() ) : start( start_ ) - , end ( end_ ) + , end( end_ ) , color( color_ ) - { - } + {} Point2d start; Point2d end; diff --git a/src/ui/x11/x11_ui.cpp b/src/ui/x11/x11_ui.cpp index 1d5bfecd6..4c9b684e7 100644 --- a/src/ui/x11/x11_ui.cpp +++ b/src/ui/x11/x11_ui.cpp @@ -94,7 +94,7 @@ void UiWindowX11::_display() } } -uint32_t UiWindowX11::_convertColor(const PaintColor &color) +uint32_t UiWindowX11::_convertColor( const PaintColor & color ) { return static_cast( ( color.red << 16 ) + ( color.green << 8 ) + color.blue ); } diff --git a/src/ui/x11/x11_ui.h b/src/ui/x11/x11_ui.h index e10034a58..fb949bfea 100644 --- a/src/ui/x11/x11_ui.h +++ b/src/ui/x11/x11_ui.h @@ -48,7 +48,7 @@ class UiWindowX11 : public UiWindow std::vector _rectangles; void _setupImage( const penguinV::Image & image ); - static uint32_t _convertColor(const PaintColor & color = PaintColor()); + static uint32_t _convertColor( const PaintColor & color = PaintColor() ); }; #endif From 7e007cd06dbde9e35fe229c9e72ab930de54e58d Mon Sep 17 00:00:00 2001 From: Eugene Gagulin Date: Wed, 25 Dec 2019 17:33:17 +0300 Subject: [PATCH 12/14] Fix for Windows. --- src/ui/win/win_ui.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ui/win/win_ui.cpp b/src/ui/win/win_ui.cpp index c4b561ce4..6fba285c1 100644 --- a/src/ui/win/win_ui.cpp +++ b/src/ui/win/win_ui.cpp @@ -67,7 +67,7 @@ namespace WindowsUi DeleteObject( hPen ); } - for ( std::vector < UiWindowWin::EllipseToDraw >::const_iterator ellipse = _window->_ellipse.cbegin(); ellipse != _window->_ellipse.cend(); ++ellipse ) { + for ( std::vector::const_iterator ellipse = _window->_ellipses.cbegin(); ellipse != _window->_ellipses.cend(); ++ellipse ) { const int left = static_cast( ellipse->topLeft.x * xFactor ); const int top = static_cast( ellipse->topLeft.y * yFactor ); const int right = static_cast( ( ellipse->topLeft.x + width ) * xFactor ); @@ -277,7 +277,7 @@ void UiWindowWin::drawLine( const Point2d & start, const Point2d & end, const Pa void UiWindowWin::drawEllipse( const Point2d & center, double xRadius, double yRadius, const PaintColor & color ) { const Point topLeft( center.x - xRadius, center.y - yRadius ); - _ellipse.emplace_back( topLeft, xRadius * 2, yRadius * 2, color ); + _ellipses.emplace_back( topLeft, xRadius * 2, yRadius * 2, color ); _display(); } From 878cd86329c03a118cd4de8b172b1cbe9cb386a2 Mon Sep 17 00:00:00 2001 From: Eugene Gagulin Date: Wed, 25 Dec 2019 17:50:25 +0300 Subject: [PATCH 13/14] One more fix. --- src/ui/win/win_ui.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/ui/win/win_ui.cpp b/src/ui/win/win_ui.cpp index 6fba285c1..0cb15015e 100644 --- a/src/ui/win/win_ui.cpp +++ b/src/ui/win/win_ui.cpp @@ -39,7 +39,7 @@ namespace WindowsUi const int minPointFactor = static_cast(xFactor < yFactor ? xFactor : yFactor); const int pointMultiplicator = minPointFactor > 1 ? minPointFactor / 2 : 1; - for ( std::vector < UiWindowWin::PointToDraw >::const_iterator point = _window->_point.cbegin(); point != _window->_point.cend(); ++point ) { + for ( std::vector::const_iterator point = _window->_point.cbegin(); point != _window->_point.cend(); ++point ) { const int x = static_cast(point->point.x * xFactor); const int y = static_cast(point->point.y * yFactor); @@ -53,7 +53,7 @@ namespace WindowsUi DeleteObject( hPen ); } - for ( std::vector < UiWindowWin::LineToDraw >::const_iterator line = _window->_line.cbegin(); line != _window->_line.cend(); ++line ) { + for ( std::vector::const_iterator line = _window->_lines.cbegin(); line != _window->_lines.cend(); ++line ) { const int xStart = static_cast(line->start.x * xFactor); const int yStart = static_cast(line->start.y * yFactor); const int xEnd = static_cast(line->end.x * xFactor); @@ -269,7 +269,7 @@ void UiWindowWin::drawPoint( const Point2d & point, const PaintColor & color ) void UiWindowWin::drawLine( const Point2d & start, const Point2d & end, const PaintColor & color ) { - _line.emplace_back( start, end, color ); + _lines.emplace_back( start, end, color ); _display(); } @@ -288,10 +288,10 @@ void UiWindowWin::drawRectangle( const Point2d & topLeftCorner, double width, do const Point2d bottomLeftCorner( topLeftCorner.x, topLeftCorner.y + height ); const Point2d bottomRightCorner( topLeftCorner.x + width, topLeftCorner.y + height ); - _line.emplace_back( topLeftCorner, topRightCorner, color ); - _line.emplace_back( topLeftCorner, bottomLeftCorner, color ); - _line.emplace_back( topRightCorner, bottomRightCorner, color ); - _line.emplace_back( bottomLeftCorner, bottomRightCorner, color ); + _lines.emplace_back( topLeftCorner, topRightCorner, color ); + _lines.emplace_back( topLeftCorner, bottomLeftCorner, color ); + _lines.emplace_back( topRightCorner, bottomRightCorner, color ); + _lines.emplace_back( bottomLeftCorner, bottomRightCorner, color ); _display(); } From f660769fe0fa8ba97a1212fc268a94e7ca8892bd Mon Sep 17 00:00:00 2001 From: Eugene Gagulin Date: Thu, 26 Dec 2019 14:17:16 +0300 Subject: [PATCH 14/14] Revert 4 last commit to check windows buildings. --- src/ui/ui.h | 43 -------------------------------------- src/ui/win/win_ui.cpp | 27 ++++++++++++------------ src/ui/win/win_ui.h | 48 +++++++++++++++++++++++++++++++++++++++++++ src/ui/x11/x11_ui.cpp | 30 +++++++++++---------------- src/ui/x11/x11_ui.h | 47 +++++++++++++++++++++++++++++++++++++++--- 5 files changed, 117 insertions(+), 78 deletions(-) diff --git a/src/ui/ui.h b/src/ui/ui.h index 84fd67405..aae696f13 100644 --- a/src/ui/ui.h +++ b/src/ui/ui.h @@ -33,49 +33,6 @@ class UiWindow protected: virtual void _display(); - struct PointToDraw - { - PointToDraw( const Point2d & point_ = Point2d(), const PaintColor & color_ = PaintColor() ) - : point( point_ ) - , color( color_ ) - {} - - Point2d point; - PaintColor color; - }; - - struct LineToDraw - { - LineToDraw( const Point2d & start_ = Point2d(), const Point2d & end_ = Point2d(), const PaintColor & color_ = PaintColor() ) - : start( start_ ) - , end( end_ ) - , color( color_ ) - {} - - Point2d start; - Point2d end; - PaintColor color; - }; - - struct EllipseToDraw - { - EllipseToDraw( const Point2d & topLeft_ = Point2d(), double width_ = 0.0, double height_ = 0.0, const PaintColor & color_ = PaintColor() ) - : topLeft( topLeft_ ) - , width( width_ ) - , height( height_ ) - , color( color_ ) - {} - - Point2d topLeft; - double width; - double height; - PaintColor color; - }; - - std::vector _point; - std::vector _lines; - std::vector _ellipses; - penguinV::Image _image; // we store a copy of image std::string _title; bool _shown; diff --git a/src/ui/win/win_ui.cpp b/src/ui/win/win_ui.cpp index 0cb15015e..dbe29615c 100644 --- a/src/ui/win/win_ui.cpp +++ b/src/ui/win/win_ui.cpp @@ -39,7 +39,7 @@ namespace WindowsUi const int minPointFactor = static_cast(xFactor < yFactor ? xFactor : yFactor); const int pointMultiplicator = minPointFactor > 1 ? minPointFactor / 2 : 1; - for ( std::vector::const_iterator point = _window->_point.cbegin(); point != _window->_point.cend(); ++point ) { + for ( std::vector < UiWindowWin::PointToDraw >::const_iterator point = _window->_point.cbegin(); point != _window->_point.cend(); ++point ) { const int x = static_cast(point->point.x * xFactor); const int y = static_cast(point->point.y * yFactor); @@ -53,7 +53,7 @@ namespace WindowsUi DeleteObject( hPen ); } - for ( std::vector::const_iterator line = _window->_lines.cbegin(); line != _window->_lines.cend(); ++line ) { + for ( std::vector < UiWindowWin::LineToDraw >::const_iterator line = _window->_line.cbegin(); line != _window->_line.cend(); ++line ) { const int xStart = static_cast(line->start.x * xFactor); const int yStart = static_cast(line->start.y * yFactor); const int xEnd = static_cast(line->end.x * xFactor); @@ -67,11 +67,11 @@ namespace WindowsUi DeleteObject( hPen ); } - for ( std::vector::const_iterator ellipse = _window->_ellipses.cbegin(); ellipse != _window->_ellipses.cend(); ++ellipse ) { - const int left = static_cast( ellipse->topLeft.x * xFactor ); - const int top = static_cast( ellipse->topLeft.y * yFactor ); - const int right = static_cast( ( ellipse->topLeft.x + width ) * xFactor ); - const int bottom = static_cast( ( ellipse->topLeft.y + height ) * yFactor ); + for ( std::vector < UiWindowWin::EllipseToDraw >::const_iterator ellipse = _window->_ellipse.cbegin(); ellipse != _window->_ellipse.cend(); ++ellipse ) { + const int left = static_cast( ellipse->left * xFactor ); + const int top = static_cast( ellipse->top * yFactor ); + const int right = static_cast( ellipse->right * xFactor ); + const int bottom = static_cast( ellipse->bottom * yFactor ); HPEN hPen = CreatePen( PS_SOLID, 1, RGB( ellipse->color.red, ellipse->color.green, ellipse->color.blue ) ); HGDIOBJ hOldPen = SelectObject( hdc, hPen ); @@ -269,15 +269,14 @@ void UiWindowWin::drawPoint( const Point2d & point, const PaintColor & color ) void UiWindowWin::drawLine( const Point2d & start, const Point2d & end, const PaintColor & color ) { - _lines.emplace_back( start, end, color ); + _line.emplace_back( start, end, color ); _display(); } void UiWindowWin::drawEllipse( const Point2d & center, double xRadius, double yRadius, const PaintColor & color ) { - const Point topLeft( center.x - xRadius, center.y - yRadius ); - _ellipses.emplace_back( topLeft, xRadius * 2, yRadius * 2, color ); + _ellipse.emplace_back( center.x - xRadius, center.y - yRadius, center.x + xRadius, center.y + yRadius, color ); _display(); } @@ -288,10 +287,10 @@ void UiWindowWin::drawRectangle( const Point2d & topLeftCorner, double width, do const Point2d bottomLeftCorner( topLeftCorner.x, topLeftCorner.y + height ); const Point2d bottomRightCorner( topLeftCorner.x + width, topLeftCorner.y + height ); - _lines.emplace_back( topLeftCorner, topRightCorner, color ); - _lines.emplace_back( topLeftCorner, bottomLeftCorner, color ); - _lines.emplace_back( topRightCorner, bottomRightCorner, color ); - _lines.emplace_back( bottomLeftCorner, bottomRightCorner, color ); + _line.emplace_back( topLeftCorner, topRightCorner, color ); + _line.emplace_back( topLeftCorner, bottomLeftCorner, color ); + _line.emplace_back( topRightCorner, bottomRightCorner, color ); + _line.emplace_back( bottomLeftCorner, bottomRightCorner, color ); _display(); } diff --git a/src/ui/win/win_ui.h b/src/ui/win/win_ui.h index 69977d408..2844b19b8 100644 --- a/src/ui/win/win_ui.h +++ b/src/ui/win/win_ui.h @@ -28,6 +28,54 @@ class UiWindowWin : public UiWindow HWND _window; // Windows OS window handle (just an unique ID) BITMAPINFO * _bmpInfo; // bitmap structure needed for drawing + struct PointToDraw + { + PointToDraw( const Point2d & point_ = Point2d(), const PaintColor & color_ = PaintColor() ) + : point( point_ ) + , color( color_ ) + { + } + + Point2d point; + PaintColor color; + }; + + struct LineToDraw + { + LineToDraw( const Point2d & start_ = Point2d(), const Point2d & end_ = Point2d(), const PaintColor & color_ = PaintColor() ) + : start( start_ ) + , end ( end_ ) + , color( color_ ) + { + } + + Point2d start; + Point2d end; + PaintColor color; + }; + + struct EllipseToDraw + { + EllipseToDraw( double left_ = 0, double top_ = 0, double right_ = 0, double bottom_ = 0, const PaintColor & color_ = PaintColor() ) + : left ( left_ ) + , top ( top_ ) + , right ( right_ ) + , bottom( bottom_ ) + , color ( color_ ) + { + } + + double left; + double top; + double right; + double bottom; + PaintColor color; + }; + + std::vector < PointToDraw > _point; + std::vector < LineToDraw > _line; + std::vector < EllipseToDraw > _ellipse; + friend class WindowsUi::UiWindowWinInfo; void _free(); diff --git a/src/ui/x11/x11_ui.cpp b/src/ui/x11/x11_ui.cpp index 4c9b684e7..d8df93d6a 100644 --- a/src/ui/x11/x11_ui.cpp +++ b/src/ui/x11/x11_ui.cpp @@ -51,8 +51,7 @@ void UiWindowX11::_display() for ( size_t i = 0u; i < _point.size(); ++i ) { const Point2d & point = _point[i].point; - const uint32_t foreground = UiWindowX11::_convertColor( _point[i].color ); - XSetForeground( _uiDisplay, defaultGC, foreground ); + XSetForeground( _uiDisplay, defaultGC, _point[i].color ); XDrawLine( _uiDisplay, _window, defaultGC, static_cast( point.x - 1 ), static_cast( point.y - 1 ), static_cast( point.x + 1 ), static_cast( point.y + 1 ) ); } @@ -60,7 +59,7 @@ void UiWindowX11::_display() for ( size_t i = 0u; i < _lines.size(); ++i ) { const Point2d & start = _lines[i].start; const Point2d & end = _lines[i].end; - const uint32_t foreground = UiWindowX11::_convertColor( _lines[i].color ); + const uint32_t & foreground = _lines[i].color; XSetForeground( _uiDisplay, defaultGC, foreground ); XDrawLine( _uiDisplay, _window, defaultGC, static_cast( start.x ), static_cast( start.y ), static_cast( end.x ), @@ -71,22 +70,22 @@ void UiWindowX11::_display() const Point2d & position = _ellipses[i].topLeft; const double & width = _ellipses[i].width; const double & height = _ellipses[i].height; - const uint32_t foreground = UiWindowX11::_convertColor( _ellipses[i].color ); + const uint32_t & foreground = _ellipses[i].color; XSetForeground( _uiDisplay, defaultGC, foreground ); - XDrawArc( _uiDisplay, _window, defaultGC, static_cast( position.x ), static_cast( position.y ), static_cast( width ), - static_cast( height ), 0, 360 * 64 ); + XDrawArc( _uiDisplay, _window, defaultGC, static_cast( position.x ), static_cast( position.y ), static_cast( width ), + static_cast( height ), 0, 360 * 64 ); } for ( size_t i = 0u; i < _rectangles.size(); ++i ) { const Point2d & topLeft = _rectangles[i].topLeft; const double & width = _rectangles[i].width; const double & height = _rectangles[i].height; - const uint32_t foreground = UiWindowX11::_convertColor( _rectangles[i].color ); + const uint32_t & foreground = _rectangles[i].color; XSetForeground( _uiDisplay, defaultGC, foreground ); - XDrawRectangle( _uiDisplay, _window, defaultGC, static_cast( topLeft.x ), static_cast( topLeft.y ), static_cast( width ), - static_cast( height ) ); + XDrawRectangle( _uiDisplay, _window, defaultGC, static_cast( topLeft.x ), static_cast( topLeft.y ), static_cast( width ), + static_cast( height ) ); } } else if ( (e.type == ClientMessage) && (static_cast(e.xclient.data.l[0]) == _deleteWindowEvent) ) @@ -94,11 +93,6 @@ void UiWindowX11::_display() } } -uint32_t UiWindowX11::_convertColor( const PaintColor & color ) -{ - return static_cast( ( color.red << 16 ) + ( color.green << 8 ) + color.blue ); -} - void UiWindowX11::_setupImage( const penguinV::Image & image ) { if ( image.empty() ) @@ -147,12 +141,12 @@ void UiWindowX11::_setupImage( const penguinV::Image & image ) void UiWindowX11::drawPoint( const Point2d & point, const PaintColor & color ) { - _point.push_back( PointToDraw( point, color ) ); + _point.push_back( PointToDraw( point, ( color.red << 16 ) + ( color.green << 8 ) + color.blue ) ); } void UiWindowX11::drawLine( const Point2d & start, const Point2d & end, const PaintColor & color ) { - _lines.push_back( LineToDraw( start, end, color ) ); + _lines.push_back( LineToDraw( start, end, ( color.red << 16 ) + ( color.green << 8 ) + color.blue ) ); } void UiWindowX11::drawEllipse( const Point2d & center, double xRadius, double yRadius, const PaintColor & color ) @@ -160,12 +154,12 @@ void UiWindowX11::drawEllipse( const Point2d & center, double xRadius, double yR // XDrawArc needs x and y coordinates of the upper-left corner of the bounding rectangle but not the center of the ellipse. const Point2d position( center.x - xRadius, center.y - yRadius ); - _ellipses.push_back( EllipseToDraw( position, xRadius * 2, yRadius * 2, color ) ); + _ellipses.push_back( EllipseToDraw( position, xRadius * 2, yRadius * 2, ( color.red << 16 ) + ( color.green << 8 ) + color.blue ) ); } void UiWindowX11::drawRectangle( const Point2d & topLeftCorner, double width, double height, const PaintColor & color ) { - _rectangles.push_back( RectangleToDraw( topLeftCorner, width, height, color ) ); + _rectangles.push_back( RectangleToDraw( topLeftCorner, width, height, ( color.red << 16 ) + ( color.green << 8 ) + color.blue ) ); } #endif diff --git a/src/ui/x11/x11_ui.h b/src/ui/x11/x11_ui.h index fb949bfea..4c1eed4be 100644 --- a/src/ui/x11/x11_ui.h +++ b/src/ui/x11/x11_ui.h @@ -30,9 +30,48 @@ class UiWindowX11 : public UiWindow uint32_t _width; uint32_t _height; + struct PointToDraw + { + PointToDraw( const Point2d & point_ = Point2d(), uint32_t color_ = 0 ) + : point( point_ ) + , color( color_ ) + {} + + Point2d point; + uint32_t color; + }; + + struct LineToDraw + { + LineToDraw( const Point2d & start_ = Point2d(), const Point2d & end_ = Point2d(), uint32_t color_ = 0 ) + : start( start_ ) + , end( end_ ) + , color( color_ ) + {} + + Point2d start; + Point2d end; + uint32_t color; + }; + + struct EllipseToDraw + { + EllipseToDraw( const Point2d & topLeft_ = Point2d(), double width_ = 0.0, double height_ = 0.0, uint32_t color_ = 0 ) + : topLeft( topLeft_ ) + , width( width_ ) + , height( height_ ) + , color( color_ ) + {} + + Point2d topLeft; + double width; + double height; + uint32_t color; + }; + struct RectangleToDraw { - RectangleToDraw( const Point2d & topLeft_ = Point2d(), double width_ = 0.0, double height_ = 0.0, const PaintColor & color_ = PaintColor() ) + RectangleToDraw( const Point2d & topLeft_ = Point2d(), double width_ = 0.0, double height_ = 0.0, uint32_t color_ = 0 ) : topLeft( topLeft_ ) , width( width_ ) , height( height_ ) @@ -42,13 +81,15 @@ class UiWindowX11 : public UiWindow Point2d topLeft; double width; double height; - PaintColor color; + uint32_t color; }; + std::vector _point; + std::vector _lines; + std::vector _ellipses; std::vector _rectangles; void _setupImage( const penguinV::Image & image ); - static uint32_t _convertColor( const PaintColor & color = PaintColor() ); }; #endif