DialogBox.cpp 910 B

1234567891011121314151617181920212223242526272829303132333435
  1. // ----------------------------------------------------------------
  2. // From Game Programming in C++ by Sanjay Madhav
  3. // Copyright (C) 2017 Sanjay Madhav. All rights reserved.
  4. //
  5. // Released under the BSD License
  6. // See LICENSE in root directory for full details.
  7. // ----------------------------------------------------------------
  8. #include "DialogBox.h"
  9. #include "Game.h"
  10. #include "Renderer.h"
  11. #include <SDL/SDL.h>
  12. DialogBox::DialogBox(Game* game, const std::string& text,
  13. std::function<void()> onOK)
  14. :UIScreen(game)
  15. {
  16. // Adjust positions for dialog box
  17. mBGPos = Vector2(0.0f, 0.0f);
  18. mTitlePos = Vector2(0.0f, 100.0f);
  19. mNextButtonPos = Vector2(0.0f, 0.0f);
  20. mBackground = mGame->GetRenderer()->GetTexture("Assets/DialogBG.png");
  21. SetTitle(text, Vector3::Zero, 30);
  22. AddButton("OKButton", [onOK]() {
  23. onOK();
  24. });
  25. AddButton("CancelButton", [this]() {
  26. Close();
  27. });
  28. }
  29. DialogBox::~DialogBox()
  30. {
  31. }