Posted By

NicolaSomers on 11/30/13


Tagged

functions button


Versions (?)

Function Make Button


 / Published in: C++
 

Applied in the Game files written by Kevin Hoefman for students DAE Declaration of a function, where to call it and how to implement it in the GAME ENGINE

  1. //in .h, make your function:
  2.  
  3. // -------------------------
  4. // Member functions
  5. // -------------------------
  6. Button* CreateButton(String text, int posX, int posY, int width, int height, bool show, bool action, bool enabled);
  7.  
  8.  
  9. //in .cpp :
  10.  
  11. //all the way down, under CallAction
  12. //insert:
  13.  
  14. Button* <NAME OF YOUR PROJECT>::CreateButton(String text, int posX, int posY, int width, int height, bool show, bool action, bool enabled)
  15. {
  16. Button* temp = new Button(text); //making a temporary button
  17. temp->SetBounds(posX, posY, width, height); //set bounds
  18. if(action) temp->AddActionListener(this); //if true add ActionListener
  19. if(show) temp->Show(); //if true show
  20. if(enabled) temp->SetEnabled(true); //if true enabled, otherwise disable
  21. else temp->SetEnabled(false);
  22.  
  23. return temp; //return temporary button to save it before destruction
  24. }
  25.  
  26.  
  27. //making a button with the function
  28. //first, in the .h, make a member pointer to save the temporary button in
  29.  
  30.  
  31.  
  32. // -------------------------
  33. // Datamembers
  34. // -------------------------
  35.  
  36. Button *m_BtnMyButtonPtr;
  37.  
  38.  
  39.  
  40. //next step: initialize the button in .cpp as nullptr. do this before the curly brackets {}
  41.  
  42. <NAME OF YOUR PROJECT>::<NAME OF YOUR PROJECT>():m_BtnMyButtonPtr(nullptr)
  43.  
  44.  
  45.  
  46. //calling the function you made to make a button IN the GameStart, and using your datamember to save your temporary button in before destroying it.
  47. //This will enable you to interact with the button when debugged, even after your temporary button was destroyed
  48.  
  49. //general form:
  50. //<pointer where you want to save your temporary button to make it permanent> = <name of your function>(<the arguments that are required>);
  51.  
  52. m_BtnMyButtonPtr = CreateButton("This is my button",10,10,200,30,true,true,true);
  53.  
  54.  
  55.  
  56. //don't forget to delete your button IN the GameEnd
  57.  
  58. delete m_BtnMyButtonPtr;
  59. m_BtnMyButtonPtr = nullptr;

Report this snippet  

You need to login to post a comment.