Skip to content

Commit

Permalink
Refactor: Enforce data hiding in ddwindow_t; renamed to Window
Browse files Browse the repository at this point in the history
  • Loading branch information
skyjake committed Mar 11, 2012
1 parent 91941a8 commit 5f6d441
Show file tree
Hide file tree
Showing 30 changed files with 353 additions and 279 deletions.
20 changes: 19 additions & 1 deletion doomsday/engine/portable/include/sys_console.h
Expand Up @@ -29,10 +29,28 @@
#ifndef __DOOMSDAY_WINCONSOLE_H__
#define __DOOMSDAY_WINCONSOLE_H__

struct consolewindow_s;

#include "sys_window.h"
#include "sys_input.h"

ddwindow_t* Sys_ConInit(const char* title);
// Console window state.
typedef struct consolewindow_s {
#if defined(WIN32)
HANDLE hcScreen;
CONSOLE_SCREEN_BUFFER_INFO cbInfo;
WORD attrib;
#elif defined(UNIX)
WINDOW *winTitle, *winText, *winCommand;
#endif
int cx, cy;
int needNewLine;
struct {
int flags;
} cmdline;
} consolewindow_t;

Window* Sys_ConInit(const char* title);
void Sys_ConShutdown(uint idx);

void Sys_ConSetTitle(uint idx, const char* title);
Expand Down
1 change: 1 addition & 0 deletions doomsday/engine/portable/include/sys_opengl.h
Expand Up @@ -47,6 +47,7 @@
# define GL_GLEXT_PROTOTYPES
# ifdef MACOSX
# include <GL/gl.h>
# include <GL/glu.h>
# include <OpenGL/OpenGL.h>
# else
# include <SDL.h>
Expand Down
69 changes: 33 additions & 36 deletions doomsday/engine/portable/include/sys_window.h
Expand Up @@ -68,38 +68,8 @@ typedef enum {
#define CLF_CURSOR_LARGE 0x1 // Use the large command line cursor.
/**@}*/

typedef struct {
ddwindowtype_t type;
boolean inited;
/// \note SDL cannot move windows; thus origin is ignored.
RectRaw geometry;
int flags;
#if defined(WIN32)
HWND hWnd; // Needed for input (among other things).
#endif
union {
struct {
#if defined(WIN32)
HGLRC glContext;
#endif
int bpp;
} normal;
struct {
#if defined(WIN32)
HANDLE hcScreen;
CONSOLE_SCREEN_BUFFER_INFO cbInfo;
WORD attrib;
#elif defined(UNIX)
WINDOW *winTitle, *winText, *winCommand;
#endif
int cx, cy;
int needNewLine;
struct {
int flags;
} cmdline;
} console;
};
} ddwindow_t;
struct ddwindow_s; // opaque
typedef struct ddwindow_s Window;

// Doomsday window flags.
#define DDWF_VISIBLE 0x01
Expand All @@ -122,11 +92,11 @@ typedef struct {
* to worry about NULLs. The easiest way to get information about the
* window where drawing is being is done.
*/
extern const ddwindow_t* theWindow;
extern const Window* theWindow;

// A helpful macro that changes the origin of the screen
// coordinate system.
#define FLIP(y) (theWindow->geometry.size.height - (y+1))
#define FLIP(y) (Window_Height(theWindow) - (y+1))

boolean Sys_InitWindowManager(void);
boolean Sys_ShutdownWindowManager(void);
Expand Down Expand Up @@ -160,6 +130,33 @@ uint Sys_CreateWindow(application_t* app, uint parentIDX, const Point2Raw* origi
const Size2Raw* size, int bpp, int flags, ddwindowtype_t type, const char* title, void* data);
boolean Sys_DestroyWindow(uint idx);

ddwindowtype_t Window_Type(const Window* wnd);

struct consolewindow_s* Window_Console(Window* wnd);

const struct consolewindow_s* Window_ConsoleConst(const Window* wnd);

/**
* Returns the current width of the window.
* @param wnd Window instance.
*/
int Window_Width(const Window* wnd);

/**
* Returns the current height of the window.
* @param wnd Window instance.
*/
int Window_Height(const Window* wnd);

int Window_BitsPerPixel(const Window* wnd);

/**
* Determines the size of the window.
* @param wnd Window instance.
* @return Window size.
*/
const Size2Raw* Window_Size(const Window* wnd);

void Sys_UpdateWindow(uint idx);

/**
Expand All @@ -181,8 +178,8 @@ boolean Sys_SetActiveWindow(uint idx);
boolean Sys_SetWindow(uint idx, int x, int y, int w, int h, int bpp, uint wflags, uint uflags);
boolean Sys_SetWindowTitle(uint idx, const char* title);

ddwindow_t* Sys_Window(uint idx);
ddwindow_t* Sys_MainWindow(void);
Window* Sys_Window(uint idx);
Window* Sys_MainWindow(void);

/**
*\todo This is a compromise to prevent having to refactor half the
Expand Down
16 changes: 8 additions & 8 deletions doomsday/engine/portable/src/blockmapvisual.c
Expand Up @@ -69,7 +69,7 @@ static int rendBspLeaf(BspLeaf* bspLeaf, void* parameters)
if(bspLeaf->validCount != validCount)
{
const float scale = MAX_OF(bmapDebugSize, 1);
const float width = (theWindow->geometry.size.width / 16) / scale;
const float width = (Window_Width(theWindow) / 16) / scale;
float length, dx, dy, normal[2], unit[2];
HEdge** hedgeIter, *hedge;
vec2_t start, end;
Expand Down Expand Up @@ -555,12 +555,12 @@ void Rend_BlockmapDebug(void)
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
glOrtho(0, theWindow->geometry.size.width, theWindow->geometry.size.height, 0, -1, 1);
glOrtho(0, Window_Width(theWindow), Window_Height(theWindow), 0, -1, 1);
// Orient on the center of the window.
glTranslatef((theWindow->geometry.size.width / 2), (theWindow->geometry.size.height / 2), 0);
glTranslatef((Window_Width(theWindow) / 2), (Window_Height(theWindow) / 2), 0);

// Uniform scaling factor for this visual.
scale = bmapDebugSize / MAX_OF(theWindow->geometry.size.height / 100, 1);
scale = bmapDebugSize / MAX_OF(Window_Height(theWindow) / 100, 1);
glScalef(scale, -scale, 1);

// If possible we'll tailor what we draw relative to the viewPlayer.
Expand All @@ -579,23 +579,23 @@ void Rend_BlockmapDebug(void)
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
glOrtho(0, theWindow->geometry.size.width, theWindow->geometry.size.height, 0, -1, 1);
glOrtho(0, Window_Width(theWindow), Window_Height(theWindow), 0, -1, 1);

if(followMobj)
{
// About the cell the followed Mobj is in.
BlockmapCell cell;
if(!Blockmap_Cell(blockmap, cell, followMobj->pos))
{
origin.x = theWindow->geometry.size.width / 2;
origin.x = Window_Width(theWindow) / 2;
origin.y = 30;
drawCellInfoBox(blockmap, &origin, objectTypeName, cell);
}
}

// About the Blockmap itself.
origin.x = theWindow->geometry.size.width - 10;
origin.y = theWindow->geometry.size.height - 10;
origin.x = Window_Width(theWindow) - 10;
origin.y = Window_Height(theWindow) - 10;
drawBlockmapInfo(&origin, blockmap);

glMatrixMode(GL_PROJECTION);
Expand Down
30 changes: 15 additions & 15 deletions doomsday/engine/portable/src/con_busy.c
Expand Up @@ -344,7 +344,7 @@ static void Con_BusyPrepareResources(void)
{ FN_SYSTEM_NAME":normal12", "}data/fonts/normal12.dfn" },
{ FN_SYSTEM_NAME":normal18", "}data/fonts/normal18.dfn" }
};
int fontIdx = !(theWindow->geometry.size.width > 640)? 0 : 1;
int fontIdx = !(Window_Width(theWindow) > 640)? 0 : 1;
Uri* uri = Uri_NewWithPath2(fonts[fontIdx].name, RC_NULL);
font_t* font = R_CreateFontFromFile(uri, fonts[fontIdx].path);
Uri_Delete(uri);
Expand Down Expand Up @@ -393,10 +393,10 @@ void Con_AcquireScreenshotTexture(void)
startTime = Sys_GetRealSeconds();
#endif

frame = malloc(theWindow->geometry.size.width * theWindow->geometry.size.height * 3);
GL_Grab(0, 0, theWindow->geometry.size.width, theWindow->geometry.size.height, DGL_RGB, frame);
frame = malloc(Window_Width(theWindow) * Window_Height(theWindow) * 3);
GL_Grab(0, 0, Window_Width(theWindow), Window_Height(theWindow), DGL_RGB, frame);
GL_state.maxTexSize = SCREENSHOT_TEXTURE_SIZE; // A bit of a hack, but don't use too large a texture.
texScreenshot = GL_NewTextureWithParams2(DGL_RGB, theWindow->geometry.size.width, theWindow->geometry.size.height,
texScreenshot = GL_NewTextureWithParams2(DGL_RGB, Window_Width(theWindow), Window_Height(theWindow),
frame, TXCF_NEVER_DEFER|TXCF_NO_COMPRESSION|TXCF_UPLOAD_ARG_NOSMARTFILTER, 0, GL_LINEAR, GL_LINEAR, 0 /*no anisotropy*/,
GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE);
GL_state.maxTexSize = oldMaxTexSize;
Expand Down Expand Up @@ -431,7 +431,7 @@ static void Con_BusyLoop(void)
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
glOrtho(0, theWindow->geometry.size.width, theWindow->geometry.size.height, 0, -1, 1);
glOrtho(0, Window_Width(theWindow), Window_Height(theWindow), 0, -1, 1);
}

