1/*
2 * LegacyClonk
3 *
4 * Copyright (c) 1998-2000, Matthes Bender (RedWolf Design)
5 * Copyright (c) 2017-2019, 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/* Screen area marked for mouse interaction */
18
19#include <C4Include.h>
20#include <C4Region.h>
21
22#include <C4Facet.h>
23
24C4Region::C4Region()
25{
26 Default();
27}
28
29C4Region::~C4Region()
30{
31 Clear();
32}
33
34void C4Region::Default()
35{
36 X = Y = Wdt = Hgt = 0;
37 Caption[0] = 0;
38 Com = RightCom = MoveOverCom = HoldCom = COM_None;
39 Data = 0;
40 id = C4ID_None;
41 Target = nullptr;
42}
43
44void C4Region::Clear() {}
45
46C4RegionList::C4RegionList()
47{
48 Default();
49}
50
51C4RegionList::~C4RegionList()
52{
53 Clear();
54}
55
56void C4RegionList::Default()
57{
58 First = nullptr;
59 AdjustX = AdjustY = 0;
60}
61
62void C4RegionList::Clear()
63{
64 C4Region *pRgn, *pNext;
65 for (pRgn = First; pRgn; pRgn = pNext) { pNext = pRgn->Next; delete pRgn; }
66 First = nullptr;
67}
68
69bool C4RegionList::Add(int iX, int iY, int iWdt, int iHgt, const char *szCaption,
70 int iCom, C4Object *pTarget, int iMoveOverCom, int iHoldCom, int iData)
71{
72 C4Region *pRgn = new C4Region;
73 pRgn->Set(iX: iX + AdjustX, iY: iY + AdjustY, iWdt, iHgt, szCaption, iCom, iMoveOverCom, iHoldCom, iData, pTarget);
74 pRgn->Next = First;
75 First = pRgn;
76 return true;
77}
78
79bool C4RegionList::Add(C4Region &rRegion)
80{
81 C4Region *pRgn = new C4Region;
82 *pRgn = rRegion;
83 pRgn->X += AdjustX;
84 pRgn->Y += AdjustY;
85 pRgn->Next = First;
86 First = pRgn;
87 return true;
88}
89
90void C4Region::Set(int iX, int iY, int iWdt, int iHgt, const char *szCaption,
91 int iCom, int iMoveOverCom, int iHoldCom, int iData,
92 C4Object *pTarget)
93{
94 X = iX; Y = iY; Wdt = iWdt; Hgt = iHgt;
95 SCopy(szSource: szCaption, sTarget: Caption, iMaxL: C4RGN_MaxCaption);
96 Com = iCom; MoveOverCom = iMoveOverCom; HoldCom = iHoldCom;
97 Data = iData;
98 Target = pTarget;
99}
100
101void C4RegionList::SetAdjust(int iX, int iY)
102{
103 AdjustX = iX; AdjustY = iY;
104}
105
106C4Region *C4RegionList::Find(int iX, int iY)
107{
108 for (C4Region *pRgn = First; pRgn; pRgn = pRgn->Next)
109 if (Inside(ival: iX - pRgn->X, lbound: 0, rbound: pRgn->Wdt - 1))
110 if (Inside(ival: iY - pRgn->Y, lbound: 0, rbound: pRgn->Hgt - 1))
111 return pRgn;
112 return nullptr;
113}
114
115void C4Region::ClearPointers(C4Object *pObj)
116{
117 if (Target == pObj) Target = nullptr;
118}
119
120void C4RegionList::ClearPointers(C4Object *pObj)
121{
122 for (C4Region *pRgn = First; pRgn; pRgn = pRgn->Next)
123 pRgn->ClearPointers(pObj);
124}
125
126void C4Region::Set(C4Facet &fctArea, const char *szCaption, C4Object *pTarget)
127{
128 X = fctArea.X;
129 Y = fctArea.Y;
130 Wdt = fctArea.Wdt;
131 Hgt = fctArea.Hgt;
132 if (szCaption) SCopy(szSource: szCaption, sTarget: Caption, iMaxL: C4RGN_MaxCaption);
133 if (pTarget) Target = pTarget;
134}
135