void DashboardInstrument_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 MapperRoomRender::renderShadow(int x, int y) { MaskDC m(m_hdc, m_size, m_size); m.makeMask(x, y); RECT rd = { x, y, x + m_size, y + m_size }; CMemoryDC tdc(m_hdc, rd); tdc.FillRect(&rd, m_shadowBrush); tdc.BitBlt(x, y, m_size, m_size, m, 0, 0, SRCAND); tdc.BitBlt(x, y, m_size, m_size, m_hdc, x, y, SRCERASE); }
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 }
TMatrixD Chol (TVectorD& covV) { int nCov = covV.GetNrows(); int n = int((sqrt(8*nCov+1.)-1.)/2.+0.5); if ( nCov != n*(n+1)/2. ) { std::cout << "Chol: length of vector " << nCov << " is not n*(n+1)/2" << std::endl; return TMatrixD(); } // get diagonal elements int ind(0); TVectorD sigmas(n); for ( int i=0; i<n; ++i ) { for ( int j=0; j<=i; ++j ) { if ( j == i ) sigmas[i] = covV(ind); ++ind; } } // fill cov matrix (could be more elegant ...) ind = 0; TMatrixDSym covMatrix(n); for ( int i=0; i<n; ++i ) { for ( int j=0; j<=i; ++j ) { if ( j == i ) covMatrix(i,i) = sigmas(i)*sigmas(i); else covMatrix(i,j) = covMatrix(j,i) = covV(ind)*sigmas(i)*sigmas(j); ++ind; } } covMatrix.Print(); TDecompChol tdc(covMatrix); bool worked = tdc.Decompose(); if ( !worked ) { std::cout << "Decomposition failed" << std::endl; return TMatrixD(); } TMatrixD matU = tdc.GetU(); return matU; // // // // cross check with random generation // // // double sum0(0.); // TVectorD sum1(n); // TMatrixDSym sum2(n); // TRandom2 rgen; // TVectorD xrnd(n); // TVectorD xrndRot(n); // for ( unsigned int i=0; i<1000000; ++i ) { // for ( unsigned int j=0; j<n; ++j ) xrnd(j) = 0.; // for ( unsigned int j=0; j<n; ++j ) { // TVectorD aux(n); // for ( int k=0; k<n; ++k ) aux(k) = matU(j,k); // xrnd += rgen.Gaus(0.,1.)*aux; // } // // xrnd *= matUT; // sum0 += 1.; // for ( unsigned int j0=0; j0<n; ++j0 ) { // sum1(j0) += xrnd(j0); // for ( unsigned int j1=0; j1<n; ++j1 ) { // sum2(j0,j1) += xrnd(j0)*xrnd(j1); // } // } // } // for ( unsigned int j0=0; j0<n; ++j0 ) { // printf("%10.3g",sum1(j0)/sum0); // } // printf(" sum1 \n"); // printf("\n"); // for ( unsigned int j0=0; j0<n; ++j0 ) { // for ( unsigned int j1=0; j1<n; ++j1 ) { // printf("%10.3g",sum2(j0,j1)/sum0); // } // printf(" sum2 \n"); // } // return matU; }
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 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 } }