mini-arcade-native-backend 0.2.3__tar.gz → 0.3.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (25) hide show
  1. mini_arcade_native_backend-0.3.0/.changelog_section +9 -0
  2. {mini_arcade_native_backend-0.2.3 → mini_arcade_native_backend-0.3.0}/.github/workflows/ci.yml +1 -1
  3. mini_arcade_native_backend-0.3.0/.github/workflows/release-finalize.yml +20 -0
  4. mini_arcade_native_backend-0.3.0/.version_to_tag +1 -0
  5. mini_arcade_native_backend-0.3.0/.vscode/settings.json +53 -0
  6. {mini_arcade_native_backend-0.2.3 → mini_arcade_native_backend-0.3.0}/CHANGELOG.md +9 -0
  7. {mini_arcade_native_backend-0.2.3 → mini_arcade_native_backend-0.3.0}/CMakeLists.txt +2 -1
  8. {mini_arcade_native_backend-0.2.3 → mini_arcade_native_backend-0.3.0}/PKG-INFO +1 -1
  9. {mini_arcade_native_backend-0.2.3 → mini_arcade_native_backend-0.3.0}/cpp/bindings.cpp +20 -4
  10. {mini_arcade_native_backend-0.2.3 → mini_arcade_native_backend-0.3.0}/cpp/engine.cpp +75 -2
  11. {mini_arcade_native_backend-0.2.3 → mini_arcade_native_backend-0.3.0}/cpp/engine.h +8 -0
  12. {mini_arcade_native_backend-0.2.3 → mini_arcade_native_backend-0.3.0}/pyproject.toml +1 -1
  13. {mini_arcade_native_backend-0.2.3 → mini_arcade_native_backend-0.3.0}/src/mini_arcade_native_backend/__init__.py +22 -1
  14. mini_arcade_native_backend-0.2.3/.changelog_section +0 -4
  15. mini_arcade_native_backend-0.2.3/.version_to_tag +0 -1
  16. mini_arcade_native_backend-0.2.3/.vscode/settings.json +0 -5
  17. {mini_arcade_native_backend-0.2.3 → mini_arcade_native_backend-0.3.0}/.github/workflows/create-release-branch.yml +0 -0
  18. {mini_arcade_native_backend-0.2.3 → mini_arcade_native_backend-0.3.0}/.github/workflows/release-publish.yml +0 -0
  19. {mini_arcade_native_backend-0.2.3 → mini_arcade_native_backend-0.3.0}/.gitignore +0 -0
  20. {mini_arcade_native_backend-0.2.3 → mini_arcade_native_backend-0.3.0}/LICENSE +0 -0
  21. {mini_arcade_native_backend-0.2.3 → mini_arcade_native_backend-0.3.0}/README.md +0 -0
  22. {mini_arcade_native_backend-0.2.3 → mini_arcade_native_backend-0.3.0}/examples/native_backend_demo.py +0 -0
  23. {mini_arcade_native_backend-0.2.3 → mini_arcade_native_backend-0.3.0}/poetry.lock +0 -0
  24. {mini_arcade_native_backend-0.2.3 → mini_arcade_native_backend-0.3.0}/poetry.toml +0 -0
  25. {mini_arcade_native_backend-0.2.3 → mini_arcade_native_backend-0.3.0}/tests/test_init.py +0 -0
@@ -0,0 +1,9 @@
1
+ ## [0.3.0] - 2025-12-05
2
+
3
+ ### Added
4
+ - add text rendering support with SDL2_ttf integration
5
+
6
+ ### Other
7
+ - Merge pull request #7 from alexsc6955/feature/text_support
8
+ - Merge release/0.2 into develop
9
+
@@ -19,7 +19,7 @@ jobs:
19
19
  with:
20
20
  project-name: "mini-arcade-native-backend"
21
21
  lint-path: "src/mini_arcade_native_backend"
22
- apt-deps: "libsdl2-dev"
22
+ apt-deps: "libsdl2-dev libsdl2-ttf-dev"
23
23
  secrets:
24
24
  SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}
25
25
  SLACK_CHANNEL_ID: ${{ secrets.SLACK_CHANNEL_ID }}
@@ -0,0 +1,20 @@
1
+ name: Finalize Release
2
+
3
+ permissions:
4
+ contents: write
5
+
6
+ on:
7
+ workflow_dispatch:
8
+ inputs:
9
+ release_branch_suffix:
10
+ description: "Release suffix (e.g. 0.6 for branch release/0.6)"
11
+ required: true
12
+ type: string
13
+
14
+ jobs:
15
+ finalize-release:
16
+ uses: trivox-io/trivox-ci/.github/workflows/finalize-release.yml@main
17
+ with:
18
+ release_branch_suffix: ${{ inputs.release_branch_suffix }}
19
+ main_branch: "main"
20
+ develop_branch: "develop"
@@ -0,0 +1 @@
1
+ 0.3.0
@@ -0,0 +1,53 @@
1
+ {
2
+ "files.associations": {
3
+ "system_error": "cpp",
4
+ "atomic": "cpp",
5
+ "bit": "cpp",
6
+ "cctype": "cpp",
7
+ "charconv": "cpp",
8
+ "clocale": "cpp",
9
+ "cmath": "cpp",
10
+ "compare": "cpp",
11
+ "concepts": "cpp",
12
+ "cstddef": "cpp",
13
+ "cstdint": "cpp",
14
+ "cstdio": "cpp",
15
+ "cstdlib": "cpp",
16
+ "cstring": "cpp",
17
+ "ctime": "cpp",
18
+ "cwchar": "cpp",
19
+ "exception": "cpp",
20
+ "format": "cpp",
21
+ "initializer_list": "cpp",
22
+ "ios": "cpp",
23
+ "iosfwd": "cpp",
24
+ "iostream": "cpp",
25
+ "istream": "cpp",
26
+ "iterator": "cpp",
27
+ "limits": "cpp",
28
+ "locale": "cpp",
29
+ "memory": "cpp",
30
+ "new": "cpp",
31
+ "ostream": "cpp",
32
+ "stdexcept": "cpp",
33
+ "streambuf": "cpp",
34
+ "tuple": "cpp",
35
+ "type_traits": "cpp",
36
+ "typeinfo": "cpp",
37
+ "utility": "cpp",
38
+ "vector": "cpp",
39
+ "xfacet": "cpp",
40
+ "xiosbase": "cpp",
41
+ "xlocale": "cpp",
42
+ "xlocbuf": "cpp",
43
+ "xlocinfo": "cpp",
44
+ "xlocmes": "cpp",
45
+ "xlocmon": "cpp",
46
+ "xlocnum": "cpp",
47
+ "xloctime": "cpp",
48
+ "xmemory": "cpp",
49
+ "xstring": "cpp",
50
+ "xtr1common": "cpp",
51
+ "xutility": "cpp"
52
+ }
53
+ }
@@ -6,6 +6,15 @@ This project adheres to [Semantic Versioning](https://semver.org/).
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [0.3.0] - 2025-12-05
10
+
11
+ ### Added
12
+ - add text rendering support with SDL2_ttf integration
13
+
14
+ ### Other
15
+ - Merge pull request #7 from alexsc6955/feature/text_support
16
+ - Merge release/0.2 into develop
17
+
9
18
  ## [0.2.3] - 2025-12-04
10
19
 
11
20
  - Internal changes only.
@@ -9,6 +9,7 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
9
9
 
10
10
  find_package(pybind11 CONFIG REQUIRED)
11
11
  find_package(SDL2 CONFIG REQUIRED)
12
+ find_package(SDL2_ttf CONFIG REQUIRED)
12
13
 
13
14
  set(TARGET_NAME _native)
14
15
 
@@ -18,7 +19,7 @@ pybind11_add_module(${TARGET_NAME}
18
19
  cpp/engine.cpp
19
20
  )
20
21
 
21
- target_link_libraries(${TARGET_NAME} PRIVATE SDL2::SDL2)
22
+ target_link_libraries(${TARGET_NAME} PRIVATE SDL2::SDL2 SDL2_ttf::SDL2_ttf)
22
23
 
23
24
  # Install the compiled extension into the Python package directory
24
25
  # so it ends up as mini_arcade_native_backend/_native.*.pyd
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: mini-arcade-native-backend
3
- Version: 0.2.3
3
+ Version: 0.3.0
4
4
  Summary: Native SDL2 backend for mini-arcade-core using SDL2 + pybind11.
5
5
  Author-Email: Santiago Rincon <rincores@gmail.com>
6
6
  License: Copyright (c) 2025 Santiago Rincón
@@ -25,13 +25,29 @@ PYBIND11_MODULE(_native, m) {
25
25
  py::class_<mini::Engine>(m, "Engine")
26
26
  .def(py::init<>())
27
27
  .def("init", &mini::Engine::init,
28
- py::arg("width"), py::arg("height"), py::arg("title"))
28
+ py::arg("width"), py::arg("height"), py::arg("title"))
29
+
29
30
  .def("begin_frame", &mini::Engine::begin_frame)
30
31
  .def("end_frame", &mini::Engine::end_frame)
32
+
31
33
  .def("draw_rect", &mini::Engine::draw_rect,
32
- py::arg("x"), py::arg("y"), py::arg("w"), py::arg("h"))
34
+ py::arg("x"), py::arg("y"), py::arg("w"), py::arg("h"))
33
35
  .def("draw_sprite", &mini::Engine::draw_sprite,
34
- py::arg("texture_id"), py::arg("x"), py::arg("y"),
35
- py::arg("w"), py::arg("h"))
36
+ py::arg("texture_id"), py::arg("x"), py::arg("y"),
37
+ py::arg("w"), py::arg("h"))
38
+
39
+ .def("load_font", &mini::Engine::load_font,
40
+ py::arg("path"), py::arg("pt_size"))
41
+
42
+ .def(
43
+ "draw_text",
44
+ &mini::Engine::draw_text,
45
+ py::arg("text"),
46
+ py::arg("x"),
47
+ py::arg("y"),
48
+ py::arg("r"),
49
+ py::arg("g"),
50
+ py::arg("b")
51
+ )
36
52
  .def("poll_events", &mini::Engine::poll_events);
