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 30 of file C4LoaderScreen.cpp.

References fBlackScreen, and szInfo.

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

Definition at line 37 of file C4LoaderScreen.cpp.

References szInfo.

38 {
39  // clear fields
40  if (szInfo) delete [] szInfo;
41 }

Member Function Documentation

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

Definition at line 137 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().

138 {
139  // simple black screen loader?
140  if (fBlackScreen)
141  {
142  pDraw->FillBG();
143  return;
144  }
145  // cgo.X/Y is assumed 0 here...
146  // fixed positions for now
147  int iHIndent=20;
148  int iVIndent=20;
149  int iLogBoxHgt=84;
150  int iLogBoxMargin=2;
151  int iVMargin=5;
152  int iProgressBarHgt=15;
155  float fLogBoxFontZoom=1.0f;
156  // Background (loader)
158  // draw scenario title
159  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);
160  //
161  // draw progress bar
162  pDraw->DrawBoxDw(cgo.Surface, iHIndent, cgo.Hgt-iVIndent-iLogBoxHgt-iVMargin-iProgressBarHgt, cgo.Wdt-iHIndent, cgo.Hgt-iVIndent-iLogBoxHgt-iVMargin, 0xb0000000);
163  int iProgressBarWdt=cgo.Wdt-iHIndent*2-2;
165  {
166  ::GraphicsResource.fctProgressBar.DrawX(cgo.Surface, iHIndent+1, cgo.Hgt-iVIndent-iLogBoxHgt-iVMargin-iProgressBarHgt+1, iProgressBarWdt*iProgress/100, iProgressBarHgt-2);
167  }
168  else
169  {
170  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);
171  }
172  pDraw->StringOut(FormatString("%i%%", iProgress).getData(), rProgressBarFont, 1.0f, cgo.Surface,
173  cgo.Wdt/2, cgo.Hgt-iVIndent-iLogBoxHgt-iVMargin-rProgressBarFont.GetLineHeight()/2-iProgressBarHgt/2, 0xffffffff,
174  ACenter, true);
175  // draw log box
176  if (pLog)
177  {
178  pDraw->DrawBoxDw(cgo.Surface, iHIndent, cgo.Hgt-iVIndent-iLogBoxHgt, cgo.Wdt-iHIndent, cgo.Hgt-iVIndent, 0x7f000000);
179  int iLineHgt=int(fLogBoxFontZoom*LogFont.GetLineHeight()); if (!iLineHgt) iLineHgt=5;
180  int iLinesVisible = (iLogBoxHgt-2*iLogBoxMargin)/iLineHgt;
181  int iX = iHIndent+iLogBoxMargin;
182  int iY = cgo.Hgt-iVIndent-iLogBoxHgt+iLogBoxMargin;
183  int32_t w,h;
184  for (int i = -iLinesVisible; i < 0; ++i)
185  {
186  const char *szLine = pLog->GetLine(i, nullptr, nullptr, nullptr);
187  if (!szLine || !*szLine) continue;
188  LogFont.GetTextExtent(szLine, w,h, true);
189  pDraw->TextOut(szLine,LogFont,fLogBoxFontZoom,cgo.Surface,iX,iY);
190  iY += h;
191  }
192  // append process text
193  if (Process)
194  {
195  iY -= h; iX += w;
196  pDraw->TextOut(FormatString("%i%%", (int) Process).getData(),LogFont,fLogBoxFontZoom,cgo.Surface,iX,iY);
197  }
198  }
199 }
const char * getData() const
Definition: StdBuf.h:450
int GetLineHeight() const
Definition: C4FontLoader.h:132
C4FacetSurface fctBackground
C4Game Game
Definition: C4Globals.cpp:52
StdCopyStrBuf ScenarioTitle
Definition: C4Game.h:105
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:570
const int ARight
Definition: C4Surface.h:43
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:579
const int ACenter
Definition: C4Surface.h:43
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:849
C4Draw * pDraw
Definition: C4Draw.cpp:45
void DrawFullScreen(C4Facet &cgo)
Definition: C4Facet.cpp:184
virtual void FillBG(DWORD dwClr=0)=0
float Hgt
Definition: C4Facet.h:120
C4Surface * Surface
Definition: C4Facet.h:119
float Wdt
Definition: C4Facet.h:120
StdStrBuf FormatString(const char *szFmt,...)
Definition: StdBuf.cpp:277

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 43 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().

