Skip to content

Commit

Permalink
Refactor|Client: Use new ClientWindow class, WindowSystem methods
Browse files Browse the repository at this point in the history
Moved window management methods to WindowSystem.
  • Loading branch information
skyjake committed Apr 5, 2013
1 parent 40f3b08 commit 03d94c4
Show file tree
Hide file tree
Showing 26 changed files with 283 additions and 205 deletions.
2 changes: 2 additions & 0 deletions doomsday/client/include/clientapp.h
Expand Up @@ -21,6 +21,7 @@

#include <de/GuiApp>
#include "network/serverlink.h"
#include "ui/windowsystem.h"

/**
* The client application.
Expand All @@ -42,6 +43,7 @@ class ClientApp : public de::GuiApp
public:
static ClientApp &app();
static ServerLink &serverLink();
static WindowSystem &windowSystem();

private:
DENG2_PRIVATE(d)
Expand Down
2 changes: 1 addition & 1 deletion doomsday/client/include/de_system.h
Expand Up @@ -29,8 +29,8 @@
#ifdef __CLIENT__
# include "network/sys_network.h"
# include "gl/sys_opengl.h"
# include "ui/window.h"
# include "ui/sys_input.h"
# include "ui/clientwindow.h"
#endif

#ifdef __SERVER__
Expand Down
2 changes: 2 additions & 0 deletions doomsday/client/include/de_ui.h
Expand Up @@ -28,6 +28,8 @@
#include "ui/fi_main.h"

#ifdef __CLIENT__
# include <de/gui/ddkey.h>
# include "ui/windowsystem.h"
# include "ui/ui_main.h"
# include "ui/ui_panel.h"
# include "network/ui_mpi.h"
Expand Down
2 changes: 1 addition & 1 deletion doomsday/client/include/gl/sys_opengl.h
Expand Up @@ -78,7 +78,7 @@
#include <string.h>
#include "gl_deferredapi.h"
#ifdef __CLIENT__
# include "ui/window.h"
# include "ui/clientwindow.h"
#endif

/**
Expand Down
58 changes: 57 additions & 1 deletion doomsday/client/include/ui/windowsystem.h
@@ -1,4 +1,8 @@
/** @file windowsystem.h Window management subsystem.
*
* @todo Deferred window changes should be done using a queue-type solution
* where it is possible to schedule multiple tasks into the future separately
* for each window. Each window could have its own queue.
*
* @authors Copyright (c) 2013 Jaakko Keränen <jaakko.keranen@iki.fi>
*
Expand All @@ -20,6 +24,9 @@
#define CLIENT_WINDOWSYSTEM_H

#include <de/System>
#include <de/String>

class ClientWindow;

/**
* Window management subsystem.
Expand All @@ -31,11 +38,60 @@
*/
class WindowSystem : public de::System
{
public:
/// Required/referenced Window instance is missing. @ingroup errors
DENG2_ERROR(MissingWindowError);

public:
WindowSystem();

bool processEvent(de::Event const &);
/**
* Constructs a new window using the default configuration. Note that the
* default configuration is saved persistently when the engine shuts down
* and is restored when the engine is restarted.
*
* Command line options (e.g., -xpos) can be used to modify the window
* configuration.
*
* @param id Identifier of the window ("main" for the main window).
*
* @return ClientWindow instance. Ownership is retained by the window system.
*/
ClientWindow *createWindow(de::String const &id = "main");

/**
* Returns @c true iff a main window is available.
*/
static bool haveMain();

/**
* Returns the main window.
*/
static ClientWindow &main();

/**
* Returns a pointer to the @em main window.
*
* @see haveMain()
*/
inline static ClientWindow *mainPtr() { return haveMain()? &main() : 0; }

/**
* Find a window.
*
* @param id Window identifier. "main" for the main window.
*
* @return Window instance or @c NULL if not found.
*/
ClientWindow *find(de::String const &id) const;

/**
* Closes all windows, including the main window.
*/
void closeAll();

// System.
bool processEvent(de::Event const &);
void timeChanged(de::Clock const &);

private:
Expand Down
10 changes: 5 additions & 5 deletions doomsday/client/src/busymode.cpp
Expand Up @@ -36,8 +36,8 @@
#include <QEventLoop>

#ifdef __CLIENT__

#include "clientapp.h"
#include "ui/windowsystem.h"

static void BusyMode_Exit(void);

Expand Down Expand Up @@ -245,7 +245,7 @@ static void preBusySetup(int initialMode)
ClientApp::app().loop().setRate(60);

// Switch the window to busy mode UI.
Window::main().canvasWindow().setMode(CanvasWindow::Busy);
WindowSystem::main().setMode(ClientWindow::Busy);

#else
DENG_UNUSED(initialMode);
Expand All @@ -265,7 +265,7 @@ static void postBusyCleanup()
ClientApp::app().loop().setRate(0);

// Switch the window to normal UI.
Window::main().canvasWindow().setMode(CanvasWindow::Normal);
WindowSystem::main().setMode(ClientWindow::Normal);
#endif
}