Sys_Lock(busy_Mutex);
Expand Down Expand Up @@ -691,18 +691,18 @@ void Con_BusyDrawConsoleOutput(void)
// Dark gradient as background.
glBegin(GL_QUADS);
glColor4ub(0, 0, 0, 0);
y = theWindow->geometry.size.height - (LINE_COUNT + 3) * busyFontHgt;
y = Window_Height(theWindow) - (LINE_COUNT + 3) * busyFontHgt;
glVertex2f(0, y);
glVertex2f(theWindow->geometry.size.width, y);
glVertex2f(Window_Width(theWindow), y);
glColor4ub(0, 0, 0, 128);
glVertex2f(theWindow->geometry.size.width, theWindow->geometry.size.height);
glVertex2f(0, theWindow->geometry.size.height);
glVertex2f(Window_Width(theWindow), Window_Height(theWindow));
glVertex2f(0, Window_Height(theWindow));
glEnd();

glEnable(GL_TEXTURE_2D);

// The text lines.
topY = y = theWindow->geometry.size.height - busyFontHgt * (2 * LINE_COUNT + .5f);
topY = y = Window_Height(theWindow) - busyFontHgt * (2 * LINE_COUNT + .5f);
if(newCount > 0 ||
(nowTime >= scrollStartTime && nowTime < scrollEndTime && scrollEndTime > scrollStartTime))
{
Expand Down Expand Up @@ -730,7 +730,7 @@ void Con_BusyDrawConsoleOutput(void)
alpha = 1 - (alpha - LINE_COUNT);

FR_SetAlpha(alpha);
FR_DrawTextXY3(line->text, theWindow->geometry.size.width/2, y, ALIGN_TOP, DTF_ONLY_SHADOW);
FR_DrawTextXY3(line->text, Window_Width(theWindow)/2, y, ALIGN_TOP, DTF_ONLY_SHADOW);
}

