MCPcopy Create free account
hub / github.com/OpenImageDebugger/OpenImageDebugger / Component

Class Component

src/visualization/components/component.h:40–100  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

38class GameObject;
39
40class Component {
41 public:
42 Component(const std::shared_ptr<GameObject>& game_object,
43 const std::shared_ptr<RenderCanvas>& gl_canvas);
44
45 [[nodiscard]] virtual bool initialize();
46
47 [[nodiscard]] virtual bool buffer_update();
48
49 [[nodiscard]] virtual bool post_buffer_update();
50
51 [[nodiscard]] virtual int render_index() const;
52
53 // Called after all components are initialized
54 [[nodiscard]] virtual bool post_initialize();
55
56 virtual void update() = 0;
57
58 virtual void draw(const mat4& projection, const mat4& viewInv) = 0;
59
60 ///
61 // Events
62 virtual EventProcessCode key_press_event(int /* key_code */) {
63 return EventProcessCode::IGNORED;
64 }
65
66 virtual void mouse_drag_event(int /* mouse_x */, int /* mouse_y */) {
67 // Do nothing
68 }
69
70 virtual void mouse_move_event(int /* mouse_x */, int /* mouse_y */) {
71 // Do nothing
72 }
73
74 virtual ~Component() noexcept;
75
76 [[nodiscard]] std::shared_ptr<GameObject> game_object() const noexcept {
77 return game_object_.lock();
78 }
79
80 [[nodiscard]] GameObject& game_object_ref() const {
81 auto obj = game_object_.lock();
82 assert(obj && "GameObject has been destroyed");
83 return *obj;
84 }
85
86 [[nodiscard]] std::shared_ptr<RenderCanvas> gl_canvas() const noexcept {
87 return gl_canvas_.lock();
88 }
89
90 [[nodiscard]] RenderCanvas& gl_canvas_ref() const {
91 const auto canvas = gl_canvas_.lock();
92 assert(canvas && "RenderCanvas has been destroyed");
93 return *canvas;
94 }
95
96 public:
97 std::weak_ptr<GameObject> game_object_;

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected