Type prefixes (#34)
* update documentation * Fix typo * Added some examples * changed window names * Minor fix * Added mfb_update_events to all platforms. Checked on Windows, X11 and Wayland * simplify CMake * Upgrade to CMake 3.5, simplify script and generalize it Now the users only have to add_directory and link_libraries(minifb) in CMake * Renamed typo scrool by scroll Added some checks Removed some warnings * working Windows, X11 and Wayland * fix issue 32 Co-authored-by: Carlos Aragones <> Co-authored-by: caragones <carlos.aragonesmartinez-external@gemalto.com>
This commit is contained in:
@ -1,141 +1,149 @@
|
||||
#include <MiniFB.h>
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#define kUnused(var) (void) var
|
||||
|
||||
#define WIDTH 800
|
||||
#define HEIGHT 600
|
||||
static unsigned int g_buffer[WIDTH * HEIGHT];
|
||||
static bool g_active = true;
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void active(struct Window *window, bool isActive) {
|
||||
const char *window_title = "";
|
||||
if(window) {
|
||||
window_title = (const char *) mfb_get_user_data(window);
|
||||
}
|
||||
fprintf(stdout, "%s > active: %d\n", window_title, isActive);
|
||||
g_active = isActive;
|
||||
}
|
||||
|
||||
void resize(struct Window *window, int width, int height) {
|
||||
uint32_t x = 0;
|
||||
uint32_t y = 0;
|
||||
const char *window_title = "";
|
||||
if(window) {
|
||||
window_title = (const char *) mfb_get_user_data(window);
|
||||
}
|
||||
|
||||
fprintf(stdout, "%s > resize: %d, %d\n", window_title, width, height);
|
||||
if(width > WIDTH) {
|
||||
x = (width - WIDTH) >> 1;
|
||||
width = WIDTH;
|
||||
}
|
||||
if(height > HEIGHT) {
|
||||
y = (height - HEIGHT) >> 1;
|
||||
height = HEIGHT;
|
||||
}
|
||||
mfb_set_viewport(window, x, y, width, height);
|
||||
}
|
||||
|
||||
void keyboard(struct Window *window, Key key, KeyMod mod, bool isPressed) {
|
||||
const char *window_title = "";
|
||||
if(window) {
|
||||
window_title = (const char *) mfb_get_user_data(window);
|
||||
}
|
||||
fprintf(stdout, "%s > keyboard: key: %s (pressed: %d) [KeyMod: %x]\n", window_title, mfb_get_key_name(key), isPressed, mod);
|
||||
if(key == KB_KEY_ESCAPE) {
|
||||
mfb_close(window);
|
||||
}
|
||||
}
|
||||
|
||||
void char_input(struct Window *window, unsigned int charCode) {
|
||||
const char *window_title = "";
|
||||
if(window) {
|
||||
window_title = (const char *) mfb_get_user_data(window);
|
||||
}
|
||||
fprintf(stdout, "%s > charCode: %d\n", window_title, charCode);
|
||||
}
|
||||
|
||||
void mouse_btn(struct Window *window, MouseButton button, KeyMod mod, bool isPressed) {
|
||||
const char *window_title = "";
|
||||
if(window) {
|
||||
window_title = (const char *) mfb_get_user_data(window);
|
||||
}
|
||||
fprintf(stdout, "%s > mouse_btn: button: %d (pressed: %d) [KeyMod: %x]\n", window_title, button, isPressed, mod);
|
||||
}
|
||||
|
||||
void mouse_move(struct Window *window, int x, int y) {
|
||||
kUnused(window);
|
||||
kUnused(x);
|
||||
kUnused(y);
|
||||
// const char *window_title = "";
|
||||
// if(window) {
|
||||
// window_t(const char *) itle = mfb_get_user_data(window);
|
||||
// }
|
||||
//fprintf(stdout, "%s > mouse_move: %d, %d\n", window_title, x, y);
|
||||
}
|
||||
|
||||
void mouse_scroll(struct Window *window, KeyMod mod, float deltaX, float deltaY) {
|
||||
const char *window_title = "";
|
||||
if(window) {
|
||||
window_title = (const char *) mfb_get_user_data(window);
|
||||
}
|
||||
fprintf(stdout, "%s > mouse_scroll: x: %f, y: %f [KeyMod: %x]\n", window_title, deltaX, deltaY, mod);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
int main()
|
||||
{
|
||||
int noise, carry, seed = 0xbeef;
|
||||
|
||||
struct Window *window = mfb_open_ex("Input Events Test", WIDTH, HEIGHT, WF_RESIZABLE);
|
||||
if (!window)
|
||||
return 0;
|
||||
|
||||
mfb_set_active_callback(window, active);
|
||||
mfb_set_resize_callback(window, resize);
|
||||
mfb_set_keyboard_callback(window, keyboard);
|
||||
mfb_set_char_input_callback(window, char_input);
|
||||
mfb_set_mouse_button_callback(window, mouse_btn);
|
||||
mfb_set_mouse_move_callback(window, mouse_move);
|
||||
mfb_set_mouse_scroll_callback(window, mouse_scroll);
|
||||
|
||||
mfb_set_user_data(window, (void *) "Input Events Test");
|
||||
|
||||
for (;;)
|
||||
{
|
||||
int i;
|
||||
UpdateState state;
|
||||
|
||||
if(g_active)
|
||||
{
|
||||
for (i = 0; i < WIDTH * HEIGHT; ++i)
|
||||
{
|
||||
noise = seed;
|
||||
noise >>= 3;
|
||||
noise ^= seed;
|
||||
carry = noise & 1;
|
||||
noise >>= 1;
|
||||
seed >>= 1;
|
||||
seed |= (carry << 30);
|
||||
noise &= 0xFF;
|
||||
g_buffer[i] = MFB_RGB(noise, noise, noise);
|
||||
}
|
||||
|
||||
state = mfb_update(window, g_buffer);
|
||||
}
|
||||
else {
|
||||
state = mfb_update_events(window);
|
||||
}
|
||||
if (state != STATE_OK) {
|
||||
window = 0x0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
#include <MiniFB.h>
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#define kUnused(var) (void) var
|
||||
|
||||
#define WIDTH 800
|
||||
#define HEIGHT 600
|
||||
static unsigned int g_buffer[WIDTH * HEIGHT];
|
||||
static bool g_active = true;
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void
|
||||
active(struct mfb_window *window, bool isActive) {
|
||||
const char *window_title = "";
|
||||
if(window) {
|
||||
window_title = (const char *) mfb_get_user_data(window);
|
||||
}
|
||||
fprintf(stdout, "%s > active: %d\n", window_title, isActive);
|
||||
g_active = isActive;
|
||||
}
|
||||
|
||||
void
|
||||
resize(struct mfb_window *window, int width, int height) {
|
||||
uint32_t x = 0;
|
||||
uint32_t y = 0;
|
||||
const char *window_title = "";
|
||||
if(window) {
|
||||
window_title = (const char *) mfb_get_user_data(window);
|
||||
}
|
||||
|
||||
fprintf(stdout, "%s > resize: %d, %d\n", window_title, width, height);
|
||||
if(width > WIDTH) {
|
||||
x = (width - WIDTH) >> 1;
|
||||
width = WIDTH;
|
||||
}
|
||||
if(height > HEIGHT) {
|
||||
y = (height - HEIGHT) >> 1;
|
||||
height = HEIGHT;
|
||||
}
|
||||
mfb_set_viewport(window, x, y, width, height);
|
||||
}
|
||||
|
||||
void
|
||||
keyboard(struct mfb_window *window, mfb_key key, mfb_key_mod mod, bool isPressed) {
|
||||
const char *window_title = "";
|
||||
if(window) {
|
||||
window_title = (const char *) mfb_get_user_data(window);
|
||||
}
|
||||
fprintf(stdout, "%s > keyboard: key: %s (pressed: %d) [key_mod: %x]\n", window_title, mfb_get_key_name(key), isPressed, mod);
|
||||
if(key == KB_KEY_ESCAPE) {
|
||||
mfb_close(window);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
char_input(struct mfb_window *window, unsigned int charCode) {
|
||||
const char *window_title = "";
|
||||
if(window) {
|
||||
window_title = (const char *) mfb_get_user_data(window);
|
||||
}
|
||||
fprintf(stdout, "%s > charCode: %d\n", window_title, charCode);
|
||||
}
|
||||
|
||||
void
|
||||
mouse_btn(struct mfb_window *window, mfb_mouse_button button, mfb_key_mod mod, bool isPressed) {
|
||||
const char *window_title = "";
|
||||
if(window) {
|
||||
window_title = (const char *) mfb_get_user_data(window);
|
||||
}
|
||||
fprintf(stdout, "%s > mouse_btn: button: %d (pressed: %d) [key_mod: %x]\n", window_title, button, isPressed, mod);
|
||||
}
|
||||
|
||||
void
|
||||
mouse_move(struct mfb_window *window, int x, int y) {
|
||||
kUnused(window);
|
||||
kUnused(x);
|
||||
kUnused(y);
|
||||
// const char *window_title = "";
|
||||
// if(window) {
|
||||
// window_t(const char *) itle = mfb_get_user_data(window);
|
||||
// }
|
||||
//fprintf(stdout, "%s > mouse_move: %d, %d\n", window_title, x, y);
|
||||
}
|
||||
|
||||
void
|
||||
mouse_scroll(struct mfb_window *window, mfb_key_mod mod, float deltaX, float deltaY) {
|
||||
const char *window_title = "";
|
||||
if(window) {
|
||||
window_title = (const char *) mfb_get_user_data(window);
|
||||
}
|
||||
fprintf(stdout, "%s > mouse_scroll: x: %f, y: %f [key_mod: %x]\n", window_title, deltaX, deltaY, mod);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
int
|
||||
main()
|
||||
{
|
||||
int noise, carry, seed = 0xbeef;
|
||||
|
||||
struct mfb_window *window = mfb_open_ex("Input Events Test", WIDTH, HEIGHT, WF_RESIZABLE);
|
||||
if (!window)
|
||||
return 0;
|
||||
|
||||
mfb_set_active_callback(window, active);
|
||||
mfb_set_resize_callback(window, resize);
|
||||
mfb_set_keyboard_callback(window, keyboard);
|
||||
mfb_set_char_input_callback(window, char_input);
|
||||
mfb_set_mouse_button_callback(window, mouse_btn);
|
||||
mfb_set_mouse_move_callback(window, mouse_move);
|
||||
mfb_set_mouse_scroll_callback(window, mouse_scroll);
|
||||
|
||||
mfb_set_user_data(window, (void *) "Input Events Test");
|
||||
|
||||
for (;;)
|
||||
{
|
||||
int i;
|
||||
mfb_update_state state;
|
||||
|
||||
if(g_active)
|
||||
{
|
||||
for (i = 0; i < WIDTH * HEIGHT; ++i)
|
||||
{
|
||||
noise = seed;
|
||||
noise >>= 3;
|
||||
noise ^= seed;
|
||||
carry = noise & 1;
|
||||
noise >>= 1;
|
||||
seed >>= 1;
|
||||
seed |= (carry << 30);
|
||||
noise &= 0xFF;
|
||||
g_buffer[i] = MFB_RGB(noise, noise, noise);
|
||||
}
|
||||
|
||||
state = mfb_update(window, g_buffer);
|
||||
}
|
||||
else {
|
||||
state = mfb_update_events(window);
|
||||
}
|
||||
if (state != STATE_OK) {
|
||||
window = 0x0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -1,138 +1,139 @@
|
||||
#include <MiniFB.h>
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#define kUnused(var) (void) var;
|
||||
|
||||
#define WIDTH 800
|
||||
#define HEIGHT 600
|
||||
static unsigned int g_buffer[WIDTH * HEIGHT];
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class Events {
|
||||
public:
|
||||
void active(struct Window *window, bool isActive) {
|
||||
const char *window_title = "";
|
||||
if(window) {
|
||||
window_title = (const char *) mfb_get_user_data(window);
|
||||
}
|
||||
fprintf(stdout, "%s > active: %d\n", window_title, isActive);
|
||||
}
|
||||
|
||||
void resize(struct Window *window, int width, int height) {
|
||||
uint32_t x = 0;
|
||||
uint32_t y = 0;
|
||||
const char *window_title = "";
|
||||
if(window) {
|
||||
window_title = (const char *) mfb_get_user_data(window);
|
||||
}
|
||||
|
||||
fprintf(stdout, "%s > resize: %d, %d\n", window_title, width, height);
|
||||
if(width > WIDTH) {
|
||||
x = (width - WIDTH) >> 1;
|
||||
width = WIDTH;
|
||||
}
|
||||
if(height > HEIGHT) {
|
||||
y = (height - HEIGHT) >> 1;
|
||||
height = HEIGHT;
|
||||
}
|
||||
mfb_set_viewport(window, x, y, width, height);
|
||||
}
|
||||
|
||||
void keyboard(struct Window *window, Key key, KeyMod mod, bool isPressed) {
|
||||
const char *window_title = "";
|
||||
if(window) {
|
||||
window_title = (const char *) mfb_get_user_data(window);
|
||||
}
|
||||
fprintf(stdout, "%s > keyboard: key: %s (pressed: %d) [KeyMod: %x]\n", window_title, mfb_get_key_name(key), isPressed, mod);
|
||||
if(key == KB_KEY_ESCAPE) {
|
||||
mfb_close(window);
|
||||
}
|
||||
}
|
||||
|
||||
void char_input(struct Window *window, unsigned int charCode) {
|
||||
const char *window_title = "";
|
||||
if(window) {
|
||||
window_title = (const char *) mfb_get_user_data(window);
|
||||
}
|
||||
fprintf(stdout, "%s > charCode: %d\n", window_title, charCode);
|
||||
}
|
||||
|
||||
void mouse_btn(struct Window *window, MouseButton button, KeyMod mod, bool isPressed) {
|
||||
const char *window_title = "";
|
||||
if(window) {
|
||||
window_title = (const char *) mfb_get_user_data(window);
|
||||
}
|
||||
fprintf(stdout, "%s > mouse_btn: button: %d (pressed: %d) [KeyMod: %x]\n", window_title, button, isPressed, mod);
|
||||
}
|
||||
|
||||
void mouse_move(struct Window *window, int x, int y) {
|
||||
kUnused(window);
|
||||
kUnused(x);
|
||||
kUnused(y);
|
||||
// const char *window_title = "";
|
||||
// if(window) {
|
||||
// window_t(const char *) itle = mfb_get_user_data(window);
|
||||
// }
|
||||
//fprintf(stdout, "%s > mouse_move: %d, %d\n", window_title, x, y);
|
||||
}
|
||||
|
||||
void mouse_scroll(struct Window *window, KeyMod mod, float deltaX, float deltaY) {
|
||||
const char *window_title = "";
|
||||
if(window) {
|
||||
window_title = (const char *) mfb_get_user_data(window);
|
||||
}
|
||||
fprintf(stdout, "%s > mouse_scroll: x: %f, y: %f [KeyMod: %x]\n", window_title, deltaX, deltaY, mod);
|
||||
}
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
int main()
|
||||
{
|
||||
int noise, carry, seed = 0xbeef;
|
||||
|
||||
struct Window *window = mfb_open_ex("Input Events CPP Test", WIDTH, HEIGHT, WF_RESIZABLE);
|
||||
if (!window)
|
||||
return 0;
|
||||
|
||||
Events e;
|
||||
|
||||
mfb_set_active_callback(window, &e, &Events::active);
|
||||
mfb_set_resize_callback(window, &e, &Events::resize);
|
||||
mfb_set_keyboard_callback(window, &e, &Events::keyboard);
|
||||
mfb_set_char_input_callback(window, &e, &Events::char_input);
|
||||
mfb_set_mouse_button_callback(window, &e, &Events::mouse_btn);
|
||||
mfb_set_mouse_move_callback(window, &e, &Events::mouse_move);
|
||||
mfb_set_mouse_scroll_callback(window, &e, &Events::mouse_scroll);
|
||||
|
||||
mfb_set_user_data(window, (void *) "Input Events CPP Test");
|
||||
|
||||
for (;;)
|
||||
{
|
||||
int i;
|
||||
UpdateState state;
|
||||
|
||||
for (i = 0; i < WIDTH * HEIGHT; ++i)
|
||||
{
|
||||
noise = seed;
|
||||
noise >>= 3;
|
||||
noise ^= seed;
|
||||
carry = noise & 1;
|
||||
noise >>= 1;
|
||||
seed >>= 1;
|
||||
seed |= (carry << 30);
|
||||
noise &= 0xFF;
|
||||
g_buffer[i] = MFB_RGB(noise, noise, noise);
|
||||
}
|
||||
|
||||
state = mfb_update(window, g_buffer);
|
||||
if (state != STATE_OK) {
|
||||
window = 0x0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
#include <MiniFB.h>
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#define kUnused(var) (void) var;
|
||||
|
||||
#define WIDTH 800
|
||||
#define HEIGHT 600
|
||||
static unsigned int g_buffer[WIDTH * HEIGHT];
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class Events {
|
||||
public:
|
||||
void active(struct mfb_window *window, bool isActive) {
|
||||
const char *window_title = "";
|
||||
if(window) {
|
||||
window_title = (const char *) mfb_get_user_data(window);
|
||||
}
|
||||
fprintf(stdout, "%s > active: %d\n", window_title, isActive);
|
||||
}
|
||||
|
||||
void resize(struct mfb_window *window, int width, int height) {
|
||||
uint32_t x = 0;
|
||||
uint32_t y = 0;
|
||||
const char *window_title = "";
|
||||
if(window) {
|
||||
window_title = (const char *) mfb_get_user_data(window);
|
||||
}
|
||||
|
||||
fprintf(stdout, "%s > resize: %d, %d\n", window_title, width, height);
|
||||
if(width > WIDTH) {
|
||||
x = (width - WIDTH) >> 1;
|
||||
width = WIDTH;
|
||||
}
|
||||
if(height > HEIGHT) {
|
||||
y = (height - HEIGHT) >> 1;
|
||||
height = HEIGHT;
|
||||
}
|
||||
mfb_set_viewport(window, x, y, width, height);
|
||||
}
|
||||
|
||||
void keyboard(struct mfb_window *window, mfb_key key, mfb_key_mod mod, bool isPressed) {
|
||||
const char *window_title = "";
|
||||
if(window) {
|
||||
window_title = (const char *) mfb_get_user_data(window);
|
||||
}
|
||||
fprintf(stdout, "%s > keyboard: key: %s (pressed: %d) [key_mod: %x]\n", window_title, mfb_get_key_name(key), isPressed, mod);
|
||||
if(key == KB_KEY_ESCAPE) {
|
||||
mfb_close(window);
|
||||
}
|
||||
}
|
||||
|
||||
void char_input(struct mfb_window *window, unsigned int charCode) {
|
||||
const char *window_title = "";
|
||||
if(window) {
|
||||
window_title = (const char *) mfb_get_user_data(window);
|
||||
}
|
||||
fprintf(stdout, "%s > charCode: %d\n", window_title, charCode);
|
||||
}
|
||||
|
||||
void mouse_btn(struct mfb_window *window, mfb_mouse_button button, mfb_key_mod mod, bool isPressed) {
|
||||
const char *window_title = "";
|
||||
if(window) {
|
||||
window_title = (const char *) mfb_get_user_data(window);
|
||||
}
|
||||
fprintf(stdout, "%s > mouse_btn: button: %d (pressed: %d) [key_mod: %x]\n", window_title, button, isPressed, mod);
|
||||
}
|
||||
|
||||
void mouse_move(struct mfb_window *window, int x, int y) {
|
||||
kUnused(window);
|
||||
kUnused(x);
|
||||
kUnused(y);
|
||||
// const char *window_title = "";
|
||||
// if(window) {
|
||||
// window_t(const char *) itle = mfb_get_user_data(window);
|
||||
// }
|
||||
//fprintf(stdout, "%s > mouse_move: %d, %d\n", window_title, x, y);
|
||||
}
|
||||
|
||||
void mouse_scroll(struct mfb_window *window, mfb_key_mod mod, float deltaX, float deltaY) {
|
||||
const char *window_title = "";
|
||||
if(window) {
|
||||
window_title = (const char *) mfb_get_user_data(window);
|
||||
}
|
||||
fprintf(stdout, "%s > mouse_scroll: x: %f, y: %f [key_mod: %x]\n", window_title, deltaX, deltaY, mod);
|
||||
}
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
int
|
||||
main()
|
||||
{
|
||||
int noise, carry, seed = 0xbeef;
|
||||
|
||||
struct mfb_window *window = mfb_open_ex("Input Events CPP Test", WIDTH, HEIGHT, WF_RESIZABLE);
|
||||
if (!window)
|
||||
return 0;
|
||||
|
||||
Events e;
|
||||
|
||||
mfb_set_active_callback(window, &e, &Events::active);
|
||||
mfb_set_resize_callback(window, &e, &Events::resize);
|
||||
mfb_set_keyboard_callback(window, &e, &Events::keyboard);
|
||||
mfb_set_char_input_callback(window, &e, &Events::char_input);
|
||||
mfb_set_mouse_button_callback(window, &e, &Events::mouse_btn);
|
||||
mfb_set_mouse_move_callback(window, &e, &Events::mouse_move);
|
||||
mfb_set_mouse_scroll_callback(window, &e, &Events::mouse_scroll);
|
||||
|
||||
mfb_set_user_data(window, (void *) "Input Events CPP Test");
|
||||
|
||||
for (;;)
|
||||
{
|
||||
int i;
|
||||
mfb_update_state state;
|
||||
|
||||
for (i = 0; i < WIDTH * HEIGHT; ++i)
|
||||
{
|
||||
noise = seed;
|
||||
noise >>= 3;
|
||||
noise ^= seed;
|
||||
carry = noise & 1;
|
||||
noise >>= 1;
|
||||
seed >>= 1;
|
||||
seed |= (carry << 30);
|
||||
noise &= 0xFF;
|
||||
g_buffer[i] = MFB_RGB(noise, noise, noise);
|
||||
}
|
||||
|
||||
state = mfb_update(window, g_buffer);
|
||||
if (state != STATE_OK) {
|
||||
window = 0x0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -1,188 +1,197 @@
|
||||
#include <MiniFB.h>
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#define _USE_MATH_DEFINES
|
||||
#include <math.h>
|
||||
|
||||
#define kPI 3.14159265358979323846f
|
||||
#define kUnused(var) (void) var;
|
||||
|
||||
#define WIDTH_A 800
|
||||
#define HEIGHT_A 600
|
||||
static unsigned int g_buffer_a[WIDTH_A * HEIGHT_A];
|
||||
|
||||
#define WIDTH_B 320
|
||||
#define HEIGHT_B 240
|
||||
static unsigned int g_buffer_b[WIDTH_B * HEIGHT_B];
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void active(struct Window *window, bool isActive) {
|
||||
const char *window_title = "";
|
||||
if(window) {
|
||||
window_title = (const char *) mfb_get_user_data(window);
|
||||
}
|
||||
fprintf(stdout, "%s > active: %d\n", window_title, isActive);
|
||||
}
|
||||
|
||||
void resize(struct Window *window, int width, int height) {
|
||||
const char *window_title = "";
|
||||
if(window) {
|
||||
window_title = (const char *) mfb_get_user_data(window);
|
||||
}
|
||||
|
||||
fprintf(stdout, "%s > resize: %d, %d\n", window_title, width, height);
|
||||
}
|
||||
|
||||
void keyboard(struct Window *window, Key key, KeyMod mod, bool isPressed) {
|
||||
const char *window_title = "";
|
||||
if(window) {
|
||||
window_title = (const char *) mfb_get_user_data(window);
|
||||
}
|
||||
fprintf(stdout, "%s > keyboard: key: %s (pressed: %d) [KeyMod: %x]\n", window_title, mfb_get_key_name(key), isPressed, mod);
|
||||
if(key == KB_KEY_ESCAPE) {
|
||||
mfb_close(window);
|
||||
}
|
||||
}
|
||||
|
||||
void char_input(struct Window *window, unsigned int charCode) {
|
||||
const char *window_title = "";
|
||||
if(window) {
|
||||
window_title = (const char *) mfb_get_user_data(window);
|
||||
}
|
||||
fprintf(stdout, "%s > charCode: %d\n", window_title, charCode);
|
||||
}
|
||||
|
||||
void mouse_btn(struct Window *window, MouseButton button, KeyMod mod, bool isPressed) {
|
||||
const char *window_title = "";
|
||||
if(window) {
|
||||
window_title = (const char *) mfb_get_user_data(window);
|
||||
}
|
||||
fprintf(stdout, "%s > mouse_btn: button: %d (pressed: %d) [KeyMod: %x]\n", window_title, button, isPressed, mod);
|
||||
}
|
||||
|
||||
void mouse_move(struct Window *window, int x, int y) {
|
||||
kUnused(window);
|
||||
kUnused(x);
|
||||
kUnused(y);
|
||||
// const char *window_title = "";
|
||||
// if(window) {
|
||||
// window_t(const char *) itle = mfb_get_user_data(window);
|
||||
// }
|
||||
//fprintf(stdout, "%s > mouse_move: %d, %d\n", window_title, x, y);
|
||||
}
|
||||
|
||||
void mouse_scroll(struct Window *window, KeyMod mod, float deltaX, float deltaY) {
|
||||
const char *window_title = "";
|
||||
if(window) {
|
||||
window_title = (const char *) mfb_get_user_data(window);
|
||||
}
|
||||
fprintf(stdout, "%s > mouse_scroll: x: %f, y: %f [KeyMod: %x]\n", window_title, deltaX, deltaY, mod);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
int main()
|
||||
{
|
||||
int noise, carry, seed = 0xbeef;
|
||||
|
||||
struct Window *window_a = mfb_open_ex("Multiple Windows Test", WIDTH_A, HEIGHT_A, WF_RESIZABLE);
|
||||
if (!window_a)
|
||||
return 0;
|
||||
|
||||
mfb_set_active_callback(window_a, active);
|
||||
mfb_set_resize_callback(window_a, resize);
|
||||
mfb_set_keyboard_callback(window_a, keyboard);
|
||||
mfb_set_char_input_callback(window_a, char_input);
|
||||
mfb_set_mouse_button_callback(window_a, mouse_btn);
|
||||
mfb_set_mouse_move_callback(window_a, mouse_move);
|
||||
mfb_set_mouse_scroll_callback(window_a, mouse_scroll);
|
||||
|
||||
mfb_set_user_data(window_a, (void *) "Window A");
|
||||
|
||||
//--
|
||||
struct Window *window_b = mfb_open_ex("Secondary Window", WIDTH_B, HEIGHT_B, WF_RESIZABLE);
|
||||
if (!window_b)
|
||||
return 0;
|
||||
|
||||
mfb_set_active_callback(window_b, active);
|
||||
mfb_set_resize_callback(window_b, resize);
|
||||
mfb_set_keyboard_callback(window_b, keyboard);
|
||||
mfb_set_char_input_callback(window_b, char_input);
|
||||
mfb_set_mouse_button_callback(window_b, mouse_btn);
|
||||
mfb_set_mouse_move_callback(window_b, mouse_move);
|
||||
mfb_set_mouse_scroll_callback(window_b, mouse_scroll);
|
||||
|
||||
mfb_set_user_data(window_b, (void *) "Window B");
|
||||
|
||||
// Generate pallete for plasma effect
|
||||
uint32_t pallete[512];
|
||||
float inc = 90.0f / 64.0f;
|
||||
for(uint32_t c=0; c<64; ++c) {
|
||||
int32_t col = (int32_t) ((255.0f * sinf(c * inc * kPI / 180.0f)) + 0.5f);
|
||||
pallete[64*0 + c] = MFB_RGB(col, 0, 0);
|
||||
pallete[64*1 + c] = MFB_RGB(255, col, 0);
|
||||
pallete[64*2 + c] = MFB_RGB(255-col, 255, 0);
|
||||
pallete[64*3 + c] = MFB_RGB(0, 255, col);
|
||||
pallete[64*4 + c] = MFB_RGB(0, 255-col, 255);
|
||||
pallete[64*5 + c] = MFB_RGB(col, 0, 255);
|
||||
pallete[64*6 + c] = MFB_RGB(255, 0, 255-col);
|
||||
pallete[64*7 + c] = MFB_RGB(255-col, 0, 0);
|
||||
}
|
||||
|
||||
//--
|
||||
float time = 0;
|
||||
for (;;)
|
||||
{
|
||||
int i, x, y;
|
||||
float dx, dy, time_x, time_y;
|
||||
int index;
|
||||
UpdateState state_a, state_b;
|
||||
|
||||
for (i = 0; i < WIDTH_A * HEIGHT_A; ++i)
|
||||
{
|
||||
noise = seed;
|
||||
noise >>= 3;
|
||||
noise ^= seed;
|
||||
carry = noise & 1;
|
||||
noise >>= 1;
|
||||
seed >>= 1;
|
||||
seed |= (carry << 30);
|
||||
noise &= 0xFF;
|
||||
g_buffer_a[i] = MFB_RGB(noise, noise, noise);
|
||||
}
|
||||
|
||||
//--
|
||||
time_x = sinf(time * kPI / 180.0f);
|
||||
time_y = cosf(time * kPI / 180.0f);
|
||||
i = 0;
|
||||
for(y=0; y<HEIGHT_B; ++y) {
|
||||
dy = cosf((y * time_y) * kPI / 180.0f); // [-1, 1]
|
||||
for(x=0; x<WIDTH_B; ++x) {
|
||||
dx = sinf((x * time_x) * kPI / 180.0f); // [-1, 1]
|
||||
|
||||
index = (int) ((2.0f + dx + dy) * 0.25f * 511.0f); // [0, 511]
|
||||
g_buffer_b[i++] = pallete[index];
|
||||
}
|
||||
}
|
||||
time += 0.1f;
|
||||
|
||||
//--
|
||||
state_a = mfb_update(window_a, g_buffer_a);
|
||||
if (state_a != STATE_OK) {
|
||||
window_a = 0x0;
|
||||
}
|
||||
|
||||
//--
|
||||
state_b = mfb_update(window_b, g_buffer_b);
|
||||
if (state_b != STATE_OK) {
|
||||
window_b = 0x0;
|
||||
}
|
||||
|
||||
if(window_a == 0x0 && window_b == 0x0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
#include <MiniFB.h>
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#define _USE_MATH_DEFINES
|
||||
#include <math.h>
|
||||
|
||||
#define kPI 3.14159265358979323846f
|
||||
#define kUnused(var) (void) var;
|
||||
|
||||
#define WIDTH_A 800
|
||||
#define HEIGHT_A 600
|
||||
static unsigned int g_buffer_a[WIDTH_A * HEIGHT_A];
|
||||
|
||||
#define WIDTH_B 320
|
||||
#define HEIGHT_B 240
|
||||
static unsigned int g_buffer_b[WIDTH_B * HEIGHT_B];
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void
|
||||
active(struct mfb_window *window, bool isActive) {
|
||||
const char *window_title = "";
|
||||
if(window) {
|
||||
window_title = (const char *) mfb_get_user_data(window);
|
||||
}
|
||||
fprintf(stdout, "%s > active: %d\n", window_title, isActive);
|
||||
}
|
||||
|
||||
void
|
||||
resize(struct mfb_window *window, int width, int height) {
|
||||
const char *window_title = "";
|
||||
if(window) {
|
||||
window_title = (const char *) mfb_get_user_data(window);
|
||||
}
|
||||
|
||||
fprintf(stdout, "%s > resize: %d, %d\n", window_title, width, height);
|
||||
}
|
||||
|
||||
void
|
||||
keyboard(struct mfb_window *window, mfb_key key, mfb_key_mod mod, bool isPressed) {
|
||||
const char *window_title = "";
|
||||
if(window) {
|
||||
window_title = (const char *) mfb_get_user_data(window);
|
||||
}
|
||||
fprintf(stdout, "%s > keyboard: key: %s (pressed: %d) [key_mod: %x]\n", window_title, mfb_get_key_name(key), isPressed, mod);
|
||||
if(key == KB_KEY_ESCAPE) {
|
||||
mfb_close(window);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
char_input(struct mfb_window *window, unsigned int charCode) {
|
||||
const char *window_title = "";
|
||||
if(window) {
|
||||
window_title = (const char *) mfb_get_user_data(window);
|
||||
}
|
||||
fprintf(stdout, "%s > charCode: %d\n", window_title, charCode);
|
||||
}
|
||||
|
||||
void
|
||||
mouse_btn(struct mfb_window *window, mfb_mouse_button button, mfb_key_mod mod, bool isPressed) {
|
||||
const char *window_title = "";
|
||||
if(window) {
|
||||
window_title = (const char *) mfb_get_user_data(window);
|
||||
}
|
||||
fprintf(stdout, "%s > mouse_btn: button: %d (pressed: %d) [key_mod: %x]\n", window_title, button, isPressed, mod);
|
||||
}
|
||||
|
||||
void
|
||||
mouse_move(struct mfb_window *window, int x, int y) {
|
||||
kUnused(window);
|
||||
kUnused(x);
|
||||
kUnused(y);
|
||||
// const char *window_title = "";
|
||||
// if(window) {
|
||||
// window_t(const char *) itle = mfb_get_user_data(window);
|
||||
// }
|
||||
//fprintf(stdout, "%s > mouse_move: %d, %d\n", window_title, x, y);
|
||||
}
|
||||
|
||||
void
|
||||
mouse_scroll(struct mfb_window *window, mfb_key_mod mod, float deltaX, float deltaY) {
|
||||
const char *window_title = "";
|
||||
if(window) {
|
||||
window_title = (const char *) mfb_get_user_data(window);
|
||||
}
|
||||
fprintf(stdout, "%s > mouse_scroll: x: %f, y: %f [key_mod: %x]\n", window_title, deltaX, deltaY, mod);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
int
|
||||
main()
|
||||
{
|
||||
int noise, carry, seed = 0xbeef;
|
||||
|
||||
struct mfb_window *window_a = mfb_open_ex("Multiple Windows Test", WIDTH_A, HEIGHT_A, WF_RESIZABLE);
|
||||
if (!window_a)
|
||||
return 0;
|
||||
|
||||
mfb_set_active_callback(window_a, active);
|
||||
mfb_set_resize_callback(window_a, resize);
|
||||
mfb_set_keyboard_callback(window_a, keyboard);
|
||||
mfb_set_char_input_callback(window_a, char_input);
|
||||
mfb_set_mouse_button_callback(window_a, mouse_btn);
|
||||
mfb_set_mouse_move_callback(window_a, mouse_move);
|
||||
mfb_set_mouse_scroll_callback(window_a, mouse_scroll);
|
||||
|
||||
mfb_set_user_data(window_a, (void *) "Window A");
|
||||
|
||||
//--
|
||||
struct mfb_window *window_b = mfb_open_ex("Secondary Window", WIDTH_B, HEIGHT_B, WF_RESIZABLE);
|
||||
if (!window_b)
|
||||
return 0;
|
||||
|
||||
mfb_set_active_callback(window_b, active);
|
||||
mfb_set_resize_callback(window_b, resize);
|
||||
mfb_set_keyboard_callback(window_b, keyboard);
|
||||
mfb_set_char_input_callback(window_b, char_input);
|
||||
mfb_set_mouse_button_callback(window_b, mouse_btn);
|
||||
mfb_set_mouse_move_callback(window_b, mouse_move);
|
||||
mfb_set_mouse_scroll_callback(window_b, mouse_scroll);
|
||||
|
||||
mfb_set_user_data(window_b, (void *) "Window B");
|
||||
|
||||
// Generate pallete for plasma effect
|
||||
uint32_t pallete[512];
|
||||
float inc = 90.0f / 64.0f;
|
||||
for(uint32_t c=0; c<64; ++c) {
|
||||
int32_t col = (int32_t) ((255.0f * sinf(c * inc * kPI / 180.0f)) + 0.5f);
|
||||
pallete[64*0 + c] = MFB_RGB(col, 0, 0);
|
||||
pallete[64*1 + c] = MFB_RGB(255, col, 0);
|
||||
pallete[64*2 + c] = MFB_RGB(255-col, 255, 0);
|
||||
pallete[64*3 + c] = MFB_RGB(0, 255, col);
|
||||
pallete[64*4 + c] = MFB_RGB(0, 255-col, 255);
|
||||
pallete[64*5 + c] = MFB_RGB(col, 0, 255);
|
||||
pallete[64*6 + c] = MFB_RGB(255, 0, 255-col);
|
||||
pallete[64*7 + c] = MFB_RGB(255-col, 0, 0);
|
||||
}
|
||||
|
||||
//--
|
||||
float time = 0;
|
||||
for (;;)
|
||||
{
|
||||
int i, x, y;
|
||||
float dx, dy, time_x, time_y;
|
||||
int index;
|
||||
|
||||
mfb_update_state state_a, state_b;
|
||||
|
||||
for (i = 0; i < WIDTH_A * HEIGHT_A; ++i)
|
||||
{
|
||||
noise = seed;
|
||||
noise >>= 3;
|
||||
noise ^= seed;
|
||||
carry = noise & 1;
|
||||
noise >>= 1;
|
||||
seed >>= 1;
|
||||
seed |= (carry << 30);
|
||||
noise &= 0xFF;
|
||||
g_buffer_a[i] = MFB_RGB(noise, noise, noise);
|
||||
}
|
||||
|
||||
//--
|
||||
time_x = sinf(time * kPI / 180.0f);
|
||||
time_y = cosf(time * kPI / 180.0f);
|
||||
i = 0;
|
||||
for(y=0; y<HEIGHT_B; ++y) {
|
||||
dy = cosf((y * time_y) * kPI / 180.0f); // [-1, 1]
|
||||
for(x=0; x<WIDTH_B; ++x) {
|
||||
dx = sinf((x * time_x) * kPI / 180.0f); // [-1, 1]
|
||||
|
||||
index = (int) ((2.0f + dx + dy) * 0.25f * 511.0f); // [0, 511]
|
||||
g_buffer_b[i++] = pallete[index];
|
||||
}
|
||||
}
|
||||
time += 0.1f;
|
||||
|
||||
//--
|
||||
state_a = mfb_update(window_a, g_buffer_a);
|
||||
if (state_a != STATE_OK) {
|
||||
window_a = 0x0;
|
||||
}
|
||||
|
||||
//--
|
||||
state_b = mfb_update(window_b, g_buffer_b);
|
||||
if (state_b != STATE_OK) {
|
||||
window_b = 0x0;
|
||||
}
|
||||
|
||||
if(window_a == 0x0 && window_b == 0x0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -1,45 +1,46 @@
|
||||
#include <MiniFB.h>
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#define WIDTH 800
|
||||
#define HEIGHT 600
|
||||
static unsigned int g_buffer[WIDTH * HEIGHT];
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
int main()
|
||||
{
|
||||
int noise, carry, seed = 0xbeef;
|
||||
|
||||
struct Window *window = mfb_open_ex("Noise Test", WIDTH, HEIGHT, WF_RESIZABLE);
|
||||
if (!window)
|
||||
return 0;
|
||||
|
||||
for (;;)
|
||||
{
|
||||
int i;
|
||||
UpdateState state;
|
||||
|
||||
for (i = 0; i < WIDTH * HEIGHT; ++i)
|
||||
{
|
||||
noise = seed;
|
||||
noise >>= 3;
|
||||
noise ^= seed;
|
||||
carry = noise & 1;
|
||||
noise >>= 1;
|
||||
seed >>= 1;
|
||||
seed |= (carry << 30);
|
||||
noise &= 0xFF;
|
||||
g_buffer[i] = MFB_RGB(noise, noise, noise);
|
||||
}
|
||||
|
||||
state = mfb_update(window, g_buffer);
|
||||
if (state != STATE_OK) {
|
||||
window = 0x0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
#include <MiniFB.h>
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#define WIDTH 800
|
||||
#define HEIGHT 600
|
||||
static unsigned int g_buffer[WIDTH * HEIGHT];
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
int
|
||||
main()
|
||||
{
|
||||
int noise, carry, seed = 0xbeef;
|
||||
|
||||
struct mfb_window *window = mfb_open_ex("Noise Test", WIDTH, HEIGHT, WF_RESIZABLE);
|
||||
if (!window)
|
||||
return 0;
|
||||
|
||||
for (;;)
|
||||
{
|
||||
int i;
|
||||
mfb_update_state state;
|
||||
|
||||
for (i = 0; i < WIDTH * HEIGHT; ++i)
|
||||
{
|
||||
noise = seed;
|
||||
noise >>= 3;
|
||||
noise ^= seed;
|
||||
carry = noise & 1;
|
||||
noise >>= 1;
|
||||
seed >>= 1;
|
||||
seed |= (carry << 30);
|
||||
noise &= 0xFF;
|
||||
g_buffer[i] = MFB_RGB(noise, noise, noise);
|
||||
}
|
||||
|
||||
state = mfb_update(window, g_buffer);
|
||||
if (state != STATE_OK) {
|
||||
window = 0x0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
Reference in New Issue
Block a user