OpenClonk
C4Pattern Class Reference

#include <C4Draw.h>

Public Member Functions

C4Patternoperator= (const C4Pattern &)
 
const C4SurfacegetSurface () const
 
DWORD PatternClr (unsigned int iX, unsigned int iY) const
 
bool Set (class C4Surface *sfcSource, int iZoom=0)
 
void SetZoom (int iZoom)
 
void Clear ()
 
 C4Pattern ()
 
 ~C4Pattern ()
 

Detailed Description

Definition at line 38 of file C4Draw.h.

Constructor & Destructor Documentation

◆ C4Pattern()

C4Pattern::C4Pattern ( )

Definition at line 138 of file C4Draw.cpp.

139 {
140  // disable
141  sfcPattern32=nullptr;
142  CachedPattern = nullptr;
143  Zoom=0;
144 }

◆ ~C4Pattern()

C4Pattern::~C4Pattern ( )
inline

Definition at line 55 of file C4Draw.h.

55 { Clear(); } // dtor
void Clear()
Definition: C4Draw.cpp:146

References Clear().

Here is the call graph for this function:

Member Function Documentation

◆ Clear()

void C4Pattern::Clear ( )

Definition at line 146 of file C4Draw.cpp.

147 {
148  // pattern assigned
149  if (sfcPattern32)
150  {
151  // unlock it
152  sfcPattern32->Unlock();
153  // clear field
154  sfcPattern32=nullptr;
155  }
156  delete[] CachedPattern; CachedPattern = nullptr;
157 }
bool Unlock()
Definition: C4Surface.cpp:464

References C4Surface::Unlock().

Referenced by C4TexMapEntry::Clear(), Set(), and ~C4Pattern().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getSurface()

const C4Surface* C4Pattern::getSurface ( ) const
inline

Definition at line 49 of file C4Draw.h.

49 { return sfcPattern32; }

◆ operator=()

C4Pattern & C4Pattern::operator= ( const C4Pattern nPattern)

Definition at line 94 of file C4Draw.cpp.

95 {
96  sfcPattern32 = nPattern.sfcPattern32;
97  if (sfcPattern32) sfcPattern32->Lock();
98  delete [] CachedPattern;
99  if (nPattern.CachedPattern)
100  {
101  CachedPattern = new uint32_t[sfcPattern32->Wdt * sfcPattern32->Hgt];
102  memcpy(CachedPattern, nPattern.CachedPattern, sfcPattern32->Wdt * sfcPattern32->Hgt * 4);
103  }
104  else
105  {
106  CachedPattern = nullptr;
107  }
108  Wdt = nPattern.Wdt;
109  Hgt = nPattern.Hgt;
110  Zoom = nPattern.Zoom;
111  return *this;
112 }
int Wdt
Definition: C4Surface.h:65
bool Lock()
Definition: C4Surface.cpp:453
int Hgt
Definition: C4Surface.h:65

References C4Surface::Hgt, C4Surface::Lock(), and C4Surface::Wdt.

Here is the call graph for this function:

◆ PatternClr()

DWORD C4Pattern::PatternClr ( unsigned int  iX,
unsigned int  iY 
) const

Definition at line 159 of file C4Draw.cpp.

160 {
161  if (!CachedPattern) return 0;
162  // wrap position
163  iX %= Wdt; iY %= Hgt;
164  return CachedPattern[iY * Wdt + iX];
165 }

Referenced by C4Draw::DrawPatternedCircle(), C4Landscape::P::Mat2Pal(), and C4TextureMap::StoreMapPalette().

Here is the caller graph for this function:

◆ Set()

bool C4Pattern::Set ( class C4Surface sfcSource,
int  iZoom = 0 
)

Definition at line 114 of file C4Draw.cpp.

115 {
116  // Safety
117  if (!sfcSource) return false;
118  // Clear existing pattern
119  Clear();
120  // new style: simply store pattern for modulation or shifting, which will be decided upon use
121  sfcPattern32=sfcSource;
122  sfcPattern32->Lock();
123  Wdt = sfcPattern32->Wdt;
124  Hgt = sfcPattern32->Hgt;
125  // set zoom
126  Zoom=iZoom;
127  // set flags
128  CachedPattern = new uint32_t[Wdt * Hgt];
129  if (!CachedPattern) return false;
130  for (int y = 0; y < Hgt; ++y)
131  for (int x = 0; x < Wdt; ++x)
132  {
133  CachedPattern[y * Wdt + x] = sfcPattern32->GetPixDw(x, y, false);
134  }
135  return true;
136 }
DWORD GetPixDw(int iX, int iY, bool fApplyModulation)
Definition: C4Surface.cpp:491

References Clear(), C4Surface::GetPixDw(), C4Surface::Hgt, C4Surface::Lock(), and C4Surface::Wdt.

Referenced by C4TexMapEntry::Init().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SetZoom()

void C4Pattern::SetZoom ( int  iZoom)
inline

Definition at line 52 of file C4Draw.h.

52 { Zoom = iZoom; }

The documentation for this class was generated from the following files: