mini-arcade-native-backend 0.3.0__tar.gz → 0.3.2__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.
- mini_arcade_native_backend-0.3.2/.changelog_section +11 -0
- mini_arcade_native_backend-0.3.2/.version_to_tag +1 -0
- {mini_arcade_native_backend-0.3.0 → mini_arcade_native_backend-0.3.2}/CHANGELOG.md +20 -0
- {mini_arcade_native_backend-0.3.0 → mini_arcade_native_backend-0.3.2}/PKG-INFO +1 -1
- {mini_arcade_native_backend-0.3.0 → mini_arcade_native_backend-0.3.2}/cpp/bindings.cpp +16 -2
- {mini_arcade_native_backend-0.3.0 → mini_arcade_native_backend-0.3.2}/cpp/engine.cpp +120 -11
- {mini_arcade_native_backend-0.3.0 → mini_arcade_native_backend-0.3.2}/cpp/engine.h +12 -1
- {mini_arcade_native_backend-0.3.0 → mini_arcade_native_backend-0.3.2}/pyproject.toml +1 -1
- {mini_arcade_native_backend-0.3.0 → mini_arcade_native_backend-0.3.2}/src/mini_arcade_native_backend/__init__.py +24 -2
- mini_arcade_native_backend-0.3.0/.changelog_section +0 -9
- mini_arcade_native_backend-0.3.0/.version_to_tag +0 -1
- {mini_arcade_native_backend-0.3.0 → mini_arcade_native_backend-0.3.2}/.github/workflows/ci.yml +0 -0
- {mini_arcade_native_backend-0.3.0 → mini_arcade_native_backend-0.3.2}/.github/workflows/create-release-branch.yml +0 -0
- {mini_arcade_native_backend-0.3.0 → mini_arcade_native_backend-0.3.2}/.github/workflows/release-finalize.yml +0 -0
- {mini_arcade_native_backend-0.3.0 → mini_arcade_native_backend-0.3.2}/.github/workflows/release-publish.yml +0 -0
- {mini_arcade_native_backend-0.3.0 → mini_arcade_native_backend-0.3.2}/.gitignore +0 -0
- {mini_arcade_native_backend-0.3.0 → mini_arcade_native_backend-0.3.2}/.vscode/settings.json +0 -0
- {mini_arcade_native_backend-0.3.0 → mini_arcade_native_backend-0.3.2}/CMakeLists.txt +0 -0
- {mini_arcade_native_backend-0.3.0 → mini_arcade_native_backend-0.3.2}/LICENSE +0 -0
- {mini_arcade_native_backend-0.3.0 → mini_arcade_native_backend-0.3.2}/README.md +0 -0
- {mini_arcade_native_backend-0.3.0 → mini_arcade_native_backend-0.3.2}/examples/native_backend_demo.py +0 -0
- {mini_arcade_native_backend-0.3.0 → mini_arcade_native_backend-0.3.2}/poetry.lock +0 -0
- {mini_arcade_native_backend-0.3.0 → mini_arcade_native_backend-0.3.2}/poetry.toml +0 -0
- {mini_arcade_native_backend-0.3.0 → mini_arcade_native_backend-0.3.2}/tests/test_init.py +0 -0
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
## [0.3.2] - 2025-12-05
|
|
2
|
+
|
|
3
|
+
### Added
|
|
4
|
+
- add draw_rect_rgba method to Engine for RGBA rectangle drawing and update Python bindings
|
|
5
|
+
- add capture_frame method to Engine and expose it in Python bindings
|
|
6
|
+
- add clear color customization and update draw_rect method
|
|
7
|
+
|
|
8
|
+
### Other
|
|
9
|
+
- Merge branch 'release/0.3' of https://github.com/alexsc6955/mini-arcade-native-backend into release/0.3
|
|
10
|
+
- Merge branch 'release/0.3' of https://github.com/alexsc6955/mini-arcade-native-backend into release/0.3
|
|
11
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
0.3.2
|
|
@@ -6,6 +6,26 @@ This project adheres to [Semantic Versioning](https://semver.org/).
|
|
|
6
6
|
|
|
7
7
|
## [Unreleased]
|
|
8
8
|
|
|
9
|
+
## [0.3.2] - 2025-12-05
|
|
10
|
+
|
|
11
|
+
### Added
|
|
12
|
+
- add draw_rect_rgba method to Engine for RGBA rectangle drawing and update Python bindings
|
|
13
|
+
- add capture_frame method to Engine and expose it in Python bindings
|
|
14
|
+
- add clear color customization and update draw_rect method
|
|
15
|
+
|
|
16
|
+
### Other
|
|
17
|
+
- Merge branch 'release/0.3' of https://github.com/alexsc6955/mini-arcade-native-backend into release/0.3
|
|
18
|
+
- Merge branch 'release/0.3' of https://github.com/alexsc6955/mini-arcade-native-backend into release/0.3
|
|
19
|
+
|
|
20
|
+
## [0.3.1] - 2025-12-05
|
|
21
|
+
|
|
22
|
+
### Added
|
|
23
|
+
- add capture_frame method to Engine and expose it in Python bindings
|
|
24
|
+
- add clear color customization and update draw_rect method
|
|
25
|
+
|
|
26
|
+
### Other
|
|
27
|
+
- Merge branch 'release/0.3' of https://github.com/alexsc6955/mini-arcade-native-backend into release/0.3
|
|
28
|
+
|
|
9
29
|
## [0.3.0] - 2025-12-05
|
|
10
30
|
|
|
11
31
|
### Added
|
|
@@ -27,15 +27,26 @@ PYBIND11_MODULE(_native, m) {
|
|
|
27
27
|
.def("init", &mini::Engine::init,
|
|
28
28
|
py::arg("width"), py::arg("height"), py::arg("title"))
|
|
29
29
|
|
|
30
|
+
.def("set_clear_color", &mini::Engine::set_clear_color,
|
|
31
|
+
py::arg("r"), py::arg("g"), py::arg("b"))
|
|
32
|
+
|
|
30
33
|
.def("begin_frame", &mini::Engine::begin_frame)
|
|
31
34
|
.def("end_frame", &mini::Engine::end_frame)
|
|
32
35
|
|
|
33
36
|
.def("draw_rect", &mini::Engine::draw_rect,
|
|
34
|
-
py::arg("x"), py::arg("y"),
|
|
37
|
+
py::arg("x"), py::arg("y"),
|
|
38
|
+
py::arg("w"), py::arg("h"),
|
|
39
|
+
py::arg("r"), py::arg("g"), py::arg("b"))
|
|
40
|
+
|
|
35
41
|
.def("draw_sprite", &mini::Engine::draw_sprite,
|
|
36
42
|
py::arg("texture_id"), py::arg("x"), py::arg("y"),
|
|
37
43
|
py::arg("w"), py::arg("h"))
|
|
38
44
|
|
|
45
|
+
.def("draw_rect_rgba", &mini::Engine::draw_rect_rgba,
|
|
46
|
+
py::arg("x"), py::arg("y"),
|
|
47
|
+
py::arg("w"), py::arg("h"),
|
|
48
|
+
py::arg("r"), py::arg("g"), py::arg("b"), py::arg("a"))
|
|
49
|
+
|
|
39
50
|
.def("load_font", &mini::Engine::load_font,
|
|
40
51
|
py::arg("path"), py::arg("pt_size"))
|
|
41
52
|
|
|
@@ -49,5 +60,8 @@ PYBIND11_MODULE(_native, m) {
|
|
|
49
60
|
py::arg("g"),
|
|
50
61
|
py::arg("b")
|
|
51
62
|
)
|
|
52
|
-
.def("poll_events", &mini::Engine::poll_events)
|
|
63
|
+
.def("poll_events", &mini::Engine::poll_events)
|
|
64
|
+
|
|
65
|
+
.def("capture_frame", &mini::Engine::capture_frame,
|
|
66
|
+
py::arg("path"));
|
|
53
67
|
}
|
|
@@ -9,7 +9,8 @@ namespace mini {
|
|
|
9
9
|
: window_(nullptr),
|
|
10
10
|
renderer_(nullptr),
|
|
11
11
|
initialized_(false),
|
|
12
|
-
font_(nullptr)
|
|
12
|
+
font_(nullptr),
|
|
13
|
+
clear_color_{0, 0, 0, 255}
|
|
13
14
|
{
|
|
14
15
|
}
|
|
15
16
|
|
|
@@ -83,17 +84,40 @@ namespace mini {
|
|
|
83
84
|
throw std::runtime_error(msg);
|
|
84
85
|
}
|
|
85
86
|
|
|
87
|
+
// Enable alpha blending for RGBA drawing
|
|
88
|
+
SDL_SetRenderDrawBlendMode(renderer_, SDL_BLENDMODE_BLEND);
|
|
89
|
+
|
|
86
90
|
initialized_ = true;
|
|
87
91
|
}
|
|
88
92
|
|
|
93
|
+
void Engine::set_clear_color(int r, int g, int b)
|
|
94
|
+
{
|
|
95
|
+
auto clamp = [](int v) {
|
|
96
|
+
if (v < 0) return 0;
|
|
97
|
+
if (v > 255) return 255;
|
|
98
|
+
return v;
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
clear_color_.r = static_cast<Uint8>(clamp(r));
|
|
102
|
+
clear_color_.g = static_cast<Uint8>(clamp(g));
|
|
103
|
+
clear_color_.b = static_cast<Uint8>(clamp(b));
|
|
104
|
+
clear_color_.a = 255;
|
|
105
|
+
}
|
|
106
|
+
|
|
89
107
|
void Engine::begin_frame()
|
|
90
108
|
{
|
|
91
109
|
if (!initialized_ || renderer_ == nullptr) {
|
|
92
110
|
return;
|
|
93
111
|
}
|
|
94
112
|
|
|
95
|
-
//
|
|
96
|
-
SDL_SetRenderDrawColor(
|
|
113
|
+
// use stored clear color instead of hard-coded black
|
|
114
|
+
SDL_SetRenderDrawColor(
|
|
115
|
+
renderer_,
|
|
116
|
+
clear_color_.r,
|
|
117
|
+
clear_color_.g,
|
|
118
|
+
clear_color_.b,
|
|
119
|
+
clear_color_.a
|
|
120
|
+
);
|
|
97
121
|
SDL_RenderClear(renderer_);
|
|
98
122
|
}
|
|
99
123
|
|
|
@@ -106,21 +130,29 @@ namespace mini {
|
|
|
106
130
|
SDL_RenderPresent(renderer_);
|
|
107
131
|
}
|
|
108
132
|
|
|
109
|
-
void Engine::draw_rect(int x, int y, int w, int h)
|
|
133
|
+
void Engine::draw_rect(int x, int y, int w, int h, int r, int g, int b)
|
|
110
134
|
{
|
|
111
135
|
if (!initialized_ || renderer_ == nullptr) {
|
|
112
136
|
return;
|
|
113
137
|
}
|
|
114
138
|
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
139
|
+
auto clamp = [](int v) {
|
|
140
|
+
if (v < 0) return 0;
|
|
141
|
+
if (v > 255) return 255;
|
|
142
|
+
return v;
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
SDL_Rect rect{ x, y, w, h };
|
|
120
146
|
|
|
121
|
-
|
|
122
|
-
|
|
147
|
+
SDL_SetRenderDrawColor(
|
|
148
|
+
renderer_,
|
|
149
|
+
static_cast<Uint8>(clamp(r)),
|
|
150
|
+
static_cast<Uint8>(clamp(g)),
|
|
151
|
+
static_cast<Uint8>(clamp(b)),
|
|
152
|
+
255
|
|
153
|
+
);
|
|
123
154
|
SDL_RenderFillRect(renderer_, &rect);
|
|
155
|
+
|
|
124
156
|
}
|
|
125
157
|
|
|
126
158
|
void Engine::draw_sprite(int /*texture_id*/, int /*x*/, int /*y*/, int /*w*/, int /*h*/)
|
|
@@ -187,6 +219,83 @@ namespace mini {
|
|
|
187
219
|
SDL_DestroyTexture(texture);
|
|
188
220
|
}
|
|
189
221
|
|
|
222
|
+
void Engine::draw_rect_rgba(int x, int y, int w, int h, int r, int g, int b, int a)
|
|
223
|
+
{
|
|
224
|
+
if (!initialized_ || renderer_ == nullptr) {
|
|
225
|
+
return;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
auto clamp = [](int v) {
|
|
229
|
+
if (v < 0) return 0;
|
|
230
|
+
if (v > 255) return 255;
|
|
231
|
+
return v;
|
|
232
|
+
};
|
|
233
|
+
|
|
234
|
+
SDL_Rect rect{ x, y, w, h };
|
|
235
|
+
|
|
236
|
+
SDL_SetRenderDrawColor(
|
|
237
|
+
renderer_,
|
|
238
|
+
static_cast<Uint8>(clamp(r)),
|
|
239
|
+
static_cast<Uint8>(clamp(g)),
|
|
240
|
+
static_cast<Uint8>(clamp(b)),
|
|
241
|
+
static_cast<Uint8>(clamp(a))
|
|
242
|
+
);
|
|
243
|
+
SDL_RenderFillRect(renderer_, &rect);
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
|
|
247
|
+
bool Engine::capture_frame(const char* path)
|
|
248
|
+
{
|
|
249
|
+
if (!initialized_ || renderer_ == nullptr) {
|
|
250
|
+
return false;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
int width = 0;
|
|
254
|
+
int height = 0;
|
|
255
|
+
if (SDL_GetRendererOutputSize(renderer_, &width, &height) != 0) {
|
|
256
|
+
std::cerr << "SDL_GetRendererOutputSize Error: " << SDL_GetError() << std::endl;
|
|
257
|
+
return false;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
// Create a surface to hold the pixels (32-bit RGBA)
|
|
261
|
+
SDL_Surface* surface = SDL_CreateRGBSurfaceWithFormat(
|
|
262
|
+
0,
|
|
263
|
+
width,
|
|
264
|
+
height,
|
|
265
|
+
32,
|
|
266
|
+
SDL_PIXELFORMAT_ARGB8888
|
|
267
|
+
);
|
|
268
|
+
|
|
269
|
+
if (!surface) {
|
|
270
|
+
std::cerr << "SDL_CreateRGBSurfaceWithFormat Error: " << SDL_GetError() << std::endl;
|
|
271
|
+
return false;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
// Read pixels from the current render target into the surface
|
|
275
|
+
if (SDL_RenderReadPixels(
|
|
276
|
+
renderer_,
|
|
277
|
+
nullptr, // whole screen
|
|
278
|
+
surface->format->format,
|
|
279
|
+
surface->pixels,
|
|
280
|
+
surface->pitch) != 0)
|
|
281
|
+
{
|
|
282
|
+
std::cerr << "SDL_RenderReadPixels Error: " << SDL_GetError() << std::endl;
|
|
283
|
+
SDL_FreeSurface(surface);
|
|
284
|
+
return false;
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
// Save as BMP (simple, no extra dependencies).
|
|
288
|
+
// Use .bmp extension in the path you pass from Python.
|
|
289
|
+
if (SDL_SaveBMP(surface, path) != 0) {
|
|
290
|
+
std::cerr << "SDL_SaveBMP Error: " << SDL_GetError() << std::endl;
|
|
291
|
+
SDL_FreeSurface(surface);
|
|
292
|
+
return false;
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
SDL_FreeSurface(surface);
|
|
296
|
+
return true;
|
|
297
|
+
}
|
|
298
|
+
|
|
190
299
|
std::vector<Event> Engine::poll_events()
|
|
191
300
|
{
|
|
192
301
|
std::vector<Event> events;
|
|
@@ -30,6 +30,9 @@ namespace mini {
|
|
|
30
30
|
// Initialize the engine with a window of given width, height, and title.
|
|
31
31
|
void init(int width, int height, const char* title);
|
|
32
32
|
|
|
33
|
+
// Set the clear color for the screen.
|
|
34
|
+
void set_clear_color(int r, int g, int b);
|
|
35
|
+
|
|
33
36
|
// Clear the screen to a default color (black) and get ready to draw.
|
|
34
37
|
void begin_frame();
|
|
35
38
|
|
|
@@ -37,7 +40,7 @@ namespace mini {
|
|
|
37
40
|
void end_frame();
|
|
38
41
|
|
|
39
42
|
// Draw a simple filled rectangle (we'll use a fixed color for now).
|
|
40
|
-
void draw_rect(int x, int y, int w, int h);
|
|
43
|
+
void draw_rect(int x, int y, int w, int h, int r, int g, int b);
|
|
41
44
|
|
|
42
45
|
// Sprite drawing stub for later.
|
|
43
46
|
void draw_sprite(int texture_id, int x, int y, int w, int h);
|
|
@@ -51,11 +54,19 @@ namespace mini {
|
|
|
51
54
|
// Draw text at specified position.
|
|
52
55
|
void draw_text(const char* text, int x, int y, int r, int g, int b);
|
|
53
56
|
|
|
57
|
+
// Capture the current frame into an image file (BMP for now).
|
|
58
|
+
// Returns true on success, false on failure.
|
|
59
|
+
bool capture_frame(const char* path);
|
|
60
|
+
|
|
61
|
+
// Draw a filled rectangle with RGBA color (supports transparency).
|
|
62
|
+
void draw_rect_rgba(int x, int y, int w, int h, int r, int g, int b, int a);
|
|
63
|
+
|
|
54
64
|
private:
|
|
55
65
|
SDL_Window* window_;
|
|
56
66
|
SDL_Renderer* renderer_;
|
|
57
67
|
bool initialized_;
|
|
58
68
|
TTF_Font* font_;
|
|
69
|
+
SDL_Color clear_color_;
|
|
59
70
|
};
|
|
60
71
|
|
|
61
72
|
} // 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.3.
|
|
11
|
+
version = "0.3.2"
|
|
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" },
|
|
@@ -69,6 +69,9 @@ class NativeBackend(Backend):
|
|
|
69
69
|
if self._font_path is not None:
|
|
70
70
|
self._engine.load_font(self._font_path, self._font_size)
|
|
71
71
|
|
|
72
|
+
def set_clear_color(self, r: int, g: int, b: int) -> None:
|
|
73
|
+
self._engine.set_clear_color(int(r), int(g), int(b))
|
|
74
|
+
|
|
72
75
|
def poll_events(self) -> list[Event]:
|
|
73
76
|
"""
|
|
74
77
|
Poll for events from the backend and return them as a list of Event objects.
|
|
@@ -91,7 +94,14 @@ class NativeBackend(Backend):
|
|
|
91
94
|
"""End the current frame for rendering."""
|
|
92
95
|
self._engine.end_frame()
|
|
93
96
|
|
|
94
|
-
def draw_rect(
|
|
97
|
+
def draw_rect(
|
|
98
|
+
self,
|
|
99
|
+
x: int,
|
|
100
|
+
y: int,
|
|
101
|
+
w: int,
|
|
102
|
+
h: int,
|
|
103
|
+
color: tuple[int, ...] = (255, 255, 255),
|
|
104
|
+
):
|
|
95
105
|
"""
|
|
96
106
|
Draw a rectangle at the specified position with given width and height.
|
|
97
107
|
|
|
@@ -107,7 +117,16 @@ class NativeBackend(Backend):
|
|
|
107
117
|
:param h: Height of the rectangle.
|
|
108
118
|
:type h: int
|
|
109
119
|
"""
|
|
110
|
-
|
|
120
|
+
if len(color) == 3:
|
|
121
|
+
r, g, b = color
|
|
122
|
+
self._engine.draw_rect(x, y, w, h, r, g, b)
|
|
123
|
+
elif len(color) == 4:
|
|
124
|
+
r, g, b, a = color
|
|
125
|
+
self._engine.draw_rect_rgba(x, y, w, h, r, g, b, a)
|
|
126
|
+
else:
|
|
127
|
+
raise ValueError(
|
|
128
|
+
f"Color must be (r,g,b) or (r,g,b,a), got {color!r}"
|
|
129
|
+
)
|
|
111
130
|
|
|
112
131
|
def draw_text(
|
|
113
132
|
self,
|
|
@@ -123,3 +142,6 @@ class NativeBackend(Backend):
|
|
|
123
142
|
# We rely on C++ side to no-op if font is missing
|
|
124
143
|
r, g, b = color
|
|
125
144
|
self._engine.draw_text(text, x, y, int(r), int(g), int(b))
|
|
145
|
+
|
|
146
|
+
def capture_frame(self, path: str) -> bool:
|
|
147
|
+
return self._engine.capture_frame(path)
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
0.3.0
|
{mini_arcade_native_backend-0.3.0 → mini_arcade_native_backend-0.3.2}/.github/workflows/ci.yml
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|