Windows like controls in DirectDraw

Started by
5 comments, last by gimp 23 years, 11 months ago
I know it wouldn''t be too hard to do myself but I was wondering if anyone knows of some source that provides some basic windows controls in directx. Some things I''d like to use are checkboxes, listboxes, sliders, dropdowns, spin buttons... etc. Yeah I know what your thinking, draw a bitmap remember the area and check for mouse clicks... Just wondering if I can save myself some time in the menu department and get back to the network stack... gimp
Chris Brodie
Advertisement
You should read the "Developing a GUI using C++ and DirectX" articles in the programming section of GameDev.net, I think that it has links to the source code.
---Ranok---
I''ve made a really simple setup for buttons, boxes, etc. I''ll post the code, tell me if you need more help figuring it out.

========================================================
#define NOT_ACTIVE 0
#define ACTIVE 1

typedef class tagControl
{
int State;
void Draw(void);
public:
LPDIRECTDRAWSURFACE4 ControlSurface[2];
RECT ControlDestination;
BITMAP_FILE ControlBitmap[2];

void Init(char *NonActiveBitmap, char *ActiveBitmap, int x, int y);
int IsActivated( int(*Test)(void *ptr), void(*Active)(void), void(*Inactive)(void) );
~tagControl();

}Control, *Control_Ptr;

void Control::Init(char *NonActiveBitmap, char *ActiveBitmap, int x, int y)
{
State = NOT_ACTIVE;

ControlDestination.left = x;
ControlDestination.top = y;


Load_Bitmap_File(&ControlBitmap[0], NonActiveBitmap);
ControlSurface[0] = CreateOffScreen(ControlBitmap[0].bitmapinfoheader.biWidth, ControlBitmap[0].bitmapinfoheader.biHeight);
CopyBitmap(&ControlBitmap[0], ControlSurface[0]);
ControlDestination.right = ControlDestination.left + ControlBitmap[0].bitmapinfoheader.biWidth;
ControlDestination.bottom = ControlDestination.top + ControlBitmap[0].bitmapinfoheader.biHeight;
Unload_Bitmap_File(&ControlBitmap[0]);

Load_Bitmap_File(&ControlBitmap[1], ActiveBitmap);
ControlSurface[1] = CreateOffScreen(ControlBitmap[1].bitmapinfoheader.biWidth, ControlBitmap[1].bitmapinfoheader.biHeight);
CopyBitmap(&ControlBitmap[1], ControlSurface[1]);
Unload_Bitmap_File(&ControlBitmap[1]);
}

void Control::Draw(void)
{
lpddsback->Blt(&ControlDestination, ControlSurface[State], NULL, DDBLT_WAIT, NULL);
}

int Control::IsActivated( int(*Test)(void *ptr), void(*Active)(void), void(*Inactive)(void) ) // Returns TRUE (1) if condition is satisfied, use in if-then
{
if( Test(this) )// call Test() in the If
{
State = ACTIVE;
Active(); //ptr to active
Draw();
return 1;
}
else
{
State = NOT_ACTIVE;
Inactive(); // ptr to not active
Draw();
return 0;
}

return 0;

}


Control::~tagControl()
{
ControlSurface[0]->Release();
ControlSurface[1]->Release();
}
========================================================
As the TEST function i use this to check for clicks:

int ClickTest(void *ptr)
{
Control_Ptr Ptr = (Control_Ptr)ptr;
if(Clicked(&Ptr->ControlDestination))
return 1;
else
return 0;
}

Whereas Clicked() is:

int Clicked(LPRECT pos)
{
if(mousestate.rgbButtons[0] & 0x80 && mouse_x > pos->left && mouse_x < pos->right && mouse_y > pos->top && mouse_y < pos->bottom)
return 1;
else
return 0;
}

=========================================================

It works even if it is slow. It won''t work on it''s own, i use globals for the DDraw objects and stuff, but feel free to modify it.

---------------------------------------------------------

"The Gates of Pearl have turned to gold, it seems you've lost your way."
"The Gates of Pearl have turned to gold, it seems you've lost your way."
Ahhh.... So you would use an ... array? of objects derived from your classes, enumerate each object and ask it if the click was in it''s area.

cool...

thanks for the source...
Chris Brodie
Just one thing. Whats the point of typdefing a class?
-----------------------------A wise man once said "A person with half a clue is more dangerous than a person with or without one."The Micro$haft BSOD T-Shirt
Normally there is no reason to typedef a class, but in this case he is also defining a pointer type. That could be done on a separate line, but it has the same effect.
What is that "BITMAP_FILE" ?

This topic is closed to new replies.

Advertisement