update: removed blx bc idc

This commit is contained in:
maix0 2024-10-12 17:12:18 +02:00
parent d8bc34aa91
commit 46bd637d1a
26 changed files with 2 additions and 1488 deletions

View file

@ -1,145 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* blx.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/13 17:05:45 by maiboyer #+# #+# */
/* Updated: 2024/07/11 18:56:47 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef BLX_H
# define BLX_H
# include "me/blx/blx_key.h"
# include "me/blx/colors.h"
# include "me/blx/inputs.h"
# include "me/blx/sprite.h"
# include "me/types.h"
# include "me/vec2/vec2.h"
typedef struct s_blx t_blx;
typedef struct s_blx_app
{
t_str title;
t_u32 size_x;
t_u32 size_y;
t_u32 pixel_size;
void *data;
} t_blx_app;
typedef bool (*t_run_function)(t_blx *ctx);
typedef void (*t_free_function)(t_blx_app app);
typedef enum e_draw_mode
{
REPLACE,
MASK,
ALPHA,
} t_draw_mode;
typedef struct s_blx_data
{
t_sprite screen;
bool exit;
t_draw_mode draw_mode;
t_sprite font;
} t_blx_data;
typedef struct s_blx
{
void *mlx;
void *win;
t_blx_input inputs;
t_run_function func;
t_free_function mem_free;
t_blx_app app;
t_blx_data _data;
} t_blx;
/// @brief The main loop function
/// @param ctx the BLX context
/// @note this is the function that will be called every frame
/// @note this is an internal function, you should not call it yourself
int blx_loop_func(t_blx *ctx);
/// @brief Initialize the BLX context
/// @param func the main loop function
/// @param free_fn the free function
/// @param data the application data
/// @return
t_blx blx_initialize(t_run_function func, \
t_free_function free_fn, t_blx_app data);
/// @brief Draw a sprite onto the screen
/// @param app The blx context
/// @param pos The position to draw the sprite at
/// @param spr The sprite to draw
void draw_sprite(t_blx *app, t_vi2d pos, t_sprite *spr);
/// @brief is the key pressed
/// @param ctx the BLX context
/// @param input the key to check
/// @return true if the key is pressed, false otherwise
bool is_key_pressed(t_blx *ctx, t_keysym input);
/// @brief is the key held
/// @param ctx the BLX context
/// @param input the key to check
/// @return true if the key is held, false otherwise
bool is_key_held(t_blx *ctx, t_keysym input);
/// @brief is the key released
/// @param ctx the BLX context
/// @param input the key to check
/// @return true if the key is released, false otherwise
bool is_key_released(t_blx *ctx, t_keysym input);
/// @brief Start the game
/// @param app the BLX context
void blx_run(t_blx app);
/// @brief Free the game
/// @param app the BLX context
void blx_free(t_blx app);
/// @brief Draw a pixel onto the screen
/// @param app the BLX context
/// @param pos the position to draw the pixel at
/// @param col the color of the pixel
void blx_draw(t_blx *app, t_vi2d pos, t_color col);
/// @brief Clear the screen with a color
/// @param app the BLX context
/// @param col the color to clear the screen with
void blx_clear(t_blx *app, t_color col);
/// @brief Draw a sprite onto another sprite
/// @param dest the sprite to be drawn onto
/// @param pos the position to draw the sprite at
/// @param source the sprite to draw
void sprite_draw_onto(t_sprite *dest, t_vi2d pos,
t_sprite *source);
/// @brief Draw a string onto the screen
/// @param app the BLX context
/// @param pos the position to draw the string at
/// @param s the string to draw
/// @param col the color of the string
void blx_draw_string(t_blx *app, t_vi2d pos,
t_const_str s, t_color col);
static inline t_draw_mode get_draw_mode(t_blx *app)
{
return (app->_data.draw_mode);
}
static inline void set_draw_mode(t_blx *app, t_draw_mode mode)
{
app->_data.draw_mode = mode;
}
#endif

View file

@ -1,35 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* blx_handlers.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/21 17:37:50 by maiboyer #+# #+# */
/* Updated: 2023/12/21 18:32:01 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef BLX_HANDLERS_H
# define BLX_HANDLERS_H
# include "me/blx/blx_key.h"
# include "me/types.h"
/// @brief Handle a key press event
/// @param keysym the key that was pressed
/// @param ctx the BLX context
/// @note this is an internal function, you should not call it yourself
int blx_key_pressed_handler(t_keysym keysym, t_blx *ctx);
/// @brief Handle a key released event
/// @param keysym the key that was released
/// @param ctx the BLX context
/// @note this is an internal function, you should not call it yourself
int blx_key_released_handler(t_keysym keysym, t_blx *ctx);
/// @brief Handle a exit event
/// @param ctx the BLX context
/// @note this is an internal function, you should not call it yourself
int blx_key_exit_handler(t_blx *ctx);
#endif

View file

@ -1,199 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* blx_key.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/13 18:15:50 by maiboyer #+# #+# */
/* Updated: 2023/12/21 17:37:02 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef BLX_KEY_H
# define BLX_KEY_H
# include "me/types.h"
# include "me/vec/vec_u8.h"
typedef enum e_keysym
{
KB_space = 0x0020,
KB_exclam = 0x0021,
KB_quotedbl = 0x0022,
KB_numbersign = 0x0023,
KB_dollar = 0x0024,
KB_percent = 0x0025,
KB_ampersand = 0x0026,
KB_apostrophe = 0x0027,
KB_quoteright = 0x0027,
KB_parenleft = 0x0028,
KB_parenright = 0x0029,
KB_asterisk = 0x002a,
KB_plus = 0x002b,
KB_comma = 0x002c,
KB_minus = 0x002d,
KB_period = 0x002e,
KB_slash = 0x002f,
KB_0 = 0x0030,
KB_1 = 0x0031,
KB_2 = 0x0032,
KB_3 = 0x0033,
KB_4 = 0x0034,
KB_5 = 0x0035,
KB_6 = 0x0036,
KB_7 = 0x0037,
KB_8 = 0x0038,
KB_9 = 0x0039,
KB_colon = 0x003a,
KB_semicolon = 0x003b,
KB_less = 0x003c,
KB_equal = 0x003d,
KB_greater = 0x003e,
KB_question = 0x003f,
KB_at = 0x0040,
KB_A = 0x0041,
KB_B = 0x0042,
KB_C = 0x0043,
KB_D = 0x0044,
KB_E = 0x0045,
KB_F = 0x0046,
KB_G = 0x0047,
KB_H = 0x0048,
KB_I = 0x0049,
KB_J = 0x004a,
KB_K = 0x004b,
KB_L = 0x004c,
KB_M = 0x004d,
KB_N = 0x004e,
KB_O = 0x004f,
KB_P = 0x0050,
KB_Q = 0x0051,
KB_R = 0x0052,
KB_S = 0x0053,
KB_T = 0x0054,
KB_U = 0x0055,
KB_V = 0x0056,
KB_W = 0x0057,
KB_X = 0x0058,
KB_Y = 0x0059,
KB_Z = 0x005a,
KB_bracketleft = 0x005b,
KB_backslash = 0x005c,
KB_bracketright = 0x005d,
KB_asciicircum = 0x005e,
KB_underscore = 0x005f,
KB_grave = 0x0060,
KB_quoteleft = 0x0060,
KB_a = 0x0061,
KB_b = 0x0062,
KB_c = 0x0063,
KB_d = 0x0064,
KB_e = 0x0065,
KB_f = 0x0066,
KB_g = 0x0067,
KB_h = 0x0068,
KB_i = 0x0069,
KB_j = 0x006a,
KB_k = 0x006b,
KB_l = 0x006c,
KB_m = 0x006d,
KB_n = 0x006e,
KB_o = 0x006f,
KB_p = 0x0070,
KB_q = 0x0071,
KB_r = 0x0072,
KB_s = 0x0073,
KB_t = 0x0074,
KB_u = 0x0075,
KB_v = 0x0076,
KB_w = 0x0077,
KB_x = 0x0078,
KB_y = 0x0079,
KB_z = 0x007a,
KB_braceleft = 0x007b,
KB_bar = 0x007c,
KB_braceright = 0x007d,
KB_asciitilde = 0x007e,
KB_BackSpace = 0xff08,
KB_Tab = 0xff09,
KB_Linefeed = 0xff0a,
KB_Clear = 0xff0b,
KB_Return = 0xff0d,
KB_Pause = 0xff13,
KB_Scroll_Lock = 0xff14,
KB_Sys_Req = 0xff15,
KB_Escape = 0xff1b,
KB_Delete = 0xffff,
KB_Home = 0xff50,
KB_Left = 0xff51,
KB_Up = 0xff52,
KB_Right = 0xff53,
KB_Down = 0xff54,
KB_Prior = 0xff55,
KB_Page_Up = 0xff55,
KB_Next = 0xff56,
KB_Page_Down = 0xff56,
KB_End = 0xff57,
KB_Begin = 0xff58,
KB_F1 = 0xffbe,
KB_F2 = 0xffbf,
KB_F3 = 0xffc0,
KB_F4 = 0xffc1,
KB_F5 = 0xffc2,
KB_F6 = 0xffc3,
KB_F7 = 0xffc4,
KB_F8 = 0xffc5,
KB_F9 = 0xffc6,
KB_F10 = 0xffc7,
KB_F11 = 0xffc8,
KB_F12 = 0xffc9,
KB_Shift_L = 0xffe1,
KB_Shift_R = 0xffe2,
KB_Control_L = 0xffe3,
KB_Control_R = 0xffe4,
KB_Caps_Lock = 0xffe5,
KB_Shift_Lock = 0xffe6,
KB_Meta_L = 0xffe7,
KB_Meta_R = 0xffe8,
KB_Alt_L = 0xffe9,
KB_Alt_R = 0xffea,
KB_Super_L = 0xffeb,
KB_Super_R = 0xffec,
KB_Hyper_L = 0xffed,
KB_Hyper_R = 0xffee,
} t_keysym;
typedef struct s_blx t_blx;
/// @brief Convert a keysym to a bit index
/// @param key the keysym to convert
/// @return the bit index
/// @note this is an internal function, you should not call it yourself
t_usize keysym_to_bit_index(t_keysym key);
/// @brief Get a key from a key storage
/// @param key_storage the key storage
/// @param keysym the key to get
/// @return true if the key is present in the storage, false otherwise
bool get_key(t_vec_u8 *key_storage, t_keysym keysym);
/// @brief is the key pressed
/// @param ctx The BLX context
/// @param key the key to check
/// @return true if the key is pressed, false otherwise
bool is_key_pressed(t_blx *ctx, t_keysym key);
/// @brief is the key held
/// @param ctx The BLX context
/// @param key the key to check
/// @return true if the key is held, false otherwise
bool is_key_held(t_blx *ctx, t_keysym key);
/// @brief is the key released
/// @param ctx The BLX context
/// @param key the key to check
/// @return true if the key is released, false otherwise
bool is_key_released(t_blx *ctx, t_keysym key);
#endif

View file

@ -1,41 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* colors.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/13 17:49:02 by maiboyer #+# #+# */
/* Updated: 2023/12/24 17:36:50 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef COLORS_H
# define COLORS_H
# include "me/types.h"
typedef __attribute__((aligned(4))) struct s_color
{
t_u8 r;
t_u8 b;
t_u8 g;
t_u8 a;
} t_color;
/// @brief Create a new color with an specified alpha channel
/// @param r the red channel
/// @param g the green channel
/// @param b the blue channel
/// @param alpha the alpha channel
/// @return the resulting color
t_color new_color_with_alpha(t_u8 r, t_u8 g, t_u8 b, t_u8 alpha);
/// @brief Create a new color
/// @param r the red channel
/// @param g the green channel
/// @param b the blue channel
/// @return the resulting color
t_color new_color(t_u8 r, t_u8 g, t_u8 b);
#endif

View file

@ -1,40 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* inputs.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/13 17:38:22 by maiboyer #+# #+# */
/* Updated: 2023/12/21 20:15:54 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef INPUTS_H
# define INPUTS_H
# include "me/types.h"
# include "me/vec/vec_u8.h"
# ifndef BLX_H
typedef struct s_blx t_blx;
# endif
typedef struct s_blx_input
{
t_vec_u8 keysyms_pressed;
t_vec_u8 keysyms_held;
t_vec_u8 keysyms_released;
t_u8 mouse;
} t_blx_input;
/// @brief Create an input manager
/// @param ctx the BLX context
/// @return the created input manager
/// @note this is an internal function, you should not call it yourself
t_blx_input create_inputs_manager(t_blx *ctx);
#endif

View file

@ -1,98 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* sprite.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/21 21:59:18 by maiboyer #+# #+# */
/* Updated: 2024/01/05 00:09:47 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef SPRITE_H
# define SPRITE_H
# include "me/blx/colors.h"
# include "me/types.h"
# include "me/vec2/vec2.h"
# ifndef BLX_H
typedef struct s_blx t_blx;
# endif
typedef struct s_sprite
{
t_blx *ctx;
void *img;
t_i32 width;
t_i32 height;
t_u8 *data;
t_i32 bpp;
t_usize line_size;
bool big_endian;
} t_sprite;
/// @brief Create a sprite from an XPM file
/// @param ctx the BLX context
/// @param path the path to the XPM file
/// @param[out] out the output sprite
/// @return true if an error occured, false otherwise
t_error blx_sprite_from_xpm(t_blx *ctx, t_str path,
t_sprite *out);
/// @brief Create a new sprite
/// @param ctx the BLX context
/// @param width the width of the sprite in pixels
/// @param height the height of the sprite in pixels
/// @param out[out] the output sprite
/// @return true if an error occured, false otherwise
t_error blx_sprite_new(t_blx *ctx, t_i32 width, t_i32 height,
t_sprite *out);
/// @brief Free a sprite
/// @param img the sprite to free
void blx_sprite_free(t_sprite img);
/// @brief Draw a sprite at a position onto the screen
/// @param ctx the BLX context
/// @param pos the position to draw the sprite at
/// @param img the sprite to draw
void blx_draw_sprite_raw(t_blx *ctx, t_vi2d pos,
t_sprite *img);
/// @brief Draw a pixel onto the sprite
/// @param img the sprite to draw onto
/// @param pos the position to draw the pixel at
/// @param col the color of the pixel
void sprite_draw(t_sprite *img, t_vi2d pos, t_color col);
/// @brief Clear a sprite with a color
/// @param img the sprite to clear
/// @param col the color to clear the sprite with
void sprite_clear(t_sprite *img, t_color col);
/// @brief Get the color of a pixel on a sprite
/// @param spr the sprite to get the pixel from
/// @param pos the position of the pixel
/// @param[out] out the color of the pixel
/// @return true if an error occured, false otherwise
t_error sprite_get_pixel(t_sprite *spr, t_vi2d pos,
t_color *out);
/// @brief Draw a sprite onto another sprite
/// @param dest The sprite to be drawn onto
/// @param pos The position to draw the sprite at
/// @param source The sprite to draw
void sprite_draw_onto(t_sprite *dest, t_vi2d pos,
t_sprite *source);
/// @brief Draw a string onto a sprite
/// @param spr The sprite to draw onto
/// @param pos The position to draw the string at
/// @param sText The string to draw
/// @param col The color of the string
void sprite_draw_string(t_sprite *spr, t_vi2d pos,
t_const_str sText, t_color col);
#endif

View file

@ -1,78 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* xdata.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/21 17:20:57 by maiboyer #+# #+# */
/* Updated: 2023/12/21 20:15:32 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef XDATA_H
# define XDATA_H
# define KEYPRESS 2
# define KEYRELEASE 3
# define BUTTONPRESS 4
# define BUTTONRELEASE 5
# define MOTIONNOTIFY 6
# define ENTERNOTIFY 7
# define LEAVENOTIFY 8
# define FOCUSIN 9
# define FOCUSOUT 10
# define KEYMAPNOTIFY 11
# define EXPOSE 12
# define GRAPHICSEXPOSE 13
# define NOEXPOSE 14
# define VISIBILITYNOTIFY 15
# define CREATENOTIFY 16
# define DESTROYNOTIFY 17
# define UNMAPNOTIFY 18
# define MAPNOTIFY 19
# define MAPREQUEST 20
# define REPARENTNOTIFY 21
# define CONFIGURENOTIFY 22
# define CONFIGUREREQUEST 23
# define GRAVITYNOTIFY 24
# define RESIZEREQUEST 25
# define CIRCULATENOTIFY 26
# define CIRCULATEREQUEST 27
# define PROPERTYNOTIFY 28
# define SELECTIONCLEAR 29
# define SELECTIONREQUEST 30
# define SELECTIONNOTIFY 31
# define COLORMAPNOTIFY 32
# define CLIENTMESSAGE 33
# define MAPPINGNOTIFY 34
# define GENERICEVENT 35
# define NOEVENTMASK 0b0L
# define KEYPRESSMASK 0b1L
# define KEYRELEASEMASK 0b10L
# define BUTTONPRESSMASK 0b100L
# define BUTTONRELEASEMASK 0b1000L
# define ENTERWINDOWMASK 0b10000L
# define LEAVEWINDOWMASK 0b100000L
# define POINTERMOTIONMASK 0b1000000L
# define POINTERMOTIONHINTMASK 0b10000000L
# define BUTTON1MOTIONMASK 0b100000000L
# define BUTTON2MOTIONMASK 0b1000000000L
# define BUTTON3MOTIONMASK 0b10000000000L
# define BUTTON4MOTIONMASK 0b100000000000L
# define BUTTON5MOTIONMASK 0b1000000000000L
# define BUTTONMOTIONMASK 0b10000000000000L
# define KEYMAPSTATEMASK 0b100000000000000L
# define EXPOSUREMASK 0b1000000000000000L
# define VISIBILITYCHANGEMASK 0b10000000000000000L
# define STRUCTURENOTIFYMASK 0b100000000000000000L
# define RESIZEREDIRECTMASK 0b1000000000000000000L
# define SUBSTRUCTURENOTIFYMASK 0b10000000000000000000L
# define SUBSTRUCTUREREDIRECTMASK 0b100000000000000000000L
# define FOCUSCHANGEMASK 0b1000000000000000000000L
# define PROPERTYCHANGEMASK 0b10000000000000000000000L
# define COLORMAPCHANGEMASK 0b100000000000000000000000L
# define OWNERGRABBUTTONMASK 0b1000000000000000000000000L
#endif