123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226 |
- /*
- * Copyright (c) Contributors to the Open 3D Engine Project.
- * For complete copyright and license terms please see the LICENSE at the root of this distribution.
- *
- * SPDX-License-Identifier: Apache-2.0 OR MIT
- *
- */
- #pragma once
- #if !defined(Q_MOC_RUN)
- #include "EditorCommon.h"
- #include "LyShinePassDataBus.h"
- #include <AzToolsFramework/API/ToolsApplicationAPI.h>
- #include <AtomToolsFramework/Viewport/RenderViewportWidget.h>
- #include <Atom/RPI.Public/ViewportContextBus.h>
- #include <IFont.h>
- #include <QTimer>
- #endif
- class RulerWidget;
- class QMimeData;
- class UiRenderer;
- class CDraw2d;
- class ViewportWidget
- : public AtomToolsFramework::RenderViewportWidget
- , private AzToolsFramework::EditorPickModeNotificationBus::Handler
- , private FontNotificationBus::Handler
- , private LyShinePassDataRequestBus::Handler
- , public AZ::RPI::ViewportContextNotificationBus::Handler
- {
- Q_OBJECT
- public: // types
- enum DrawElementBorders
- {
- DrawElementBorders_Unselected = 0x1,
- DrawElementBorders_Visual = 0x2,
- DrawElementBorders_Parent = 0x4,
- DrawElementBorders_Hidden = 0x8,
- };
- public: // member functions
- explicit ViewportWidget(EditorWindow* parent);
- virtual ~ViewportWidget();
- ViewportInteraction* GetViewportInteraction();
- bool IsDrawingElementBorders(uint32 flags) const;
- void ToggleDrawElementBorders(uint32 flags);
- void ActiveCanvasChanged();
- void EntityContextChanged();
- //! Flags the viewport display as needing a refresh
- void Refresh();
- //! Used to clear the viewport and prevent rendering until the viewport layout updates
- void ClearUntilSafeToRedraw();
- //! Set whether to render the canvas
- void SetRedrawEnabled(bool enabled);
- //! Get the canvas scale factor being used for the preview mode
- float GetPreviewCanvasScale() { return m_previewCanvasScale; }
- //! Used by ViewportInteraction for drawing
- ViewportHighlight* GetViewportHighlight() { return m_viewportHighlight.get(); }
- //! Get the size of the RPI render viewport
- AZ::Vector2 GetRenderViewportSize() const;
- //! Get the widget to viewport scale factor
- float WidgetToViewportFactor() const;
- bool IsInObjectPickMode() { return m_inObjectPickMode; }
- void PickItem(AZ::EntityId entityId);
- QWidget* CreateViewportWithRulersWidget(QWidget* parent);
- void ShowRulers(bool show);
- bool AreRulersShown() { return m_rulersVisible; }
- void RefreshRulers();
- void SetRulerCursorPositions(const QPoint& globalPos);
- void ShowGuides(bool show);
- bool AreGuidesShown() { return m_guidesVisible; }
- void InitUiRenderer();
- protected:
- void contextMenuEvent(QContextMenuEvent* e) override;
- private slots:
- void UserSelectionChanged(HierarchyItemRawPtrList* items);
- void EnableCanvasRender();
- //! Called by a timer at the max frequency that we want to refresh the display
- void RefreshTick();
- protected:
- //! Forwards mouse press events to ViewportInteraction.
- //!
- //! Event is NOT propagated to parent class.
- void mousePressEvent(QMouseEvent* ev) override;
- //! Forwards mouse move events to ViewportInteraction.
- //!
- //! Event is NOT propagated to parent class.
- void mouseMoveEvent(QMouseEvent* ev) override;
- //! Forwards mouse release events to ViewportInteraction.
- //!
- //! Event is NOT propagated to parent class.
- void mouseReleaseEvent(QMouseEvent* ev) override;
- //! Forwards mouse wheel events to ViewportInteraction.
- //!
- //! Event is propagated to parent class.
- void wheelEvent(QWheelEvent* ev) override;
- //! Prevents shortcuts from interfering with preview mode.
- bool eventFilter(QObject* watched, QEvent* event) override;
- //! Handle events from Qt.
- bool event(QEvent* ev) override;
- //! Key press event from Qt.
- void keyPressEvent(QKeyEvent* event) override;
- //! Key release event from Qt.
- void keyReleaseEvent(QKeyEvent* event) override;
- void focusOutEvent(QFocusEvent* ev) override;
- private: // member functions
- // EditorPickModeNotificationBus
- void OnEntityPickModeStarted() override;
- void OnEntityPickModeStopped() override;
- // FontNotifications
- void OnFontsReloaded() override;
- void OnFontTextureUpdated(IFFont* font) override;
- // ~FontNotifications
- // LyShinePassDataRequestBus
- LyShine::AttachmentImagesAndDependencies GetRenderTargets() override;
- // ~LyShinePassDataRequestBus
- // AZ::TickBus::Handler
- void OnTick(float deltaTime, AZ::ScriptTimePoint time) override;
- int GetTickOrder() override;
- // ~AZ::TickBus::Handler
- // AZ::RPI::ViewportContextNotificationBus::Handler overrides...
- void OnRenderTick() override;
- void OnViewportDpiScalingChanged(float dpiScale) override;
- //! Update UI canvases when in edit mode
- void UpdateEditMode(float deltaTime);
- //! Render the viewport when in edit mode
- void RenderEditMode();
- //! Update UI canvases when in preview mode
- void UpdatePreviewMode(float deltaTime);
- //! Render the viewport when in preview mode
- void RenderPreviewMode();
- //! Fill the entire viewport area with a background color
- void RenderViewportBackground();
- //! Create shortcuts for manipulating the viewport
- void SetupShortcuts();
- //! Do the Qt stuff to hide/show the rulers
- void ApplyRulerVisibility();
- private: // data
- void resizeEvent(QResizeEvent* ev) override;
- void dragEnterEvent(QDragEnterEvent* event) override;
- void dropEvent(QDropEvent* event) override;
- bool AcceptsMimeData(const QMimeData* mimeData);
- QPointF WidgetToViewport(const QPointF &point) const;
- EditorWindow* m_editorWindow;
- std::unique_ptr< ViewportInteraction > m_viewportInteraction;
- std::unique_ptr< ViewportAnchor > m_viewportAnchor;
- std::unique_ptr< ViewportHighlight > m_viewportHighlight;
- std::unique_ptr< ViewportCanvasBackground > m_viewportBackground;
- std::unique_ptr< ViewportPivot > m_viewportPivot;
- uint32 m_drawElementBordersFlags;
- bool m_refreshRequested;
- bool m_canvasRenderIsEnabled;
- QTimer m_updateTimer;
- float m_previewCanvasScale;
- bool m_inObjectPickMode = false;
- RulerWidget* m_rulerHorizontal = nullptr;
- RulerWidget* m_rulerVertical = nullptr;
- QWidget* m_rulerCorner = nullptr;
- bool m_rulersVisible;
- bool m_guidesVisible;
- bool m_fontTextureHasChanged = false;
- AZStd::shared_ptr<UiRenderer> m_uiRenderer;
- AZStd::shared_ptr<CDraw2d> m_draw2d;
- };
|