glDisable(GL_TEXTURE_2D);
Expand All @@ -745,7 +745,7 @@ static void Con_BusyDrawer(void)
{
float pos = 0;

Con_DrawScreenshotBackground(0, 0, theWindow->geometry.size.width, theWindow->geometry.size.height);
Con_DrawScreenshotBackground(0, 0, Window_Width(theWindow), Window_Height(theWindow));

// Indefinite activity?
if((busyTask->mode & BUSYF_ACTIVITY) || (busyTask->mode & BUSYF_PROGRESS_BAR))
Expand All @@ -755,9 +755,9 @@ static void Con_BusyDrawer(void)
else // The progress is animated elsewhere.
pos = Con_GetProgress();

Con_BusyDrawIndicator(theWindow->geometry.size.width/2,
theWindow->geometry.size.height/2,
theWindow->geometry.size.height/12, pos);
Con_BusyDrawIndicator(Window_Width(theWindow)/2,
Window_Height(theWindow)/2,
Window_Height(theWindow)/12, pos);
}

// Output from the console?
Expand Down
2 changes: 1 addition & 1 deletion doomsday/engine/portable/src/con_main.c
Expand Up @@ -259,7 +259,7 @@ void Con_ResizeHistoryBuffer(void)
cw = (FR_TextWidth("AA") * consoleFontScale[0]) / 2;
if(0 != cw)
{
maxLength = MIN_OF(theWindow->geometry.size.width / cw - 2, 250);
maxLength = MIN_OF(Window_Width(theWindow) / cw - 2, 250);
}
}

