cmdfx 0.2.1
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 <stdlib.h>
15 #include "cmdfx/core/scenes.h"
16 #include "cmdfx/ui/scenes.h"
17}
18
19#include "cmdfx/core/scenes.hpp"
20#include "cmdfx/ui/button.hpp"
21#include <vector>
22#include <memory>
23
24namespace CmdFX {
25
26 class SceneButtons final {
27 private:
28 int sceneUid;
29
30 public:
31 SceneButtons(int uid) : sceneUid(uid) {}
32 SceneButtons(const Scene& scene) : sceneUid(scene.getUniqueId()) {}
33 ~SceneButtons() { Scene_removeAllButtons(sceneUid); }
34
39 std::vector<std::unique_ptr<Button>> getButtons() {
40 CmdFX_Button** buttons = Scene_getButtons(sceneUid);
41 int count = Scene_getButtonsCount(sceneUid);
42
43 std::vector<std::unique_ptr<Button>> buttonList;
44 buttonList.reserve(count);
45
46 for (int i = 0; i < count; i++) {
47 if (buttons[i] != nullptr) {
48 buttonList.emplace_back(std::make_unique<Button>(buttons[i]));
49 }
50 }
51
52 return buttonList;
53 }
54
55 std::vector<int> getButtonCoordinates(int index, Button& button) {
56 int* coords = Scene_getButtonCoordinates(sceneUid, button.getButton());
57 if (coords == nullptr) return { -1, -1 };
58
59 std::vector<int> coordinates = { coords[0], coords[1] };
60 return coordinates;
61 }
62
63 int addButton(Button& button, int x, int y) {
64 return Scene_addButton(sceneUid, button.getButton(), x, y);
65 }
66
67 int removeButton(Button& button) {
68 return Scene_removeButton(sceneUid, button.getButton());
69 }
70
71 int removeButtonAt(int x, int y) {
72 return Scene_removeButtonAt(sceneUid, x, y);
73 }
74
75 int removeAllButtons() {
76 return Scene_removeAllButtons(sceneUid);
77 }
78 };
79
80}
C++ Extensions for CmdFX Button UI.
A C++ wrapper around the CmdFX_Button struct.
Definition button.hpp:34
std::vector< std::unique_ptr< Button > > getButtons()
Gets the buttons in the scene.
Definition scenes.hpp:39
A C++ wrapper around a CmdFX_Scene struct.
Definition scenes.hpp:32
int getUniqueId() const
Gets the unique identifier of the scene.
Definition scenes.hpp:90
Scenes API for CmdFX.
C++ Extensions for the CmdFX Scenes API.
Primary namespace for CmdFX.
Definition cmdfx.hpp:22
Represents a CmdFX button.
Definition button.h:42
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.