Expand Down Expand Up @@ -437,7 +437,7 @@ void BusyMode_Loop(void)

if(canUpload)
{
Window::main().glActivate();
WindowSystem::main().glActivate();

// Any deferred content needs to get uploaded.
GL_ProcessDeferredTasks(15);
Expand All @@ -460,7 +460,7 @@ void BusyMode_Loop(void)
!Con_IsProgressAnimationCompleted())
{
// Let's keep running the busy loop.
Window::main().draw();
WindowSystem::main().draw();
return;
}

Expand Down
28 changes: 20 additions & 8 deletions doomsday/client/src/clientapp.cpp
Expand Up @@ -25,6 +25,7 @@
#include <stdlib.h>

#include <de/Log>
#include <de/DisplayMode>
#include <de/Error>
#include <de/c_wrapper.h>
#include <de/garbage.h>
Expand All @@ -37,9 +38,8 @@
#include "sys_system.h"
#include "audio/s_main.h"
#include "gl/gl_main.h"
#include "ui/displaymode.h"
#include "ui/windowsystem.h"
#include "ui/window.h"
#include "ui/clientwindow.h"
#include "updater.h"

#if WIN32
Expand All @@ -61,20 +61,21 @@ static void continueInitWithEventLoopRunning()
{
// Show the main window. This causes initialization to finish (in busy mode)
// as the canvas is visible and ready for initialization.
Window::main().show();
WindowSystem::main().show();
}

DENG2_PIMPL(ClientApp)
{
LegacyCore *legacyCore;
QMenuBar *menuBar;
WindowSystem winSys;
WindowSystem *winSys;
ServerLink *svLink;

Instance(Public *i)
: Base(i),
legacyCore(0),
menuBar(0),
winSys(0),
svLink(0)
{
clientAppSingleton = thisPublic;
Expand All @@ -88,6 +89,7 @@ DENG2_PIMPL(ClientApp)
LegacyCore_Delete(legacyCore);

delete svLink;
delete winSys;
delete menuBar;
clientAppSingleton = 0;
}
Expand Down Expand Up @@ -125,9 +127,6 @@ ClientApp::ClientApp(int &argc, char **argv)
QCoreApplication::setApplicationVersion (DOOMSDAY_VERSION_BASE);

setTerminateFunc(handleLegacyCoreTerminate);

// Subsystems.
addSystem(d->winSys);
}

void ClientApp::initialize()
Expand Down Expand Up @@ -161,10 +160,16 @@ void ClientApp::initialize()
}
#endif

// Create the window system.
d->winSys = new WindowSystem;
addSystem(*d->winSys);

Plug_LoadAll();

// Create the main window.
char title[256];
DD_ComposeMainWindowTitle(title);
Window::create(title);
d->winSys->createWindow()->setWindowTitle(title);

LegacyCore_Timer(1, continueInitWithEventLoopRunning);
}
Expand Down Expand Up @@ -208,3 +213,10 @@ ServerLink &ClientApp::serverLink()
DENG2_ASSERT(a.d->svLink != 0);
return *a.d->svLink;
}

WindowSystem &ClientApp::windowSystem()
{
ClientApp &a = ClientApp::app();
DENG2_ASSERT(a.d->winSys != 0);
return *a.d->winSys;
}
14 changes: 8 additions & 6 deletions doomsday/client/src/con_main.cpp
Expand Up @@ -54,14 +54,15 @@
#include "de_filesys.h"

#include "resource/fonts.h"
#include "ui/displaymode.h"
#include "ui/busyvisual.h"
#include "cbuffer.h"
#include "Game"

