Skip to content

Commit

Permalink
Refactor|Client: Game view size is taken from LegacyWidget
Browse files Browse the repository at this point in the history
The objective is to make LegacyWidget resizable within the window.

Todo: GL viewport needs to be set separately for LegacyWidget
(using GLState).
  • Loading branch information
skyjake committed Sep 6, 2013
1 parent 99cbbfd commit 9b3530a
Show file tree
Hide file tree
Showing 18 changed files with 85 additions and 76 deletions.
9 changes: 7 additions & 2 deletions doomsday/client/include/ui/clientwindow.h
Expand Up @@ -25,18 +25,22 @@

#include "GuiRootWidget"
#include "resource/image.h"
#include "ui/widgets/legacywidget.h"

/**
* Macro for conveniently accessing the current active window. There is always
* one active window, so no need to worry about NULLs. The easiest way to get
* information about the window where drawing is done.
*/
#define DENG_WINDOW (&ClientWindow::main())
//#define DENG_WINDOW (&ClientWindow::main())

#define DENG_GAMEVIEW_WIDTH ClientWindow::main().game().rule().width().valuei()
#define DENG_GAMEVIEW_HEIGHT ClientWindow::main().game().rule().height().valuei()

/**
* A helpful macro that changes the origin of the window space coordinate system.
*/
#define FLIP(y) (DENG_WINDOW->height() - (y+1))
#define FLIP(y) (ClientWindow::main().height() - ((y)+1))

class ConsoleWidget;
class TaskBarWidget;
Expand Down Expand Up @@ -66,6 +70,7 @@ class ClientWindow : public de::PersistentCanvasWindow,
TaskBarWidget &taskBar();
ConsoleWidget &console();
NotificationWidget &notifications();
LegacyWidget &game();
BusyWidget &busy();

