SlicerManipulator.h 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #pragma once
  9. #include <LyShine/Bus/UiImageBus.h>
  10. //! On-screen control used to modify border info for 9-slicing sprites.
  11. class SlicerManipulator
  12. : public QGraphicsRectItem
  13. {
  14. public:
  15. SlicerManipulator(SpriteBorder border,
  16. QSize& unscaledPixmapSize,
  17. QSize& scaledPixmapSize,
  18. ISprite* sprite,
  19. QGraphicsScene* scene,
  20. SlicerEdit* edit);
  21. //! Associates a text input/QLineEdit control with this manipulator.
  22. void SetEdit(SlicerEdit* edit);
  23. //! Provides the scale and unscale sprite sizes as displayed in the properties pane.
  24. //!
  25. //! This method is intended to be called when the displayed pixmap/image
  26. //! changes, such as when the user selects a different cell of a sprite-sheet.
  27. //!
  28. //! The scale values themselves are primarily used to convert between viewport
  29. //! and spritesheet cell texture spaces.
  30. void SetPixmapSizes(const QSize& unscaledSize, const QSize& scaledSize);
  31. //! A cell index can be provided when working with sprite-sheets.
  32. //!
  33. //! The cell index is used to set the border info on the sprite-sheet
  34. //! cell as the border values are manipulated by the user with this
  35. //! manipulator.
  36. void SetCellIndex(AZ::u32 cellIndex) { m_cellIndex = cellIndex; };
  37. //! Changes the on-screen position of this manipulator based on the new border pixel value.
  38. void setPixelPosition(float p);
  39. protected:
  40. QVariant itemChange(GraphicsItemChange change, const QVariant& value) override;
  41. void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) override;
  42. void hoverEnterEvent(QGraphicsSceneHoverEvent* event) override;
  43. void hoverLeaveEvent(QGraphicsSceneHoverEvent* event) override;
  44. private:
  45. SpriteBorder m_border;
  46. bool m_isVertical;
  47. QSize m_unscaledPixmapSize;
  48. QSize m_scaledPixmapSize;
  49. ISprite* m_sprite;
  50. QPointF m_unscaledOverScaledFactor;
  51. QPointF m_scaledOverUnscaledFactor;
  52. QPen m_penFront;
  53. QPen m_penBack;
  54. SlicerEdit* m_edit;
  55. AZ::u32 m_cellIndex = 0; //!< The cell index currently displayed to the user (if applicable).
  56. };