#ifdef __CLIENT__
# include <de/DisplayMode>
# include "clientapp.h"
# include "ui/windowsystem.h"
# include "updater/downloaddialog.h"
# include <de/GuiApp>
#endif

using namespace de;
Expand Down Expand Up @@ -2005,13 +2006,15 @@ void Con_Error(char const *error, ...)
va_list argptr;

#ifdef __CLIENT__
Window::main().trapMouse(false);
ClientWindow::main().canvas().trapMouse(false);
#endif

// Already in an error?
if(!ConsoleInited || errorInProgress)
{
#ifdef __CLIENT__
DisplayMode_Shutdown();
#endif

va_start(argptr, error);
dd_vsnprintf(buff, sizeof(buff), error, argptr);
Expand Down Expand Up @@ -2074,18 +2077,17 @@ void Con_Error(char const *error, ...)
void Con_AbnormalShutdown(char const *message)
{
Sys_Shutdown();
DisplayMode_Shutdown();

#ifdef __CLIENT__
Window::main().trapMouse(false);
DisplayMode_Shutdown();

DENG2_GUI_APP->loop().pause();

// This is an abnormal shutdown, we cannot continue drawing any of the
// windows. (Alternatively could hide/disable drawing of the windows.) Note
// that the app's event loop is running normally while we show the native
// message box below.
Window::shutdown();
ClientApp::app().windowSystem().closeAll();
#endif

if(message) // Only show if a message given.
Expand Down
4 changes: 2 additions & 2 deletions doomsday/client/src/dd_loop.cpp
Expand Up @@ -39,7 +39,7 @@

#ifdef __CLIENT__
# include "ui/busyvisual.h"
# include "ui/window.h"
# include "ui/clientwindow.h"
#endif

/// Development utility: on sharp tics, print player 0 movement state.
Expand Down Expand Up @@ -102,7 +102,7 @@ int DD_GameLoopExitCode(void)
float DD_GetFrameRate()
{
#ifdef __CLIENT__
return Window::main().canvasWindow().frameRate();
return ClientWindow::main().frameRate();
#else
return 0;
#endif
Expand Down
15 changes: 6 additions & 9 deletions doomsday/client/src/dd_main.cpp
Expand Up @@ -34,6 +34,9 @@
#include <de/App>
#include <de/NativePath>
#include <de/binangle.h>
#ifdef __CLIENT__
# include <de/DisplayMode>
#endif

#include "de_platform.h"

Expand All @@ -60,7 +63,6 @@
#include "map/p_players.h"
#include "map/p_maputil.h"
#include "map/p_objlink.h"
#include "ui/displaymode.h"
#include "ui/p_control.h"
#include "updater.h"
#include "m_misc.h"
Expand Down Expand Up @@ -1564,7 +1566,7 @@ bool DD_ChangeGame(de::Game& game, bool allowReload = false)
#ifdef __CLIENT__
char buf[256];
DD_ComposeMainWindowTitle(buf);
DENG_WINDOW->setTitle(buf);
DENG_WINDOW->setWindowTitle(buf);
#endif

if(!DD_IsShuttingDown())
Expand All @@ -1588,7 +1590,7 @@ bool DD_ChangeGame(de::Game& game, bool allowReload = false)

#ifdef __CLIENT__
DD_ComposeMainWindowTitle(buf);
DENG_WINDOW->setTitle(buf);
DENG_WINDOW->setWindowTitle(buf);
#endif

/**
Expand Down Expand Up @@ -1743,11 +1745,6 @@ int DD_EarlyInit()
// Register the engine's console commands and variables.
DD_Register();

#ifdef __CLIENT__
// Bring the window manager online.
Window::initialize();
#endif

// Instantiate the Games collection.
games = new Games();

Expand Down Expand Up @@ -1775,7 +1772,7 @@ void DD_FinishInitializationAfterWindowReady()
{
char buf[256];
DD_ComposeMainWindowTitle(buf);
DENG_WINDOW->setTitle(buf);
DENG_WINDOW->setWindowTitle(buf);
}
#endif

Expand Down
3 changes: 0 additions & 3 deletions doomsday/client/src/dd_pinit.cpp
Expand Up @@ -192,7 +192,4 @@ void DD_ShutdownAll(void)
F_Shutdown();
DD_ClearResourceClasses();
Libdeng_Shutdown();
#ifdef __CLIENT__
Window::shutdown();
#endif
}

0 comments on commit 03d94c4

Please sign in to comment.