OpenClonk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
C4LoaderScreen Class Reference

#include <C4LoaderScreen.h>

Collaboration diagram for C4LoaderScreen:
[legend]

Public Member Functions

 C4LoaderScreen ()
 
 ~C4LoaderScreen ()
 
bool Init (const char *szLoaderSpec)
 
void SetBlackScreen (bool fIsBlack)
 
int SeekLoaderScreens (C4Group &rFromGrp, const char *szWildcard, int iLoaderCount, char *szDstName, C4Group **ppDestGrp)
 
void Draw (C4Facet &cgo, int iProgress=0, class C4LogBuffer *pLog=nullptr, int Process=0)
 

Public Attributes

C4FacetSurface fctBackground
 
char * szInfo
 
bool fBlackScreen
 

Detailed Description

Definition at line 23 of file C4LoaderScreen.h.

Constructor & Destructor Documentation

C4LoaderScreen::C4LoaderScreen ( )

Definition at line 28 of file C4LoaderScreen.cpp.

References fBlackScreen, and szInfo.

29 {
30  // zero fields
31  szInfo=nullptr;
32  fBlackScreen = false;
33 }
C4LoaderScreen::~C4LoaderScreen ( )

Definition at line 35 of file C4LoaderScreen.cpp.

References szInfo.

36 {
37  // clear fields
38  if (szInfo) delete [] szInfo;
39 }

Member Function Documentation

void C4LoaderScreen::Draw ( C4Facet cgo,
int  iProgress = 0,
class C4LogBuffer pLog = nullptr,
int  Process = 0 
)

Definition at line 135 of file C4LoaderScreen.cpp.

References ACenter, ARight, C4Draw::DrawBoxDw(), C4Facet::DrawFullScreen(), C4Facet::DrawX(), fBlackScreen, fctBackground, C4GraphicsResource::fctProgressBar, C4Draw::FillBG(), C4GraphicsResource::FontRegular, C4GraphicsResource::FontTiny, C4GraphicsResource::FontTitle, FormatString(), Game, StdStrBuf::getData(), C4LogBuffer::GetLine(), CStdFont::GetLineHeight(), CStdFont::GetTextExtent(), GraphicsResource, C4Facet::Hgt, pDraw, C4Game::ScenarioTitle, C4Draw::StringOut(), C4Facet::Surface, C4Draw::TextOut(), and C4Facet::Wdt.

Referenced by C4MessageBoard::Draw().

