void Route::RenderSegment( ocpnDC& dc, int xa, int ya, int xb, int yb, ViewPort &VP, bool bdraw_arrow, int hilite_width ) { // Get the dc boundary int sx, sy; dc.GetSize( &sx, &sy ); // Try to exit early if the segment is nowhere near the screen wxRect r( 0, 0, sx, sy ); wxRect s( xa, ya, 1, 1 ); wxRect t( xb, yb, 1, 1 ); s.Union( t ); if( !r.Intersects( s ) ) return; // Clip the line segment to the dc boundary int x0 = xa; int y0 = ya; int x1 = xb; int y1 = yb; // If hilite is desired, use a Native Graphics context to render alpha colours // That is, if wxGraphicsContext is available..... if( hilite_width ) { if( Visible == cohen_sutherland_line_clip_i( &x0, &y0, &x1, &y1, 0, sx, 0, sy ) ) { wxPen psave = dc.GetPen(); wxColour y = GetGlobalColor( _T ( "YELO1" ) ); wxColour hilt( y.Red(), y.Green(), y.Blue(), 128 ); wxPen HiPen( hilt, hilite_width, wxSOLID ); dc.SetPen( HiPen ); dc.StrokeLine( x0, y0, x1, y1 ); dc.SetPen( psave ); dc.StrokeLine( x0, y0, x1, y1 ); } } else { if( Visible == cohen_sutherland_line_clip_i( &x0, &y0, &x1, &y1, 0, sx, 0, sy ) ) dc.StrokeLine( x0, y0, x1, y1 ); } if( bdraw_arrow ) { // Draw a direction arrow double theta = atan2( (double) ( yb - ya ), (double) ( xb - xa ) ); theta -= PI / 2; wxPoint icon[10]; double icon_scale_factor = 100 * VP.view_scale_ppm; icon_scale_factor = fmin ( icon_scale_factor, 1.5 ); // Sets the max size icon_scale_factor = fmax ( icon_scale_factor, .10 ); // Get the absolute line length // and constrain the arrow to be no more than xx% of the line length double nom_arrow_size = 20.; double max_arrow_to_leg = .20; double lpp = sqrt( pow( (double) ( xa - xb ), 2 ) + pow( (double) ( ya - yb ), 2 ) ); double icon_size = icon_scale_factor * nom_arrow_size; if( icon_size > ( lpp * max_arrow_to_leg ) ) icon_scale_factor = ( lpp * max_arrow_to_leg ) / nom_arrow_size; for( int i = 0; i < 7; i++ ) { int j = i * 2; double pxa = (double) ( s_arrow_icon[j] ); double pya = (double) ( s_arrow_icon[j + 1] ); pya *= icon_scale_factor; pxa *= icon_scale_factor; double px = ( pxa * sin( theta ) ) + ( pya * cos( theta ) ); double py = ( pya * sin( theta ) ) - ( pxa * cos( theta ) ); icon[i].x = (int) ( px ) + xb; icon[i].y = (int) ( py ) + yb; } wxPen savePen = dc.GetPen(); dc.SetPen( *wxTRANSPARENT_PEN ); dc.StrokePolygon( 6, &icon[0], 0, 0 ); dc.SetPen( savePen ); } }
void Route::DrawGLRouteLines( ViewPort &vp ) { #ifdef ocpnUSE_GL // Hiliting first // Being special case to draw something for a 1 point route.... ocpnDC dc; if(m_hiliteWidth) { wxColour y = GetGlobalColor( _T ( "YELO1" ) ); wxColour hilt( y.Red(), y.Green(), y.Blue(), 128 ); wxPen HiPen( hilt, m_hiliteWidth, wxPENSTYLE_SOLID ); ocpnDC dc; dc.SetPen( HiPen ); DrawGLLines(vp, &dc); } /* determine color and width */ wxColour col; int width = g_pRouteMan->GetRoutePen()->GetWidth(); //g_route_line_width; if( m_width != wxPENSTYLE_INVALID ) width = m_width; if( m_bRtIsActive ) { col = g_pRouteMan->GetActiveRoutePen()->GetColour(); } else if( m_bRtIsSelected ) { col = g_pRouteMan->GetSelectedRoutePen()->GetColour(); } else { if( m_Colour == wxEmptyString ) { col = g_pRouteMan->GetRoutePen()->GetColour(); } else { for( unsigned int i = 0; i < sizeof( ::GpxxColorNames ) / sizeof(wxString); i++ ) { if( m_Colour == ::GpxxColorNames[i] ) { col = ::GpxxColors[i]; break; } } } } wxPenStyle style = wxPENSTYLE_SOLID; if( m_style != wxPENSTYLE_INVALID ) style = m_style; dc.SetPen( *wxThePenList->FindOrCreatePen( col, width, style ) ); glColor3ub(col.Red(), col.Green(), col.Blue()); glLineWidth( wxMax( g_GLMinSymbolLineWidth, width ) ); dc.SetGLStipple(); DrawGLLines(vp, NULL); glDisable (GL_LINE_STIPPLE); /* direction arrows.. could probably be further optimized for opengl */ wxRoutePointListNode *node = pRoutePointList->GetFirst(); wxPoint rpt1, rpt2; while(node) { RoutePoint *prp = node->GetData(); cc1->GetCanvasPointPix( prp->m_lat, prp->m_lon, &rpt2 ); if(node != pRoutePointList->GetFirst()) RenderSegmentArrowsGL( rpt1.x, rpt1.y, rpt2.x, rpt2.y, vp ); rpt1 = rpt2; node = node->GetNext(); } #endif }
void Track::Draw( ocpnDC& dc, ViewPort &VP, const LLBBox &box ) { std::list< std::list<wxPoint> > pointlists; GetPointLists(pointlists, VP, box); if(!pointlists.size()) return; unsigned short int FromSegNo = 1; // Establish basic colour wxColour basic_colour; if( IsRunning() ) basic_colour = GetGlobalColor( _T ( "URED" ) ); else basic_colour = GetDimColor(g_colourTrackLineColour); wxPenStyle style = wxPENSTYLE_SOLID; int width = g_pRouteMan->GetTrackPen()->GetWidth(); wxColour col; if( m_style != wxPENSTYLE_INVALID ) style = m_style; if( m_width != WIDTH_UNDEFINED ) width = m_width; if( m_Colour == wxEmptyString ) { col = basic_colour; } else { for( unsigned int i = 0; i < sizeof( ::GpxxColorNames ) / sizeof(wxString); i++ ) { if( m_Colour == ::GpxxColorNames[i] ) { col = ::GpxxColors[i]; break; } } } double radius = 0.; if( g_bHighliteTracks ) { double radius_meters = 20; //Current_Ch->GetNativeScale() * .0015; // 1.5 mm at original scale radius = radius_meters * VP.view_scale_ppm; if(radius < 1.0) radius = 0; } if( dc.GetDC() || radius ) { dc.SetPen( *wxThePenList->FindOrCreatePen( col, width, style ) ); dc.SetBrush( *wxTheBrushList->FindOrCreateBrush( col, wxBRUSHSTYLE_SOLID ) ); for(std::list< std::list<wxPoint> >::iterator lines = pointlists.begin(); lines != pointlists.end(); lines++) { // convert from linked list to array wxPoint *points = new wxPoint[lines->size()]; int i = 0; for(std::list<wxPoint>::iterator line = lines->begin(); line != lines->end(); line++) { points[i] = *line; i++; } int hilite_width = radius; if( hilite_width ) { wxPen psave = dc.GetPen(); dc.StrokeLines( i, points ); wxColor trackLine_dim_colour = GetDimColor(g_colourTrackLineColour); wxColour hilt( trackLine_dim_colour.Red(), trackLine_dim_colour.Green(), trackLine_dim_colour.Blue(), 128 ); wxPen HiPen( hilt, hilite_width, wxPENSTYLE_SOLID ); dc.SetPen( HiPen ); dc.StrokeLines( i, points ); dc.SetPen( psave ); } else dc.StrokeLines( i, points ); delete [] points; } } #ifdef ocpnUSE_GL else { // opengl version glColor3ub(col.Red(), col.Green(), col.Blue()); glLineWidth( wxMax( g_GLMinSymbolLineWidth, width ) ); if( g_GLOptions.m_GLLineSmoothing ) glEnable( GL_LINE_SMOOTH ); glEnable( GL_BLEND ); int size = 0; // convert from linked list to array, allocate array just once for(std::list< std::list<wxPoint> >::iterator lines = pointlists.begin(); lines != pointlists.end(); lines++) size = wxMax(size, lines->size()); int *points = new int[2*size]; glVertexPointer(2, GL_INT, 0, points); glEnableClientState(GL_VERTEX_ARRAY); for(std::list< std::list<wxPoint> >::iterator lines = pointlists.begin(); lines != pointlists.end(); lines++) { // convert from linked list to array int i = 0; for(std::list<wxPoint>::iterator line = lines->begin(); line != lines->end(); line++) { points[i+0] = line->x; points[i+1] = line->y; i+=2; } glDrawArrays(GL_LINE_STRIP, 0, i >> 1); } glDisableClientState(GL_VERTEX_ARRAY); delete [] points; glDisable( GL_LINE_SMOOTH ); glDisable( GL_BLEND ); } #endif if(m_HighlightedTrackPoint >= 0) TrackPoints[m_HighlightedTrackPoint]->Draw(dc); }
void Route::DrawGL( ViewPort &VP, OCPNRegion ®ion ) { #ifdef ocpnUSE_GL if( m_nPoints < 1 || !m_bVisible ) return; if(m_hiliteWidth) { wxColour y = GetGlobalColor( _T ( "YELO1" ) ); wxColour hilt( y.Red(), y.Green(), y.Blue(), 128 ); wxPen HiPen( hilt, m_hiliteWidth, wxPENSTYLE_SOLID ); ocpnDC dc; dc.SetPen( HiPen ); DrawGLLines(VP, &dc); } /* determine color and width */ wxColour col; int width = g_pRouteMan->GetRoutePen()->GetWidth(); //g_route_line_width; if( m_width != wxPENSTYLE_INVALID ) width = m_width; if(m_bIsTrack) width = g_pRouteMan->GetTrackPen()->GetWidth(); if( m_bRtIsActive ) { col = g_pRouteMan->GetActiveRoutePen()->GetColour(); } else if( m_bRtIsSelected ) { col = g_pRouteMan->GetSelectedRoutePen()->GetColour(); } else { if( m_Colour == wxEmptyString ) { col = g_pRouteMan->GetRoutePen()->GetColour(); // For tracks, establish colour based on first icon name if(m_bIsTrack){ wxRoutePointListNode *node = pRoutePointList->GetFirst(); RoutePoint *prp = node->GetData(); if( prp->GetIconName().StartsWith( _T("xmred") ) ) col = GetGlobalColor( _T ( "URED" ) ); else if( prp->GetIconName().StartsWith( _T("xmblue") ) ) col = GetGlobalColor( _T ( "BLUE3" ) ); else if( prp->GetIconName().StartsWith( _T("xmgreen") ) ) col = GetGlobalColor( _T ( "UGREN" ) ); else col = GetGlobalColor( _T ( "CHMGD" ) ); } } else { for( unsigned int i = 0; i < sizeof( ::GpxxColorNames ) / sizeof(wxString); i++ ) { if( m_Colour == ::GpxxColorNames[i] ) { col = ::GpxxColors[i]; break; } } } } glColor3ub(col.Red(), col.Green(), col.Blue()); glLineWidth(wxMax( g_GLMinSymbolLineWidth, width )); #ifndef ocpnUSE_GLES // linestipple is emulated poorly if( m_style != wxPENSTYLE_INVALID ) glEnable( GL_LINE_STIPPLE ); switch( m_style ) { case wxDOT: glLineStipple( 1, 0x3333 ); break; case wxLONG_DASH: glLineStipple( 1, 0xFFF8 ); break; case wxSHORT_DASH: glLineStipple( 1, 0x3F3F ); break; case wxDOT_DASH: glLineStipple( 1, 0x8FF1 ); break; default: break; } #endif DrawGLLines(VP, NULL); glDisable (GL_LINE_STIPPLE); /* direction arrows.. could probably be further optimized for opengl */ if( !m_bIsTrack ) { wxRoutePointListNode *node = pRoutePointList->GetFirst(); wxPoint2DDouble rpt1, rpt2; while(node) { RoutePoint *prp = node->GetData(); // cc1->GetDoubleCanvasPointPix( prp->m_lat, prp->m_lon, &rpt2 ); rpt2 = prp->m_screen_pos; if(node != pRoutePointList->GetFirst() && prp->m_pos_on_screen) RenderSegmentArrowsGL( rpt1.m_x, rpt1.m_y, rpt2.m_x, rpt2.m_y, cc1->GetVP() ); rpt1 = rpt2; node = node->GetNext(); } } /* Route points */ for(wxRoutePointListNode *node = pRoutePointList->GetFirst(); node; node = node->GetNext()) { RoutePoint *prp = node->GetData(); if ( m_bVisible || prp->m_bKeepXRoute ) prp->DrawGL( VP, region, true ); } #endif }
void Route::DrawGL( ViewPort &VP ) { #ifdef ocpnUSE_GL if( m_nPoints < 1 || !m_bVisible ) return; // Hiliting first // Being special case to draw something for a 1 point route.... ocpnDC dc; if(m_hiliteWidth) { wxColour y = GetGlobalColor( _T ( "YELO1" ) ); wxColour hilt( y.Red(), y.Green(), y.Blue(), 128 ); wxPen HiPen( hilt, m_hiliteWidth, wxPENSTYLE_SOLID ); ocpnDC dc; dc.SetPen( HiPen ); wxRoutePointListNode *node = pRoutePointList->GetFirst(); RoutePoint *prp0 = node->GetData(); wxPoint r0; bool r0valid = cc1->GetCanvasPointPix( prp0->m_lat, prp0->m_lon, &r0); int lines = 0; node = node->GetNext(); while( node ) { RoutePoint *prp = node->GetData(); wxPoint r1; bool r1valid = cc1->GetCanvasPointPix( prp->m_lat, prp->m_lon, &r1); if(r0valid && r1valid) { dc.StrokeLine( r0.x, r0.y, r1.x, r1.y ); lines++; } r0valid = r1valid; r0 = r1; node = node->GetNext(); } if(lines == 0 && cc1->GetCanvasPointPix( prp0->m_lat, prp0->m_lon, &r0)) { dc.StrokeLine( r0.x, r0.y, r0.x + 2, r0.y + 2 ); return; } } // if( m_nPoints < 2 ) // return; /* determine color and width */ wxColour col; int width = g_pRouteMan->GetRoutePen()->GetWidth(); //g_route_line_width; if( m_width != wxPENSTYLE_INVALID ) width = m_width; if(m_bIsTrack) width = g_pRouteMan->GetTrackPen()->GetWidth(); if( m_bRtIsActive ) { col = g_pRouteMan->GetActiveRoutePen()->GetColour(); } else if( m_bRtIsSelected ) { col = g_pRouteMan->GetSelectedRoutePen()->GetColour(); } else { if( m_Colour == wxEmptyString ) { col = g_pRouteMan->GetRoutePen()->GetColour(); // For tracks, establish colour based on first icon name if(m_bIsTrack) { wxRoutePointListNode *node = pRoutePointList->GetFirst(); RoutePoint *prp = node->GetData(); if( prp->GetIconName().StartsWith( _T("xmred") ) ) col = GetGlobalColor( _T ( "URED" ) ); else if( prp->GetIconName().StartsWith( _T("xmblue") ) ) col = GetGlobalColor( _T ( "BLUE3" ) ); else if( prp->GetIconName().StartsWith( _T("xmgreen") ) ) col = GetGlobalColor( _T ( "UGREN" ) ); else col = GetGlobalColor( _T ( "CHMGD" ) ); } } else { for( unsigned int i = 0; i < sizeof( ::GpxxColorNames ) / sizeof(wxString); i++ ) { if( m_Colour == ::GpxxColorNames[i] ) { col = ::GpxxColors[i]; break; } } } } int style = wxSOLID; if( m_style != wxPENSTYLE_INVALID ) style = m_style; dc.SetPen( *wxThePenList->FindOrCreatePen( col, width, style ) ); glColor3ub(col.Red(), col.Green(), col.Blue()); glLineWidth( wxMax( g_GLMinSymbolLineWidth, width ) ); dc.SetGLStipple(); glBegin(GL_LINE_STRIP); float lastlon = 0; float lastlat = 0; unsigned short int FromSegNo = 1; for(wxRoutePointListNode *node = pRoutePointList->GetFirst(); node; node = node->GetNext()) { RoutePoint *prp = node->GetData(); unsigned short int ToSegNo = prp->m_GPXTrkSegNo; /* crosses IDL? if so break up into two segments */ int dir = 0; if(prp->m_lon > 150 && lastlon < -150) dir = -1; else if(prp->m_lon < -150 && lastlon > 150) dir = 1; wxPoint r; if (FromSegNo != ToSegNo) { glEnd(); FromSegNo = ToSegNo; glBegin(GL_LINE_STRIP); } if(dir) { double crosslat = lat_rl_crosses_meridian(lastlat, lastlon, prp->m_lat, prp->m_lon, 180.0); if(cc1->GetCanvasPointPix( crosslat, dir*180, &r)) glVertex2i(r.x, r.y); glEnd(); glBegin(GL_LINE_STRIP); if(cc1->GetCanvasPointPix( crosslat, -dir*180, &r)) glVertex2i(r.x, r.y); } lastlat=prp->m_lat; lastlon=prp->m_lon; if(cc1->GetCanvasPointPix( prp->m_lat, prp->m_lon, &r)) glVertex2i(r.x, r.y); else { glEnd(); glBegin(GL_LINE_STRIP); } } glEnd(); glDisable (GL_LINE_STIPPLE); /* direction arrows.. could probably be further optimized for opengl */ if( !m_bIsTrack ) { wxRoutePointListNode *node = pRoutePointList->GetFirst(); wxPoint rpt1, rpt2; while(node) { RoutePoint *prp = node->GetData(); cc1->GetCanvasPointPix( prp->m_lat, prp->m_lon, &rpt2 ); if(node != pRoutePointList->GetFirst()) RenderSegmentArrowsGL( rpt1.x, rpt1.y, rpt2.x, rpt2.y, cc1->GetVP() ); rpt1 = rpt2; node = node->GetNext(); } } /* Route points */ for(wxRoutePointListNode *node = pRoutePointList->GetFirst(); node; node = node->GetNext()) { RoutePoint *prp = node->GetData(); if ( !m_bVisible && prp->m_bKeepXRoute ) prp->DrawGL( VP ); else if (m_bVisible) prp->DrawGL( VP ); } #endif }