UserInterface.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. #pragma once
  2. //========================================================================
  3. // UserInterface.h : Defines UI elements of the GameCode4 application
  4. //
  5. // Part of the GameCode4 Application
  6. //
  7. // GameCode4 is the sample application that encapsulates much of the source code
  8. // discussed in "Game Coding Complete - 4th Edition" by Mike McShaffry and David
  9. // "Rez" Graham, published by Charles River Media.
  10. // ISBN-10: 1133776574 | ISBN-13: 978-1133776574
  11. //
  12. // If this source code has found it's way to you, and you think it has helped you
  13. // in any way, do the authors a favor and buy a new copy of the book - there are
  14. // detailed explanations in it that compliment this code well. Buy a copy at Amazon.com
  15. // by clicking here:
  16. // http://www.amazon.com/gp/product/1133776574/ref=olp_product_details?ie=UTF8&me=&seller=
  17. //
  18. // There's a companion web site at http://www.mcshaffry.com/GameCode/
  19. //
  20. // The source code is managed and maintained through Google Code:
  21. // http://code.google.com/p/gamecode4/
  22. //
  23. // (c) Copyright 2012 Michael L. McShaffry and David Graham
  24. //
  25. // This program is free software; you can redistribute it and/or
  26. // modify it under the terms of the GNU Lesser GPL v3
  27. // as published by the Free Software Foundation.
  28. //
  29. // This program is distributed in the hope that it will be useful,
  30. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  31. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
  32. // http://www.gnu.org/licenses/lgpl-3.0.txt for more details.
  33. //
  34. // You should have received a copy of the GNU Lesser GPL v3
  35. // along with this program; if not, write to the Free Software
  36. // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  37. //
  38. //========================================================================
  39. #include <optional>
  40. #include "../Graphics3D/Scene.h"
  41. // This class is a group of user interface controls.
  42. // It can be modal or modeless.
  43. //
  44. // class BaseUI - Chapter 10, page 286
  45. //
  46. // This was factored to create a common class that
  47. // implements some of the IScreenElement class common
  48. // to modal/modeless dialogs
  49. //
  50. class BaseUI : public IScreenElement
  51. {
  52. protected:
  53. int m_PosX, m_PosY;
  54. int m_Width, m_Height;
  55. std::optional<int> m_Result;
  56. bool m_bIsVisible;
  57. public:
  58. BaseUI() { m_bIsVisible = true; m_PosX = m_PosY = 0; m_Width = 100; m_Height = 100; }
  59. virtual void VOnUpdate(int) { };
  60. // virtual int VOnLostDevice() { return S_OK; }
  61. virtual bool VIsVisible() const { return m_bIsVisible; }
  62. virtual void VSetVisible(bool visible) { m_bIsVisible = visible; }
  63. };
  64. //
  65. // class ScreenElementScene - Chapter X, page Y
  66. //
  67. class ScreenElementScene : public IScreenElement, public Scene
  68. {
  69. public:
  70. ScreenElementScene(std::shared_ptr<IRenderer> renderer) : Scene(renderer) { }
  71. virtual ~ScreenElementScene(void)
  72. {
  73. GCC_WARNING("~ScreenElementScene()");
  74. }
  75. // IScreenElement Implementation
  76. virtual void VOnUpdate(int deltaMS) { OnUpdate(deltaMS); };
  77. virtual int VOnRestore()
  78. { OnRestore(); return 0; }
  79. virtual int VOnRender(double fTime, float fElapsedTime)
  80. { OnRender(); return 0; }
  81. // virtual int VOnLostDevice()
  82. // { OnLostDevice(); return 0; }
  83. virtual int VGetZOrder() const { return 0; }
  84. virtual void VSetZOrder(int const zOrder) { }
  85. // Don't handle any messages
  86. virtual int VOnMsgProc( SDL_Event &e ) { return 0; }
  87. virtual bool VIsVisible() const { return true; }
  88. virtual void VSetVisible(bool visible) { }
  89. virtual bool VAddChild(ActorId id, std::shared_ptr<ISceneNode> kid) { return Scene::AddChild(id, kid); }
  90. };