guit  0.1
 All Classes Functions Variables Typedefs Enumerations Friends
gborder.hpp
1 //
2 // Borders
3 // Guit GUI Toolkit
4 // Copyright © 2019/2020 Eric Lecolinet. All rights reserved.
5 // http://www.telecom-paris.fr/~elc
6 //
7 
8 #ifndef GuitBorder_hpp
9 #define GuitBorder_hpp
10 #include <gmargin.hpp>
11 namespace guit {
12 
14 class GBorderValue : public GMarginValue {
15 public:
16  enum Kind {None=0, Squared=1<<0, Rounded=1<<2, Oval=1<<3, Polygon=1<<4, TextEdit=1<<5};
17 
18  ~GBorderValue();
19  GBorderValue() = default;
20  GBorderValue(Kind type, float left, float right, float top, float bottom,
21  GColor& idle_color, GColor& active_color);
22  GBorderValue(GPoints const& polygon, GColor& idle, GColor& selected);
23  GBorderValue(GBorderValue const&);
24 
25  GBorderValue& operator=(GBorderValue const&);
26  bool operator==(const GBorderValue&) const;
27  bool operator!=(const GBorderValue&) const;
28  friend std::ostream& operator<<(std::ostream& out, const GBorderValue&);
29 
30  bool hasDrawShape(Gadget&);
31  bool hasPickShape(Gadget&);
32  void drawBorder(GRenderGraphics&, GRender&);
33  bool pickBorder(Gadget&, GRect const&, GPoint const&);
34 
35  Kind style{};
36  gptr<GColor> idlecolor, activecolor;
37  GPoints* polygon{};
38 };
39 
40 inline bool gconvert(GBorderValue const& from, GBorderValue& to) {to = from; return true;}
41 bool gconvert(GString const& from, GBorderValue& to);
42 bool gconvert(GBorderValue const& from, GString& to);
43 
44 
54 class GBorder : public GVarProp_<GBorderValue> {
55 public:
57  enum Kind {None=0, Squared=1<<0, Rounded=1<<2, Oval=1<<3, Polygon=1<<4, TextEdit=1<<5};
58 
60  static GBorder none, squared, rounded, oval, polygon, textedit;
61 
62  GBorder();
63 
70  GBorder(GString const& value);
71 
73  GBorder(Kind, float left_right_padding, float top_bottom_padding,
74  GColor& idle_color, GColor& checked_color);
75 
76  GBorder(GPoints const& polygon, GColor& idle_color, GColor& active_color);
77 
78  GBorder(GBorderValue const&);
79 
80  GBorder(GBorder const& from, float left_right_padding, float top_bottom_padding,
81  GColor* idle_color = {}, GColor* active_color = {});
82 
83  GBorder* clone(bool copy_value) const override;
84 
85  using GType = GPropType_<GBorder,GProp>;
86  static GType& Type();
87  GType& type() const override {return Type();}
88 
89 protected:
90  friend class GRender;
91  void apply(Gadget*, GRender&, Specif) final;
92  void updateGadget(Gadget&) override;
93 };
94 
95 
98 inline GBorder& Border() {return *new GBorder();}
99 inline GBorder& Border(GString const& value) {return *new GBorder(value);}
101 
102 }
103 #endif