37
53
  }
@@ -7,13 +7,19 @@ namespace mini {
7
7
 
8
8
  Engine::Engine()
9
9
  : window_(nullptr),
10
- renderer_(nullptr),
11
- initialized_(false)
10
+ renderer_(nullptr),
11
+ initialized_(false),
12
+ font_(nullptr)
12
13
  {
13
14
  }
14
15
 
15
16
  Engine::~Engine()
16
17
  {
18
+ if (font_ != nullptr) {
19
+ TTF_CloseFont(font_);
20
+ font_ = nullptr;
21
+ }
22
+
17
23
  if (renderer_ != nullptr) {
18
24
  SDL_DestroyRenderer(renderer_);
19
25
  renderer_ = nullptr;
@@ -40,6 +46,12 @@ namespace mini {
40
46
  throw std::runtime_error(std::string("SDL_Init Error: ") + SDL_GetError());
41
47
  }
42
48
 
49
+ if (TTF_Init() != 0) {
50
+ std::string msg = std::string("TTF_Init Error: ") + TTF_GetError();
51
+ SDL_Quit();
52
+ throw std::runtime_error(msg);
53
+ }
54
+
43
55
  window_ = SDL_CreateWindow(
44
56
  title,
45
57
  SDL_WINDOWPOS_CENTERED,
@@ -51,6 +63,7 @@ namespace mini {
51
63
 
52
64
  if (window_ == nullptr) {
53
65
  std::string msg = std::string("SDL_CreateWindow Error: ") + SDL_GetError();
66
+ TTF_Quit();
54
67
  SDL_Quit();
55
68
  throw std::runtime_error(msg);
56
69
  }
@@ -65,6 +78,7 @@ namespace mini {
65
78
  std::string msg = std::string("SDL_CreateRenderer Error: ") + SDL_GetError();
66
79
  SDL_DestroyWindow(window_);
67
80
  window_ = nullptr;
81
+ TTF_Quit();
68
82
  SDL_Quit();
69
83
  throw std::runtime_error(msg);
70
84
  }
@@ -114,6 +128,65 @@ namespace mini {
114
128
  // TODO: placeholder for later texture management.
115
129
  }
116
130
 
131
+ // Load a TTF font from file at specified point size.
132
+ void Engine::load_font(const char* path, int pt_size)
133
+ {
134
+ if (!initialized_) {
135
+ throw std::runtime_error("Engine::init must be called before load_font");
136
+ }
137
+
138
+ if (font_ != nullptr) {
139
+ TTF_CloseFont(font_);
140
+ font_ = nullptr;
141
+ }
142
+
143
+ font_ = TTF_OpenFont(path, pt_size);
144
+ if (!font_) {
145
+ std::string msg = std::string("TTF_OpenFont Error: ") + TTF_GetError();
146
+ throw std::runtime_error(msg);
147
+ }
148
+ }
149
+
150
+ // Draw text at specified position.
151
+ void Engine::draw_text(const char* text, int x, int y, int r, int g, int b)
152
+ {
153
+ if (!initialized_ || renderer_ == nullptr || font_ == nullptr) {
154
+ return;
155
+ }
156
+
157
+ // clamp a bit to be safe
158
+ auto clamp = [](int v) {
159
+ if (v < 0) return 0;
160
+ if (v > 255) return 255;
161
+ return v;
162
+ };
163
+
164
+ SDL_Color color = { (Uint8)clamp(r), (Uint8)clamp(g), (Uint8)clamp(b), 255 }; // white text
165
+ SDL_Surface* surface = TTF_RenderUTF8_Blended(font_, text, color);
166
+ if (!surface) {
167
+ std::cerr << "TTF_RenderUTF8_Blended Error: " << TTF_GetError() << std::endl;
168
+ return;
169
+ }
170
+
171
+ SDL_Texture* texture = SDL_CreateTextureFromSurface(renderer_, surface);
172
+ if (!texture) {
173
+ std::cerr << "SDL_CreateTextureFromSurface Error: " << SDL_GetError() << std::endl;
174
+ SDL_FreeSurface(surface);
175
+ return;
176
+ }
177
+
178
+ SDL_Rect dstRect;
179
+ dstRect.x = x;
180
+ dstRect.y = y;
181
+ dstRect.w = surface->w;
182
+ dstRect.h = surface->h;
183
+
184
+ SDL_FreeSurface(surface);
185
+
186
+ SDL_RenderCopy(renderer_, texture, nullptr, &dstRect);
187
+ SDL_DestroyTexture(texture);
188
+ }
189
+
117
190
  std::vector<Event> Engine::poll_events()
118
191
  {
119
192
  std::vector<Event> events;
@@ -1,6 +1,7 @@
1
1
  #pragma once
2
2
 
3
3
  #include <SDL.h>
4
+ #include <SDL_ttf.h>
4
5
  #include <vector>
5
6
 
6
7
  // A minimal 2D graphics engine binding for Python using SDL.
@@ -43,11 +44,18 @@ namespace mini {
43
44
 
44
45
  // Poll all pending events and return them.
45
46
  std::vector<Event> poll_events();
47
+
48
+ // Load a TTF font from file at specified point size.
49
+ void load_font(const char* path, int pt_size);
50
+
51
+ // Draw text at specified position.
52
+ void draw_text(const char* text, int x, int y, int r, int g, int b);
46
53
 
47
54
  private:
48
55
  SDL_Window* window_;
49
56
  SDL_Renderer* renderer_;
50
57
  bool initialized_;
58
+ TTF_Font* font_;
51
59
  };
52
60
 
53
61
  } // namespace mini
@@ -8,7 +8,7 @@ build-backend = "scikit_build_core.build"
8
8
 
9
9
  [project]
10
10
  name = "mini-arcade-native-backend"
11
- version = "0.2.3"
11
+ version = "0.3.0"
12
12
  description = "Native SDL2 backend for mini-arcade-core using SDL2 + pybind11."
13
13
  authors = [
14
14
  { name = "Santiago Rincon", email = "rincores@gmail.com" },
@@ -45,8 +45,10 @@ _NATIVE_TO_CORE = {
45
45
  class NativeBackend(Backend):
46
46
  """Adapter that makes the C++ Engine usable as a mini-arcade backend."""
47
47
 
48
- def __init__(self):
48
+ def __init__(self, font_path: str | None = None, font_size: int = 24):
49
49
  self._engine = native.Engine()
50
+ self._font_path = font_path
51
+ self._font_size = font_size
50
52
 
51
53
  def init(self, width: int, height: int, title: str):
52
54
  """
@@ -63,6 +65,10 @@ class NativeBackend(Backend):
63
65
  """
64
66
  self._engine.init(width, height, title)
65
67
 
68
+ # Load font if provided
69
+ if self._font_path is not None:
70
+ self._engine.load_font(self._font_path, self._font_size)
71
+
66
72
  def poll_events(self) -> list[Event]:
67
73
  """
68
74
  Poll for events from the backend and return them as a list of Event objects.
@@ -102,3 +108,18 @@ class NativeBackend(Backend):
102
108
  :type h: int
103
109
  """
104
110
  self._engine.draw_rect(x, y, w, h)
111
+
112
+ def draw_text(
113
+ self,
114
+ x: int,
115
+ y: int,
116
+ text: str,
117
+ color: tuple[int, int, int] = (255, 255, 255),
118
+ ) -> None:
119
+ """
120
+ Draw text at the given position using the loaded font.
121
+ If no font is loaded, this is a no-op.
122
+ """
123
+ # We rely on C++ side to no-op if font is missing
124
+ r, g, b = color
125
+ self._engine.draw_text(text, x, y, int(r), int(g), int(b))
@@ -1,4 +0,0 @@
1
- ## [0.2.3] - 2025-12-04
2
-
3
- - Internal changes only.
4
-
@@ -1 +0,0 @@
1
- 0.2.3
@@ -1,5 +0,0 @@
1
- {
2
- "files.associations": {
3
- "system_error": "cpp"
4
- }
5
- }