neoGFX
Cross-platform C++ app/game engine
Loading...
Searching...
No Matches
framed_widget.ipp
Go to the documentation of this file.
1// framed_widget.ipp
2/*
3 neogfx C++ App/Game Engine
4 Copyright (c) 2023 Leigh Johnston. All Rights Reserved.
5
6 This program is free software: you can redistribute it and / or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
18*/
19
20#pragma once
21
22#include <neogfx/neogfx.hpp>
24
25namespace neogfx
26{
27 template <typename Base>
29 {
30 return neogfx::border{ effective_frame_width(), effective_frame_width(), effective_frame_width(), effective_frame_width() };
31 }
32
33 template <typename Base>
35 {
36#ifdef NEOGFX_DEBUG
37 if (debug::renderItem == this)
38 {
39 aGc.flush();
40 service<debug::logger>() << neolib::logger::severity::Debug << typeid(*this).name() << "::paint_non_client(), frame_color: " << frame_color() << endl;
41 }
42#endif // NEOGFX_DEBUG
43
44 if (!has_frame_radius())
45 base_type::paint_non_client(aGc);
46
47 switch (iStyle)
48 {
51 default:
52 break;
54 break;
56 break;
59 if (!has_frame_radius())
60 aGc.draw_rect(rect{ point{ 0.0, 0.0 }, base_type::as_widget().non_client_rect().extents() }, pen{ frame_color(), effective_frame_width() });
61 else
62 aGc.draw_rounded_rect(rect{ point{ 0.0, 0.0 }, base_type::as_widget().non_client_rect().extents() }, frame_radius(), pen{ frame_color(), effective_frame_width() },
63 base_type::as_widget().has_background_color() || !base_type::as_widget().background_is_transparent() ?
64 brush{ base_type::as_widget().background_color().with_combined_alpha(base_type::as_widget().has_background_opacity() ? base_type::as_widget().background_opacity() : 1.0) } : brush{});
65 break;
67 {
68 rect rectBorder{ point{ 0.0, 0.0 }, base_type::as_widget().non_client_rect().extents() };
69 rectBorder.deflate(line_width(), line_width());
70 aGc.draw_rect(rectBorder, pen(inner_frame_color(), line_width()));
71 rectBorder.inflate(line_width(), line_width());
72 aGc.draw_rect(rectBorder, pen(frame_color(), line_width()));
73 }
74 break;
76 break;
78 break;
80 break;
82 break;
84 break;
85 }
86 }
87
88 template <typename Base>
90 {
91 if (iStyle != aStyle)
92 {
93 iStyle = aStyle;
94 base_type::as_widget().update_layout();
95 }
96 }
97
98 template <typename Base>
100 {
101 return iFrameColor != std::nullopt;
102 }
103
104 template <typename Base>
106 {
107 if (has_frame_color())
108 return *iFrameColor;
109 else
110 return base_type::as_widget().background_color().shaded(0x20);
111 }
112
113 template <typename Base>
115 {
116 iFrameColor = aFrameColor;
117 base_type::as_widget().update(true);
118 }
119
120 template <typename Base>
122 {
123 if (iStyle != frame_style::ContainerFrame)
124 return frame_color();
125 else
126 return (base_type::as_widget().has_base_color() ? base_type::as_widget().base_color() : base_type::as_widget().container_background_color()).lighter(0x40);
127 }
129 template <typename Base>
132 return iFrameRadius != std::nullopt;
135 template <typename Base>
137 {
138 if (has_frame_radius())
139 return *iFrameRadius;
140 else
141 return vec4{};
142 }
143
144 template <typename Base>
146 {
147 iFrameRadius = aFrameRadius;
148 base_type::as_widget().update(true);
149 }
150
151 template <typename Base>
153 {
154 return units_converter{ *this }.from_device_units(iLineWidth);
155 }
156
157 template <typename Base>
159 {
160 switch (iStyle)
161 {
163 default:
164 return 0.0;
168 return line_width();
171 return line_width() * 2.0;
175 return line_width() * 3.0;
179 return line_width();
180 }
181 }
182}
return_type shaded(view_component aDelta) const
Definition color.inl:151
virtual bool has_frame_color() const
neogfx::border border() const override
virtual void set_frame_color(const optional_color &aFrameColor=optional_color{})
virtual color inner_frame_color() const
void paint_non_client(i_graphics_context &aGc) const override
void set_frame_style(frame_style aStyle)
virtual bool has_frame_radius() const
virtual vec4 frame_radius() const
dimension line_width() const
virtual color frame_color() const
virtual void set_frame_radius(const optional_vec4 &aFrameRadius=optional_vec4{})
dimension effective_frame_width() const
virtual void draw_rounded_rect(const rect &aRect, const vec4 &aRadius, const pen &aPen, const brush &aFill=brush{}) const =0
virtual void flush() const =0
virtual void draw_rect(const rect &aRect, const pen &aPen, const brush &aFill=brush{}) const =0
vector2 from_device_units(const vector2 &aValue) const
default_geometry_value_type dimension