void ODPoint::DrawGL( PlugIn_ViewPort &pivp ) { if( !m_bIsVisible ) return; // Optimization, especially apparent on tracks in normal cases if( m_IconName == _T("empty") && !m_bShowName && !m_bPtIsSelected ) return; if(m_wpBBox.GetValid() && pivp.chart_scale == m_wpBBox_chart_scale && pivp.rotation == m_wpBBox_rotation) { } wxPoint r; wxRect hilitebox; unsigned char transparency = 150; GetCanvasPixLL( &g_VP, &r, m_lat, m_lon ); // Substitue icon? wxBitmap *pbm; if( ( m_bIsActive ) && ( m_IconName != _T("mob") ) ) pbm = g_pODPointMan->GetIconBitmap( _T ( "activepoint" ) ); else pbm = m_pbmIcon; int sx2 = pbm->GetWidth() / 2; int sy2 = pbm->GetHeight() / 2; // Calculate the mark drawing extents wxRect r1( r.x - sx2, r.y - sy2, sx2 * 2, sy2 * 2 ); // the bitmap extents float l_fIconScaleFactor = GetOCPNChartScaleFactor_Plugin(); wxRect r3 = r1; if( m_bShowName ) { if( !m_pMarkFont ) { m_pMarkFont = GetOCPNScaledFont_PlugIn( wxT( "Marks" ) ); m_FontColor = GetFontColour_PlugIn( wxS( "Marks" ) ); CalculateNameExtents(); } if( m_pMarkFont ) { wxRect r2( r.x + (m_NameLocationOffsetX * l_fIconScaleFactor), r.y + (m_NameLocationOffsetY * l_fIconScaleFactor), m_NameExtents.x, m_NameExtents.y ); r3.Union( r2 ); } } hilitebox = r3; hilitebox.x -= r.x; hilitebox.y -= r.y; float radius; if( IsTouchInterface_PlugIn() ){ hilitebox.Inflate( 20 ); radius = 20.0f; } else{ hilitebox.Inflate( 4 ); radius = 4.0f; } /* update bounding box */ if(!m_wpBBox.GetValid() || pivp.chart_scale != m_wpBBox_chart_scale || pivp.rotation != m_wpBBox_rotation) { double lat1, lon1, lat2, lon2; wxPoint wxpoint; wxpoint.x = r.x+hilitebox.x; wxpoint.y = r.y + hilitebox.height; GetCanvasLLPix( &pivp, wxpoint, &lat1, &lon1 ); wxpoint.x = r.x + hilitebox.x + hilitebox.width; wxpoint.y = r.y + hilitebox.y; GetCanvasLLPix( &pivp, wxpoint, &lat2, &lon2 ); if(lon1 > lon2) m_wpBBox.Set(lat1, lon1, lat2, lon2+360); else m_wpBBox.Set(lat1, lon1, lat2, lon2); m_wpBBox_chart_scale = pivp.chart_scale; m_wpBBox_rotation = pivp.rotation; } ODDC dc; // Highlite any selected point if( m_bPtIsSelected || m_bIsBeingEdited ) { wxColour hi_colour; if( m_bPointPropertiesBlink || m_bPathManagerBlink ){ wxPen *pen = g_pPathMan->GetActiveODPointPen(); hi_colour = pen->GetColour(); } else{ GetGlobalColor( wxS( "YELO1" ), &hi_colour ); } g_ocpn_draw_pi->AlphaBlending( dc, r.x + hilitebox.x, r.y + hilitebox.y, hilitebox.width, hilitebox.height, radius, hi_colour, transparency ); } bool bDrawHL = false; if( (m_bPointPropertiesBlink || m_bPathManagerBlink) && ( g_ocpn_draw_pi->nBlinkerTick & 1 ) ) bDrawHL = true; if( ( !bDrawHL ) && ( NULL != m_pbmIcon ) ) { int glw, glh; unsigned int IconTexture = g_pODPointMan->GetIconTexture( pbm, glw, glh ); glBindTexture(GL_TEXTURE_2D, IconTexture); glEnable(GL_TEXTURE_2D); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE ); glColor3f(1, 1, 1); float l_ChartScaleFactorExp = GetOCPNChartScaleFactor_Plugin(); float w = r1.width * l_ChartScaleFactorExp; float h = r1.height * l_ChartScaleFactorExp; float x = r.x - w/2; float y = r.y - h/2; float u = (float)r1.width/glw, v = (float)r1.height/glh; glBegin(GL_QUADS); glTexCoord2f(0, 0); glVertex2f(x, y); glTexCoord2f(u, 0); glVertex2f(x+w, y); glTexCoord2f(u, v); glVertex2f(x+w, y+h); glTexCoord2f(0, v); glVertex2f(x, y+h); glEnd(); glDisable(GL_BLEND); glDisable(GL_TEXTURE_2D); } if( m_bShowName && m_pMarkFont ) { int w = m_NameExtents.x, h = m_NameExtents.y; if(!m_iTextTexture && w && h) { wxBitmap tbm(w, h); /* render text on dc */ wxMemoryDC dc; dc.SelectObject( tbm ); dc.SetBackground( wxBrush( *wxBLACK ) ); dc.Clear(); dc.SetFont( *m_pMarkFont ); dc.SetTextForeground( *wxWHITE ); dc.DrawText( m_ODPointName, 0, 0); dc.SelectObject( wxNullBitmap ); /* make alpha texture for text */ wxImage image = tbm.ConvertToImage(); unsigned char *d = image.GetData(); unsigned char *e = new unsigned char[w * h]; if(d && e){ for( int p = 0; p < w*h; p++) e[p] = d[3*p + 0]; } /* create texture for rendered text */ glGenTextures(1, &m_iTextTexture); glBindTexture(GL_TEXTURE_2D, m_iTextTexture); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST ); m_iTextTextureWidth = NextPow2(w); m_iTextTextureHeight = NextPow2(h); glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, m_iTextTextureWidth, m_iTextTextureHeight, 0, GL_ALPHA, GL_UNSIGNED_BYTE, NULL); glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, w, h, GL_ALPHA, GL_UNSIGNED_BYTE, e); delete [] e; } if(m_iTextTexture) { /* draw texture with text */ glBindTexture(GL_TEXTURE_2D, m_iTextTexture); glEnable(GL_TEXTURE_2D); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glColor3ub(m_FontColor.Red(), m_FontColor.Green(), m_FontColor.Blue()); int x = r.x + (m_NameLocationOffsetX * l_fIconScaleFactor), y = r.y + (m_NameLocationOffsetY * l_fIconScaleFactor); float u = (float)w/m_iTextTextureWidth, v = (float)h/m_iTextTextureHeight; glBegin(GL_QUADS); glTexCoord2f(0, 0); glVertex2f(x, y); glTexCoord2f(u, 0); glVertex2f(x+w, y); glTexCoord2f(u, v); glVertex2f(x+w, y+h); glTexCoord2f(0, v); glVertex2f(x, y+h); glEnd(); glDisable(GL_BLEND); glDisable(GL_TEXTURE_2D); } } // Draw ODPoint range rings if activated if( m_iODPointRangeRingsNumber && m_bShowODPointRangeRings ) { double factor = 1.00; if( m_iODPointRangeRingsStepUnits == 1 ) // nautical miles factor = 1 / 1.852; factor *= m_fODPointRangeRingsStep; double tlat, tlon; wxPoint r1; ll_gc_ll( m_lat, m_lon, 0, factor, &tlat, &tlon ); GetCanvasPixLL( &g_VP, &r1, tlat, tlon); double lpp = sqrt( pow( (double) (r.x - r1.x), 2) + pow( (double) (r.y - r1.y), 2 ) ); int pix_radius = (int) lpp; wxPen ppPen1( m_wxcODPointRangeRingsSchemeColour, m_iRangeRingWidth, m_iRangeRingStyle ); wxBrush saveBrush = dc.GetBrush(); wxPen savePen = dc.GetPen(); dc.SetPen( ppPen1 ); dc.SetBrush( wxBrush( m_wxcODPointRangeRingsSchemeColour, wxBRUSHSTYLE_TRANSPARENT ) ); dc.SetGLStipple(); for( int i = 1; i <= m_iODPointRangeRingsNumber; i++ ) dc.StrokeCircle( r.x, r.y, i * pix_radius ); glDisable( GL_LINE_STIPPLE ); dc.SetPen( savePen ); dc.SetBrush( saveBrush ); } if( m_bPointPropertiesBlink || m_bPathManagerBlink ) g_blink_rect = CurrentRect_in_DC; // also save for global blinker // This will be useful for fast icon redraws CurrentRect_in_DC.x = r.x + hilitebox.x; CurrentRect_in_DC.y = r.y + hilitebox.y; CurrentRect_in_DC.width = hilitebox.width; CurrentRect_in_DC.height = hilitebox.height; if( m_bPointPropertiesBlink || m_bPathManagerBlink ) g_blink_rect = CurrentRect_in_DC; // also save for global blinker }
void ODPoint::Draw( ODDC& dc, wxPoint *rpn ) { wxPoint r; wxRect hilitebox; GetCanvasPixLL( &g_VP, &r, m_lat, m_lon); // return the home point in this dc to allow "connect the dots" if( NULL != rpn ) *rpn = r; if( !m_bIsVisible /*&& !m_bIsInTrack*/) // pjotrc 2010.02.13, 2011.02.24 return; // Optimization, especially apparent on tracks in normal cases if( m_IconName == _T("empty") && !m_bShowName && !m_bPtIsSelected ) return; wxPen *pen; if( m_bPointPropertiesBlink || m_bPathManagerBlink ) pen = g_pPathMan->GetActiveODPointPen(); else pen = g_pPathMan->GetODPointPen(); // Substitue icon? wxBitmap *pbm; if( ( m_bIsActive ) && ( m_IconName != _T("mob") ) ) pbm = g_pODPointMan->GetIconBitmap( _T ( "activepoint" ) ); else pbm = m_pbmIcon; float l_ChartScaleFactorExp = GetOCPNChartScaleFactor_Plugin(); if(m_fIconScaleFactor != l_ChartScaleFactorExp) { m_fIconScaleFactor = l_ChartScaleFactorExp; if(m_fIconScaleFactor != 0) { wxImage scaled_image = pbm->ConvertToImage(); int new_width = pbm->GetWidth() * m_fIconScaleFactor; int new_height = pbm->GetHeight() * m_fIconScaleFactor; m_ScaledBMP = wxBitmap(scaled_image.Scale(new_width, new_height, wxIMAGE_QUALITY_HIGH)); } } if( m_fIconScaleFactor != 0 && m_ScaledBMP.IsOk() ) pbm = &m_ScaledBMP; int sx2 = pbm->GetWidth() / 2; int sy2 = pbm->GetHeight() / 2; // Calculate the mark drawing extents wxRect r1( r.x - sx2, r.y - sy2, sx2 * 2, sy2 * 2 ); // the bitmap extents if( m_bShowName ) { if( 0 == m_pMarkFont ) { m_pMarkFont = GetOCPNScaledFont_PlugIn( wxS("Marks") ); m_FontColor = GetFontColour_PlugIn( wxS( "Marks" ) ); CalculateNameExtents(); } if( m_pMarkFont ) { wxRect r2( r.x + (m_NameLocationOffsetX * m_fIconScaleFactor), r.y + (m_NameLocationOffsetY * m_fIconScaleFactor), m_NameExtents.x, m_NameExtents.y ); r1.Union( r2 ); } } hilitebox = r1; hilitebox.x -= r.x; hilitebox.y -= r.y; float radius; if( IsTouchInterface_PlugIn() ){ hilitebox.Inflate( 20 ); radius = 20.0f; } else{ hilitebox.Inflate( 4 ); radius = 4.0f; } wxColour hi_colour; hi_colour = pen->GetColour(); unsigned char transparency = 100; if( m_bIsBeingEdited ){ GetGlobalColor( wxS( "YELO1" ), &hi_colour ); transparency = 150; } // Highlite any selected point if( m_bPtIsSelected || m_bIsBeingEdited ) { g_ocpn_draw_pi->AlphaBlending( dc, r.x + hilitebox.x, r.y + hilitebox.y, hilitebox.width, hilitebox.height, radius, hi_colour, transparency ); } bool bDrawHL = false; if( (m_bPointPropertiesBlink || m_bPathManagerBlink) && ( g_ocpn_draw_pi->nBlinkerTick & 1 ) ) bDrawHL = true; if( ( !bDrawHL ) && ( NULL != m_pbmIcon ) ) { dc.DrawBitmap( *pbm, r.x - sx2, r.y - sy2, true ); // on MSW, the dc Bounding box is not updated on DrawBitmap() method. // Do it explicitely here for all platforms. dc.CalcBoundingBox( r.x - sx2, r.y - sy2 ); dc.CalcBoundingBox( r.x + sx2, r.y + sy2 ); } if( m_bShowName ) { if( m_pMarkFont ) { dc.SetFont( *m_pMarkFont ); dc.SetTextForeground( m_FontColor ); dc.DrawText( m_ODPointName, r.x + (m_NameLocationOffsetX * m_fIconScaleFactor), r.y + (m_NameLocationOffsetY * m_fIconScaleFactor) ); } } // Draw ODPoint range rings if activated if( m_iODPointRangeRingsNumber && m_bShowODPointRangeRings ) { double factor = 1.00; if( m_iODPointRangeRingsStepUnits == 1 ) // nautical miles factor = 1 / 1.852; factor *= m_fODPointRangeRingsStep; double tlat, tlon; wxPoint r1; ll_gc_ll( m_lat, m_lon, 0, factor, &tlat, &tlon ); GetCanvasPixLL( &g_VP, &r1, tlat, tlon); double lpp = sqrt( pow( (double) (r.x - r1.x), 2) + pow( (double) (r.y - r1.y), 2 ) ); int pix_radius = (int) lpp; wxBrush saveBrush = dc.GetBrush(); wxPen savePen = dc.GetPen(); dc.SetPen( wxPen( m_wxcODPointRangeRingsSchemeColour, m_iRangeRingWidth, m_iRangeRingStyle ) ); dc.SetBrush( wxBrush( m_wxcODPointRangeRingsSchemeColour, wxBRUSHSTYLE_TRANSPARENT ) ); for( int i = 1; i <= m_iODPointRangeRingsNumber; i++ ) dc.StrokeCircle( r.x, r.y, i * pix_radius ); dc.SetPen( savePen ); dc.SetBrush( saveBrush ); } // Save the current draw rectangle in the current DC // This will be useful for fast icon redraws CurrentRect_in_DC.x = r.x + hilitebox.x; CurrentRect_in_DC.y = r.y + hilitebox.y; CurrentRect_in_DC.width = hilitebox.width; CurrentRect_in_DC.height = hilitebox.height; if( m_bPointPropertiesBlink || m_bPathManagerBlink ) g_blink_rect = CurrentRect_in_DC; // also save for global blinker }