OpenClonk
C4LoaderScreen Class Reference

#include <C4LoaderScreen.h>

Collaboration diagram for C4LoaderScreen:
[legend]

Public Types

enum  Flag : int {
  BLACK = 0x00, BACKGROUND = 0x01, TITLE = 0x02, PROGRESS = 0x04,
  LOG = 0x08, PROCESS = 0x0f, ALL = 0xFF
}
 

Public Member Functions

 C4LoaderScreen ()
 
 ~C4LoaderScreen ()
 
bool Init (std::string szLoaderSpec)
 
void SetBlackScreen (bool fIsBlack)
 
void Draw (C4Facet &cgo, Flag options=Flag::ALL, int iProgress=0, class C4LogBuffer *pLog=nullptr, int Process=0)
 

Protected Member Functions

void SeekLoaderScreens (C4Group &rFromGrp, const std::string &wildcard)
 

Protected Attributes

C4FacetSurface fctBackground
 
char * szInfo
 
bool fBlackScreen
 
std::map< C4Group *, const std::string > loaders
 

Detailed Description

Definition at line 24 of file C4LoaderScreen.h.

Member Enumeration Documentation

◆ Flag

Enumerator
BLACK 
BACKGROUND 
TITLE 
PROGRESS 
LOG 
PROCESS 
ALL 

Definition at line 27 of file C4LoaderScreen.h.

27  : int {
28  BLACK = 0x00,
29  BACKGROUND = 0x01,
30  TITLE = 0x02,
31  PROGRESS = 0x04,
32  LOG = 0x08,
33  PROCESS = 0x0f,
34 
35  // All of the above
36  ALL = 0xFF
37  };

Constructor & Destructor Documentation

◆ C4LoaderScreen()

C4LoaderScreen::C4LoaderScreen ( )

Definition at line 29 of file C4LoaderScreen.cpp.

References fBlackScreen, and szInfo.

30 {
31  // zero fields
32  szInfo=nullptr;
33  fBlackScreen = false;
34 }

◆ ~C4LoaderScreen()

C4LoaderScreen::~C4LoaderScreen ( )

Definition at line 36 of file C4LoaderScreen.cpp.

References szInfo.

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

Member Function Documentation

◆ Draw()

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

Definition at line 118 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(), and C4GUI::Screen::Draw().

119 {
120  // simple black screen loader?
121  if (fBlackScreen || options == Flag::BLACK)
122  {
123  pDraw->FillBG();
124  return;
125  }
126  // cgo.X/Y is assumed 0 here...
127  // fixed positions for now
128  int iHIndent=20;
129  int iVIndent=20;
130  int iLogBoxHgt=84;
131  int iLogBoxMargin=2;
132  int iVMargin=5;
133  int iProgressBarHgt=15;
136  float fLogBoxFontZoom=1.0f;
137 
138  if (options & Flag::BACKGROUND) {
139  // Background (loader)
141  }
142 
143  if (options & Flag::TITLE) {
144  // draw scenario title
145  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);
146  }
147 
148  if (options & Flag::PROGRESS) {
149  // draw progress bar
150  pDraw->DrawBoxDw(cgo.Surface, iHIndent, cgo.Hgt - iVIndent - iLogBoxHgt - iVMargin - iProgressBarHgt, cgo.Wdt - iHIndent, cgo.Hgt - iVIndent - iLogBoxHgt - iVMargin, 0xb0000000);
151  int iProgressBarWdt = cgo.Wdt - iHIndent * 2 - 2;
153  {
154  ::GraphicsResource.fctProgressBar.DrawX(cgo.Surface, iHIndent + 1, cgo.Hgt - iVIndent - iLogBoxHgt - iVMargin - iProgressBarHgt + 1, iProgressBarWdt*iProgress / 100, iProgressBarHgt - 2);
155  }
156  else
157  {
158  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);
159  }
160  pDraw->StringOut(FormatString("%i%%", iProgress).getData(), rProgressBarFont, 1.0f, cgo.Surface,
161  cgo.Wdt / 2, cgo.Hgt - iVIndent - iLogBoxHgt - iVMargin - rProgressBarFont.GetLineHeight() / 2 - iProgressBarHgt / 2, 0xffffffff,
162  ACenter, true);
163  }
164 
165  if (options & Flag::LOG) {
166  // draw log box
167  if (pLog)
168  {
169  pDraw->DrawBoxDw(cgo.Surface, iHIndent, cgo.Hgt - iVIndent - iLogBoxHgt, cgo.Wdt - iHIndent, cgo.Hgt - iVIndent, 0x7f000000);
170  int iLineHgt = int(fLogBoxFontZoom*LogFont.GetLineHeight()); if (!iLineHgt) iLineHgt = 5;
171  int iLinesVisible = (iLogBoxHgt - 2 * iLogBoxMargin) / iLineHgt;
172  int iX = iHIndent + iLogBoxMargin;
173  int iY = cgo.Hgt - iVIndent - iLogBoxHgt + iLogBoxMargin;
174  int32_t w, h;
175  for (int i = -iLinesVisible; i < 0; ++i)
176  {
177  const char *szLine = pLog->GetLine(i, nullptr, nullptr, nullptr);
178  if (!szLine || !*szLine) continue;
179  LogFont.GetTextExtent(szLine, w, h, true);
180  pDraw->TextOut(szLine, LogFont, fLogBoxFontZoom, cgo.Surface, iX, iY);
181  iY += h;
182  }
183 
184  if (options & Flag::PROCESS) {
185  // append process text
186  if (Process)
187  {
188  iY -= h; iX += w;
189  pDraw->TextOut(FormatString("%i%%", (int)Process).getData(), LogFont, fLogBoxFontZoom, cgo.Surface, iX, iY);
190  }
191  }
192  }
193  }
194 }
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 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
const char * getData() const
Definition: StdBuf.h:442
virtual void FillBG(DWORD dwClr=0)=0
float Hgt
Definition: C4Facet.h:118
int GetLineHeight() const
Definition: C4FontLoader.h:125
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
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:

◆ Init()

bool C4LoaderScreen::Init ( std::string  szLoaderSpec)

Definition at line 42 of file C4LoaderScreen.cpp.

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

Referenced by C4GraphicsSystem::InitLoaderScreen().

43 {
44  // Determine loader specification
45  if (loaderSpec.empty())
46  loaderSpec = "Loader*";
47 
48  C4Group *pGroup = nullptr;
49  // query groups of equal priority in set
50  while ((pGroup=Game.GroupSet.FindGroup(C4GSCnt_Loaders, pGroup, true)))
51  {
52  SeekLoaderScreens(*pGroup, loaderSpec);
53  }
54  // nothing found? seek in main gfx grp
55  C4Group GfxGrp;
56  if (loaders.empty())
57  {
58  // open it
59  GfxGrp.Close();
60  if (!Reloc.Open(GfxGrp, C4CFN_Graphics))
61  {
62  LogFatal(FormatString(LoadResStr("IDS_PRC_NOGFXFILE"),C4CFN_Graphics,GfxGrp.GetError()).getData());
63  return false;
64  }
65  // seek for loaders
66  SeekLoaderScreens(GfxGrp, loaderSpec);
67 
68  // Still nothing found: fall back to general loader spec in main graphics group
69  if (loaders.empty())
70  {
71  SeekLoaderScreens(GfxGrp, "Loader*");
72  }
73  // Not even default loaders available? Fail.
74  if (loaders.empty())
75  {
76  LogFatal(FormatString("No loaders found for loader specification: %s", loaderSpec.c_str()).getData());
77  return false;
78  }
79  }
80 
81  // choose random loader
82  auto entry = loaders.begin();
83  std::advance(entry, UnsyncedRandom(loaders.size()));
84 
85  // load loader
87  if (!fctBackground.Load(*(entry->first), entry->second.c_str(), C4FCT_Full, C4FCT_Full, true, 0)) return false;
88 
89  // load info
90  if (szInfo) { delete [] szInfo; szInfo=nullptr; }
91 
92  // done, success!
93  return true;
94 }
C4FacetSurface fctBackground
C4Game Game
Definition: C4Globals.cpp:52
uint32_t UnsyncedRandom()
Definition: C4Random.cpp:58
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 C4GSCnt_Loaders
Definition: C4GroupSet.h:35
const char * LoadResStr(const char *id)
Definition: C4Language.h:83
bool Close()
Definition: C4Group.cpp:755
bool LogFatal(const char *szMessage)
Definition: C4Log.cpp:237
C4Reloc Reloc
Definition: C4Reloc.cpp:21
#define C4CFN_Graphics
Definition: C4Components.h:28
const char * GetError()
Definition: C4Group.cpp:504
std::map< C4Group *, const std::string > loaders
C4Group * FindGroup(int32_t Contents, C4Group *pAfter=nullptr, bool fSamePrio=false)
Definition: C4GroupSet.cpp:155
bool Open(C4Group &hGroup, const char *filename) const
Definition: C4Reloc.cpp:82
void SeekLoaderScreens(C4Group &rFromGrp, const std::string &wildcard)
void SetBackground()
Definition: C4Surface.h:92
const int C4FCT_Full
Definition: C4FacetEx.h:26
C4Surface & GetFace()
Definition: C4FacetEx.h:52
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:

