Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- typedef struct D3D9VERTEX
- {
- FLOAT X;
- FLOAT Y;
- FLOAT Z;
- FLOAT RHW;
- DWORD dwColour;
- }*PD3D9VERTEX, *LPD3D9VERTEX;
- void SetVertexArray(D3D9VERTEX* pVertices, UINT Count, D3D9VERTEX Sample)
- {
- for (UINT i = 0; i != Count; ++i)
- {
- pVertices[i] = Sample;
- }
- }
- void CreatePrimitive2D(FLOAT x1, FLOAT y1, FLOAT x2, FLOAT y2, FLOAT x3, FLOAT y3, DWORD Colour, D3D9VERTEX* pVertices)
- {
- pVertices[0] = { x1, y1, 0.0f, 1.0f, Colour };
- pVertices[1] = { x2, y2, 0.0f, 1.0f, Colour };
- pVertices[2] = { x3, y3, 0.0f, 1.0f, Colour };
- }
- struct D3D9VECT2
- {
- FLOAT X;
- FLOAT Y;
- D3D9VECT2 operator+ (const D3D9VECT2& v)
- {
- return{ X + v.X, Y + v.Y };
- }
- D3D9VECT2 operator- (const D3D9VECT2& v)
- {
- return{ X - v.X, Y - v.Y };
- }
- D3D9VECT2& operator+= (const D3D9VECT2& v)
- {
- X += v.X;
- Y += v.Y;
- return *this;
- }
- D3D9VECT2& operator-= (const D3D9VECT2& v)
- {
- X -= v.X;
- Y -= v.Y;
- return *this;
- }
- D3D9VECT2 operator* (const FLOAT& f)
- {
- return{ X * f, Y * f };
- }
- D3D9VECT2 operator/ (const FLOAT& f)
- {
- return{ X / f, Y / f };
- }
- D3D9VECT2& operator*= (const FLOAT& f)
- {
- X *= f;
- Y *= f;
- return *this;
- }
- D3D9VECT2& operator/= (const FLOAT& f)
- {
- X /= f;
- Y /= f;
- return *this;
- }
- FLOAT Length()
- {
- return sqrt(X * X + Y * Y);
- }
- };
- class D3D9ROUNDEDBOX
- {
- public:
- D3D9ROUNDEDBOX()
- {
- m_X = 0;
- m_Y = 0;
- m_Width = 0;
- m_Height = 0;
- m_Colour = 0;
- m_Rounding = 0;
- m_PrimCount = 0;
- m_Precision = 0;
- m_Pi = 3.14159236535897932385;
- m_pVertices = nullptr;
- }
- void Set(UINT X, UINT Y, UINT Width, UINT Height, UINT Rounding, DWORD Colour, UINT Precision)
- {
- if (m_pVertices)
- {
- Memory::SafeDeleteArr(m_pVertices);
- }
- m_X = X;
- m_Y = Y;
- m_Width = Width;
- m_Height = Height;
- m_Rounding = Rounding;
- m_Precision = Precision;
- m_Colour = Colour;
- m_PrimCount = 6 + (m_Precision) * 2 - 1;
- D3D9VECT2 Center = { m_X + m_Width / 2 - m_Rounding, m_Y - m_Height / 2 + m_Rounding };
- D3D9VECT2 StartPoint = { m_X + m_Width / 2 - m_Rounding, m_Y - m_Height / 2 };
- DOUBLE Step = (DOUBLE)m_Rounding / (DOUBLE)m_Precision;
- DOUBLE Alpha = m_Pi / (m_Precision + 1) / 2;
- DOUBLE CurrAlpha = Alpha;
- m_pVertices = new D3D9VERTEX[m_PrimCount * 3 * 4];
- SetVertexArray(m_pVertices, m_PrimCount * 3, { 0.0f, 0.0f, 0.0f, 1.0f, 0 });
- CreatePrimitive2D(m_X - m_Width / 2 + m_Rounding, m_Y - m_Height / 2, m_X + m_Width / 2 - m_Rounding, m_Y - m_Height / 2, m_X - m_Width / 2, m_Y - m_Height / 2 + m_Rounding, m_Colour, &(m_pVertices[0]));
- CreatePrimitive2D(m_X + m_Width / 2, m_Y - m_Height / 2 + m_Rounding, m_X + m_Width / 2 - m_Rounding, m_Y - m_Height / 2, m_X - m_Width / 2, m_Y - m_Height / 2 + m_Rounding, m_Colour, &(m_pVertices[3]));
- CreatePrimitive2D(m_X + m_Width / 2, m_Y - m_Height / 2 + m_Rounding, m_X - m_Width / 2, m_Y + m_Height / 2 - m_Rounding, m_X - m_Width / 2, m_Y - m_Height / 2 + m_Rounding, m_Colour, &(m_pVertices[6]));
- CreatePrimitive2D(m_X + m_Width / 2, m_Y - m_Height / 2 + m_Rounding, m_X - m_Width / 2, m_Y + m_Height / 2 - m_Rounding, m_X + m_Width / 2, m_Y + m_Height / 2 - m_Rounding, m_Colour, &(m_pVertices[9]));
- CreatePrimitive2D(m_X - m_Width / 2 + m_Rounding, m_Y + m_Height / 2, m_X - m_Width / 2, m_Y + m_Height / 2 - m_Rounding, m_X + m_Width / 2, m_Y + m_Height / 2 - m_Rounding, m_Colour, &(m_pVertices[12]));
- CreatePrimitive2D(m_X - m_Width / 2 + m_Rounding, m_Y + m_Height / 2, m_X + m_Width / 2 - m_Rounding, m_Y + m_Height / 2, m_X + m_Width / 2, m_Y + m_Height / 2 - m_Rounding, m_Colour, &(m_pVertices[15]));
- for (UINT i = 18; i != (m_PrimCount * 3); StartPoint.X += Step, StartPoint.Y += Step)
- {
- if (i != 18)
- {
- CurrAlpha += Alpha;
- CreatePrimitive2D(
- StartPoint.X, StartPoint.Y,
- StartPoint.X + Step, StartPoint.Y + Step,
- Center.X + m_Rounding * sin(CurrAlpha), Center.Y - m_Rounding * cos(CurrAlpha),
- 0xFF00FF00, //m_Colour
- &(m_pVertices[i + 3]));
- CreatePrimitive2D(
- m_X - (m_pVertices[i + 3].X - m_X), m_pVertices[i + 3].Y,
- m_X - (m_pVertices[i + 4].X - m_X), m_pVertices[i + 4].Y,
- m_X - (m_pVertices[i + 5].X - m_X), m_pVertices[i + 5].Y,
- 0xFF00FF00, //m_Colour
- &(m_pVertices[i + 3 + (m_PrimCount * 3 - 18) * 1]));
- CreatePrimitive2D(
- m_pVertices[i + 3].X, m_Y + (m_Y - m_pVertices[i + 3].Y),
- m_pVertices[i + 4].X, m_Y + (m_Y - m_pVertices[i + 4].Y),
- m_pVertices[i + 5].X, m_Y + (m_Y - m_pVertices[i + 5].Y),
- 0xFF00FF00, //m_Colour
- &(m_pVertices[i + 3 + (m_PrimCount * 3 - 18) * 2]));
- CreatePrimitive2D(
- m_X - (m_pVertices[i + 3].X - m_X), m_Y + (m_Y - m_pVertices[i + 3].Y),
- m_X - (m_pVertices[i + 4].X - m_X), m_Y + (m_Y - m_pVertices[i + 4].Y),
- m_X - (m_pVertices[i + 5].X - m_X), m_Y + (m_Y - m_pVertices[i + 5].Y),
- 0xFF00FF00, //m_Colour
- &(m_pVertices[i + 3 + (m_PrimCount * 3 - 18) * 3]));
- CreatePrimitive2D(
- m_pVertices[i + 3].X, m_pVertices[i + 3].Y,
- m_pVertices[i + 5].X, m_pVertices[i + 5].Y,
- m_pVertices[i - 1].X, m_pVertices[i - 1].Y,
- 0xFF0000FF, //m_Colour
- &(m_pVertices[i]));
- CreatePrimitive2D(
- m_X - (m_pVertices[i + 0].X - m_X), m_pVertices[i + 0].Y,
- m_X - (m_pVertices[i + 1].X - m_X), m_pVertices[i + 1].Y,
- m_X - (m_pVertices[i + 2].X - m_X), m_pVertices[i + 2].Y,
- 0xFF0000FF, //m_Colour
- &(m_pVertices[i + (m_PrimCount * 3 - 18) * 1]));
- CreatePrimitive2D(
- m_pVertices[i + 0].X, m_Y + (m_Y - m_pVertices[i + 0].Y),
- m_pVertices[i + 1].X, m_Y + (m_Y - m_pVertices[i + 1].Y),
- m_pVertices[i + 2].X, m_Y + (m_Y - m_pVertices[i + 2].Y),
- 0xFF0000FF, //m_Colour
- &(m_pVertices[i + (m_PrimCount * 3 - 18) * 2]));
- CreatePrimitive2D(
- m_X - (m_pVertices[i + 0].X - m_X), m_Y + (m_Y - m_pVertices[i + 0].Y),
- m_X - (m_pVertices[i + 1].X - m_X), m_Y + (m_Y - m_pVertices[i + 1].Y),
- m_X - (m_pVertices[i + 2].X - m_X), m_Y + (m_Y - m_pVertices[i + 2].Y),
- 0xFF0000FF, //m_Colour
- &(m_pVertices[i + (m_PrimCount * 3 - 18) * 3]));
- i += 6;
- }
- else
- {
- CreatePrimitive2D(
- StartPoint.X, StartPoint.Y,
- StartPoint.X + Step, StartPoint.Y + Step,
- Center.X + m_Rounding * sin(CurrAlpha), Center.Y - m_Rounding * cos(CurrAlpha),
- 0xFF00FF00, //m_Colour
- &(m_pVertices[i]));
- CreatePrimitive2D(
- m_X - (m_pVertices[i + 0].X - m_X), m_pVertices[i + 0].Y,
- m_X - (m_pVertices[i + 1].X - m_X), m_pVertices[i + 1].Y,
- m_X - (m_pVertices[i + 2].X - m_X), m_pVertices[i + 2].Y,
- 0xFF00FF00, //m_Colour
- &(m_pVertices[i + (m_PrimCount * 3 - 18) * 1]));
- CreatePrimitive2D(
- m_pVertices[i + 0].X, m_Y + (m_Y - m_pVertices[i + 0].Y),
- m_pVertices[i + 1].X, m_Y + (m_Y - m_pVertices[i + 1].Y),
- m_pVertices[i + 2].X, m_Y + (m_Y - m_pVertices[i + 2].Y),
- 0xFF00FF00, //m_Colour
- &(m_pVertices[i + (m_PrimCount * 3 - 18) * 2]));
- CreatePrimitive2D(
- m_X - (m_pVertices[i + 0].X - m_X), m_Y + (m_Y - m_pVertices[i + 0].Y),
- m_X - (m_pVertices[i + 1].X - m_X), m_Y + (m_Y - m_pVertices[i + 1].Y),
- m_X - (m_pVertices[i + 2].X - m_X), m_Y + (m_Y - m_pVertices[i + 2].Y),
- 0xFF00FF00, //m_Colour
- &(m_pVertices[i + (m_PrimCount * 3 - 18) * 3]));
- i += 3;
- }
- }
- }
- void Draw(IDirect3DDevice9* pDevice)
- {
- pDevice->DrawPrimitiveUP(D3DPT_TRIANGLELIST, m_PrimCount + (m_PrimCount - 6) * 3, m_pVertices, sizeof(D3D9VERTEX));
- }
- private:
- UINT m_X;
- UINT m_Y;
- UINT m_Width;
- UINT m_Height;
- DWORD m_Colour;
- UINT m_Rounding;
- UINT m_PrimCount;
- UINT m_Precision;
- DOUBLE m_Pi;
- D3D9VERTEX* m_pVertices;
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement