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