Direct mode (#23)

* update documentation

* Fix typo

* Added some examples

* changed window names

* Minor fix

* renamed callback setters (added _set_)
Direct / Poll Mode for asking events:
 bool            mfb_is_window_active(struct Window *window);
unsigned        mfb_get_window_width(struct Window *window);
unsigned        mfb_get_window_height(struct Window *window);
int             mfb_get_mouse_x(struct Window *window);            // Last mouse pos X
int             mfb_get_mouse_y(struct Window *window);            // Last mouse pos Y
float           mfb_get_mouse_scrool_x(struct Window *window);     // Mouse wheel X as a sum. When you call this function it resets.
float           mfb_get_mouse_scrool_y(struct Window *window);     // Mouse wheel Y as a sum. When you call this function it resets.
const uint8_t * mfb_get_mouse_button_buffer(struct Window *window);  // One byte for every button. Press (1), Release 0.
const uint8_t * mfb_get_key_buffer(struct Window *window);           // One byte for every key. Press (1), Release 0.

* Minor fixes

* Fixes related to mouse poll

* Minor fix on Win64
This commit is contained in:
Carlos Aragonés
2019-11-14 16:18:42 +01:00
committed by Daniel Collin
parent 25a440f822
commit cdaa54f5d6
17 changed files with 732 additions and 602 deletions

View File

@ -94,13 +94,13 @@ int main()
if (!window)
return 0;
mfb_active_callback(window, active);
mfb_resize_callback(window, resize);
mfb_keyboard_callback(window, keyboard);
mfb_char_input_callback(window, char_input);
mfb_mouse_button_callback(window, mouse_btn);
mfb_mouse_move_callback(window, mouse_move);
mfb_mouse_scroll_callback(window, mouse_scroll);
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");

View File

@ -99,13 +99,13 @@ int main()
Events e;
mfb_active_callback(window, &e, &Events::active);
mfb_resize_callback(window, &e, &Events::resize);
mfb_keyboard_callback(window, &e, &Events::keyboard);
mfb_char_input_callback(window, &e, &Events::char_input);
mfb_mouse_button_callback(window, &e, &Events::mouse_btn);
mfb_mouse_move_callback(window, &e, &Events::mouse_move);
mfb_mouse_scroll_callback(window, &e, &Events::mouse_scroll);
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");

View File

@ -1,8 +1,10 @@
#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
@ -88,13 +90,13 @@ int main()
if (!window_a)
return 0;
mfb_active_callback(window_a, active);
mfb_resize_callback(window_a, resize);
mfb_keyboard_callback(window_a, keyboard);
mfb_char_input_callback(window_a, char_input);
mfb_mouse_button_callback(window_a, mouse_btn);
mfb_mouse_move_callback(window_a, mouse_move);
mfb_mouse_scroll_callback(window_a, mouse_scroll);
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");
@ -103,13 +105,13 @@ int main()
if (!window_b)
return 0;
mfb_active_callback(window_b, active);
mfb_resize_callback(window_b, resize);
mfb_keyboard_callback(window_b, keyboard);
mfb_char_input_callback(window_b, char_input);
mfb_mouse_button_callback(window_b, mouse_btn);
mfb_mouse_move_callback(window_b, mouse_move);
mfb_mouse_scroll_callback(window_b, mouse_scroll);
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");
@ -117,7 +119,7 @@ int main()
uint32_t pallete[512];
float inc = 90.0f / 64.0f;
for(uint32_t c=0; c<64; ++c) {
int32_t col = (255.0f * sinf(c * inc * M_PI / 180.0f)) + 0.5f;
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);
@ -151,13 +153,13 @@ int main()
}
//--
time_x = sinf(time * M_PI / 180.0f);
time_y = cosf(time * M_PI / 180.0f);
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) * M_PI / 180.0f); // [-1, 1]
dy = cosf((y * time_y) * kPI / 180.0f); // [-1, 1]
for(x=0; x<WIDTH_B; ++x) {
dx = sinf((x * time_x) * M_PI / 180.0f); // [-1, 1]
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];