initial commit

This commit is contained in:
erysdren 2024-05-20 20:35:31 -05:00
commit 3124bf4ae5
14 changed files with 11291 additions and 0 deletions

6
.gitignore vendored Normal file
View file

@ -0,0 +1,6 @@
*.exe
*.o
*.obj
sbe
untracked

21
LICENSE Normal file
View file

@ -0,0 +1,21 @@
MIT License
Copyright (c) 2023-2024 erysdren (it/she/they)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.9 KiB

BIN
art/editortest_ship.bmp Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.1 KiB

BIN
art/nakey rights.bmp Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.1 KiB

BIN
art/snonk.bmp Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.1 KiB

1092
editor.c Normal file

File diff suppressed because it is too large Load diff

1194
eui.c Normal file

File diff suppressed because it is too large Load diff

371
eui.h Normal file
View file

@ -0,0 +1,371 @@
/*
MIT License
Copyright (c) 2023-2024 erysdren (it/she/they)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#pragma once
#ifndef _EUI_H_
#define _EUI_H_
#ifdef __cplusplus
extern "C" {
#endif
#include <stdint.h>
/* element alignment */
enum {
EUI_ALIGN_START,
EUI_ALIGN_MIDDLE,
EUI_ALIGN_END
};
/* true/false/unset */
enum {
EUI_FALSE = 0,
EUI_TRUE = 1
};
/* button type */
enum {
EUI_BUTTON_LEFT = 1,
EUI_BUTTON_RIGHT = 2
};
/* event type */
enum {
EUI_EVENT_NONE,
EUI_EVENT_KEY_DOWN,
EUI_EVENT_KEY_UP,
EUI_EVENT_MOUSE,
EUI_EVENT_BUTTON_DOWN,
EUI_EVENT_BUTTON_UP
};
/* keyboard scancodes */
enum {
EUI_SCANCODE_ESCAPE = 0x01,
EUI_SCANCODE_1 = 0x02,
EUI_SCANCODE_2 = 0x03,
EUI_SCANCODE_3 = 0x04,
EUI_SCANCODE_4 = 0x05,
EUI_SCANCODE_5 = 0x06,
EUI_SCANCODE_6 = 0x07,
EUI_SCANCODE_7 = 0x08,
EUI_SCANCODE_8 = 0x09,
EUI_SCANCODE_9 = 0x0A,
EUI_SCANCODE_0 = 0x0B,
EUI_SCANCODE_MINUS = 0x0C,
EUI_SCANCODE_EQUALS = 0x0D,
EUI_SCANCODE_BACKSPACE = 0x0E,
EUI_SCANCODE_TAB = 0x0F,
EUI_SCANCODE_Q = 0x10,
EUI_SCANCODE_W = 0x11,
EUI_SCANCODE_E = 0x12,
EUI_SCANCODE_R = 0x13,
EUI_SCANCODE_T = 0x14,
EUI_SCANCODE_Y = 0x15,
EUI_SCANCODE_U = 0x16,
EUI_SCANCODE_I = 0x17,
EUI_SCANCODE_O = 0x18,
EUI_SCANCODE_P = 0x19,
EUI_SCANCODE_LEFTBRACKET = 0x1A,
EUI_SCANCODE_RIGHTBRACKET = 0x1B,
EUI_SCANCODE_ENTER = 0x1C,
EUI_SCANCODE_CONTROL = 0x1D,
EUI_SCANCODE_A = 0x1E,
EUI_SCANCODE_S = 0x1F,
EUI_SCANCODE_D = 0x20,
EUI_SCANCODE_F = 0x21,
EUI_SCANCODE_G = 0x22,
EUI_SCANCODE_H = 0x23,
EUI_SCANCODE_J = 0x24,
EUI_SCANCODE_K = 0x25,
EUI_SCANCODE_L = 0x26,
EUI_SCANCODE_SEMICOLON = 0x27,
EUI_SCANCODE_QUOTE = 0x28,
EUI_SCANCODE_TILDE = 0x29,
EUI_SCANCODE_LSHIFT = 0x2A,
EUI_SCANCODE_BACKSLASH = 0x2B,
EUI_SCANCODE_Z = 0x2C,
EUI_SCANCODE_X = 0x2D,
EUI_SCANCODE_C = 0x2E,
EUI_SCANCODE_V = 0x2F,
EUI_SCANCODE_B = 0x30,
EUI_SCANCODE_N = 0x31,
EUI_SCANCODE_M = 0x32,
EUI_SCANCODE_COMMA = 0x33,
EUI_SCANCODE_PERIOD = 0x34,
EUI_SCANCODE_SLASH = 0x35,
EUI_SCANCODE_RSHIFT = 0x36,
EUI_SCANCODE_MULTIPLY = 0x37,
EUI_SCANCODE_ALT = 0x38,
EUI_SCANCODE_SPACE = 0x39,
EUI_SCANCODE_CAPSLOCK = 0x3A,
EUI_SCANCODE_F1 = 0x3B,
EUI_SCANCODE_F2 = 0x3C,
EUI_SCANCODE_F3 = 0x3D,
EUI_SCANCODE_F4 = 0x3E,
EUI_SCANCODE_F5 = 0x3F,
EUI_SCANCODE_F6 = 0x40,
EUI_SCANCODE_F7 = 0x41,
EUI_SCANCODE_F8 = 0x42,
EUI_SCANCODE_F9 = 0x43,
EUI_SCANCODE_F10 = 0x44,
EUI_SCANCODE_NUMLOCK = 0x45,
EUI_SCANCODE_SCROLLLOCK = 0x46,
EUI_SCANCODE_HOME = 0x47,
EUI_SCANCODE_UP = 0x48,
EUI_SCANCODE_PAGEUP = 0x49,
EUI_SCANCODE_LEFT = 0x4B,
EUI_SCANCODE_RIGHT = 0x4D,
EUI_SCANCODE_PLUS = 0x4E,
EUI_SCANCODE_END = 0x4F,
EUI_SCANCODE_DOWN = 0x50,
EUI_SCANCODE_PAGEDOWN = 0x51,
EUI_SCANCODE_INSERT = 0x52,
EUI_SCANCODE_DELETE = 0x53,
EUI_SCANCODE_F11 = 0x57,
EUI_SCANCODE_F12 = 0x58
};
/*
*
* eui types
*
*/
/* default pixel depth is 8bpp */
#ifndef EUI_PIXEL_DEPTH
#error Please define EUI_PIXEL_DEPTH! Valid values: 8, 16, 32
#endif
/* pixel color type */
#if (EUI_PIXEL_DEPTH == 8)
typedef uint8_t eui_color_t;
#elif (EUI_PIXEL_DEPTH == 16)
typedef uint16_t eui_color_t;
#elif (EUI_PIXEL_DEPTH == 32)
typedef uint32_t eui_color_t;
#else
#error Unsupported pixel depth!
#endif
/* vec2 */
typedef struct eui_vec2_t {
int x, y;
} eui_vec2_t;
/* event */
typedef union eui_event_t {
int type;
struct { int type; int scancode; } key;
struct { int type; int x; int y; int xrel; int yrel; } mouse;
struct { int type; int x; int y; int button; } button;
} eui_event_t;
/* configuration */
typedef struct eui_config_t {
struct {
eui_color_t border_color;
eui_color_t border_color_hover;
eui_color_t bg_color;
eui_color_t bg_color_hover;
eui_color_t text_color;
eui_color_t text_color_hover;
int border_width;
} button;
} eui_config_t;
/* pixelmap */
typedef struct eui_pixelmap_t {
int w;
int h;
int pitch;
eui_color_t *pixels;
} eui_pixelmap_t;
/* general callback function */
typedef void eui_callback(void *user);
/*
*
* helper macros
*
*/
/* unused */
#define EUI_UNUSED(x) ((void)(x))
/* create vec2 */
#define EUI_VEC2(x, y) (eui_vec2_t){(x), (y)}
/* create pixelmap */
#define EUI_PIXELMAP(w, h, pitch, pixels) (eui_pixelmap_t){(w), (h), (pitch), (pixels)}
/*
*
* basic transforms
*
*/
/* transform point to current frame, with alignment */
void eui_transform_point(eui_vec2_t *pos);
/* transform box to current frame, with alignment */
void eui_transform_box(eui_vec2_t *pos, eui_vec2_t size);
/* clip box to screen size, returns EUI_FALSE if the shape will never be visible */
int eui_clip_box(eui_vec2_t *pos, eui_vec2_t *size);
/*
*
* frame handling
*
*/
/* go to subframe, transformed from current frame */
void eui_push_frame(eui_vec2_t pos, eui_vec2_t size);
/* return to parent frame */
void eui_pop_frame(void);
/* reset all frame transforms */
void eui_reset_frame(void);
/* set current frame alignment */
void eui_set_align(int xalign, int yalign);
/*
*
* event handling
*
*/
/* push event to the queue */
void eui_push_event(eui_event_t event);
/* pop event from the top of the queue */
int eui_pop_event(eui_event_t *out);
/* clear event queue */
void eui_clear_events(void);
/* push key to the queue */
void eui_push_key(int scancode);
/* pop key from the top of the queue */
int eui_pop_key(void);
/*
*
* begin/end
*
*/
/* begin eui with given pixelmap destination */
int eui_begin(eui_pixelmap_t dest);
/* end eui */
void eui_end(void);
/*
*
* configuration
*
*/
/* get modifiable config struct */
eui_config_t *eui_get_config(void);
/*
*
* utilities
*
*/
/* get dimensions of text string, with newlines */
eui_vec2_t eui_get_text_size(char *s);
/* returns EUI_TRUE if the mouse cursor is hovering over the given area */
int eui_is_hovered(eui_vec2_t pos, eui_vec2_t size);
/* clear screen with color */
void eui_clear(eui_color_t color);
/* draw built-in cursor */
void eui_cursor(eui_color_t color);
/* get cursor position */
eui_vec2_t eui_get_cursor_pos(void);
/* get button state */
int eui_get_button(void);
/*
*
* drawing primitives
*
*/
/* draw filled box at pos, transformed */
void eui_filled_box(eui_vec2_t pos, eui_vec2_t size, eui_color_t color);
/* draw hollow box at pos, transformed */
void eui_border_box(eui_vec2_t pos, eui_vec2_t size, int width, eui_color_t color);
/* draw text at pos, transformed */
void eui_text(eui_vec2_t pos, eui_color_t color, char *s);
/* draw formatted text at pos, transformed */
void eui_textf(eui_vec2_t pos, eui_color_t color, char *s, ...);
/* draw filled triangle with provided points, transformed */
void eui_filled_triangle(eui_vec2_t p0, eui_vec2_t p1, eui_vec2_t p2, eui_color_t color);
/* draw line from p0 to p1, transformed */
void eui_line(eui_vec2_t p0, eui_vec2_t p1, eui_color_t color);
/* draw pixelmap, transformed */
void eui_pixelmap(eui_vec2_t pos, eui_pixelmap_t pixelmap);
/* draw xbm graphic, transformed */
void eui_xbm(eui_vec2_t pos, eui_color_t color, int w, int h, unsigned char *bits);
/*
*
* widgets
*
*/
/* fires callback function if pressed and returns EUI_TRUE if hovered */
int eui_button(eui_vec2_t pos, eui_vec2_t size, char *text, eui_callback callback, void *user);
/* fires callback function if pressed and returns EUI_TRUE if hovered (xbm graphic) */
int eui_button_xbm(eui_vec2_t pos, int w, int h, unsigned char *bits, eui_callback callback, void *user);
/* on/off checkbox */
void eui_checkbox(eui_vec2_t pos, char *label, eui_color_t color, int *value);
#ifdef __cplusplus
}
#endif
#endif /* _EUI_H_ */

