OpenClonk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
C4Facet.h
Go to the documentation of this file.
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) 2011-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 piece of a DirectDraw surface */
19 
20 #ifndef INC_C4Facet
21 #define INC_C4Facet
22 
24 
25 const int32_t C4FCT_None = 0,
26 
29  C4FCT_Top = 4,
32 
34 
35  C4FCT_Half = 32,
37  C4FCT_Triple = 128;
38 
39 // tuple of two integers
40 struct C4Vec2D
41 {
42  int32_t x,y;
43 
44  C4Vec2D(int32_t x=0, int32_t y=0) : x(x), y(y) {}
45 };
46 
48 {
49 public:
50  int32_t FlipDir; // +1 or -1; multiplied as x-flip
51 
52  C4DrawTransform(C4DrawTransform &rCopy, float iOffX, float iOffY) // ctor doing transform at given offset - doesn't init FlipDir (for temp use only)
53  {
54  SetTransformAt(rCopy, iOffX, iOffY);
55  }
56 
58  {
59  // ctor without matrix initialization
60  FlipDir = 1;
61  }
62 
63  C4DrawTransform(int32_t iFlipDir)
64  {
65  // ctor setting flipdir only
66  FlipDir = iFlipDir;
67  // set identity
68  Set(1,0,0,0,1,0,0,0,1);
69  }
70 
71  ~C4DrawTransform() = default;
72 
73  // do transform at given offset - doesn't init FlipDir (for temp use only)
74  void SetTransformAt(C4DrawTransform &rCopy, float iOffX, float iOffY);
75 
76  void Set(float fA, float fB, float fC, float fD, float fE, float fF, float fG, float fH, float fI)
77  {
78  // set values; apply flipdir
79  C4BltTransform::Set(fA*FlipDir, fB, fC, fD, fE, fF, fG, fH, fI);
80  }
81 
82  void SetFlipDir(int32_t iNewFlipDir)
83  {
84  // no change?
85  if (iNewFlipDir == FlipDir) return;
86  // set and apply in matrix
87  FlipDir = iNewFlipDir; mat[0] = -mat[0];
88  }
89 
90  bool IsIdentity() const
91  {
92  return (mat[0]==1.0f) && (mat[1]==0.0f) && (mat[2]==0.0f)
93  && (mat[3]==0.0f) && (mat[4]==1.0f) && (mat[5]==0.0f)
94  && (mat[6]==0.0f) && (mat[7]==0.0f) && (mat[8]==1.0f)
95  && (FlipDir==1); // flipdir must be 1, because otherwise matrices flipped by action+script would be removed
96  }
97 
98  // default comparison op won't work :(
99  bool operator == (const C4DrawTransform &rCmp) const
100  {
101  return (mat[0]==rCmp.mat[0]) && (mat[1]==rCmp.mat[1]) && (mat[2]==rCmp.mat[2])
102  && (mat[3]==rCmp.mat[3]) && (mat[4]==rCmp.mat[4]) && (mat[5]==rCmp.mat[5])
103  && (mat[6]==rCmp.mat[6]) && (mat[7]==rCmp.mat[7]) && (mat[8]==rCmp.mat[8]) && (FlipDir == rCmp.FlipDir);
104  }
105  C4DrawTransform * operator&() { return this; }
106  void CompileFunc(StdCompiler *pComp);
107 
108  // rounded pixel offsets generated by this transformation
109  int32_t GetXOffset() const { return static_cast<int32_t>(mat[2]); }
110  int32_t GetYOffset() const { return static_cast<int32_t>(mat[5]); }
111 
112 };
113 
114 class C4Facet
115 {
116 public:
118  float X,Y,Wdt,Hgt;
119 public:
120  C4Facet();
121  C4Facet(C4Surface * pSfc, float iX, float iY, float iWdt, float iHgt)
122  : Surface(pSfc), X(iX), Y(iY), Wdt(iWdt), Hgt(iHgt) { }
123 public:
124  void Default();
125  void Set(C4Surface &rSfc);
126  void Set(C4Surface * nsfc, float nx, float ny, float nwdt, float nhgt);
127  void Set(const C4Facet &cpy) { *this=cpy; }
128  void Expand(int32_t iLeft=0, int32_t iRight=0, int32_t iTop=0, int32_t iBottom=0);
129  void DrawEnergyLevelEx(int32_t iLevel, int32_t iRange, const C4Facet &gfx, int32_t bar_idx); // draw energy level using graphics
130  void DrawX(C4Surface * sfcTarget, float iX, float iY, float iWdt, float iHgt, int32_t iPhaseX=0, int32_t iPhaseY=0) const;
131  void DrawXFloat(C4Surface * sfcTarget, float fX, float fY, float fWdt, float fHgt) const;
132  void DrawValue(C4Facet &cgo, int32_t iValue, int32_t iPhaseX=0, int32_t iPhaseY=0, int32_t iAlign=C4FCT_Center);
133  void DrawValue2(C4Facet &cgo, int32_t iValue1, int32_t iValue2, int32_t iPhaseX=0, int32_t iPhaseY=0, int32_t iAlign=C4FCT_Center, int32_t *piUsedWidth=nullptr);
134  void Draw(C4Facet &cgo, bool fAspect=true, int32_t iPhaseX=0, int32_t iPhaseY=0, bool fTransparent=true);
135  void DrawFullScreen(C4Facet &cgo);
136  void DrawT(C4Surface * sfcTarget, float iX, float iY, int32_t iPhaseX, int32_t iPhaseY, C4DrawTransform *pTransform); // draw with transformation (if pTransform is assigned)
137  void DrawT(C4Facet &cgo, bool fAspect, int32_t iPhaseX, int32_t iPhaseY, C4DrawTransform *pTransform);
138  void DrawTUnscaled(C4Surface * sfcTarget, float iX, float iY, int32_t iPhaseX, int32_t iPhaseY, C4DrawTransform *pTransform); // interpret source coordinates as unscaled
139  void DrawTUnscaled(C4Facet &cgo, bool fAspect, int32_t iPhaseX, int32_t iPhaseY, C4DrawTransform *pTransform);
140  void DrawXT(C4Surface * sfcTarget, float iX, float iY, int32_t iWdt, int32_t iHgt, int32_t iPhaseX, int32_t iPhaseY, C4DrawTransform *pTransform);
141  void DrawClr(C4Facet &cgo, bool fAspect=true, DWORD dwClr=0); // set surface color and draw
142  void DrawXClr(C4Surface * sfcTarget, int32_t iX, int32_t iY, int32_t iWdt, int32_t iHgt, DWORD dwClr); // set surface color and draw
143  void DrawValue2Clr(C4Facet &cgo, int32_t iValue1, int32_t iValue2, DWORD dwClr); // set surface color and draw
144  void DrawXR(C4Surface * sfcTarget, int32_t iX, int32_t iY, int32_t iWdt, int32_t iHgt, int32_t iPhaseX=0, int32_t iPhaseY=0, int32_t r=0); // draw rotated
145  void Draw(C4Surface * sfcTarget, float iX, float iY, int32_t iPhaseX=0, int32_t iPhaseY=0);
146  bool GetPhaseNum(int32_t &rX, int32_t &rY); // return number of phases in this graphic
147  C4Facet GetSection(int32_t iSection);
148  C4Facet GetPhase(int iPhaseX=0, int iPhaseY=0);
149  C4Facet GetFraction(int32_t percentWdt, int32_t percentHgt=0, int32_t alignX=C4FCT_Left, int32_t alignY=C4FCT_Top);
150  C4Facet TruncateSection(int32_t iAlign=C4FCT_Left);
151  C4Facet Truncate(int32_t iAlign, int32_t iSize);
152  int32_t GetSectionCount();
153  int32_t GetWidthByHeight(int32_t iHeight) // calc width so it matches facet aspect to height
154  { return iHeight * Wdt / (Hgt ? Hgt : 1); }
155  int32_t GetHeightByWidth(int32_t iWidth) // calc height so it matches facet aspect to width
156  { return iWidth * Hgt / (Wdt ? Wdt : 1); }
157 };
158 
159 class C4TargetFacet: public C4Facet
160 {
161 public:
163  ~C4TargetFacet() = default;
164 public:
166 
167  // Reference values for parallax computations. This is similar to
168  // a scrolling position. In most cases these are the same as TargetX
169  // and TargetY, however for full map screenshots, which are composed
170  // of several individual screenshots, these are kept fixed while
171  // TargetX/TargetY are varied to cover the full map. This prevents
172  // duplicate parallax objects in fullscreen map screenshots. If
173  // TargetX/TargetY are different from ParRefX/ParRefY it can be thought
174  // of as drawing only a part of a window/viewport at a given fixed
175  // scroll position.
176  // See bug #1042.
177  float ParRefX, ParRefY;
178 public:
179  void Default() { TargetX=TargetY=0; Zoom=1; ParRefX=ParRefY=0; C4Facet::Default(); }
180  void Clear() { Surface=nullptr; }
181 
182  void Set(const C4Facet &cpy) { TargetX=TargetY=0; Zoom=1; ParRefX=ParRefY=0; C4Facet::Set(cpy); }
183  void Set(const C4TargetFacet &cpy) { *this = cpy; }
184  void Set(class C4Surface *nsfc, float nx, float ny, float nwdt, float nhgt, float ntx=0, float nty=0, float Zoom=1);
185  void Set(class C4Surface *nsfc, const C4Rect & r, float ntx=0, float nty=0, float Zoom=1);
186  void Set(class C4Surface *nsfc, float nx, float ny, float nwdt, float nhgt, float ntx, float nty, float Zoom, float prx, float pry);
187 
188 public:
190  {
191  Set(rhs.Surface,rhs.X,rhs.Y,rhs.Wdt,rhs.Hgt);
192  return *this;
193  }
194  void SetRect(C4TargetRect &rSrc);
195 };
196 
197 #endif // INC_C4Facet
const int32_t C4FCT_None
Definition: C4Facet.h:25
void DrawXClr(C4Surface *sfcTarget, int32_t iX, int32_t iY, int32_t iWdt, int32_t iHgt, DWORD dwClr)
Definition: C4Facet.cpp:222
void SetTransformAt(C4DrawTransform &rCopy, float iOffX, float iOffY)
Definition: C4Facet.cpp:541
C4Facet TruncateSection(int32_t iAlign=C4FCT_Left)
Definition: C4Facet.cpp:250
float Y
Definition: C4Facet.h:118
float Zoom
Definition: C4Facet.h:165
~C4DrawTransform()=default
void DrawTUnscaled(C4Surface *sfcTarget, float iX, float iY, int32_t iPhaseX, int32_t iPhaseY, C4DrawTransform *pTransform)
Definition: C4Facet.cpp:115
void Set(const C4Facet &cpy)
Definition: C4Facet.h:127
C4DrawTransform(int32_t iFlipDir)
Definition: C4Facet.h:63
const int32_t C4FCT_Alignment
Definition: C4Facet.h:33
C4Facet Truncate(int32_t iAlign, int32_t iSize)
Definition: C4Facet.cpp:284
bool GetPhaseNum(int32_t &rX, int32_t &rY)
Definition: C4Facet.cpp:472
C4DrawTransform(C4DrawTransform &rCopy, float iOffX, float iOffY)
Definition: C4Facet.h:52
void SetRect(C4TargetRect &rSrc)
Definition: C4FacetEx.cpp:44
int32_t GetSectionCount()
Definition: C4Facet.cpp:46
int32_t FlipDir
Definition: C4Facet.h:50
void DrawClr(C4Facet &cgo, bool fAspect=true, DWORD dwClr=0)
Definition: C4Facet.cpp:213
Definition: C4Rect.h:27
C4Facet(C4Surface *pSfc, float iX, float iY, float iWdt, float iHgt)
Definition: C4Facet.h:121
int32_t y
Definition: C4Facet.h:42
const int32_t C4FCT_Right
Definition: C4Facet.h:28
const int32_t C4FCT_Double
Definition: C4Facet.h:36
const int32_t C4FCT_Half
Definition: C4Facet.h:35
void Set(C4Surface &rSfc)
Definition: C4Facet.cpp:459
void Set(float fA, float fB, float fC, float fD, float fE, float fF, float fG, float fH, float fI)
Definition: C4Facet.h:76
void DrawValue2Clr(C4Facet &cgo, int32_t iValue1, int32_t iValue2, DWORD dwClr)
Definition: C4Facet.cpp:230
C4Facet GetFraction(int32_t percentWdt, int32_t percentHgt=0, int32_t alignX=C4FCT_Left, int32_t alignY=C4FCT_Top)
Definition: C4Facet.cpp:555
void DrawXFloat(C4Surface *sfcTarget, float fX, float fY, float fWdt, float fHgt) const
Definition: C4Facet.cpp:368
int32_t GetXOffset() const
Definition: C4Facet.h:109
void DrawValue(C4Facet &cgo, int32_t iValue, int32_t iPhaseX=0, int32_t iPhaseY=0, int32_t iAlign=C4FCT_Center)
Definition: C4Facet.cpp:308
void Set(float fA, float fB, float fC, float fD, float fE, float fF, float fG, float fH, float fI)
const int32_t C4FCT_Bottom
Definition: C4Facet.h:30
void SetFlipDir(int32_t iNewFlipDir)
Definition: C4Facet.h:82
void DrawT(C4Surface *sfcTarget, float iX, float iY, int32_t iPhaseX, int32_t iPhaseY, C4DrawTransform *pTransform)
Definition: C4Facet.cpp:76
bool operator==(const C4DrawTransform &rCmp) const
Definition: C4Facet.h:99
void Default()
Definition: C4Facet.cpp:31
void DrawX(C4Surface *sfcTarget, float iX, float iY, float iWdt, float iHgt, int32_t iPhaseX=0, int32_t iPhaseY=0) const
Definition: C4Facet.cpp:358
void Set(const C4Facet &cpy)
Definition: C4Facet.h:182
C4DrawTransform * operator&()
Definition: C4Facet.h:105
void Draw(C4Facet &cgo, bool fAspect=true, int32_t iPhaseX=0, int32_t iPhaseY=0, bool fTransparent=true)
Definition: C4Facet.cpp:154
void Clear()
Definition: C4Facet.h:180
C4Facet()
Definition: C4Facet.cpp:41
void Set(const C4TargetFacet &cpy)
Definition: C4Facet.h:183
void DrawFullScreen(C4Facet &cgo)
Definition: C4Facet.cpp:184
C4Vec2D(int32_t x=0, int32_t y=0)
Definition: C4Facet.h:44
float TargetX
Definition: C4Facet.h:165
void CompileFunc(StdCompiler *pComp)
Definition: C4Facet.cpp:482
const int32_t C4FCT_Left
Definition: C4Facet.h:27
void DrawValue2(C4Facet &cgo, int32_t iValue1, int32_t iValue2, int32_t iPhaseX=0, int32_t iPhaseY=0, int32_t iAlign=C4FCT_Center, int32_t *piUsedWidth=nullptr)
Definition: C4Facet.cpp:332
void Default()
Definition: C4Facet.h:179
int32_t GetWidthByHeight(int32_t iHeight)
Definition: C4Facet.h:153
float Hgt
Definition: C4Facet.h:118
void DrawXR(C4Surface *sfcTarget, int32_t iX, int32_t iY, int32_t iWdt, int32_t iHgt, int32_t iPhaseX=0, int32_t iPhaseY=0, int32_t r=0)
Definition: C4Facet.cpp:238
const int32_t C4FCT_Center
Definition: C4Facet.h:31
const int32_t C4FCT_Triple
Definition: C4Facet.h:37
int32_t GetYOffset() const
Definition: C4Facet.h:110
float ParRefY
Definition: C4Facet.h:177
void DrawEnergyLevelEx(int32_t iLevel, int32_t iRange, const C4Facet &gfx, int32_t bar_idx)
Definition: C4Facet.cpp:402
~C4TargetFacet()=default
void DrawXT(C4Surface *sfcTarget, float iX, float iY, int32_t iWdt, int32_t iHgt, int32_t iPhaseX, int32_t iPhaseY, C4DrawTransform *pTransform)
Definition: C4Facet.cpp:392
int32_t GetHeightByWidth(int32_t iWidth)
Definition: C4Facet.h:155
C4Surface * Surface
Definition: C4Facet.h:117
float TargetY
Definition: C4Facet.h:165
uint32_t DWORD
float ParRefX
Definition: C4Facet.h:177
float Wdt
Definition: C4Facet.h:118
C4Facet GetPhase(int iPhaseX=0, int iPhaseY=0)
Definition: C4Facet.cpp:59
bool IsIdentity() const
Definition: C4Facet.h:90
float X
Definition: C4Facet.h:118
C4Facet GetSection(int32_t iSection)
Definition: C4Facet.cpp:52
void Expand(int32_t iLeft=0, int32_t iRight=0, int32_t iTop=0, int32_t iBottom=0)
Definition: C4Facet.cpp:464
C4TargetFacet & operator=(const C4Facet &rhs)
Definition: C4Facet.h:189
int32_t x
Definition: C4Facet.h:42
int iSize
Definition: TstC4NetIO.cpp:32
const int32_t C4FCT_Top
Definition: C4Facet.h:29