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