Show using dynamic splash screen contents in the sample

Demonstrate how dynamic information can be shown in the splash screen
overlaying the static bitmap.

Closes https://github.com/wxWidgets/wxWidgets/pull/958
This commit is contained in:
Blake Eryx 2018-10-02 20:26:49 -04:00 committed by Vadim Zeitlin
parent 28f7e6130d
commit c1a2d2c967

View File

@ -62,6 +62,8 @@ public:
// initialization (doing it here and not in the ctor allows to have an error
// return: if OnInit() returns false, the application terminates)
virtual bool OnInit() wxOVERRIDE;
void DecorateSplashScreen(wxBitmap& bmp);
};
// Define a new frame type: this is going to be our main frame
@ -141,6 +143,10 @@ bool MyApp::OnInit()
if (ok)
{
// we can even draw dynamic artwork onto our splashscreen
DecorateSplashScreen(bitmap);
// show the splashscreen
new wxSplashScreen(bitmap,
wxSPLASH_CENTRE_ON_SCREEN|wxSPLASH_TIMEOUT,
6000, frame, wxID_ANY, wxDefaultPosition, wxDefaultSize,
@ -162,6 +168,41 @@ bool MyApp::OnInit()
return true;
}
// Draws artwork onto our splashscreen at runtime
void MyApp::DecorateSplashScreen(wxBitmap& bmp)
{
// use a memory DC to draw directly onto the bitmap
wxMemoryDC memDc(bmp);
// draw an orange box (with black outline) at the bottom of the splashscreen.
// this box will be 10% of the height of the bitmap, and be at the bottom.
const wxRect bannerRect(wxPoint(0, (bmp.GetHeight() / 10)*9),
wxPoint(bmp.GetWidth(), bmp.GetHeight()));
wxDCBrushChanger bc(memDc, wxBrush(wxColour(255, 102, 0)));
memDc.DrawRectangle(bannerRect);
memDc.DrawLine(bannerRect.GetTopLeft(), bannerRect.GetTopRight());
// dynamically get the wxWidgets version to display
wxString description = wxString::Format("wxWidgets %s", wxVERSION_NUM_DOT_STRING);
// create a copyright notice that uses the year that this file was compiled
wxString year(__DATE__);
wxString copyrightLabel = wxString::Format("%s%s wxWidgets. %s",
wxString::FromUTF8("\xc2\xa9"), year.Mid(year.Length() - 4),
"All rights reserved.");
// draw the (white) labels inside of our orange box (at the bottom of the splashscreen)
memDc.SetTextForeground(*wxWHITE);
// draw the "wxWidget" label on the left side, vertically centered.
// note that we deflate the banner rect a little bit horizontally
// so that the text has some padding to its left.
memDc.DrawLabel(description, bannerRect.Deflate(5, 0), wxALIGN_CENTRE_VERTICAL|wxALIGN_LEFT);
// draw the copyright label on the right side
memDc.SetFont(wxFontInfo(8));
memDc.DrawLabel(copyrightLabel, bannerRect.Deflate(5, 0), wxALIGN_CENTRE_VERTICAL | wxALIGN_RIGHT);
}
// ----------------------------------------------------------------------------
// main frame
// ----------------------------------------------------------------------------