neoGFX
Cross-platform C++ app/game engine
Loading...
Searching...
No Matches
utility.hpp
Go to the documentation of this file.
1// utility.hpp
2/*
3 neogfx C++ App/Game Engine
4 Copyright (c) 2020 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>
25#include <neogfx/app/i_app.hpp>
26
27namespace neogfx
28{
29 inline texture colored_icon(const texture& aSource, const optional_color& aColor = {})
30 {
31 texture result{ aSource.extents(), 1.0, texture_sampling::Multisample };
32 graphics_context gc{ result };
33 scalar const outline = 4.0;
34 auto const targetRect = aColor ? rect{ point{ outline, outline }, aSource.extents() - size{ outline * 2.0 } } : rect{ point{}, aSource.extents() };
35 if (aColor)
36 {
37 // draw a black outline for a non-text color icon...
38 // todo: provide an easier way to blur any drawing primitive
39 rect const r{ point{}, size{aSource.extents()} };
40 auto pingPongBuffers = create_ping_pong_buffers(gc, aSource.extents(), texture_sampling::Multisample);
41 {
42 scoped_render_target srt{ *pingPongBuffers.buffer1 };
43 pingPongBuffers.buffer1->draw_texture(targetRect, aSource, color::Black);
44 }
45 {
46 scoped_render_target srt{ *pingPongBuffers.buffer2 };
47 pingPongBuffers.buffer2->blur(r, *pingPongBuffers.buffer1, r, outline, blurring_algorithm::Gaussian, 5.0, 1.0);
48 }
49 scoped_render_target srt{ gc };
50 gc.blit(r, *pingPongBuffers.buffer2, r);
51 }
52 scoped_render_target srt{ gc };
53 gc.draw_texture(targetRect, aSource, aColor ? *aColor : service<i_app>().current_style().palette().color(color_role::Text), shader_effect::ColorizeAlpha);
54 return result;
55 };
56}
static const sRGB_color Black
Definition color.hpp:403
size extents() const final
ping_pong_buffers create_ping_pong_buffers(const i_rendering_context &aContext, const size &aExtents, texture_sampling aSampling=texture_sampling::Multisample, const optional_color &aClearColor=color{ vec4{0.0, 0.0, 0.0, 0.0} })
texture colored_icon(const texture &aSource, const optional_color &aColor={})
Definition utility.hpp:29
gui_rect rect
sRGB_color color
Definition color.hpp:1067
basic_point< coordinate > point
basic_size< coordinate > size
double scalar
Definition numerical.hpp:63
Service & service()
Definition services.hpp:113