Spinning Topp Logo BlackTopp Studios
inc
nineboxstrategy.h
1 // © Copyright 2010 - 2016 BlackTopp Studios Inc.
2 /* This file is part of The Mezzanine Engine.
3 
4  The Mezzanine Engine is free software: you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation, either version 3 of the License, or
7  (at your option) any later version.
8 
9  The Mezzanine Engine is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with The Mezzanine Engine. If not, see <http://www.gnu.org/licenses/>.
16 */
17 /* The original authors have included a copy of the license specified above in the
18  'Docs' folder. See 'gpl.txt'
19 */
20 /* We welcome the use of the Mezzanine engine to anyone, including companies who wish to
21  Build professional software and charge for their product.
22 
23  However there are some practical restrictions, so if your project involves
24  any of the following you should contact us and we will try to work something
25  out:
26  - DRM or Copy Protection of any kind(except Copyrights)
27  - Software Patents You Do Not Wish to Freely License
28  - Any Kind of Linking to Non-GPL licensed Works
29  - Are Currently In Violation of Another Copyright Holder's GPL License
30  - If You want to change our code and not add a few hundred MB of stuff to
31  your distribution
32 
33  These and other limitations could cause serious legal problems if you ignore
34  them, so it is best to simply contact us or the Free Software Foundation, if
35  you have any questions.
36 
37  Joseph Toppi - toppij@gmail.com
38  John Blackwood - makoenergy02@gmail.com
39 */
40 #ifndef _uinineboxstrategy_h
41 #define _uinineboxstrategy_h
42 
43 #include "UI/mousehoverstrategy.h"
44 #include "UI/rect.h"
45 #include <map>
46 
47 namespace Mezzanine
48 {
49  namespace UI
50  {
51  /// @brief Enum describing the different 9-Box partitions of a screen.
53  {
54  NBP_TopLeft = 1,
55  NBP_TopCenter = 2,
56  NBP_TopRight = 4,
57  NBP_RightCenter = 8,
58  NBP_Center = 16,
59  NBP_LeftCenter = 32,
60  NBP_BottomLeft = 64,
61  NBP_BottomCenter = 128,
62  NBP_BottomRight = 256
63  };//NineBoxPartition
64 
65  ///////////////////////////////////////////////////////////////////////////////
66  /// @class PartitionData
67  /// @headerfile nineboxstrategy.h
68  /// @brief This is a helper class for storing metadata for partitions.
69  /// @details
70  ///////////////////////////////////////
72  {
73  public:
74  /// @brief Basic container type for Widget storage by this class.
75  typedef std::vector<Widget*> WidgetContainer;
76  public:
77  /// @brief An enum value identifying which screen partition this is.
79  /// @brief A Rect representing the pixel limits of this screen partition.
81  /// @brief A container storing all the quads that overlap with this screen partition.
82  WidgetContainer Widgets;
83 
84  /// @brief Class constructor.
85  /// @param PartID An enum value identifying which screen partition this is.
87  PartitionID(PartID)
88  { }
89  /// @brief Class destructor.
91  { }
92  };//PartitionData
93 
94  ///////////////////////////////////////////////////////////////////////////////
95  /// @class NineBoxStrategy
96  /// @headerfile nineboxstrategy.h
97  /// @brief This strategy partitions the screen into 9 area's that track which Quads are in them, allowing a smaller list of quads to be checked.
98  /// @details
99  ///////////////////////////////////////
101  {
102  public:
103  /// @brief Basic container type for PartitionData storage by this class.
104  typedef std::vector<PartitionData*> PartitionVec;
105  protected:
106  /// @brief A container storing all the quads that overlap with this screen partition.
107  PartitionVec Partitions;
108 
109  /// @brief Updates the partition cache with the newest quad positions
110  void UpdateCache();
111  /// @brief Convenience method for calculating the actual size and position of a single partition.
112  /// @param PartID The enum value to calculate the pixel size and position for.
113  /// @param ScreenSize The current size of the screen the partition is on.
114  /// @param Returns a Rect storing the actual size and position of the specified partition.
115  /// @return Returns a Rect containing the size and position of the partition requested.
116  Rect CalculatePartitionRect(const NineBoxPartition& PartID, const Vector2& ScreenSize);
117  /// @brief Gets the partition that the provided position is in.
118  /// @param MousePos The screen position used to determine which partition to retrieve.
119  /// @return Returns a pointer to the PartitionData of the partition the provided mouse position is above.
120  PartitionData* GetHoveredPartition(const Vector2& MousePos);
121  public:
122  /// @brief Class constructor.
123  NineBoxStrategy();
124  /// @brief Class destructor.
125  virtual ~NineBoxStrategy();
126 
127  ///////////////////////////////////////////////////////////////////////////////
128  // Utility
129 
130  /// @copydoc MouseHoverStrategy::FindHoveredWidget(const Vector2& MousePos)
131  Widget* FindHoveredWidget(const Vector2& MousePos);
132  };//NineBoxStrategy
133  }//UI
134 }//Mezzanine
135 
136 #endif
This class represents a box shaped area on the screen.
Definition: rect.h:55
NineBoxPartition PartitionID
An enum value identifying which screen partition this is.
std::vector< Widget * > WidgetContainer
Basic container type for Widget storage by this class.
This is the base class for a method of finding which quad the mouse is hovered over.
~PartitionData()
Class destructor.
PartitionData(const NineBoxPartition &PartID)
Class constructor.
This is used to represent a point on a 2 dimentional area, such as a screen.
Definition: vector2.h:63
This is the base class for all widgets.
Definition: widget.h:126
This is a helper class for storing metadata for partitions.
NineBoxPartition
Enum describing the different 9-Box partitions of a screen.
Rect PartitionRect
A Rect representing the pixel limits of this screen partition.
#define MEZZ_LIB
Some platforms require special decorations to denote what is exported/imported in a share library...
The bulk of the engine components go in this namspace.
Definition: actor.cpp:56
std::vector< PartitionData * > PartitionVec
Basic container type for PartitionData storage by this class.
WidgetContainer Widgets
A container storing all the quads that overlap with this screen partition.
This strategy partitions the screen into 9 area's that track which Quads are in them, allowing a smaller list of quads to be checked.
PartitionVec Partitions
A container storing all the quads that overlap with this screen partition.