diff --git a/src/ui/x11/x11_ui.cpp b/src/ui/x11/x11_ui.cpp index 6bac2563b..d8df93d6a 100644 --- a/src/ui/x11/x11_ui.cpp +++ b/src/ui/x11/x11_ui.cpp @@ -50,10 +50,42 @@ 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 ); - XDrawLine( _uiDisplay, _window, defaultGC, static_cast(point.x - 1), static_cast(point.y - 1), - static_cast(point.x + 1), static_cast(point.y + 1) ); + 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 = _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 ), + static_cast( end.y ) ); + } + + for ( size_t i = 0u; i < _ellipses.size(); ++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 ), + 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; + + XSetForeground( _uiDisplay, defaultGC, foreground ); + 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) ) @@ -109,7 +141,25 @@ 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( LineToDraw( 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. + 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 ) ); +} + +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 ) ); } #endif diff --git a/src/ui/x11/x11_ui.h b/src/ui/x11/x11_ui.h index d088d5451..4c1eed4be 100644 --- a/src/ui/x11/x11_ui.h +++ b/src/ui/x11/x11_ui.h @@ -14,6 +14,10 @@ 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 ); + 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: @@ -26,7 +30,64 @@ class UiWindowX11 : public UiWindow uint32_t _width; uint32_t _height; - std::vector< std::pair > _point; + 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 _point; + std::vector _lines; + std::vector _ellipses; + std::vector _rectangles; void _setupImage( const penguinV::Image & image ); };