xtd - Reference Guide  0.2.0
Modern c++17/20 framework to create console, GUI and unit test applications on Windows, macOS, Linux, iOS and android.
renderer.h
Go to the documentation of this file.
1 #pragma once
5 #include <optional>
6 #include <xtd/delegate.h>
7 #include <xtd/object.h>
8 #include <xtd/ustring.h>
9 #include <xtd/drawing/color.h>
10 #include <xtd/drawing/font.h>
11 #include <xtd/drawing/graphics.h>
12 #include <xtd/drawing/image.h>
13 #include <xtd/drawing/rectangle.h>
14 #include "../forms_export.h"
15 #include "text_format_flags.h"
19 
21 namespace xtd {
23  namespace forms {
30  class forms_export_ renderer : public object {
31  public:
32  using button_renderer = xtd::delegate<void(xtd::drawing::graphics, const xtd::drawing::rectangle&, const xtd::ustring&, const xtd::drawing::font&, xtd::forms::text_format_flags, const xtd::drawing::image&, const xtd::drawing::rectangle&, bool focused, xtd::forms::visual_styles::push_button_state, const std::optional<xtd::drawing::color>&, const std::optional<xtd::drawing::color>&)>;
33  using check_box_renderer = xtd::delegate<void(xtd::drawing::graphics, const xtd::drawing::rectangle&, const xtd::ustring&, const xtd::drawing::font&, xtd::forms::text_format_flags, const xtd::drawing::image&, const xtd::drawing::rectangle&, bool focused, xtd::forms::visual_styles::check_box_state, const std::optional<xtd::drawing::color>&, const std::optional<xtd::drawing::color>&)>;
34  using radio_button_renderer = xtd::delegate<void(xtd::drawing::graphics, const xtd::drawing::rectangle&, const xtd::ustring&, const xtd::drawing::font&, xtd::forms::text_format_flags, const xtd::drawing::image&, const xtd::drawing::rectangle&, bool focused, xtd::forms::visual_styles::radio_button_state, const std::optional<xtd::drawing::color>&, const std::optional<xtd::drawing::color>&)>;
35 
36  renderer() = default;
37  explicit renderer(const xtd::ustring& name) : name_(name) {}
39  renderer(const renderer&) = default;
40  renderer& operator=(const renderer&) = default;
41  bool operator==(const renderer& value) const {return name_ == value.name_;}
42  bool operator!=(const renderer& value) const {return !operator==(value);}
43  friend std::ostream& operator<<(std::ostream& os, const renderer& theme) noexcept {return os << theme.to_string();}
45 
46  virtual const xtd::ustring& name() const {return name_;}
47  renderer& name(const xtd::ustring& name) {
48  name_ = name;
49  return *this;
50  }
51 
52  button_renderer button_render() const {return button_renderer_;}
53  void button_render(button_renderer button_renderer) {button_renderer_ = button_renderer;}
54 
55  check_box_renderer check_box_render() const {return check_box_renderer_;}
56  void check_box_render(check_box_renderer check_box_renderer) {check_box_renderer_ = check_box_renderer;}
57 
58  radio_button_renderer radio_button_render() const {return radio_button_renderer_;}
59  void radio_button_render(radio_button_renderer radio_button_renderer) {radio_button_renderer_ = radio_button_renderer;}
60 
61  void draw_button(xtd::drawing::graphics g, const xtd::drawing::rectangle& bounds, const xtd::ustring& text, const xtd::drawing::font& font, xtd::forms::text_format_flags flags, const xtd::drawing::image& image, const xtd::drawing::rectangle& image_bounds, bool focused, xtd::forms::visual_styles::push_button_state state, const std::optional<xtd::drawing::color>& back_color, const std::optional<xtd::drawing::color>& fore_color) {button_renderer_(g, bounds, text, font, flags, image, image_bounds, focused, state, back_color, fore_color);}
62  void draw_check_box(xtd::drawing::graphics g, const xtd::drawing::rectangle& bounds, const xtd::ustring& text, const xtd::drawing::font& font, xtd::forms::text_format_flags flags, const xtd::drawing::image& image, const xtd::drawing::rectangle& image_bounds, bool focused, xtd::forms::visual_styles::check_box_state state, const std::optional<xtd::drawing::color>& back_color, const std::optional<xtd::drawing::color>& fore_color) {check_box_renderer_(g, bounds, text, font, flags, image, image_bounds, focused, state, back_color, fore_color);}
63  void draw_radio_button(xtd::drawing::graphics g, const xtd::drawing::rectangle& bounds, const xtd::ustring& text, const xtd::drawing::font& font, xtd::forms::text_format_flags flags, const xtd::drawing::image& image, const xtd::drawing::rectangle& image_bounds, bool focused, xtd::forms::visual_styles::radio_button_state state, const std::optional<xtd::drawing::color>& back_color, const std::optional<xtd::drawing::color>& fore_color) {radio_button_renderer_(g, bounds, text, font, flags, image, image_bounds, focused, state, back_color, fore_color);}
64 
65  xtd::ustring to_string() const noexcept override {
66  if (!name_.empty()) return xtd::ustring::format("{}, name: {}", ustring::full_class_name(*this), name_);
68  }
69 
70  static const renderer empty;
71 
72  protected:
73 
74  private:
75  static void default_button_renderer(xtd::drawing::graphics g, const xtd::drawing::rectangle& bounds, const xtd::ustring& text, const xtd::drawing::font& font, xtd::forms::text_format_flags flags, const xtd::drawing::image& image, const xtd::drawing::rectangle& image_bounds, bool focused, xtd::forms::visual_styles::push_button_state state, const std::optional<xtd::drawing::color>& back_color, const std::optional<xtd::drawing::color>& fore_color);
76  static void default_check_box_renderer(xtd::drawing::graphics g, const xtd::drawing::rectangle& bounds, const xtd::ustring& text, const xtd::drawing::font& font, xtd::forms::text_format_flags flags, const xtd::drawing::image& image, const xtd::drawing::rectangle& image_bounds, bool focused, xtd::forms::visual_styles::check_box_state state, const std::optional<xtd::drawing::color>& back_color, const std::optional<xtd::drawing::color>& fore_color);
77  static void default_radio_button_renderer(xtd::drawing::graphics g, const xtd::drawing::rectangle& bounds, const xtd::ustring& text, const xtd::drawing::font& font, xtd::forms::text_format_flags flags, const xtd::drawing::image& image, const xtd::drawing::rectangle& image_bounds, bool focused, xtd::forms::visual_styles::radio_button_state state, const std::optional<xtd::drawing::color>& back_color, const std::optional<xtd::drawing::color>& fore_color);
78 
79  xtd::ustring name_;
80  button_renderer button_renderer_ = button_renderer(default_button_renderer);
81  check_box_renderer check_box_renderer_ = check_box_renderer(default_check_box_renderer);
82  radio_button_renderer radio_button_renderer_ = radio_button_renderer(default_radio_button_renderer);
83  };
84  }
85 }
Defines a particular format for text, including font face, size, and style attributes. This class cannot be inherited.
Definition: font.h:39
Contains xtd::delegate delegate.
radio_button_state
Specifies the visual state of a radio button that is drawn with visual styles.
Definition: radio_button_state.h:20
Contains xtd::forms::visual_styles::radio_button_state enum class.
The xtd namespace contains all fundamental classes to access Hardware, Os, System, and more.
Definition: system_report.h:17
Contains xtd::forms::text_format_flags enum class.
Represents text as a sequence of UTF-8 code units.
Definition: ustring.h:48
Contains xtd::forms::visual_styles::push_button_state enum class.
Definition: theme.h:14
xtd::ustring to_string() const noexcept override
Returns a std::string that represents the current object.
Definition: renderer.h:65
check_box_state
Specifies the visual state of a check box that is drawn with visual styles.
Definition: check_box_state.h:20
Contains xtd::drawing::image class.
Contains xtd::drawing::rectangle class.
Provides control renderers methods.
Definition: renderer.h:30
Stores a set of four integers that represent the location and size of a rectangle.
Definition: rectangle.h:25
Contains xtd::ustring class.
Contains xtd::drawing::color class.
An abstract base class that provides functionality for the bitmap and metafile descended classes...
Definition: image.h:34
Contains xtd::forms::visual_styles::check_box_state enum class.
Contains xtd::object class.
Supports all classes in the xtd class hierarchy and provides low-level services to derived classes...
Definition: object.h:27
static ustring full_class_name()
Gets the fully qualified class name of the objec_t, including the namespace of the objec_t...
Definition: ustring.h:427
push_button_state
Specifies the visual state of a button that is drawn with visual styles.
Definition: push_button_state.h:20
static ustring format(const ustring &fmt, args_t &&... args)
Writes the text representation of the specified arguments list, to string using the specified format ...
Definition: ustring.h:689
The xtd::forms namespace contains classes for creating Windows-based applications that take full adva...
Definition: about_box.h:13
text_format_flags
Specifies the display and layout information for text strings.
Definition: text_format_flags.h:18
Defines an object used to draw lines and curves. This class cannot be inherited.
Definition: graphics.h:48
Contains xtd::drawing::graphics class.
Contains xtd::drawing::font class.