PoeditListCtrl::PoeditListCtrl(wxWindow *parent, wxWindowID id, const wxPoint &pos, const wxSize &size, long style, bool dispIDs, const wxValidator& validator, const wxString &name) : wxListView(parent, id, pos, size, style | wxLC_VIRTUAL, validator, name) { m_catalog = NULL; m_displayIDs = dispIDs; m_isRTL = false; m_appIsRTL = (wxTheApp->GetLayoutDirection() == wxLayout_RightToLeft); sortOrder = SortOrder::Default(); CreateColumns(); int i; wxImageList *list = new wxImageList(16, 16); // IMG_NOTHING: list->Add(wxArtProvider::GetBitmap("poedit-status-nothing")); // IMG_AUTOMATIC: list->Add(wxArtProvider::GetBitmap("poedit-status-automatic")); // IMG_COMMENT: list->Add(wxArtProvider::GetBitmap("poedit-status-comment")); // IMG_AUTOMATIC | IMG_COMMENT: list->Add(MergeBitmaps(wxArtProvider::GetBitmap("poedit-status-automatic"), wxArtProvider::GetBitmap("poedit-status-comment"))); // IMG_MODIFIED list->Add(wxArtProvider::GetBitmap("poedit-status-modified")); // IMG_MODIFIED variations: for (i = 1; i < IMG_MODIFIED; i++) { list->Add(MergeBitmaps(BitmapFromList(list, i), wxArtProvider::GetBitmap("poedit-status-modified"))); } // BK_XX variations: for (int bk = 0; bk < 10; bk++) { for(i = 0; i <= (IMG_AUTOMATIC|IMG_COMMENT|IMG_MODIFIED); i++) { wxBitmap bmp = BitmapFromList(list, i); list->Add(AddDigit(bk, 0, 0, bmp)); } } AssignImageList(list, wxIMAGE_LIST_SMALL); // configure items colors & fonts: wxVisualAttributes visual = GetDefaultAttributes(); wxColour shaded = visual.colBg; #ifdef __WXMSW__ // On Windows 7, shaded list items make it impossible to see the selection, // so use different color for it (see bug #336). int verMaj, verMin; wxGetOsVersion(&verMaj, &verMin); if ( verMaj > 6 || (verMaj == 6 && verMin >= 1) ) { shaded.Set(int(0.99 * shaded.Red()), int(0.99 * shaded.Green()), shaded.Blue()); } else #endif // __WXMSW__ #ifdef __WXOSX__ if ( shaded == *wxWHITE ) { // use standard shaded color from finder/databrowser: shaded.Set("#f0f5fd"); } else #endif // __WXOSX__ { shaded.Set(int(DARKEN_FACTOR * shaded.Red()), int(DARKEN_FACTOR * shaded.Green()), int(DARKEN_FACTOR * shaded.Blue())); } m_attrNormal[1].SetBackgroundColour(shaded); m_attrUntranslated[1].SetBackgroundColour(shaded); m_attrFuzzy[1].SetBackgroundColour(shaded); m_attrInvalid[1].SetBackgroundColour(shaded); // FIXME: make this user-configurable if ( IsAlmostWhite(visual.colBg) ) { m_attrUntranslated[0].SetTextColour(gs_UntranslatedForWhite); m_attrUntranslated[1].SetTextColour(gs_UntranslatedForWhite); m_attrFuzzy[0].SetTextColour(gs_FuzzyForWhite); m_attrFuzzy[1].SetTextColour(gs_FuzzyForWhite); } else if ( IsAlmostBlack(visual.colBg) ) { m_attrUntranslated[0].SetTextColour(gs_UntranslatedForBlack); m_attrUntranslated[1].SetTextColour(gs_UntranslatedForBlack); m_attrFuzzy[0].SetTextColour(gs_FuzzyForBlack); m_attrFuzzy[1].SetTextColour(gs_FuzzyForBlack); } // else: we don't know if the default colors would be well-visible on // user's background color, so play it safe and don't highlight // anything // FIXME: todo; use appropriate font for fuzzy/trans/untrans m_attrInvalid[0].SetBackgroundColour(gs_ErrorColor); m_attrInvalid[1].SetBackgroundColour(gs_ErrorColor); // Use gray for IDs if ( IsAlmostBlack(visual.colFg) ) m_attrId.SetTextColour(wxColour("#A1A1A1")); SetCustomFont(wxNullFont); }
void ocpnCompass::CreateBmp( bool newColorScheme ) { if(!m_shown) return; wxString gpsIconName; ocpnStyle::Style* style = g_StyleManager->GetCurrentStyle(); // In order to draw a horizontal compass window when the toolbar is vertical, we // need to save away the sizes and backgrounds for the two icons. static wxBitmap compassBg, gpsBg; static wxSize toolsize; static int topmargin, leftmargin, radius; if( ! compassBg.IsOk() || newColorScheme ) { int orient = style->GetOrientation(); style->SetOrientation( wxTB_HORIZONTAL ); if( style->HasBackground() ) { compassBg = style->GetNormalBG(); style->DrawToolbarLineStart( compassBg ); compassBg = style->SetBitmapBrightness( compassBg ); gpsBg = style->GetNormalBG(); style->DrawToolbarLineEnd( gpsBg ); gpsBg = style->SetBitmapBrightness( gpsBg ); } if(fabs(m_scale-1.0) > 0.1){ wxImage bg_img = compassBg.ConvertToImage(); bg_img.Rescale(compassBg.GetWidth() * m_scale, compassBg.GetHeight() *m_scale, wxIMAGE_QUALITY_NORMAL); compassBg = wxBitmap( bg_img ); bg_img = gpsBg.ConvertToImage(); bg_img.Rescale(gpsBg.GetWidth() * m_scale, gpsBg.GetHeight() *m_scale, wxIMAGE_QUALITY_NORMAL); gpsBg = wxBitmap( bg_img ); } leftmargin = style->GetCompassLeftMargin(); topmargin = style->GetCompassTopMargin(); radius = style->GetCompassCornerRadius(); if( orient ) style->SetOrientation( wxTB_VERTICAL ); } bool b_need_refresh = false; if( bGPSValid ) { if( g_bSatValid ) { gpsIconName = _T("gps3Bar"); if( g_SatsInView <= 8 ) gpsIconName = _T("gps2Bar"); if( g_SatsInView <= 4 ) gpsIconName = _T("gps1Bar"); if( g_SatsInView < 0 ) gpsIconName = _T("gpsGry"); } else gpsIconName = _T("gpsGrn"); } else gpsIconName = _T("gpsRed"); if( m_lastgpsIconName != gpsIconName ) b_need_refresh = true; double rose_angle = -999.; if( ( fabs( cc1->GetVPRotation() ) > .01 ) || ( fabs( cc1->GetVPSkew() ) > .01 ) ) { rose_angle = -cc1->GetVPRotation(); } else rose_angle = 0.; if( fabs( m_rose_angle - rose_angle ) > .1 ) b_need_refresh = true; if( !b_need_refresh ) return; int width = compassBg.GetWidth() + gpsBg.GetWidth() + leftmargin; if( !style->marginsInvisible ) width += leftmargin + style->GetToolSeparation(); m_StatBmp.Create( width, compassBg.GetHeight() + topmargin + style->GetCompassBottomMargin() ); m_rect.width = m_StatBmp.GetWidth(); m_rect.height = m_StatBmp.GetHeight(); if( !m_StatBmp.IsOk() ) return; m_MaskBmp = wxBitmap( m_StatBmp.GetWidth(), m_StatBmp.GetHeight() ); if( style->marginsInvisible ) { wxMemoryDC sdc( m_MaskBmp ); sdc.SetBackground( *wxWHITE_BRUSH ); sdc.Clear(); sdc.SetBrush( *wxBLACK_BRUSH ); sdc.SetPen( *wxBLACK_PEN ); wxSize maskSize = wxSize(m_MaskBmp.GetWidth() - leftmargin, m_MaskBmp.GetHeight() - (2 * topmargin)); sdc.DrawRoundedRectangle( wxPoint( leftmargin, topmargin ), maskSize, radius ); sdc.SelectObject( wxNullBitmap ); } else if(radius) { wxMemoryDC sdc( m_MaskBmp ); sdc.SetBackground( *wxWHITE_BRUSH ); sdc.Clear(); sdc.SetBrush( *wxBLACK_BRUSH ); sdc.SetPen( *wxBLACK_PEN ); sdc.DrawRoundedRectangle( 0, 0, m_MaskBmp.GetWidth(), m_MaskBmp.GetHeight(), radius ); sdc.SelectObject( wxNullBitmap ); } m_StatBmp.SetMask(new wxMask(m_MaskBmp, *wxWHITE)); wxMemoryDC mdc; mdc.SelectObject( m_StatBmp ); mdc.SetBackground( wxBrush( GetGlobalColor( _T("COMP1") ), wxSOLID ) ); mdc.Clear(); mdc.SetPen( wxPen( GetGlobalColor( _T("UITX1") ), 1 ) ); mdc.SetBrush( wxBrush( GetGlobalColor( _T("UITX1") ), wxTRANSPARENT ) ); if( !style->marginsInvisible ) mdc.DrawRoundedRectangle( 0, 0, m_StatBmp.GetWidth(), m_StatBmp.GetHeight(),radius ); wxPoint offset(leftmargin, topmargin); // Build Compass Rose, rotated... wxBitmap BMPRose; wxPoint after_rotate; int cwidth = style->GetToolSize().x * m_scale; int cheight = style->GetToolSize().y * m_scale; cheight = wxMin(cheight, compassBg.GetHeight()); cwidth = wxMin( cwidth, cheight ); cheight = cwidth; if( g_bCourseUp ) BMPRose = style->GetIcon( _T("CompassRose"), cwidth, cheight ); else BMPRose = style->GetIcon( _T("CompassRoseBlue"), cwidth, cheight ); if( ( fabs( cc1->GetVPRotation() ) > .01 ) || ( fabs( cc1->GetVPSkew() ) > .01 ) ) { wxImage rose_img = BMPRose.ConvertToImage(); wxPoint rot_ctr( cwidth / 2, cheight / 2 ); wxImage rot_image = rose_img.Rotate( rose_angle, rot_ctr, true, &after_rotate ); BMPRose = wxBitmap( rot_image ).GetSubBitmap( wxRect( -after_rotate.x, -after_rotate.y, cwidth, cheight )); } wxBitmap iconBm; if( style->HasBackground() ) { iconBm = MergeBitmaps( compassBg, BMPRose, wxSize( 0, 0 ) ); } else { iconBm = BMPRose; } iconBm = ConvertTo24Bit( wxColor(0,0,0), iconBm); mdc.DrawBitmap( iconBm, offset ); offset.x += iconBm.GetWidth(); offset.x += style->GetToolSeparation(); m_rose_angle = rose_angle; // GPS Icon int twidth = style->GetToolSize().x * m_scale; int theight = style->GetToolSize().y * m_scale; theight = wxMin(cheight, compassBg.GetHeight()); int swidth = wxMax( twidth, theight ); int sheight = wxMin( twidth, theight ); // Sometimes, the SVG renderer gets the size wrong due to some internal rounding error. // If so found, it seems to work OK by just reducing the requested size by one pixel.... wxBitmap gicon = style->GetIcon( gpsIconName, swidth, sheight ); if( gicon.GetHeight() != sheight ) gicon = style->GetIcon( gpsIconName, swidth-1, sheight-1, true ); if( style->HasBackground() ) { iconBm = MergeBitmaps( gpsBg, gicon, wxSize( 0, 0 ) ); } else { iconBm = gicon; } iconBm = ConvertTo24Bit( wxColor(0,0,0), iconBm); mdc.DrawBitmap( iconBm, offset ); mdc.SelectObject( wxNullBitmap ); m_lastgpsIconName = gpsIconName; #if defined(ocpnUSE_GLES) // GLES does not do ocpnDC::DrawBitmap(), so use texture if(g_bopengl){ wxImage image = m_StatBmp.ConvertToImage(); unsigned char *imgdata = image.GetData(); unsigned char *imgalpha = image.GetAlpha(); int tex_w = image.GetWidth(); int tex_h = image.GetHeight(); GLuint format = GL_RGBA; GLuint internalformat = format; int stride = 4; if(imgdata){ unsigned char *teximage = (unsigned char *) malloc( stride * tex_w * tex_h ); for( int j = 0; j < tex_w*tex_h; j++ ){ for( int k = 0; k < 3; k++ ) teximage[j * stride + k] = imgdata[3*j + k]; teximage[j * stride + 3] = imgalpha ? imgalpha[j] : 255; // alpha } if(texobj){ glDeleteTextures(1, &texobj); texobj = 0; } glGenTextures( 1, &texobj ); glBindTexture( GL_TEXTURE_2D, texobj ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST/*GL_LINEAR*/ ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST ); glTexImage2D( GL_TEXTURE_2D, 0, internalformat, tex_w, tex_h, 0, format, GL_UNSIGNED_BYTE, teximage ); free(teximage); } } #endif }
wxBitmap ocpnFloatingCompassWindow::CreateBmp() { wxString gpsIconName; ocpnStyle::Style* style = g_StyleManager->GetCurrentStyle(); // In order to draw a horizontal compass window when the toolbar is vertical, we // need to save away the sizes and backgrounds for the two icons. static wxBitmap compassBg, gpsBg; static wxSize toolsize; static int topmargin, leftmargin, radius; if( ! compassBg.IsOk() ) { int orient = style->GetOrientation(); style->SetOrientation( wxTB_HORIZONTAL ); if( style->HasBackground() ) { compassBg = style->GetNormalBG(); style->DrawToolbarLineStart( compassBg ); gpsBg = style->GetNormalBG(); style->DrawToolbarLineEnd( gpsBg ); } leftmargin = style->GetLeftMargin(); topmargin = style->GetTopMargin(); toolsize = style->GetToolSize(); toolsize.x *= 2; radius = style->GetToolbarCornerRadius(); if( orient ) style->SetOrientation( wxTB_VERTICAL ); } bool b_need_refresh = false; if( bGPSValid ) { if( g_bSatValid ) { gpsIconName = _T("gps3Bar"); if( g_SatsInView <= 8 ) gpsIconName = _T("gps2Bar"); if( g_SatsInView <= 4 ) gpsIconName = _T("gps1Bar"); if( g_SatsInView < 0 ) gpsIconName = _T("gpsGry"); } else gpsIconName = _T("gpsGrn"); } else gpsIconName = _T("gpsRed"); if( m_lastgpsIconName != gpsIconName ) b_need_refresh = true; double rose_angle = -999.; if( ( fabs( cc1->GetVPRotation() ) > .01 ) || ( fabs( cc1->GetVPSkew() ) > .01 ) ) { rose_angle = -cc1->GetVPRotation(); if( !g_bCourseUp && !g_bskew_comp ) rose_angle = -cc1->GetVPRotation() - cc1->GetVPSkew(); b_need_refresh = true; } else rose_angle = 0.; if( fabs( m_rose_angle - rose_angle ) > .001 ) b_need_refresh = true; if( b_need_refresh ) { wxBitmap StatBmp; StatBmp.Create( ( _img_compass.GetWidth() + _img_gpsRed.GetWidth() ) + style->GetLeftMargin() * 2 + style->GetToolSeparation(), _img_compass.GetHeight() + style->GetTopMargin() + style->GetBottomMargin() ); if( StatBmp.IsOk() ) { wxMemoryDC mdc; mdc.SelectObject( StatBmp ); mdc.SetBackground( wxBrush( GetGlobalColor( _T("GREY2") ), wxSOLID ) ); mdc.Clear(); mdc.SetPen( wxPen( GetGlobalColor( _T("UITX1") ), 1 ) ); mdc.SetBrush( wxBrush( GetGlobalColor( _T("UITX1") ), wxTRANSPARENT ) ); mdc.DrawRoundedRectangle( 0, 0, StatBmp.GetWidth(), StatBmp.GetHeight(), style->GetToolbarCornerRadius() ); wxPoint offset( style->GetLeftMargin(), style->GetTopMargin() ); // Build Compass Rose, rotated... wxBitmap BMPRose; wxPoint after_rotate; if( g_bCourseUp ) BMPRose = style->GetIcon( _T("CompassRose") ); else BMPRose = style->GetIcon( _T("CompassRoseBlue") ); if( ( fabs( cc1->GetVPRotation() ) > .01 ) || ( fabs( cc1->GetVPSkew() ) > .01 ) ) { wxPoint rot_ctr( BMPRose.GetWidth() / 2, BMPRose.GetHeight() / 2 ); wxImage rose_img = BMPRose.ConvertToImage(); wxImage rot_image = rose_img.Rotate( rose_angle, rot_ctr, true, &after_rotate ); BMPRose = wxBitmap( rot_image ).GetSubBitmap( wxRect( -after_rotate.x, -after_rotate.y, BMPRose.GetWidth(), BMPRose.GetHeight()) ); } wxBitmap iconBm; if( style->HasBackground() ) { iconBm = MergeBitmaps( compassBg, BMPRose, wxSize( 0, 0 ) ); } else { iconBm = BMPRose; } mdc.DrawBitmap( iconBm, offset ); offset.x += iconBm.GetWidth(); m_rose_angle = rose_angle; if( style->HasBackground() ) { iconBm = MergeBitmaps( gpsBg, style->GetIcon( gpsIconName ), wxSize( 0, 0 ) ); } else { iconBm = style->GetIcon( gpsIconName ); } mdc.DrawBitmap( iconBm, offset ); mdc.SelectObject( wxNullBitmap ); m_lastgpsIconName = gpsIconName; } if( style->marginsInvisible ) { m_MaskBmp = wxBitmap( StatBmp.GetWidth(), StatBmp.GetHeight() ); wxMemoryDC sdc( m_MaskBmp ); sdc.SetBackground( *wxWHITE_BRUSH ); sdc.Clear(); sdc.SetBrush( *wxBLACK_BRUSH ); sdc.SetPen( *wxBLACK_PEN ); sdc.DrawRoundedRectangle( wxPoint( leftmargin, topmargin ), toolsize, radius ); sdc.SelectObject( wxNullBitmap ); SetShape( wxRegion( m_MaskBmp, *wxWHITE, 0 ) ); } return StatBmp; } else return wxNullBitmap; }
int main(int argc, void **argv) { HANDLE hFile; char szBuf[1024]; char *pszName = (char *)argv[1]; BITMAPFILEHEADER bmfh; BITMAPINFOHEADER bmih, bmih2; printf("\t\n---------%s-----------\n\n", argv[0]); printf("\tvalve L.L.C.\n"); if ((argc != 2) || (*pszName == '-')) { PrintUsage((char *)argv[0]); exit(1); } // Make sure that we have access to our source files printf("\tLoading %s ... ", pszName); hFile = CreateFile(pszName, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); if (hFile == INVALID_HANDLE_VALUE) { sprintf(szBuf, "Couldn't open %s.", argv[1]); ReportError(szBuf); } if (LoadBMP(hFile, &pbFBits, &ppalF, &bmfh, &bmih) < 0) ReportError("\n"); // LoadBMP displays error. CloseHandle(hFile); printf("Loaded.\n"); *pszName = 'N'; printf("\tLoading %s ... ", pszName); hFile = CreateFile(pszName, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); if (hFile == INVALID_HANDLE_VALUE) { sprintf(szBuf, "Couldn't open %s.", argv[1]); ReportError(szBuf); } if (LoadBMP(hFile, &pbNBits, &ppalN, NULL, &bmih2) < 0) ReportError("\n"); // LoadBMP displays error. CloseHandle(hFile); printf("Loaded.\n"); if ((bmih.biWidth != bmih2.biWidth) || (bmih.biHeight != bmih2.biHeight)) { sprintf(szBuf, "BMP Sizes don't match (%d,%d), (%d,%d)\n", bmih.biWidth, bmih.biHeight, bmih2.biWidth, bmih2.biHeight); ReportError(szBuf); } *pszName = 'M'; // Skip past the "N_" char *pOutName = strdup( pszName ); if( pOutName[ 2 ] == '+' ) { pOutName[ 1 ] = pOutName[ 2 ]; pOutName[ 2 ] = pOutName[ 3 ]; pOutName[ 3 ] = '~'; } else { pOutName[ 1 ] = '~'; } hFile = CreateFile( &pOutName[1], GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); if (hFile == INVALID_HANDLE_VALUE) { sprintf(szBuf, " Could not create the target bitmap: %s\n", pszName); ReportError(szBuf); } free( pOutName ); // Merge files CreateFBRemap(); CreateNormalRemap(); MergeBitmaps( bmih.biWidth, bmih.biHeight ); // Write Files BOOL fSuccess; DWORD dwActual; printf("\tWriting %s ... ", pszName); // Write out new bitmap fSuccess = WriteFile(hFile, &bmfh, sizeof(bmfh), &dwActual, NULL); if (!fSuccess || (dwActual != sizeof(bmfh))) ReportError("Write Failure.\n"); fSuccess = WriteFile(hFile, &bmih, sizeof(bmih), &dwActual, NULL); if (!fSuccess || (dwActual != sizeof(bmih))) ReportError("Write Failure.\n"); fSuccess = WriteFile(hFile, ppalN, sizeof(RGBQUAD) * 256, &dwActual, NULL); if (!fSuccess || (dwActual != (sizeof(RGBQUAD) * 256))) ReportError("Write Failure.\n"); fSuccess = WriteFile(hFile, pbNBits, (bmih.biWidth * bmih.biHeight), &dwActual, NULL); if (!fSuccess || (dwActual != (DWORD)(bmih.biWidth * bmih.biHeight))) ReportError("Write Failure.\n"); CloseHandle(hFile); printf("done!\n\n"); return 0; }