1// Aseprite UI Library
2// Copyright (C) 2021 Igara Studio S.A.
3// Copyright (C) 2001-2017 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_POPUP_WINDOW_H_INCLUDED
9#define UI_POPUP_WINDOW_H_INCLUDED
10#pragma once
11
12#include "ui/window.h"
13
14namespace ui {
15
16 class PopupWindow : public Window {
17 public:
18 enum class ClickBehavior {
19 DoNothingOnClick,
20 CloseOnClickInOtherWindow,
21 CloseOnClickOutsideHotRegion
22 };
23
24 enum class EnterBehavior {
25 DoNothingOnEnter,
26 CloseOnEnter,
27 };
28
29 PopupWindow(const std::string& text = "",
30 const ClickBehavior clickBehavior = ClickBehavior::CloseOnClickOutsideHotRegion,
31 const EnterBehavior enterBehavior = EnterBehavior::CloseOnEnter,
32 const bool withCloseButton = false);
33 ~PopupWindow();
34
35 // Sets the hot region. This region indicates the area where the
36 // mouse can be located and the window will be kept open.
37 //
38 // The screenRegion must be specified in native screen coordinates.
39 void setHotRegion(const gfx::Region& screenRegion);
40
41 void setClickBehavior(ClickBehavior behavior);
42 void setEnterBehavior(EnterBehavior behavior);
43
44 void makeFloating();
45 void makeFixed();
46
47 protected:
48 bool onProcessMessage(Message* msg) override;
49 void onHitTest(HitTestEvent& ev) override;
50
51 virtual void onMakeFloating();
52 virtual void onMakeFixed();
53
54 private:
55 void startFilteringMessages();
56 void stopFilteringMessages();
57
58 ClickBehavior m_clickBehavior;
59 EnterBehavior m_enterBehavior;
60 gfx::Region m_hotRegion;
61 bool m_filtering = false;
62 bool m_fixed = false;
63 };
64
65 class TransparentPopupWindow : public PopupWindow {
66 public:
67 TransparentPopupWindow(ClickBehavior clickBehavior);
68 protected:
69 void onInitTheme(InitThemeEvent& ev) override;
70 };
71
72} // namespace ui
73
74#endif
75