1 | // LAF OS Library |
---|---|
2 | // Copyright (C) 2019-2021 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 | #ifdef HAVE_CONFIG_H |
8 | #include "config.h" |
9 | #endif |
10 | |
11 | #include "os/window.h" |
12 | |
13 | #include "gfx/rect.h" |
14 | #include "gfx/region.h" |
15 | #include "os/event.h" |
16 | #include "os/event_queue.h" |
17 | |
18 | namespace os { |
19 | |
20 | gfx::Rect Window::bounds() const |
21 | { |
22 | return gfx::Rect(0, 0, width(), height()); |
23 | } |
24 | |
25 | void Window::invalidate() |
26 | { |
27 | invalidateRegion(gfx::Region(bounds())); |
28 | } |
29 | |
30 | gfx::Point Window::pointToScreen(const gfx::Point& clientPosition) const |
31 | { |
32 | gfx::Point res = clientPosition; |
33 | res *= scale(); |
34 | res += contentRect().origin(); |
35 | return res; |
36 | } |
37 | |
38 | gfx::Point Window::pointFromScreen(const gfx::Point& screenPosition) const |
39 | { |
40 | gfx::Point res = screenPosition; |
41 | res -= contentRect().origin(); |
42 | res /= scale(); |
43 | return res; |
44 | } |
45 | |
46 | void Window::queueEvent(os::Event& ev) |
47 | { |
48 | onQueueEvent(ev); |
49 | } |
50 | |
51 | void Window::onQueueEvent(Event& ev) |
52 | { |
53 | // Some events are used more than one time (e.g. to send MouseEnter |
54 | // and then MouseMove). |
55 | if (!ev.window()) |
56 | ev.setWindow(AddRef(this)); |
57 | else { |
58 | ASSERT(ev.window().get() == this); |
59 | } |
60 | |
61 | os::queue_event(ev); |
62 | } |
63 | |
64 | } // namespace os |
65 |