OpenClonk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
C4Facet.cpp
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) 2009-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 #include "C4Include.h"
21 #include "graphics/C4Draw.h"
22 #include "graphics/C4Facet.h"
24 
25 #include "lib/StdAdaptors.h"
26 
27 #ifdef WITH_GLIB
28 #include <glib.h>
29 #endif
30 
32 {
33  Set(nullptr,0,0,0,0);
34 }
35 
36 void C4Facet::Set(C4Surface * nsfc, float nx, float ny, float nwdt, float nhgt)
37 {
38  Surface=nsfc; X=nx; Y=ny; Wdt=nwdt; Hgt=nhgt;
39 }
40 
42 {
43  Default();
44 }
45 
47 {
48  if (Hgt==0) return 0;
49  return Wdt/Hgt;
50 }
51 
52 C4Facet C4Facet::GetSection(int32_t iSection)
53 {
54  C4Facet rval;
55  rval.Set(Surface,X+Hgt*iSection,Y,Hgt,Hgt);
56  return rval;
57 }
58 
59 C4Facet C4Facet::GetPhase(int iPhaseX, int iPhaseY)
60 {
61  C4Facet fctResult;
62  fctResult.Set(Surface,X+Wdt*iPhaseX,Y+Hgt*iPhaseY,Wdt,Hgt);
63  return fctResult;
64 }
65 
66 void C4Facet::Draw(C4Surface * sfcTarget, float iX, float iY, int32_t iPhaseX, int32_t iPhaseY)
67 {
68  if (!pDraw || !Surface || !sfcTarget || !Wdt || !Hgt) return;
69 
71  float(X+Wdt*iPhaseX),float(Y+Hgt*iPhaseY),float(Wdt),float(Hgt),
72  sfcTarget,
73  iX,iY,Wdt,Hgt,true);
74 }
75 
76 void C4Facet::DrawT(C4Surface * sfcTarget, float iX, float iY, int32_t iPhaseX, int32_t iPhaseY, C4DrawTransform *pTransform)
77 {
78  if (!pDraw || !Surface || !sfcTarget || !Wdt || !Hgt) return;
79 
81  float(X+Wdt*iPhaseX),float(Y+Hgt*iPhaseY),float(Wdt),float(Hgt),
82  sfcTarget,
83  iX,iY,Wdt,Hgt,true,pTransform);
84 }
85 
86 void C4Facet::DrawT(C4Facet &cgo, bool fAspect, int32_t iPhaseX, int32_t iPhaseY, C4DrawTransform *pTransform)
87 {
88  if (!pDraw || !Surface || !cgo.Surface || !Wdt || !Hgt) return;
89 
90  // Drawing area
91  C4Facet ccgo = cgo;
92  // Adjust for fixed aspect ratio
93  if (fAspect)
94  {
95  // By height
96  if (100*cgo.Wdt/Wdt<100*cgo.Hgt/Hgt)
97  {
98  ccgo.Hgt=Hgt*cgo.Wdt/Wdt;
99  ccgo.Y+=(cgo.Hgt-ccgo.Hgt)/2;
100  }
101  // By width
102  else if (100*cgo.Hgt/Hgt<100*cgo.Wdt/Wdt)
103  {
104  ccgo.Wdt=Wdt*cgo.Hgt/Hgt;
105  ccgo.X+=(cgo.Wdt-ccgo.Wdt)/2;
106  }
107  }
108 
109  pDraw->Blit(Surface,
110  float(X+Wdt*iPhaseX),float(Y+Hgt*iPhaseY),float(Wdt),float(Hgt),
111  ccgo.Surface,ccgo.X,ccgo.Y,ccgo.Wdt,ccgo.Hgt,
112  true,pTransform);
113 }
114 
115 void C4Facet::DrawTUnscaled(C4Surface * sfcTarget, float iX, float iY, int32_t iPhaseX, int32_t iPhaseY, C4DrawTransform *pTransform)
116 {
117  if (!pDraw || !Surface || !sfcTarget || !Wdt || !Hgt) return;
118 
120  float(X+Wdt*iPhaseX),float(Y+Hgt*iPhaseY),float(Wdt),float(Hgt),
121  sfcTarget,
122  iX,iY,Wdt,Hgt,true,pTransform);
123 }
124 
125 void C4Facet::DrawTUnscaled(C4Facet &cgo, bool fAspect, int32_t iPhaseX, int32_t iPhaseY, C4DrawTransform *pTransform)
126 {
127  if (!pDraw || !Surface || !cgo.Surface || !Wdt || !Hgt) return;
128 
129  // Drawing area
130  C4Facet ccgo = cgo;
131  // Adjust for fixed aspect ratio
132  if (fAspect)
133  {
134  // By height
135  if (100*cgo.Wdt/Wdt<100*cgo.Hgt/Hgt)
136  {
137  ccgo.Hgt=Hgt*cgo.Wdt/Wdt;
138  ccgo.Y+=(cgo.Hgt-ccgo.Hgt)/2;
139  }
140  // By width
141  else if (100*cgo.Hgt/Hgt<100*cgo.Wdt/Wdt)
142  {
143  ccgo.Wdt=Wdt*cgo.Hgt/Hgt;
144  ccgo.X+=(cgo.Wdt-ccgo.Wdt)/2;
145  }
146  }
147 
149  float(X+Wdt*iPhaseX),float(Y+Hgt*iPhaseY),float(Wdt),float(Hgt),
150  ccgo.Surface,ccgo.X,ccgo.Y,ccgo.Wdt,ccgo.Hgt,
151  true,pTransform);
152 }
153 
154 void C4Facet::Draw(C4Facet &cgo, bool fAspect, int32_t iPhaseX, int32_t iPhaseY, bool fTransparent)
155 {
156  // Valid parameter check
157  if (!pDraw || !Surface || !cgo.Surface || !Wdt || !Hgt) return;
158  // Drawing area
159  C4Facet ccgo = cgo;
160  // Adjust for fixed aspect ratio (letterbox)
161  if (fAspect)
162  {
163  // By height
164  if (cgo.Wdt / Wdt < cgo.Hgt / Hgt)
165  {
166  ccgo.Hgt = Hgt * cgo.Wdt / Wdt;
167  ccgo.Y += (cgo.Hgt - ccgo.Hgt) / 2;
168  }
169  // By width
170  else if (cgo.Hgt / Hgt < cgo.Wdt / Wdt)
171  {
172  ccgo.Wdt = Wdt * cgo.Hgt / Hgt;
173  ccgo.X += (cgo.Wdt - ccgo.Wdt) / 2;
174  }
175  }
176  // Blit
177  pDraw->Blit(Surface,
178  float(X+Wdt*iPhaseX),float(Y+Hgt*iPhaseY),float(Wdt),float(Hgt),
179  ccgo.Surface,
180  ccgo.X,ccgo.Y,ccgo.Wdt,ccgo.Hgt,
181  fTransparent);
182 }
183 
185 {
186  // Valid parameter check
187  if (!pDraw || !Surface || !cgo.Surface || !Wdt || !Hgt) return;
188  // Drawing area
189  C4Facet ccgo = cgo;
190  // stretched fullscreen blit: make sure right and lower side are cleared, because this may be missed due to stretching
191  if (cgo.Wdt > Wdt+2 || cgo.Hgt > Wdt+2)
192  {
193  ccgo.X -= 1; ccgo.Y -= 1;
194  ccgo.Wdt += 2; ccgo.Hgt += 2;
195  }
196  // Adjust for fixed aspect ratio (crop)
197  // By height
198  if (cgo.Wdt / Wdt < cgo.Hgt / Hgt)
199  {
200  ccgo.Wdt = Wdt * cgo.Hgt / Hgt;
201  ccgo.X += (cgo.Wdt - ccgo.Wdt) / 2;
202  }
203  // By width
204  else if (cgo.Hgt / Hgt < cgo.Wdt / Wdt)
205  {
206  ccgo.Hgt = Hgt * cgo.Wdt / Wdt;
207  ccgo.Y += (cgo.Hgt - ccgo.Hgt) / 2;
208  }
209  // Blit
210  pDraw->Blit(Surface, X, Y, Wdt, Hgt, ccgo.Surface, ccgo.X, ccgo.Y, ccgo.Wdt, ccgo.Hgt);
211 }
212 
213 void C4Facet::DrawClr(C4Facet &cgo, bool fAspect, DWORD dwClr)
214 {
215  if (!Surface) return;
216  // set ColorByOwner-color
217  Surface->SetClr(dwClr);
218  // draw
219  Draw(cgo, fAspect);
220 }
221 
222 void C4Facet::DrawXClr(C4Surface * sfcTarget, int32_t iX, int32_t iY, int32_t iWdt, int32_t iHgt, DWORD dwClr)
223 {
224  // set ColorByOwner-color
225  Surface->SetClr(dwClr);
226  // draw
227  DrawX(sfcTarget, iX, iY, iWdt, iHgt);
228 }
229 
230 void C4Facet::DrawValue2Clr(C4Facet &cgo, int32_t iValue1, int32_t iValue2, DWORD dwClr)
231 {
232  // set ColorByOwner-color
233  Surface->SetClr(dwClr);
234  // draw
235  DrawValue2(cgo, iValue1, iValue2);
236 }
237 
238 void C4Facet::DrawXR(C4Surface * sfcTarget, int32_t iX, int32_t iY, int32_t iWdt, int32_t iHgt, int32_t iSectionX, int32_t iSectionY, int32_t r)
239 {
240  if (!pDraw || !Surface || !sfcTarget || !Wdt || !Hgt) return;
241  C4BltTransform rot;
242  rot.SetRotate(r / 100.0f, (float) (iX+iX+iWdt)/2, (float) (iY+iY+iHgt)/2);
243  pDraw->Blit(Surface,
244  float(X+Wdt*iSectionX),float(Y+Hgt*iSectionY),float(Wdt),float(Hgt),
245  sfcTarget,
246  iX,iY,iWdt,iHgt,
247  true,&rot);
248 }
249 
251 {
252  C4Facet fctResult; fctResult.Set(Surface,0,0,0,0);
253  // Calculate section size
254  int32_t iWdt=Wdt,iHgt=Hgt;
255  switch (iAlign & C4FCT_Alignment)
256  {
257  case C4FCT_Left: case C4FCT_Right:
258  iWdt=Hgt;
259  if (iAlign & C4FCT_Triple) iWdt*=3;
260  if (iAlign & C4FCT_Double) iWdt*=2;
261  if (iAlign & C4FCT_Half) iWdt/=2;
262  break;
263  case C4FCT_Top: case C4FCT_Bottom:
264  iHgt=Wdt;
265  if (iAlign & C4FCT_Triple) iHgt*=3;
266  if (iAlign & C4FCT_Double) iHgt*=2;
267  if (iAlign & C4FCT_Half) iHgt/=2;
268  break;
269  }
270  // Size safety
271  if ((iWdt>Wdt) || (iHgt>Hgt)) return fctResult;
272  // Truncate
273  switch (iAlign & C4FCT_Alignment)
274  {
275  case C4FCT_Left: fctResult.Set(Surface,X,Y,iWdt,iHgt); X+=iWdt; Wdt-=iWdt; break;
276  case C4FCT_Right: fctResult.Set(Surface,X+Wdt-iWdt,Y,iWdt,iHgt); Wdt-=iWdt; break;
277  case C4FCT_Top: fctResult.Set(Surface,X,Y,iWdt,iHgt); Y+=iHgt; Hgt-=iHgt; break;
278  case C4FCT_Bottom: fctResult.Set(Surface,X,Y+Hgt-iHgt,iWdt,iHgt); Hgt-=iHgt; break;
279  }
280  // Done
281  return fctResult;
282 }
283 
284 C4Facet C4Facet::Truncate(int32_t iAlign, int32_t iSize)
285 {
286  C4Facet fctResult; fctResult.Set(Surface,0,0,0,0);
287  // Calculate section size
288  int32_t iWdt=Wdt,iHgt=Hgt;
289  switch (iAlign)
290  {
291  case C4FCT_Left: case C4FCT_Right: iWdt=iSize; break;
292  case C4FCT_Top: case C4FCT_Bottom: iHgt=iSize; break;
293  }
294  // Size safety
295  if ((iWdt>Wdt) || (iHgt>Hgt)) return fctResult;
296  // Truncate
297  switch (iAlign)
298  {
299  case C4FCT_Left: fctResult.Set(Surface,X,Y,iWdt,iHgt); X+=iWdt; Wdt-=iWdt; break;
300  case C4FCT_Right: fctResult.Set(Surface,X+Wdt-iWdt,Y,iWdt,iHgt); Wdt-=iWdt; break;
301  case C4FCT_Top: fctResult.Set(Surface,X,Y,iWdt,iHgt); Y+=iHgt; Hgt-=iHgt; break;
302  case C4FCT_Bottom: fctResult.Set(Surface,X,Y+Hgt-iHgt,iWdt,iHgt); Hgt-=iHgt; break;
303  }
304  // Done
305  return fctResult;
306 }
307 
308 void C4Facet::DrawValue(C4Facet &cgo, int32_t iValue, int32_t iSectionX, int32_t iSectionY, int32_t iAlign)
309 {
310  if (!pDraw) return;
311  char ostr[25]; sprintf(ostr,"%i",iValue);
312  switch (iAlign)
313  {
314  case C4FCT_Center:
315  Draw(cgo, true, iSectionX, iSectionY);
316  pDraw->TextOut(ostr, ::GraphicsResource.FontRegular, 1.0, cgo.Surface,
317  cgo.X + cgo.Wdt - 1, cgo.Y + cgo.Hgt - 1, C4Draw::DEFAULT_MESSAGE_COLOR, ARight);
318  break;
319  case C4FCT_Right:
320  {
321  int32_t textwdt, texthgt;
322  ::GraphicsResource.FontRegular.GetTextExtent(ostr, textwdt, texthgt, false);
323  pDraw->TextOut(ostr, ::GraphicsResource.FontRegular, 1.0, cgo.Surface,
324  cgo.X + cgo.Wdt - 1, cgo.Y, C4Draw::DEFAULT_MESSAGE_COLOR, ARight);
325  cgo.Set(cgo.Surface, cgo.X + cgo.Wdt - 1 - textwdt - 2 * cgo.Hgt, cgo.Y, 2 * cgo.Hgt, cgo.Hgt);
326  Draw(cgo, true, iSectionX, iSectionY);
327  break;
328  }
329  }
330 }
331 
332 void C4Facet::DrawValue2(C4Facet &cgo, int32_t iValue1, int32_t iValue2, int32_t iSectionX, int32_t iSectionY, int32_t iAlign, int32_t *piUsedWidth)
333 {
334  if (!pDraw) return;
335  char ostr[25]; sprintf(ostr,"%i/%i",iValue1,iValue2);
336  switch (iAlign)
337  {
338  case C4FCT_Center:
339  Draw(cgo, true, iSectionX, iSectionY);
340  pDraw->TextOut(ostr, ::GraphicsResource.FontRegular, 1.0, cgo.Surface,
341  cgo.X + cgo.Wdt - 1, cgo.Y + cgo.Hgt - 1, C4Draw::DEFAULT_MESSAGE_COLOR, ARight);
342  break;
343  case C4FCT_Right:
344  {
345  int32_t textwdt, texthgt;
346  ::GraphicsResource.FontRegular.GetTextExtent(ostr, textwdt, texthgt, false);
347  textwdt += Wdt + 3;
348  pDraw->TextOut(ostr, ::GraphicsResource.FontRegular, 1.0, cgo.Surface,
349  cgo.X + cgo.Wdt - 1, cgo.Y, C4Draw::DEFAULT_MESSAGE_COLOR, ARight);
350  cgo.Set(cgo.Surface, cgo.X + cgo.Wdt - textwdt, cgo.Y, 2 * cgo.Hgt, cgo.Hgt);
351  Draw(cgo, true, iSectionX, iSectionY);
352  if (piUsedWidth) *piUsedWidth = textwdt;
353  }
354  break;
355  }
356 }
357 
358 void C4Facet::DrawX(C4Surface * sfcTarget, float iX, float iY, float iWdt, float iHgt, int32_t iSectionX, int32_t iSectionY) const
359 {
360  if (!pDraw || !Surface || !sfcTarget || !Wdt || !Hgt) return;
361  pDraw->Blit(Surface,
362  float(X+Wdt*iSectionX),float(Y+Hgt*iSectionY),float(Wdt),float(Hgt),
363  sfcTarget,
364  iX,iY,iWdt,iHgt,
365  true);
366 }
367 
368 void C4Facet::DrawXFloat(C4Surface * sfcTarget, float fX, float fY, float fWdt, float fHgt) const
369 {
370  if (!pDraw || !Surface || !sfcTarget || !Wdt || !Hgt || fWdt<=0 || fHgt<=0) return;
371  // Since only source coordinates are available as floats for blitting, go inwards into this facet to match blit
372  // for closest integer target coordinates
373  float zx = fWdt / float(Wdt), zy = fHgt / float(Hgt);
374  int32_t iX = (int32_t) ceilf(fX), iY = (int32_t) ceilf(fY), iX2 = (int32_t) floorf(fX+fWdt), iY2 = (int32_t) floorf(fY+fHgt);
375  float ox = (-fX+iX)/zx, oy = (-fY+iY)/zy;
376  float oxs = (+fX+fWdt-iX2)/zx, oys = (+fY+fHgt-iY2)/zy;
377  pDraw->Blit(Surface,
378  float(X)+ox, float(Y)+oy, float(Wdt)-ox-oxs, float(Hgt)-oy-oys,
379  sfcTarget,
380  iX,iY,iX2-iX,iY2-iY,
381  true);
382  zx=(iX2-iX)/(float(Wdt)-ox-oxs);
383  zy=(iY2-iY)/(float(Hgt)-oy-oys);
384  /* int32_t iX = floorf(fX+0.5)-1, iY = floorf(fY+0.5)-1, iX2 = floorf(fX+fWdt+0.5)-1, iY2 = floorf(fY+fHgt+0.5)-1;
385  pDraw->Blit(Surface,
386  X, Y, Wdt, Hgt,
387  sfcTarget,
388  iX,iY,iX2-iX+1,iY2-iY+1,
389  true);*/
390 }
391 
392 void C4Facet::DrawXT(C4Surface * sfcTarget, float iX, float iY, int32_t iWdt, int32_t iHgt, int32_t iPhaseX, int32_t iPhaseY, C4DrawTransform *pTransform)
393 {
394  if (!pDraw || !Surface || !sfcTarget || !Wdt || !Hgt) return;
395  pDraw->Blit(Surface,
396  float(X+Wdt*iPhaseX),float(Y+Hgt*iPhaseY),float(Wdt),float(Hgt),
397  sfcTarget,
398  iX,iY,iWdt,iHgt,
399  true, pTransform);
400 }
401 
402 void C4Facet::DrawEnergyLevelEx(int32_t iLevel, int32_t iRange, const C4Facet &gfx, int32_t bar_idx)
403 {
404  // draw energy level using graphics
405  if (!pDraw || !gfx.Surface) return;
406  int32_t h=gfx.Hgt;
407  int32_t yBar = Hgt - Clamp<int32_t>(iLevel,0,iRange) * Hgt / std::max<int32_t>(iRange,1);
408  int32_t iY = 0, vidx=0;
409  C4Facet gfx_draw = gfx;
410  bool filled = false;
411  while (iY < Hgt)
412  {
413  int32_t dy = iY % h;
414  int32_t dh = (iY >= Hgt-h) ? Hgt - iY : h - dy;
415  if (!filled)
416  {
417  if (iY >= yBar)
418  {
419  filled = true; // fully filled
420  }
421  else if (iY + h >= yBar)
422  dh = yBar - iY; // partially filled
423  }
424  if (!vidx && iY && iY + dh > h)
425  {
426  if (iY < h)
427  {
428  // had a break within top section of bar; finish top section
429  dh = h - iY;
430  }
431  else
432  {
433  // top section finished
434  ++vidx;
435  }
436  }
437  if (iY + dh >= Hgt - h)
438  {
439  if (iY >= Hgt - h)
440  {
441  // within bottom section
442  vidx = 2;
443  dy = iY + h - Hgt;
444  }
445  else
446  {
447  // finish middle section
448  dh = Hgt - h - iY;
449  }
450  }
451  // draw it; partially if necessary
452  gfx_draw.Y = gfx.Y + vidx*h + dy;
453  gfx_draw.Hgt = dh;
454  gfx_draw.Draw(Surface, X, Y+iY, bar_idx+bar_idx+!filled);
455  iY += dh;
456  }
457 }
458 
460 {
461  Set(&rSfc,0,0,rSfc.Wdt,rSfc.Hgt);
462 }
463 
464 void C4Facet::Expand(int32_t iLeft, int32_t iRight, int32_t iTop, int32_t iBottom)
465 {
466  X-=iLeft; Wdt+=iLeft;
467  Wdt+=iRight;
468  Y-=iTop; Hgt+=iTop;
469  Hgt+=iBottom;
470 }
471 
472 bool C4Facet::GetPhaseNum(int32_t &rX, int32_t &rY)
473 {
474  // safety
475  if (!Surface) return false;
476  // newgfx: use locally stored size
477  rX=Surface->Wdt/Wdt; rY=Surface->Hgt/Hgt;
478  // success
479  return true;
480 }
481 
483 {
484  bool deserializing = pComp->isDeserializer();
485  int i;
486  // hacky. StdCompiler doesn't allow floats to be safed directly.
487  for (i = 0; i < 6; i++)
488  {
489  if (i) pComp->Separator();
490  StdStrBuf val;
491  if (!deserializing)
492  {
493 #ifdef WITH_GLIB
494  val.SetLength(G_ASCII_DTOSTR_BUF_SIZE);
495  // g_ascii_dtostr is locale-independent which printf is not.
496  g_ascii_dtostr(val.getMData(), G_ASCII_DTOSTR_BUF_SIZE, mat[i]);
497 #else
498  val.Format("%g", mat[i]);
499 #endif
500  }
501  pComp->Value(mkParAdapt(val, StdCompiler::RCT_Idtf));
502  if (deserializing && pComp->hasNaming())
503  if (pComp->Separator(StdCompiler::SEP_PART))
504  {
505  StdStrBuf val2;
506  pComp->Value(mkParAdapt(val2, StdCompiler::RCT_Idtf));
507  val.AppendChar('.'); val.Append(val2);
508  }
509 #ifdef WITH_GLIB
510  mat[i] = g_ascii_strtod (val.getData(), nullptr);
511 #else
512  if (deserializing) sscanf(val.getData(), "%g", &mat[i]);
513 #endif
514  }
515  pComp->Separator();
516  pComp->Value(FlipDir);
517  if (!deserializing && mat[6] == 0 && mat[7] == 0 && mat[8] == 1) return;
518  // because of backwards-compatibility, the last row comes after flipdir
519  for (i = 6; i < 9; ++i)
520  {
521  if (!pComp->Separator())
522  {
523  mat[i] = (i == 8) ? 1.0f : 0.0f;
524  }
525  else
526  {
527  StdStrBuf val; if (!deserializing) val.Format("%g", mat[i]);
528  pComp->Value(mkParAdapt(val, StdCompiler::RCT_Idtf));
529  if (deserializing && pComp->hasNaming())
530  if (pComp->Separator(StdCompiler::SEP_PART))
531  {
532  StdStrBuf val2;
533  pComp->Value(mkParAdapt(val2, StdCompiler::RCT_Idtf));
534  val.AppendChar('.'); val.Append(val2);
535  }
536  if (deserializing) sscanf(val.getData(), "%g", &mat[i]);
537  }
538  }
539 }
540 
541 void C4DrawTransform::SetTransformAt(C4DrawTransform &r, float iOffX, float iOffY)
542 {
543  // Set matrix, so that r*(x,y,1)-(x,y,1)==this*(x+iOffX,y+iOffY,1)-(x+iOffX,y+iOffY,1)
544  float A = r.mat[0] + r.mat[6]*iOffX;
545  float B = r.mat[1] + r.mat[7]*iOffX;
546  float D = r.mat[3] + r.mat[6]*iOffY;
547  float E = r.mat[4] + r.mat[7]*iOffY;
549  A, B, r.mat[2] - A *iOffX - B *iOffY + r.mat[8]*iOffX,
550  D, E, r.mat[5] - D *iOffX - E *iOffY + r.mat[8]*iOffY,
551  r.mat[6], r.mat[7], r.mat[8] - r.mat[6]*iOffX - r.mat[7]*iOffY);
552 }
553 
554 
555 C4Facet C4Facet::GetFraction(int32_t percentWdt, int32_t percentHgt, int32_t alignX, int32_t alignY)
556 {
557  C4Facet rval;
558  // Simple spec for square fractions
559  if (percentHgt == 0) percentHgt = percentWdt;
560  // Alignment
561  int iX = X, iY = Y, iWdt = std::max(Wdt*percentWdt/100, 1.0f), iHgt = std::max(Hgt*percentHgt/100, 1.0f);
562  if (alignX & C4FCT_Right) iX += Wdt - iWdt;
563  if (alignX & C4FCT_Center) iX += Wdt/2 - iWdt/2;
564  if (alignY & C4FCT_Bottom) iY += Hgt - iHgt;
565  if (alignY & C4FCT_Center) iY += Hgt/2 - iHgt/2;
566  // Set resulting facet
567  rval.Set(Surface, iX, iY, iWdt, iHgt);
568  return rval;
569 }
const char * getData() const
Definition: StdBuf.h:442
virtual bool Separator(Sep eSep=SEP_SEP)
Definition: StdCompiler.h:119
void DrawXClr(C4Surface *sfcTarget, int32_t iX, int32_t iY, int32_t iWdt, int32_t iHgt, DWORD dwClr)
Definition: C4Facet.cpp:222
virtual bool hasNaming()
Definition: StdCompiler.h:58
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
void DrawTUnscaled(C4Surface *sfcTarget, float iX, float iY, int32_t iPhaseX, int32_t iPhaseY, C4DrawTransform *pTransform)
Definition: C4Facet.cpp:115
int Wdt
Definition: C4Surface.h:65
const int32_t C4FCT_Alignment
Definition: C4Facet.h:33
#define sprintf
Definition: Standard.h:164
C4Facet Truncate(int32_t iAlign, int32_t iSize)
Definition: C4Facet.cpp:284
bool GetPhaseNum(int32_t &rX, int32_t &rY)
Definition: C4Facet.cpp:472
bool TextOut(const char *szText, CStdFont &rFont, float fZoom, C4Surface *sfcDest, float iTx, float iTy, DWORD dwFCol=0xffffffff, BYTE byForm=ALeft, bool fDoMarkup=true)
Definition: C4Draw.cpp:567
int32_t GetSectionCount()
Definition: C4Facet.cpp:46
const int ARight
Definition: C4Surface.h:41
int32_t FlipDir
Definition: C4Facet.h:50
void DrawClr(C4Facet &cgo, bool fAspect=true, DWORD dwClr=0)
Definition: C4Facet.cpp:213
bool GetTextExtent(const char *szText, int32_t &rsx, int32_t &rsy, bool fCheckMarkup=true)
void Format(const char *szFmt,...) GNUC_FORMAT_ATTRIBUTE_O
Definition: StdBuf.cpp:174
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
int Hgt
Definition: C4Surface.h:65
C4GraphicsResource GraphicsResource
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
char * getMData()
Definition: StdBuf.h:443
void AppendChar(char cChar)
Definition: StdBuf.h:588
void DrawXFloat(C4Surface *sfcTarget, float fX, float fY, float fWdt, float fHgt) const
Definition: C4Facet.cpp:368
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 DrawT(C4Surface *sfcTarget, float iX, float iY, int32_t iPhaseX, int32_t iPhaseY, C4DrawTransform *pTransform)
Definition: C4Facet.cpp:76
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 SetClr(DWORD toClr)
Definition: C4Surface.h:132
void Append(const char *pnData, size_t iChars)
Definition: StdBuf.h:519
void Draw(C4Facet &cgo, bool fAspect=true, int32_t iPhaseX=0, int32_t iPhaseY=0, bool fTransparent=true)
Definition: C4Facet.cpp:154
C4Draw * pDraw
Definition: C4Draw.cpp:42
bool BlitUnscaled(C4Surface *sfcSource, float fx, float fy, float fwdt, float fhgt, C4Surface *sfcTarget, float tx, float ty, float twdt, float thgt, bool fSrcColKey=false, const C4BltTransform *pTransform=nullptr)
Definition: C4Draw.cpp:309
C4Facet()
Definition: C4Facet.cpp:41
void Value(const T &rStruct)
Definition: StdCompiler.h:161
void DrawFullScreen(C4Facet &cgo)
Definition: C4Facet.cpp:184
virtual bool isDeserializer()
Definition: StdCompiler.h:53
bool Blit(C4Surface *sfcSource, float fx, float fy, float fwdt, float fhgt, C4Surface *sfcTarget, float tx, float ty, float twdt, float thgt, bool fSrcColKey=false, const C4BltTransform *pTransform=nullptr)
Definition: C4Draw.cpp:301
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
float Hgt
Definition: C4Facet.h:118
void SetRotate(float iAngle, float fOffX, float fOffY)
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
StdParameterAdapt< T, P > mkParAdapt(T &&rObj, P &&rPar)
Definition: StdAdaptors.h:458
void DrawEnergyLevelEx(int32_t iLevel, int32_t iRange, const C4Facet &gfx, int32_t bar_idx)
Definition: C4Facet.cpp:402
void SetLength(size_t iLength)
Definition: StdBuf.h:509
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
C4Surface * Surface
Definition: C4Facet.h:117
uint32_t DWORD
float Wdt
Definition: C4Facet.h:118
C4Facet GetPhase(int iPhaseX=0, int iPhaseY=0)
Definition: C4Facet.cpp:59
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
int iSize
Definition: TstC4NetIO.cpp:32
const int32_t C4FCT_Top
Definition: C4Facet.h:29