Skip to content

Commit

Permalink
Refactor: UIWidget geometry is now represented as Rect (was RectRaw)
Browse files Browse the repository at this point in the history
Composite head-up display geometry is now precisely calculated by
union of child widget geometries.
  • Loading branch information
danij-deng committed Jan 2, 2012
1 parent d82a945 commit 1488c55
Show file tree
Hide file tree
Showing 12 changed files with 500 additions and 722 deletions.
6 changes: 5 additions & 1 deletion doomsday/engine/api/doomsday.def
@@ -1,6 +1,6 @@
; Doomsday Engine API (Routines exported from Doomsday.exe).
;
; Highest ordinal is currently: --> 730 <--
; Highest ordinal is currently: --> 734 <--
; Other free ordinals:
;
; 126
Expand Down Expand Up @@ -133,6 +133,8 @@ EXPORTS
Rect_Y @672 NONAME
Rect_SetOrigin @673 NONAME
Rect_SetXY @674 NONAME
Rect_SetX @731 NONAME
Rect_SetY @732 NONAME
Rect_Size @675 NONAME
Rect_SetSize @676 NONAME
Rect_SetWidthHeight @677 NONAME
Expand Down Expand Up @@ -164,6 +166,8 @@ EXPORTS
Rectf_Y @715 NONAME
Rectf_SetOrigin @716 NONAME
Rectf_SetXY @717 NONAME
Rectf_SetX @733 NONAME
Rectf_SetY @734 NONAME
Rectf_Size @718 NONAME
Rectf_SetSize @719 NONAME
Rectf_SetWidthHeight @720 NONAME
Expand Down
4 changes: 4 additions & 0 deletions doomsday/engine/api/rect.h
Expand Up @@ -62,6 +62,8 @@ int Rect_X(const Rect* r);
int Rect_Y(const Rect* r);

void Rect_SetOrigin(Rect* r, const Point2* origin);
void Rect_SetX(Rect* r, int x);
void Rect_SetY(Rect* r, int y);
void Rect_SetXY(Rect* r, int x, int y);

const Size2* Rect_Size(const Rect* rect);
Expand Down Expand Up @@ -122,6 +124,8 @@ int Rectf_X(const Rectf* r);
int Rectf_Y(const Rectf* r);

void Rectf_SetOrigin(Rectf* rect, const Point2f* origin);
void Rectf_SetX(Rectf* r, double x);
void Rectf_SetY(Rectf* r, double y);
void Rectf_SetXY(Rectf* r, double x, double y);

const Size2f* Rectf_Size(const Rectf* rect);
Expand Down
24 changes: 24 additions & 0 deletions doomsday/engine/portable/src/rect.c
Expand Up @@ -140,6 +140,18 @@ void Rect_SetOrigin(Rect* r, const Point2* origin)
Point2_SetXY(r->origin, Point2_X(origin), Point2_Y(origin));
}

void Rect_SetX(Rect* r, int x)
{
assert(r);
Point2_SetX(r->origin, x);
}

void Rect_SetY(Rect* r, int y)
{
assert(r);
Point2_SetY(r->origin, y);
}

void Rect_SetXY(Rect* r, int x, int y)
{
assert(r);
Expand Down Expand Up @@ -393,6 +405,18 @@ void Rectf_SetOrigin(Rectf* r, const Point2f* origin)
Point2f_SetXY(r->origin, Point2f_X(origin), Point2f_Y(origin));
}

void Rectf_SetX(Rectf* r, double x)
{
assert(r);
Point2f_SetX(r->origin, x);
}

void Rectf_SetY(Rectf* r, double y)
{
assert(r);
Point2f_SetY(r->origin, y);
}