136 {
137  // simple black screen loader?
138  if (fBlackScreen)
139  {
140  pDraw->FillBG();
141  return;
142  }
143  // cgo.X/Y is assumed 0 here...
144  // fixed positions for now
145  int iHIndent=20;
146  int iVIndent=20;
147  int iLogBoxHgt=84;
148  int iLogBoxMargin=2;
149  int iVMargin=5;
150  int iProgressBarHgt=15;
153  float fLogBoxFontZoom=1.0f;
154  // Background (loader)
156  // draw scenario title
157  pDraw->StringOut(Game.ScenarioTitle.getData(), TitleFont, 1.0f, cgo.Surface, cgo.Wdt-iHIndent, cgo.Hgt-iVIndent-iLogBoxHgt-iVMargin-iProgressBarHgt-iVMargin-TitleFont.GetLineHeight(), 0xdddddddd, ARight, false);
158  //
159  // draw progress bar
160  pDraw->DrawBoxDw(cgo.Surface, iHIndent, cgo.Hgt-iVIndent-iLogBoxHgt-iVMargin-iProgressBarHgt, cgo.Wdt-iHIndent, cgo.Hgt-iVIndent-iLogBoxHgt-iVMargin, 0xb0000000);
161  int iProgressBarWdt=cgo.Wdt-iHIndent*2-2;
163  {
164  ::GraphicsResource.fctProgressBar.DrawX(cgo.Surface, iHIndent+1, cgo.Hgt-iVIndent-iLogBoxHgt-iVMargin-iProgressBarHgt+1, iProgressBarWdt*iProgress/100, iProgressBarHgt-2);
165  }
166  else
167  {
168  pDraw->DrawBoxDw(cgo.Surface, iHIndent+1, cgo.Hgt-iVIndent-iLogBoxHgt-iVMargin-iProgressBarHgt+1, iHIndent+1+iProgressBarWdt*iProgress/100, cgo.Hgt-iVIndent-iLogBoxHgt-iVMargin-1, 0xb0ff0000);
169  }
170  pDraw->StringOut(FormatString("%i%%", iProgress).getData(), rProgressBarFont, 1.0f, cgo.Surface,
171  cgo.Wdt/2, cgo.Hgt-iVIndent-iLogBoxHgt-iVMargin-rProgressBarFont.GetLineHeight()/2-iProgressBarHgt/2, 0xffffffff,
172  ACenter, true);
173  // draw log box
174  if (pLog)
175  {
176  pDraw->DrawBoxDw(cgo.Surface, iHIndent, cgo.Hgt-iVIndent-iLogBoxHgt, cgo.Wdt-iHIndent, cgo.Hgt-iVIndent, 0x7f000000);
177  int iLineHgt=int(fLogBoxFontZoom*LogFont.GetLineHeight()); if (!iLineHgt) iLineHgt=5;
178  int iLinesVisible = (iLogBoxHgt-2*iLogBoxMargin)/iLineHgt;
179  int iX = iHIndent+iLogBoxMargin;
180  int iY = cgo.Hgt-iVIndent-iLogBoxHgt+iLogBoxMargin;
181  int32_t w,h;
182  for (int i = -iLinesVisible; i < 0; ++i)
183  {
184  const char *szLine = pLog->GetLine(i, nullptr, nullptr, nullptr);
185  if (!szLine || !*szLine) continue;
186  LogFont.GetTextExtent(szLine, w,h, true);
187  pDraw->TextOut(szLine,LogFont,fLogBoxFontZoom,cgo.Surface,iX,iY);
188  iY += h;
189  }
190  // append process text
191  if (Process)
192  {
193  iY -= h; iX += w;
194  pDraw->TextOut(FormatString("%i%%", (int) Process).getData(),LogFont,fLogBoxFontZoom,cgo.Surface,iX,iY);
195  }
196  }
197 }
const char * getData() const
Definition: StdBuf.h:442
int GetLineHeight() const
Definition: C4FontLoader.h:125
C4FacetSurface fctBackground
C4Game Game
Definition: C4Globals.cpp:52
StdCopyStrBuf ScenarioTitle
Definition: C4Game.h:103
bool TextOut(const char *szText, CStdFont &rFont, float fZoom, C4Surface *sfcDest, float iTx, float iTy, DWORD dwFCol=0xffffffff, BYTE byForm=ALeft, bool fDoMarkup=true)
Definition: C4Draw.cpp:567
const int ARight
Definition: C4Surface.h:41
bool GetTextExtent(const char *szText, int32_t &rsx, int32_t &rsy, bool fCheckMarkup=true)
C4GraphicsResource GraphicsResource
bool StringOut(const char *szText, CStdFont &rFont, float fZoom, C4Surface *sfcDest, float iTx, float iTy, DWORD dwFCol=0xffffffff, BYTE byForm=ALeft, bool fDoMarkup=true)
Definition: C4Draw.cpp:576
const int ACenter
Definition: C4Surface.h:41
void DrawX(C4Surface *sfcTarget, float iX, float iY, float iWdt, float iHgt, int32_t iPhaseX=0, int32_t iPhaseY=0) const
Definition: C4Facet.cpp:358
void DrawBoxDw(C4Surface *sfcDest, int iX1, int iY1, int iX2, int iY2, DWORD dwClr)
Definition: C4Draw.cpp:846
C4Draw * pDraw
Definition: C4Draw.cpp:42
void DrawFullScreen(C4Facet &cgo)
Definition: C4Facet.cpp:184
virtual void FillBG(DWORD dwClr=0)=0
float Hgt
Definition: C4Facet.h:118
C4Surface * Surface
Definition: C4Facet.h:117
float Wdt
Definition: C4Facet.h:118
StdStrBuf FormatString(const char *szFmt,...)
Definition: StdBuf.cpp:270

Here is the call graph for this function:

Here is the caller graph for this function:

bool C4LoaderScreen::Init ( const char *  szLoaderSpec)

Definition at line 41 of file C4LoaderScreen.cpp.

References _MAX_PATH, C4CFN_Graphics, C4FCT_Full, C4GSCnt_Loaders, C4Group::Close(), DefaultExtension(), fctBackground, C4GroupSet::FindGroup(), FormatString(), Game, C4Group::GetError(), C4FacetSurface::GetFace(), C4Game::GroupSet, C4FacetSurface::Load(), LoadResStr(), LogFatal(), C4Reloc::Open(), Reloc, SCopy(), SeekLoaderScreens(), C4Surface::SetBackground(), and szInfo.

Referenced by C4GraphicsSystem::InitLoaderScreen().

