Advertisement
Guest User

Untitled

a guest
Mar 30th, 2017
388
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.48 KB | None | 0 0
  1. class BaseWindow;
  2.  
  3. class Button
  4. {
  5. public:
  6. Button(BaseWindow* parent)
  7. {
  8. parent->AddButton(this);
  9. }
  10.  
  11. void SetBehavior(/*Owners pointer and owner's methos*/)
  12. {
  13. /* Save Owner pointer and owner's method*/
  14. }
  15.  
  16. void Clicked(/*coords*/)
  17. {
  18. if(/*coords == my coords*/)
  19. {
  20. /*Call Owner's method*/
  21. }
  22. }
  23. };
  24.  
  25. class BaseWindow
  26. {
  27. vector<Button*> Buttons;
  28.  
  29. WindowClicked(/*coords*/)
  30. {
  31. for (std::vector<Button*>::iterator it = Buttons.begin(); it != Buttons.end(); ++it)
  32. {
  33. it->Clicked(/*coords*/);
  34. }
  35. }
  36.  
  37. public:
  38. void AddButton(Button* butt)
  39. {
  40. Buttons<<butt;
  41. }
  42.  
  43. };
  44.  
  45. class UserWindow:public BaseWindow
  46. {
  47. Button MyButton;
  48. public:
  49. void FunctionForButton(Button* butt){ cout<<"Say Hello, my sweet button";}
  50.  
  51. UserWindow():MyButton(this)
  52. {
  53. MyButton.SetBehavior(/*Put here my Function for Button and my pointer*/);
  54. }
  55. };
  56.  
  57. typedef void (BaseWindow::*TBehavior)(Button *);
  58.  
  59. (parent->*behavior)(this);
  60.  
  61. MyButton.SetBehavior(static_cast<TBehavior>(&UserWindow::FunctionForButton));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement