Archived

This topic is now archived and is closed to further replies.

pointguard1

GUI Using DirectDraw and DirectInput

Recommended Posts

Anyone have any suggestions on how to implement a GUI using a class and a linked list? I did read the GUI Programming article in the For Beginners sections but I''m still kinda lacking on the advanced aspects of C++ so the code he wrote was hard for me to follow.

Share this post


Link to post
Share on other sites
Here''s my code so far. Tell me how it looks

//gui.h Graphic User Interface header for use in multiple programs
//


#define MAX_WINDOWS 8


#define BUTTON 456
#define T_BOX 564
#define S_TEXT 645
#define L_BOX 654
#define KBMWINDOW 546



//main object (flexible for different types)

class KBM_WINDOW_OBJECT
{

public:




int type; //object type (i.e. text box, button, etc.)

char text[32]; //button text
int x, y, length, height; //location within window and dimentions (if window type absolute screen coords)

UCHAR color; //object color

bool toggle_cursor; //text box cursor on/off
int cursor_location; //cursor location in character spaces (for T_BOX only)
bool visible; //visible flag

KBM_WINDOW_OBJECT* parent; //ptr to parent window
KBM_WINDOW_OBJECT* child[MAX_WINDOWS]; //array of ptrs to child windows

SCREEN* screen_used; //screen to link with
KBMFILE file_used; //file to link with

HWND hWnd; //window to link with

public:

void Draw (void)
{

if (visible == FALSE)
return;

RECT box2; //rectangle to draw borders
RECT corner[4]; //rectangle to draw corners for resizing


//for windows don''t add extra length, etc.
if (type == KBMWINDOW)
{
//set main coords and dims
box2.top = y;
box2.bottom = y + height;
box2.left = x;
box2.right = x + length;

//set corners
corner[0].top = y; //top left corner
corner[0].bottom = y + 5;
corner[0].left = x;
corner[0].right = x + 5;

corner[1].top = y; //top right corner
corner[1].bottom = y + 5;
corner[1].left = y + length - 5;
corner[1].right = y + length;

corner[2].top = y + height - 5; //bottom left
corner[2].bottom = y + height;
corner[2].left = x;
corner[2].right = x + 5;

corner[3].top = y + height - 5; //bottom right
corner[3].bottom = y + height;
corner[3].left = y + length - 5;
corner[3].right = y + length;

}
else
{
box2.top = (parent->y + y); //window location + location within window
box2.bottom = (parent->y + y + height);
box2.left = (parent->x + x);
box2.right = (parent->x + x + length);
}


switch (type)
{

case BUTTON:
Rect(screen_used, box2, color, color, TRUE);
PrintString(text, screen_used, box2.left + 2, box2.top + 2, color);
break;

case T_BOX:
Rect(screen_used, box2, color, color, TRUE);
if (toggle_cursor)
VLine8(screen_used, box2.top + 2, box2.bottom - 2, box2.left + 2, WHITE);
break;

case S_TEXT:
PrintString(text, screen_used, box2.left, box2.top, color);
break;

case L_BOX:
Rect(screen_used, box2, color, color, TRUE);
//text here
break;

case KBMWINDOW:
//Draw border
Rect(screen_used, box2, color, color, FALSE);

//Draw resizers
for (char ctr; ctr < 4; ctr++)
{
Rect(screen_used, corner[ctr], GRAY, GRAY, TRUE);
}
break;




default:
break;

}


//draw children
/*if (child)
{

for (int ctr = 0; ctr < MAX_WINDOWS; ctr++)
{
child[ctr]->Draw();
}

}*/
//end draw children


}
//*************End Draw****************************************************************


//////////////////////////////////////////////////////////////////////////////////////
//Init - takes file and loads all info into KBM_WINDOW_OBJECT members/////////////////
bool Init (HWND hWnd2b, char* guifile, SCREEN* screen2linkwith)
{

screen_used = screen2linkwith;

hWnd = hWnd2b;


file_used.Init(hWnd, guifile);
if (file_used.Open() != TRUE)
return FALSE;

//file_used.ReadInt();


return TRUE;


}
//End Init////////////////////////////////////////////////////////////////////////////



void ToggleCursor (void)
{
if (toggle_cursor == TRUE)
toggle_cursor = FALSE;
else
toggle_cursor = TRUE;
}

void SetType (int type2b)
{
type = type2b;
}


void SetColor (UCHAR col)
{
color = col;
}

void SetXY (int x1, int y1)
{
x = x1;
y = y1;
}

void SetText (char *text2put)
{
strcpy(text, text2put);
}

void SetDims (int h, int l)
{
length = l;
height = h;
}

void ToggleVisibility (void)
{
if (visible == TRUE)
visible = FALSE;
else
visible = TRUE;
}



////////////////////////////

KBM_WINDOW_OBJECT()
{


}


~KBM_WINDOW_OBJECT()
{



}




};

Share this post


Link to post
Share on other sites