1// Aseprite UI Library
2// Copyright (C) 2018-2022 Igara Studio S.A.
3// Copyright (C) 2001-2016 David Capello
4//
5// This file is released under the terms of the MIT license.
6// Read LICENSE.txt for more information.
7
8#ifndef UI_OVERLAY_H_INCLUDED
9#define UI_OVERLAY_H_INCLUDED
10#pragma once
11
12#include "base/ref.h"
13#include "gfx/fwd.h"
14#include "gfx/point.h"
15#include "os/surface.h"
16#include "ui/base.h"
17
18namespace os {
19 class Surface;
20}
21
22namespace ui {
23 class Display;
24
25 class Overlay;
26 using OverlayRef = base::Ref<Overlay>;
27
28 class Overlay : public base::RefCountT<Overlay> {
29 public:
30 enum ZOrder {
31 NormalZOrder = 0,
32 MouseZOrder = 5000
33 };
34
35 Overlay(Display* display,
36 const os::SurfaceRef& overlaySurface,
37 const gfx::Point& pos,
38 ZOrder zorder = NormalZOrder);
39 ~Overlay();
40
41 os::SurfaceRef setSurface(const os::SurfaceRef& newSurface);
42
43 const gfx::Point& position() const { return m_pos; }
44 gfx::Rect bounds() const;
45
46 void captureOverlappedArea();
47 void restoreOverlappedArea(const gfx::Rect& restoreBounds);
48
49 void drawOverlay();
50 void moveOverlay(const gfx::Point& newPos);
51
52 bool operator<(const Overlay& other) const {
53 return m_zorder < other.m_zorder;
54 }
55
56 private:
57 Display* m_display;
58 os::SurfaceRef m_surface;
59 os::SurfaceRef m_overlap;
60
61 // Surface where we captured the overlapped (m_overlap)
62 // region. It's nullptr if the overlay wasn't drawn yet.
63 os::SurfaceRef m_captured;
64
65 gfx::Point m_pos;
66 ZOrder m_zorder;
67 };
68
69} // namespace ui
70
71#endif
72