File: SoundPlugin.h

package info (click to toggle)
freespace2 24.2.0%2Brepack-1
  • links: PTS, VCS
  • area: non-free
  • in suites: forky, sid
  • size: 43,716 kB
  • sloc: cpp: 595,001; ansic: 21,741; python: 1,174; sh: 457; makefile: 248; xml: 181
file content (79 lines) | stat: -rw-r--r-- 2,246 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#pragma once

#include "globalincs/pstypes.h"

// Our Assert conflicts with the definitions inside libRocket
#pragma push_macro("Assert")
#undef Assert

#ifdef __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wshadow"
#endif

#include <Rocket/Core.h>
#include <Rocket/Core/Plugin.h>

#ifdef __GNUC__
#pragma GCC diagnostic pop
#endif

#pragma pop_macro("Assert")

namespace scpui {

class SoundPropertyParser : public Rocket::Core::PropertyParser {
	bool ParseValue(Rocket::Core::Property& property, const Rocket::Core::String& value,
	                const Rocket::Core::ParameterMap& parameters) const override;
	void Release() override;
};

class SoundPlugin : public Rocket::Core::Plugin {
	class SoundEventHandler : public Rocket::Core::EventListener {
	  public:
		void ProcessEvent(Rocket::Core::Event& event) override;
	};

	std::unique_ptr<SoundEventHandler> _event_handler;

	float _last_scrollchange_time = -1.0f;

	static SoundPlugin* _instance;
	static SCP_vector<SCP_string> _event_types;

  public:
	SoundPlugin();
	~SoundPlugin() override;

	SoundPlugin(const SoundPlugin&) = delete;
	SoundPlugin& operator=(const SoundPlugin&) = delete;

	SoundPlugin(SoundPlugin&&) noexcept = delete;
	SoundPlugin& operator=(SoundPlugin&&) noexcept = delete;

	void OnShutdown() override;
	int GetEventClasses() override;

	void OnElementCreate(Rocket::Core::Element* element) override;
	void OnElementDestroy(Rocket::Core::Element* element) override;

	/**
	 * @brief Plays a element specific sound
	 *
	 * This can be used for implementing context specific sounds for specific elements where the actual sounds are
	 * defined by the interface designer in the RCSS.
	 *
	 * @param element The element to play the sound for
	 * @param event The event identification
	 * @param state The state for which the sound should be played. May be empty in which case the default sound is
	 * used.
	 * @return @c true if a sound was played, @c false otherwise
	 */
	bool PlayElementSound(Rocket::Core::Element* element, const Rocket::Core::String& event,
	                      const Rocket::Core::String& state = "");

	static const SCP_vector<SCP_string>& getEventTypes();
	static SoundPlugin* instance();
};

} // namespace scpui