Canvas.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /*
  2. GWEN
  3. Copyright (c) 2010 Facepunch Studios
  4. See license in Gwen.h
  5. */
  6. #pragma once
  7. #ifndef GWEN_CONTROLS_CANVAS_H
  8. #define GWEN_CONTROLS_CANVAS_H
  9. #include <set>
  10. #include "Gwen/Controls/Base.h"
  11. #include "Gwen/InputHandler.h"
  12. namespace Gwen
  13. {
  14. namespace Controls
  15. {
  16. class GWEN_EXPORT Canvas : public Base
  17. {
  18. public:
  19. typedef Controls::Base BaseClass;
  20. Canvas( Skin::Base* pSkin );
  21. //
  22. // For additional initialization
  23. // (which is sometimes not appropriate in the constructor)
  24. //
  25. virtual void Initialize(){};
  26. //
  27. // You should call this to render your canvas.
  28. //
  29. virtual void RenderCanvas();
  30. //
  31. // Call this whenever you want to process input. This
  32. // is usually once a frame..
  33. //
  34. virtual void DoThink();
  35. //
  36. // In most situations you will be rendering the canvas
  37. // every frame. But in some situations you will only want
  38. // to render when there have been changes. You can do this
  39. // by checking NeedsRedraw().
  40. //
  41. virtual bool NeedsRedraw(){ return m_bNeedsRedraw; }
  42. virtual void Redraw(){ m_bNeedsRedraw = true; }
  43. // Internal. Do not call directly.
  44. virtual void Render( Skin::Base* pRender );
  45. // Childpanels call parent->GetCanvas() until they get to
  46. // this top level function.
  47. virtual Controls::Canvas* GetCanvas(){ return this; }
  48. virtual void SetScale( float f );
  49. virtual float Scale() const { return m_fScale; }
  50. virtual void OnBoundsChanged( Gwen::Rect oldBounds );
  51. //
  52. // Call this to delete the canvas, and its children
  53. // in the right order.
  54. //
  55. virtual void Release();
  56. // Delayed deletes
  57. virtual void AddDelayedDelete( Controls::Base* pControl );
  58. virtual void ProcessDelayedDeletes();
  59. Controls::Base* FirstTab;
  60. Controls::Base* NextTab;
  61. // Input
  62. virtual bool InputMouseMoved( int x, int y, int deltaX, int deltaY );
  63. virtual bool InputMouseButton( int iButton, bool bDown );
  64. virtual bool InputKey( int iKey, bool bDown );
  65. virtual bool InputCharacter( Gwen::UnicodeChar chr );
  66. virtual bool InputMouseWheel( int val );
  67. // Background
  68. virtual void SetBackgroundColor( const Gwen::Color& color ){ m_BackgroundColor = color; }
  69. virtual void SetDrawBackground( bool bShouldDraw ){ m_bDrawBackground = bShouldDraw; }
  70. private:
  71. bool m_bNeedsRedraw;
  72. bool m_bAnyDelete;
  73. float m_fScale;
  74. Controls::Base::List m_DeleteList;
  75. std::set< Controls::Base* > m_DeleteSet;
  76. friend class Controls::Base;
  77. void PreDelete( Controls::Base * );
  78. bool m_bDrawBackground;
  79. Gwen::Color m_BackgroundColor;
  80. };
  81. }
  82. }
  83. #endif