Skip to content

Commit

Permalink
Refactor|UI|Client: Split GameUIWidget from GameWidget
Browse files Browse the repository at this point in the history
The new widget handles the drawing of all overlaid UI elements
visible on top of the game's 3D world.
  • Loading branch information
skyjake committed Nov 3, 2013
1 parent 9168692 commit bce9925
Show file tree
Hide file tree
Showing 7 changed files with 185 additions and 69 deletions.
2 changes: 2 additions & 0 deletions doomsday/client/client.pro
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,7 @@ DENG_HEADERS += \
include/ui/widgets/foldpanelwidget.h \
include/ui/widgets/gameselectionwidget.h \
include/ui/widgets/gamewidget.h \
include/ui/widgets/gameuiwidget.h \
include/ui/widgets/gridpopupwidget.h \
include/ui/widgets/icvarwidget.h \
include/ui/widgets/keygrabberwidget.h \
Expand Down Expand Up @@ -776,6 +777,7 @@ SOURCES += \
src/ui/widgets/foldpanelwidget.cpp \
src/ui/widgets/gameselectionwidget.cpp \
src/ui/widgets/gamewidget.cpp \
src/ui/widgets/gameuiwidget.cpp \
src/ui/widgets/gridpopupwidget.cpp \
src/ui/widgets/keygrabberwidget.cpp \
src/ui/widgets/labelwidget.cpp \
Expand Down
38 changes: 38 additions & 0 deletions doomsday/client/include/ui/widgets/gameuiwidget.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/** @file gameuiwidget.h Widget for legacy game UI elements.
*
* @authors Copyright (c) 2013 Jaakko Keränen <jaakko.keranen@iki.fi>
*
* @par License
* GPL: http://www.gnu.org/licenses/gpl.html
*
* <small>This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version. This program is distributed in the hope that it
* will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
* Public License for more details. You should have received a copy of the GNU
* General Public License along with this program; if not, see:
* http://www.gnu.org/licenses</small>
*/

#ifndef DENG_CLIENT_GAMEUIWIDGET_H
#define DENG_CLIENT_GAMEUIWIDGET_H

#include "GuiWidget"

/**
* Widget that encapsulates game-side UI elements.
*/
class GameUIWidget : public GuiWidget
{
public:
GameUIWidget();

void draw();

private:
DENG2_PRIVATE(d)
};