void Rectf_SetXY(Rectf* r, double x, double y)
{
assert(r);
Expand Down
6 changes: 3 additions & 3 deletions doomsday/plugins/common/include/hu_lib.h
Expand Up @@ -757,7 +757,7 @@ typedef struct uiwidget_s {
Size2Raw maxSize;

/// Geometry of this widget in pixels.
RectRaw geometry;
Rect* geometry;

/// Local player number associated with this widget.
/// \todo refactor away.
Expand All @@ -784,15 +784,15 @@ int UIWidget_Alignment(uiwidget_t* obj);

float UIWidget_Opacity(uiwidget_t* obj);

const RectRaw* UIWidget_Geometry(uiwidget_t* obj);
const Rect* UIWidget_Geometry(uiwidget_t* obj);

int UIWidget_MaximumHeight(uiwidget_t* obj);

const Size2Raw* UIWidget_MaximumSize(uiwidget_t* obj);

int UIWidget_MaximumWidth(uiwidget_t* obj);

const Point2Raw* UIWidget_Origin(uiwidget_t* obj);
const Point2* UIWidget_Origin(uiwidget_t* obj);

/// @return Local player number of the owner of this widget.
int UIWidget_Player(uiwidget_t* obj);
Expand Down
64 changes: 35 additions & 29 deletions doomsday/plugins/common/src/hu_automap.c
Expand Up @@ -159,11 +159,11 @@ static void calcViewScaleFactors(uiwidget_t* obj)
if(dist < 0)
dist = -dist;

a = UIWidget_Geometry(obj)->size.width / dist;
b = UIWidget_Geometry(obj)->size.height / dist;
a = Rect_Width(UIWidget_Geometry(obj)) / dist;
b = Rect_Height(UIWidget_Geometry(obj)) / dist;

am->minScaleMTOF = (a < b ? a : b);
am->maxScaleMTOF = UIWidget_Geometry(obj)->size.height / am->minScale;
am->maxScaleMTOF = Rect_Height(UIWidget_Geometry(obj)) / am->minScale;

am->updateViewScale = false;
}
Expand Down Expand Up @@ -1146,11 +1146,14 @@ static void setupGLStateForMap(uiwidget_t* obj)
const float alpha = uiRendState->pageAlpha;
int player = UIWidget_Player(obj);
float angle, plx, ply, bgColor[3];
RectRaw geometry;
assert(obj->type == GUI_AUTOMAP);

UIAutomap_ParallaxLayerOrigin(obj, &plx, &ply);
angle = UIAutomap_CameraAngle(obj);

Rect_Raw(obj->geometry, &geometry);

// Check for scissor box (to clip the map lines and stuff).
// Store the old scissor state.
DGL_GetIntegerv(DGL_SCISSOR_TEST, am->scissorState);
Expand Down Expand Up @@ -1189,17 +1192,17 @@ static void setupGLStateForMap(uiwidget_t* obj)
DGL_SetRawImage(autopageLumpNum, DGL_REPEAT, DGL_REPEAT);
DGL_Color4f(bgColor[CR], bgColor[CG], bgColor[CB], cfg.automapOpacity * alpha);

DGL_Translatef(UIWidget_Geometry(obj)->origin.x, UIWidget_Geometry(obj)->origin.y, 0);
DGL_Translatef(geometry.origin.x, geometry.origin.y, 0);

// Apply the parallax scrolling, map rotation and counteract the
// aspect of the quad (sized to map window dimensions).
DGL_Translatef(UIAutomap_MapToFrame(obj, plx) + .5f,
UIAutomap_MapToFrame(obj, ply) + .5f, 0);
DGL_Rotatef(360-angle, 0, 0, 1);
DGL_Scalef(1, (float)UIWidget_Geometry(obj)->size.height / UIWidget_Geometry(obj)->size.width, 1);
DGL_Scalef(1, (float)geometry.size.height / geometry.size.width, 1);
DGL_Translatef(-(.5f), -(.5f), 0);

DGL_DrawRect2(0, 0, obj->geometry.size.width, obj->geometry.size.height);
DGL_DrawRect2(0, 0, geometry.size.width, geometry.size.height);

DGL_MatrixMode(DGL_TEXTURE);
DGL_PopMatrix();
Expand All @@ -1211,7 +1214,7 @@ static void setupGLStateForMap(uiwidget_t* obj)
// Nope just a solid color.
DGL_SetNoMaterial();
DGL_Color4f(bgColor[CR], bgColor[CG], bgColor[CB], cfg.automapOpacity * alpha);
DGL_DrawRect2(0, 0, obj->geometry.size.width, obj->geometry.size.height);
DGL_DrawRect2(0, 0, geometry.size.width, geometry.size.height);
}

#if __JDOOM64__
Expand Down Expand Up @@ -1240,7 +1243,7 @@ static void setupGLStateForMap(uiwidget_t* obj)