250
eui_sdl2.c Normal file
View file

@ -0,0 +1,250 @@
/*
MIT License
Copyright (c) 2023-2024 erysdren (it/she/they)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
/*
*
* EUI_SDL2.C
*
*/
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <stdarg.h>
#include <stdlib.h>
#include "eui_sdl2.h"
static int scancode_table_initialized = EUI_FALSE;
static int scancode_table[SDL_NUM_SCANCODES];
static void initialize_scancode_table(void)
{
if (scancode_table_initialized)
return;
scancode_table[SDL_SCANCODE_ESCAPE] = EUI_SCANCODE_ESCAPE;
scancode_table[SDL_SCANCODE_1] = EUI_SCANCODE_1;
scancode_table[SDL_SCANCODE_2] = EUI_SCANCODE_2;
scancode_table[SDL_SCANCODE_3] = EUI_SCANCODE_3;
scancode_table[SDL_SCANCODE_4] = EUI_SCANCODE_4;
scancode_table[SDL_SCANCODE_5] = EUI_SCANCODE_5;
scancode_table[SDL_SCANCODE_6] = EUI_SCANCODE_6;
scancode_table[SDL_SCANCODE_7] = EUI_SCANCODE_7;
scancode_table[SDL_SCANCODE_8] = EUI_SCANCODE_8;
scancode_table[SDL_SCANCODE_9] = EUI_SCANCODE_9;
scancode_table[SDL_SCANCODE_0] = EUI_SCANCODE_0;
scancode_table[SDL_SCANCODE_MINUS] = EUI_SCANCODE_MINUS;
scancode_table[SDL_SCANCODE_EQUALS] = EUI_SCANCODE_EQUALS;
scancode_table[SDL_SCANCODE_BACKSPACE] = EUI_SCANCODE_BACKSPACE;
scancode_table[SDL_SCANCODE_TAB] = EUI_SCANCODE_TAB;
scancode_table[SDL_SCANCODE_Q] = EUI_SCANCODE_Q;
scancode_table[SDL_SCANCODE_W] = EUI_SCANCODE_W;
scancode_table[SDL_SCANCODE_E] = EUI_SCANCODE_E;
scancode_table[SDL_SCANCODE_R] = EUI_SCANCODE_R;
scancode_table[SDL_SCANCODE_T] = EUI_SCANCODE_T;
scancode_table[SDL_SCANCODE_Y] = EUI_SCANCODE_Y;
scancode_table[SDL_SCANCODE_U] = EUI_SCANCODE_U;
scancode_table[SDL_SCANCODE_I] = EUI_SCANCODE_I;
scancode_table[SDL_SCANCODE_O] = EUI_SCANCODE_O;
scancode_table[SDL_SCANCODE_P] = EUI_SCANCODE_P;
scancode_table[SDL_SCANCODE_LEFTBRACKET] = EUI_SCANCODE_LEFTBRACKET;
scancode_table[SDL_SCANCODE_RIGHTBRACKET] = EUI_SCANCODE_RIGHTBRACKET;
scancode_table[SDL_SCANCODE_RETURN] = EUI_SCANCODE_ENTER;
scancode_table[SDL_SCANCODE_LCTRL] = EUI_SCANCODE_CONTROL;
scancode_table[SDL_SCANCODE_RCTRL] = EUI_SCANCODE_CONTROL;
scancode_table[SDL_SCANCODE_A] = EUI_SCANCODE_A;
scancode_table[SDL_SCANCODE_S] = EUI_SCANCODE_S;
scancode_table[SDL_SCANCODE_D] = EUI_SCANCODE_D;
scancode_table[SDL_SCANCODE_F] = EUI_SCANCODE_F;
scancode_table[SDL_SCANCODE_G] = EUI_SCANCODE_G;
scancode_table[SDL_SCANCODE_H] = EUI_SCANCODE_H;
scancode_table[SDL_SCANCODE_J] = EUI_SCANCODE_J;
scancode_table[SDL_SCANCODE_K] = EUI_SCANCODE_K;
scancode_table[SDL_SCANCODE_L] = EUI_SCANCODE_L;
scancode_table[SDL_SCANCODE_SEMICOLON] = EUI_SCANCODE_SEMICOLON;
scancode_table[SDL_SCANCODE_APOSTROPHE] = EUI_SCANCODE_QUOTE;
scancode_table[SDL_SCANCODE_GRAVE] = EUI_SCANCODE_TILDE;
scancode_table[SDL_SCANCODE_LSHIFT] = EUI_SCANCODE_LSHIFT;
scancode_table[SDL_SCANCODE_BACKSLASH] = EUI_SCANCODE_BACKSLASH;
scancode_table[SDL_SCANCODE_Z] = EUI_SCANCODE_Z;
scancode_table[SDL_SCANCODE_X] = EUI_SCANCODE_X;
scancode_table[SDL_SCANCODE_C] = EUI_SCANCODE_C;
scancode_table[SDL_SCANCODE_V] = EUI_SCANCODE_V;
scancode_table[SDL_SCANCODE_B] = EUI_SCANCODE_B;
scancode_table[SDL_SCANCODE_N] = EUI_SCANCODE_N;
scancode_table[SDL_SCANCODE_M] = EUI_SCANCODE_M;
scancode_table[SDL_SCANCODE_COMMA] = EUI_SCANCODE_COMMA;
scancode_table[SDL_SCANCODE_PERIOD] = EUI_SCANCODE_PERIOD;
scancode_table[SDL_SCANCODE_SLASH] = EUI_SCANCODE_SLASH;
scancode_table[SDL_SCANCODE_RSHIFT] = EUI_SCANCODE_RSHIFT;
scancode_table[SDL_SCANCODE_KP_MULTIPLY] = EUI_SCANCODE_MULTIPLY;
scancode_table[SDL_SCANCODE_LALT] = EUI_SCANCODE_ALT;
scancode_table[SDL_SCANCODE_SPACE] = EUI_SCANCODE_SPACE;
scancode_table[SDL_SCANCODE_CAPSLOCK] = EUI_SCANCODE_CAPSLOCK;
scancode_table[SDL_SCANCODE_F1] = EUI_SCANCODE_F1;
scancode_table[SDL_SCANCODE_F2] = EUI_SCANCODE_F2;
scancode_table[SDL_SCANCODE_F3] = EUI_SCANCODE_F3;
scancode_table[SDL_SCANCODE_F4] = EUI_SCANCODE_F4;
scancode_table[SDL_SCANCODE_F5] = EUI_SCANCODE_F5;
scancode_table[SDL_SCANCODE_F6] = EUI_SCANCODE_F6;
scancode_table[SDL_SCANCODE_F7] = EUI_SCANCODE_F7;
scancode_table[SDL_SCANCODE_F8] = EUI_SCANCODE_F8;
scancode_table[SDL_SCANCODE_F9] = EUI_SCANCODE_F9;
scancode_table[SDL_SCANCODE_F10] = EUI_SCANCODE_F10;
scancode_table[SDL_SCANCODE_NUMLOCKCLEAR] = EUI_SCANCODE_NUMLOCK;
scancode_table[SDL_SCANCODE_SCROLLLOCK] = EUI_SCANCODE_SCROLLLOCK;
scancode_table[SDL_SCANCODE_HOME] = EUI_SCANCODE_HOME;
scancode_table[SDL_SCANCODE_UP] = EUI_SCANCODE_UP;
scancode_table[SDL_SCANCODE_PAGEUP] = EUI_SCANCODE_PAGEUP;
scancode_table[SDL_SCANCODE_LEFT] = EUI_SCANCODE_LEFT;
scancode_table[SDL_SCANCODE_RIGHT] = EUI_SCANCODE_RIGHT;
scancode_table[SDL_SCANCODE_KP_PLUS] = EUI_SCANCODE_PLUS;
scancode_table[SDL_SCANCODE_END] = EUI_SCANCODE_END;
scancode_table[SDL_SCANCODE_DOWN] = EUI_SCANCODE_DOWN;
scancode_table[SDL_SCANCODE_PAGEDOWN] = EUI_SCANCODE_PAGEDOWN;
scancode_table[SDL_SCANCODE_INSERT] = EUI_SCANCODE_INSERT;
scancode_table[SDL_SCANCODE_DELETE] = EUI_SCANCODE_DELETE;
scancode_table[SDL_SCANCODE_F11] = EUI_SCANCODE_F11;
scancode_table[SDL_SCANCODE_F12] = EUI_SCANCODE_F12;
scancode_table_initialized = EUI_TRUE;
}
/* begin eui with given SDL_Surface destination */
int eui_begin_sdl2(SDL_Surface *surface)
{
eui_pixelmap_t dest;
if (sizeof(eui_color_t) != surface->format->BytesPerPixel)
return EUI_FALSE;
dest.w = surface->w;
dest.h = surface->h;
dest.pitch = surface->pitch;
dest.pixels = (eui_color_t *)surface->pixels;
initialize_scancode_table();
return eui_begin(dest);
}
/* process and push SDL_Event */
void eui_push_event_sdl2(SDL_Event *event)
{
eui_event_t eui_event;
initialize_scancode_table();
switch (event->type)
{
case SDL_KEYDOWN:
if (scancode_table[event->key.keysym.scancode])
{
eui_event.type = EUI_EVENT_KEY_DOWN;
eui_event.key.scancode = scancode_table[event->key.keysym.scancode];
eui_push_event(eui_event);
}
break;
case SDL_KEYUP:
if (scancode_table[event->key.keysym.scancode])
{
eui_event.type = EUI_EVENT_KEY_UP;
eui_event.key.scancode = scancode_table[event->key.keysym.scancode];
eui_push_event(eui_event);
}
break;
case SDL_MOUSEBUTTONDOWN:
switch (event->button.button)
{
case SDL_BUTTON_LEFT:
eui_event.type = EUI_EVENT_BUTTON_DOWN;
eui_event.button.x = event->button.x;
eui_event.button.y = event->button.y;
eui_event.button.button = EUI_BUTTON_LEFT;
eui_push_event(eui_event);
break;
case SDL_BUTTON_RIGHT:
eui_event.type = EUI_EVENT_BUTTON_DOWN;
eui_event.button.x = event->button.x;
eui_event.button.y = event->button.y;
eui_event.button.button = EUI_BUTTON_RIGHT;
eui_push_event(eui_event);
break;
}
break;
case SDL_MOUSEBUTTONUP:
switch (event->button.button)
{
case SDL_BUTTON_LEFT:
eui_event.type = EUI_EVENT_BUTTON_UP;
eui_event.button.x = event->button.x;
eui_event.button.y = event->button.y;
eui_event.button.button = EUI_BUTTON_LEFT;
eui_push_event(eui_event);
break;
case SDL_BUTTON_RIGHT:
eui_event.type = EUI_EVENT_BUTTON_UP;
eui_event.button.x = event->button.x;
eui_event.button.y = event->button.y;
eui_event.button.button = EUI_BUTTON_RIGHT;
eui_push_event(eui_event);
break;
}
break;
case SDL_MOUSEMOTION:
eui_event.type = EUI_EVENT_MOUSE;
eui_event.mouse.x = event->motion.x;
eui_event.mouse.y = event->motion.y;
eui_event.mouse.xrel = event->motion.xrel;
eui_event.mouse.yrel = event->motion.yrel;
eui_push_event(eui_event);
break;
default:
break;
}
}
/* draw SDL_Surface, transformed */
void eui_pixelmap_sdl2(eui_vec2_t pos, SDL_Surface *surface)
{
eui_pixelmap_t pm;
if (sizeof(eui_color_t) != surface->format->BytesPerPixel)
return;
pm.w = surface->w;
pm.h = surface->h;
pm.pitch = surface->pitch;
pm.pixels = (eui_color_t *)surface->pixels;
eui_pixelmap(pos, pm);
}

