2006-02-24 04:48:15 +00:00
|
|
|
/*
|
|
|
|
** v_draw.cpp
|
|
|
|
** Draw patches and blocks to a canvas
|
|
|
|
**
|
|
|
|
**---------------------------------------------------------------------------
|
2006-06-11 01:37:00 +00:00
|
|
|
** Copyright 1998-2006 Randy Heit
|
2006-02-24 04:48:15 +00:00
|
|
|
** All rights reserved.
|
|
|
|
**
|
|
|
|
** Redistribution and use in source and binary forms, with or without
|
|
|
|
** modification, are permitted provided that the following conditions
|
|
|
|
** are met:
|
|
|
|
**
|
|
|
|
** 1. Redistributions of source code must retain the above copyright
|
|
|
|
** notice, this list of conditions and the following disclaimer.
|
|
|
|
** 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
** notice, this list of conditions and the following disclaimer in the
|
|
|
|
** documentation and/or other materials provided with the distribution.
|
|
|
|
** 3. The name of the author may not be used to endorse or promote products
|
|
|
|
** derived from this software without specific prior written permission.
|
|
|
|
**
|
|
|
|
** THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
** IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
** OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
** IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
** NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
** THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
**---------------------------------------------------------------------------
|
|
|
|
**
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
|
|
|
|
#include "doomtype.h"
|
|
|
|
#include "v_video.h"
|
|
|
|
#include "m_swap.h"
|
|
|
|
#include "r_defs.h"
|
|
|
|
#include "r_draw.h"
|
|
|
|
#include "r_things.h"
|
|
|
|
|
|
|
|
#include "i_system.h"
|
|
|
|
#include "i_video.h"
|
|
|
|
#include "templates.h"
|
|
|
|
|
|
|
|
// [RH] Stretch values to make a 320x200 image best fit the screen
|
|
|
|
// without using fractional steppings
|
|
|
|
int CleanXfac, CleanYfac;
|
|
|
|
|
|
|
|
// [RH] Effective screen sizes that the above scale values give you
|
|
|
|
int CleanWidth, CleanHeight;
|
|
|
|
|
|
|
|
CVAR (Bool, hud_scale, false, CVAR_ARCHIVE);
|
|
|
|
|
2007-12-20 04:36:43 +00:00
|
|
|
void STACK_ARGS DCanvas::DrawTexture (FTexture *img, int x, int y, int tags_first, ...)
|
|
|
|
{
|
|
|
|
va_list tags;
|
|
|
|
va_start(tags, tags_first);
|
|
|
|
DrawTextureV(img, x, y, tags_first, tags);
|
|
|
|
}
|
|
|
|
|
|
|
|
void STACK_ARGS DCanvas::DrawTextureV(FTexture *img, int x, int y, uint32 tag, va_list tags)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
|
|
|
FTexture::Span unmaskedSpan[2];
|
|
|
|
const FTexture::Span **spanptr, *spans;
|
|
|
|
static BYTE identitymap[256];
|
|
|
|
static short bottomclipper[MAXWIDTH], topclipper[MAXWIDTH];
|
2007-12-20 04:36:43 +00:00
|
|
|
|
|
|
|
DrawParms parms;
|
|
|
|
|
|
|
|
if (!ParseDrawTextureTags(img, x, y, tag, tags, &parms))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (parms.masked)
|
|
|
|
{
|
|
|
|
spanptr = &spans;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
spanptr = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
fixedcolormap = identitymap;
|
|
|
|
ESPSResult mode = R_SetPatchStyle (parms.style, parms.alpha, 0, parms.fillcolor);
|
|
|
|
|
|
|
|
if (parms.style != STYLE_Shaded)
|
|
|
|
{
|
2007-12-23 14:13:29 +00:00
|
|
|
if (parms.font != NULL)
|
2007-12-20 04:36:43 +00:00
|
|
|
{
|
2007-12-23 21:56:46 +00:00
|
|
|
if (img->UseType == FTexture::TEX_FontChar)
|
|
|
|
dc_colormap = parms.font->GetColorTranslation (EColorRange(parms.translation));
|
|
|
|
else
|
|
|
|
dc_colormap = identitymap;
|
2007-12-23 14:13:29 +00:00
|
|
|
}
|
|
|
|
else if (parms.translation != 0)
|
|
|
|
{
|
|
|
|
dc_colormap = translationtables[(parms.translation&0xff00)>>8] + (parms.translation&0x00ff)*256;
|
2007-12-20 04:36:43 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
dc_colormap = identitymap;
|
2007-12-23 21:56:46 +00:00
|
|
|
}
|
2007-12-20 04:36:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
BYTE *destorgsave = dc_destorg;
|
|
|
|
dc_destorg = screen->GetBuffer();
|
|
|
|
|
|
|
|
fixed_t x0 = parms.x - Scale (parms.left, parms.destwidth, parms.texwidth);
|
|
|
|
fixed_t y0 = parms.y - Scale (parms.top, parms.destheight, parms.texheight);
|
|
|
|
|
|
|
|
if (mode != DontDraw)
|
|
|
|
{
|
|
|
|
const BYTE *pixels;
|
|
|
|
int stop4;
|
|
|
|
|
|
|
|
if (spanptr == NULL)
|
|
|
|
{ // Create a single span for forced unmasked images
|
|
|
|
spans = unmaskedSpan;
|
|
|
|
unmaskedSpan[0].TopOffset = 0;
|
|
|
|
unmaskedSpan[0].Length = img->GetHeight();
|
|
|
|
unmaskedSpan[1].TopOffset = 0;
|
|
|
|
unmaskedSpan[1].Length = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
fixed_t centeryback = centeryfrac;
|
|
|
|
centeryfrac = 0;
|
|
|
|
|
|
|
|
sprtopscreen = y0;
|
|
|
|
spryscale = parms.destheight / img->GetHeight();
|
|
|
|
|
|
|
|
// Fix precision errors that are noticeable at some resolutions
|
|
|
|
if (((y0 + parms.destheight) >> FRACBITS) > ((y0 + spryscale * img->GetHeight()) >> FRACBITS))
|
|
|
|
{
|
|
|
|
spryscale++;
|
|
|
|
}
|
|
|
|
|
|
|
|
sprflipvert = false;
|
|
|
|
dc_iscale = 0xffffffffu / (unsigned)spryscale;
|
|
|
|
dc_texturemid = FixedMul (-y0, dc_iscale);
|
|
|
|
fixed_t frac = 0;
|
|
|
|
fixed_t xiscale = DivScale32 (img->GetWidth(), parms.destwidth);
|
|
|
|
int x2 = (x0 + parms.destwidth) >> FRACBITS;
|
|
|
|
|
|
|
|
if (bottomclipper[0] != parms.dclip)
|
|
|
|
{
|
|
|
|
clearbufshort (bottomclipper, screen->GetWidth(), (short)parms.dclip);
|
|
|
|
if (identitymap[1] != 1)
|
|
|
|
{
|
|
|
|
for (int i = 0; i < 256; ++i)
|
|
|
|
{
|
|
|
|
identitymap[i] = i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (parms.uclip != 0)
|
|
|
|
{
|
|
|
|
if (topclipper[0] != parms.uclip)
|
|
|
|
{
|
|
|
|
clearbufshort (topclipper, screen->GetWidth(), (short)parms.uclip);
|
|
|
|
}
|
|
|
|
mceilingclip = topclipper;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
mceilingclip = zeroarray;
|
|
|
|
}
|
|
|
|
mfloorclip = bottomclipper;
|
|
|
|
|
|
|
|
if (parms.flipX)
|
|
|
|
{
|
|
|
|
frac = (img->GetWidth() << FRACBITS) - 1;
|
|
|
|
xiscale = -xiscale;
|
|
|
|
}
|
|
|
|
|
|
|
|
dc_x = x0 >> FRACBITS;
|
|
|
|
if (parms.windowleft > 0 || parms.windowright < parms.texwidth)
|
|
|
|
{
|
|
|
|
fixed_t xscale = parms.destwidth / parms.texwidth;
|
|
|
|
dc_x += (parms.windowleft * xscale) >> FRACBITS;
|
|
|
|
frac += parms.windowleft << FRACBITS;
|
|
|
|
x2 -= ((parms.texwidth - parms.windowright) * xscale) >> FRACBITS;
|
|
|
|
}
|
|
|
|
if (dc_x < parms.lclip)
|
|
|
|
{
|
|
|
|
frac += (parms.lclip - dc_x) * xiscale;
|
|
|
|
dc_x = parms.lclip;
|
|
|
|
}
|
|
|
|
if (x2 > parms.rclip)
|
|
|
|
{
|
|
|
|
x2 = parms.rclip;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (parms.destheight < 32*FRACUNIT)
|
|
|
|
{
|
|
|
|
mode = DoDraw0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mode == DoDraw0)
|
|
|
|
{
|
|
|
|
// One column at a time
|
|
|
|
stop4 = dc_x;
|
|
|
|
}
|
|
|
|
else // DoDraw1
|
|
|
|
{
|
|
|
|
// Up to four columns at a time
|
|
|
|
stop4 = x2 & ~3;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dc_x < x2)
|
|
|
|
{
|
|
|
|
while ((dc_x < stop4) && (dc_x & 3))
|
|
|
|
{
|
|
|
|
pixels = img->GetColumn (frac >> FRACBITS, spanptr);
|
|
|
|
R_DrawMaskedColumn (pixels, spans);
|
|
|
|
dc_x++;
|
|
|
|
frac += xiscale;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (dc_x < stop4)
|
|
|
|
{
|
|
|
|
rt_initcols();
|
|
|
|
for (int zz = 4; zz; --zz)
|
|
|
|
{
|
|
|
|
pixels = img->GetColumn (frac >> FRACBITS, spanptr);
|
|
|
|
R_DrawMaskedColumnHoriz (pixels, spans);
|
|
|
|
dc_x++;
|
|
|
|
frac += xiscale;
|
|
|
|
}
|
|
|
|
rt_draw4cols (dc_x - 4);
|
|
|
|
}
|
|
|
|
|
|
|
|
while (dc_x < x2)
|
|
|
|
{
|
|
|
|
pixels = img->GetColumn (frac >> FRACBITS, spanptr);
|
|
|
|
R_DrawMaskedColumn (pixels, spans);
|
|
|
|
dc_x++;
|
|
|
|
frac += xiscale;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
centeryfrac = centeryback;
|
|
|
|
}
|
|
|
|
R_FinishSetPatchStyle ();
|
|
|
|
|
|
|
|
dc_destorg = destorgsave;
|
|
|
|
|
|
|
|
if (ticdup != 0 && menuactive == MENU_Off)
|
|
|
|
{
|
|
|
|
NetUpdate ();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool DCanvas::ParseDrawTextureTags (FTexture *img, int x, int y, DWORD tag, va_list tags, DrawParms *parms) const
|
|
|
|
{
|
2006-09-14 00:02:31 +00:00
|
|
|
INTBOOL boolval;
|
2006-02-24 04:48:15 +00:00
|
|
|
int intval;
|
2007-12-23 14:13:29 +00:00
|
|
|
bool translationset = false;
|
2006-02-24 04:48:15 +00:00
|
|
|
|
|
|
|
if (img == NULL || img->UseType == FTexture::TEX_Null)
|
|
|
|
{
|
2007-12-20 04:36:43 +00:00
|
|
|
return false;
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
|
|
|
|
2007-12-20 04:36:43 +00:00
|
|
|
parms->texwidth = img->GetScaledWidth();
|
|
|
|
parms->texheight = img->GetScaledHeight();
|
|
|
|
|
|
|
|
parms->windowleft = 0;
|
|
|
|
parms->windowright = parms->texwidth;
|
|
|
|
parms->dclip = this->GetHeight();
|
|
|
|
parms->uclip = 0;
|
|
|
|
parms->lclip = 0;
|
|
|
|
parms->rclip = this->GetWidth();
|
|
|
|
parms->destwidth = parms->windowright << FRACBITS;
|
|
|
|
parms->destheight = parms->texheight << FRACBITS;
|
|
|
|
parms->top = img->GetScaledTopOffset();
|
|
|
|
parms->left = img->GetScaledLeftOffset();
|
|
|
|
parms->alpha = FRACUNIT;
|
|
|
|
parms->fillcolor = -1;
|
2007-12-23 14:13:29 +00:00
|
|
|
parms->font = NULL;
|
|
|
|
parms->translation = 0;
|
2007-12-20 04:36:43 +00:00
|
|
|
parms->alphaChannel = false;
|
|
|
|
parms->flipX = false;
|
|
|
|
parms->shadowAlpha = 0;
|
|
|
|
parms->shadowColor = 0;
|
|
|
|
parms->virtWidth = this->GetWidth();
|
|
|
|
parms->virtHeight = this->GetHeight();
|
|
|
|
parms->keepratio = false;
|
|
|
|
parms->style = STYLE_Count;
|
|
|
|
parms->masked = true;
|
|
|
|
|
|
|
|
parms->x = x << FRACBITS;
|
|
|
|
parms->y = y << FRACBITS;
|
2006-02-24 04:48:15 +00:00
|
|
|
|
|
|
|
// Parse the tag list for attributes
|
|
|
|
while (tag != TAG_DONE)
|
|
|
|
{
|
2006-05-24 15:31:21 +00:00
|
|
|
va_list *more_p;
|
2006-02-24 04:48:15 +00:00
|
|
|
DWORD data;
|
|
|
|
|
|
|
|
switch (tag)
|
|
|
|
{
|
|
|
|
case TAG_IGNORE:
|
|
|
|
default:
|
|
|
|
data = va_arg (tags, DWORD);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TAG_MORE:
|
2006-05-24 15:31:21 +00:00
|
|
|
more_p = va_arg (tags, va_list *);
|
2006-02-24 04:48:15 +00:00
|
|
|
va_end (tags);
|
2006-05-24 15:31:21 +00:00
|
|
|
#ifdef __GNUC__
|
|
|
|
__va_copy (tags, *more_p);
|
|
|
|
#else
|
|
|
|
tags = *more_p;
|
|
|
|
#endif
|
2006-02-24 04:48:15 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case DTA_DestWidth:
|
2007-12-20 04:36:43 +00:00
|
|
|
parms->destwidth = va_arg (tags, int) << FRACBITS;
|
2006-02-24 04:48:15 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case DTA_DestHeight:
|
2007-12-20 04:36:43 +00:00
|
|
|
parms->destheight = va_arg (tags, int) << FRACBITS;
|
2006-02-24 04:48:15 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case DTA_Clean:
|
2006-09-14 00:02:31 +00:00
|
|
|
boolval = va_arg (tags, INTBOOL);
|
2006-02-24 04:48:15 +00:00
|
|
|
if (boolval)
|
|
|
|
{
|
2007-12-20 04:36:43 +00:00
|
|
|
parms->x = (parms->x - 160*FRACUNIT) * CleanXfac + (Width * (FRACUNIT/2));
|
|
|
|
parms->y = (parms->y - 100*FRACUNIT) * CleanYfac + (Height * (FRACUNIT/2));
|
|
|
|
parms->destwidth = parms->texwidth * CleanXfac * FRACUNIT;
|
|
|
|
parms->destheight = parms->texheight * CleanYfac * FRACUNIT;
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DTA_CleanNoMove:
|
2006-09-14 00:02:31 +00:00
|
|
|
boolval = va_arg (tags, INTBOOL);
|
2006-02-24 04:48:15 +00:00
|
|
|
if (boolval)
|
|
|
|
{
|
2007-12-20 04:36:43 +00:00
|
|
|
parms->destwidth = parms->texwidth * CleanXfac * FRACUNIT;
|
|
|
|
parms->destheight = parms->texheight * CleanYfac * FRACUNIT;
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DTA_320x200:
|
2006-09-14 00:02:31 +00:00
|
|
|
boolval = va_arg (tags, INTBOOL);
|
2006-02-24 04:48:15 +00:00
|
|
|
if (boolval)
|
|
|
|
{
|
2007-12-20 04:36:43 +00:00
|
|
|
parms->virtWidth = 320;
|
|
|
|
parms->virtHeight = 200;
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DTA_HUDRules:
|
|
|
|
{
|
2007-12-20 04:36:43 +00:00
|
|
|
bool xright = parms->x < 0;
|
|
|
|
bool ybot = parms->y < 0;
|
2006-02-24 04:48:15 +00:00
|
|
|
intval = va_arg (tags, int);
|
|
|
|
|
|
|
|
if (hud_scale)
|
|
|
|
{
|
2007-12-20 04:36:43 +00:00
|
|
|
parms->x *= CleanXfac;
|
2006-02-24 04:48:15 +00:00
|
|
|
if (intval == HUD_HorizCenter)
|
2007-12-20 04:36:43 +00:00
|
|
|
parms->x += Width * FRACUNIT / 2;
|
2006-02-24 04:48:15 +00:00
|
|
|
else if (xright)
|
2007-12-20 04:36:43 +00:00
|
|
|
parms->x = Width * FRACUNIT + parms->x;
|
|
|
|
parms->y *= CleanYfac;
|
2006-02-24 04:48:15 +00:00
|
|
|
if (ybot)
|
2007-12-20 04:36:43 +00:00
|
|
|
parms->y = Height * FRACUNIT + parms->y;
|
|
|
|
parms->destwidth = parms->texwidth * CleanXfac * FRACUNIT;
|
|
|
|
parms->destheight = parms->texheight * CleanYfac * FRACUNIT;
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (intval == HUD_HorizCenter)
|
2007-12-20 04:36:43 +00:00
|
|
|
parms->x += Width * FRACUNIT / 2;
|
2006-02-24 04:48:15 +00:00
|
|
|
else if (xright)
|
2007-12-20 04:36:43 +00:00
|
|
|
parms->x = Width * FRACUNIT + parms->x;
|
2006-02-24 04:48:15 +00:00
|
|
|
if (ybot)
|
2007-12-20 04:36:43 +00:00
|
|
|
parms->y = Height * FRACUNIT + parms->y;
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DTA_VirtualWidth:
|
2007-12-20 04:36:43 +00:00
|
|
|
parms->virtWidth = va_arg (tags, int);
|
2006-02-24 04:48:15 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case DTA_VirtualHeight:
|
2007-12-20 04:36:43 +00:00
|
|
|
parms->virtHeight = va_arg (tags, int);
|
2006-02-24 04:48:15 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case DTA_Alpha:
|
2007-12-20 04:36:43 +00:00
|
|
|
parms->alpha = MIN<fixed_t> (FRACUNIT, va_arg (tags, fixed_t));
|
2006-02-24 04:48:15 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case DTA_AlphaChannel:
|
2007-12-20 04:36:43 +00:00
|
|
|
parms->alphaChannel = va_arg (tags, INTBOOL);
|
2006-02-24 04:48:15 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case DTA_FillColor:
|
2007-12-20 04:36:43 +00:00
|
|
|
parms->fillcolor = va_arg (tags, int);
|
2006-02-24 04:48:15 +00:00
|
|
|
break;
|
|
|
|
|
2007-12-23 14:13:29 +00:00
|
|
|
case DTA_Font:
|
|
|
|
parms->font = va_arg(tags, FFont*);
|
|
|
|
if (!translationset)
|
|
|
|
{
|
|
|
|
// default translation for fonts should be untranslated which unfortunately is not 0.
|
|
|
|
parms->translation = CR_UNTRANSLATED;
|
|
|
|
translationset = true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2006-02-24 04:48:15 +00:00
|
|
|
case DTA_Translation:
|
2007-12-23 14:13:29 +00:00
|
|
|
parms->translation = va_arg(tags, int);
|
|
|
|
translationset = true;
|
2006-02-24 04:48:15 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case DTA_FlipX:
|
2007-12-20 04:36:43 +00:00
|
|
|
parms->flipX = va_arg (tags, INTBOOL);
|
2006-02-24 04:48:15 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case DTA_TopOffset:
|
2007-12-20 04:36:43 +00:00
|
|
|
parms->top = va_arg (tags, int);
|
2006-02-24 04:48:15 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case DTA_LeftOffset:
|
2007-12-20 04:36:43 +00:00
|
|
|
parms->left = va_arg (tags, int);
|
2006-02-24 04:48:15 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case DTA_CenterOffset:
|
|
|
|
if (va_arg (tags, int))
|
|
|
|
{
|
2007-12-20 04:36:43 +00:00
|
|
|
parms->left = parms->texwidth / 2;
|
|
|
|
parms->top = parms->texheight / 2;
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DTA_CenterBottomOffset:
|
|
|
|
if (va_arg (tags, int))
|
|
|
|
{
|
2007-12-20 04:36:43 +00:00
|
|
|
parms->left = parms->texwidth / 2;
|
|
|
|
parms->top = parms->texheight;
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DTA_WindowLeft:
|
2007-12-20 04:36:43 +00:00
|
|
|
parms->windowleft = va_arg (tags, int);
|
2006-02-24 04:48:15 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case DTA_WindowRight:
|
2007-12-20 04:36:43 +00:00
|
|
|
parms->windowright = va_arg (tags, int);
|
2006-02-24 04:48:15 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case DTA_ClipTop:
|
2007-12-20 04:36:43 +00:00
|
|
|
parms->uclip = va_arg (tags, int);
|
|
|
|
if (parms->uclip < 0)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
2007-12-20 04:36:43 +00:00
|
|
|
parms->uclip = 0;
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DTA_ClipBottom:
|
2007-12-20 04:36:43 +00:00
|
|
|
parms->dclip = va_arg (tags, int);
|
|
|
|
if (parms->dclip > this->GetHeight())
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
2007-12-20 04:36:43 +00:00
|
|
|
parms->dclip = this->GetHeight();
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DTA_ClipLeft:
|
2007-12-20 04:36:43 +00:00
|
|
|
parms->lclip = va_arg (tags, int);
|
|
|
|
if (parms->lclip < 0)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
2007-12-20 04:36:43 +00:00
|
|
|
parms->lclip = 0;
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DTA_ClipRight:
|
2007-12-20 04:36:43 +00:00
|
|
|
parms->rclip = va_arg (tags, int);
|
|
|
|
if (parms->rclip > this->GetWidth())
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
2007-12-20 04:36:43 +00:00
|
|
|
parms->rclip = this->GetWidth();
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DTA_ShadowAlpha:
|
2007-12-20 04:36:43 +00:00
|
|
|
parms->shadowAlpha = MIN<fixed_t> (FRACUNIT, va_arg (tags, fixed_t));
|
2006-02-24 04:48:15 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case DTA_ShadowColor:
|
2007-12-20 04:36:43 +00:00
|
|
|
parms->shadowColor = va_arg (tags, int);
|
2006-02-24 04:48:15 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case DTA_Shadow:
|
2006-09-14 00:02:31 +00:00
|
|
|
boolval = va_arg (tags, INTBOOL);
|
2006-02-24 04:48:15 +00:00
|
|
|
if (boolval)
|
|
|
|
{
|
2007-12-20 04:36:43 +00:00
|
|
|
parms->shadowAlpha = FRACUNIT/2;
|
|
|
|
parms->shadowColor = 0;
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2007-12-20 04:36:43 +00:00
|
|
|
parms->shadowAlpha = 0;
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DTA_Masked:
|
2007-12-20 04:36:43 +00:00
|
|
|
parms->masked = va_arg (tags, INTBOOL);
|
2006-02-24 04:48:15 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case DTA_KeepRatio:
|
2007-12-20 04:36:43 +00:00
|
|
|
parms->keepratio = va_arg (tags, INTBOOL);
|
2006-02-24 04:48:15 +00:00
|
|
|
break;
|
2006-10-20 04:04:04 +00:00
|
|
|
|
|
|
|
case DTA_RenderStyle:
|
2007-12-20 04:36:43 +00:00
|
|
|
parms->style = ERenderStyle(va_arg (tags, int));
|
2006-10-20 04:04:04 +00:00
|
|
|
break;
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
|
|
|
tag = va_arg (tags, DWORD);
|
|
|
|
}
|
|
|
|
va_end (tags);
|
|
|
|
|
2007-12-20 04:36:43 +00:00
|
|
|
if (parms->virtWidth != Width || parms->virtHeight != Height)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
|
|
|
int myratio = CheckRatio (Width, Height);
|
2007-12-20 04:36:43 +00:00
|
|
|
int right = parms->x + parms->destwidth;
|
|
|
|
int bottom = parms->y + parms->destheight;
|
2007-01-22 23:14:00 +00:00
|
|
|
|
2007-12-20 04:36:43 +00:00
|
|
|
if (myratio != 0 && myratio != 4 && !parms->keepratio)
|
2006-02-24 04:48:15 +00:00
|
|
|
{ // The target surface is not 4:3, so expand the specified
|
|
|
|
// virtual size to avoid undesired stretching of the image.
|
|
|
|
// Does not handle non-4:3 virtual sizes. I'll worry about
|
|
|
|
// those if somebody expresses a desire to use them.
|
2007-12-20 04:36:43 +00:00
|
|
|
parms->x = Scale(parms->x - parms->virtWidth*FRACUNIT/2,
|
|
|
|
Width*960,
|
|
|
|
parms->virtWidth*BaseRatioSizes[myratio][0])
|
|
|
|
+ Width*FRACUNIT/2;
|
|
|
|
parms->destwidth = Scale(right - parms->virtWidth*FRACUNIT/2,
|
|
|
|
Width*960,
|
|
|
|
parms->virtWidth*BaseRatioSizes[myratio][0])
|
|
|
|
+ Width*FRACUNIT/2 - parms->x;
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2007-12-20 04:36:43 +00:00
|
|
|
parms->x = Scale (parms->x, Width, parms->virtWidth);
|
|
|
|
parms->destwidth = Scale (right, Width, parms->virtWidth) - parms->x;
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
2007-12-20 04:36:43 +00:00
|
|
|
parms->y = Scale (parms->y, Height, parms->virtHeight);
|
|
|
|
parms->destheight = Scale (bottom, Height, parms->virtHeight) - parms->y;
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
|
|
|
|
2007-12-20 04:36:43 +00:00
|
|
|
if (parms->destwidth <= 0 || parms->destheight <= 0)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
2007-12-20 04:36:43 +00:00
|
|
|
return false;
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
|
|
|
|
2007-12-20 04:36:43 +00:00
|
|
|
if (parms->style == STYLE_Count)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
2007-12-20 04:36:43 +00:00
|
|
|
if (parms->fillcolor != -1)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
2007-12-20 04:36:43 +00:00
|
|
|
if (parms->alphaChannel)
|
2006-10-20 04:04:04 +00:00
|
|
|
{
|
2007-12-20 04:36:43 +00:00
|
|
|
parms->style = STYLE_Shaded;
|
2006-10-20 04:04:04 +00:00
|
|
|
}
|
2007-12-20 04:36:43 +00:00
|
|
|
else if (parms->alpha < FRACUNIT)
|
2006-10-20 04:04:04 +00:00
|
|
|
{
|
2007-12-20 04:36:43 +00:00
|
|
|
parms->style = STYLE_TranslucentStencil;
|
2006-10-20 04:04:04 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2007-12-20 04:36:43 +00:00
|
|
|
parms->style = STYLE_Stencil;
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
|
|
|
}
|
2007-12-20 04:36:43 +00:00
|
|
|
else if (parms->alpha < FRACUNIT)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
2007-12-20 04:36:43 +00:00
|
|
|
parms->style = STYLE_Translucent;
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2007-12-20 04:36:43 +00:00
|
|
|
parms->style = STYLE_Normal;
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
|
|
|
}
|
2007-12-20 04:36:43 +00:00
|
|
|
return true;
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DCanvas::FillBorder (FTexture *img)
|
|
|
|
{
|
|
|
|
int myratio = CheckRatio (Width, Height);
|
|
|
|
if (myratio == 0)
|
|
|
|
{ // This is a 4:3 display, so no border to show
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
int bordtop, bordbottom, bordleft, bordright, bord;
|
|
|
|
if (myratio & 4)
|
|
|
|
{ // Screen is taller than it is wide
|
|
|
|
bordleft = bordright = 0;
|
|
|
|
bord = Height - Height * BaseRatioSizes[myratio][3] / 48;
|
|
|
|
bordtop = bord / 2;
|
|
|
|
bordbottom = bord - bordtop;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{ // Screen is wider than it is tall
|
|
|
|
bordtop = bordbottom = 0;
|
|
|
|
bord = Width - Width * BaseRatioSizes[myratio][3] / 48;
|
|
|
|
bordleft = bord / 2;
|
|
|
|
bordright = bord - bordleft;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (img != NULL)
|
|
|
|
{
|
|
|
|
FlatFill (0, 0, Width, bordtop, img); // Top
|
|
|
|
FlatFill (0, bordtop, bordleft, Height - bordbottom, img); // Left
|
|
|
|
FlatFill (Width - bordright, bordtop, Width, Height - bordbottom, img); // Right
|
|
|
|
FlatFill (0, Height - bordbottom, Width, Height, img); // Bottom
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2007-12-22 04:52:51 +00:00
|
|
|
Clear (0, 0, Width, bordtop, 0, 0); // Top
|
|
|
|
Clear (0, bordtop, bordleft, Height - bordbottom, 0, 0); // Left
|
|
|
|
Clear (Width - bordright, bordtop, Width, Height - bordbottom, 0, 0); // Right
|
|
|
|
Clear (0, Height - bordbottom, Width, Height, 0, 0); // Bottom
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-12-23 21:56:46 +00:00
|
|
|
// This was in m_menu.cpp but it's better to be here because
|
|
|
|
// non-software renderers must be able to override it.
|
|
|
|
void DCanvas::DrawPlayerBackdrop (DCanvas *src, const BYTE *FireRemap, int x, int y)
|
|
|
|
{
|
2007-12-23 22:22:21 +00:00
|
|
|
DCanvas *dest = this;
|
2007-12-23 21:56:46 +00:00
|
|
|
BYTE *destline, *srcline;
|
|
|
|
const int destwidth = src->GetWidth() * CleanXfac / 2;
|
|
|
|
const int destheight = src->GetHeight() * CleanYfac / 2;
|
|
|
|
const int desty = y;
|
|
|
|
const int destx = x;
|
|
|
|
const fixed_t fracxstep = FRACUNIT*2 / CleanXfac;
|
|
|
|
const fixed_t fracystep = FRACUNIT*2 / CleanYfac;
|
|
|
|
fixed_t fracx, fracy = 0;
|
|
|
|
|
|
|
|
src->Lock();
|
|
|
|
|
|
|
|
if (fracxstep == FRACUNIT)
|
|
|
|
{
|
|
|
|
for (y = desty; y < desty + destheight; y++, fracy += fracystep)
|
|
|
|
{
|
|
|
|
srcline = src->GetBuffer() + (fracy >> FRACBITS) * src->GetPitch();
|
|
|
|
destline = dest->GetBuffer() + y * dest->GetPitch() + destx;
|
|
|
|
|
|
|
|
for (x = 0; x < destwidth; x++)
|
|
|
|
{
|
|
|
|
destline[x] = FireRemap[srcline[x]];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for (y = desty; y < desty + destheight; y++, fracy += fracystep)
|
|
|
|
{
|
|
|
|
srcline = src->GetBuffer() + (fracy >> FRACBITS) * src->GetPitch();
|
|
|
|
destline = dest->GetBuffer() + y * dest->GetPitch() + destx;
|
|
|
|
for (x = fracx = 0; x < destwidth; x++, fracx += fracxstep)
|
|
|
|
{
|
|
|
|
destline[x] = FireRemap[srcline[fracx >> FRACBITS]];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
src->Unlock();
|
|
|
|
}
|
|
|
|
|
2006-02-24 04:48:15 +00:00
|
|
|
|
2007-12-24 14:24:24 +00:00
|
|
|
void DCanvas::PUTTRANSDOT (int xx, int yy, int basecolor, int level)
|
|
|
|
{
|
|
|
|
static int oldyy;
|
|
|
|
static int oldyyshifted;
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
if(xx < 32)
|
|
|
|
cc += 7-(xx>>2);
|
|
|
|
else if(xx > (finit_width - 32))
|
|
|
|
cc += 7-((finit_width-xx) >> 2);
|
|
|
|
// if(cc==oldcc) //make sure that we don't double fade the corners.
|
|
|
|
// {
|
|
|
|
if(yy < 32)
|
|
|
|
cc += 7-(yy>>2);
|
|
|
|
else if(yy > (finit_height - 32))
|
|
|
|
cc += 7-((finit_height-yy) >> 2);
|
|
|
|
// }
|
|
|
|
if(cc > cm && cm != NULL)
|
|
|
|
{
|
|
|
|
cc = cm;
|
|
|
|
}
|
|
|
|
else if(cc > oldcc+6) // don't let the color escape from the fade table...
|
|
|
|
{
|
|
|
|
cc=oldcc+6;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
if (yy == oldyy+1)
|
|
|
|
{
|
|
|
|
oldyy++;
|
|
|
|
oldyyshifted += GetPitch();
|
|
|
|
}
|
|
|
|
else if (yy == oldyy-1)
|
|
|
|
{
|
|
|
|
oldyy--;
|
|
|
|
oldyyshifted -= GetPitch();
|
|
|
|
}
|
|
|
|
else if (yy != oldyy)
|
|
|
|
{
|
|
|
|
oldyy = yy;
|
|
|
|
oldyyshifted = yy * GetPitch();
|
|
|
|
}
|
|
|
|
|
|
|
|
BYTE *spot = GetBuffer() + oldyyshifted + xx;
|
|
|
|
DWORD *bg2rgb = Col2RGB8[1+level];
|
|
|
|
DWORD *fg2rgb = Col2RGB8[63-level];
|
|
|
|
DWORD fg = fg2rgb[basecolor];
|
|
|
|
DWORD bg = bg2rgb[*spot];
|
|
|
|
bg = (fg+bg) | 0x1f07c1f;
|
|
|
|
*spot = RGB32k[0][0][bg&(bg>>15)];
|
|
|
|
}
|
|
|
|
|
|
|
|
void DCanvas::DrawLine(int x0, int y0, int x1, int y1, int palColor, uint32 realcolor)
|
|
|
|
//void DrawTransWuLine (int x0, int y0, int x1, int y1, BYTE palColor)
|
|
|
|
{
|
|
|
|
const int WeightingScale = 0;
|
|
|
|
const int WEIGHTBITS = 6;
|
|
|
|
const int WEIGHTSHIFT = 16-WEIGHTBITS;
|
|
|
|
const int NUMWEIGHTS = (1<<WEIGHTBITS);
|
|
|
|
const int WEIGHTMASK = (NUMWEIGHTS-1);
|
|
|
|
|
|
|
|
if (palColor < 0)
|
|
|
|
{
|
|
|
|
// Quick check for black.
|
|
|
|
if (realcolor == MAKEARGB(255,0,0,0))
|
|
|
|
{
|
|
|
|
palColor = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
palColor = ColorMatcher.Pick(RPART(realcolor), GPART(realcolor), BPART(realcolor));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Lock();
|
|
|
|
int deltaX, deltaY, xDir;
|
|
|
|
|
|
|
|
if (y0 > y1)
|
|
|
|
{
|
|
|
|
int temp = y0; y0 = y1; y1 = temp;
|
|
|
|
temp = x0; x0 = x1; x1 = temp;
|
|
|
|
}
|
|
|
|
|
|
|
|
PUTTRANSDOT (x0, y0, palColor, 0);
|
|
|
|
|
|
|
|
if ((deltaX = x1 - x0) >= 0)
|
|
|
|
{
|
|
|
|
xDir = 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
xDir = -1;
|
|
|
|
deltaX = -deltaX;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((deltaY = y1 - y0) == 0)
|
|
|
|
{ // horizontal line
|
|
|
|
if (x0 > x1)
|
|
|
|
{
|
|
|
|
swap (x0, x1);
|
|
|
|
}
|
|
|
|
memset (GetBuffer() + y0*GetPitch() + x0, palColor, deltaX+1);
|
|
|
|
}
|
|
|
|
else if (deltaX == 0)
|
|
|
|
{ // vertical line
|
|
|
|
BYTE *spot = GetBuffer() + y0*GetPitch() + x0;
|
|
|
|
int pitch = GetPitch ();
|
|
|
|
do
|
|
|
|
{
|
|
|
|
*spot = palColor;
|
|
|
|
spot += pitch;
|
|
|
|
} while (--deltaY != 0);
|
|
|
|
}
|
|
|
|
else if (deltaX == deltaY)
|
|
|
|
{ // diagonal line.
|
|
|
|
BYTE *spot = GetBuffer() + y0*GetPitch() + x0;
|
|
|
|
int advance = GetPitch() + xDir;
|
|
|
|
do
|
|
|
|
{
|
|
|
|
*spot = palColor;
|
|
|
|
spot += advance;
|
|
|
|
} while (--deltaY != 0);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// line is not horizontal, diagonal, or vertical
|
|
|
|
fixed_t errorAcc = 0;
|
|
|
|
|
|
|
|
if (deltaY > deltaX)
|
|
|
|
{ // y-major line
|
|
|
|
fixed_t errorAdj = (((unsigned)deltaX << 16) / (unsigned)deltaY) & 0xffff;
|
|
|
|
if (xDir < 0)
|
|
|
|
{
|
|
|
|
if (WeightingScale == 0)
|
|
|
|
{
|
|
|
|
while (--deltaY)
|
|
|
|
{
|
|
|
|
errorAcc += errorAdj;
|
|
|
|
y0++;
|
|
|
|
int weighting = (errorAcc >> WEIGHTSHIFT) & WEIGHTMASK;
|
|
|
|
PUTTRANSDOT (x0 - (errorAcc >> 16), y0, palColor, weighting);
|
|
|
|
PUTTRANSDOT (x0 - (errorAcc >> 16) - 1, y0,
|
|
|
|
palColor, WEIGHTMASK - weighting);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
while (--deltaY)
|
|
|
|
{
|
|
|
|
errorAcc += errorAdj;
|
|
|
|
y0++;
|
|
|
|
int weighting = ((errorAcc * WeightingScale) >> (WEIGHTSHIFT+8)) & WEIGHTMASK;
|
|
|
|
PUTTRANSDOT (x0 - (errorAcc >> 16), y0, palColor, weighting);
|
|
|
|
PUTTRANSDOT (x0 - (errorAcc >> 16) - 1, y0,
|
|
|
|
palColor, WEIGHTMASK - weighting);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (WeightingScale == 0)
|
|
|
|
{
|
|
|
|
while (--deltaY)
|
|
|
|
{
|
|
|
|
errorAcc += errorAdj;
|
|
|
|
y0++;
|
|
|
|
int weighting = (errorAcc >> WEIGHTSHIFT) & WEIGHTMASK;
|
|
|
|
PUTTRANSDOT (x0 + (errorAcc >> 16), y0, palColor, weighting);
|
|
|
|
PUTTRANSDOT (x0 + (errorAcc >> 16) + xDir, y0,
|
|
|
|
palColor, WEIGHTMASK - weighting);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
while (--deltaY)
|
|
|
|
{
|
|
|
|
errorAcc += errorAdj;
|
|
|
|
y0++;
|
|
|
|
int weighting = ((errorAcc * WeightingScale) >> (WEIGHTSHIFT+8)) & WEIGHTMASK;
|
|
|
|
PUTTRANSDOT (x0 + (errorAcc >> 16), y0, palColor, weighting);
|
|
|
|
PUTTRANSDOT (x0 + (errorAcc >> 16) + xDir, y0,
|
|
|
|
palColor, WEIGHTMASK - weighting);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{ // x-major line
|
|
|
|
fixed_t errorAdj = (((DWORD) deltaY << 16) / (DWORD) deltaX) & 0xffff;
|
|
|
|
|
|
|
|
if (WeightingScale == 0)
|
|
|
|
{
|
|
|
|
while (--deltaX)
|
|
|
|
{
|
|
|
|
errorAcc += errorAdj;
|
|
|
|
x0 += xDir;
|
|
|
|
int weighting = (errorAcc >> WEIGHTSHIFT) & WEIGHTMASK;
|
|
|
|
PUTTRANSDOT (x0, y0 + (errorAcc >> 16), palColor, weighting);
|
|
|
|
PUTTRANSDOT (x0, y0 + (errorAcc >> 16) + 1,
|
|
|
|
palColor, WEIGHTMASK - weighting);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
while (--deltaX)
|
|
|
|
{
|
|
|
|
errorAcc += errorAdj;
|
|
|
|
x0 += xDir;
|
|
|
|
int weighting = ((errorAcc * WeightingScale) >> (WEIGHTSHIFT+8)) & WEIGHTMASK;
|
|
|
|
PUTTRANSDOT (x0, y0 + (errorAcc >> 16), palColor, weighting);
|
|
|
|
PUTTRANSDOT (x0, y0 + (errorAcc >> 16) + 1,
|
|
|
|
palColor, WEIGHTMASK - weighting);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
PUTTRANSDOT (x1, y1, palColor, 0);
|
|
|
|
}
|
|
|
|
Unlock();
|
|
|
|
}
|
|
|
|
|
|
|
|
void DCanvas::DrawPixel(int x, int y, int palColor, uint32 realcolor)
|
|
|
|
{
|
|
|
|
if (palColor < 0)
|
|
|
|
{
|
|
|
|
// Quick check for black.
|
|
|
|
if (realcolor == MAKEARGB(255,0,0,0))
|
|
|
|
{
|
|
|
|
palColor = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
palColor = ColorMatcher.Pick(RPART(realcolor), GPART(realcolor), BPART(realcolor));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Lock();
|
|
|
|
GetBuffer()[GetPitch() * y + x] = (BYTE)palColor;
|
|
|
|
Unlock();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-02-24 04:48:15 +00:00
|
|
|
/********************************/
|
|
|
|
/* */
|
|
|
|
/* Other miscellaneous routines */
|
|
|
|
/* */
|
|
|
|
/********************************/
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// V_DrawBlock
|
|
|
|
// Draw a linear block of pixels into the view buffer.
|
|
|
|
//
|
2006-09-14 00:02:31 +00:00
|
|
|
void DCanvas::DrawBlock (int x, int y, int _width, int _height, const BYTE *src) const
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
|
|
|
int srcpitch = _width;
|
|
|
|
int destpitch;
|
2006-09-14 00:02:31 +00:00
|
|
|
BYTE *dest;
|
2006-02-24 04:48:15 +00:00
|
|
|
|
|
|
|
if (ClipBox (x, y, _width, _height, src, srcpitch))
|
|
|
|
{
|
|
|
|
return; // Nothing to draw
|
|
|
|
}
|
|
|
|
|
|
|
|
destpitch = Pitch;
|
|
|
|
dest = Buffer + y*Pitch + x;
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
memcpy (dest, src, _width);
|
|
|
|
src += srcpitch;
|
|
|
|
dest += destpitch;
|
|
|
|
} while (--_height);
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// V_GetBlock
|
|
|
|
// Gets a linear block of pixels from the view buffer.
|
|
|
|
//
|
2006-09-14 00:02:31 +00:00
|
|
|
void DCanvas::GetBlock (int x, int y, int _width, int _height, BYTE *dest) const
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
2006-09-14 00:02:31 +00:00
|
|
|
const BYTE *src;
|
2006-02-24 04:48:15 +00:00
|
|
|
|
|
|
|
#ifdef RANGECHECK
|
|
|
|
if (x<0
|
|
|
|
||x+_width > Width
|
|
|
|
|| y<0
|
|
|
|
|| y+_height>Height)
|
|
|
|
{
|
|
|
|
I_Error ("Bad V_GetBlock");
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
src = Buffer + y*Pitch + x;
|
|
|
|
|
|
|
|
while (_height--)
|
|
|
|
{
|
|
|
|
memcpy (dest, src, _width);
|
|
|
|
src += Pitch;
|
|
|
|
dest += _width;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Returns true if the box was completely clipped. False otherwise.
|
2006-09-14 00:02:31 +00:00
|
|
|
bool DCanvas::ClipBox (int &x, int &y, int &w, int &h, const BYTE *&src, const int srcpitch) const
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
|
|
|
if (x >= Width || y >= Height || x+w <= 0 || y+h <= 0)
|
|
|
|
{ // Completely clipped off screen
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (x < 0) // clip left edge
|
|
|
|
{
|
|
|
|
src -= x;
|
|
|
|
w += x;
|
|
|
|
x = 0;
|
|
|
|
}
|
|
|
|
if (x+w > Width) // clip right edge
|
|
|
|
{
|
|
|
|
w = Width - x;
|
|
|
|
}
|
|
|
|
if (y < 0) // clip top edge
|
|
|
|
{
|
|
|
|
src -= y*srcpitch;
|
|
|
|
h += y;
|
|
|
|
y = 0;
|
|
|
|
}
|
|
|
|
if (y+h > Height) // clip bottom edge
|
|
|
|
{
|
|
|
|
h = Height - y;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|