iconAlpha = MINMAX_OF(.0f, alpha, .5f);

spacing = UIWidget_Geometry(obj)->size.height / num;
spacing = geometry.size.height / num;
y = 0;

for(i = 0; i < 3; ++i)
Expand All @@ -1251,8 +1254,8 @@ static void setupGLStateForMap(uiwidget_t* obj)
DGL_SetPSprite(sprInfo.material);
DGL_Enable(DGL_TEXTURE_2D);

scale = UIWidget_Geometry(obj)->size.height / (sprInfo.geometry.size.height * num);
x = UIWidget_Geometry(obj)->size.width - sprInfo.geometry.size.width * scale;
scale = geometry.size.height / (sprInfo.geometry.size.height * num);
x = geometry.size.width - sprInfo.geometry.size.width * scale;
w = sprInfo.geometry.size.width;
h = sprInfo.geometry.size.height;

Expand Down Expand Up @@ -1288,10 +1291,10 @@ static void setupGLStateForMap(uiwidget_t* obj)
Size2Raw portSize;

R_ViewPortSize(obj->player, &portSize);
clipRegion.origin.x = .5f + FIXXTOSCREENX(obj->geometry.origin.x + am->border);
clipRegion.origin.y = .5f + FIXYTOSCREENY(obj->geometry.origin.y + am->border);
clipRegion.size.width = .5f + FIXXTOSCREENX(obj->geometry.size.width - am->border*2);
clipRegion.size.height = .5f + FIXYTOSCREENY(obj->geometry.size.height - am->border*2);
clipRegion.origin.x = .5f + FIXXTOSCREENX(geometry.origin.x + am->border);
clipRegion.origin.y = .5f + FIXYTOSCREENY(geometry.origin.y + am->border);
clipRegion.size.width = .5f + FIXXTOSCREENX(geometry.size.width - am->border*2);
clipRegion.size.height = .5f + FIXYTOSCREENY(geometry.size.height - am->border*2);

DGL_Scissor(clipRegion.origin.x, clipRegion.origin.y,
clipRegion.size.width, clipRegion.size.height);
Expand Down Expand Up @@ -1388,6 +1391,7 @@ void UIAutomap_Drawer(uiwidget_t* obj, const Point2Raw* offset)
const float alpha = uiRendState->pageAlpha;
player_t* plr = &players[UIWidget_Player(obj)];
float vx, vy, angle, oldLineWidth;
RectRaw geometry;
int i;
assert(obj->type == GUI_AUTOMAP);

Expand All @@ -1397,6 +1401,7 @@ void UIAutomap_Drawer(uiwidget_t* obj, const Point2Raw* offset)
rs.plr = plr;
UIAutomap_CameraOrigin(obj, &vx, &vy);
angle = UIAutomap_CameraAngle(obj);
Rect_Raw(obj->geometry, &geometry);

// Freeze the lists if the map is fading out from being open, or for debug.
if((++updateWait % 10) && am->constructMap && !freezeMapRLs && UIAutomap_Active(obj))
Expand All @@ -1410,8 +1415,8 @@ void UIAutomap_Drawer(uiwidget_t* obj, const Point2Raw* offset)

DGL_MatrixMode(DGL_MODELVIEW);
if(offset) DGL_Translatef(offset->x, offset->y, 0);
DGL_Translatef(obj->geometry.size.width / 2,
obj->geometry.size.height / 2, 0);
DGL_Translatef(geometry.size.width / 2,
geometry.size.height / 2, 0);
DGL_Rotatef(angle, 0, 0, 1);
DGL_Scalef(1, -1, 1);
DGL_Scalef(am->scaleMTOF, am->scaleMTOF, 1);
Expand Down Expand Up @@ -1454,10 +1459,10 @@ DGL_End();
DGL_LoadIdentity();

