Merge pull request #4676 from jmarshallnz/dont_set_scraper_on_tvshow_on_nfo
[vuplus_xbmc] / xbmc / utils / Splash.cpp
1 /*
2  *      Copyright (C) 2005-2013 Team XBMC
3  *      http://xbmc.org
4  *
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)
8  *  any later version.
9  *
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.
14  *
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/>.
18  *
19  */
20
21 #include "system.h"
22 #include "Splash.h"
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"
29 #include "log.h"
30
31 using namespace XFILE;
32
33 CSplash::CSplash(const CStdString& imageName) : CThread("Splash")
34 {
35   m_ImageName = imageName;
36   fade = 0.5;
37   m_messageLayout = NULL;
38   m_image = NULL;
39   m_layoutWasLoading = false;
40 }
41
42
43 CSplash::~CSplash()
44 {
45   Stop();
46   delete m_image;
47   delete m_messageLayout;
48 }
49
50 void CSplash::OnStartup()
51 {}
52
53 void CSplash::OnExit()
54 {}
55
56 void CSplash::Show()
57 {
58   Show("");
59 }
60
61 void CSplash::Show(const CStdString& message)
62 {
63   g_graphicsContext.Lock();
64   g_graphicsContext.Clear();
65
66   RESOLUTION_INFO res(1280,720,0);
67   g_graphicsContext.SetRenderingResolution(res, true);  
68   if (!m_image)
69   {
70     m_image = new CGUIImage(0, 0, 0, 0, 1280, 720, m_ImageName);
71     m_image->SetAspectRatio(CAspectRatio::AR_CENTER);
72   }
73
74   //render splash image
75   g_Windowing.BeginRender();
76
77   m_image->AllocResources();
78   m_image->Render();
79   m_image->FreeResources();
80
81   // render message
82   if (!message.empty())
83   {
84     if (!m_layoutWasLoading)
85     {
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);
88       if (messageFont)
89         m_messageLayout = new CGUITextLayout(messageFont, true, 0);
90       m_layoutWasLoading = true;
91     }
92     if (m_messageLayout)
93     {
94       m_messageLayout->Update(message, 1150, false, true);
95
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;
102
103       m_messageLayout->RenderOutline(640, y, 0, 0xFF000000, XBFONT_CENTER_X, 1280);
104     }
105   }
106
107   //show it on screen
108   g_Windowing.EndRender();
109   CDirtyRegionList dirty;
110   g_graphicsContext.Flip(dirty);
111   g_graphicsContext.Unlock();
112 }
113
114 void CSplash::Hide()
115 {
116 }
117
118 void CSplash::Process()
119 {
120   Show();
121 }
122
123 bool CSplash::Start()
124 {
125   if (m_ImageName.empty() || !CFile::Exists(m_ImageName))
126   {
127     CLog::Log(LOGDEBUG, "Splash image %s not found", m_ImageName.c_str());
128     return false;
129   }
130   Create();
131   return true;
132 }
133
134 void CSplash::Stop()
135 {
136   StopThread();
137 }