42 {
43  // Determine loader specification
44  if (!szLoaderSpec || !szLoaderSpec[0])
45  szLoaderSpec = "Loader*";
46  char szLoaderSpecPng[128 + 1 + 4], szLoaderSpecBmp[128 + 1 + 4];
47  char szLoaderSpecJpg[128 + 1 + 4], szLoaderSpecJpeg[128 + 1 + 5];
48  SCopy(szLoaderSpec, szLoaderSpecPng); DefaultExtension(szLoaderSpecPng, "png");
49  SCopy(szLoaderSpec, szLoaderSpecBmp); DefaultExtension(szLoaderSpecBmp, "bmp");
50  SCopy(szLoaderSpec, szLoaderSpecJpg); DefaultExtension(szLoaderSpecJpg, "jpg");
51  SCopy(szLoaderSpec, szLoaderSpecJpeg); DefaultExtension(szLoaderSpecJpeg, "jpeg");
52  int iLoaders=0;
53  C4Group *pGroup=nullptr,*pChosenGrp=nullptr;
54  char ChosenFilename[_MAX_PATH+1];
55  // query groups of equal priority in set
56  while ((pGroup=Game.GroupSet.FindGroup(C4GSCnt_Loaders, pGroup, true)))
57  {
58  iLoaders+=SeekLoaderScreens(*pGroup, szLoaderSpecPng, iLoaders, ChosenFilename, &pChosenGrp);
59  iLoaders+=SeekLoaderScreens(*pGroup, szLoaderSpecJpeg, iLoaders, ChosenFilename, &pChosenGrp);
60  iLoaders+=SeekLoaderScreens(*pGroup, szLoaderSpecJpg, iLoaders, ChosenFilename, &pChosenGrp);
61  // lower the chance for any loader other than png
62  iLoaders*=2;
63  iLoaders+=SeekLoaderScreens(*pGroup, szLoaderSpecBmp, iLoaders, ChosenFilename, &pChosenGrp);
64  }
65  // nothing found? seek in main gfx grp
66  C4Group GfxGrp;
67  if (!iLoaders)
68  {
69  // open it
70  GfxGrp.Close();
71  if (!Reloc.Open(GfxGrp, C4CFN_Graphics))
72  {
73  LogFatal(FormatString(LoadResStr("IDS_PRC_NOGFXFILE"),C4CFN_Graphics,GfxGrp.GetError()).getData());
74  return false;
75  }
76  // seek for png-loaders
77  iLoaders=SeekLoaderScreens(GfxGrp, szLoaderSpecPng, iLoaders, ChosenFilename, &pChosenGrp);
78  iLoaders+=SeekLoaderScreens(GfxGrp, szLoaderSpecJpg, iLoaders, ChosenFilename, &pChosenGrp);
79  iLoaders+=SeekLoaderScreens(GfxGrp, szLoaderSpecJpeg, iLoaders, ChosenFilename, &pChosenGrp);
80  iLoaders*=2;
81  // seek for bmp-loaders
82  iLoaders+=SeekLoaderScreens(GfxGrp, szLoaderSpecBmp, iLoaders, ChosenFilename, &pChosenGrp);
83  // Still nothing found: fall back to general loader spec in main graphics group
84  if (!iLoaders)
85  {
86  iLoaders = SeekLoaderScreens(GfxGrp, "Loader*.png", 0, ChosenFilename, &pChosenGrp);
87  iLoaders += SeekLoaderScreens(GfxGrp, "Loader*.jpg", iLoaders, ChosenFilename, &pChosenGrp);
88  iLoaders += SeekLoaderScreens(GfxGrp, "Loader*.jpeg", iLoaders, ChosenFilename, &pChosenGrp);
89  }
90  // Not even default loaders available? Fail.
91  if (!iLoaders)
92  {
93  LogFatal(FormatString("No loaders found for loader specification: %s/%s/%s/%s", szLoaderSpecPng, szLoaderSpecBmp, szLoaderSpecJpg, szLoaderSpecJpeg).getData());
94  return false;
95  }
96  }
97 
98  // load loader
100  if (!fctBackground.Load(*pChosenGrp,ChosenFilename, C4FCT_Full,C4FCT_Full,true,0)) return false;
101 
102  // load info
103  if (szInfo) { delete [] szInfo; szInfo=nullptr; }
104 
105  // done, success!
106  return true;
107 }
void SCopy(const char *szSource, char *sTarget, size_t iMaxL)
Definition: Standard.cpp:152
C4FacetSurface fctBackground
C4Game Game
Definition: C4Globals.cpp:52
C4GroupSet GroupSet
Definition: C4Game.h:87
bool Load(C4Group &hGroup, const char *szName, int iWdt, int iHgt, bool fNoErrIfNotFound, int iFlags)
Definition: C4FacetEx.cpp:78
#define _MAX_PATH
#define C4GSCnt_Loaders
Definition: C4GroupSet.h:35
const char * LoadResStr(const char *id)
Definition: C4Language.h:83
bool Close()
Definition: C4Group.cpp:755
bool Open(C4Group &hGroup, const char *filename) const
Definition: C4Reloc.cpp:82
bool LogFatal(const char *szMessage)
Definition: C4Log.cpp:227
void DefaultExtension(char *szFilename, const char *szExtension)
Definition: StdFile.cpp:274
C4Reloc Reloc
Definition: C4Reloc.cpp:21
#define C4CFN_Graphics
Definition: C4Components.h:28
const char * GetError()
Definition: C4Group.cpp:504
C4Group * FindGroup(int32_t Contents, C4Group *pAfter=nullptr, bool fSamePrio=false)
Definition: C4GroupSet.cpp:155
void SetBackground()
Definition: C4Surface.h:92
const int C4FCT_Full
Definition: C4FacetEx.h:26
C4Surface & GetFace()
Definition: C4FacetEx.h:52
int SeekLoaderScreens(C4Group &rFromGrp, const char *szWildcard, int iLoaderCount, char *szDstName, C4Group **ppDestGrp)
StdStrBuf FormatString(const char *szFmt,...)
Definition: StdBuf.cpp:270