Expand Down
15 changes: 8 additions & 7 deletions doomsday/engine/portable/src/dd_input.c
Expand Up @@ -1026,10 +1026,6 @@ static void postEvents(timespan_t ticLength)
}
#endif

#ifdef UNIX
SDL_PumpEvents();
#endif

if(ArgExists("-noinput")) return;

DD_ReadKeyboard();
Expand Down Expand Up @@ -1254,18 +1250,23 @@ void I_SetUIMouseMode(boolean on)
{
uiMouseMode = on;

/// @todo Update this after the Qt window management is working.

#if 0
#ifdef UNIX
if(I_MousePresent())
{
// Release mouse grab when in windowed mode.
boolean isFullScreen = true;

Sys_GetWindowFullscreen(1, &isFullScreen);
if(!isFullScreen)
{
SDL_WM_GrabInput(on? SDL_GRAB_OFF : SDL_GRAB_ON);
}
}
#endif
#endif
}

/**
Expand Down Expand Up @@ -1334,8 +1335,8 @@ void DD_ReadMouse(timespan_t ticLength)
if(uiMouseMode)
{
// Scale the movement depending on screen resolution.
xpos *= MAX_OF(1, theWindow->geometry.size.width / 800.0f);
ypos *= MAX_OF(1, theWindow->geometry.size.height / 600.0f);
xpos *= MAX_OF(1, Window_Width(theWindow) / 800.0f);
ypos *= MAX_OF(1, Window_Height(theWindow) / 600.0f);
}
else
{
Expand Down Expand Up @@ -2114,7 +2115,7 @@ void Rend_AllInputDeviceStateVisuals(void)
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
glOrtho(0, theWindow->geometry.size.width, theWindow->geometry.size.height, 0, -1, 1);
glOrtho(0, Window_Width(theWindow), Window_Height(theWindow), 0, -1, 1);

if(devRendKeyState)
{
Expand Down
2 changes: 1 addition & 1 deletion doomsday/engine/portable/src/dd_loop.c
Expand Up @@ -209,7 +209,7 @@ static void drawAndUpdate(void)

// Draw any full window game graphics.
if(DD_GameLoaded() && gx.DrawWindow)
gx.DrawWindow(&theWindow->geometry.size);
gx.DrawWindow(Window_Size(theWindow));
}
}

Expand Down
8 changes: 4 additions & 4 deletions doomsday/engine/portable/src/dd_main.c
Expand Up @@ -460,8 +460,8 @@ void DD_StartTitle(void)
Str_Init(&setupCmds);

// Configure the predefined fonts (all normal, variable width).
fontName = R_ChooseVariableFont(FS_NORMAL, theWindow->geometry.size.width,
theWindow->geometry.size.height);
fontName = R_ChooseVariableFont(FS_NORMAL, Window_Width(theWindow),
Window_Height(theWindow));
for(i = 1; i <= FIPAGE_NUM_PREDEFINED_FONTS; ++i)
{
Str_Appendf(&setupCmds, "prefont %i "FN_SYSTEM_NAME":%s\n", i, fontName);
Expand Down Expand Up @@ -2028,10 +2028,10 @@ int DD_GetInteger(int ddvalue)
switch(ddvalue)
{
case DD_WINDOW_WIDTH:
return theWindow->geometry.size.width;
return Window_Width(theWindow);

case DD_WINDOW_HEIGHT:
return theWindow->geometry.size.height;
return Window_Height(theWindow);

case DD_DYNLIGHT_TEXTURE:
return (int) GL_PrepareLSTexture(LST_DYNAMIC);
Expand Down

0 comments on commit 5f6d441

Please sign in to comment.