Hehe I’m having hard time on choosing the question title. But let me explain about my problem to make it clearer.
I’m now writing my own GUI library for my game in C++ with a DirectX wrapper out there.
But I got no idea on how to render my in-game windows by just calling the “manager” class’s draw function.
For example, say I have a “manager” and “window” class already.
the manager:
class MyGUIManager
{
private:
std::vector<MyGUIWindow> WindowCollector;
public:
MyGUIManager()
{
}
virtual MyGUIWindow *NewWindow(char *szWindowTitle)
{
MyGUIWindow *temp = new MyGUIWindow();
temp->SetWindowTitle(szWindowTitle);
return temp;
}
void RegisterWindow(MyGUIWindow targetWindow) // hopely this
{
this->WindowCollector.push_back(targetWindow);
}
void Draw()
{
// I wanted this function to be able to call all MyGUIWindow instances' Draw() function
// can it be helped like this?
for(int i = 0; i < this->WindowCollector.size(); i++)
this->WindowCollector.at(i)->Draw(); // but the vector members must be referenced to each window instance..
}
};
the window:
class MyGUIWindow
{
public:
MyGUIWindow()
{
this->SetWindowTitle("New Window");
}
void SetWindowTitle(char *szWindowTitle);
void Draw();
};
and the main program:
//...
MyGUIManager *GUIMAN = new MyGUIManager();
MyGUIWindow *FirstWindow = GUIMAN->NewWindow("Hello World");
MyGUIWindow *SecondWindow = GUIMAN->NewWindow("Hello World!!!");
GUIMAN->RegisterWindow(FirstWindow); // ??
GUIMAN->RegisterWindow(SecondWindow);
while(Drawing())
{
GUIMAN->Draw(); // I wanted this function to be able to call ALL MyGUIWindow instances' Draw() function
//...
}
so the main question is, how to make all of MyGUIWindow variables can be controlled through WindowCollector vector?
Yes basically that will work, why don’t you just try it out? But I would prefer using iterators instead of your loop, and also some kind of auto-pointer instead of just
new(current example will probably cause a memory leak).Actually, begin by Googling
std::vector… And passing arguments as references.