-
Notifications
You must be signed in to change notification settings - Fork 111
Expand file tree
/
Copy pathscripted_object.hpp
More file actions
79 lines (75 loc) · 2.56 KB
/
Copy pathscripted_object.hpp
File metadata and controls
79 lines (75 loc) · 2.56 KB
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
#ifndef _RIVE_SCRIPTED_OBJECT_HPP_
#define _RIVE_SCRIPTED_OBJECT_HPP_
#include "rive/assets/file_asset_referencer.hpp"
#include "rive/assets/script_asset.hpp"
#include "rive/custom_property.hpp"
#include "rive/custom_property_container.hpp"
#include "rive/refcnt.hpp"
#include "rive/generated/assets/script_asset_base.hpp"
#ifdef WITH_RIVE_SCRIPTING
#include "rive/lua/scripting_vm.hpp"
#endif
#include <stdio.h>
namespace rive
{
class Artboard;
class Component;
class DataContext;
class ViewModelInstanceValue;
class DataBindContainer;
class ScriptedObject : public FileAssetReferencer,
public CustomPropertyContainer,
public OptionalScriptedMethods
{
protected:
int m_self = 0;
int m_context = 0;
virtual void disposeScriptInputs();
#ifdef WITH_RIVE_SCRIPTING
#ifdef WITH_RIVE_TOOLS
rcp<ScriptingVM> m_vm; // Ref-counted for editor
#else
ScriptingVM* m_vm = nullptr; // Non-owning for runtime
#endif
#endif
private:
rcp<DataContext> m_dataContext = nullptr;
void disposeScriptedContext();
public:
virtual ~ScriptedObject() { scriptDispose(); }
ScriptAsset* scriptAsset() const;
void setArtboardInput(std::string name, Artboard* artboard);
void setBooleanInput(std::string name, bool value);
void setIntegerInput(std::string name, int value);
void setNumberInput(std::string name, float value);
void setStringInput(std::string name, std::string value);
void setViewModelInput(std::string name, ViewModelInstanceValue* value);
void trigger(std::string name);
bool scriptAdvance(float elapsedSeconds);
void scriptUpdate();
void reinit();
virtual void markNeedsUpdate();
virtual rcp<DataContext> dataContext() { return m_dataContext; }
void dataContext(rcp<DataContext> value) { m_dataContext = value; }
#ifdef WITH_RIVE_SCRIPTING
virtual bool scriptInit(ScriptingVM* vm);
lua_State* state() const { return m_vm ? m_vm->state() : nullptr; }
#endif
void scriptDispose();
#ifdef WITH_RIVE_SCRIPTING
static void collectLuaGarbage(lua_State* state);
#endif
virtual bool addScriptedDirt(ComponentDirt value, bool recurse = false) = 0;
void setAsset(rcp<FileAsset> asset) override;
static ScriptedObject* from(Core* object);
virtual ScriptProtocol scriptProtocol() = 0;
int self() { return m_self; }
virtual Component* component() = 0;
virtual ScriptedObject* cloneScriptedObject(DataBindContainer*) const
{
return nullptr;
}
void cloneProperties(CustomPropertyContainer*, DataBindContainer*) const;
};
} // namespace rive
#endif