1// Aseprite UI Library
2// Copyright (C) 2019-2022 Igara Studio S.A.
3//
4// This file is released under the terms of the MIT license.
5// Read LICENSE.txt for more information.
6
7#ifndef UI_DISPLAY_H_INCLUDED
8#define UI_DISPLAY_H_INCLUDED
9#pragma once
10
11#include "gfx/rect.h"
12#include "gfx/region.h"
13#include "gfx/size.h"
14#include "os/window.h"
15
16#include <vector>
17
18namespace ui {
19 class Widget;
20 class Window;
21
22 // Wraps a native window (os::Window). On each "display" we can show
23 // the main manager or a window (containedWidget), and a set of
24 // children window that doesn't have a native window counterpart
25 // (tooltips?)
26 class Display {
27 public:
28 Display(Display* parentDisplay,
29 const os::WindowRef& nativeWindow,
30 Widget* containedWidget);
31
32 Display* parentDisplay() { return m_parentDisplay; }
33 os::Window* nativeWindow() const { return m_nativeWindow.get(); }
34 os::Surface* surface() const;
35
36 int scale() const { return m_nativeWindow->scale(); }
37 gfx::Size size() const;
38 gfx::Rect bounds() const { return gfx::Rect(size()); }
39
40 Widget* containedWidget() const { return m_containedWidget; }
41
42 // Mark the given rectangle as a area to be flipped to the real
43 // screen.
44 void dirtyRect(const gfx::Rect& bounds);
45
46 // Refreshes the real display with the UI content.
47 void flipDisplay();
48
49 // Returns the invalid region in the screen to being updated with
50 // PaintMessages. This region is cleared when each widget receives
51 // a paint message.
52 const gfx::Region& getInvalidRegion() const {
53 return m_invalidRegion;
54 }
55
56 void addInvalidRegion(const gfx::Region& b) {
57 m_invalidRegion |= b;
58 }
59
60 void subtractInvalidRegion(const gfx::Region& b) {
61 m_invalidRegion -= b;
62 }
63
64 void setInvalidRegion(const gfx::Region& b) {
65 m_invalidRegion = b;
66 }
67
68 void invalidateRect(const gfx::Rect& rect);
69 void invalidateRegion(const gfx::Region& region);
70
71 void addWindow(Window* window);
72 void removeWindow(Window* window);
73 void handleWindowZOrder(Window* window);
74 const std::vector<Window*>& getWindows() const { return m_windows; }
75
76 gfx::Size workareaSizeUIScale();
77
78 void _setParentDisplay(Display* parentDisplay) {
79 m_parentDisplay = parentDisplay;
80 }
81
82 private:
83 Display* m_parentDisplay;
84 os::WindowRef m_nativeWindow;
85 Widget* m_containedWidget; // A ui::Manager or a ui::Window
86 std::vector<Window*> m_windows; // Sub-windows in this display
87 gfx::Region m_invalidRegion; // Invalid region (we didn't receive paint messages yet for this).
88 gfx::Region m_dirtyRegion; // Region to flip to the os::Display
89 };
90
91} // namespace ui
92
93#endif
94