style_box.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /**************************************************************************/
  2. /* style_box.h */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /**************************************************************************/
  30. #ifndef STYLE_BOX_H
  31. #define STYLE_BOX_H
  32. #include "core/io/resource.h"
  33. #include "core/object/class_db.h"
  34. #include "core/object/gdvirtual.gen.inc"
  35. class CanvasItem;
  36. class StyleBox : public Resource {
  37. GDCLASS(StyleBox, Resource);
  38. RES_BASE_EXTENSION("stylebox");
  39. OBJ_SAVE_TYPE(StyleBox);
  40. float content_margin[4];
  41. protected:
  42. static void _bind_methods();
  43. virtual float get_style_margin(Side p_side) const { return 0; }
  44. GDVIRTUAL2C_REQUIRED(_draw, RID, Rect2)
  45. GDVIRTUAL1RC(Rect2, _get_draw_rect, Rect2)
  46. GDVIRTUAL0RC(Size2, _get_minimum_size)
  47. GDVIRTUAL2RC(bool, _test_mask, Point2, Rect2)
  48. public:
  49. virtual Size2 get_minimum_size() const;
  50. void set_content_margin(Side p_side, float p_value);
  51. void set_content_margin_all(float p_value);
  52. void set_content_margin_individual(float p_left, float p_top, float p_right, float p_bottom);
  53. float get_content_margin(Side p_side) const;
  54. float get_margin(Side p_side) const;
  55. Point2 get_offset() const;
  56. virtual void draw(RID p_canvas_item, const Rect2 &p_rect) const;
  57. virtual Rect2 get_draw_rect(const Rect2 &p_rect) const;
  58. CanvasItem *get_current_item_drawn() const;
  59. virtual bool test_mask(const Point2 &p_point, const Rect2 &p_rect) const;
  60. StyleBox();
  61. };
  62. class StyleBoxEmpty : public StyleBox {
  63. GDCLASS(StyleBoxEmpty, StyleBox);
  64. virtual float get_style_margin(Side p_side) const override { return 0; }
  65. public:
  66. virtual void draw(RID p_canvas_item, const Rect2 &p_rect) const override {}
  67. StyleBoxEmpty() {}
  68. };
  69. #endif // STYLE_BOX_H