libAlgAudio  v1.99-440-g08538e5-dirty
The development library for AlgAudio framework.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
StandardModuleGUI.hpp
Go to the documentation of this file.
1 #ifndef STANDARDMODULEGUI_HPP
2 #define STANDARDMODULEGUI_HPP
3 /*
4 This file is part of AlgAudio.
5 
6 AlgAudio, Copyright (C) 2015 CeTA - Audiovisual Technology Center
7 
8 AlgAudio is free software: you can redistribute it and/or modify
9 it under the terms of the GNU Lesser General Public License as
10 published by the Free Software Foundation, either version 3 of the
11 License, or (at your option) any later version.
12 
13 AlgAudio is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU Lesser General Public License for more details.
17 
18 You should have received a copy of the GNU Lesser General Public License
19 along with AlgAudio. If not, see <http://www.gnu.org/licenses/>.
20 */
21 #include "UI/UIWidget.hpp"
22 #include "Module.hpp"
23 #include "ModuleGUI.hpp"
24 #include "UI/UIMarginBox.hpp"
25 #include "UI/UIBox.hpp"
26 #include "UI/UILabel.hpp"
27 #include "ModuleUI/UISlider.hpp"
28 
29 namespace AlgAudio{
30 
32 public:
33  static std::shared_ptr<StandardModuleGUI> CreateFromXML(std::shared_ptr<Window> w, std::string xml_data, std::shared_ptr<Module> mod);
34  static std::shared_ptr<StandardModuleGUI> CreateFromTemplate(std::shared_ptr<Window> w, std::shared_ptr<Module> mod);
35  void CustomDraw(DrawContext& c) override;
36  void CustomResize(Size2D s) override;
37  void SetHighlight(bool) override;
38  void OnChildRequestedSizeChanged() override;
39  void OnChildVisibilityChanged() override;
40  virtual bool CustomMousePress(bool down, MouseButton b,Point2D pos) override {return main_margin->OnMousePress(down,b,pos);}
41  virtual void CustomMouseMotion(Point2D pos1,Point2D pos2) override {main_margin->OnMouseMotion(pos1,pos2);}
42  virtual void CustomMouseEnter(Point2D pos) override {main_margin->OnMouseEnter(pos);}
43  virtual void CustomMouseLeave(Point2D pos) override {main_margin->OnMouseLeave(pos);}
44  virtual Point2D WhereIsInlet(std::string inlet) override;
45  virtual Point2D WhereIsOutlet(std::string outlet) override;
46  virtual Point2D WhereIsParamInlet(std::string inlet) override;
47  virtual Point2D WhereIsParamRelativeOutlet(std::string outlet) override;
48  virtual Point2D WhereIsParamAbsoluteOutlet(std::string outlet) override;
49  virtual WhatIsHere GetWhatIsHere(Point2D) const override;
50  virtual void SliderDragStart(UIWidget::ID id) override;
51  virtual void SliderDragStep(UIWidget::ID id, Point2D_<float> current_offset) override;
52  virtual void SliderDragEnd(UIWidget::ID id) override;
53  virtual std::string GetIoletParamID(UIWidget::ID) const override;
54  virtual std::shared_ptr<UIWidget> CustomFindChild(ID id) const override{ return main_margin->FindChild(id);}
55  virtual void OnInletsChanged();
56  virtual Point2D GetChildPos() const {return Point2D(0,0);}
57 
58  virtual inline std::shared_ptr<UIWidget> Widget() override{
59  return shared_from_this();
60  };
61 
62 protected:
63  StandardModuleGUI(std::shared_ptr<Window> w, std::shared_ptr<Module> mod) : ModuleGUI(mod), UIContainerSingle(w){}
64 private:
65  void LoadFromXML(std::string xml_data, std::shared_ptr<ModuleTemplate> templ);
66  void LoadFromTemplate(std::shared_ptr<ModuleTemplate> templ);
67  void UpdateMinimalSize();
68  void CommonInit();
69  bool highlight = false;
70  std::shared_ptr<UILabel> caption;
71 
72  std::shared_ptr<UIMarginBox> main_margin;
73  std::shared_ptr<UIVBox> main_box;
74  std::shared_ptr<UIHBox> inlets_box;
75  std::shared_ptr<UIHBox> outlets_box;
76  std::shared_ptr<UIVBox> params_box;
77 
78  std::shared_ptr<SDLTextTexture> id_texture = nullptr;
79 
80  class IOConn : public UIWidget{
81  public:
82  std::string iolet_id;
83  std::string iolet_name;
84  VertAlignment align;
85  Color main_color;
86  Color border_color;
87  Signal<bool> on_press;
88  Signal<bool> on_connector_pointed;
89  // This flag is set iff the mouse pointer is not only pointing at this
90  // widget, but also is inside the inlet/outlet rect.
91  bool inside = false;
92  static std::shared_ptr<IOConn> Create(std::weak_ptr<Window> w, std::string id, std::string name, VertAlignment align, Color c);
93  void CustomDraw(DrawContext& c) override;
94  void SetBorderColor(Color c);
95  virtual bool CustomMousePress(bool down, MouseButton b,Point2D pos) override;
96  virtual void CustomMouseMotion(Point2D p1,Point2D p2) override;
97  virtual void CustomMouseEnter(Point2D p) override;
98  virtual void CustomMouseLeave(Point2D p) override;
99  friend class StandardModuleGUI;
100  static const int width, height;
101  private:
102  void Init();
103  IOConn(std::weak_ptr<Window> w, std::string id_, std::string name, VertAlignment align_, Color c);
104  Point2D GetRectPos() const;
105  inline Size2D GetRectSize() const {return Size2D(width,height);}
106  Point2D GetCenterPos() const;
107  };
108 
109  // Here all crucial elements are stored.
110  std::map<UIWidget::ID, std::shared_ptr<IOConn>> inlets;
111  std::map<UIWidget::ID, std::shared_ptr<IOConn>> outlets;
112  std::map<UIWidget::ID, std::shared_ptr<UISlider>> param_sliders;
113 
114  // Rectangle cache for WhatIsHere method
115  void UpdateWhatIsHereCache();
116  std::list<std::pair<Rect, WhatIsHere>> rect_cache;
117 
118 };
119 
120 } // namespace AlgAudio
121 
122 #endif //STANDARDMODULEGUI_HPP
virtual void CustomMouseLeave(Point2D pos) override
Definition: StandardModuleGUI.hpp:43
Definition: UIWidget.hpp:65
Definition: Color.hpp:28
VertAlignment
Definition: Utilities.hpp:149
void OnChildRequestedSizeChanged() override
Definition: UIContainer.hpp:27
Definition: DrawContext.hpp:65
Point2D_< int > Point2D
Definition: Utilities.hpp:35
MouseButton
Definition: Utilities.hpp:190
virtual Point2D GetChildPos() const
Definition: StandardModuleGUI.hpp:56
virtual Point2D WhereIsParamRelativeOutlet(std::string outlet) override
virtual Point2D WhereIsParamAbsoluteOutlet(std::string outlet) override
virtual void SliderDragStart(UIWidget::ID id) override
Definition: ModuleGUI.hpp:40
void CustomResize(Size2D s) override
virtual Point2D WhereIsParamInlet(std::string inlet) override
Definition: Alertable.hpp:26
Definition: UIWidget.hpp:137
virtual void SliderDragStep(UIWidget::ID id, Point2D_< float > current_offset) override
virtual void CustomMouseMotion(Point2D pos1, Point2D pos2) override
Definition: StandardModuleGUI.hpp:41
Definition: StandardModuleGUI.hpp:31
virtual bool CustomMousePress(bool down, MouseButton b, Point2D pos) override
Definition: StandardModuleGUI.hpp:40
virtual std::shared_ptr< UIWidget > Widget() override
Definition: StandardModuleGUI.hpp:58
static std::shared_ptr< StandardModuleGUI > CreateFromXML(std::shared_ptr< Window > w, std::string xml_data, std::shared_ptr< Module > mod)
virtual WhatIsHere GetWhatIsHere(Point2D) const override
virtual void OnInletsChanged()
static std::shared_ptr< StandardModuleGUI > CreateFromTemplate(std::shared_ptr< Window > w, std::shared_ptr< Module > mod)
virtual Point2D WhereIsInlet(std::string inlet) override
virtual std::string GetIoletParamID(UIWidget::ID) const override
virtual Point2D WhereIsOutlet(std::string outlet) override
StandardModuleGUI(std::shared_ptr< Window > w, std::shared_ptr< Module > mod)
Definition: StandardModuleGUI.hpp:63
void SetHighlight(bool) override
virtual void SliderDragEnd(UIWidget::ID id) override
void CustomDraw(DrawContext &c) override
virtual void CustomMouseEnter(Point2D pos) override
Definition: StandardModuleGUI.hpp:42
virtual std::shared_ptr< UIWidget > CustomFindChild(ID id) const override
Definition: StandardModuleGUI.hpp:54
Definition: Utilities.hpp:40
void OnChildVisibilityChanged() override