PDA

View Full Version : [Source] Buttonz with Rounded Edges



Gellin
04-23-2008, 03:59 AM
I was bored and i wanted to make some buttons that had rounded edges so here goes.
i probably over did the entire thing and could've done it 1000 times easier but i don't know how :(



void DrawRoundedButtonz(IDirect3DDevice8* dev, int x, int y, int w, int h, DWORD color)
{
DrawRect(dev, x, y , w, 1, color);
DrawRect(dev, x - 6, y + 6, 1, h - 13, color);
DrawRect(dev, x - 2, y + 1 , 2, 1, color);
DrawRect(dev, x - 3, y + 2 , 1, 1, color);
DrawRect(dev, x - 4, y + 3 , 1, 1, color);
DrawRect(dev, x - 5, y + 4 , 1, 1, color);
DrawRect(dev, x - 5, y + 5 , 1, 1, color);
DrawRect(dev, x, y + h, w, 1, color);
DrawRect(dev, x + w + 5, y + h + - 13, 1, 5, color);
DrawRect(dev, x + w, y + 1, 2, 1, color);
DrawRect(dev, x + w + 2, y + 2, 1, 1, color);
DrawRect(dev, x + w + 3, y + 3, 1, 1, color);
DrawRect(dev, x + w + 4, y + 4, 1, 2, color);
DrawRect(dev, x - 2, y + 18, 2, 1, color);
DrawRect(dev, x - 3, y + 17, 1, 1, color);
DrawRect(dev, x - 4, y + 16, 1, 1, color);
DrawRect(dev, x - 5, y + 14, 1, 2, color);
DrawRect(dev, x - 6, y + 12, 1, 2, color);
DrawRect(dev, x + w, y + 18, 2, 1, color);
DrawRect(dev, x + w + 2, y + 17, 1, 1, color);
DrawRect(dev, x + w + 3, y + 16, 1, 1, color);
DrawRect(dev, x + w + 4, y + 14, 1, 2, color);
DrawRect(dev, x + w + 5, y + 11, 1, 3, color);
}

To Draw

DrawRoundedButtonz(m_pD3Ddev, 500, 400, 68, 19, D3DCOLOR_ARGB( 255, 0, 255, 0));

Please do not change the size unless u are going to edit everything else....

The Result is: http://img99.imageshack.us/img99/8490/roundedbuttonzkj5.jpg
http://img99.imageshack.us/img99/8490/roundedbuttonzkj5.jpg

Credits :
who ever made the draw rect
Cobra
Massacre
Ghouster
Kriss
Konvict - one of meh hero's
Micro - my papa
-CD- He is Mr SEE DEE
Ms Paint - " used to count pixels"

i might start a D3D tut of the week or something getting more advanced every week :p

purple
04-23-2008, 07:30 AM
would be great if u can tell us how i can load a texture (like a button ;-) from a file and put this on the screen... id like to make a gui for my hack!

Gellin
04-23-2008, 08:07 AM
you can use this for a gui but i can tell you i guess. later tonight look for a post.

purple
04-23-2008, 08:15 AM
ty. i think its really hot if u have a godlike designed gui for h4ck1ng warrck ;-)

Chris
04-24-2008, 12:55 AM
dude u gave me credits <33
and nice

purple
04-29-2008, 10:06 AM
just wanted to remember u making a tut ;-)

man2fight
05-06-2008, 09:20 AM
how do u declare Drawrect

seth26jan
05-06-2008, 05:30 PM
This is sweet! Thanks, I needed this.

masterboy
05-07-2008, 12:39 PM
how do u declare Drawrect

like this...
#define DrawRect

-TiM-
05-07-2008, 05:39 PM
Nice job, thanks for releasing, it might be better/smaller/faster? If you decrease the rounded edge to a little smaller, but this is still good.

purple
05-08-2008, 07:16 AM
DrawRect: (credits to the one who wrote this, i think freddy)

////////////////////////////////////////////////////////////////////
#define SAFE_RELEASE( res ) if( res ) { (res)->Release( ); (res) = NULL; }

/************************************************/
/* Variables */

typedef struct
{
float x;
float y;
float z;
float rhw;
DWORD Color;
} VERTEX2;
////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////
/************************************************/
/* DrawLine */

HRESULT DrawLine( IDirect3DDevice8 *pDevice, int x1, int y1, int x2, int y2, int Width, DWORD Color )
{
if( !pDevice )
return E_FAIL;

// Set a single device render-state (D3DRS_***ABLE) to FALSE.
pDevice->SetRenderState( D3DRS_***ABLE, FALSE );
// Set a single device render-state (D3DRS_CULLMODE) to D3DCULL_NONE.
pDevice->SetRenderState( D3DRS_CULLMODE, D3DCULL_NONE );
// Set a single device render-state (D3DRS_LIGHTING) to FALSE.
pDevice->SetRenderState( D3DRS_LIGHTING, FALSE );

IDirect3DVertexBuffer8 *pVertexBuffer = NULL;

// Create a vertex buffer.
if( pDevice->CreateVertexBuffer( (sizeof( VERTEX2 ) * 2), D3DUSAGE_WRITEONLY|D3DUSAGE_DYNAMIC, D3DFVF_XYZRHW|D3DFVF_DIFFUSE, D3DPOOL_DEFAULT, &pVertexBuffer ) < 0 )
return E_FAIL; // The vertex buffer was not created (the line was not drawn).

int LineWidth = (Width < 1 ? 1 : Width);

PBYTE pVertexData = NULL;

// Lock a range of vertex data and obtains a pointer to the vertex buffer memory (pVertexData).
if( pVertexBuffer->Lock( 0, 0, &pVertexData, D3DLOCK_NOSYSLOCK|D3DLOCK_DISCARD ) == D3DERR_INVALIDCALL )
SAFE_RELEASE( pVertexBuffer ); // Release the vertex buffer.

VERTEX2 Vertex[2];
Vertex[0].Color = Color;Vertex[1].Color = Color;
Vertex[0].rhw = 0; Vertex[1].rhw = 0;
Vertex[0].x = x1; Vertex[1].x = x2;
Vertex[0].y = y1; Vertex[1].y = y2;
Vertex[0].z = 0; Vertex[1].z = 0;

memcpy( pVertexData, Vertex, (sizeof( VERTEX2 ) * 2) );

// Unlock vertex data (pVertexData).
pVertexBuffer->Unlock( );

pVertexData = NULL;

// Binds a vertex buffer (pVertexBuffer) to a device data stream.
pDevice->SetStreamSource( 0, pVertexBuffer, sizeof( VERTEX2 ) );

// Set the current vertex shader to a flexible vertex format fixed function shader.
pDevice->SetVertexShader( D3DFVF_XYZRHW|D3DFVF_DIFFUSE );

// Renders a sequence of nonindexed, geometric primitives of the specified type (D3DPT_LINELIST) from the current set of data input streams.
pDevice->DrawPrimitive( D3DPT_LINELIST, 0, 1 );

// Release the vertex buffer.
SAFE_RELEASE( pVertexBuffer );

return S_OK; // The vertex shader was created (the line was drawn).
}
///////////////////////////////////////////////////////////////////////////