Skip to content

Commit

Permalink
Support custom loading screens
Browse files Browse the repository at this point in the history
  • Loading branch information
TheGondos committed Jan 2, 2025
1 parent d4437e3 commit 203c82c
Show file tree
Hide file tree
Showing 8 changed files with 301 additions and 66 deletions.
83 changes: 57 additions & 26 deletions OVP/D3D9Client/D3D9Client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,8 @@ D3D9Client::D3D9Client (HINSTANCE hInstance) :
pWM (NULL),
pBltSkp (NULL),
pBltGrpTgt (NULL),
pCustomSplashScreen(NULL),
pSplashTextColor(0xE0A0A0),
hRenderWnd(),
scene (),
meshmgr (),
Expand Down Expand Up @@ -860,6 +862,8 @@ void D3D9Client::clbkCloseSession(bool fastclose)
if (x) x->DumpTextures();
} */
//GraphicsClient::clbkCloseSession(fastclose);
pCustomSplashScreen = NULL;
pSplashTextColor = 0xE0A0A0;

SAFE_DELETE(pWM);
LogAlw("================= Deleting Scene ================");
Expand All @@ -868,7 +872,7 @@ void D3D9Client::clbkCloseSession(bool fastclose)
LogAlw("============== Deleting Mesh Manager ============");
SAFE_DELETE(meshmgr);
WriteLog("[Session Closed. Scene deleted.]");

}

// ==============================================================
Expand Down Expand Up @@ -2865,7 +2869,7 @@ bool D3D9Client::OutputLoadStatus(const char *txt, int line)
HR(pTextScreen->GetDC(&hDC));

HFONT hO = (HFONT)SelectObject(hDC, hLblFont1);
SetTextColor(hDC, 0xE0A0A0);
SetTextColor(hDC, pSplashTextColor);
SetBkMode(hDC,TRANSPARENT);
SetTextAlign(hDC, TA_LEFT|TA_TOP);

Expand All @@ -2874,7 +2878,7 @@ bool D3D9Client::OutputLoadStatus(const char *txt, int line)
SelectObject(hDC, hLblFont2);
TextOut(hDC, 2, 36, pLoadItem, lstrlen(pLoadItem));

HPEN pen = CreatePen(PS_SOLID,1,0xE0A0A0);
HPEN pen = CreatePen(PS_SOLID,1,pSplashTextColor);
HPEN po = (HPEN)SelectObject(hDC, pen);

MoveToEx(hDC, 0, 32, NULL);
Expand Down Expand Up @@ -2904,6 +2908,11 @@ bool D3D9Client::OutputLoadStatus(const char *txt, int line)
}

// =======================================================================
void D3D9Client::clbkSetSplashScreen(const char *filename, DWORD textCol)
{
pCustomSplashScreen = filename;
pSplashTextColor = textCol;
}

