1 /*
2  * OpenClonk, http://www.openclonk.org
3  *
4  * Copyright (c) 1998-2000, Matthes Bender
5  * Copyright (c) 2001-2009, RedWolf Design GmbH, http://www.clonk.de/
6  * Copyright (c) 2009-2016, The OpenClonk Team and contributors
7  *
8  * Distributed under the terms of the ISC license; see accompanying file
9  * "COPYING" for details.
10  *
11  * "Clonk" is a registered trademark of Matthes Bender, used with permission.
12  * See accompanying file "TRADEMARK" for details.
13  *
14  * To redistribute this file separately, substitute the full license texts
15  * for the above references.
16  */
17 
18 /* A facet that can hold its own surface and also target coordinates */
19 
20 #ifndef INC_C4FacetEx
21 #define INC_C4FacetEx
22 
23 #include "graphics/C4Facet.h"
24 #include "graphics/C4Surface.h"
25 
26 const int C4FCT_Full   = -1,
27           C4FCT_Height = -2,
28           C4FCT_Width  = -3;
29 
30 // facet that can hold its own surface
31 class C4FacetSurface : public C4Facet
32 {
33 private:
34 	C4Surface Face;
35 
36 private:
37 	C4FacetSurface(const C4FacetSurface &rCpy); // NO copy!
38 	C4FacetSurface &operator = (const C4FacetSurface &rCpy); // NO copy assignment!
39 public:
C4FacetSurface()40 	C4FacetSurface() { Default(); }
~C4FacetSurface()41 	~C4FacetSurface() { Clear(); }
42 
Default()43 	void Default() { Face.Default(); C4Facet::Default(); }
Clear()44 	void Clear() { Face.Clear(); }
45 
Set(const C4Facet & cpy)46 	void Set(const C4Facet &cpy) { Clear(); C4Facet::Set(cpy); }
Set(C4Surface * nsfc,int nx,int ny,int nwdt,int nhgt)47 	void Set(C4Surface * nsfc, int nx, int ny, int nwdt, int nhgt)
48 	{ C4Facet::Set(nsfc, nx,ny,nwdt,nhgt); }
49 
50 	void Grayscale(int32_t iOffset = 0);
51 	bool Create(int iWdt, int iHgt, int iWdt2=C4FCT_Full, int iHgt2=C4FCT_Full);
GetFace()52 	C4Surface &GetFace() { return Face; } // get internal face
53 	bool CreateClrByOwner(C4Surface *pBySurface);
54 	bool EnsureOwnSurface();
55 	bool Load(C4Group &hGroup, const char *szName, int iWdt, int iHgt, bool fNoErrIfNotFound, int iFlags);
56 	bool Save(C4Group &hGroup, const char *szName);
GrabFrom(C4FacetSurface & rSource)57 	void GrabFrom(C4FacetSurface &rSource)
58 	{
59 		Clear(); Default();
60 		Face.MoveFrom(&rSource.Face);
61 		Set(rSource.Surface == &rSource.Face ? &Face : rSource.Surface, rSource.X, rSource.Y, rSource.Wdt, rSource.Hgt);
62 		rSource.Default();
63 	}
64 	bool CopyFromSfcMaxSize(C4Surface &srcSfc, int32_t iMaxSize, uint32_t dwColor=0u);
65 };
66 
67 // facet with source group ID; used to avoid doubled loading from same group
68 class C4FacetID : public C4FacetSurface
69 {
70 public:
71 	int32_t idSourceGroup{0};
72 
C4FacetID()73 	C4FacetID() : C4FacetSurface() { } // ctor
74 
Default()75 	void Default() { C4FacetSurface::Default(); idSourceGroup = 0; } // default to std values
Clear()76 	void Clear() { C4FacetSurface::Clear(); idSourceGroup = 0; } // clear all data in class
77 };
78 
79 #endif
80