1 #ifndef WOLF_RIGHT_CLICK_MENU_H
2 #define WOLF_RIGHT_CLICK_MENU_H
3 
4 #include "Widget.hpp"
5 #include "Window.hpp"
6 #include "NanoVG.hpp"
7 #include "NanoLabel.hpp"
8 #include "WolfWidget.hpp"
9 
10 #include <vector>
11 
12 START_NAMESPACE_DISTRHO
13 
14 class RightClickMenuItem
15 {
16 public:
17   RightClickMenuItem(int id, const char *label, const char *comment = "", bool enabled = true) noexcept;
18 
19   int getId();
20   bool getEnabled();
21   void setEnabled(bool enabled);
22   const char *getLabel();
23   void setLabel(const char *label);
24   const char *getComment();
25   bool hasComment();
26 
27   bool getSelected();
28   void setSelected(const bool selected);
29 
30   bool isSection();
31 
32 protected:
33   bool fIsSection;
34 
35 private:
36   int fId;
37   bool fEnabled;
38   const char *fLabel;
39   const char *fComment;
40 
41   bool fSelected;
42 
43   DGL_NAMESPACE::Rectangle<float> fBounds;
44 };
45 
46 class RightClickMenuSection : public RightClickMenuItem
47 {
48 public:
49   RightClickMenuSection(const char *label) noexcept;
50 };
51 
52 class RightClickMenu : private Window,
53                        public WolfWidget
54 {
55 public:
56   class Callback
57   {
58   public:
~Callback()59     virtual ~Callback() {}
60     virtual void rightClickMenuItemSelected(RightClickMenuItem *rightClickMenuItem) = 0;
61   };
62 
63   RightClickMenu(Widget  *parent) noexcept;
64   ~RightClickMenu();
65 
66   void show(int posX, int posY);
67   void close();
68   void addItem(int id, const char *label, const char *comment = "");
69   void addSection(const char *sectionName);
70   void setBorderColor(const Color color);
71   void setRegularFontSize(float fontSize);
72   void setSectionFontSize(float fontSize);
73   RightClickMenuItem *getItemById(int id);
74   void setCallback(Callback *callback) noexcept;
75   void setSectionEnabled(int index, bool enabled);
76 
77 protected:
78   void onNanoDisplay() override;
79   //void onFocusOut() override;
80   bool onMouse(const MouseEvent &ev) override;
81   bool onMotion(const MotionEvent &ev) override;
82   void adaptSize();
83   bool onClose() override;
84 
85   DGL_NAMESPACE::Rectangle<float> getBoundsOfItem(const int index);
86   DGL_NAMESPACE::Rectangle<float> getBoundsOfItemComment(const int index);
87 
88 private:
89   void findLongestItem();
90 
91   std::vector<RightClickMenuItem> fItems;
92 
93   float fFontSize;
94   float fSectionFontSize;
95 
96   float fHoveredIndex;
97   float fLongestWidth;
98   Color fBorderColor;
99   Margin fMargin;
100 
101   Callback *fCallback;
102 };
103 
104 #endif
105 
106 END_NAMESPACE_DISTRHO
107