guit  0.1
 All Classes Functions Variables Typedefs Enumerations Friends
gicon.hpp
1 //
2 // Icon Property.
3 // guit GUI Toolkit
4 // Copyright © 2019 Eric Lecolinet. All rights reserved.
5 // http://www.telecom-paristech.fr/~elc
6 //
7 
8 #ifndef Guit_Icon_hpp
9 #define Guit_Icon_hpp
10 #include <gcolor.hpp>
11 namespace guit {
12 
13 class GIconValue {
14 public:
15  enum LoadStatus {CantLoad=-1, Unloaded=0, Loaded=1};
16  typedef void (DrawFun)(GRenderGraphics&, GRender&, GRect const& iconframe);
17 
18  ~GIconValue();
19  bool operator==(const GIconValue&) const;
20  bool operator!=(const GIconValue&) const;
21 
22  mutable LoadStatus status{Unloaded};
23  mutable GTexture texture{};
24  DrawFun* drawfun{};
25  GString filename;
26  const char** xpm{};
27  gptr<GColor> fg, bg;
28  int w{}, h{}, area{};
29 };
30 
31 bool gconvert(GIconValue const& from, GIconValue& to);
32 bool gconvert(GString const& from, GIconValue& to);
33 bool gconvert(GIconValue const& from, GString& to);
34 
35 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
36 
38 class GIcon : public GVarProp_<GIconValue> {
39 public:
41  using DrawFun = GIconValue::DrawFun;
42  static DrawFun Image, XPM,
43  CheckSymbol, RadioSymbol, ComboSymbol, LeftSymbol, RightSymbol, UpSymbol,
44  DownSymbol, UpDownSymbol;
45 
47  static GIcon check, radio, left, right, up, down, updown, combo;
48 
49  GIcon();
50  GIcon(GString const& filename);
51  GIcon(const char** xpm);
52  GIcon(DrawFun, GColor& fg, GColor& bg);
53  GIcon(GIconValue const& value);
54  GIcon* clone(bool copy_value) const override;
55 
58  GPropRef operator~() {return GPropRef(*this);}
59 
60  using GType = GPropType_<GIcon,GProp>;
61  static GType& Type();
62  GType& type() const override {return Type();}
63 
64  void apply(Gadget*, GRender&, Specif) override;
65  void updateGadget(Gadget&) override;
66  static void drawHArrow(GRenderGraphics& g, GRect const& frame,
67  float lx, float rx, float ty, float by);
68  static void drawVArrow(GRenderGraphics& g, GRect const& frame,
69  float lx, float rx, float ty, float by);
70 };
71 
74 inline GIcon& Icon() {return *new GIcon();}
75 inline GIcon& Icon(GString const& filename) {return *new GIcon(filename);}
77 
78 }
79 #endif