Here is the call graph for this function:

Here is the caller graph for this function:

int C4LoaderScreen::SeekLoaderScreens ( C4Group rFromGrp,
const char *  szWildcard,
int  iLoaderCount,
char *  szDstName,
C4Group **  ppDestGrp 
)

Definition at line 116 of file C4LoaderScreen.cpp.

References _MAX_PATH, C4Group::FindEntry(), C4Group::FindNextEntry(), SCopy(), and UnsyncedRandom().

Referenced by Init().

117 {
118  bool fFound;
119  int iLocalLoaders=0;
120  char Filename[_MAX_PATH+1];
121  for (fFound=rFromGrp.FindEntry(szWildcard, Filename); fFound; fFound=rFromGrp.FindNextEntry(szWildcard, Filename))
122  {
123  // loader found; choose it, if Daniel wants it that way
124  ++iLocalLoaders;
125  if (!UnsyncedRandom(++iLoaderCount))
126  {
127  // copy group and path
128  *ppDestGrp=&rFromGrp;
129  SCopy(Filename, szDstName, _MAX_PATH);
130  }
131  }
132  return iLocalLoaders;
133 }
bool FindEntry(const char *szWildCard, StdStrBuf *sFileName=nullptr, size_t *iSize=nullptr)
Definition: C4Group.cpp:1774
void SCopy(const char *szSource, char *sTarget, size_t iMaxL)
Definition: Standard.cpp:152
uint32_t UnsyncedRandom()
Definition: C4Random.cpp:58
#define _MAX_PATH
bool FindNextEntry(const char *szWildCard, StdStrBuf *sFileName=nullptr, size_t *iSize=nullptr, bool fStartAtFilename=false)
Definition: C4Group.cpp:1780

Here is the call graph for this function:

Here is the caller graph for this function:

void C4LoaderScreen::SetBlackScreen ( bool  fIsBlack)

Definition at line 109 of file C4LoaderScreen.cpp.

References fBlackScreen.

Referenced by C4GraphicsSystem::EnableLoaderDrawing(), and C4GraphicsSystem::InitLoaderScreen().

110 {
111  // enabled/disables drawing of loader screen
112  fBlackScreen = fIsBlack;
113  // will be updated when drawn next time
114 }

Here is the caller graph for this function:

Member Data Documentation

bool C4LoaderScreen::fBlackScreen

Definition at line 28 of file C4LoaderScreen.h.

Referenced by C4LoaderScreen(), Draw(), and SetBlackScreen().

C4FacetSurface C4LoaderScreen::fctBackground

Definition at line 26 of file C4LoaderScreen.h.

Referenced by Draw(), C4GUI::Screen::Draw(), and Init().

char* C4LoaderScreen::szInfo

Definition at line 27 of file C4LoaderScreen.h.

Referenced by C4LoaderScreen(), Init(), and ~C4LoaderScreen().


The documentation for this class was generated from the following files: