added mfb_update_ex - Windows version
This commit is contained in:
parent
dda1275bd7
commit
f09780d761
@ -23,6 +23,8 @@ struct mfb_window * mfb_open_ex(const char *title, unsigned width, unsigned heig
|
|||||||
// Also updates the window events
|
// Also updates the window events
|
||||||
mfb_update_state mfb_update(struct mfb_window *window, void *buffer);
|
mfb_update_state mfb_update(struct mfb_window *window, void *buffer);
|
||||||
|
|
||||||
|
mfb_update_state mfb_update_ex(struct mfb_window *window, void *buffer, unsigned width, unsigned height);
|
||||||
|
|
||||||
// Only updates the window events
|
// Only updates the window events
|
||||||
mfb_update_state mfb_update_events(struct mfb_window *window);
|
mfb_update_state mfb_update_events(struct mfb_window *window);
|
||||||
|
|
||||||
|
@ -375,13 +375,26 @@ mfb_open(const char *title, unsigned width, unsigned height) {
|
|||||||
|
|
||||||
mfb_update_state
|
mfb_update_state
|
||||||
mfb_update(struct mfb_window *window, void *buffer) {
|
mfb_update(struct mfb_window *window, void *buffer) {
|
||||||
|
if (window == 0x0) {
|
||||||
|
return STATE_INVALID_WINDOW;
|
||||||
|
}
|
||||||
|
|
||||||
|
SWindowData *window_data = (SWindowData *) window;
|
||||||
|
|
||||||
|
return mfb_update_ex(window, buffer, window_data->buffer_width, window_data->buffer_height);
|
||||||
|
}
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
mfb_update_state
|
||||||
|
mfb_update_ex(struct mfb_window *window, void *buffer, unsigned width, unsigned height) {
|
||||||
MSG msg;
|
MSG msg;
|
||||||
|
|
||||||
if (window == 0x0) {
|
if (window == 0x0) {
|
||||||
return STATE_INVALID_WINDOW;
|
return STATE_INVALID_WINDOW;
|
||||||
}
|
}
|
||||||
|
|
||||||
SWindowData *window_data = (SWindowData *)window;
|
SWindowData *window_data = (SWindowData *) window;
|
||||||
if (window_data->close) {
|
if (window_data->close) {
|
||||||
destroy_window_data(window_data);
|
destroy_window_data(window_data);
|
||||||
return STATE_EXIT;
|
return STATE_EXIT;
|
||||||
@ -391,9 +404,13 @@ mfb_update(struct mfb_window *window, void *buffer) {
|
|||||||
return STATE_INVALID_BUFFER;
|
return STATE_INVALID_BUFFER;
|
||||||
}
|
}
|
||||||
|
|
||||||
window_data->draw_buffer = buffer;
|
window_data->draw_buffer = buffer;
|
||||||
|
window_data->buffer_width = width;
|
||||||
|
window_data->buffer_height = height;
|
||||||
|
|
||||||
SWindowData_Win *window_data_win = (SWindowData_Win *) window_data->specific;
|
SWindowData_Win *window_data_win = (SWindowData_Win *) window_data->specific;
|
||||||
|
window_data_win->bitmapInfo->bmiHeader.biWidth = window_data->buffer_width;
|
||||||
|
window_data_win->bitmapInfo->bmiHeader.biHeight = -(LONG) window_data->buffer_height;
|
||||||
InvalidateRect(window_data_win->window, 0x0, TRUE);
|
InvalidateRect(window_data_win->window, 0x0, TRUE);
|
||||||
SendMessage(window_data_win->window, WM_PAINT, 0, 0);
|
SendMessage(window_data_win->window, WM_PAINT, 0, 0);
|
||||||
|
|
||||||
@ -692,7 +709,7 @@ translate_key(unsigned int wParam, unsigned long lParam) {
|
|||||||
|
|
||||||
bool
|
bool
|
||||||
mfb_set_viewport(struct mfb_window *window, unsigned offset_x, unsigned offset_y, unsigned width, unsigned height) {
|
mfb_set_viewport(struct mfb_window *window, unsigned offset_x, unsigned offset_y, unsigned width, unsigned height) {
|
||||||
SWindowData *window_data = (SWindowData *) window;
|
SWindowData *window_data = (SWindowData *) window;
|
||||||
|
|
||||||
if (offset_x + width > window_data->window_width) {
|
if (offset_x + width > window_data->window_width) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -1,25 +1,38 @@
|
|||||||
#include <MiniFB.h>
|
#include <MiniFB.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
#define WIDTH 800
|
static uint32_t g_width = 800;
|
||||||
#define HEIGHT 600
|
static uint32_t g_height = 600;
|
||||||
static unsigned int g_buffer[WIDTH * HEIGHT];
|
static uint32_t *g_buffer = 0x0;
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
void
|
||||||
|
resize(struct mfb_window *window, int width, int height) {
|
||||||
|
g_width = width;
|
||||||
|
g_height = height;
|
||||||
|
g_buffer = realloc(g_buffer, g_width * g_height * 4);
|
||||||
|
}
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
int
|
int
|
||||||
main()
|
main()
|
||||||
{
|
{
|
||||||
int i, noise, carry, seed = 0xbeef;
|
uint32_t i, noise, carry, seed = 0xbeef;
|
||||||
|
|
||||||
struct mfb_window *window = mfb_open_ex("Noise Test", WIDTH, HEIGHT, WF_RESIZABLE);
|
struct mfb_window *window = mfb_open_ex("Noise Test", g_width, g_height, WF_RESIZABLE);
|
||||||
if (!window)
|
if (!window)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
g_buffer = (uint32_t *) malloc(g_width * g_height * 4);
|
||||||
|
mfb_set_resize_callback(window, resize);
|
||||||
|
|
||||||
mfb_update_state state;
|
mfb_update_state state;
|
||||||
do {
|
do {
|
||||||
for (i = 0; i < WIDTH * HEIGHT; ++i) {
|
for (i = 0; i < g_width * g_height; ++i) {
|
||||||
noise = seed;
|
noise = seed;
|
||||||
noise >>= 3;
|
noise >>= 3;
|
||||||
noise ^= seed;
|
noise ^= seed;
|
||||||
@ -31,7 +44,7 @@ main()
|
|||||||
g_buffer[i] = MFB_RGB(noise, noise, noise);
|
g_buffer[i] = MFB_RGB(noise, noise, noise);
|
||||||
}
|
}
|
||||||
|
|
||||||
state = mfb_update(window, g_buffer);
|
state = mfb_update_ex(window, g_buffer, g_width, g_height);
|
||||||
if (state != STATE_OK) {
|
if (state != STATE_OK) {
|
||||||
window = 0x0;
|
window = 0x0;
|
||||||
break;
|
break;
|
||||||
|
Loading…
Reference in New Issue
Block a user