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 
72  {
73  }
74 
75  // do transform at given offset - doesn't init FlipDir (for temp use only)
76  void SetTransformAt(C4DrawTransform &rCopy, float iOffX, float iOffY);
77 
78  void Set(float fA, float fB, float fC, float fD, float fE, float fF, float fG, float fH, float fI)
79  {
80  // set values; apply flipdir
81  C4BltTransform::Set(fA*FlipDir, fB, fC, fD, fE, fF, fG, fH, fI);
82  }
83 
84  void SetFlipDir(int32_t iNewFlipDir)
85  {
86  // no change?
87  if (iNewFlipDir == FlipDir) return;
88  // set and apply in matrix
89  FlipDir = iNewFlipDir; mat[0] = -mat[0];
90  }
91 
92  bool IsIdentity() const
93  {
94  return (mat[0]==1.0f) && (mat[1]==0.0f) && (mat[2]==0.0f)
95  && (mat[3]==0.0f) && (mat[4]==1.0f) && (mat[5]==0.0f)
96  && (mat[6]==0.0f) && (mat[7]==0.0f) && (mat[8]==1.0f)
97  && (FlipDir==1); // flipdir must be 1, because otherwise matrices flipped by action+script would be removed
98  }
99 
100  // default comparison op won't work :(
101  bool operator == (const C4DrawTransform &rCmp) const
102  {
103  return (mat[0]==rCmp.mat[0]) && (mat[1]==rCmp.mat[1]) && (mat[2]==rCmp.mat[2])
104  && (mat[3]==rCmp.mat[3]) && (mat[4]==rCmp.mat[4]) && (mat[5]==rCmp.mat[5])
105  && (mat[6]==rCmp.mat[6]) && (mat[7]==rCmp.mat[7]) && (mat[8]==rCmp.mat[8]) && (FlipDir == rCmp.FlipDir);
106  }
107  C4DrawTransform * operator&() { return this; }
108  void CompileFunc(StdCompiler *pComp);
109 
110  // rounded pixel offsets generated by this transformation
111  int32_t GetXOffset() const { return static_cast<int32_t>(mat[2]); }
112  int32_t GetYOffset() const { return static_cast<int32_t>(mat[5]); }
113 
114 };
115 
116 class C4Facet
117 {
118 public:
120  float X,Y,Wdt,Hgt;
121 public:
122  C4Facet();
123  C4Facet(C4Surface * pSfc, float iX, float iY, float iWdt, float iHgt)
124  : Surface(pSfc), X(iX), Y(iY), Wdt(iWdt), Hgt(iHgt) { }
125 public:
126  void Default();
127  void Set(C4Surface &rSfc);
128  void Set(C4Surface * nsfc, float nx, float ny, float nwdt, float nhgt);
129  void Set(const C4Facet &cpy) { *this=cpy; }
130  void Expand(int32_t iLeft=0, int32_t iRight=0, int32_t iTop=0, int32_t iBottom=0);
131  void DrawEnergyLevelEx(int32_t iLevel, int32_t iRange, const C4Facet &gfx, int32_t bar_idx); // draw energy level using graphics
132  void DrawX(C4Surface * sfcTarget, float iX, float iY, float iWdt, float iHgt, int32_t iPhaseX=0, int32_t iPhaseY=0) const;
133  void DrawXFloat(C4Surface * sfcTarget, float fX, float fY, float fWdt, float fHgt) const;
134  void DrawValue(C4Facet &cgo, int32_t iValue, int32_t iPhaseX=0, int32_t iPhaseY=0, int32_t iAlign=C4FCT_Center);
135  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);
136  void Draw(C4Facet &cgo, bool fAspect=true, int32_t iPhaseX=0, int32_t iPhaseY=0, bool fTransparent=true);
137  void DrawFullScreen(C4Facet &cgo);
138  void DrawT(C4Surface * sfcTarget, float iX, float iY, int32_t iPhaseX, int32_t iPhaseY, C4DrawTransform *pTransform); // draw with transformation (if pTransform is assigned)
139  void DrawT(C4Facet &cgo, bool fAspect, int32_t iPhaseX, int32_t iPhaseY, C4DrawTransform *pTransform);
140  void DrawTUnscaled(C4Surface * sfcTarget, float iX, float iY, int32_t iPhaseX, int32_t iPhaseY, C4DrawTransform *pTransform); // interpret source coordinates as unscaled
141  void DrawTUnscaled(C4Facet &cgo, bool fAspect, int32_t iPhaseX, int32_t iPhaseY, C4DrawTransform *pTransform);
142  void DrawXT(C4Surface * sfcTarget, float iX, float iY, int32_t iWdt, int32_t iHgt, int32_t iPhaseX, int32_t iPhaseY, C4DrawTransform *pTransform);
143  void DrawClr(C4Facet &cgo, bool fAspect=true, DWORD dwClr=0); // set surface color and draw
144  void DrawXClr(C4Surface * sfcTarget, int32_t iX, int32_t iY, int32_t iWdt, int32_t iHgt, DWORD dwClr); // set surface color and draw
145  void DrawValue2Clr(C4Facet &cgo, int32_t iValue1, int32_t iValue2, DWORD dwClr); // set surface color and draw
146  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
147  void Draw(C4Surface * sfcTarget, float iX, float iY, int32_t iPhaseX=0, int32_t iPhaseY=0);
148  bool GetPhaseNum(int32_t &rX, int32_t &rY); // return number of phases in this graphic
149  C4Facet GetSection(int32_t iSection);
150  C4Facet GetPhase(int iPhaseX=0, int iPhaseY=0);
151  C4Facet GetFraction(int32_t percentWdt, int32_t percentHgt=0, int32_t alignX=C4FCT_Left, int32_t alignY=C4FCT_Top);
152  C4Facet TruncateSection(int32_t iAlign=C4FCT_Left);
153  C4Facet Truncate(int32_t iAlign, int32_t iSize);
154  int32_t GetSectionCount();
155  int32_t GetWidthByHeight(int32_t iHeight) // calc width so it matches facet aspect to height
156  { return iHeight * Wdt / (Hgt ? Hgt : 1); }
157  int32_t GetHeightByWidth(int32_t iWidth) // calc height so it matches facet aspect to width
158  { return iWidth * Hgt / (Wdt ? Wdt : 1); }
159 };
160 
161 class C4TargetFacet: public C4Facet
162 {
163 public:
166 public:
168 
169  // Reference values for parallax computations. This is similar to
170  // a scrolling position. In most cases these are the same as TargetX
171  // and TargetY, however for full map screenshots, which are composed
172  // of several individual screenshots, these are kept fixed while
173  // TargetX/TargetY are varied to cover the full map. This prevents
174  // duplicate parallax objects in fullscreen map screenshots. If
175  // TargetX/TargetY are different from ParRefX/ParRefY it can be thought
176  // of as drawing only a part of a window/viewport at a given fixed
177  // scroll position.
178  // See bug #1042.
179  float ParRefX, ParRefY;
180 public:
181  void Default() { TargetX=TargetY=0; Zoom=1; ParRefX=ParRefY=0; C4Facet::Default(); }
182  void Clear() { Surface=nullptr; }
183 
184  void Set(const C4Facet &cpy) { TargetX=TargetY=0; Zoom=1; ParRefX=ParRefY=0; C4Facet::Set(cpy); }
185  void Set(const C4TargetFacet &cpy) { *this = cpy; }
186  void Set(class C4Surface *nsfc, float nx, float ny, float nwdt, float nhgt, float ntx=0, float nty=0, float Zoom=1);
187  void Set(class C4Surface *nsfc, const C4Rect & r, float ntx=0, float nty=0, float Zoom=1);
188  void Set(class C4Surface *nsfc, float nx, float ny, float nwdt, float nhgt, float ntx, float nty, float Zoom, float prx, float pry);
189 
190 public:
192  {
193  Set(rhs.Surface,rhs.X,rhs.Y,rhs.Wdt,rhs.Hgt);
194  return *this;
195  }
196  void SetRect(C4TargetRect &rSrc);
197 };
198 
199 #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:120
float Zoom
Definition: C4Facet.h:167
void DrawTUnscaled(C4Surface *sfcTarget, float iX, float iY, int32_t iPhaseX, int32_t iPhaseY, C4DrawTransform *pTransform)
Definition: C4Facet.cpp:115
~C4DrawTransform()
Definition: C4Facet.h:71
void Set(const C4Facet &cpy)
Definition: C4Facet.h:129
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:29
C4Facet(C4Surface *pSfc, float iX, float iY, float iWdt, float iHgt)
Definition: C4Facet.h:123
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:78
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:111
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:84
~C4TargetFacet()
Definition: C4Facet.h:165
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:101
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:184
C4DrawTransform * operator&()
Definition: C4Facet.h:107
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:182
C4Facet()
Definition: C4Facet.cpp:41
void Set(const C4TargetFacet &cpy)
Definition: C4Facet.h:185
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:167
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:181
int32_t GetWidthByHeight(int32_t iHeight)
Definition: C4Facet.h:155
float Hgt
Definition: C4Facet.h:120
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:112
float ParRefY
Definition: C4Facet.h:179
void DrawEnergyLevelEx(int32_t iLevel, int32_t iRange, const C4Facet &gfx, int32_t bar_idx)
Definition: C4Facet.cpp:402
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:157
C4Surface * Surface
Definition: C4Facet.h:119
float TargetY
Definition: C4Facet.h:167
uint32_t DWORD
float ParRefX
Definition: C4Facet.h:179
float Wdt
Definition: C4Facet.h:120
C4Facet GetPhase(int iPhaseX=0, int iPhaseY=0)
Definition: C4Facet.cpp:59
bool IsIdentity() const
Definition: C4Facet.h:92
float X
Definition: C4Facet.h:120
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:191
int32_t x
Definition: C4Facet.h:42
int iSize
Definition: TstC4NetIO.cpp:35
const int32_t C4FCT_Top
Definition: C4Facet.h:29