Skip to content

Commit

Permalink
Code clean up.
Browse files Browse the repository at this point in the history
  • Loading branch information
fullset committed Nov 21, 2019
1 parent 192cd2f commit f677654
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 22 deletions.
38 changes: 20 additions & 18 deletions src/ui/x11/x11_ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<int>(point.x - 1), static_cast<int>(point.y - 1),
static_cast<int>(point.x + 1), static_cast<int>(point.y + 1) );
XDrawLine( _uiDisplay, _window, defaultGC, static_cast<int>(point.x - 1), static_cast<int>(point.y + 1),
static_cast<int>(point.x + 1), static_cast<int>(point.y - 1) );
XDrawLine( _uiDisplay, _window, defaultGC, static_cast<int>( point.x - 1 ), static_cast<int>( point.y - 1 ), static_cast<int>( point.x + 1 ),
static_cast<int>( point.y + 1 ) );
XDrawLine( _uiDisplay, _window, defaultGC, static_cast<int>( point.x - 1 ), static_cast<int>( point.y + 1 ), static_cast<int>( point.x + 1 ),
static_cast<int>( 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<int>(start.x), static_cast<int>(start.y),
static_cast<int>(end.x), static_cast<int>(end.y) );
XDrawLine( _uiDisplay, _window, defaultGC, static_cast<int>( start.x ), static_cast<int>( start.y ), static_cast<int>( end.x ),
static_cast<int>( end.y ) );
}

for ( size_t i = 0u; i < _ellipses.size(); ++i ) {
Expand All @@ -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<int>( position.x ), static_cast<int>( position.y ), static_cast<int>( width ),
static_cast<int>( 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<int>( topLeftCorner.x ), static_cast<int>( topLeftCorner.y ), static_cast<int>( width ),
static_cast<int>( height ) );
}
}
else if ( (e.type == ClientMessage) && (static_cast<unsigned int>(e.xclient.data.l[0]) == _deleteWindowEvent) )
Expand Down Expand Up @@ -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
9 changes: 5 additions & 4 deletions src/ui/x11/x11_ui.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -30,10 +31,10 @@ class UiWindowX11 : public UiWindow
uint32_t _width;
uint32_t _height;

std::vector< std::pair<Point2d, uint32_t> > _point;
std::vector< std::tuple<Point2d, Point2d, uint32_t> > _lines;
std::vector< std::tuple<Point2d, double, double, uint32_t> > _ellipses;
std::vector< std::tuple<Point2d, double, double, uint32_t> > _rectangles;
std::vector<std::pair<Point2d, uint32_t>> _point;
std::vector<std::tuple<Point2d, Point2d, uint32_t>> _lines;
std::vector<std::tuple<Point2d, double, double, uint32_t>> _ellipses;
std::vector<std::tuple<Point2d, double, double, uint32_t>> _rectangles;

void _setupImage( const PenguinV_Image::Image & image );
};
Expand Down

0 comments on commit f677654

Please sign in to comment.