void TacticsInstrument_Position::Draw(wxGCDC* dc) { wxColour cl; #ifdef __WXMSW__ wxBitmap tbm( dc->GetSize().x, m_DataHeight * 2, -1 ); wxMemoryDC tdc( tbm ); wxColour c2; GetGlobalColor( _T("DASHB"), &c2 ); tdc.SetBackground( c2 ); tdc.Clear(); tdc.SetFont(*g_pFontData ); GetGlobalColor( _T("DASHF"), &cl ); tdc.SetTextForeground( cl ); tdc.DrawText(m_data1, 10, 0); tdc.DrawText(m_data2, 10, m_DataHeight); tdc.SelectObject( wxNullBitmap ); dc->DrawBitmap(tbm, 0, m_TitleHeight, false); #else dc->SetFont(*g_pFontData ); GetGlobalColor( _T("DASHF"), &cl ); dc->SetTextForeground( cl ); dc->DrawText(m_data1, 10, m_TitleHeight); dc->DrawText(m_data2, 10, m_TitleHeight + m_DataHeight); #endif }
void about::SetColorScheme( void ) { DimeControl( this ); wxColor bg = GetBackgroundColour(); pAboutHTMLCtl->SetBackgroundColour( bg ); pLicenseHTMLCtl->SetBackgroundColour( bg ); pAuthorHTMLCtl->SetBackgroundColour( bg ); // This looks like non-sense, but is needed for __WXGTK__ // to get colours to propagate down the control's family tree. SetBackgroundColour( bg ); #ifdef __WXQT__ // wxQT has some trouble clearing the background of HTML window... wxBitmap tbm( GetSize().x, GetSize().y, -1 ); wxMemoryDC tdc( tbm ); tdc.SetBackground( bg ); tdc.Clear(); pAboutHTMLCtl->SetBackgroundImage(tbm); pLicenseHTMLCtl->SetBackgroundImage(tbm); pAuthorHTMLCtl->SetBackgroundImage(tbm); #endif }
void AISTargetAlertDialog::SetColorScheme( void ) { DimeControl( this ); wxColor bg = GetBackgroundColour(); m_pAlertTextCtl->SetBackgroundColour( bg ); SetBackgroundColour( bg ); // This looks like non-sense, but is needed for __WXGTK__ // to get colours to propagate down the control's family tree. #ifdef __WXQT__ // wxQT has some trouble clearing the background of HTML window... wxBitmap tbm( GetSize().x, GetSize().y, -1 ); wxMemoryDC tdc( tbm ); // wxColour cback = GetGlobalColor( _T("YELO1") ); tdc.SetBackground( bg ); tdc.Clear(); m_pAlertTextCtl->SetBackgroundImage(tbm); #endif }
// schedule a piece to download from a remote peer with bitmap. // 0 : success, the scheduled piece # is stored in idx // -1 : fail, no piece to download from this remote peer with bitmap int Content::Fetch_Piece(const std::string &, const Bitmap & bitmap, size_t & idx) { Trace("Content::Fetch_Piece()"); Bitmap tbm(bitmap); // //std::cout << "tbm.Nset()" << tbm.NSet() << std::endl; tbm.Except(this->bitmap_request_); // //std::cout << "tbm.Nset()" << tbm.NSet() << std::endl; if(tbm.NSet() == 0) return -1; idx = tbm.FirstSetBit(); // //std::cout << "idx " << idx << std::endl; // //std::cout << "tbm.Nset()" << tbm.NSet() << std::endl; this->bitmap_request_.Set(idx); // //std::cout << idx << std::endl; return 0; }
//public void TrackSection::cacheParts(const std::vector<sf::Uint8>& ids) { //build meshes as needed std::vector<ModelID> cached; for (auto id : ids) { auto result = std::find_if(cached.begin(), cached.end(), [id](const ModelID& mi) {return mi.id == id; }); if (result == cached.end()) { //create mesh builder for id TrackMeshBuilder tbm(id, connections); //cache mesh in mesh renderer and map to id m_meshRenderer.loadModel(id, tbm); m_uids.emplace_back(id, tbm.getFirstBarrierIndex()); cached.emplace_back(id, tbm.getFirstBarrierIndex()); } else { m_uids.emplace_back(result->id, result->barrierOffset); } } }
void RoutePoint::DrawGL( ViewPort &vp, bool use_cached_screen_coords ) { 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() && vp.view_scale_ppm == m_wpBBox_view_scale_ppm && vp.rotation == m_wpBBox_rotation) { /* see if this waypoint can intersect with bounding box */ LLBBox vpBBox = vp.GetBBox(); if( vpBBox.IntersectOut( m_wpBBox ) ){ // Are Range Rings enabled? if(m_bShowWaypointRangeRings && (m_iWaypointRangeRingsNumber > 0)){ double factor = 1.00; if( m_iWaypointRangeRingsStepUnits == 1 ) // convert kilometers to NMi factor = 1 / 1.852; double radius = factor * m_iWaypointRangeRingsNumber * m_fWaypointRangeRingsStep / 60.; LLBBox radar_box = m_wpBBox; radar_box.EnLarge(radius * 2 ); if( vpBBox.IntersectOut( radar_box ) ){ return; } } else return; } } wxPoint r; wxRect hilitebox; unsigned char transparency = 150; double platform_pen_width = wxRound(wxMax(1.0, g_Platform->GetDisplayDPmm() / 2)); // 0.5 mm nominal, but not less than 1 pixel if(use_cached_screen_coords && m_pos_on_screen) r.x = m_screen_pos.m_x, r.y = m_screen_pos.m_y; else cc1->GetCanvasPointPix( m_lat, m_lon, &r ); if(r.x == INVALID_COORD) return; // Substitute icon? wxBitmap *pbm; if( ( m_bIsActive ) && ( m_IconName != _T("mob") ) ) pbm = pWayPointMan->GetIconBitmap( _T ( "activepoint" ) ); else pbm = m_pbmIcon; // If icon is corrupt, there is really nothing else to do... if(!pbm->IsOk()) return; 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 wxRect r3 = r1; if( m_bShowName ) { if( !m_pMarkFont ) { m_pMarkFont = FontMgr::Get().GetFont( _( "Marks" ) ); m_FontColor = FontMgr::Get().GetFontColor( _( "Marks" ) ); CalculateNameExtents(); } if( m_pMarkFont ) { wxRect r2( r.x + m_NameLocationOffsetX, r.y + m_NameLocationOffsetY, m_NameExtents.x, m_NameExtents.y ); r3.Union( r2 ); } } hilitebox = r3; hilitebox.x -= r.x; hilitebox.y -= r.y; hilitebox.x *= g_ChartScaleFactorExp; hilitebox.y *= g_ChartScaleFactorExp; hilitebox.width *= g_ChartScaleFactorExp; hilitebox.height *= g_ChartScaleFactorExp; float radius; if( g_btouch ){ hilitebox.Inflate( 20 ); radius = 20.0f; } else{ hilitebox.Inflate( 4 ); radius = 4.0f; } /* update bounding box */ if(!m_wpBBox.GetValid() || vp.view_scale_ppm != m_wpBBox_view_scale_ppm || vp.rotation != m_wpBBox_rotation) { double lat1, lon1, lat2, lon2; cc1->GetCanvasPixPoint(r.x+hilitebox.x, r.y+hilitebox.y+hilitebox.height, lat1, lon1); cc1->GetCanvasPixPoint(r.x+hilitebox.x+hilitebox.width, r.y+hilitebox.y, lat2, lon2); if(lon1 > lon2) m_wpBBox.Set(lat1, lon1, lat2, lon2+360); else m_wpBBox.Set(lat1, lon1, lat2, lon2); m_wpBBox_view_scale_ppm = vp.view_scale_ppm; m_wpBBox_rotation = vp.rotation; } // if(region.Contains(r3) == wxOutRegion) // return; ocpnDC dc; // Highlite any selected point if( m_bPtIsSelected ) { wxColour hi_colour; if( m_bBlink ){ wxPen *pen = g_pRouteMan->GetActiveRoutePointPen(); hi_colour = pen->GetColour(); } else{ hi_colour = GetGlobalColor( _T ( "YELO1" ) ); } AlphaBlending( dc, r.x + hilitebox.x, r.y + hilitebox.y, hilitebox.width, hilitebox.height, radius, hi_colour, transparency ); } bool bDrawHL = false; if( m_bBlink && ( gFrame->nBlinkerTick & 1 ) ) bDrawHL = true; if( ( !bDrawHL ) && ( NULL != m_pbmIcon ) ) { int glw, glh; unsigned int IconTexture = pWayPointMan->GetIconTexture( pbm, glw, glh ); glBindTexture(GL_TEXTURE_2D, IconTexture); glEnable(GL_TEXTURE_2D); glEnable(GL_BLEND); glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE ); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glColor3f(1, 1, 1); int x = r1.x, y = r1.y, w = r1.width, h = r1.height; float scale = 1.0; // if(g_bresponsive){ scale = g_ChartScaleFactorExp; // } float ws = r1.width * scale; float hs = r1.height * scale; float xs = r.x - ws/2.; float ys = r.y - hs/2.; float u = (float)w/glw, v = (float)h/glh; glBegin(GL_QUADS); glTexCoord2f(0, 0); glVertex2f(xs, ys); glTexCoord2f(u, 0); glVertex2f(xs+ws, ys); glTexCoord2f(u, v); glVertex2f(xs+ws, ys+hs); glTexCoord2f(0, v); glVertex2f(xs, ys+hs); glEnd(); // 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_MarkName, 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); glColor3ub(m_FontColor.Red(), m_FontColor.Green(), m_FontColor.Blue()); int x = r.x + m_NameLocationOffsetX, y = r.y + m_NameLocationOffsetY; 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 waypoint radar rings if activated if( m_iWaypointRangeRingsNumber && m_bShowWaypointRangeRings ) { double factor = 1.00; if( m_iWaypointRangeRingsStepUnits == 1 ) // nautical miles factor = 1 / 1.852; factor *= m_fWaypointRangeRingsStep; double tlat, tlon; wxPoint r1; ll_gc_ll( m_lat, m_lon, 0, factor, &tlat, &tlon ); cc1->GetCanvasPointPix( tlat, tlon, &r1 ); 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_wxcWaypointRangeRingsColour, platform_pen_width ); wxBrush saveBrush = dc.GetBrush(); wxPen savePen = dc.GetPen(); dc.SetPen( ppPen1 ); dc.SetBrush( wxBrush( m_wxcWaypointRangeRingsColour, wxBRUSHSTYLE_TRANSPARENT ) ); for( int i = 1; i <= m_iWaypointRangeRingsNumber; i++ ) dc.StrokeCircle( r.x, r.y, i * pix_radius ); dc.SetPen( savePen ); dc.SetBrush( saveBrush ); } if( m_bBlink ) 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_bBlink ) g_blink_rect = CurrentRect_in_DC; // also save for global blinker }
void TextPoint::DrawGL( PlugIn_ViewPort &pivp ) { if( !m_bIsVisible ) return; if( m_iDisplayTextWhen == ID_TEXTPOINT_DISPLAY_TEXT_SHOW_ALWAYS || m_iDisplayTextWhen == ID_TEXTPOINT_DISPLAY_TEXT_SHOW_ON_ROLLOVER ) { if( m_TextPointText.Len() > 0 ) { CalculateTextExtents(); int teX, teY; int scalefactor = round(g_ocpn_draw_pi->m_chart_scale / m_natural_scale); if(m_natural_scale > (g_ocpn_draw_pi->m_chart_scale / 2) ) { teX = m_TextExtents.x; teY = m_TextExtents.y; } else { teX = m_TextExtents.x / scalefactor; teY = m_TextExtents.y / scalefactor; } if(teX > 0 && teY > 0 && scalefactor <= 8 ) { switch ( m_iTextPosition ) { case ID_TEXT_TOP: m_TextLocationOffsetX = g_iTextTopOffsetX; m_TextLocationOffsetY = g_iTextTopOffsetY - teY; break; case ID_TEXT_CENTRE_TOP: m_TextLocationOffsetX = g_iTextTopOffsetX - (teX / 2); m_TextLocationOffsetY = g_iTextTopOffsetY - teY; break; case ID_TEXT_BOTTOM: m_TextLocationOffsetX = g_iTextBottomOffsetX; m_TextLocationOffsetY = g_iTextBottomOffsetY; if(m_bShowName) m_TextLocationOffsetY += g_iTextBottomNameExtraOffsetY; break; case ID_TEXT_CENTRE_BOTTOM: m_TextLocationOffsetX = g_iTextBottomOffsetX - (teX / 2); m_TextLocationOffsetY = g_iTextBottomOffsetY; break; case ID_TEXT_CENTRE: m_TextLocationOffsetX = g_iTextCentreOffsetX - (teX / 2); m_TextLocationOffsetY = g_iTextCentreOffsetY - (teY / 2); break; case ID_TEXT_RIGHT: m_TextLocationOffsetX = g_iTextRightOffsetX; m_TextLocationOffsetY = g_iTextRightOffsetY; break; case ID_TEXT_LEFT: m_TextLocationOffsetX = g_iTextLeftOffsetX - teX; m_TextLocationOffsetY = g_iTextLeftOffsetY; break; } int sx2 = m_pbmIcon->GetWidth() / 2; int sy2 = m_pbmIcon->GetHeight() / 2; // Calculate the mark drawing extents wxPoint r; GetCanvasPixLL( g_pivp, &r, m_lat, m_lon); wxRect r1( r.x - sx2, r.y - sy2, sx2 * 2, sy2 * 2 ); // the bitmap extents if( m_DisplayTextFont.IsOk() ) { // Added to help with display of text (stops end clipping) teX += 20; wxRect r2( r.x + m_TextLocationOffsetX, r.y + m_TextLocationOffsetY, teX, teY ); r1.Union( r2 ); r.x = r.x + m_TextLocationOffsetX; r.y = r.y + m_TextLocationOffsetY; if( scalefactor != m_scale_factor || m_bTextChanged || ( !m_iDisplayTextTexture && teX != 0 && teY != 0 ) ) { m_scale_factor = scalefactor; m_bTextChanged = false; wxBitmap tbm(teX, teY); /* render text on dc */ wxMemoryDC dc; dc.SelectObject( tbm ); dc.SetBackground( wxBrush( *wxBLACK ) ); dc.Clear(); dc.SetFont( m_DisplayTextFont ); dc.SetTextForeground(* wxWHITE ); if(m_natural_scale > (g_ocpn_draw_pi->m_chart_scale / 2)) dc.DrawText( m_TextPointText, 10, 0); //else // dc.DrawText( wxT(""), 10, 0 ); dc.SelectObject( wxNullBitmap ); /* make alpha texture for text */ wxImage image = tbm.ConvertToImage(); unsigned char *d = image.GetData(); unsigned char *e = new unsigned char[teX * teY]; if(d && e){ for( int p = 0; p < teX*teY; p++) e[p] = d[3*p + 0]; } /* create texture for rendered text */ glGenTextures(1, &m_iDisplayTextTexture); glBindTexture(GL_TEXTURE_2D, m_iDisplayTextTexture); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST ); m_iDisplayTextTextureWidth = NextPow2(teX); m_iDisplayTextTextureHeight = NextPow2(teY); glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, m_iDisplayTextTextureWidth, m_iDisplayTextTextureHeight, 0, GL_ALPHA, GL_UNSIGNED_BYTE, NULL); glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, teX, teY, GL_ALPHA, GL_UNSIGNED_BYTE, e); delete [] e; } if(m_iDisplayTextTexture) { // Draw backing box ODDC ocpndc; g_ocpn_draw_pi->AlphaBlending( ocpndc, r.x, r.y, r2.width, r2.height, 6.0, m_colourTextBackgroundColour, m_iBackgroundTransparency ); /* draw texture with text */ glBindTexture(GL_TEXTURE_2D, m_iDisplayTextTexture); glEnable(GL_TEXTURE_2D); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glColor3ub(m_colourTextColour.Red(), m_colourTextColour.Green(), m_colourTextColour.Blue()); int x = r.x, y = r.y; float u = (float)teX/m_iDisplayTextTextureWidth, v = (float)teY/m_iDisplayTextTextureHeight; glBegin(GL_QUADS); glTexCoord2f(0, 0); glVertex2f(x, y); glTexCoord2f(u, 0); glVertex2f(x+teX, y); glTexCoord2f(u, v); glVertex2f(x+teX, y+teY); glTexCoord2f(0, v); glVertex2f(x, y+teY); glEnd(); glDisable(GL_BLEND); glDisable(GL_TEXTURE_2D); } } } } } ODPoint::DrawGL( pivp ); }
void DashboardInstrument_Dial::DrawData(wxGCDC* dc, double value, wxString unit, wxString format, DialPositionOption position) { if (position == DIAL_POSITION_NONE) return; dc->SetFont(*g_pFontLabel); wxColour cl; GetGlobalColor(_T("DASHF"), &cl); dc->SetTextForeground(cl); wxSize size = GetClientSize(); wxString text; if(!wxIsNaN(value)) { if (unit == _T("Deg")) text = wxString::Format(format, value)+DEGREE_SIGN; else if (unit == _T("DegL")) // No special display for now, might be XX°< (as in text-only instrument) text = wxString::Format(format, value)+DEGREE_SIGN; else if (unit == _T("DegR")) // No special display for now, might be >XX° text = wxString::Format(format, value)+DEGREE_SIGN; else if (unit == _T("DegT")) text = wxString::Format(format, value)+DEGREE_SIGN+_T("T"); else if (unit == _T("DegM")) text = wxString::Format(format, value)+DEGREE_SIGN+_T("M"); else if (unit == _T("N")) // Knots text = wxString::Format(format, value)+_T(" Kts"); else text = wxString::Format(format, value)+_T(" ")+unit; } else text = _T("---"); int width, height; wxScreenDC sdc; sdc.GetMultiLineTextExtent(text, &width, &height, NULL, g_pFontLabel); wxRect TextPoint; TextPoint.width = width; TextPoint.height = height; switch (position) { case DIAL_POSITION_NONE: // This case was already handled before, it's here just // to avoid compiler warning. return; case DIAL_POSITION_INSIDE: { TextPoint.x = m_cx - (width / 2) - 1; TextPoint.y = (size.y * .75) - height; GetGlobalColor(_T("DASHL"), &cl); int penwidth = size.x / 100; wxPen* pen = wxThePenList->FindOrCreatePen( cl, penwidth, wxSOLID ); dc->SetPen( *pen ); GetGlobalColor(_T("DASHB"), &cl); dc->SetBrush(cl); // There might be a background drawn below // so we must clear it first. dc->DrawRoundedRectangle(TextPoint.x-2, TextPoint.y-2, width+4, height+4, 3); break; } case DIAL_POSITION_TOPLEFT: TextPoint.x = 0; TextPoint.y = m_TitleHeight; break; case DIAL_POSITION_TOPRIGHT: TextPoint.x = size.x-width-1; TextPoint.y = m_TitleHeight; break; case DIAL_POSITION_BOTTOMLEFT: TextPoint.x = 0; TextPoint.y = size.y-height; break; case DIAL_POSITION_BOTTOMRIGHT: TextPoint.x = size.x-width-1; TextPoint.y = size.x-height; break; } wxColour c2; GetGlobalColor( _T("DASHB"), &c2 ); wxColour c3; GetGlobalColor( _T("DASHF"), &c3 ); wxStringTokenizer tkz( text, _T("\n") ); wxString token; token = tkz.GetNextToken(); while(token.Length()) { sdc.GetTextExtent(token, &width, &height, NULL, NULL, g_pFontLabel); if( g_pFontLabel->GetPointSize() <= 12 ) { wxBitmap tbm( width, height, -1 ); wxMemoryDC tdc( tbm ); tdc.SetBackground( c2 ); tdc.Clear(); tdc.SetFont(*g_pFontLabel ); tdc.SetTextForeground( c3 ); tdc.DrawText(token, 0, 0 ); tdc.SelectObject( wxNullBitmap ); dc->DrawBitmap(tbm, TextPoint.x, TextPoint.y, false); } else dc->DrawText(token, TextPoint.x, TextPoint.y ); TextPoint.y += height; token = tkz.GetNextToken(); } }
void DashboardInstrument_Dial::DrawLabels(wxGCDC* dc) { if (m_LabelOption == DIAL_LABEL_NONE) return; wxSize size = GetClientSize(); // Create a new bitmap for this method graphics wxBitmap tbm( size.x, size.y, -1 ); wxMemoryDC tdc( tbm ); wxColour cback; GetGlobalColor( _T("DASHB"), &cback ); tdc.SetBackground( cback ); tdc.Clear(); wxPoint TextPoint; wxPen pen; tdc.SetFont(*g_pFontSmall); wxColor cl; GetGlobalColor(_T("DASHF"), &cl); tdc.SetTextForeground(cl); dc->SetFont(*g_pFontSmall); dc->SetTextForeground(cl); int diff_angle = m_AngleStart + m_AngleRange - ANGLE_OFFSET; // angle between markers double abm = m_AngleRange * m_LabelStep / (m_MainValueMax - m_MainValueMin); // don't draw last value, it's already done as first if (m_AngleRange == 360) diff_angle -= abm; int offset = 0; int value = m_MainValueMin; int width, height; for(double angle = m_AngleStart - ANGLE_OFFSET; angle <= diff_angle; angle += abm) { wxString label = (m_LabelArray.GetCount() ? m_LabelArray.Item(offset) : wxString::Format(_T("%d"), value)); tdc.GetTextExtent(label, &width, &height, 0, 0, g_pFontSmall); double halfW = width / 2; if (m_LabelOption == DIAL_LABEL_HORIZONTAL) { double halfH = height / 2; //double delta = sqrt(width*width+height*height); double delta = sqrt(halfW*halfW+halfH*halfH); TextPoint.x = m_cx + ((m_radius * 0.90) - delta) * cos(deg2rad(angle)) - halfW; TextPoint.y = m_cy + ((m_radius * 0.90) - delta) * sin(deg2rad(angle)) - halfH; if( g_pFontSmall->GetPointSize() <= 12 ) tdc.DrawText(label, TextPoint); else dc->DrawText(label, TextPoint); } else if (m_LabelOption == DIAL_LABEL_ROTATED) { // The coordinates of dc->DrawRotatedText refer to the top-left corner // of the rectangle bounding the string. So we must calculate the // right coordinates depending of the angle. // Move left from the Marker so that the position is in the Middle of Text long double tmpangle = angle - rad2deg(asin(halfW / (0.90 * m_radius))); TextPoint.x = m_cx + m_radius * 0.90 * cos(deg2rad(tmpangle)); TextPoint.y = m_cy + m_radius * 0.90 * sin(deg2rad(tmpangle)); if( g_pFontSmall->GetPointSize() <= 12 ) tdc.DrawRotatedText(label, TextPoint, -90 - angle); else dc->DrawRotatedText(label, TextPoint, -90 - angle); } offset++; value += m_LabelStep; } tdc.SelectObject( wxNullBitmap ); if( g_pFontSmall->GetPointSize() <= 12 ) dc->DrawBitmap(tbm, 0, 0, false); }
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 DashboardInstrument::OnPaint( wxPaintEvent& WXUNUSED(event) ) { wxBufferedPaintDC pdc( this ); if( !pdc.IsOk() ) { wxLogMessage( _T("DashboardInstrument::OnPaint() fatal: wxBufferedPaintDC.IsOk() false.") ); return; } wxSize size = GetClientSize(); if( size.x == 0 || size.y == 0 ) { wxLogMessage( _T("DashboardInstrument::OnPaint() fatal: Zero size DC.") ); return; } wxBitmap bm( size.x, size.y, 32 ); #if !wxCHECK_VERSION(2,9,4) bm.UseAlpha(); #endif wxMemoryDC mdc( bm ); #if wxUSE_GRAPHICS_CONTEXT wxGCDC dc( mdc ); #else wxMemoryDC &dc( mdc ); #endif wxColour cl; GetGlobalColor( _T("DASHB"), &cl ); dc.SetBackground( cl ); dc.Clear(); Draw( &dc ); if(m_drawSoloInPane) { mdc.SelectObject( wxNullBitmap ); pdc.DrawBitmap( bm, 0, 0, false ); } else { // Windows GCDC does a terrible job of rendering small texts // Workaround by using plain old DC for title box if text size is too small #ifdef __WXMSW__ if( g_pFontTitle->GetPointSize() > 12 ) #endif { wxPen pen; pen.SetStyle( wxSOLID ); GetGlobalColor( _T("DASHL"), &cl ); pen.SetColour( cl ); dc.SetPen( pen ); dc.SetBrush( cl ); dc.DrawRoundedRectangle( 0, 0, size.x, m_TitleHeight, 3 ); dc.SetFont( *g_pFontTitle ); GetGlobalColor( _T("DASHF"), &cl ); dc.SetTextForeground( cl ); dc.DrawText( m_title, 5, 0 ); mdc.SelectObject( wxNullBitmap ); pdc.DrawBitmap( bm, 0, 0, false ); } #ifdef __WXMSW__ if( g_pFontTitle->GetPointSize() <= 12 ) { mdc.SelectObject( wxNullBitmap ); // the instrument body pdc.DrawBitmap( bm, 0, 0, false ); wxBitmap tbm( size.x, m_TitleHeight, -1 ); wxMemoryDC tdc( tbm ); wxColour cl; GetGlobalColor( _T("DASHB"), &cl ); tdc.SetBackground( cl ); tdc.Clear(); wxPen pen; pen.SetStyle( wxSOLID ); GetGlobalColor( _T("DASHL"), &cl ); pen.SetColour( cl ); tdc.SetPen( pen ); tdc.SetBrush( cl ); tdc.DrawRoundedRectangle( 0, 0, size.x, m_TitleHeight, 3 ); tdc.SetFont( *g_pFontTitle ); GetGlobalColor( _T("DASHF"), &cl ); tdc.SetTextForeground( cl ); tdc.DrawText( m_title, 5, 0 ); tdc.SelectObject( wxNullBitmap ); pdc.DrawBitmap( tbm, 0, 0, false ); } #endif } }