47
eui_sdl2.h Normal file
View file

@ -0,0 +1,47 @@
/*
MIT License
Copyright (c) 2023-2024 erysdren (it/she/they)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#pragma once
#ifndef _EUI_SDL2_H_
#define _EUI_SDL2_H_
#ifdef __cplusplus
extern "C" {
#endif
#include "eui.h"
#include "SDL.h"
/* begin eui with given SDL_Surface destination */
int eui_begin_sdl2(SDL_Surface *surface);
/* process and push SDL2 event */
void eui_push_event_sdl2(SDL_Event *event);
/* draw SDL_Surface, transformed */
void eui_pixelmap_sdl2(eui_vec2_t pos, SDL_Surface *surface);
#ifdef __cplusplus
}
#endif
#endif /* _EUI_SDL2_H_ */

33
makefile Normal file
View file

@ -0,0 +1,33 @@
ifeq ($(MINGW),1)
EXEC ?= sbe.exe
RM ?= rm -f
CC = x86_64-w64-mingw32-gcc
STRIP = x86_64-w64-mingw32-strip
PKGCONFIG = x86_64-w64-mingw32-pkg-config
override LDFLAGS += -lcomdlg32 -lole32
else
EXEC ?= sbe
RM ?= rm -f
CC ?= gcc
STRIP ?= strip
PKGCONFIG ?= pkg-config
endif
override CFLAGS += $(shell $(PKGCONFIG) sdl2 --cflags) -DEUI_PIXEL_DEPTH=8 -pedantic -Wextra -Wall
override LDFLAGS += $(shell $(PKGCONFIG) sdl2 --libs)
OBJECTS = editor.o eui_sdl2.o eui.o tinyfiledialogs.o
all: clean $(EXEC)
clean:
$(RM) $(OBJECTS) $(EXEC)
$(EXEC): $(OBJECTS)
$(CC) -o $@ $^ $(LDFLAGS)
$(STRIP) $(EXEC)
%.o: %.c
$(CC) -c -o $@ $< $(CFLAGS)

