guit  0.1
 All Classes Functions Variables Typedefs Enumerations Friends
grender.hpp
1 //
2 // Core Layer: Gadget Rendering
3 // Guit GUI Toolkit
4 // Copyright © 2019/2020 Eric Lecolinet. All rights reserved.
5 // http://www.telecom-paris.fr/~elc
6 //
7 
8 #ifndef GuitRender_hpp
9 #define GuitRender_hpp
10 #include <ggraphics.hpp>
11 #include <gflow.hpp>
12 #include <gflex.hpp>
13 #include <galign.hpp>
14 #include <ggap.hpp>
15 #include <gpos.hpp>
16 #include <gsize.hpp>
17 #include <gfont.hpp>
18 namespace guit {
19 
20 
23 class GRenderGraphics : public GGraphics {
24 public:
25  GRenderGraphics(GWindow&);
26  bool setClipRect(Gadget&);
27  GRect area_, cliprect_;
28 };
29 
30 
32 class GRender {
33 public:
34  enum {
35  DrawNone = 0, DrawBackground = 1<<0, DrawBorder = 1<<1, DrawText = 1<<2,
36  AddMargin = 1<<2,
37  DrawAll = (DrawBackground | DrawBorder | DrawText | AddMargin)
38  };
39 
40  struct StyleNode {
41  StyleNode() : level_(0), style_(nullptr) {}
42  StyleNode(int level, GStyle* style) : level_(level), style_(style) {}
43  int level_;
44  GStyle* style_;
45  };
46 
47  ~GRender();
48  GRender() = default;
49  GRender(Gadget&, GRender* parent_render);
50  GRender(const Gadget&) = delete;
51 
52  GRender& operator=(GRender const&);
53 
54  Gadget& gadget() {return *obj_;}
55  void print(std::ostream& out);
56 
57  void addCombinator(GStyle*);
58  void applyStyles(Gadget*, GStyle& class_style /*,int pseudo*/);
59  void applyInStyles(StyleNode& asc_style, Gadget*, GStyle& desc_style /*,int pseudo*/);
60 
61  bool paintGadget(GRenderGraphics&, int options);
62  void paintPieBackground(GRenderGraphics&);
63  void paintBox(GRenderGraphics&, GBox&);
64  void drawText(GRenderGraphics&, float offest);
65  void drawHotkey(GRenderGraphics&);
66  void drawIcon(GRenderGraphics&);
67  void drawCaret(GRenderGraphics&, GString const& text,
68  class GFontValue const&, GTextAttributes const*,
69  size_t begline, ssize_t caretpos, bool richtext,
70  float x, float y, float h);
71  void setAutoColor(GRenderGraphics&);
72  void setTextAutoColor(GRenderGraphics&);
73  void setTextAutoColor(GRenderGraphics&, float pos, float offset);
74  static bool formatText(class GFormatValue const&, GString const& from, GString& to);
75 
76  Gadget* obj_{};
77  GRender* parr_{}; // parent_render
78  int level_{};
79  size_t own_inscount_{}, child_inscount_{};
80  std::vector<StyleNode>* instyles_{};
81  GString const* text_{};
82  GString const* tip_{};
83  GString const* hotkey_{};
84  GPoint textpos_;
85  GDim textsize_;
86  GFontValue font_;
87  GFlowValue flow_;
88  GFlexValue flex_;
89  GPosValue pos_;
90  GSizeValue size_;
91  GGapValue gap_;
92  GAlignValue align_;
93  class GFormatValue* format_{};
94  class GRgba const* color_{};
95  class GRgba const* background_{};
96  class GIconValue* icon_{};
97  class GMarginValue* margin_{};
98  class GBorderValue* border_{};
99  GProp::Specif specif[GPropType::RenderCount]{};
100 };
101 
102 }
103 #endif