2 * Copyright (C) 2005-2013 Team XBMC
5 * This Program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2, or (at your option)
10 * This Program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with XBMC; see the file COPYING. If not, see
17 * <http://www.gnu.org/licenses/>.
23 #include "guilib/GUIImage.h"
24 #include "guilib/GUILabelControl.h"
25 #include "guilib/GUIFontManager.h"
26 #include "filesystem/File.h"
27 #include "windowing/WindowingFactory.h"
28 #include "rendering/RenderSystem.h"
31 using namespace XFILE;
33 CSplash::CSplash(const CStdString& imageName) : CThread("Splash")
35 m_ImageName = imageName;
37 m_messageLayout = NULL;
39 m_layoutWasLoading = false;
47 delete m_messageLayout;
50 void CSplash::OnStartup()
53 void CSplash::OnExit()
61 void CSplash::Show(const CStdString& message)
63 g_graphicsContext.Lock();
64 g_graphicsContext.Clear();
66 RESOLUTION_INFO res(1280,720,0);
67 g_graphicsContext.SetRenderingResolution(res, true);
70 m_image = new CGUIImage(0, 0, 0, 0, 1280, 720, m_ImageName);
71 m_image->SetAspectRatio(CAspectRatio::AR_CENTER);
75 g_Windowing.BeginRender();
77 m_image->AllocResources();
79 m_image->FreeResources();
84 if (!m_layoutWasLoading)
86 // load arial font, white body, no shadow, size: 20, no additional styling
87 CGUIFont *messageFont = g_fontManager.LoadTTF("__splash__", "arial.ttf", 0xFFFFFFFF, 0, 20, FONT_STYLE_NORMAL, false, 1.0f, 1.0f, &res);
89 m_messageLayout = new CGUITextLayout(messageFont, true, 0);
90 m_layoutWasLoading = true;
94 m_messageLayout->Update(message, 1150, false, true);
96 float textWidth, textHeight;
97 m_messageLayout->GetTextExtent(textWidth, textHeight);
98 // ideally place text in center of empty area below splash image
99 float y = 540 + m_image->GetTextureHeight() / 4 - textHeight / 2;
100 if (y + textHeight > 720) // make sure entire text is visible
101 y = 720 - textHeight;
103 m_messageLayout->RenderOutline(640, y, 0, 0xFF000000, XBFONT_CENTER_X, 1280);
108 g_Windowing.EndRender();
109 CDirtyRegionList dirty;
110 g_graphicsContext.Flip(dirty);
111 g_graphicsContext.Unlock();
118 void CSplash::Process()
123 bool CSplash::Start()
125 if (m_ImageName.empty() || !CFile::Exists(m_ImageName))
127 CLog::Log(LOGDEBUG, "Splash image %s not found", m_ImageName.c_str());