PolyScreen.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. /*
  2. Copyright (C) 2011 by Ivan Safrin
  3. Permission is hereby granted, free of charge, to any person obtaining a copy
  4. of this software and associated documentation files (the "Software"), to deal
  5. in the Software without restriction, including without limitation the rights
  6. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  7. copies of the Software, and to permit persons to whom the Software is
  8. furnished to do so, subject to the following conditions:
  9. The above copyright notice and this permission notice shall be included in
  10. all copies or substantial portions of the Software.
  11. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  12. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  13. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  14. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  15. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  16. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  17. THE SOFTWARE.
  18. */
  19. #pragma once
  20. #include "PolyGlobals.h"
  21. #include "PolyVector2.h"
  22. #include "PolyEventDispatcher.h"
  23. #include "PolyScreenEntity.h"
  24. #include <vector>
  25. namespace Polycode {
  26. class InputEvent;
  27. class Renderer;
  28. class Material;
  29. class Texture;
  30. class ShaderBinding;
  31. /**
  32. * 2D rendering base. The Screen is the container for all 2D rendering in Polycode. Screens are automatically rendered and need only be instantiated to immediately add themselves to the rendering pipeline. Each screen has a root entity.
  33. */
  34. class _PolyExport Screen : public EventDispatcher {
  35. public:
  36. /**
  37. * Default constructor.
  38. */
  39. Screen();
  40. virtual ~Screen();
  41. /**
  42. * Adds a ScreenEntity to the 2d rendering pipeline.
  43. * @param newEntity Entity to add.
  44. */
  45. void addChild(ScreenEntity *newEntity);
  46. /**
  47. * Adds a ScreenEntity to the 2d rendering pipeline.
  48. * @param newEntity Entity to add.
  49. */
  50. void addEntity(ScreenEntity *newEntity);
  51. /**
  52. * Removes a ScreenEntity from the screen's root entity
  53. * @param entityToRemove Entity to remove.
  54. */
  55. virtual void removeChild(ScreenEntity *entityToRemove);
  56. /**
  57. * Sets the screen's offset. You can also translate the root entity to do the same thing.
  58. * @param x New x offset.
  59. * @param y New y offset.
  60. */
  61. void setScreenOffset(Number x, Number y);
  62. virtual void Shutdown();
  63. virtual void Update();
  64. void Render();
  65. void setRenderer(Renderer *renderer);
  66. /**
  67. * Changes the screen's coordinate system. By default, screens' dimensions are in pixels. To accommodate changing resolutions without changing the dimensions of a screen's content, you can call this method to make it use normalized coordinates.
  68. * @param newVal If true, the screen will use normalized coordinates, if false, it will use pixel coordinates.
  69. * @param yCoordinateSize The normalized size of the screen vertically. The horizontal size will be calculated based on the resolution.
  70. */
  71. void setNormalizedCoordinates(bool newVal, Number yCoordinateSize = 1.0f);
  72. /**
  73. * Sets the shader material to use for post processing on this screen.
  74. * @param shaderName Name of the shader material to use.
  75. */
  76. void setScreenShader(const String& shaderName);
  77. /**
  78. * Removes the current screen shader for this screen.
  79. */
  80. void clearScreenShader();
  81. void handleInputEvent(InputEvent *inputEvent);
  82. /**
  83. * Returns true if the screen has a shader applied to it.
  84. */
  85. bool hasFilterShader() const;
  86. void drawFilter();
  87. bool usesNormalizedCoordinates() const { return useNormalizedCoordinates; }
  88. Number getYCoordinateSize() const { return yCoordinateSize; }
  89. /**
  90. * If set to false, the screen will not be rendered or updated.
  91. */
  92. bool enabled;
  93. /**
  94. * Returns the local shader options for the camera post processing material.
  95. */
  96. const std::vector<ShaderBinding*>& getLocalShaderOptions() const { return localShaderOptions; }
  97. /**
  98. * Returns the shader material applied to the camera.
  99. */
  100. Material *getScreenShaderMaterial() const { return filterShaderMaterial; }
  101. /**
  102. * If set to true, will process touch events as mouse clicks. Defaults to false.
  103. */
  104. bool processTouchEventsAsMouse;
  105. /**
  106. * If ownsChildren is set to true, the scene will delete its children upon destruction (defaults to false).
  107. */
  108. bool ownsChildren;
  109. ScreenEntity rootEntity;
  110. protected:
  111. Vector2 offset;
  112. bool useNormalizedCoordinates;
  113. Number yCoordinateSize;
  114. Renderer *renderer;
  115. ScreenEntity *focusChild;
  116. Material *filterShaderMaterial;
  117. Texture *originalSceneTexture;
  118. std::vector<ShaderBinding*> localShaderOptions;
  119. bool _hasFilterShader;
  120. };
  121. }