| 1 | /* |
| 2 | * LegacyClonk |
| 3 | * |
| 4 | * Copyright (c) 1998-2000, Matthes Bender (RedWolf Design) |
| 5 | * Copyright (c) 2017-2022, The LegacyClonk Team and contributors |
| 6 | * |
| 7 | * Distributed under the terms of the ISC license; see accompanying file |
| 8 | * "COPYING" for details. |
| 9 | * |
| 10 | * "Clonk" is a registered trademark of Matthes Bender, used with permission. |
| 11 | * See accompanying file "TRADEMARK" for details. |
| 12 | * |
| 13 | * To redistribute this file separately, substitute the full license texts |
| 14 | * for the above references. |
| 15 | */ |
| 16 | |
| 17 | /* A facet that can hold its own surface and also target coordinates */ |
| 18 | |
| 19 | #pragma once |
| 20 | |
| 21 | #include <C4Facet.h> |
| 22 | #include <C4Surface.h> |
| 23 | |
| 24 | const int C4FCT_Full = -1, |
| 25 | C4FCT_Height = -2, |
| 26 | C4FCT_Width = -3; |
| 27 | |
| 28 | class C4FacetEx : public C4Facet |
| 29 | { |
| 30 | public: |
| 31 | C4FacetEx() { Default(); } |
| 32 | ~C4FacetEx() {} |
| 33 | |
| 34 | public: |
| 35 | int TargetX, TargetY; |
| 36 | |
| 37 | public: |
| 38 | void Default() { TargetX = TargetY = 0; C4Facet::Default(); } |
| 39 | void Clear() { Surface = nullptr; } |
| 40 | |
| 41 | void Set(const C4Facet &cpy) { TargetX = TargetY = 0; C4Facet::Set(cpy); } |
| 42 | void Set(const C4FacetEx &cpy) { *this = cpy; } |
| 43 | void Set(C4Surface *nsfc, int nx, int ny, int nwdt, int nhgt, int ntx = 0, int nty = 0); |
| 44 | |
| 45 | void DrawBolt(int iX1, int iY1, int iX2, int iY2, uint8_t bCol, uint8_t bCol2); |
| 46 | void DrawLine(int iX1, int iY1, int iX2, int iY2, uint8_t bCol1, uint8_t bCol2); |
| 47 | C4FacetEx GetSection(int iSection); |
| 48 | C4FacetEx GetPhase(int iPhaseX = 0, int iPhaseY = 0); |
| 49 | |
| 50 | public: |
| 51 | C4FacetEx &operator=(const C4Facet &rhs) |
| 52 | { |
| 53 | Set(nsfc: rhs.Surface, nx: rhs.X, ny: rhs.Y, nwdt: rhs.Wdt, nhgt: rhs.Hgt); |
| 54 | return *this; |
| 55 | } |
| 56 | }; |
| 57 | |
| 58 | // facet that can hold its own surface |
| 59 | class C4FacetExSurface : public C4FacetEx |
| 60 | { |
| 61 | private: |
| 62 | C4Surface Face; |
| 63 | |
| 64 | public: |
| 65 | C4FacetExSurface() { Default(); } |
| 66 | ~C4FacetExSurface() { Clear(); } |
| 67 | |
| 68 | C4FacetExSurface(const C4FacetExSurface &rCpy) = delete; |
| 69 | C4FacetExSurface &operator=(const C4FacetExSurface &rCpy) = delete; |
| 70 | |
| 71 | void Default() { Face.Default(); C4FacetEx::Default(); } |
| 72 | void Clear() { Face.Clear(); C4FacetEx::Clear(); } |
| 73 | |
| 74 | void Set(const C4Facet &cpy) { Clear(); C4Facet::Set(cpy); } |
| 75 | void Set(const C4FacetEx &cpy) { Clear(); C4FacetEx::Set(cpy); } |
| 76 | |
| 77 | void Set(C4Surface *nsfc, int nx, int ny, int nwdt, int nhgt, int ntx = 0, int nty = 0) |
| 78 | { |
| 79 | C4FacetEx::Set(nsfc, nx, ny, nwdt, nhgt, ntx, nty); |
| 80 | } |
| 81 | |
| 82 | void Grayscale(int32_t iOffset = 0); |
| 83 | bool Create(int iWdt, int iHgt, int iWdt2 = C4FCT_Full, int iHgt2 = C4FCT_Full); |
| 84 | C4Surface &GetFace() { return Face; } // get internal face |
| 85 | bool CreateClrByOwner(C4Surface *pBySurface); |
| 86 | bool EnsureSize(int iMinWdt, int iMinHgt); |
| 87 | bool Load(C4Group &hGroup, const char *szName, int iWdt = C4FCT_Full, int iHgt = C4FCT_Full, bool fOwnPal = false, bool fNoErrIfNotFound = false); |
| 88 | |
| 89 | void GrabFrom(C4FacetExSurface &rSource) |
| 90 | { |
| 91 | Clear(); Default(); |
| 92 | Face = std::move(rSource.Face); |
| 93 | Set(nsfc: rSource.Surface == &rSource.Face ? &Face : rSource.Surface, nx: rSource.X, ny: rSource.Y, nwdt: rSource.Wdt, nhgt: rSource.Hgt, ntx: rSource.TargetX, nty: rSource.TargetY); |
| 94 | rSource.Default(); |
| 95 | } |
| 96 | |
| 97 | bool CopyFromSfcMaxSize(C4Surface &srcSfc, int32_t iMaxSize, uint32_t dwColor = 0u); |
| 98 | }; |
| 99 | |
| 100 | // facet with source group ID; used to avoid doubled loading from same group |
| 101 | class C4FacetExID : public C4FacetExSurface |
| 102 | { |
| 103 | public: |
| 104 | int32_t idSourceGroup; |
| 105 | |
| 106 | C4FacetExID() : C4FacetExSurface(), idSourceGroup(0) {} |
| 107 | |
| 108 | void Default() { C4FacetExSurface::Default(); idSourceGroup = 0; } // default to std values |
| 109 | void Clear() { C4FacetExSurface::Clear(); idSourceGroup = 0; } // clear all data in class |
| 110 | }; |
| 111 | |