AUI Framework  master
Cross-platform module-based framework for developing C++20 desktop applications
RenderHints.h
1/*
2 * AUI Framework - Declarative UI toolkit for modern C++20
3 * Copyright (C) 2020-2024 Alex2772 and Contributors
4 *
5 * SPDX-License-Identifier: MPL-2.0
6 *
7 * This Source Code Form is subject to the terms of the Mozilla Public
8 * License, v. 2.0. If a copy of the MPL was not distributed with this
9 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 */
11
12#pragma once
13
14#include <glm/glm.hpp>
15#include <AUI/Views.h>
16#include <AUI/Common/AColor.h>
17#include <AUI/GL/gl.h>
18#include "IRenderer.h"
19
20namespace RenderHints {
27 template<aui::invocable Callable>
28 static void pushMask(IRenderer& render, Callable&& maskRenderer) {
29 render.pushMaskBefore();
30 maskRenderer();
31 render.pushMaskAfter();
32 }
33
40 template<aui::invocable Callable>
41 static void popMask(IRenderer& render, Callable&& maskRenderer) {
42 render.popMaskBefore();
43 maskRenderer();
44 render.popMaskAfter();
45 }
46
47 template<aui::invocable Callable>
48 struct PushMask {
49 public:
50 inline explicit PushMask(IRenderer& render, Callable&& maskRenderer) :
51 render(render),
52 maskRenderer(std::forward<Callable>(maskRenderer)) {
53 pushMask(render, std::forward<Callable>(maskRenderer));
54 }
55
56 inline ~PushMask() {
57 popMask(render, std::forward<Callable>(maskRenderer));
58 }
59
60 private:
61 IRenderer& render;
62 Callable maskRenderer;
63 };
64
65 struct PushMatrix {
66 public:
67 inline explicit PushMatrix(IRenderer& render) : render(render), stored(render.getTransform()) {
68 }
69
70 inline ~PushMatrix() {
71 render.setTransformForced(stored);
72 }
73
74 private:
75 IRenderer& render;
76 glm::mat4 stored;
77 };
78
79 struct PushColor {
80 public:
81 inline explicit PushColor(IRenderer& render): render(render), stored(render.getColor()) {
82 }
83
84 inline ~PushColor() {
85 render.setColorForced(stored);
86 }
87
88 private:
89 IRenderer& render;
90 AColor stored;
91 };
92
94 public:
95 inline explicit PushState(IRenderer& render): PushColor(render), PushMatrix(render) {}
96 };
97}
Represents a 4-component floating point color.
Definition: AColor.h:27
Base class for rendering.
Definition: IRenderer.h:149
virtual void popMaskAfter()=0
Switches drawing to the color buffer back from the stencil. Decreases stencil depth.
void setColorForced(const AColor &color)
Sets the color which is multiplied with any brush.
Definition: IRenderer.h:420
virtual void popMaskBefore()=0
Switches drawing to the stencil buffer instead of color buffer.
void setTransformForced(const glm::mat4 &transform)
Sets the transform matrix which is applicable for any figure.
Definition: IRenderer.h:454
virtual void pushMaskAfter()=0
Switches drawing to the color buffer back from the stencil. Increases stencil depth.
virtual void pushMaskBefore()=0
witches drawing to the stencil buffer instead of color buffer.
Definition: RenderHints.h:93
Definition: RenderHints.h:79
Definition: RenderHints.h:48
Definition: RenderHints.h:65