2009-05-08 13:28:41 +00:00
|
|
|
/*
|
|
|
|
* OpenClonk, http://www.openclonk.org
|
|
|
|
*
|
2013-12-17 20:01:09 +00:00
|
|
|
* Copyright (c) 1998-2000, Matthes Bender
|
|
|
|
* Copyright (c) 2001-2009, RedWolf Design GmbH, http://www.clonk.de/
|
2016-04-03 18:18:29 +00:00
|
|
|
* Copyright (c) 2009-2016, The OpenClonk Team and contributors
|
2009-05-08 13:28:41 +00:00
|
|
|
*
|
2013-12-17 20:01:09 +00:00
|
|
|
* Distributed under the terms of the ISC license; see accompanying file
|
|
|
|
* "COPYING" for details.
|
2009-05-08 13:28:41 +00:00
|
|
|
*
|
2013-12-17 20:01:09 +00:00
|
|
|
* "Clonk" is a registered trademark of Matthes Bender, used with permission.
|
|
|
|
* See accompanying file "TRADEMARK" for details.
|
2009-05-08 13:28:41 +00:00
|
|
|
*
|
2013-12-17 20:01:09 +00:00
|
|
|
* To redistribute this file separately, substitute the full license texts
|
|
|
|
* for the above references.
|
2009-05-08 13:28:41 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/* A facet that can hold its own surface and also target coordinates */
|
|
|
|
|
2016-04-03 18:07:56 +00:00
|
|
|
#include "C4Include.h"
|
|
|
|
#include "graphics/C4FacetEx.h"
|
2016-10-20 16:30:05 +00:00
|
|
|
#include "graphics/C4Draw.h"
|
2009-05-08 13:28:41 +00:00
|
|
|
|
2016-04-03 18:07:56 +00:00
|
|
|
#include "lib/C4Rect.h"
|
|
|
|
#include "c4group/C4Group.h"
|
2009-05-08 13:28:41 +00:00
|
|
|
|
2012-10-28 14:33:58 +00:00
|
|
|
void C4TargetFacet::Set(C4Surface * nsfc, float nx, float ny, float nwdt, float nhgt, float ntx, float nty, float Zoom)
|
2015-10-17 21:35:33 +00:00
|
|
|
{
|
|
|
|
Set(nsfc, nx, ny, nwdt, nhgt, ntx, nty, Zoom, ntx, nty);
|
|
|
|
}
|
|
|
|
|
|
|
|
void C4TargetFacet::Set(C4Surface * nsfc, float nx, float ny, float nwdt, float nhgt, float ntx, float nty, float Zoom, float prx, float pry)
|
2010-03-28 18:58:01 +00:00
|
|
|
{
|
2010-09-24 18:17:07 +00:00
|
|
|
C4Facet::Set(nsfc, nx, ny, nwdt, nhgt);
|
|
|
|
TargetX = ntx; TargetY = nty; this->Zoom = Zoom;
|
2015-10-17 21:35:33 +00:00
|
|
|
ParRefX = prx; ParRefY = pry;
|
2010-03-28 18:58:01 +00:00
|
|
|
}
|
2009-05-08 13:28:41 +00:00
|
|
|
|
2011-10-03 14:07:07 +00:00
|
|
|
void C4TargetFacet::Set(C4Surface * nsfc, const C4Rect & r, float ntx, float nty, float Zoom)
|
2010-03-28 18:58:01 +00:00
|
|
|
{
|
2010-09-24 18:17:07 +00:00
|
|
|
Set(nsfc, r.x, r.y, r.Wdt, r.Hgt, ntx, nty, Zoom);
|
2010-03-28 18:58:01 +00:00
|
|
|
}
|
2015-10-17 21:35:33 +00:00
|
|
|
|
2009-05-08 13:28:41 +00:00
|
|
|
void C4TargetFacet::SetRect(C4TargetRect &rSrc)
|
2010-03-28 18:58:01 +00:00
|
|
|
{
|
2015-10-17 21:35:33 +00:00
|
|
|
X=rSrc.x; Y=rSrc.y; Wdt=rSrc.Wdt; Hgt=rSrc.Hgt;
|
|
|
|
TargetX=rSrc.tx; TargetY=rSrc.ty;
|
|
|
|
ParRefX=rSrc.tx; TargetY=rSrc.ty;
|
2010-03-28 18:58:01 +00:00
|
|
|
}
|
2009-05-08 13:28:41 +00:00
|
|
|
|
|
|
|
// ------------------------
|
|
|
|
// C4FacetSurface
|
|
|
|
|
2009-08-15 18:50:32 +00:00
|
|
|
bool C4FacetSurface::Create(int iWdt, int iHgt, int iWdt2, int iHgt2)
|
2010-03-28 18:58:01 +00:00
|
|
|
{
|
2009-05-08 13:28:41 +00:00
|
|
|
Clear();
|
|
|
|
// Create surface
|
|
|
|
Face.Default();
|
2016-01-10 00:18:28 +00:00
|
|
|
if (!Face.Create(iWdt,iHgt)) return false;
|
2009-05-08 13:28:41 +00:00
|
|
|
// Set facet
|
|
|
|
if (iWdt2==C4FCT_Full) iWdt2=Face.Wdt; if (iWdt2==C4FCT_Height) iWdt2=Face.Hgt; if (iWdt2==C4FCT_Width) iWdt2=Face.Wdt;
|
|
|
|
if (iHgt2==C4FCT_Full) iHgt2=Face.Hgt; if (iHgt2==C4FCT_Height) iHgt2=Face.Hgt; if (iHgt2==C4FCT_Width) iHgt2=Face.Wdt;
|
2011-03-28 17:31:28 +00:00
|
|
|
Set(&Face,0,0,iWdt2,iHgt2);
|
2009-08-15 18:50:32 +00:00
|
|
|
return true;
|
2010-03-28 18:58:01 +00:00
|
|
|
}
|
2009-05-08 13:28:41 +00:00
|
|
|
|
2011-10-03 14:06:41 +00:00
|
|
|
bool C4FacetSurface::CreateClrByOwner(C4Surface *pBySurface)
|
2010-03-28 18:58:01 +00:00
|
|
|
{
|
2009-05-08 13:28:41 +00:00
|
|
|
Clear();
|
|
|
|
// create surface
|
2009-08-15 18:50:32 +00:00
|
|
|
if (!Face.CreateColorByOwner(pBySurface)) return false;
|
2009-05-08 13:28:41 +00:00
|
|
|
// set facet
|
2011-03-28 17:31:28 +00:00
|
|
|
Set(&Face,0,0,Face.Wdt,Face.Hgt);
|
2009-05-08 13:28:41 +00:00
|
|
|
// success
|
2009-08-15 18:50:32 +00:00
|
|
|
return true;
|
2010-03-28 18:58:01 +00:00
|
|
|
}
|
2009-05-08 13:28:41 +00:00
|
|
|
|
2015-09-19 01:10:39 +00:00
|
|
|
bool C4FacetSurface::Load(C4Group &hGroup, const char *szName, int iWdt, int iHgt, bool fNoErrIfNotFound, int iFlags)
|
2010-03-28 18:58:01 +00:00
|
|
|
{
|
2009-05-08 13:28:41 +00:00
|
|
|
Clear();
|
|
|
|
// Entry name
|
|
|
|
char szFilename[_MAX_FNAME+1];
|
|
|
|
SCopy(szName,szFilename,_MAX_FNAME);
|
|
|
|
char *szExt = GetExtension(szFilename);
|
|
|
|
if (!*szExt)
|
2010-03-28 18:58:01 +00:00
|
|
|
{
|
2009-05-08 13:28:41 +00:00
|
|
|
// no extension: Default to extension that is found as file in group
|
2016-11-02 23:58:02 +00:00
|
|
|
const char * const extensions[] = { "png", "bmp", "jpeg", "jpg", nullptr };
|
2009-05-08 13:28:41 +00:00
|
|
|
int i = 0; const char *szExt;
|
2010-01-25 04:00:59 +00:00
|
|
|
while ((szExt = extensions[i++]))
|
2010-03-28 18:58:01 +00:00
|
|
|
{
|
2009-05-08 13:28:41 +00:00
|
|
|
EnforceExtension(szFilename, szExt);
|
|
|
|
if (hGroup.FindEntry(szFilename)) break;
|
|
|
|
}
|
2010-03-28 18:58:01 +00:00
|
|
|
}
|
2009-05-08 13:28:41 +00:00
|
|
|
// Load surface
|
2015-09-19 01:10:39 +00:00
|
|
|
if (!Face.Load(hGroup,szFilename,false,fNoErrIfNotFound, iFlags)) return false;
|
2009-05-08 13:28:41 +00:00
|
|
|
// Set facet
|
|
|
|
if (iWdt==C4FCT_Full) iWdt=Face.Wdt; if (iWdt==C4FCT_Height) iWdt=Face.Hgt; if (iWdt==C4FCT_Width) iWdt=Face.Wdt;
|
|
|
|
if (iHgt==C4FCT_Full) iHgt=Face.Hgt; if (iHgt==C4FCT_Height) iHgt=Face.Hgt; if (iHgt==C4FCT_Width) iHgt=Face.Wdt;
|
2011-03-28 17:31:28 +00:00
|
|
|
Set(&Face,0,0,iWdt,iHgt);
|
2009-08-15 18:50:32 +00:00
|
|
|
return true;
|
2010-03-28 18:58:01 +00:00
|
|
|
}
|
2009-05-08 13:28:41 +00:00
|
|
|
|
|
|
|
bool C4FacetSurface::CopyFromSfcMaxSize(C4Surface &srcSfc, int32_t iMaxSize, uint32_t dwColor)
|
2010-03-28 18:58:01 +00:00
|
|
|
{
|
2009-05-08 13:28:41 +00:00
|
|
|
// safety
|
|
|
|
if (!srcSfc.Wdt || !srcSfc.Hgt) return false;
|
|
|
|
Clear();
|
|
|
|
// no scale?
|
|
|
|
bool fNeedsScale = !(srcSfc.Wdt <= iMaxSize && srcSfc.Hgt <= iMaxSize);
|
|
|
|
if (!fNeedsScale && !dwColor)
|
2010-03-28 18:58:01 +00:00
|
|
|
{
|
2009-05-08 13:28:41 +00:00
|
|
|
// no change necessary; just copy then
|
|
|
|
Face.Copy(srcSfc);
|
2010-03-28 18:58:01 +00:00
|
|
|
}
|
2009-05-08 13:28:41 +00:00
|
|
|
else
|
2010-03-28 18:58:01 +00:00
|
|
|
{
|
2009-05-08 13:28:41 +00:00
|
|
|
// must scale down or colorize. Just blit.
|
|
|
|
C4Facet fctSource;
|
|
|
|
fctSource.Set(&srcSfc, 0,0,srcSfc.Wdt,srcSfc.Hgt);
|
|
|
|
int32_t iTargetWdt, iTargetHgt;
|
|
|
|
if (fNeedsScale)
|
2010-03-28 18:58:01 +00:00
|
|
|
{
|
2009-05-08 13:28:41 +00:00
|
|
|
if (fctSource.Wdt > fctSource.Hgt)
|
2010-03-28 18:58:01 +00:00
|
|
|
{
|
2009-05-08 13:28:41 +00:00
|
|
|
iTargetWdt = iMaxSize;
|
|
|
|
iTargetHgt = fctSource.Hgt * iTargetWdt / fctSource.Wdt;
|
2010-03-28 18:58:01 +00:00
|
|
|
}
|
2009-05-08 13:28:41 +00:00
|
|
|
else
|
2010-03-28 18:58:01 +00:00
|
|
|
{
|
2009-05-08 13:28:41 +00:00
|
|
|
iTargetHgt = iMaxSize;
|
|
|
|
iTargetWdt = fctSource.Wdt * iTargetHgt / fctSource.Hgt;
|
|
|
|
}
|
2010-03-28 18:58:01 +00:00
|
|
|
}
|
2009-05-08 13:28:41 +00:00
|
|
|
else
|
2010-03-28 18:58:01 +00:00
|
|
|
{
|
2009-05-08 13:28:41 +00:00
|
|
|
iTargetWdt = fctSource.Wdt;
|
|
|
|
iTargetHgt = fctSource.Hgt;
|
2010-03-28 18:58:01 +00:00
|
|
|
}
|
2009-05-08 13:28:41 +00:00
|
|
|
if (dwColor) srcSfc.SetClr(dwColor);
|
|
|
|
Create(iTargetWdt, iTargetHgt);
|
2011-10-03 14:30:18 +00:00
|
|
|
pDraw->Blit(&srcSfc, 0.0f,0.0f,float(fctSource.Wdt),float(fctSource.Hgt),
|
2009-05-08 13:28:41 +00:00
|
|
|
&Face, 0,0,iTargetWdt,iTargetHgt);
|
2010-03-28 18:58:01 +00:00
|
|
|
}
|
2009-05-08 13:28:41 +00:00
|
|
|
Set(&Face, 0,0, Face.Wdt, Face.Hgt);
|
|
|
|
return true;
|
2010-03-28 18:58:01 +00:00
|
|
|
}
|
2009-05-08 13:28:41 +00:00
|
|
|
|
|
|
|
void C4FacetSurface::Grayscale(int32_t iOffset)
|
2010-03-28 18:58:01 +00:00
|
|
|
{
|
2011-10-03 14:30:18 +00:00
|
|
|
if (!pDraw || !Surface || !Wdt || !Hgt) return;
|
|
|
|
pDraw->Grayscale(Surface, iOffset);
|
2010-03-28 18:58:01 +00:00
|
|
|
}
|
2009-05-08 13:28:41 +00:00
|
|
|
|
|
|
|
bool C4FacetSurface::EnsureOwnSurface()
|
2010-03-28 18:58:01 +00:00
|
|
|
{
|
2009-05-08 13:28:41 +00:00
|
|
|
// is it a link?
|
|
|
|
if (Surface != &Face)
|
2010-03-28 18:58:01 +00:00
|
|
|
{
|
2009-05-08 13:28:41 +00:00
|
|
|
// then recreate in same size
|
|
|
|
C4Facet fctOld = *this;
|
|
|
|
if (!Create(fctOld.Wdt, fctOld.Hgt)) return false;
|
|
|
|
fctOld.Draw(*this);
|
|
|
|
}
|
2010-03-28 18:58:01 +00:00
|
|
|
return true;
|
|
|
|
}
|
2009-05-08 13:28:41 +00:00
|
|
|
|