void D3D9Client::SplashScreen()
{
Expand All @@ -2925,28 +2934,50 @@ void D3D9Client::SplashScreen()
HR(pDevice->CreateOffscreenPlainSurface(loadd_w, loadd_h, D3DFMT_X8R8G8B8, D3DPOOL_DEFAULT, &pTextScreen, NULL));
HR(pDevice->CreateOffscreenPlainSurface(viewW, viewH, D3DFMT_X8R8G8B8, D3DPOOL_DEFAULT, &pSplashScreen, NULL));

D3DXIMAGE_INFO Info;

HMODULE hOrbiter = GetModuleHandleA("orbiter.exe");
HRSRC hRes = FindResourceA(hOrbiter, MAKEINTRESOURCEA(292), "IMAGE");
HGLOBAL hImage = LoadResource(hOrbiter, hRes);
LPVOID pData = LockResource(hImage);
DWORD size = SizeofResource(hOrbiter, hRes);

// Splash screen image is 1920 x 1200 pixel
double scale = min(viewW / 1920.0, viewH / 1200.0);
double _w = (1920.0 * scale);
double _h = (1200.0 * scale);
double _l = abs(viewW - _w)/2.0;
double _t = abs(viewH - _h)/2.0;
RECT imgRect = {
static_cast<LONG>( round(_l) ),
static_cast<LONG>( round(_t) ),
static_cast<LONG>( round(_w + _l) ),
static_cast<LONG>( round(_h + _t) )
};
HR(pDevice->ColorFill(pSplashScreen, NULL, D3DCOLOR_XRGB(0, 0, 0)));
HR(D3DXLoadSurfaceFromFileInMemory(pSplashScreen, NULL, &imgRect, pData, size, NULL, D3DX_FILTER_LINEAR, 0, &Info));

if(pCustomSplashScreen != NULL) {
D3DXIMAGE_INFO info;
HR(D3DXGetImageInfoFromFile(pCustomSplashScreen, &info));

double imageW = info.Width;
double imageH = info.Height;

double scale = min(viewW / imageW, viewH / imageH);
double _w = (imageW * scale);
double _h = (imageH * scale);
double _l = abs(viewW - _w)/2.0;
double _t = abs(viewH - _h)/2.0;
RECT imgRect = {
static_cast<LONG>( round(_l) ),
static_cast<LONG>( round(_t) ),
static_cast<LONG>( round(_w + _l) ),
static_cast<LONG>( round(_h + _t) )
};
HR(pDevice->ColorFill(pSplashScreen, NULL, D3DCOLOR_XRGB(0, 0, 0)));
HR(D3DXLoadSurfaceFromFile(pSplashScreen, NULL, &imgRect, pCustomSplashScreen, NULL, D3DX_FILTER_LINEAR, 0, NULL));
} else {
D3DXIMAGE_INFO Info;
HMODULE hOrbiter = GetModuleHandleA("orbiter.exe");
HRSRC hRes = FindResourceA(hOrbiter, MAKEINTRESOURCEA(292), "IMAGE");
HGLOBAL hImage = LoadResource(hOrbiter, hRes);
LPVOID pData = LockResource(hImage);
DWORD size = SizeofResource(hOrbiter, hRes);

// Splash screen image is 1920 x 1200 pixel
double scale = min(viewW / 1920.0, viewH / 1200.0);
double _w = (1920.0 * scale);
double _h = (1200.0 * scale);
double _l = abs(viewW - _w)/2.0;
double _t = abs(viewH - _h)/2.0;
RECT imgRect = {
static_cast<LONG>( round(_l) ),
static_cast<LONG>( round(_t) ),
static_cast<LONG>( round(_w + _l) ),
static_cast<LONG>( round(_h + _t) )
};
HR(pDevice->ColorFill(pSplashScreen, NULL, D3DCOLOR_XRGB(0, 0, 0)));
HR(D3DXLoadSurfaceFromFileInMemory(pSplashScreen, NULL, &imgRect, pData, size, NULL, D3DX_FILTER_LINEAR, 0, &Info));
}

HDC hDC;
HR(pSplashScreen->GetDC(&hDC));
Expand All @@ -2965,7 +2996,7 @@ void D3D9Client::SplashScreen()
HFONT hF = CreateFontIndirect(&fnt);

HFONT hO = (HFONT)SelectObject(hDC, hF);
SetTextColor(hDC, 0xE0A0A0);
SetTextColor(hDC, pSplashTextColor);
SetBkMode(hDC,TRANSPARENT);

const char *months[]={"???","Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec","???"};
Expand Down
3 changes: 3 additions & 0 deletions OVP/D3D9Client/D3D9Client.h
Original file line number Diff line number Diff line change
Expand Up @@ -1233,6 +1233,7 @@ class D3D9Client : public GraphicsClient
*/
bool clbkSplashLoadMsg (const char *msg, int line);

void clbkSetSplashScreen(const char *filename, DWORD textCol) override;

/**
* \brief Store a persistent mesh template
Expand Down Expand Up @@ -1307,6 +1308,8 @@ class D3D9Client : public GraphicsClient
std::string scenarioName;
HANDLE hMainThread;
WindowManager * pWM;
const char * pCustomSplashScreen;
DWORD pSplashTextColor;

HWND hRenderWnd; // render window handle

Expand Down
11 changes: 11 additions & 0 deletions Orbitersdk/include/GraphicsAPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -1619,6 +1619,17 @@ class OAPIFUNC GraphicsClient: public Module {
*/
virtual bool clbkSplashLoadMsg (const char *msg, int line) { return false; }

/**
* \brief Change the default splash screen
*
* Called before clbkCreateRenderWindow to override the default splash screen
* image and text color.
*
* \param fname File containing the splashscreen (jpg/bmp)
* \param textCol text color
*/
virtual void clbkSetSplashScreen(const char *fname, DWORD textCol) {}

/**
* \brief Notifies Orbiter to to initiate rendering of the 2D scene overlay
*
Expand Down
2 changes: 2 additions & 0 deletions Src/Orbiter/Orbiter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -730,6 +730,8 @@ HWND Orbiter::CreateRenderWindow (Config *pCfg, const char *scenario)
m_pLaunchpad->Hide(); // hide launchpad dialog while the render window is visible

if (gclient) {
if(pState->SplashScreen())
gclient->clbkSetSplashScreen(pState->SplashScreen(), pState->SplashColor());
hRenderWnd = gclient->InitRenderWnd (gclient->clbkCreateRenderWindow());
GetRenderParameters ();
} else {
Expand Down
54 changes: 30 additions & 24 deletions Src/Orbiter/State.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "State.h"
#include "Vessel.h"
#include "Astro.h"
#include "Util.h"

using namespace std;

Expand All @@ -29,18 +30,13 @@ extern TimeData td;
State::State ()
{
mjd = mjd0 = MJD (time (NULL)); // default to current system time
strcpy (solsys, "Sol"); // default name
memset (scenario, 0, 256);
memset (context, 0, 64);
memset (scnhelp, 0, 128); // no scenario help by default
memset (script, 0, 128);
memset (playback, 0, 128);
solsys = "Sol"; // default name
}

void State::Update ()
{
mjd = td.MJD1;
strcpy (focus, g_focusobj->Name());
focus = g_focusobj->Name();
}

bool State::Read (const char *fname)
Expand All @@ -49,7 +45,7 @@ bool State::Read (const char *fname)
if (!ifs) return false;

int i;
strncpy (scenario, fname, 255);
scenario = fname;
for (i = strlen(fname); i >= 0; i--)
if (fname[i] == '.') break;
if (i >= 0 && i < 256) scenario[i] = '\0';
Expand All @@ -59,12 +55,13 @@ bool State::Read (const char *fname)
mjd0 = MJD (time (NULL)); // default to current system time
mjd0 += UTC_CT_diff*day; // map from UTC to CT (or TDB) time scales
mjd = mjd0;
memset (solsys, 0, 64); // no scenario solsys by default
memset (context, 0, 64); // no scenario context by default
memset (script, 0, 128); // no scenario script by default
memset (scnhelp, 0, 128); // no scenario help by default
memset (playback, 0, 128); // no scenario playback by default
memset (focus, 0, 64); // no scenario focus by default
solsys.clear(); // no scenario solsys by default
context.clear(); // no scenario context by default
splashscreen.clear(); // no scplashscreen by default
script.clear(); // no scenario script by default
scnhelp.clear(); // no scenario help by default
playback.clear(); // no scenario playback by default
focus.clear(); // no scenario focus by default

if (FindLine (ifs, "BEGIN_ENVIRONMENT")) {
for (;;) {
Expand All @@ -80,15 +77,22 @@ bool State::Read (const char *fname)
else if (!_strnicmp (pc, "JE", 2) && sscanf (pc+2, "%lf", &t) == 1)
mjd = mjd0 = Jepoch2MJD (t);
} else if (!_strnicmp (pc, "System", 6)) {
strcpy (solsys, trim_string (pc+6));
solsys = trim_string (pc+6);
} else if (!_strnicmp (pc, "Context", 7)) {
strcpy (context, trim_string (pc+7));
context = trim_string (pc+7);
} else if (!_strnicmp (pc, "SplashScreen", 12)) {
char color[256];
int nChar = 0;
if(sscanf(pc+12, "%255s %n", &color, &nChar)==1) {
splashcolor = GetCSSColor(color);
splashscreen = trim_string (pc+12+nChar);
}
} else if (!_strnicmp (pc, "Script", 6)) {
strcpy (script, trim_string (pc+6));
script = trim_string (pc+6);
} else if (!_strnicmp (pc, "Help", 4)) {
strncpy (scnhelp, trim_string (pc+4), 127);
scnhelp = trim_string (pc+4);
} else if (!_strnicmp (pc, "Playback", 8)) {
strncpy (playback, trim_string (pc+8), 127);
playback = trim_string (pc+8);
}
}
}
Expand All @@ -98,7 +102,7 @@ bool State::Read (const char *fname)
pc = trim_string (cbuf);
if (!_stricmp (pc, "END_FOCUS")) break;
if (!_strnicmp (pc, "Ship", 4)) {
strcpy (focus, trim_string (pc+4));
focus = trim_string (pc+4);
}
}
}
Expand All @@ -122,15 +126,17 @@ void State::Write (ostream &ofs, const char *desc, int desc_fmt, const char *hel
ofs << "BEGIN_ENVIRONMENT" << endl;
ofs << " System " << solsys << endl;
ofs << " Date MJD " << mjd << endl;
if (context[0])
if (context.length())
ofs << " Context " << context << endl;
if (script[0])
if (splashscreen.length())
ofs << " SplashScreen " << splashscreen << endl;
if (script.length())
ofs << " Script " << script << endl;
if (scnhelp[0])
if (scnhelp.length())
ofs << " Help " << scnhelp << endl;
else if (help)
ofs << " Help " << help << endl;
if (playback[0])
if (playback.length())
ofs << " Playback " << playback << endl;
ofs << "END_ENVIRONMENT" << endl << endl;

Expand Down
35 changes: 20 additions & 15 deletions Src/Orbiter/State.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,21 @@

#include <iostream>
#include <fstream>
#include <string>

class State {
public:
State();

double Mjd() const { return mjd; }
char *Solsys() { return solsys; }
const char *Context() const { return context[0] ? context : 0; }
const char *Script() const { return script[0] ? script : 0; }
const char *Focus() const { return focus; }
const char *ScnHelp() const { return (scnhelp[0] ? scnhelp : 0); }
const char *PlaybackDir() const { return (playback[0] ? playback : scenario); }
char *Solsys() { return const_cast<char *>(solsys.c_str()); }
const char *Context() const { return context.length() ? context.c_str() : 0; }
const char *SplashScreen() const { return splashscreen.length() ? splashscreen.c_str() : 0; }
DWORD SplashColor() const { return splashcolor; }
const char *Script() const { return script.length() ? script.c_str() : 0; }
const char *Focus() const { return focus.c_str(); }
const char *ScnHelp() const { return (scnhelp.length() ? scnhelp.c_str() : 0); }
const char *PlaybackDir() const { return (playback.length() ? playback.c_str() : scenario.c_str()); }
void Update ();

/// \brief Read state from scenario file
Expand All @@ -37,15 +40,17 @@ class State {
// load/save scenario state

private:
double mjd0; // start time (MJD format)
double mjd; // current simulation time
char scenario[256]; // scenario name
char solsys[64]; // name of planetary system
char context[64]; // scenario context
char script[128]; // scenario script
char focus[64]; // current focus vessel
char scnhelp[128]; // scenario help file
char playback[128]; // playback folder name, if applicable
double mjd0; // start time (MJD format)
double mjd; // current simulation time
std::string scenario; // scenario name
std::string solsys; // name of planetary system
std::string context; // scenario context
std::string splashscreen;// scenario splash screen
DWORD splashcolor; // text color on splashscreen
std::string script; // scenario script
std::string focus; // current focus vessel
std::string scnhelp; // scenario help file
std::string playback; // playback folder name, if applicable

};

Expand Down
Loading

0 comments on commit 203c82c

Please sign in to comment.