benjamin17801
Programmer
I'm posting this message to try to get some help an pointers about programming. I'm new to c++ and object oriented programming. The code I posted is an idea i'm working on for a directx driven gui. I'm using an article on GameDev.net by Mason McCuskey. Any comments anything at all that is constuctive would be nice. Thank you and it is appreciated. Here is the little bit of code I have so far:
this is the header file:
class Xg_Window
{
int TopLeft_X; // 0 - 9600 virtual window coords for location
int TopLeft_Y; // 0 - 7200 " "
int SizeOf_X; // Width in virtual windows coords
int SizeOf_Y; // Heighth " "
int BkgColor; // Back ground color of window
int BrdColor; // Border color of window
int Opacity; // 0 - 100 value to indicate the opacity of the window
// Private Xg_Window management code
// Called in the constructer
void Add_Window(); // A pointer to a Xg_Window Object to be added to a collection at the top
public:
Xg_Window( int, int, int, int, int, int, int ); // Sets the initial attributes for the Xg_window object
~Xg_Window(); // Destroys the object
// Top physical attributes
void New_Location( int, int ); // Sets new TopLeft_X and the TopLeft_Y fields
void New_Size( int, int ); // Sets new SizeOf_X and the SizeOf_Y fields
void New_Color( int, int, int ); // Sets new BkgColor, BrdColor, Opacity fields
// public Xg_Windows management code
static void Delete_Window(Xg_Window *w); // A pointer to a Xg_Window Object to be deleted from the container
static void BringTo_Top( Xg_Window *w ); // Brings The Xg_Window Object that is pointed to, to the top
};
and the .cpp file
#include <stdafx.h>
#include <Gui.h>
#include <vector>
#include <algorithm>
using namespace std;
vector<Xg_Window*> vi;
vector<Xg_Window*>::iterator i;
// Constructer and Destructer for the Xg_Window object
// constucter sets the initial size location and color attribute
Xg_Window::Xg_Window(int TL_X, int TL_Y, int SO_X, int SO_Y, int BKG_C, int BRD_C, int OP)
{
TopLeft_X = TL_X;
TopLeft_Y = TL_Y;
SizeOf_X = SO_X;
SizeOf_Y = SO_Y;
BkgColor = BKG_C;
BrdColor = BRD_C;
Opacity = OP;
Add_Window();
}
Xg_Window::~Xg_Window()
{
}
// Windows physical attributes, these member functions of class Xg_Window
// set the new private data fields for the class
void Xg_Window::New_Location(int LX, int LY) // Sets the top left x and y of the windows location
{
TopLeft_X = LX;
TopLeft_Y = LY;
}
void Xg_Window::New_Size(int SX, int SY) // Sets the size of the window
{
SizeOf_X = SX;
SizeOf_Y = SY;
}
void Xg_Window::New_Color(int BK, int BD, int OP) // Sets the background and border color for the window and the transparency
{
BkgColor = BK;
BrdColor = BD;
Opacity = OP;
}
// Windows Management code Add_Window is a private members of Xg_Window called upon construction
// and destruction of Xg_window object
void Xg_Window::Add_Window()
{
vi.push_back(this); // Push a pointer to this window into the collection vi
}
void Xg_Window:elete_Window(Xg_Window *w)
{
i = find(vi.begin(), vi.end(), w); // Check to see where the poniter to the Xg_Window object is in the vector
vi.erase(i); // then deletes it
delete w;
}
void Xg_Window::BringTo_Top(Xg_Window *w)
{
Xg_Window *p = w; // copies the object
i = find(vi.begin(), vi.end(), w); // finds the object in the vector
vi.erase(i); // deletes the object from its position
vi.push_back(p); // pushes the copy back on the bottom( which is the top for me )
}