PageRenderTime 238ms CodeModel.GetById 34ms RepoModel.GetById 4ms app.codeStats 0ms

/src/lib/texture/C4FacetEx.h

https://bitbucket.org/randrian/openclonk2
C Header | 117 lines | 78 code | 17 blank | 22 comment | 1 complexity | 1f3b112f3dd88e2bcd397f4afcbab888 MD5 | raw file
Possible License(s): WTFPL, 0BSD, LGPL-2.1, CC-BY-3.0
  1. /*
  2. * OpenClonk, http://www.openclonk.org
  3. *
  4. * Copyright (c) 1998-2000 Matthes Bender
  5. * Copyright (c) 2001, 2004, 2008-2009 Sven Eberhardt
  6. * Copyright (c) 2008 G?nther Brammer
  7. * Copyright (c) 2001-2009, RedWolf Design GmbH, http://www.clonk.de
  8. *
  9. * Portions might be copyrighted by other authors who have contributed
  10. * to OpenClonk.
  11. *
  12. * Permission to use, copy, modify, and/or distribute this software for any
  13. * purpose with or without fee is hereby granted, provided that the above
  14. * copyright notice and this permission notice appear in all copies.
  15. * See isc_license.txt for full license and disclaimer.
  16. *
  17. * "Clonk" is a registered trademark of Matthes Bender.
  18. * See clonk_trademark_license.txt for full license.
  19. */
  20. /* A facet that can hold its own surface and also target coordinates */
  21. #ifndef INC_C4FacetEx
  22. #define INC_C4FacetEx
  23. #include <C4Facet.h>
  24. #include <C4Surface.h>
  25. const int C4FCT_Full = -1,
  26. C4FCT_Height = -2,
  27. C4FCT_Width = -3;
  28. class C4TargetRect;
  29. class CSurface;
  30. class C4Rect;
  31. class C4TargetFacet: public C4Facet
  32. {
  33. public:
  34. C4TargetFacet() { Default(); }
  35. ~C4TargetFacet() { }
  36. public:
  37. float TargetX,TargetY;
  38. public:
  39. void Default() { TargetX=TargetY=0; C4Facet::Default(); }
  40. void Clear() { Surface=NULL; }
  41. void Set(const C4Facet &cpy) { TargetX=TargetY=0; C4Facet::Set(cpy); }
  42. void Set(const C4TargetFacet &cpy) { *this = cpy; }
  43. void Set(class CSurface *nsfc, int nx, int ny, int nwdt, int nhgt, float ntx=0, float nty=0);
  44. void Set(class CSurface *nsfc, const C4Rect & r, float ntx=0, float nty=0);
  45. void DrawBolt(int iX1, int iY1, int iX2, int iY2, BYTE bCol, BYTE bCol2);
  46. void DrawLine(int iX1, int iY1, int iX2, int iY2, BYTE bCol1, BYTE bCol2);
  47. void DrawLineDw(int iX1, int iY1, int iX2, int iY2, uint32_t col1, uint32_t col2);
  48. public:
  49. C4TargetFacet &operator = (const C4Facet& rhs)
  50. {
  51. Set(rhs.Surface,rhs.X,rhs.Y,rhs.Wdt,rhs.Hgt);
  52. return *this;
  53. }
  54. void SetRect(C4TargetRect &rSrc);
  55. };
  56. // facet that can hold its own surface
  57. class C4FacetSurface : public C4Facet
  58. {
  59. private:
  60. C4Surface Face;
  61. private:
  62. C4FacetSurface(const C4FacetSurface &rCpy); // NO copy!
  63. C4FacetSurface &operator = (const C4FacetSurface &rCpy); // NO copy assignment!
  64. public:
  65. C4FacetSurface() { Default(); }
  66. ~C4FacetSurface() { Clear(); }
  67. void Default() { Face.Default(); C4Facet::Default(); }
  68. void Clear() { Face.Clear(); }
  69. void Set(const C4Facet &cpy) { Clear(); C4Facet::Set(cpy); }
  70. void Set(const C4TargetFacet &cpy) { Clear(); C4Facet::Set(cpy); }
  71. void Set(SURFACE nsfc, int nx, int ny, int nwdt, int nhgt, int ntx=0, int nty=0)
  72. { C4Facet::Set(nsfc, nx,ny,nwdt,nhgt); }
  73. void Grayscale(int32_t iOffset = 0);
  74. bool Create(int iWdt, int iHgt, int iWdt2=C4FCT_Full, int iHgt2=C4FCT_Full);
  75. C4Surface &GetFace() { return Face; } // get internal face
  76. bool CreateClrByOwner(CSurface *pBySurface);
  77. bool EnsureSize(int iMinWdt, int iMinHgt);
  78. bool EnsureOwnSurface();
  79. bool Load(C4Group &hGroup, const char *szName, int iWdt=C4FCT_Full, int iHgt=C4FCT_Full, bool fOwnPal=false, bool fNoErrIfNotFound=false);
  80. bool Load(BYTE *bpBitmap, int iWdt=C4FCT_Full, int iHgt=C4FCT_Full);
  81. bool Save(C4Group &hGroup, const char *szName);
  82. void GrabFrom(C4FacetSurface &rSource)
  83. {
  84. Clear(); Default();
  85. Face.MoveFrom(&rSource.Face);
  86. Set(rSource.Surface == &rSource.Face ? &Face : rSource.Surface, rSource.X, rSource.Y, rSource.Wdt, rSource.Hgt);
  87. rSource.Default();
  88. }
  89. bool CopyFromSfcMaxSize(C4Surface &srcSfc, int32_t iMaxSize, uint32_t dwColor=0u);
  90. };
  91. // facet with source group ID; used to avoid doubled loading from same group
  92. class C4FacetID : public C4FacetSurface
  93. {
  94. public:
  95. int32_t idSourceGroup;
  96. C4FacetID() : C4FacetSurface(), idSourceGroup(0) { } // ctor
  97. void Default() { C4FacetSurface::Default(); idSourceGroup = 0; } // default to std values
  98. void Clear() { C4FacetSurface::Clear(); idSourceGroup = 0; } // clear all data in class
  99. };
  100. #endif