/**
Expand Down
2 changes: 1 addition & 1 deletion doomsday/client/src/audio/s_main.cpp
Expand Up @@ -590,7 +590,7 @@ void S_Drawer(void)
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
glOrtho(0, DENG_WINDOW->width(), DENG_WINDOW->height(), 0, -1, 1);
glOrtho(0, DENG_GAMEVIEW_WIDTH, DENG_GAMEVIEW_HEIGHT, 0, -1, 1);

Sfx_DebugInfo();

Expand Down
13 changes: 6 additions & 7 deletions doomsday/client/src/dd_main.cpp
Expand Up @@ -762,8 +762,7 @@ void DD_StartTitle(void)
ddstring_t setupCmds; Str_Init(&setupCmds);

// Configure the predefined fonts (all normal, variable width).
char const *fontName = R_ChooseVariableFont(FS_NORMAL, DENG_WINDOW->width(),
DENG_WINDOW->height());
char const *fontName = R_ChooseVariableFont(FS_NORMAL, DENG_GAMEVIEW_WIDTH, DENG_GAMEVIEW_HEIGHT);

for(int i = 1; i <= FIPAGE_NUM_PREDEFINED_FONTS; ++i)
{
Expand Down Expand Up @@ -1611,7 +1610,7 @@ bool App_ChangeGame(Game &game, bool allowReload)
#ifdef __CLIENT__
char buf[256];
DD_ComposeMainWindowTitle(buf);
DENG_WINDOW->setWindowTitle(buf);
ClientWindow::main().setWindowTitle(buf);
#endif

if(!DD_IsShuttingDown())
Expand All @@ -1635,7 +1634,7 @@ bool App_ChangeGame(Game &game, bool allowReload)

#ifdef __CLIENT__
DD_ComposeMainWindowTitle(buf);
DENG_WINDOW->setWindowTitle(buf);
ClientWindow::main().setWindowTitle(buf);
#endif

/**
Expand Down Expand Up @@ -1837,7 +1836,7 @@ void DD_FinishInitializationAfterWindowReady()
{
char buf[256];
DD_ComposeMainWindowTitle(buf);
DENG_WINDOW->setWindowTitle(buf);
ClientWindow::main().setWindowTitle(buf);
}
#endif

Expand Down Expand Up @@ -2458,10 +2457,10 @@ int DD_GetInteger(int ddvalue)
return I_ShiftDown();

case DD_WINDOW_WIDTH:
return DENG_WINDOW->width();
return DENG_GAMEVIEW_WIDTH;

case DD_WINDOW_HEIGHT:
return DENG_WINDOW->height();
return DENG_GAMEVIEW_HEIGHT;

case DD_CURRENT_CLIENT_FINALE_ID:
return Cl_CurrentFinale();
Expand Down
10 changes: 5 additions & 5 deletions doomsday/client/src/edit_bias.cpp
Expand Up @@ -521,8 +521,8 @@ static void drawInfoBox(BiasSource *s, int rightX, String const title, float alp
int th = FR_SingleLineHeight("Info");
Vector2i size(16 + FR_TextWidth("Color:(0.000, 0.000, 0.000)"), 16 + th * 6);

Vector2i origin(DENG_WINDOW->width() - 10 - size.x - rightX,
DENG_WINDOW->height() - 10 - size.y);
Vector2i origin(DENG_GAMEVIEW_WIDTH - 10 - size.x - rightX,
DENG_GAMEVIEW_HEIGHT - 10 - size.y);

ui_color_t color;
color.red = s->color().x;
Expand Down Expand Up @@ -680,7 +680,7 @@ void SBE_DrawGui()
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
glOrtho(0, DENG_WINDOW->width(), DENG_WINDOW->height(), 0, -1, 1);
glOrtho(0, DENG_GAMEVIEW_WIDTH, DENG_GAMEVIEW_HEIGHT, 0, -1, 1);

glEnable(GL_TEXTURE_2D);

Expand All @@ -697,7 +697,7 @@ void SBE_DrawGui()

Vector2i size(FR_TextWidth(text.toUtf8().constData()) + 16,
FR_SingleLineHeight(text.toUtf8().constData()) + 16);
int top = DENG_WINDOW->height() - 10 - size.y;
int top = DENG_GAMEVIEW_HEIGHT - 10 - size.y;

Vector2i origin(10, top);
drawBoxBackground(origin, size, 0);
Expand All @@ -724,7 +724,7 @@ void SBE_DrawGui()
drawInfoBox(&hand.grabbed().first()->as<BiasSource>(), x, "Grabbed", opacity);
}

drawLightGauge(Vector2i(20, DENG_WINDOW->height()/2 - 255/2));
drawLightGauge(Vector2i(20, DENG_GAMEVIEW_HEIGHT/2 - 255/2));
}

glMatrixMode(GL_PROJECTION);
Expand Down
2 changes: 1 addition & 1 deletion doomsday/client/src/gl/gl_main.cpp
Expand Up @@ -190,7 +190,7 @@ void GL_DoUpdate()
DD_WaitForOptimalUpdateTime();

// Blit screen to video.
DENG_WINDOW->swapBuffers();
ClientWindow::main().swapBuffers();

// We will arrive here always at the same time in relation to the displayed
// frame: it is a good time to update the mouse state.
Expand Down
4 changes: 2 additions & 2 deletions doomsday/client/src/network/net_main.cpp
Expand Up @@ -687,7 +687,7 @@ static boolean recordingDemo(void)
void Net_DrawDemoOverlay(void)
{
char buf[160], tmp[40];
int x = DENG_WINDOW->width() - 10, y = 10;
int x = DENG_GAMEVIEW_WIDTH - 10, y = 10;

if(!recordingDemo() || !(SECONDS_TO_TICKS(gameTime) & 8))
return;
Expand Down Expand Up @@ -715,7 +715,7 @@ void Net_DrawDemoOverlay(void)
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
glOrtho(0, DENG_WINDOW->width(), DENG_WINDOW->height(), 0, -1, 1);
glOrtho(0, DENG_GAMEVIEW_WIDTH, DENG_GAMEVIEW_HEIGHT, 0, -1, 1);

glEnable(GL_TEXTURE_2D);

Expand Down
16 changes: 8 additions & 8 deletions doomsday/client/src/render/blockmapvisual.cpp
Expand Up @@ -78,7 +78,7 @@ static int rendBspLeaf(BspLeaf *bspLeaf, void * /*parameters*/)
if(!bspLeaf->isDegenerate() && bspLeaf->validCount() != validCount)
{
float const scale = de::max(bmapDebugSize, 1.f);
float const width = (DENG_WINDOW->width() / 16) / scale;
float const width = (DENG_GAMEVIEW_WIDTH / 16) / scale;
float length, dx, dy, normal[2], unit[2];
vec2f_t start, end;

Expand Down Expand Up @@ -562,12 +562,12 @@ void Rend_BlockmapDebug()
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
glOrtho(0, DENG_WINDOW->width(), DENG_WINDOW->height(), 0, -1, 1);
glOrtho(0, DENG_GAMEVIEW_WIDTH, DENG_GAMEVIEW_HEIGHT, 0, -1, 1);
// Orient on the center of the window.
glTranslatef((DENG_WINDOW->width() / 2), (DENG_WINDOW->height() / 2), 0);
glTranslatef((DENG_GAMEVIEW_WIDTH / 2), (DENG_GAMEVIEW_HEIGHT / 2), 0);

// Uniform scaling factor for this visual.
scale = bmapDebugSize / de::max(DENG_WINDOW->height() / 100, 1);
scale = bmapDebugSize / de::max(DENG_GAMEVIEW_HEIGHT / 100, 1);
glScalef(scale, -scale, 1);

// If possible we'll tailor what we draw relative to the viewPlayer.
Expand All @@ -586,7 +586,7 @@ void Rend_BlockmapDebug()
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
glOrtho(0, DENG_WINDOW->width(), DENG_WINDOW->height(), 0, -1, 1);
glOrtho(0, DENG_GAMEVIEW_WIDTH, DENG_GAMEVIEW_HEIGHT, 0, -1, 1);

if(followMobj)
{
Expand All @@ -595,15 +595,15 @@ void Rend_BlockmapDebug()
Blockmap::Cell cell = blockmap->toCell(followMobj->origin, &didClip);
if(!didClip)
{
origin.x = DENG_WINDOW->width() / 2;
origin.x = DENG_GAMEVIEW_WIDTH / 2;
origin.y = 30;
drawCellInfoBox(blockmap, &origin, objectTypeName, cell);
}
}

// About the Blockmap itself.
origin.x = DENG_WINDOW->width() - 10;
origin.y = DENG_WINDOW->height() - 10;
origin.x = DENG_GAMEVIEW_WIDTH - 10;
origin.y = DENG_GAMEVIEW_HEIGHT - 10;
drawBlockmapInfo(&origin, blockmap);

glMatrixMode(GL_PROJECTION);
Expand Down
2 changes: 1 addition & 1 deletion doomsday/client/src/render/lightgrid.cpp
Expand Up @@ -981,7 +981,7 @@ void LightGrid::drawDebugVisual()
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
glOrtho(0, DENG_WINDOW->width(), DENG_WINDOW->height(), 0, -1, 1);
glOrtho(0, DENG_GAMEVIEW_WIDTH, DENG_GAMEVIEW_HEIGHT, 0, -1, 1);

for(int y = 0; y < d->dimensions.y; ++y)
{
Expand Down
26 changes: 13 additions & 13 deletions doomsday/client/src/render/r_main.cpp
Expand Up @@ -142,8 +142,8 @@ void R_BuildTexGammaLut()
#ifdef __CLIENT__
char const *R_ChooseFixedFont()
{
if(DENG_WINDOW->width() < 300) return "console11";
if(DENG_WINDOW->width() > 768) return "console18";
if(DENG_GAMEVIEW_WIDTH < 300) return "console11";
if(DENG_GAMEVIEW_WIDTH > 768) return "console18";
return "console14";
}
#endif
Expand Down Expand Up @@ -223,9 +223,9 @@ void R_LoadSystemFonts()
if(!Fonts_IsInitialized() || isDedicated) return;

loadFontIfNeeded(R_ChooseFixedFont(), &fontFixed);
loadFontIfNeeded(R_ChooseVariableFont(FS_NORMAL, DENG_WINDOW->width(), DENG_WINDOW->height()), &fontVariable[FS_NORMAL]);
loadFontIfNeeded(R_ChooseVariableFont(FS_BOLD, DENG_WINDOW->width(), DENG_WINDOW->height()), &fontVariable[FS_BOLD]);
loadFontIfNeeded(R_ChooseVariableFont(FS_LIGHT, DENG_WINDOW->width(), DENG_WINDOW->height()), &fontVariable[FS_LIGHT]);
loadFontIfNeeded(R_ChooseVariableFont(FS_NORMAL, DENG_GAMEVIEW_WIDTH, DENG_GAMEVIEW_HEIGHT), &fontVariable[FS_NORMAL]);
loadFontIfNeeded(R_ChooseVariableFont(FS_BOLD, DENG_GAMEVIEW_WIDTH, DENG_GAMEVIEW_HEIGHT), &fontVariable[FS_BOLD]);
loadFontIfNeeded(R_ChooseVariableFont(FS_LIGHT, DENG_GAMEVIEW_WIDTH, DENG_GAMEVIEW_HEIGHT), &fontVariable[FS_LIGHT]);

//Con_SetFont(fontFixed);

Expand Down Expand Up @@ -261,8 +261,8 @@ void R_SetupDefaultViewWindow(int consoleNum)

vd->window.origin.x = vd->windowOld.origin.x = vd->windowTarget.origin.x = 0;
vd->window.origin.y = vd->windowOld.origin.y = vd->windowTarget.origin.y = 0;
vd->window.size.width = vd->windowOld.size.width = vd->windowTarget.size.width = DENG_WINDOW->width();
vd->window.size.height = vd->windowOld.size.height = vd->windowTarget.size.height = DENG_WINDOW->height();
vd->window.size.width = vd->windowOld.size.width = vd->windowTarget.size.width = DENG_GAMEVIEW_WIDTH;
vd->window.size.height = vd->windowOld.size.height = vd->windowTarget.size.height = DENG_GAMEVIEW_HEIGHT;
vd->windowInter = 1;
#endif
}
Expand Down Expand Up @@ -435,10 +435,10 @@ void R_UpdateViewPortGeometry(viewport_t *port, int col, int row)
DENG_ASSERT(port);

RectRaw *rect = &port->geometry;
int const x = col * DENG_WINDOW->width() / gridCols;
int const y = row * DENG_WINDOW->height() / gridRows;
int const width = (col+1) * DENG_WINDOW->width() / gridCols - x;
int const height = (row+1) * DENG_WINDOW->height() / gridRows - y;
int const x = col * DENG_GAMEVIEW_WIDTH / gridCols;
int const y = row * DENG_GAMEVIEW_HEIGHT / gridRows;
int const width = (col+1) * DENG_GAMEVIEW_WIDTH / gridCols - x;
int const height = (row+1) * DENG_GAMEVIEW_HEIGHT / gridRows - y;
ddhook_viewport_reshape_t p;
bool doReshape = false;

Expand Down Expand Up @@ -919,8 +919,8 @@ void R_UseViewPort(viewport_t *vp)
if(!vp)
{
currentViewport = NULL;
glViewport(0, FLIP(0 + DENG_WINDOW->height() - 1),
DENG_WINDOW->width(), DENG_WINDOW->height());
glViewport(0, FLIP(0 + DENG_GAMEVIEW_HEIGHT - 1),
DENG_GAMEVIEW_WIDTH, DENG_GAMEVIEW_HEIGHT);
}
else
{
Expand Down
16 changes: 8 additions & 8 deletions doomsday/client/src/render/rend_main.cpp
Expand Up @@ -2669,7 +2669,7 @@ static void drawLabel(Vector3d const &origin, String const &label, float scale,
static void drawLabel(Vector3d const &origin, String const &label)
{
ddouble distToEye = (Vector3d(vOrigin[VX], vOrigin[VZ], vOrigin[VY]) - origin).length();
drawLabel(origin, label, distToEye / (DENG_WINDOW->width() / 2), 1 - distToEye / 2000);
drawLabel(origin, label, distToEye / (DENG_GAMEVIEW_WIDTH / 2), 1 - distToEye / 2000);
}

/*
Expand Down Expand Up @@ -2903,7 +2903,7 @@ void Rend_DrawLightModMatrix()
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
glOrtho(0, DENG_WINDOW->width(), DENG_WINDOW->height(), 0, -1, 1);
glOrtho(0, DENG_GAMEVIEW_WIDTH, DENG_GAMEVIEW_HEIGHT, 0, -1, 1);

glTranslatef(BORDER, BORDER, 0);

Expand Down Expand Up @@ -3094,7 +3094,7 @@ static int drawMobjBBox(thinker_t *th, void * /*context*/)

Vector3d eye(vOrigin[VX], vOrigin[VZ], vOrigin[VY]);

float alpha = 1 - ((Vector3d(eye - Vector3d(mo->origin)).length() / (DENG_WINDOW->width()/2)) / 4);
float alpha = 1 - ((Vector3d(eye - Vector3d(mo->origin)).length() / (DENG_GAMEVIEW_WIDTH/2)) / 4);
if(alpha < .25f)
alpha = .25f; // Don't make them totally invisible.

Expand Down Expand Up @@ -3165,7 +3165,7 @@ static void Rend_DrawBoundingBoxes(Map &map)
polyobj->aaBox.minY + length,
sec.floor().height());

float alpha = 1 - ((Vector3d(eye - pos).length() / (DENG_WINDOW->width()/2)) / 4);
float alpha = 1 - ((Vector3d(eye - pos).length() / (DENG_GAMEVIEW_WIDTH/2)) / 4);
if(alpha < .25f)
alpha = .25f; // Don't make them totally invisible.

Expand Down Expand Up @@ -3364,7 +3364,7 @@ static void drawSoundOrigin(Vector3d const &origin, char const *label, Vector3d

if(alpha > 0)
{
float scale = dist / (DENG_WINDOW->width() / 2);
float scale = dist / (DENG_GAMEVIEW_WIDTH / 2);

glMatrixMode(GL_MODELVIEW);
glPushMatrix();
Expand Down Expand Up @@ -3522,7 +3522,7 @@ static int drawPolyobjVertexes(Polyobj *po, void * /*context*/)
if(distToEye < MAX_VERTEX_POINT_DIST)
{
drawLabel(origin, labelForVertex(&vtx),
distToEye / (DENG_WINDOW->width() / 2),
distToEye / (DENG_GAMEVIEW_WIDTH / 2),
1 - distToEye / MAX_VERTEX_POINT_DIST);
}
}
Expand Down Expand Up @@ -3624,7 +3624,7 @@ static void drawVertexes(Map &map)
if(distToEye < MAX_VERTEX_POINT_DIST)
{
drawLabel(origin, labelForVertex(vertex),
distToEye / (DENG_WINDOW->width() / 2),
distToEye / (DENG_GAMEVIEW_WIDTH / 2),
1 - distToEye / MAX_VERTEX_POINT_DIST);
}
}
Expand Down Expand Up @@ -3674,7 +3674,7 @@ static void drawSectors(Map &map)
if(distToEye < MAX_LABEL_DIST)
{
drawLabel(origin, labelForCluster(cluster),
distToEye / (DENG_WINDOW->width() / 2),
distToEye / (DENG_GAMEVIEW_WIDTH / 2),
1 - distToEye / MAX_LABEL_DIST);
}
}
Expand Down
2 changes: 1 addition & 1 deletion doomsday/client/src/render/rend_model.cpp
Expand Up @@ -1009,7 +1009,7 @@ static void Mod_RenderSubModel(uint number, rendmodelparams_t const *parm)
// Determine the suitable LOD.
if(mdl->info.numLODs > 1 && rend_model_lod != 0)
{
float lodFactor = rend_model_lod * DENG_WINDOW->width() / 640.0f / (Rend_FieldOfView() / 90.0f);
float lodFactor = rend_model_lod * DENG_GAMEVIEW_WIDTH / 640.0f / (Rend_FieldOfView() / 90.0f);
if(!FEQUAL(lodFactor, 0))
lodFactor = 1 / lodFactor;

Expand Down
2 changes: 1 addition & 1 deletion doomsday/client/src/render/rend_particle.cpp
Expand Up @@ -925,7 +925,7 @@ static int drawGeneratorOrigin(ptcgen_t* gen, void* parameters)
if(alpha > 0)
{
Point2Raw const labelOrigin(2, 2);
float scale = dist / (DENG_WINDOW->width() / 2);
float scale = dist / (DENG_GAMEVIEW_WIDTH / 2);
char buf[80];

sprintf(buf, "%i", gens->generatorId(gen));
Expand Down
2 changes: 1 addition & 1 deletion doomsday/client/src/render/sprite.cpp
Expand Up @@ -126,7 +126,7 @@ static int drawThinkerId(thinker_t *thinker, void *context)

if(alpha > 0)
{
float scale = dist / (DENG_WINDOW->width() / 2);
float scale = dist / (DENG_GAMEVIEW_WIDTH / 2);

glMatrixMode(GL_MODELVIEW);
glPushMatrix();
Expand Down
7 changes: 6 additions & 1 deletion doomsday/client/src/ui/clientwindow.cpp
Expand Up @@ -136,7 +136,7 @@ public IGameChangeObserver
legacy = new LegacyWidget(LEGACY_WIDGET_NAME);
legacy->rule()
.setLeftTop (root.viewLeft(), root.viewTop())
.setRightBottom(root.viewRight(), root.viewBottom());
.setRightBottom(root.viewWidth() / 2, root.viewBottom());
// Initially the widget is disabled. It will be enabled when the window
// is visible and ready to be drawn.
legacy->disable();
Expand Down Expand Up @@ -378,6 +378,11 @@ NotificationWidget &ClientWindow::notifications()
return *d->notifications;
}

LegacyWidget &ClientWindow::game()
{
return *d->legacy;
}

BusyWidget &ClientWindow::busy()
{
return *d->busy;
Expand Down

0 comments on commit 9b3530a

Please sign in to comment.