from what i understand
there are inharit functions in C++
i dont fully understand it thats why im asking for a bit of help.
for an example i will use the common "List" idea or Resource Manager
(never built one just rad about them).
so im building a simple GUI , where there is a Drop Down Menu Bar
the menu bar has like 3 buttons (File,Options,Help)
File opens -> New,Save,Load,Exit
Options opens -> Render Options,Texture Options,Light Options
Help opens -> Tutorials,Web Link,Credits
this is just an example.
so , for now what i do is
this is the Button.H eader file
#ifndef BUTTON_H
#define BUTTON_H
class Button
{
private:
// Geo
int btnX,btnY; // Positions
int btnWidth,btnHeight; // Width and Height
float btnAngle; // Angle
char *btnAct; // action or name
int btnImg; // Image
int btnSprite ;// DarkGDK sprite Pointer / ID
char *btnHefct; // Hover Effect
char *btnCefct; // Click Effect
bool hoverOn ; // Hover State
bool clickOn ; // Click State
bool btnHide; // Hide State
public:
Button();
// Create new Button
virtual void NewButton(char *ButtonAction,int SpriteID,int ButtonWidth,int ButtonHeight,int ButtonX,int ButtonY,int ButtonImage);
// Set Button Options
void SetButtonEffect(char *ButtonHoverEffect,char *ButtonClickEffect);
void SetButtonPosition(int ButtonX,int ButtonY);
void SetButtonImage(int ButtonImage);
void SetButtonAngle(int ButtonAngle);
// Check Button State
bool ButtonActivated()
{
return 0;
}
bool ButtonHoverState(int MouseX,int MouseY); // can easily renamed to "is Mouse X,Y on the button?
bool ButtonClickState(); // can easily renamed to "is Button Clicked?
bool ButtonIsHidden(){return btnHide;} // returns btnHidden State
// Visual and Effects
void Hide();
void Show();
//Get
int GetX(){return btnX;}
int GetY(){return btnY;}
int GetImage(){return btnImg;}
int GetSprite(){return btnSprite;}
// Update overall Button.
void UpdateButton();
};
#endif
ofcourse no need to point at the Button.Cpp file as most of you can understand or imagine what is written there as you have probably mastered it already
and i my code : Main.CPP
Button Setup.
// Setting up the Actions nd Names
char *FileAction[5] = {"File,New,Save,Load,Exit"};
char *OptionsAction[5] = {"Options,Render,Textures,Lights"};
char *Help[4] = {"Help,Tutorials,Web Link,Credits"};
// File Menu
Button File[5];
for (int i = 0;i < 5;i++)
{
File[i].NewButton(FileAction[i],GetFreeSprite(),Bwidth,Bheight,0,i * Bheight+ space * i,GetFreeImage()); // Creating a New Button or the Actual Button Setup
dbSprite(File[i].GetSprite()/*recently added look up*/,File[i].GetX(),File[i].GetY(),File[i].GetImage()); // Creating the Sprite Attached to that Button
if (i > 0) // 0 i = MenuBar Button or the "File" button , this one is shown all the drop downs are hidden
File[i].Hide();
}
// Options Menu <> Same as File just with , Button Options[5]
// Help Menu <> Same as File or Options just with , Button Help[4]
updating Sprites, as Button dont really hide the sprites just contains a Boolean if the button is hidden or not
// Menu Bar First Update! //
for (int i=1;i < 10;i++)
{
if (File[i].ButtonIsHidden() && i < 5/*number representing the max buttons inside of File section */)
dbHideSprite(File[i].GetSprite());
}
main loop
while ( LoopGDK ( ) )
{
if (dbMouseClick() == 1)
{
if (ActionTimer(dbTimer(),TimeSaved,delay))
{
//Checking File Bar
if (File[0].ButtonHoverState(dbMouseX(),dbMouseY()))
{
if (File[1].ButtonIsHidden())
for (int i=1;i<10;i++)
{
File[i].Show();
}
else
for (int i=1;i<10;i++)
{
File[i].Hide();
}
}
//Checking Options Bar
//Checking Help Bar
TimeSaved = dbTimer();
}
}
// Yeah i know i shouldnot check this each cycle and it should atleast have one Boolean op if a mouse button have been clicked or something
for (int i = 1;i<10;i++)
{
if (File[i].ButtonIsHidden())
dbHideSprite(File[i].GetSprite());
else
dbShowSprite(File[i].GetSprite());
}
// update the screen
dbSync ( );
}
so i guess some of you may have seen the problem.
if i want to check on all the MenuBar Top Menus
i will have to check with File[i] and then with Options[i] and then with Help[i]
so its a bit of a mass of code not really needed , altough it will work good , it will just contain alot of code that i know there is a better way to do that with inharit but i dont know how
i appreciate any help i can get.
TY
nadav.