◆ SeekLoaderScreens()

void C4LoaderScreen::SeekLoaderScreens ( C4Group rFromGrp,
const std::string &  wildcard 
)
protected

Definition at line 103 of file C4LoaderScreen.cpp.

References _MAX_PATH, C4Group::FindEntry(), C4Group::FindNextEntry(), GetExtension(), and loaders.

Referenced by Init().

104 {
105  // seek for png, jpg, jpeg, bmp
106  char filename[_MAX_PATH + 1];
107  for (bool found = rFromGrp.FindEntry(wildcard.c_str(), filename); found; found = rFromGrp.FindNextEntry(wildcard.c_str(), filename))
108  {
109  // potential candidate - check file extension
110  std::string extension{ GetExtension(filename) };
111  std::transform(extension.begin(), extension.end(), extension.begin(), ::tolower);
112  if (extension == "png" || extension == "jpg" || extension == "jpeg" || extension == "bmp") {
113  loaders.emplace(&rFromGrp, std::string(filename));
114  }
115  }
116 }
bool FindEntry(const char *szWildCard, StdStrBuf *sFileName=nullptr, size_t *iSize=nullptr)
Definition: C4Group.cpp:1774
#define _MAX_PATH
char * GetExtension(char *szFilename)
Definition: StdFile.cpp:121
std::map< C4Group *, const std::string > loaders
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:

◆ SetBlackScreen()

void C4LoaderScreen::SetBlackScreen ( bool  fIsBlack)

Definition at line 96 of file C4LoaderScreen.cpp.

References fBlackScreen.

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

97 {
98  // enabled/disables drawing of loader screen
99  fBlackScreen = fIsBlack;
100  // will be updated when drawn next time
101 }
Here is the caller graph for this function:

Member Data Documentation

◆ fBlackScreen

bool C4LoaderScreen::fBlackScreen
protected

Definition at line 42 of file C4LoaderScreen.h.

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

◆ fctBackground

C4FacetSurface C4LoaderScreen::fctBackground
protected

Definition at line 40 of file C4LoaderScreen.h.

Referenced by Draw(), and Init().

◆ loaders

std::map<C4Group*, const std::string> C4LoaderScreen::loaders
protected

Definition at line 44 of file C4LoaderScreen.h.

Referenced by Init(), and SeekLoaderScreens().

◆ szInfo

char* C4LoaderScreen::szInfo
protected

Definition at line 41 of file C4LoaderScreen.h.

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


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