spaces and LF please
This commit is contained in:
1 parent
a2671bed5d
commit
cd6332fe0a
11 files changed
+3616
-3616
No files matched your search
+79
-79
@@ -1,80 +1,80 @@
|
||||
// audio.h
|
||||
#pragma once
|
||||
#ifndef AUDIO_H
|
||||
#define AUDIO_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
#include <cstdint>
|
||||
extern "C" {
|
||||
#else
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#endif
|
||||
|
||||
typedef struct audio_t audio_t;
|
||||
typedef uint32_t audio_stream_id_t;
|
||||
|
||||
// If the return type is bool, false means failure.
|
||||
|
||||
// Initialize audio system
|
||||
// nullptr means failure
|
||||
audio_t* audio_init(void);
|
||||
|
||||
// Destroy audio system and free resources
|
||||
void audio_destroy(audio_t* audio);
|
||||
|
||||
// Load MADPCM data from a WAV file.
|
||||
// Returns a pointer to the allocated audio data, or nullptr on failure.
|
||||
// The returned buffer must be freed with audio_free_data().
|
||||
uint8_t* audio_load_madpcm(const char* filename, int* out_size, int* out_channels, int* out_rate, int* out_total_samples);
|
||||
|
||||
// Free data allocated by audio_load_madpcm
|
||||
void audio_free_data(uint8_t* data);
|
||||
|
||||
// Play a MADPCM stream, returns unique ID
|
||||
// data must remain valid until the stream ends or is stopped
|
||||
// loop: if true, the stream restarts on EOF
|
||||
// 0 means failure, valid IDs start from 1
|
||||
audio_stream_id_t audio_play(audio_t* audio,
|
||||
const uint8_t* data,
|
||||
int size,
|
||||
int channels,
|
||||
int rate,
|
||||
bool loop);
|
||||
|
||||
// Stop and remove stream by ID
|
||||
bool audio_stop(audio_t* audio, audio_stream_id_t id);
|
||||
|
||||
bool audio_pause(audio_t* audio, audio_stream_id_t id);
|
||||
bool audio_resume(audio_t* audio, audio_stream_id_t id);
|
||||
|
||||
// Returns true if the stream is active (playing or paused)
|
||||
bool audio_is_active(audio_t* audio, audio_stream_id_t id);
|
||||
|
||||
// Returns true if the stream is currently playing (not paused, not stopped)
|
||||
bool audio_is_playing(audio_t* audio, audio_stream_id_t id);
|
||||
|
||||
// Per-stream volume, immediate effect, range [0.0, 1.0]
|
||||
bool audio_set_volume(audio_t* audio, audio_stream_id_t id, float volume);
|
||||
|
||||
// Animate per-stream volume linearly over time, driven by audio_tick()
|
||||
bool audio_animate_volume(audio_t* audio, audio_stream_id_t id,
|
||||
float to_volume, float duration_sec);
|
||||
|
||||
// Global volume, immediate effect, range [0.0, 1.0]
|
||||
// Applied on top of per-stream volume at mix time
|
||||
void audio_set_global_volume(audio_t* audio, float volume);
|
||||
|
||||
// Animate global volume linearly over time, driven by audio_tick()
|
||||
void audio_animate_global_volume(audio_t* audio,
|
||||
float to_volume, float duration_sec);
|
||||
|
||||
// Advances stream decoding and volume animations
|
||||
// Call once per main loop iteration with the same delta as compositor_tick()
|
||||
void audio_tick(audio_t* audio, float delta_time_sec);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
// audio.h
|
||||
#pragma once
|
||||
#ifndef AUDIO_H
|
||||
#define AUDIO_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
#include <cstdint>
|
||||
extern "C" {
|
||||
#else
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#endif
|
||||
|
||||
typedef struct audio_t audio_t;
|
||||
typedef uint32_t audio_stream_id_t;
|
||||
|
||||
// If the return type is bool, false means failure.
|
||||
|
||||
// Initialize audio system
|
||||
// nullptr means failure
|
||||
audio_t* audio_init(void);
|
||||
|
||||
// Destroy audio system and free resources
|
||||
void audio_destroy(audio_t* audio);
|
||||
|
||||
// Load MADPCM data from a WAV file.
|
||||
// Returns a pointer to the allocated audio data, or nullptr on failure.
|
||||
// The returned buffer must be freed with audio_free_data().
|
||||
uint8_t* audio_load_madpcm(const char* filename, int* out_size, int* out_channels, int* out_rate, int* out_total_samples);
|
||||
|
||||
// Free data allocated by audio_load_madpcm
|
||||
void audio_free_data(uint8_t* data);
|
||||
|
||||
// Play a MADPCM stream, returns unique ID
|
||||
// data must remain valid until the stream ends or is stopped
|
||||
// loop: if true, the stream restarts on EOF
|
||||
// 0 means failure, valid IDs start from 1
|
||||
audio_stream_id_t audio_play(audio_t* audio,
|
||||
const uint8_t* data,
|
||||
int size,
|
||||
int channels,
|
||||
int rate,
|
||||
bool loop);
|
||||
|
||||
// Stop and remove stream by ID
|
||||
bool audio_stop(audio_t* audio, audio_stream_id_t id);
|
||||
|
||||
bool audio_pause(audio_t* audio, audio_stream_id_t id);
|
||||
bool audio_resume(audio_t* audio, audio_stream_id_t id);
|
||||
|
||||
// Returns true if the stream is active (playing or paused)
|
||||
bool audio_is_active(audio_t* audio, audio_stream_id_t id);
|
||||
|
||||
// Returns true if the stream is currently playing (not paused, not stopped)
|
||||
bool audio_is_playing(audio_t* audio, audio_stream_id_t id);
|
||||
|
||||
// Per-stream volume, immediate effect, range [0.0, 1.0]
|
||||
bool audio_set_volume(audio_t* audio, audio_stream_id_t id, float volume);
|
||||
|
||||
// Animate per-stream volume linearly over time, driven by audio_tick()
|
||||
bool audio_animate_volume(audio_t* audio, audio_stream_id_t id,
|
||||
float to_volume, float duration_sec);
|
||||
|
||||
// Global volume, immediate effect, range [0.0, 1.0]
|
||||
// Applied on top of per-stream volume at mix time
|
||||
void audio_set_global_volume(audio_t* audio, float volume);
|
||||
|
||||
// Animate global volume linearly over time, driven by audio_tick()
|
||||
void audio_animate_global_volume(audio_t* audio,
|
||||
float to_volume, float duration_sec);
|
||||
|
||||
// Advances stream decoding and volume animations
|
||||
// Call once per main loop iteration with the same delta as compositor_tick()
|
||||
void audio_tick(audio_t* audio, float delta_time_sec);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // AUDIO_H
|
||||
+119
-119
@@ -1,120 +1,120 @@
|
||||
// compositor.h v0.3
|
||||
#pragma once
|
||||
#ifndef COMPOSITOR_H
|
||||
#define COMPOSITOR_H
|
||||
|
||||
// This subsystem is thread-unsafe.
|
||||
// Caller must serialize all calls. Calls do not need to be made from the main thread.
|
||||
// Removing an element while ticking/rendering may crash.
|
||||
// Modifying an element while ticking/rendering may cause visual glitches.
|
||||
|
||||
// Easing functions
|
||||
enum easing_t {
|
||||
EASE_LINEAR = 0,
|
||||
EASE_IN_QUAD,
|
||||
EASE_OUT_QUAD,
|
||||
EASE_IN_OUT_QUAD,
|
||||
EASE_IN_CUBIC,
|
||||
EASE_OUT_CUBIC,
|
||||
EASE_IN_OUT_CUBIC
|
||||
};
|
||||
|
||||
// Anchor points
|
||||
enum anchor_point_t {
|
||||
ANCHOR_TOP_LEFT,
|
||||
ANCHOR_TOP_CENTER,
|
||||
ANCHOR_TOP_RIGHT,
|
||||
ANCHOR_CENTER_LEFT,
|
||||
ANCHOR_CENTER,
|
||||
ANCHOR_CENTER_RIGHT,
|
||||
ANCHOR_BOTTOM_LEFT,
|
||||
ANCHOR_BOTTOM_CENTER,
|
||||
ANCHOR_BOTTOM_RIGHT,
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
#include <cstdint>
|
||||
extern "C" {
|
||||
#else
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#endif
|
||||
|
||||
typedef struct compositor_t compositor_t;
|
||||
typedef uint32_t element_handle_t;
|
||||
|
||||
// If the return type is bool, false means failure.
|
||||
|
||||
// Initialize compositor with given dimensions
|
||||
// nullptr means failure
|
||||
compositor_t* compositor_init(uint32_t width, uint32_t height);
|
||||
|
||||
// Destroy compositor and free resources. Everything dies with it.
|
||||
void compositor_destroy(compositor_t* comp);
|
||||
|
||||
// Insert element, returns unique ID
|
||||
// FB format is ARGB8888 and it always will be
|
||||
// The compositor takes a reference, caller must keep alive until removed
|
||||
// 0 means failure, valid IDs start from 1
|
||||
element_handle_t compositor_insert(compositor_t* comp,
|
||||
const uint32_t* fb,
|
||||
uint32_t fb_width,
|
||||
uint32_t fb_height,
|
||||
int32_t x, int32_t y,
|
||||
int32_t z_order, float scale,
|
||||
anchor_point_t anchor);
|
||||
|
||||
// Remove element by ID
|
||||
bool compositor_remove(compositor_t* comp, element_handle_t id);
|
||||
|
||||
// Setters, immediate effect
|
||||
bool compositor_set_position(compositor_t* comp, element_handle_t id,
|
||||
int32_t x, int32_t y);
|
||||
bool compositor_set_zorder(compositor_t* comp, element_handle_t id,
|
||||
int32_t z_order);
|
||||
bool compositor_set_scale(compositor_t* comp, element_handle_t id,
|
||||
float scale);
|
||||
bool compositor_set_visible(compositor_t* comp, element_handle_t id,
|
||||
bool visible);
|
||||
bool compositor_set_alpha(compositor_t* comp, element_handle_t id,
|
||||
float alpha);
|
||||
|
||||
// Advances all animations by a given time delta.
|
||||
void compositor_tick(compositor_t* comp, float delta_time_sec);
|
||||
|
||||
// Sets a target state to advance over time by tick()
|
||||
// Queue means the animation will start after the previous animation completed
|
||||
// Not queueing will play the animation alongside any current animation
|
||||
// You cannot stack the same type of animation without queueing, the second call will cancel the first call.
|
||||
bool compositor_animate_move(compositor_t* comp, element_handle_t id,
|
||||
int32_t to_x, int32_t to_y,
|
||||
float duration_sec, easing_t easing, bool queue, bool parallel);
|
||||
bool compositor_animate_fade(compositor_t* comp, element_handle_t id,
|
||||
float to_alpha,
|
||||
float duration_sec, easing_t easing, bool queue, bool parallel);
|
||||
bool compositor_animate_scale(compositor_t* comp, element_handle_t id,
|
||||
float to_scale,
|
||||
float duration_sec, easing_t easing, bool queue, bool parallel);
|
||||
|
||||
// Immediately finish all animations on a specific object (optionally only N queued, 0 = all), or every object.
|
||||
bool compositor_animation_finish_element(compositor_t* comp, element_handle_t id, int num_queued /*0=all*/);
|
||||
void compositor_animation_finish_all(compositor_t* comp);
|
||||
|
||||
// Returns true if any element is animating or has queued animations.
|
||||
bool compositor_is_animating(compositor_t* comp);
|
||||
|
||||
// Returns true if the specified element is animating or has queued animations.
|
||||
bool compositor_is_element_animating(compositor_t* comp, element_handle_t id);
|
||||
|
||||
// Compose all visible elements and return framebuffer pointer
|
||||
const uint32_t* compositor_compose(compositor_t* comp);
|
||||
|
||||
// Mark an element's content as dirty for redrawing
|
||||
bool compositor_mark_content_dirty(compositor_t* comp, element_handle_t id);
|
||||
void compositor_mark_all_dirty(compositor_t* comp);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
// compositor.h v0.3
|
||||
#pragma once
|
||||
#ifndef COMPOSITOR_H
|
||||
#define COMPOSITOR_H
|
||||
|
||||
// This subsystem is thread-unsafe.
|
||||
// Caller must serialize all calls. Calls do not need to be made from the main thread.
|
||||
// Removing an element while ticking/rendering may crash.
|
||||
// Modifying an element while ticking/rendering may cause visual glitches.
|
||||
|
||||
// Easing functions
|
||||
enum easing_t {
|
||||
EASE_LINEAR = 0,
|
||||
EASE_IN_QUAD,
|
||||
EASE_OUT_QUAD,
|
||||
EASE_IN_OUT_QUAD,
|
||||
EASE_IN_CUBIC,
|
||||
EASE_OUT_CUBIC,
|
||||
EASE_IN_OUT_CUBIC
|
||||
};
|
||||
|
||||
// Anchor points
|
||||
enum anchor_point_t {
|
||||
ANCHOR_TOP_LEFT,
|
||||
ANCHOR_TOP_CENTER,
|
||||
ANCHOR_TOP_RIGHT,
|
||||
ANCHOR_CENTER_LEFT,
|
||||
ANCHOR_CENTER,
|
||||
ANCHOR_CENTER_RIGHT,
|
||||
ANCHOR_BOTTOM_LEFT,
|
||||
ANCHOR_BOTTOM_CENTER,
|
||||
ANCHOR_BOTTOM_RIGHT,
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
#include <cstdint>
|
||||
extern "C" {
|
||||
#else
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#endif
|
||||
|
||||
typedef struct compositor_t compositor_t;
|
||||
typedef uint32_t element_handle_t;
|
||||
|
||||
// If the return type is bool, false means failure.
|
||||
|
||||
// Initialize compositor with given dimensions
|
||||
// nullptr means failure
|
||||
compositor_t* compositor_init(uint32_t width, uint32_t height);
|
||||
|
||||
// Destroy compositor and free resources. Everything dies with it.
|
||||
void compositor_destroy(compositor_t* comp);
|
||||
|
||||
// Insert element, returns unique ID
|
||||
// FB format is ARGB8888 and it always will be
|
||||
// The compositor takes a reference, caller must keep alive until removed
|
||||
// 0 means failure, valid IDs start from 1
|
||||
element_handle_t compositor_insert(compositor_t* comp,
|
||||
const uint32_t* fb,
|
||||
uint32_t fb_width,
|
||||
uint32_t fb_height,
|
||||
int32_t x, int32_t y,
|
||||
int32_t z_order, float scale,
|
||||
anchor_point_t anchor);
|
||||
|
||||
// Remove element by ID
|
||||
bool compositor_remove(compositor_t* comp, element_handle_t id);
|
||||
|
||||
// Setters, immediate effect
|
||||
bool compositor_set_position(compositor_t* comp, element_handle_t id,
|
||||
int32_t x, int32_t y);
|
||||
bool compositor_set_zorder(compositor_t* comp, element_handle_t id,
|
||||
int32_t z_order);
|
||||
bool compositor_set_scale(compositor_t* comp, element_handle_t id,
|
||||
float scale);
|
||||
bool compositor_set_visible(compositor_t* comp, element_handle_t id,
|
||||
bool visible);
|
||||
bool compositor_set_alpha(compositor_t* comp, element_handle_t id,
|
||||
float alpha);
|
||||
|
||||
// Advances all animations by a given time delta.
|
||||
void compositor_tick(compositor_t* comp, float delta_time_sec);
|
||||
|
||||
// Sets a target state to advance over time by tick()
|
||||
// Queue means the animation will start after the previous animation completed
|
||||
// Not queueing will play the animation alongside any current animation
|
||||
// You cannot stack the same type of animation without queueing, the second call will cancel the first call.
|
||||
bool compositor_animate_move(compositor_t* comp, element_handle_t id,
|
||||
int32_t to_x, int32_t to_y,
|
||||
float duration_sec, easing_t easing, bool queue, bool parallel);
|
||||
bool compositor_animate_fade(compositor_t* comp, element_handle_t id,
|
||||
float to_alpha,
|
||||
float duration_sec, easing_t easing, bool queue, bool parallel);
|
||||
bool compositor_animate_scale(compositor_t* comp, element_handle_t id,
|
||||
float to_scale,
|
||||
float duration_sec, easing_t easing, bool queue, bool parallel);
|
||||
|
||||
// Immediately finish all animations on a specific object (optionally only N queued, 0 = all), or every object.
|
||||
bool compositor_animation_finish_element(compositor_t* comp, element_handle_t id, int num_queued /*0=all*/);
|
||||
void compositor_animation_finish_all(compositor_t* comp);
|
||||
|
||||
// Returns true if any element is animating or has queued animations.
|
||||
bool compositor_is_animating(compositor_t* comp);
|
||||
|
||||
// Returns true if the specified element is animating or has queued animations.
|
||||
bool compositor_is_element_animating(compositor_t* comp, element_handle_t id);
|
||||
|
||||
// Compose all visible elements and return framebuffer pointer
|
||||
const uint32_t* compositor_compose(compositor_t* comp);
|
||||
|
||||
// Mark an element's content as dirty for redrawing
|
||||
bool compositor_mark_content_dirty(compositor_t* comp, element_handle_t id);
|
||||
void compositor_mark_all_dirty(compositor_t* comp);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // COMPOSITOR_H
|
||||
+24
-24
@@ -1,24 +1,24 @@
|
||||
// image.h
|
||||
#pragma once
|
||||
#ifndef IMAGE_H
|
||||
#define IMAGE_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
#include <cstdint>
|
||||
extern "C" {
|
||||
#else
|
||||
#include <stdint.h>
|
||||
#endif
|
||||
|
||||
// Loads an image file as ARGB8888. Returns pointer to pixel data, sets width/height. NULL on failure.
|
||||
uint32_t* image_load(const char* filename, int* width, int* height);
|
||||
// Loads and resizes an image file to desired dimensions as ARGB8888. Returns pointer to pixel data. NULL on failure.
|
||||
uint32_t* image_load_resized(const char* filename, int desired_width, int desired_height);
|
||||
// Frees image data.
|
||||
void image_free(uint32_t* data);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // IMAGE_H
|
||||
// image.h
|
||||
#pragma once
|
||||
#ifndef IMAGE_H
|
||||
#define IMAGE_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
#include <cstdint>
|
||||
extern "C" {
|
||||
#else
|
||||
#include <stdint.h>
|
||||
#endif
|
||||
|
||||
// Loads an image file as ARGB8888. Returns pointer to pixel data, sets width/height. NULL on failure.
|
||||
uint32_t* image_load(const char* filename, int* width, int* height);
|
||||
// Loads and resizes an image file to desired dimensions as ARGB8888. Returns pointer to pixel data. NULL on failure.
|
||||
uint32_t* image_load_resized(const char* filename, int desired_width, int desired_height);
|
||||
// Frees image data.
|
||||
void image_free(uint32_t* data);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // IMAGE_H
|
||||
+44
-44
@@ -1,45 +1,45 @@
|
||||
// text.h
|
||||
#pragma once
|
||||
#ifndef TEXT_RENDERER_H
|
||||
#define TEXT_RENDERER_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
struct text_t;
|
||||
|
||||
#ifdef __cplusplus
|
||||
#include <cstdint>
|
||||
extern "C" {
|
||||
#else
|
||||
#include <stdint.h>
|
||||
#endif
|
||||
|
||||
// initializes a new text renderer with given width and height
|
||||
text_t* text_init(int width, int height);
|
||||
// shares cache, prefer when using the same font to save memory
|
||||
text_t* text_init_shared(text_t* source, int width, int height);
|
||||
// destroys the text renderer and frees resources
|
||||
void text_destroy(text_t* text);
|
||||
// pushes new text buffer to be rendered, can be stacked
|
||||
void text_push(text_t* text,
|
||||
const char* str,
|
||||
float speed,
|
||||
bool outline);
|
||||
// load font and set as current font
|
||||
void text_set_font(text_t* text, const char* font_path, float size);
|
||||
// finish whole current text buffer immediately
|
||||
void text_show_all_current(text_t* text);
|
||||
// returns true if text is still animating
|
||||
bool text_is_animating(text_t* text);
|
||||
// advance, call every frame, returns true when it touched the framebuffer
|
||||
bool text_nextframe(text_t* text, float deltatime);
|
||||
// gets the framebuffer of the text renderer
|
||||
const uint32_t* text_getfb(text_t* text);
|
||||
// clears the text buffer and the frame buffer
|
||||
void text_clear(text_t* text);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
// text.h
|
||||
#pragma once
|
||||
#ifndef TEXT_RENDERER_H
|
||||
#define TEXT_RENDERER_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
struct text_t;
|
||||
|
||||
#ifdef __cplusplus
|
||||
#include <cstdint>
|
||||
extern "C" {
|
||||
#else
|
||||
#include <stdint.h>
|
||||
#endif
|
||||
|
||||
// initializes a new text renderer with given width and height
|
||||
text_t* text_init(int width, int height);
|
||||
// shares cache, prefer when using the same font to save memory
|
||||
text_t* text_init_shared(text_t* source, int width, int height);
|
||||
// destroys the text renderer and frees resources
|
||||
void text_destroy(text_t* text);
|
||||
// pushes new text buffer to be rendered, can be stacked
|
||||
void text_push(text_t* text,
|
||||
const char* str,
|
||||
float speed,
|
||||
bool outline);
|
||||
// load font and set as current font
|
||||
void text_set_font(text_t* text, const char* font_path, float size);
|
||||
// finish whole current text buffer immediately
|
||||
void text_show_all_current(text_t* text);
|
||||
// returns true if text is still animating
|
||||
bool text_is_animating(text_t* text);
|
||||
// advance, call every frame, returns true when it touched the framebuffer
|
||||
bool text_nextframe(text_t* text, float deltatime);
|
||||
// gets the framebuffer of the text renderer
|
||||
const uint32_t* text_getfb(text_t* text);
|
||||
// clears the text buffer and the frame buffer
|
||||
void text_clear(text_t* text);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // TEXT_RENDERER_H
|
||||
+77
-77
@@ -1,77 +1,77 @@
|
||||
// window.h
|
||||
#pragma once
|
||||
#ifndef WINDOW_H
|
||||
#define WINDOW_H
|
||||
|
||||
typedef struct window_t window_t;
|
||||
|
||||
enum KeyCode {
|
||||
// Letters
|
||||
KEY_A = 4,
|
||||
KEY_D = 7,
|
||||
KEY_S = 22,
|
||||
KEY_W = 26,
|
||||
|
||||
// Numbers
|
||||
KEY_1 = 30,
|
||||
KEY_0 = 39,
|
||||
|
||||
// Controls
|
||||
KEY_RETURN = 40,
|
||||
KEY_ESCAPE = 41,
|
||||
KEY_BACKSPACE = 42,
|
||||
KEY_TAB = 43,
|
||||
KEY_SPACE = 44,
|
||||
|
||||
// Modifiers
|
||||
KEY_LCTRL = 224,
|
||||
KEY_LSHIFT = 225,
|
||||
KEY_RCTRL = 228,
|
||||
KEY_RSHIFT = 229,
|
||||
|
||||
// Navigation
|
||||
KEY_RIGHT = 79,
|
||||
KEY_LEFT = 80,
|
||||
KEY_DOWN = 81,
|
||||
KEY_UP = 82,
|
||||
|
||||
// Function Keys
|
||||
KEY_F1 = 58,
|
||||
KEY_F2 = 59
|
||||
};
|
||||
|
||||
enum MouseButton {
|
||||
MOUSE_BUTTON_LEFT = 1,
|
||||
MOUSE_BUTTON_MIDDLE = 2,
|
||||
MOUSE_BUTTON_RIGHT = 3
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
#include <cstdint>
|
||||
extern "C" {
|
||||
#else
|
||||
#include <stdint.h>
|
||||
#endif
|
||||
|
||||
typedef struct { int x, y; } mouse_pos_t;
|
||||
|
||||
// creates a window with given width, height and title, title can be utf8
|
||||
window_t* window_create(int width, int height, const char* title);
|
||||
// destroys the window
|
||||
void window_destroy(window_t* s);
|
||||
// polls window events, returns true if the window should close
|
||||
bool window_pollevent(window_t* s);
|
||||
// blits the given framebuffer to the window. must be the same size as the window and ARGB8888 format
|
||||
void window_blit(window_t* s, const uint32_t* framebuffer);
|
||||
// returns true if the given key is currently held down
|
||||
bool window_is_key_down(window_t* s, int key_scancode);
|
||||
// returns true if the given mouse button is currently held down
|
||||
bool window_is_mouse_button_down(window_t* s, int button_index);
|
||||
// gets the current mouse position in window coordinates
|
||||
mouse_pos_t window_get_mouse_position(window_t* s);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // WINDOW_H
|
||||
// window.h
|
||||
#pragma once
|
||||
#ifndef WINDOW_H
|
||||
#define WINDOW_H
|
||||
|
||||
typedef struct window_t window_t;
|
||||
|
||||
enum KeyCode {
|
||||
// Letters
|
||||
KEY_A = 4,
|
||||
KEY_D = 7,
|
||||
KEY_S = 22,
|
||||
KEY_W = 26,
|
||||
|
||||
// Numbers
|
||||
KEY_1 = 30,
|
||||
KEY_0 = 39,
|
||||
|
||||
// Controls
|
||||
KEY_RETURN = 40,
|
||||
KEY_ESCAPE = 41,
|
||||
KEY_BACKSPACE = 42,
|
||||
KEY_TAB = 43,
|
||||
KEY_SPACE = 44,
|
||||
|
||||
// Modifiers
|
||||
KEY_LCTRL = 224,
|
||||
KEY_LSHIFT = 225,
|
||||
KEY_RCTRL = 228,
|
||||
KEY_RSHIFT = 229,
|
||||
|
||||
// Navigation
|
||||
KEY_RIGHT = 79,
|
||||
KEY_LEFT = 80,
|
||||
KEY_DOWN = 81,
|
||||
KEY_UP = 82,
|
||||
|
||||
// Function Keys
|
||||
KEY_F1 = 58,
|
||||
KEY_F2 = 59
|
||||
};
|
||||
|
||||
enum MouseButton {
|
||||
MOUSE_BUTTON_LEFT = 1,
|
||||
MOUSE_BUTTON_MIDDLE = 2,
|
||||
MOUSE_BUTTON_RIGHT = 3
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
#include <cstdint>
|
||||
extern "C" {
|
||||
#else
|
||||
#include <stdint.h>
|
||||
#endif
|
||||
|
||||
typedef struct { int x, y; } mouse_pos_t;
|
||||
|
||||
// creates a window with given width, height and title, title can be utf8
|
||||
window_t* window_create(int width, int height, const char* title);
|
||||
// destroys the window
|
||||
void window_destroy(window_t* s);
|
||||
// polls window events, returns true if the window should close
|
||||
bool window_pollevent(window_t* s);
|
||||
// blits the given framebuffer to the window. must be the same size as the window and ARGB8888 format
|
||||
void window_blit(window_t* s, const uint32_t* framebuffer);
|
||||
// returns true if the given key is currently held down
|
||||
bool window_is_key_down(window_t* s, int key_scancode);
|
||||
// returns true if the given mouse button is currently held down
|
||||
bool window_is_mouse_button_down(window_t* s, int button_index);
|
||||
// gets the current mouse position in window coordinates
|
||||
mouse_pos_t window_get_mouse_position(window_t* s);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // WINDOW_H
|
||||
Reference in new issue
Block a user