actually, make cxx bindings part of the main header

This commit is contained in:
Serge Zaitsev
2023-02-10 15:51:44 +01:00
parent 959d3ce557
commit 63e84e0a7f
2 changed files with 38 additions and 36 deletions

View File

@ -1,38 +1,5 @@
#include "fenster.h"
class Fenster {
struct fenster f;
int64_t now;
public:
Fenster(const int w, const int h, const char *title)
: f{.title = title, .width = w, .height = h} {
this->f.buf = new uint32_t[w * h];
this->now = fenster_time();
fenster_open(&this->f);
}
~Fenster() {
fenster_close(&this->f);
delete[] this->f.buf;
}
bool loop(const int fps) {
int64_t t = fenster_time();
if (t - this->now < 1000 / fps) {
fenster_sleep(t - now);
}
this->now = t;
return fenster_loop(&this->f) == 0;
}
inline uint32_t &px(const int x, const int y) {
return fenster_pixel(&this->f, x, y);
}
bool key(int c) { return c >= 0 && c < 128 ? this->f.keys[c] : false; }
int x() { return this->f.x; }
int y() { return this->f.y; }
int mouse() { return this->f.mouse; }
int mod() { return this->f.mod; }
};
#define W 320
#define H 240
@ -53,9 +20,9 @@ static int run() {
f.px(i, j) = i ^ j ^ t;
}
}
if (f.key(0x1b)) {
break;
}
if (f.key(0x1b)) {
break;
}
t++;
}
return 0;

View File

@ -328,5 +328,40 @@ FENSTER_API int64_t fenster_time() {
}
#endif
#ifdef __cplusplus
class Fenster {
struct fenster f;
int64_t now;
public:
Fenster(const int w, const int h, const char *title)
: f{.title = title, .width = w, .height = h} {
this->f.buf = new uint32_t[w * h];
this->now = fenster_time();
fenster_open(&this->f);
}
~Fenster() {
fenster_close(&this->f);
delete[] this->f.buf;
}
bool loop(const int fps) {
int64_t t = fenster_time();
if (t - this->now < 1000 / fps) {
fenster_sleep(t - now);
}
this->now = t;
return fenster_loop(&this->f) == 0;
}
inline uint32_t &px(const int x, const int y) {
return fenster_pixel(&this->f, x, y);
}
bool key(int c) { return c >= 0 && c < 128 ? this->f.keys[c] : false; }
int x() { return this->f.x; }
int y() { return this->f.y; }
int mouse() { return this->f.mouse; }
int mod() { return this->f.mod; }
};
#endif /* __cplusplus */
#endif /* !FENSTER_HEADER */
#endif /* FENSTER_H */