// Loads bitmaps bool wxEmulatorInfo::Load(const wxString& appDir) { // Try to find absolute path wxString absoluteConfigPath = m_emulatorFilename; if ( !::wxIsAbsolutePath(absoluteConfigPath) ) { wxString currDir = wxGetCwd(); absoluteConfigPath = currDir + wxString(wxFILE_SEP_PATH) + m_emulatorFilename; if ( !wxFile::Exists(absoluteConfigPath) ) { absoluteConfigPath = appDir + wxString(wxFILE_SEP_PATH) + m_emulatorFilename; } } if ( !wxFile::Exists(absoluteConfigPath) ) { wxString str; str.Printf( wxT("Could not find config file %s"), absoluteConfigPath.c_str() ); wxMessageBox(str); return false; } wxString rootPath = wxPathOnly(absoluteConfigPath); { wxFileConfig config(wxT("wxEmulator"), wxT("wxWidgets"), absoluteConfigPath, wxEmptyString, wxCONFIG_USE_LOCAL_FILE); config.Read(wxT("/General/title"), & m_emulatorTitle); config.Read(wxT("/General/description"), & m_emulatorDescription); config.Read(wxT("/General/backgroundBitmap"), & m_emulatorBackgroundBitmapName); wxString colString; if (config.Read(wxT("/General/backgroundColour"), & colString) || config.Read(wxT("/General/backgroundColor"), & colString) ) { m_emulatorBackgroundColour = wxHexStringToColour(colString); } int x = 0, y = 0, w = 0, h = 0, dw = 0, dh = 0; config.Read(wxT("/General/screenX"), & x); config.Read(wxT("/General/screenY"), & y); config.Read(wxT("/General/screenWidth"), & w); config.Read(wxT("/General/screenHeight"), & h); if (config.Read(wxT("/General/deviceWidth"), & dw) && config.Read(wxT("/General/deviceHeight"), & dh)) { m_emulatorDeviceSize = wxSize(dw, dh); } m_emulatorScreenPosition = wxPoint(x, y); m_emulatorScreenSize = wxSize(w, h); } if (!m_emulatorBackgroundBitmapName.empty()) { wxString absoluteBackgroundBitmapName = rootPath + wxString(wxFILE_SEP_PATH) + m_emulatorBackgroundBitmapName; if ( !wxFile::Exists(absoluteBackgroundBitmapName) ) { wxString str; str.Printf( wxT("Could not find bitmap %s"), absoluteBackgroundBitmapName.c_str() ); wxMessageBox(str); return false; } wxBitmapType type = wxDetermineImageType(m_emulatorBackgroundBitmapName); if (type == wxBITMAP_TYPE_INVALID) return false; if (!m_emulatorBackgroundBitmap.LoadFile(m_emulatorBackgroundBitmapName, type)) { wxString str; str.Printf( wxT("Could not load bitmap file %s"), m_emulatorBackgroundBitmapName.c_str() ); wxMessageBox(str); return false; } m_emulatorDeviceSize = wxSize(m_emulatorBackgroundBitmap.GetWidth(), m_emulatorBackgroundBitmap.GetHeight()); } return true; }
bool MyApp::MakeSplash() { // First, load the original (template) splash image. int imageType = wxDetermineImageType(m_inputFilename); wxImage templateImage; if (imageType == -1 || !wxFileExists(m_inputFilename) || !templateImage.LoadFile(m_inputFilename, imageType)) { wxString msg; msg.Printf(wxT("Sorry, could not load template image %s"), (const wxChar*) m_inputFilename); wxLogMessage(msg); return FALSE; } wxString msg; msg.Printf(wxT("Creating new file %s from template file %s and text %s"), (const wxChar*) m_outputFilename, (const wxChar*) m_inputFilename, (const wxChar*) m_text); Log(msg); wxScreenDC screenDC; bool useScaling = m_antialias && (m_scaleFactor > 1); int pointSize; #if !USE_SCALING useScaling = FALSE; #endif if (useScaling) pointSize = m_scaleFactor*m_fontPointSize; else pointSize = m_fontPointSize; wxString faceName = m_fontFaceName; wxFont font(pointSize, wxDEFAULT, m_fontStyle, m_fontWeight, FALSE, faceName); screenDC.SetFont(font); int w, h, scaledW, scaledH; screenDC.GetTextExtent(m_text, & w, & h); if (useScaling) { wxFont font2(m_fontPointSize, wxDEFAULT, m_fontStyle, m_fontWeight, FALSE, faceName); screenDC.SetFont(font2); screenDC.GetTextExtent(m_text, & scaledW, & scaledH); } screenDC.SetFont(wxNullFont); wxBrush backgroundBrush(m_textBackgroundColour, wxSOLID); wxBitmap bitmap(w, h); wxMemoryDC memDC; memDC.SelectObject(bitmap); memDC.SetFont(font); memDC.SetBackgroundMode(wxTRANSPARENT); memDC.SetTextForeground(m_textForegroundColour); memDC.SetBackground(backgroundBrush); memDC.SetBrush(backgroundBrush); memDC.Clear(); memDC.DrawText(m_text, 0, 0); memDC.SelectObject(wxNullBitmap); wxImage image = bitmap.ConvertToImage(); if (m_antialias) { wxImage anti = wxAntiAlias(image); image = anti; } if (useScaling) { // Now create an image and rescale it down to the original point size image.Rescale(w/m_scaleFactor, h/m_scaleFactor); } image.SetMaskColour(m_textBackgroundColour.Red(), m_textBackgroundColour.Green(), m_textBackgroundColour.Blue()); wxBitmap bitmap2(image); // Now draw the image into the template image wxBitmap templateBitmap(templateImage); wxMemoryDC memDCTemplate; memDCTemplate.SelectObject(templateBitmap); int x, y; if (m_centre) { y = m_textPosition.y; // Currently, always start at this position x = m_textPosition.x - (image.GetWidth() / 2); } else if (m_rightJustify) { y = m_textPosition.y; // Currently, always start at this position x = m_textPosition.x - (image.GetWidth()); } else { y = m_textPosition.y; // Currently, always start at this position x = m_textPosition.x; } memDCTemplate.DrawBitmap(bitmap2, x, y, TRUE); memDCTemplate.SelectObject(wxNullBitmap); wxImage completeImage = templateBitmap.ConvertToImage(); int saveImageType = wxDetermineImageType(m_outputFilename); if (saveImageType == -1) { wxLogMessage(wxT("Sorry, unknown output image file type.")); return FALSE; } ((MyFrame*) GetTopWindow())->m_viewerWindow->SetBitmap(templateBitmap); // TODO: get the depth from the original image, and set for this image. // May have to do explicit image reduction for this to work. if (!completeImage.SaveFile(m_outputFilename, saveImageType)) { wxString msg; msg.Printf(wxT("Sorry, could not save image to %s"), (const wxChar*) m_outputFilename); wxLogMessage(msg); return FALSE; } #if 0 if (wxTheClipboard->Open()) { wxTheClipboard->Clear(); wxTheClipboard->SetData(new wxBitmapDataObject(bitmap2)); wxTheClipboard->Close(); } #endif return TRUE; }