7962
tinyfiledialogs.c Normal file

File diff suppressed because it is too large Load diff

315
tinyfiledialogs.h Normal file
View file

@ -0,0 +1,315 @@
/* SPDX-License-Identifier: ZLIB
Copyright (c) 2014 - 2023 Guillaume Vareille http://ysengrin.com
If you are using a C++ compiler to compile tinyfiledialogs.c (maybe renamed with the extension ".cpp")
then comment out << extern "C" >> bellow in this header file)
********* TINY FILE DIALOGS OFFICIAL WEBSITE IS ON SOURCEFORGE *********
_________
/ \ tinyfiledialogs.h v3.16 [Nov 23, 2023]
|tiny file| Unique header file created [November 9, 2014]
| dialogs |
\____ ___/ http://tinyfiledialogs.sourceforge.net
\| git clone http://git.code.sf.net/p/tinyfiledialogs/code tinyfd
____________________________________________
| |
| email: tinyfiledialogs at ysengrin.com |
|____________________________________________|
________________________________________________________________________________
| ____________________________________________________________________________ |
| | | |
| | - in tinyfiledialogs, char is UTF-8 by default (since v3.6) | |
| | | |
| | on windows: | |
| | - for UTF-16, use the wchar_t functions at the bottom of the header file | |
| | - _wfopen() requires wchar_t | |
| | | |
| | - but fopen() expects MBCS (not UTF-8) | |
| | - if you want char to be MBCS: set tinyfd_winUtf8 to 0 | |
| | | |
| | - alternatively, tinyfiledialogs provides | |
| | functions to convert between UTF-8, UTF-16 and MBCS | |
| |____________________________________________________________________________| |
|________________________________________________________________________________|
If you like tinyfiledialogs, please upvote my stackoverflow answer
https://stackoverflow.com/a/47651444
- License -
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
__________________________________________
| ______________________________________ |
| | | |
| | DO NOT USE USER INPUT IN THE DIALOGS | |
| |______________________________________| |
|__________________________________________|
*/
#ifndef TINYFILEDIALOGS_H
#define TINYFILEDIALOGS_H
#ifdef __cplusplus
/* if tinydialogs.c is compiled as C++ code rather than C code, you may need to comment this out
and the corresponding closing bracket near the end of this file. */
extern "C" {
#endif
/******************************************************************************************************/
/**************************************** UTF-8 on Windows ********************************************/
/******************************************************************************************************/
#ifdef _WIN32
/* On windows, if you want to use UTF-8 ( instead of the UTF-16/wchar_t functions at the end of this file )
Make sure your code is really prepared for UTF-8 (on windows, functions like fopen() expect MBCS and not UTF-8) */
extern int tinyfd_winUtf8; /* on windows char strings can be 1:UTF-8(default) or 0:MBCS */
/* for MBCS change this to 0, in tinyfiledialogs.c or in your code */
/* Here are some functions to help you convert between UTF-16 UTF-8 MBSC */
char * tinyfd_utf8toMbcs(char const * aUtf8string);
char * tinyfd_utf16toMbcs(wchar_t const * aUtf16string);
wchar_t * tinyfd_mbcsTo16(char const * aMbcsString);
char * tinyfd_mbcsTo8(char const * aMbcsString);
wchar_t * tinyfd_utf8to16(char const * aUtf8string);
char * tinyfd_utf16to8(wchar_t const * aUtf16string);
#endif
/******************************************************************************************************/
/******************************************************************************************************/
/******************************************************************************************************/
/************* 3 funtions for C# (you don't need this in C or C++) : */
char const * tinyfd_getGlobalChar(char const * aCharVariableName); /* returns NULL on error */
int tinyfd_getGlobalInt(char const * aIntVariableName); /* returns -1 on error */
int tinyfd_setGlobalInt(char const * aIntVariableName, int aValue); /* returns -1 on error */
/* aCharVariableName: "tinyfd_version" "tinyfd_needs" "tinyfd_response"
aIntVariableName : "tinyfd_verbose" "tinyfd_silent" "tinyfd_allowCursesDialogs"
"tinyfd_forceConsole" "tinyfd_assumeGraphicDisplay" "tinyfd_winUtf8"
**************/
extern char tinyfd_version[8]; /* contains tinyfd current version number */
extern char tinyfd_needs[]; /* info about requirements */
extern int tinyfd_verbose; /* 0 (default) or 1 : on unix, prints the command line calls */
extern int tinyfd_silent; /* 1 (default) or 0 : on unix, hide errors and warnings from called dialogs */
/** Curses dialogs are difficult to use and counter-intuitive.
On windows they are only ascii and still uses the unix backslash ! **/
extern int tinyfd_allowCursesDialogs; /* 0 (default) or 1 */
extern int tinyfd_forceConsole; /* 0 (default) or 1 */
/* for unix & windows: 0 (graphic mode) or 1 (console mode).
0: try to use a graphic solution, if it fails then it uses console mode.
1: forces all dialogs into console mode even when an X server is present.
if enabled, it can use the package Dialog or dialog.exe.
on windows it only make sense for console applications */
extern int tinyfd_assumeGraphicDisplay; /* 0 (default) or 1 */
/* some systems don't set the environment variable DISPLAY even when a graphic display is present.
set this to 1 to tell tinyfiledialogs to assume the existence of a graphic display */
extern char tinyfd_response[1024];
/* if you pass "tinyfd_query" as aTitle,
the functions will not display the dialogs
but will return 0 for console mode, 1 for graphic mode.
tinyfd_response is then filled with the retain solution.
possible values for tinyfd_response are (all lowercase)
for graphic mode:
windows_wchar windows applescript kdialog zenity zenity3 yad matedialog
shellementary qarma python2-tkinter python3-tkinter python-dbus
perl-dbus gxmessage gmessage xmessage xdialog gdialog dunst
for console mode:
dialog whiptail basicinput no_solution */
void tinyfd_beep(void);
int tinyfd_notifyPopup(
char const * aTitle, /* NULL or "" */
char const * aMessage, /* NULL or "" may contain \n \t */
char const * aIconType); /* "info" "warning" "error" */
/* return has only meaning for tinyfd_query */
int tinyfd_messageBox(
char const * aTitle , /* NULL or "" */
char const * aMessage , /* NULL or "" may contain \n \t */
char const * aDialogType , /* "ok" "okcancel" "yesno" "yesnocancel" */
char const * aIconType , /* "info" "warning" "error" "question" */
int aDefaultButton ) ;
/* 0 for cancel/no , 1 for ok/yes , 2 for no in yesnocancel */
char * tinyfd_inputBox(
char const * aTitle , /* NULL or "" */
char const * aMessage , /* NULL or "" (\n and \t have no effect) */
char const * aDefaultInput ) ; /* NULL = passwordBox, "" = inputbox */
/* returns NULL on cancel */
char * tinyfd_saveFileDialog(
char const * aTitle , /* NULL or "" */
char const * aDefaultPathAndFile , /* NULL or "" */
int aNumOfFilterPatterns , /* 0 (1 in the following example) */
char const * const * aFilterPatterns , /* NULL or char const * lFilterPatterns[1]={"*.txt"} */
char const * aSingleFilterDescription ) ; /* NULL or "text files" */
/* returns NULL on cancel */
char * tinyfd_openFileDialog(
char const * aTitle, /* NULL or "" */
char const * aDefaultPathAndFile, /* NULL or "" */
int aNumOfFilterPatterns , /* 0 (2 in the following example) */
char const * const * aFilterPatterns, /* NULL or char const * lFilterPatterns[2]={"*.png","*.jpg"}; */
char const * aSingleFilterDescription, /* NULL or "image files" */
int aAllowMultipleSelects ) ; /* 0 or 1 */
/* in case of multiple files, the separator is | */
/* returns NULL on cancel */
char * tinyfd_selectFolderDialog(
char const * aTitle, /* NULL or "" */
char const * aDefaultPath); /* NULL or "" */
/* returns NULL on cancel */
char * tinyfd_colorChooser(
char const * aTitle, /* NULL or "" */
char const * aDefaultHexRGB, /* NULL or "" or "#FF0000" */
unsigned char const aDefaultRGB[3] , /* unsigned char lDefaultRGB[3] = { 0 , 128 , 255 }; */
unsigned char aoResultRGB[3] ) ; /* unsigned char lResultRGB[3]; */
/* aDefaultRGB is used only if aDefaultHexRGB is absent */
/* aDefaultRGB and aoResultRGB can be the same array */
/* returns NULL on cancel */
/* returns the hexcolor as a string "#FF0000" */
/* aoResultRGB also contains the result */
/************ WINDOWS ONLY SECTION ************************/
#ifdef _WIN32
/* windows only - utf-16 version */
int tinyfd_notifyPopupW(
wchar_t const * aTitle, /* NULL or L"" */
wchar_t const * aMessage, /* NULL or L"" may contain \n \t */
wchar_t const * aIconType); /* L"info" L"warning" L"error" */
/* windows only - utf-16 version */
int tinyfd_messageBoxW(
wchar_t const * aTitle, /* NULL or L"" */
wchar_t const * aMessage, /* NULL or L"" may contain \n \t */
wchar_t const * aDialogType, /* L"ok" L"okcancel" L"yesno" */
wchar_t const * aIconType, /* L"info" L"warning" L"error" L"question" */
int aDefaultButton ); /* 0 for cancel/no , 1 for ok/yes */
/* returns 0 for cancel/no , 1 for ok/yes */
/* windows only - utf-16 version */
wchar_t * tinyfd_inputBoxW(
wchar_t const * aTitle, /* NULL or L"" */
wchar_t const * aMessage, /* NULL or L"" (\n nor \t not respected) */
wchar_t const * aDefaultInput); /* NULL passwordBox, L"" inputbox */
/* windows only - utf-16 version */
wchar_t * tinyfd_saveFileDialogW(
wchar_t const * aTitle, /* NULL or L"" */
wchar_t const * aDefaultPathAndFile, /* NULL or L"" */
int aNumOfFilterPatterns, /* 0 (1 in the following example) */
wchar_t const * const * aFilterPatterns, /* NULL or wchar_t const * lFilterPatterns[1]={L"*.txt"} */
wchar_t const * aSingleFilterDescription); /* NULL or L"text files" */
/* returns NULL on cancel */
/* windows only - utf-16 version */
wchar_t * tinyfd_openFileDialogW(
wchar_t const * aTitle, /* NULL or L"" */
wchar_t const * aDefaultPathAndFile, /* NULL or L"" */
int aNumOfFilterPatterns , /* 0 (2 in the following example) */
wchar_t const * const * aFilterPatterns, /* NULL or wchar_t const * lFilterPatterns[2]={L"*.png","*.jpg"} */
wchar_t const * aSingleFilterDescription, /* NULL or L"image files" */
int aAllowMultipleSelects ) ; /* 0 or 1 */
/* in case of multiple files, the separator is | */
/* returns NULL on cancel */
/* windows only - utf-16 version */
wchar_t * tinyfd_selectFolderDialogW(
wchar_t const * aTitle, /* NULL or L"" */
wchar_t const * aDefaultPath); /* NULL or L"" */
/* returns NULL on cancel */
/* windows only - utf-16 version */
wchar_t * tinyfd_colorChooserW(
wchar_t const * aTitle, /* NULL or L"" */
wchar_t const * aDefaultHexRGB, /* NULL or L"#FF0000" */
unsigned char const aDefaultRGB[3], /* unsigned char lDefaultRGB[3] = { 0 , 128 , 255 }; */
unsigned char aoResultRGB[3]); /* unsigned char lResultRGB[3]; */
/* returns the hexcolor as a string L"#FF0000" */
/* aoResultRGB also contains the result */
/* aDefaultRGB is used only if aDefaultHexRGB is NULL */
/* aDefaultRGB and aoResultRGB can be the same array */
/* returns NULL on cancel */
#endif /*_WIN32 */
#ifdef __cplusplus
} /*extern "C"*/
#endif
#endif /* TINYFILEDIALOGS_H */
/*
________________________________________________________________________________
| ____________________________________________________________________________ |
| | | |
| | on windows: | |
| | - for UTF-16, use the wchar_t functions at the bottom of the header file | |
| | - _wfopen() requires wchar_t | |
| | | |
| | - in tinyfiledialogs, char is UTF-8 by default (since v3.6) | |
| | - but fopen() expects MBCS (not UTF-8) | |
| | - if you want char to be MBCS: set tinyfd_winUtf8 to 0 | |
| | | |
| | - alternatively, tinyfiledialogs provides | |
| | functions to convert between UTF-8, UTF-16 and MBCS | |
| |____________________________________________________________________________| |
|________________________________________________________________________________|
- This is not for ios nor android (it works in termux though).
- The files can be renamed with extension ".cpp" as the code is 100% compatible C C++
(just comment out << extern "C" >> in the header file)
- Windows is fully supported from XP to 10 (maybe even older versions)
- C# & LUA via dll, see files in the folder EXTRAS
- OSX supported from 10.4 to latest (maybe even older versions)
- Do not use " and ' as the dialogs will be displayed with a warning
instead of the title, message, etc...
- There's one file filter only, it may contain several patterns.
- If no filter description is provided,
the list of patterns will become the description.
- On windows link against Comdlg32.lib and Ole32.lib
(on windows the no linking claim is a lie)
- On unix: it tries command line calls, so no such need (NO LINKING).
- On unix you need one of the following:
applescript, kdialog, zenity, matedialog, shellementary, qarma, yad,
python (2 or 3)/tkinter/python-dbus (optional), Xdialog
or curses dialogs (opens terminal if running without console).
- One of those is already included on most (if not all) desktops.
- In the absence of those it will use gdialog, gxmessage or whiptail
with a textinputbox. If nothing is found, it switches to basic console input,
it opens a console if needed (requires xterm + bash).
- for curses dialogs you must set tinyfd_allowCursesDialogs=1
- You can query the type of dialog that will be used (pass "tinyfd_query" as aTitle)
- String memory is preallocated statically for all the returned values.
- File and path names are tested before return, they should be valid.
- tinyfd_forceConsole=1; at run time, forces dialogs into console mode.
- On windows, console mode only make sense for console applications.
- On windows, console mode is not implemented for wchar_T UTF-16.
- Mutiple selects are not possible in console mode.
- The package dialog must be installed to run in curses dialogs in console mode.
It is already installed on most unix systems.
- On osx, the package dialog can be installed via
http://macappstore.org/dialog or http://macports.org
- On windows, for curses dialogs console mode,
dialog.exe should be copied somewhere on your executable path.
It can be found at the bottom of the following page:
http://andrear.altervista.org/home/cdialog.php
*/