44 {
45  // Determine loader specification
46  if (!szLoaderSpec || !szLoaderSpec[0])
47  szLoaderSpec = "Loader*";
48  char szLoaderSpecPng[128 + 1 + 4], szLoaderSpecBmp[128 + 1 + 4];
49  char szLoaderSpecJpg[128 + 1 + 4], szLoaderSpecJpeg[128 + 1 + 5];
50  SCopy(szLoaderSpec, szLoaderSpecPng); DefaultExtension(szLoaderSpecPng, "png");
51  SCopy(szLoaderSpec, szLoaderSpecBmp); DefaultExtension(szLoaderSpecBmp, "bmp");
52  SCopy(szLoaderSpec, szLoaderSpecJpg); DefaultExtension(szLoaderSpecJpg, "jpg");
53  SCopy(szLoaderSpec, szLoaderSpecJpeg); DefaultExtension(szLoaderSpecJpeg, "jpeg");
54  int iLoaders=0;
55  C4Group *pGroup=nullptr,*pChosenGrp=nullptr;
56  char ChosenFilename[_MAX_PATH+1];
57  // query groups of equal priority in set
58  while ((pGroup=Game.GroupSet.FindGroup(C4GSCnt_Loaders, pGroup, true)))
59  {
60  iLoaders+=SeekLoaderScreens(*pGroup, szLoaderSpecPng, iLoaders, ChosenFilename, &pChosenGrp);
61  iLoaders+=SeekLoaderScreens(*pGroup, szLoaderSpecJpeg, iLoaders, ChosenFilename, &pChosenGrp);
62  iLoaders+=SeekLoaderScreens(*pGroup, szLoaderSpecJpg, iLoaders, ChosenFilename, &pChosenGrp);
63  // lower the chance for any loader other than png
64  iLoaders*=2;
65  iLoaders+=SeekLoaderScreens(*pGroup, szLoaderSpecBmp, iLoaders, ChosenFilename, &pChosenGrp);
66  }
67  // nothing found? seek in main gfx grp
68  C4Group GfxGrp;
69  if (!iLoaders)
70  {
71  // open it
72  GfxGrp.Close();
73  if (!Reloc.Open(GfxGrp, C4CFN_Graphics))
74  {
75  LogFatal(FormatString(LoadResStr("IDS_PRC_NOGFXFILE"),C4CFN_Graphics,GfxGrp.GetError()).getData());
76  return false;
77  }
78  // seek for png-loaders
79  iLoaders=SeekLoaderScreens(GfxGrp, szLoaderSpecPng, iLoaders, ChosenFilename, &pChosenGrp);
80  iLoaders+=SeekLoaderScreens(GfxGrp, szLoaderSpecJpg, iLoaders, ChosenFilename, &pChosenGrp);
81  iLoaders+=SeekLoaderScreens(GfxGrp, szLoaderSpecJpeg, iLoaders, ChosenFilename, &pChosenGrp);
82  iLoaders*=2;
83  // seek for bmp-loaders
84  iLoaders+=SeekLoaderScreens(GfxGrp, szLoaderSpecBmp, iLoaders, ChosenFilename, &pChosenGrp);
85  // Still nothing found: fall back to general loader spec in main graphics group
86  if (!iLoaders)
87  {
88  iLoaders = SeekLoaderScreens(GfxGrp, "Loader*.png", 0, ChosenFilename, &pChosenGrp);
89  iLoaders += SeekLoaderScreens(GfxGrp, "Loader*.jpg", iLoaders, ChosenFilename, &pChosenGrp);
90  iLoaders += SeekLoaderScreens(GfxGrp, "Loader*.jpeg", iLoaders, ChosenFilename, &pChosenGrp);
91  }
92  // Not even default loaders available? Fail.
93  if (!iLoaders)
94  {
95  LogFatal(FormatString("No loaders found for loader specification: %s/%s/%s/%s", szLoaderSpecPng, szLoaderSpecBmp, szLoaderSpecJpg, szLoaderSpecJpeg).getData());
96  return false;
97  }
98  }
99 
100  // load loader
102  if (!fctBackground.Load(*pChosenGrp,ChosenFilename, C4FCT_Full,C4FCT_Full,true,0)) return false;
103 
104  // load info
105  if (szInfo) { delete [] szInfo; szInfo=nullptr; }
106 
107  // done, success!
108  return true;
109 }
void SCopy(const char *szSource, char *sTarget, size_t iMaxL)
Definition: Standard.cpp:129
C4FacetSurface fctBackground
C4Game Game
Definition: C4Globals.cpp:52
C4GroupSet GroupSet
Definition: C4Game.h:89
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:69
bool LogFatal(const char *szMessage)
Definition: C4Log.cpp:230
void DefaultExtension(char *szFilename, const char *szExtension)
Definition: StdFile.cpp:284
C4Reloc Reloc
Definition: C4Reloc.cpp:22
#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:157
void SetBackground()
Definition: C4Surface.h:94
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:277

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 118 of file C4LoaderScreen.cpp.

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

Referenced by Init().

119 {
120  bool fFound;
121  int iLocalLoaders=0;
122  char Filename[_MAX_PATH+1];
123  for (fFound=rFromGrp.FindEntry(szWildcard, Filename); fFound; fFound=rFromGrp.FindNextEntry(szWildcard, Filename))
124  {
125  // loader found; choose it, if Daniel wants it that way
126  ++iLocalLoaders;
127  if (!UnsyncedRandom(++iLoaderCount))
128  {
129  // copy group and path
130  *ppDestGrp=&rFromGrp;
131  SCopy(Filename, szDstName, _MAX_PATH);
132  }
133  }
134  return iLocalLoaders;
135 }
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:129
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 111 of file C4LoaderScreen.cpp.

References fBlackScreen.

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

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

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: