iPlug2 - C++ Audio Plug-in Framework
Loading...
Searching...
No Matches
IGraphicsAccessibility.h
Go to the documentation of this file.
1/*
2 ==============================================================================
3
4 This file is part of the iPlug 2 library. Copyright (C) the iPlug 2 developers.
5
6 See LICENSE.txt for more info.
7
8 ==============================================================================
9*/
10
11#pragma once
12
19#ifdef IGRAPHICS_ACCESSKIT
20
21#include <atomic>
22#include <mutex>
23#include <vector>
24#include <unordered_map>
25
26#include "accesskit.h"
27
28#include "IGraphicsStructs.h"
29
30BEGIN_IPLUG_NAMESPACE
31BEGIN_IGRAPHICS_NAMESPACE
32
33class IGraphics;
34class IControl;
35
40class IGraphicsAccessibility
41{
42public:
43 IGraphicsAccessibility(IGraphics& graphics);
44 virtual ~IGraphicsAccessibility();
45
46 IGraphicsAccessibility(const IGraphicsAccessibility&) = delete;
47 IGraphicsAccessibility& operator=(const IGraphicsAccessibility&) = delete;
48
50 void ProcessActions();
51
54 void OnFrame(bool controlsDirty);
55
57 static accesskit_tree_update* ActivationHandler(void* pUserData);
58
60 static void ActionHandler(accesskit_action_request* pRequest, void* pUserData);
61
62protected:
64 virtual void UpdateIfActive(accesskit_tree_update_factory factory, void* pUserData) = 0;
65
67 virtual double GetRootScale() const;
68
71 void RequestFullUpdate();
72
74 void SetInactive();
75
76 IGraphics& mGraphics;
77
78private:
79 struct Node
80 {
81 accesskit_node_id id = 0;
82 IAccessibleNode info;
83 std::vector<accesskit_node_id> children;
84 double scale = 0.; // Only used for the root node
85 bool modal = false; // The first node of the modal control \see IGraphics::SetModalControl()
86 };
87
88 struct Action
89 {
90 accesskit_action action;
91 accesskit_node_id target;
92 bool hasValue = false;
93 double value = 0.;
94 };
95
96 static constexpr accesskit_node_id kRootId = 1;
97 static constexpr int kNodeIdxBits = 16;
98
99 static accesskit_tree_update* UpdateFactory(void* pUserData);
100
101 void BuildSnapshot(std::vector<Node>& nodes, accesskit_node_id& focus);
102 accesskit_tree_update* MakeUpdate(bool full);
103 accesskit_node* MakeNode(const Node& node) const;
104 uint32_t GetControlId(IControl* pControl);
105 IControl* GetControlForNode(accesskit_node_id id, int& nodeIdx) const;
106
107 std::vector<Node> mNodes; // The nodes that were last sent to the adapter
108 std::unordered_map<IControl*, uint32_t> mControlIds;
109 uint32_t mNextControlId = 1;
110 std::atomic<bool> mActive { false };
111 std::atomic<bool> mUpdateRequested { false };
112
113 std::mutex mActionMutex;
114 std::vector<Action> mActions;
115};
116
117END_IGRAPHICS_NAMESPACE
118END_IPLUG_NAMESPACE
119
120#endif // IGRAPHICS_ACCESSKIT
The lowest level base class of an IGraphics control.
Definition: IControl.h:49
The lowest level base class of an IGraphics context.
Definition: IGraphics.h:87
Used to describe a control (or a part of a control) to assistive technology.