guiArrayCtrl.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2012 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. #ifndef _GUIARRAYCTRL_H_
  23. #define _GUIARRAYCTRL_H_
  24. #ifndef _GUITYPES_H_
  25. #include "gui/core/guiTypes.h"
  26. #endif
  27. #ifndef _GUITEXTCTRL_H_
  28. #include "gui/controls/guiTextCtrl.h"
  29. #endif
  30. /// Renders a grid of cells.
  31. class GuiArrayCtrl : public GuiControl
  32. {
  33. typedef GuiControl Parent;
  34. protected:
  35. Point2I mHeaderDim;
  36. Point2I mSize;
  37. Point2I mCellSize;
  38. Point2I mSelectedCell;
  39. Point2I mMouseOverCell;
  40. Resource<GFont> mFont;
  41. virtual bool cellSelected(Point2I cell);
  42. virtual void onCellSelected(Point2I cell);
  43. virtual void onCellHighlighted(Point2I cell);
  44. bool _findHitCell( const Point2I& pos, Point2I& cellOut );
  45. /// @name Callbacks
  46. /// @{
  47. DECLARE_CALLBACK( void, onCellHighlighted, ( const Point2I& cell ) );
  48. DECLARE_CALLBACK( void, onCellSelected, ( const Point2I& cell ) );
  49. /// @}
  50. public:
  51. GuiArrayCtrl();
  52. DECLARE_CONOBJECT(GuiArrayCtrl);
  53. bool onWake();
  54. void onSleep();
  55. /// @name Array attribute methods
  56. /// @{
  57. Point2I getSize() { return mSize; }
  58. virtual void setSize(Point2I size);
  59. void setHeaderDim(const Point2I &dim) { mHeaderDim = dim; }
  60. void getScrollDimensions(S32 &cell_size, S32 &num_cells);
  61. /// @}
  62. /// @name Selected cell methods
  63. /// @{
  64. void setSelectedCell(Point2I cell);
  65. void deselectCells() { mSelectedCell.set(-1,-1); }
  66. Point2I getSelectedCell();
  67. void scrollSelectionVisible();
  68. void scrollCellVisible(Point2I cell);
  69. /// @}
  70. /// @name Rendering methods
  71. /// @{
  72. virtual void onRenderColumnHeaders(Point2I offset, Point2I parentOffset, Point2I headerDim);
  73. virtual void onRenderRowHeader(Point2I offset, Point2I parentOffset, Point2I headerDim, Point2I cell);
  74. virtual void onRenderCell(Point2I offset, Point2I cell, bool selected, bool mouseOver);
  75. void onRender(Point2I offset, const RectI &updateRect);
  76. /// @}
  77. /// @name Mouse input methods
  78. /// @{
  79. void onMouseDown( const GuiEvent &event );
  80. void onMouseUp( const GuiEvent &event );
  81. void onMouseMove( const GuiEvent &event );
  82. void onMouseDragged( const GuiEvent &event );
  83. void onMouseEnter( const GuiEvent &event );
  84. void onMouseLeave( const GuiEvent &event );
  85. bool onKeyDown( const GuiEvent &event );
  86. void onRightMouseDown( const GuiEvent &event );
  87. /// @}
  88. };
  89. #endif //_GUI_ARRAY_CTRL_H