DGL_PushMatrix();
DGL_Scalef(1.f / (obj->geometry.size.width - am->border*2),
1.f / (obj->geometry.size.height - am->border*2), 1);
DGL_Translatef(obj->geometry.size.width /2 - am->border,
obj->geometry.size.height /2 - am->border, 0);
DGL_Scalef(1.f / (geometry.size.width - am->border*2),
1.f / (geometry.size.height - am->border*2), 1);
DGL_Translatef(geometry.size.width /2 - am->border,
geometry.size.height /2 - am->border, 0);
DGL_Rotatef(-angle, 0, 0, 1);
DGL_Scalef(am->scaleMTOF, am->scaleMTOF, 1);
DGL_Translatef(-vx, -vy, 0);
Expand Down Expand Up @@ -1749,8 +1754,8 @@ void UIAutomap_Ticker(uiwidget_t* obj, timespan_t ticLength)
float viewPoint[2], rads, viewWidth, viewHeight;

// Determine the dimensions of the view window in am coordinates.
viewWidth = UIAutomap_FrameToMap(obj, obj->geometry.size.width - (am->border*2));
viewHeight = UIAutomap_FrameToMap(obj, obj->geometry.size.height - (am->border*2));
viewWidth = UIAutomap_FrameToMap(obj, Rect_Width(obj->geometry) - (am->border*2));
viewHeight = UIAutomap_FrameToMap(obj, Rect_Height(obj->geometry) - (am->border*2));
am->topLeft[0] = am->bottomLeft[0] = -viewWidth/2;
am->topLeft[1] = am->topRight[1] = viewHeight/2;
am->bottomRight[0] = am->topRight[0] = viewWidth/2;
Expand All @@ -1771,8 +1776,8 @@ void UIAutomap_Ticker(uiwidget_t* obj, timespan_t ticLength)
am->topRight[0] += viewPoint[0]; am->topRight[1] += viewPoint[1];
}

width = UIAutomap_FrameToMap(obj, UIWidget_Geometry(obj)->size.width);
height = UIAutomap_FrameToMap(obj, UIWidget_Geometry(obj)->size.height);
width = UIAutomap_FrameToMap(obj, Rect_Width(obj->geometry));
height = UIAutomap_FrameToMap(obj, Rect_Height(obj->geometry));

// Calculate the in-view, AABB.
{ // Rotation-aware.
Expand Down Expand Up @@ -1859,12 +1864,13 @@ void UIAutomap_UpdateGeometry(uiwidget_t* obj)
newGeom.size.width = .5f + newGeom.size.width * scaleX;
newGeom.size.height = .5f + newGeom.size.height * scaleY;

if(newGeom.origin.x != obj->geometry.origin.x ||
newGeom.origin.y != obj->geometry.origin.y ||
newGeom.size.width != obj->geometry.size.width ||
newGeom.size.height != obj->geometry.size.height)
if(newGeom.origin.x != Rect_X(obj->geometry) ||
newGeom.origin.y != Rect_Y(obj->geometry) ||
newGeom.size.width != Rect_Width(obj->geometry) ||
newGeom.size.height != Rect_Height(obj->geometry))
{
memcpy(&obj->geometry, &newGeom, sizeof obj->geometry);
Rect_SetXY(obj->geometry, newGeom.origin.x, newGeom.origin.y);
Rect_SetWidthHeight(obj->geometry, newGeom.size.width, newGeom.size.height);

// Now the screen dimensions have changed we have to update scaling
// factors accordingly.
Expand Down
8 changes: 4 additions & 4 deletions doomsday/plugins/common/src/hu_chat.c
Expand Up @@ -395,15 +395,15 @@ void UIChat_Drawer(uiwidget_t* obj, const Point2Raw* offset)
void UIChat_UpdateGeometry(uiwidget_t* obj)
{
const char* text = UIChat_Text(obj);
obj->geometry.size.width = 0;
obj->geometry.size.height = 0;
assert(obj->type == GUI_CHAT);

Rect_SetWidthHeight(obj->geometry, 0, 0);

if(!UIChat_IsActive(obj)) return;

FR_SetFont(obj->font);
obj->geometry.size.width = cfg.msgScale * (FR_TextWidth(text) + FR_CharWidth('_'));
obj->geometry.size.height = cfg.msgScale * (MAX_OF(FR_TextHeight(text), FR_CharHeight('_')));
Rect_SetWidthHeight(obj->geometry, cfg.msgScale * (FR_TextWidth(text) + FR_CharWidth('_')),
cfg.msgScale * (MAX_OF(FR_TextHeight(text), FR_CharHeight('_'))));
}

int UIChat_ParseDestination(const char* str)
Expand Down

0 comments on commit 1488c55

Please sign in to comment.