1// Aseprite
2// Copyright (C) 2022 Igara Studio S.A.
3// Copyright (C) 2001-2016 David Capello
4//
5// This program is distributed under the terms of
6// the End-User License Agreement for Aseprite.
7
8#ifndef APP_UI_WORKSPACE_PANEL_H_INCLUDED
9#define APP_UI_WORKSPACE_PANEL_H_INCLUDED
10#pragma once
11
12#include "app/ui/workspace_views.h"
13#include "ui/animated_widget.h"
14#include "ui/widget.h"
15
16#include <map>
17#include <vector>
18
19namespace app {
20 class Workspace;
21 class WorkspaceTabs;
22
23 enum class DropViewAtResult {
24 NOTHING,
25 MOVED_TO_OTHER_PANEL,
26 CLONED_VIEW,
27 };
28
29 class WorkspacePanel : public ui::Widget
30 , public ui::AnimatedWidget {
31 enum Ani : int {
32 ANI_NONE,
33 ANI_DROPAREA,
34 };
35
36 public:
37 typedef WorkspaceViews::iterator iterator;
38
39 enum PanelType {
40 MAIN_PANEL,
41 SUB_PANEL,
42 };
43
44 static ui::WidgetType Type();
45
46 WorkspacePanel(PanelType panelType);
47 ~WorkspacePanel();
48
49 void setTabsBar(WorkspaceTabs* tabs);
50 WorkspaceTabs* tabs() const { return m_tabs; }
51
52 iterator begin() { return m_views.begin(); }
53 iterator end() { return m_views.end(); }
54
55 bool isEmpty() const { return m_views.empty(); }
56
57 void addView(WorkspaceView* view, bool from_drop, int pos = -1);
58 void removeView(WorkspaceView* view);
59
60 WorkspaceView* activeView();
61 void setActiveView(WorkspaceView* view);
62
63 // Drop views into workspace
64 void setDropViewPreview(const gfx::Point& pos, WorkspaceView* view);
65 void removeDropViewPreview();
66
67 // Returns true if the view was docked inside the panel.
68 DropViewAtResult dropViewAt(const gfx::Point& screenPos,
69 WorkspacePanel* from,
70 WorkspaceView* view,
71 const bool clone);
72
73 protected:
74 void onPaint(ui::PaintEvent& ev) override;
75 void onResize(ui::ResizeEvent& ev) override;
76 void onAnimationFrame() override;
77 void onAnimationStop(int animation) override;
78
79 private:
80 int calculateDropArea(const gfx::Point& pos) const;
81 int getDropThreshold() const;
82 void adjustTime(int& time, int flag);
83 void adjustActiveViewBounds();
84 Workspace* getWorkspace();
85
86 PanelType m_panelType;
87 WorkspaceTabs* m_tabs;
88 WorkspaceViews m_views;
89 WorkspaceView* m_activeView;
90 int m_dropArea;
91 int m_leftTime, m_rightTime;
92 int m_topTime, m_bottomTime;
93 };
94
95 typedef std::vector<WorkspacePanel*> WorkspacePanels;
96
97} // namespace app
98
99#endif
100