| 1 | /* |
| 2 | * LegacyClonk |
| 3 | * |
| 4 | * Copyright (c) RedWolf Design |
| 5 | * Copyright (c) 2001, Sven2 |
| 6 | * Copyright (c) 2017-2019, The LegacyClonk 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 wrapper class to DirectDraw surfaces |
| 19 | |
| 20 | #pragma once |
| 21 | |
| 22 | #include "C4ForwardDeclarations.h" |
| 23 | #include <Standard.h> |
| 24 | #include <StdColors.h> |
| 25 | |
| 26 | class CSurface8 |
| 27 | { |
| 28 | public: |
| 29 | CSurface8(); |
| 30 | ~CSurface8(); |
| 31 | CSurface8(int iWdt, int iHgt); // create new surface and init it |
| 32 | |
| 33 | public: |
| 34 | int Wdt, Hgt, Pitch; // size of surface |
| 35 | int ClipX, ClipY, ClipX2, ClipY2; |
| 36 | uint8_t *Bits; |
| 37 | CStdPalette *pPal; // pal for this surface (usually points to the main pal) |
| 38 | bool HasOwnPal(); // return whether the surface palette is owned |
| 39 | void HLine(int iX, int iX2, int iY, int iCol); |
| 40 | void Polygon(int iNum, int *ipVtx, int iCol); |
| 41 | void Box(int iX, int iY, int iX2, int iY2, int iCol); |
| 42 | void Circle(int x, int y, int r, uint8_t col); |
| 43 | void ClearBox8Only(int iX, int iY, int iWdt, int iHgt); // clear box in 8bpp-surface only |
| 44 | |
| 45 | void SetPix(int iX, int iY, uint8_t byCol) |
| 46 | { |
| 47 | // clip |
| 48 | if ((iX < ClipX) || (iX > ClipX2) || (iY < ClipY) || (iY > ClipY2)) return; |
| 49 | // set pix in local copy... |
| 50 | if (Bits) Bits[iY * Pitch + iX] = byCol; |
| 51 | } |
| 52 | |
| 53 | uint8_t GetPix(int iX, int iY) // get pixel |
| 54 | { |
| 55 | if (iX < 0 || iY < 0 || iX >= Wdt || iY >= Hgt) return 0; |
| 56 | return Bits ? Bits[iY * Pitch + iX] : 0; |
| 57 | } |
| 58 | |
| 59 | inline uint8_t _GetPix(int x, int y) // get pixel (bounds not checked) |
| 60 | { |
| 61 | return Bits[y * Pitch + x]; |
| 62 | } |
| 63 | |
| 64 | bool Create(int iWdt, int iHgt, bool fOwnPal = false); |
| 65 | void Clear(); |
| 66 | void Clip(int iX, int iY, int iX2, int iY2); |
| 67 | void NoClip(); |
| 68 | bool Read(C4Group &hGroup, bool fOwnPal); |
| 69 | bool Save(const char *szFilename, uint8_t *bpPalette = nullptr); |
| 70 | void GetSurfaceSize(int &irX, int &irY); // get surface size |
| 71 | void EnforceC0Transparency() { pPal->EnforceC0Transparency(); } |
| 72 | void AllowColor(uint8_t iRngLo, uint8_t iRngHi, bool fAllowZero = false); |
| 73 | }; |
| 74 | |