cmdfx 0.3.2
Lightweight game engine for your terminal
Loading...
Searching...
No Matches
scenes.hpp
Go to the documentation of this file.
1
11#pragma once
12
13extern "C" {
14#include "cmdfx/core/scenes.h"
15#include "cmdfx/ui/scenes.h"
16#include <stdlib.h>
17}
18
19#include "cmdfx/core/scenes.hpp"
20#include "cmdfx/ui/button.hpp"
21#include <memory>
22#include <vector>
23
24namespace CmdFX
25{
26
27class SceneButtons final {
28 private:
29 int sceneUid;
30
31 public:
32 SceneButtons(int uid) : sceneUid(uid) {
33 }
34 SceneButtons(const Scene& scene) : sceneUid(scene.getUniqueId()) {
35 }
36 ~SceneButtons() {
37 Scene_removeAllButtons(sceneUid);
38 }
39
45 std::vector<std::unique_ptr<Button>> getButtons() {
46 CmdFX_Button** buttons = Scene_getButtons(sceneUid);
47 int count = Scene_getButtonsCount(sceneUid);
48
49 std::vector<std::unique_ptr<Button>> buttonList;
50 buttonList.reserve(count);
51
52 for (int i = 0; i < count; i++) {
53 if (buttons[i] != nullptr) {
54 buttonList.emplace_back(std::make_unique<Button>(buttons[i]));
55 }
56 }
57
58 return buttonList;
59 }
60
61 std::vector<int> getButtonCoordinates(int index, Button& button) {
62 int* coords = Scene_getButtonCoordinates(sceneUid, button.getButton());
63 if (coords == nullptr) return {-1, -1};
64
65 std::vector<int> coordinates = {coords[0], coords[1]};
66 return coordinates;
67 }
68
69 int addButton(Button& button, int x, int y) {
70 return Scene_addButton(sceneUid, button.getButton(), x, y);
71 }
72
73 int removeButton(Button& button) {
74 return Scene_removeButton(sceneUid, button.getButton());
75 }
76
77 int removeButtonAt(int x, int y) {
78 return Scene_removeButtonAt(sceneUid, x, y);
79 }
80
81 int removeAllButtons() {
82 return Scene_removeAllButtons(sceneUid);
83 }
84};
85
86} // namespace CmdFX
C++ Extensions for CmdFX Button UI.
A C++ wrapper around the CmdFX_Button struct.
Definition button.hpp:35
std::vector< std::unique_ptr< Button > > getButtons()
Gets the buttons in the scene.
Definition scenes.hpp:45
A C++ wrapper around a CmdFX_Scene struct.
Definition scenes.hpp:33
int getUniqueId() const
Gets the unique identifier of the scene.
Definition scenes.hpp:99
Scenes API for CmdFX.
C++ Extensions for the CmdFX Scenes API.
Primary namespace for CmdFX.
Definition cmdfx.hpp:26
Represents a CmdFX button.
Definition button.h:45
UI extensions for Scenes in CmdFX.
CmdFX_Button ** Scene_getButtons(int uid)
Gets the buttons of a scene.
int Scene_getButtonsCount(int uid)
Gets the number of buttons in a scene.
int Scene_removeButtonAt(int uid, int x, int y)
Removes a button from a scene at the specified coordinates.
int Scene_removeAllButtons(int uid)
Removes all buttons from a scene.
int Scene_removeButton(int uid, CmdFX_Button *button)
Removes a button from a scene.
int Scene_addButton(int uid, CmdFX_Button *button, int x, int y)
Adds a button to a scene.
int * Scene_getButtonCoordinates(int uid, CmdFX_Button *button)
Gets the coordinates of a button in a scene.