forked from aseprite/aseprite
-
Notifications
You must be signed in to change notification settings - Fork 0
/
manager.h
185 lines (150 loc) · 5.76 KB
/
manager.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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
// Aseprite UI Library
// Copyright (C) 2001-2017 David Capello
//
// This file is released under the terms of the MIT license.
// Read LICENSE.txt for more information.
#ifndef UI_MANAGER_H_INCLUDED
#define UI_MANAGER_H_INCLUDED
#pragma once
#include "gfx/region.h"
#include "ui/keys.h"
#include "ui/message_type.h"
#include "ui/mouse_buttons.h"
#include "ui/pointer_type.h"
#include "ui/widget.h"
namespace she {
class Display;
class EventQueue;
}
namespace ui {
class LayoutIO;
class Timer;
class Window;
class Manager : public Widget {
public:
static Manager* getDefault() {
return m_defaultManager;
}
Manager();
~Manager();
she::Display* getDisplay() { return m_display; }
void setDisplay(she::Display* display);
// Executes the main message loop.
void run();
// Refreshes the real display with the UI content.
void flipDisplay();
// Adds the given "msg" message to the queue of messages to be
// dispached. "msg" cannot be used after this function, it'll be
// automatically deleted.
void enqueueMessage(Message* msg);
// Returns true if there are messages in the queue to be
// dispatched through dispatchMessages().
bool generateMessages();
void dispatchMessages();
void addToGarbage(Widget* widget);
void collectGarbage();
Window* getTopWindow();
Window* getForegroundWindow();
Widget* getFocus();
Widget* getMouse();
Widget* getCapture();
void setFocus(Widget* widget);
void setMouse(Widget* widget);
void setCapture(Widget* widget);
void attractFocus(Widget* widget);
void focusFirstChild(Widget* widget);
void freeFocus();
void freeMouse();
void freeCapture();
void freeWidget(Widget* widget);
void removeMessage(Message* msg);
void removeMessagesFor(Widget* widget);
void removeMessagesFor(Widget* widget, MessageType type);
void removeMessagesForTimer(Timer* timer);
void addMessageFilter(int message, Widget* widget);
void removeMessageFilter(int message, Widget* widget);
void removeMessageFilterFor(Widget* widget);
void invalidateDisplayRegion(const gfx::Region& region);
LayoutIO* getLayoutIO();
bool isFocusMovementMessage(Message* msg);
bool processFocusMovementMessage(Message* msg);
// 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;
}
// Mark the given rectangle as a area to be flipped to the real
// screen
void dirtyRect(const gfx::Rect& bounds);
void _openWindow(Window* window);
void _closeWindow(Window* window, bool redraw_background);
protected:
bool onProcessMessage(Message* msg) override;
void onResize(ResizeEvent& ev) override;
void onSizeHint(SizeHintEvent& ev) override;
void onBroadcastMouseMessage(WidgetsList& targets) override;
virtual LayoutIO* onGetLayoutIO();
virtual void onNewDisplayConfiguration();
private:
void generateSetCursorMessage(const gfx::Point& mousePos,
KeyModifiers modifiers,
PointerType pointerType);
void generateMessagesFromSheEvents();
void handleMouseMove(const gfx::Point& mousePos,
MouseButtons mouseButtons,
KeyModifiers modifiers,
PointerType pointerType);
void handleMouseDown(const gfx::Point& mousePos,
MouseButtons mouseButtons,
KeyModifiers modifiers,
PointerType pointerType);
void handleMouseUp(const gfx::Point& mousePos,
MouseButtons mouseButtons,
KeyModifiers modifiers,
PointerType pointerType);
void handleMouseDoubleClick(const gfx::Point& mousePos,
MouseButtons mouseButtons,
KeyModifiers modifiers,
PointerType pointerType);
void handleMouseWheel(const gfx::Point& mousePos,
MouseButtons mouseButtons,
KeyModifiers modifiers,
PointerType pointerType,
const gfx::Point& wheelDelta,
bool preciseWheel);
void handleTouchMagnify(const gfx::Point& mousePos,
const KeyModifiers modifiers,
const double magnification);
void handleWindowZOrder();
int pumpQueue();
bool sendMessageToWidget(Message* msg, Widget* widget);
static void removeWidgetFromRecipients(Widget* widget, Message* msg);
static bool someParentIsFocusStop(Widget* widget);
static Widget* findMagneticWidget(Widget* widget);
static Message* newMouseMessage(
MessageType type,
Widget* widget, const gfx::Point& mousePos,
PointerType pointerType,
MouseButtons buttons,
KeyModifiers modifiers,
const gfx::Point& wheelDelta = gfx::Point(0, 0),
bool preciseWheel = false);
void broadcastKeyMsg(Message* msg);
static Manager* m_defaultManager;
static gfx::Region m_dirtyRegion;
WidgetsList m_garbage;
she::Display* m_display;
she::EventQueue* m_eventQueue;
gfx::Region m_invalidRegion; // Invalid region (we didn't receive paint messages yet for this).
// This member is used to make freeWidget() a no-op when we
// restack a window if the user clicks on it.
Widget* m_lockedWindow;
// Current pressed buttons.
MouseButtons m_mouseButtons;
};
} // namespace ui
#endif