#endif // DENG_CLIENT_GAMEUIWIDGET_H
2 changes: 1 addition & 1 deletion doomsday/client/include/ui/widgets/gamewidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
class GameWidget : public GuiWidget
{
public:
GameWidget(de::String const &name = "");
GameWidget(de::String const &name = "game");

/**
* Convenience method for changing and immediately applying a new GL
Expand Down
22 changes: 15 additions & 7 deletions doomsday/client/src/ui/clientwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include "gl/sys_opengl.h"
#include "gl/gl_main.h"
#include "ui/widgets/gamewidget.h"
#include "ui/widgets/gameuiwidget.h"
#include "ui/widgets/busywidget.h"
#include "ui/widgets/taskbarwidget.h"
#include "ui/widgets/consolewidget.h"
Expand All @@ -52,8 +53,6 @@

using namespace de;

static String const LEGACY_WIDGET_NAME = "legacy";

DENG2_PIMPL(ClientWindow),
DENG2_OBSERVES(KeyEventSource, KeyEvent),
DENG2_OBSERVES(MouseEventSource, MouseStateChange),
Expand All @@ -70,6 +69,7 @@ DENG2_OBSERVES(App, GameChange)
/// Root of the nomal UI widgets of this window.
GuiRootWidget root;
GameWidget *legacy;
GameUIWidget *gameUI;
TaskBarWidget *taskBar;
NotificationWidget *notifications;
ColorAdjustmentDialog *colorAdjust;
Expand All @@ -95,6 +95,7 @@ DENG2_OBSERVES(App, GameChange)
mode(Normal),
root(thisPublic),
legacy(0),
gameUI(0),
taskBar(0),
notifications(0),
colorAdjust(0),
Expand Down Expand Up @@ -143,15 +144,18 @@ DENG2_OBSERVES(App, GameChange)
.setInput(Rule::Bottom, root.viewBottom());
root.add(background);

legacy = new GameWidget(LEGACY_WIDGET_NAME);
legacy->rule()
.setLeftTop (root.viewLeft(), root.viewTop())
.setRightBottom(root.viewWidth(), root.viewBottom());
legacy = new GameWidget;
legacy->rule().setRect(root.viewRule());
// Initially the widget is disabled. It will be enabled when the window
// is visible and ready to be drawn.
legacy->disable();
root.add(legacy);

gameUI = new GameUIWidget;
gameUI->rule().setRect(root.viewRule());
gameUI->disable();
root.add(gameUI);

// Game selection.
games = new GameSelectionWidget;
games->rule()
Expand Down Expand Up @@ -383,6 +387,8 @@ DENG2_OBSERVES(App, GameChange)
.setInput(Rule::Bottom, taskBar->rule().top());
legacy->rule()
.setInput(Rule::Right, widget->rule().left());
gameUI->rule()
.setInput(Rule::Right, widget->rule().left());
break;
}

Expand All @@ -398,6 +404,7 @@ DENG2_OBSERVES(App, GameChange)
{
case RightEdge:
legacy->rule().setInput(Rule::Right, root.viewRight());
gameUI->rule().setInput(Rule::Right, root.viewRight());
break;
}

Expand Down Expand Up @@ -499,7 +506,8 @@ void ClientWindow::canvasGLReady(Canvas &canvas)
PersistentCanvasWindow::canvasGLReady(canvas);

// Now that the Canvas is ready for drawing we can enable the GameWidget.
d->root.find(LEGACY_WIDGET_NAME)->enable();
d->legacy->enable();
d->gameUI->enable();

// Configure a viewport immediately.
GLState::top().setViewport(Rectangleui(0, 0, canvas.width(), canvas.height())).apply();
Expand Down
8 changes: 4 additions & 4 deletions doomsday/client/src/ui/ui_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ static void strCpyLen(char* dest, const char* src, int maxWidth);
extern int glMaxTexSize;
extern boolean stopTime;
extern boolean tickUI;
extern boolean drawGame;
//extern boolean drawGame;

static boolean uiActive; /// The user interface is active.
static boolean uiNoMouse;
Expand Down Expand Up @@ -123,7 +123,7 @@ void UI_PageInit(boolean halttime, boolean tckui, boolean tckframe, boolean drwg
stopTime = halttime;
tickUI = tckui;
tickFrame = tckframe;
uiDrawGame = drawGame = drwgame;
uiDrawGame = /*drawGame = */ drwgame;
// Advise the game not to draw any HUD displays
gameDrawHUD = false;
I_SetUIMouseMode(true);
Expand Down Expand Up @@ -165,7 +165,7 @@ void UI_End(void)
tickFrame = true;
stopTime = false;
tickUI = false;
drawGame = true;
//drawGame = true;
// Advise the game it can now draw HUD displays again.
gameDrawHUD = true;

Expand Down Expand Up @@ -465,7 +465,7 @@ void UI_Ticker(timespan_t time)
{
// By default, the game is not visible, but since the alpha is not
// fully opaque, it must be shown anyway.
drawGame = (uiAlpha < 1.0);
//drawGame = (uiAlpha < 1.0);
}

// Call the active page's ticker.
Expand Down
118 changes: 118 additions & 0 deletions doomsday/client/src/ui/widgets/gameuiwidget.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
/** @file gameuiwidget.cpp Widget for legacy game UI elements.
*
* @authors Copyright (c) 2013 Jaakko Keränen <jaakko.keranen@iki.fi>
*
* @par License
* GPL: http://www.gnu.org/licenses/gpl.html
*
* <small>This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version. This program is distributed in the hope that it
* will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
* Public License for more details. You should have received a copy of the GNU
* General Public License along with this program; if not, see:
* http://www.gnu.org/licenses</small>
*/

#include "ui/widgets/gameuiwidget.h"

#include "de_base.h"
#include "de_console.h"
#include "de_ui.h"
#include "de_render.h"
#include "audio/s_main.h"

#include "gl/gl_main.h"
#include "edit_bias.h"
#include "ui/busyvisual.h"

#include <de/GLState>

using namespace de;

DENG2_PIMPL(GameUIWidget)
{
Instance(Public *i) : Base(i)
{}

void draw()
{
if(!App_GameLoaded() && titleFinale == 0)
{
// Title finale is not playing. Lets do it manually.
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
glOrtho(0, SCREENWIDTH, SCREENHEIGHT, 0, -1, 1);

R_RenderBlankView();

glMatrixMode(GL_PROJECTION);
glPopMatrix();
}

if(!(UI_IsActive() && UI_Alpha() >= 1.0))
{
UI2_Drawer();

// Draw any full window game graphics.
if(App_GameLoaded() && gx.DrawWindow)
{
Size2Raw dimensions(DENG_GAMEVIEW_WIDTH, DENG_GAMEVIEW_HEIGHT);
gx.DrawWindow(&dimensions);
}
}

/// @todo Transition must be done at window level to work correctly.
if(Con_TransitionInProgress())
Con_DrawTransition();

// Draw the widgets of the Shadow Bias Editor (if active).
SBE_DrawGui();

/*
* Draw debug information.
*/
if(App_World().hasMap() && App_World().map().hasLightGrid())
{
App_World().map().lightGrid().drawDebugVisual();
}
Net_Drawer();
S_Drawer();

if(UI_IsActive())
{
// Draw user interface.
UI_Drawer();
}

DGL_End();
}
};

GameUIWidget::GameUIWidget() : GuiWidget("game_ui"), d(new Instance(this))
{}

void GameUIWidget::draw()
{
if(isDisabled() || !GL_IsFullyInited())
return;

GLState::push();

/*
Rectanglei pos;
if(hasChangedPlace(pos))
{
// Automatically update if the widget is resized.
d->updateSize();
}*/

d->draw();

GLState::considerNativeStateUndefined();
GLState::pop();
}

64 changes: 7 additions & 57 deletions doomsday/client/src/ui/widgets/gamewidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
*/
#define FRAME_DEFERRED_UPLOAD_TIMEOUT 20

boolean drawGame = true; // If false the game viewport won't be rendered
//boolean drawGame = true; // If false the game viewport won't be rendered

using namespace de;

Expand All @@ -72,70 +72,20 @@ DENG2_PIMPL(GameWidget)

if(cannotDraw) return;

if(drawGame)
if(App_GameLoaded())
{
if(App_GameLoaded())
{
// Notify the world that a new render frame has begun.
App_World().beginFrame(CPP_BOOL(R_NextViewer()));

R_RenderViewPorts();
}
else if(titleFinale == 0)
{
// Title finale is not playing. Lets do it manually.
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
glOrtho(0, SCREENWIDTH, SCREENHEIGHT, 0, -1, 1);

R_RenderBlankView();

glMatrixMode(GL_PROJECTION);
glPopMatrix();
}

if(!(UI_IsActive() && UI_Alpha() >= 1.0))
{
UI2_Drawer();

// Draw any full window game graphics.
if(App_GameLoaded() && gx.DrawWindow)
{
Size2Raw dimensions(DENG_GAMEVIEW_WIDTH, DENG_GAMEVIEW_HEIGHT);
gx.DrawWindow(&dimensions);
}
}
}
// Notify the world that a new render frame has begun.
App_World().beginFrame(CPP_BOOL(R_NextViewer()));

if(Con_TransitionInProgress())
Con_DrawTransition();
R_RenderViewPorts();

if(drawGame)
{
// Draw the widgets of the Shadow Bias Editor (if active).
SBE_DrawGui();

/*
* Draw debug information.
*/
if(App_World().hasMap() && App_World().map().hasLightGrid())
{
App_World().map().lightGrid().drawDebugVisual();
}
Net_Drawer();
S_Drawer();
// End any open DGL sequence.
DGL_End();

// Notify the world that we've finished rendering the frame.
App_World().endFrame();
}

if(UI_IsActive())
{
// Draw user interface.
UI_Drawer();
}

// End any open DGL sequence.
DGL_End();
}
Expand Down

0 comments on commit bce9925

Please sign in to comment.