mirror of
https://github.com/zserge/fenster.git
synced 2025-04-12 10:48:41 +03:00
actually, make cxx bindings part of the main header
This commit is contained in:
@ -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;
|
||||
|
35
fenster.h
35
fenster.h
@ -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 */
|
||||
|
Reference in New Issue
Block a user