mirror of https://git.sr.ht/~kikoodx/sle
Compare commits
9 Commits
Author | SHA1 | Date |
---|---|---|
KikooDX | ab7fa16727 | |
KikooDX | 53132075b8 | |
KikooDX | 5727f19fb9 | |
KikooDX | dc7161c81b | |
KikooDX | 023ff12cb9 | |
KikooDX | c5a202a6f6 | |
KikooDX | 8f53ecbdc7 | |
KikooDX | a66aaf9bdc | |
KikooDX | 5d556f5f21 |
|
@ -1,4 +1,4 @@
|
|||
build/
|
||||
builddir/
|
||||
|
||||
# KBLE (Zig) files
|
||||
backup_*.kble
|
||||
|
|
|
@ -1,31 +0,0 @@
|
|||
cmake_minimum_required(VERSION 3.18)
|
||||
|
||||
project(sle C)
|
||||
|
||||
include_directories(include)
|
||||
|
||||
set(SOURCES
|
||||
src/main.c
|
||||
src/options.c
|
||||
src/mouse.c
|
||||
src/strtoint.c
|
||||
src/editing_area/main.c
|
||||
src/editing_area/level.c
|
||||
src/editing_area/draw.c
|
||||
src/tile_picker/main.c
|
||||
src/tile_picker/draw.c
|
||||
)
|
||||
|
||||
set(FLAGS
|
||||
-Wall -Wextra -Wshadow -Wswitch-default -Wswitch-enum
|
||||
-Wunreachable-code -Wstrict-prototypes -Wmissing-prototypes
|
||||
-Wold-style-definition -Werror-implicit-function-declaration
|
||||
-Wformat-pedantic
|
||||
-Werror -pedantic -std=c90
|
||||
-Os)
|
||||
|
||||
add_executable(${PROJECT_NAME} ${SOURCES} ${SOURCES_RAYLIB})
|
||||
|
||||
add_compile_options(PRIVATE ${FLAGS})
|
||||
|
||||
target_link_libraries(${PROJECT_NAME} raylib)
|
36
README
36
README
|
@ -3,22 +3,26 @@ SLE
|
|||
A simple project oriented single screen tilebased level editor.
|
||||
|
||||
SLE read and write KBLE level files.
|
||||
=> https://git.sr.ht/~kikoodx/kble
|
||||
KBLE format specifications:
|
||||
=> https://git.sr.ht/~kikoodx/kble/tree/dev/item/kbleformat.md
|
||||
|
||||
COMPILATION
|
||||
===========
|
||||
Dependencies: raylib
|
||||
Runtime dependencies: raylib
|
||||
Build dependencies: meson, raylib
|
||||
|
||||
$ git clone https://git.sr.ht/~kikoodx/sle
|
||||
$ mkdir sle/build && cd sle/build
|
||||
$ cmake ..
|
||||
$ make
|
||||
$ git clone https://git.sr.ht/~kikoodx/sle && cd sle
|
||||
$ meson setup builddir && cd builddir
|
||||
$ meson compile
|
||||
|
||||
The following will install the resulting `sle` binary on your system.
|
||||
# meson install
|
||||
|
||||
RUN
|
||||
===
|
||||
$ <SLE binary path> -tileset <tileset> -level <KBLE level to open>
|
||||
Example:
|
||||
$ build/sle -tileset assets/tileset.png -level sample.kble
|
||||
$ sle -tileset assets/tileset.png -level sample.kble
|
||||
|
||||
SYNOPSIS
|
||||
========
|
||||
|
@ -34,6 +38,7 @@ Main window - Editing Area
|
|||
--------------------------
|
||||
Left click: draw with selected tile
|
||||
Right click: erase (tile 0)
|
||||
Middle click: pick a tile
|
||||
|
||||
Secondary window - Tile Picker
|
||||
------------------------------
|
||||
|
@ -50,8 +55,8 @@ FLAGS
|
|||
Mandatory flags
|
||||
---------------
|
||||
All these options take a path to a file as argument.
|
||||
-tileset Tileset image
|
||||
-level KBLE file
|
||||
-tileset : tileset image
|
||||
-level : KBLE file
|
||||
|
||||
Optional flags
|
||||
--------------
|
||||
|
@ -59,19 +64,27 @@ These flags are boolean toggles. They take no option.
|
|||
-verbose : print debug informations to the standard output
|
||||
-create : create an empty level instead of reading from the -level path
|
||||
|
||||
All these flags take integers as argument.
|
||||
These flags take integers as argument.
|
||||
-tile-width
|
||||
-tile-height
|
||||
-level-width : used by -create
|
||||
-level-height : used by -create
|
||||
-tile-first
|
||||
-editor-scale
|
||||
-editor-width
|
||||
-editor-height
|
||||
-editor-target-fps
|
||||
-editor-scale
|
||||
-editor-off-x
|
||||
-editor-off-y
|
||||
-picker-target-fps
|
||||
-picker-padding
|
||||
|
||||
These flags take colors as argument.
|
||||
Color format : #RRGGBB or RRGGBB
|
||||
-editor-bg-color
|
||||
-picker-bg-color
|
||||
|
||||
Example aliases
|
||||
---------------
|
||||
By using the flags, it's very easy to create specific configurations.
|
||||
|
@ -90,7 +103,8 @@ alias sle-cg='sle -tile-width 16 -tile-height 16 -level-width 25 \
|
|||
# fx-9860G configuration
|
||||
alias sle-fx='sle -tile-width 8 -tile-height 8 -level-width 16 \
|
||||
-level-height 8 -editor-width 128 -editor-height 64 \
|
||||
-editor-off-x 0 -editor-off-y 0'
|
||||
-editor-off-x 0 -editor-off-y 0 -editor-bg-color #b0b0b0 \
|
||||
-picker-bg-color #b0b0b0'
|
||||
|
||||
DEFAULT CONFIGURATION
|
||||
=====================
|
||||
|
|
|
@ -6,22 +6,29 @@
|
|||
|
||||
#define TILE_WIDTH 16
|
||||
#define TILE_HEIGHT 16
|
||||
#define TILE_FIRST 0
|
||||
|
||||
#define EDITOR_BACKGROUND_COLOR \
|
||||
(Color) { 0, 0, 0, 255 }
|
||||
#define PICKER_BACKGROUND_COLOR \
|
||||
(Color) { 0, 0, 0, 255 }
|
||||
#define UNSELECTED_TILE_COLOR \
|
||||
(Color) { 80, 80, 80, 255 }
|
||||
#define OVERRING_TILE_COLOR \
|
||||
(Color) { 255, 255, 255, 80 }
|
||||
|
||||
#define NEW_LEVEL_WIDTH 25
|
||||
#define NEW_LEVEL_HEIGHT 14
|
||||
#define NEW_LEVEL_WIDTH 32
|
||||
#define NEW_LEVEL_HEIGHT 18
|
||||
|
||||
#define EDITOR_WINDOW_WIDTH 396
|
||||
#define EDITOR_WINDOW_HEIGHT 224
|
||||
#define EDITOR_SCALE 2
|
||||
#define EDITOR_WINDOW_WIDTH 512
|
||||
#define EDITOR_WINDOW_HEIGHT 288
|
||||
#define EDITOR_TARGET_FPS 60
|
||||
#define EDITOR_DRAW_OFFSET_X -2
|
||||
#define EDITOR_DRAW_OFFSET_X 0
|
||||
#define EDITOR_DRAW_OFFSET_Y 0
|
||||
|
||||
#define PICKER_TARGET_FPS 30
|
||||
#define PICKER_SCALE 2
|
||||
#define PICKER_TARGET_FPS 60
|
||||
#define PICKER_PADDING 4
|
||||
|
||||
#define PICKER_WINDOW_WIDTH \
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
/* Copyright (C) 2021 KikooDX */
|
||||
#pragma once
|
||||
|
||||
#include <raylib.h>
|
||||
|
||||
#define BUFFER_SIZE 256
|
||||
|
||||
struct Options {
|
||||
|
@ -11,15 +13,20 @@ struct Options {
|
|||
/* optionnal arguments, default values in conf.h */
|
||||
int tile_width;
|
||||
int tile_height;
|
||||
int tile_first;
|
||||
int new_level_width;
|
||||
int new_level_height;
|
||||
int editor_scale;
|
||||
int editor_width;
|
||||
int editor_height;
|
||||
int editor_target_fps;
|
||||
int editor_draw_offset_x;
|
||||
int editor_draw_offset_y;
|
||||
Color editor_bg_color;
|
||||
int picker_scale;
|
||||
int picker_target_fps;
|
||||
int picker_padding;
|
||||
Color picker_bg_color;
|
||||
/* determined after previous options */
|
||||
int tileset_width;
|
||||
int tileset_height;
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
/* SPDX-License-Identifier: GPL-3.0-or-later */
|
||||
/* Copyright (C) 2021 KikooDX */
|
||||
#pragma once
|
||||
|
||||
#include "options.h"
|
||||
#include <raylib.h>
|
||||
|
||||
float scale_editor(struct Options options);
|
||||
Vector2 offset_editor(struct Options options);
|
||||
float scale_picker(struct Options options);
|
||||
Vector2 offset_picker(struct Options options);
|
|
@ -0,0 +1,8 @@
|
|||
/* SPDX-License-Identifier: GPL-3.0-or-later */
|
||||
/* Copyright (C) 2021 KikooDX */
|
||||
#pragma once
|
||||
|
||||
#include <raylib.h>
|
||||
|
||||
/* Attempt to convert a string to a raylib Color. */
|
||||
Color strtocolor(char *string);
|
|
@ -0,0 +1,43 @@
|
|||
project('sle', 'c',
|
||||
version : '0.4.0',
|
||||
license : 'GPL-3.0-or-later')
|
||||
raylibdep = dependency('raylib', version: '>=3.5.0')
|
||||
|
||||
inc = include_directories('include')
|
||||
|
||||
sources = [
|
||||
'src/main.c',
|
||||
'src/mouse.c',
|
||||
'src/options.c',
|
||||
'src/scale.c',
|
||||
'src/strtocolor.c',
|
||||
'src/strtoint.c',
|
||||
'src/editing_area/draw.c',
|
||||
'src/editing_area/level.c',
|
||||
'src/editing_area/main.c',
|
||||
'src/tile_picker/draw.c',
|
||||
'src/tile_picker/main.c',
|
||||
]
|
||||
|
||||
c_flags = [
|
||||
'-std=c99',
|
||||
'-Os',
|
||||
'-Wall',
|
||||
'-Wextra',
|
||||
'-pedantic',
|
||||
'-Wshadow',
|
||||
'-Wswitch-default',
|
||||
'-Wswitch-enum',
|
||||
'-Wunreachable-code',
|
||||
'-Wstrict-prototypes',
|
||||
'-Wmissing-prototypes',
|
||||
'-Wold-style-definition',
|
||||
'-Werror-implicit-function-declaration',
|
||||
]
|
||||
|
||||
executable('sle',
|
||||
sources,
|
||||
include_directories : inc,
|
||||
dependencies : raylibdep,
|
||||
install : true,
|
||||
c_args : c_flags)
|
BIN
sample.kble
BIN
sample.kble
Binary file not shown.
|
@ -1,6 +1,7 @@
|
|||
/* SPDX-License-Identifier: GPL-3.0-or-later */
|
||||
/* Copyright (C) 2021 KikooDX */
|
||||
|
||||
#include "editing_area/draw.h"
|
||||
#include "conf.h"
|
||||
#include "editing_area/level.h"
|
||||
#include "options.h"
|
||||
|
@ -19,10 +20,11 @@ void level_draw(struct Level level, struct Options options,
|
|||
if (tile_index >= level.width * level.height)
|
||||
continue;
|
||||
const Tile tile =
|
||||
level.data[x + y * level.width];
|
||||
level.data[tile_index] - options.tile_first;
|
||||
/* if tile is not in tileset, skip */
|
||||
if (!tile || tile >= options.tileset_width *
|
||||
options.tileset_height)
|
||||
if ((!tile && !options.tile_first) ||
|
||||
tile >= (Tile)options.tileset_width *
|
||||
options.tileset_height)
|
||||
continue;
|
||||
|
||||
const Rectangle tile_rect = {
|
||||
|
|
|
@ -18,6 +18,7 @@ static int write_byte_group(FILE *file, Tile value, int size);
|
|||
int level_read(struct Level *level, char *path)
|
||||
{
|
||||
FILE *file = NULL;
|
||||
int byte_hold = 0;
|
||||
unsigned char byte = 0;
|
||||
unsigned int tile_size = 0;
|
||||
int level_size = 0;
|
||||
|
@ -43,9 +44,10 @@ int level_read(struct Level *level, char *path)
|
|||
}
|
||||
|
||||
/* get tile size (in bytes) */
|
||||
tile_size = read_byte(file);
|
||||
if (tile_size < 0)
|
||||
byte_hold = read_byte(file);
|
||||
if (byte_hold < 0)
|
||||
return -1;
|
||||
tile_size = (unsigned int)byte_hold;
|
||||
/* check than tile size is in boundaries */
|
||||
if (tile_size > sizeof(Tile) / sizeof(char)) {
|
||||
fprintf(stderr,
|
||||
|
@ -56,11 +58,11 @@ int level_read(struct Level *level, char *path)
|
|||
}
|
||||
/* get width */
|
||||
level->width = read_byte_group(file, 2);
|
||||
if (level->width == (Tile)-1)
|
||||
if ((Tile)level->width == (Tile)-1)
|
||||
return -1;
|
||||
/* get height */
|
||||
level->height = read_byte_group(file, 2);
|
||||
if (level->height == (Tile)-1)
|
||||
if ((Tile)level->height == (Tile)-1)
|
||||
return -1;
|
||||
|
||||
/* allocate memory for data */
|
||||
|
@ -96,11 +98,11 @@ int level_create(struct Level *level, struct Options options)
|
|||
|
||||
/* set width */
|
||||
level->width = options.new_level_width;
|
||||
if (level->width == (Tile)-1)
|
||||
if ((Tile)level->width == (Tile)-1)
|
||||
return -1;
|
||||
/* set height */
|
||||
level->height = options.new_level_height;
|
||||
if (level->height == (Tile)-1)
|
||||
if ((Tile)level->height == (Tile)-1)
|
||||
return -1;
|
||||
|
||||
/* allocate memory for data */
|
||||
|
|
|
@ -1,11 +1,14 @@
|
|||
/* SPDX-License-Identifier: GPL-3.0-or-later */
|
||||
/* Copyright (C) 2021 KikooDX */
|
||||
|
||||
#include "editing_area/main.h"
|
||||
#include "conf.h"
|
||||
#include "editing_area/draw.h"
|
||||
#include "editing_area/level.h"
|
||||
#include "info.h"
|
||||
#include "mouse.h"
|
||||
#include "options.h"
|
||||
#include "scale.h"
|
||||
#include "shared_data.h"
|
||||
#include <raylib.h>
|
||||
#include <stdbool.h>
|
||||
|
@ -22,19 +25,25 @@ int editing_area_main(struct Options options,
|
|||
{
|
||||
int mouse_x;
|
||||
int mouse_y;
|
||||
int error;
|
||||
struct Level level;
|
||||
level.data = NULL;
|
||||
Texture2D tileset;
|
||||
|
||||
/* initialize raylib */
|
||||
InitWindow(options.editor_width, options.editor_height,
|
||||
InitWindow(options.editor_width * options.editor_scale,
|
||||
options.editor_height * options.editor_scale,
|
||||
"SLE main window");
|
||||
SetWindowState(FLAG_WINDOW_RESIZABLE);
|
||||
SetTargetFPS(options.editor_target_fps);
|
||||
init_mouse(options);
|
||||
/* load textures */
|
||||
tileset = LoadTexture(options.tileset_path);
|
||||
|
||||
/* render targets used for upscaling */
|
||||
const RenderTexture2D rend_target = LoadRenderTexture(
|
||||
options.editor_width, options.editor_height);
|
||||
const RenderTexture2D flip_target = LoadRenderTexture(
|
||||
options.editor_width, options.editor_height);
|
||||
|
||||
/* only proceed if tileset is large enough */
|
||||
if (tileset.width < options.tile_width ||
|
||||
tileset.height < options.tile_height) {
|
||||
|
@ -55,15 +64,29 @@ int editing_area_main(struct Options options,
|
|||
|
||||
while (!WindowShouldClose()) {
|
||||
/* update */
|
||||
init_mouse(options);
|
||||
update_mouse(&mouse_x, &mouse_y, level, shared_data);
|
||||
|
||||
/* draw */
|
||||
BeginDrawing();
|
||||
BeginTextureMode(rend_target);
|
||||
|
||||
ClearBackground(BLACK);
|
||||
ClearBackground(options.editor_bg_color);
|
||||
level_draw(level, options, tileset);
|
||||
editor_mouse_draw(options, mouse_x, mouse_y);
|
||||
|
||||
EndTextureMode();
|
||||
|
||||
/* flip texture */
|
||||
BeginTextureMode(flip_target);
|
||||
DrawTexture(rend_target.texture, 0, 0, WHITE);
|
||||
EndTextureMode();
|
||||
|
||||
/* draw upscaled render */
|
||||
ClearBackground(BLACK);
|
||||
DrawTextureEx(flip_target.texture,
|
||||
offset_editor(options), 0,
|
||||
scale_editor(options), WHITE);
|
||||
EndDrawing();
|
||||
}
|
||||
|
||||
|
@ -75,8 +98,10 @@ panic:
|
|||
/* deinit */
|
||||
level_free(&level);
|
||||
|
||||
/* unload textures */
|
||||
/* unload raylib stuff */
|
||||
UnloadTexture(tileset);
|
||||
UnloadRenderTexture(rend_target);
|
||||
UnloadRenderTexture(flip_target);
|
||||
CloseWindow();
|
||||
|
||||
/* tell to the child process it can end */
|
||||
|
@ -90,10 +115,12 @@ panic:
|
|||
|
||||
static void init_mouse(struct Options options)
|
||||
{
|
||||
SetMouseOffset(-options.editor_draw_offset_x,
|
||||
-options.editor_draw_offset_y);
|
||||
SetMouseScale(1.0 / options.tile_width,
|
||||
1.0 / options.tile_height);
|
||||
const float scaling = scale_editor(options);
|
||||
const Vector2 off = offset_editor(options);
|
||||
SetMouseOffset(-options.editor_draw_offset_x - off.x,
|
||||
-options.editor_draw_offset_y - off.y);
|
||||
SetMouseScale(1.0 / scaling / options.tile_width,
|
||||
1.0 / scaling / options.tile_height);
|
||||
}
|
||||
|
||||
static void update_mouse(int *mouse_x, int *mouse_y, struct Level level,
|
||||
|
@ -107,17 +134,17 @@ static void update_mouse(int *mouse_x, int *mouse_y, struct Level level,
|
|||
level.height - 1);
|
||||
|
||||
/* set tile */
|
||||
if (left_click) {
|
||||
if (left_click)
|
||||
level.data[*mouse_x + *mouse_y * level.width] =
|
||||
shared_data->selected_tile;
|
||||
}
|
||||
/* remove tile */
|
||||
if (right_click) {
|
||||
if (right_click)
|
||||
level.data[*mouse_x + *mouse_y * level.width] = 0;
|
||||
}
|
||||
/* get info about tile */
|
||||
/* set tile to pointed cell (pick tile) */
|
||||
if (middle_click) {
|
||||
INFO_VAR("%d",
|
||||
level.data[*mouse_x + *mouse_y * level.width]);
|
||||
shared_data->selected_tile =
|
||||
level.data[*mouse_x + *mouse_y * level.width];
|
||||
}
|
||||
}
|
||||
|
|
22
src/main.c
22
src/main.c
|
@ -5,6 +5,7 @@
|
|||
#include "info.h"
|
||||
#include "options.h"
|
||||
#include "shared_data.h"
|
||||
#include "strtocolor.h"
|
||||
#include "strtoint.h"
|
||||
#include "tile_picker/main.h"
|
||||
#include <getopt.h>
|
||||
|
@ -31,7 +32,6 @@ static void set_tileset_dimensions(struct Options *options);
|
|||
* organize these panels in the way they want to. */
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int error;
|
||||
pid_t child_process;
|
||||
struct SharedData *shared_data;
|
||||
struct Options options = options_defaults();
|
||||
|
@ -98,15 +98,20 @@ static void process_arguments(int argc, char **argv,
|
|||
{"tileset", required_argument, 0, 't'},
|
||||
{"tile-width", required_argument, 0, 'w'},
|
||||
{"tile-height", required_argument, 0, 'h'},
|
||||
{"tile-first", required_argument, 0, 'I'},
|
||||
{"level-width", required_argument, 0, 'i'},
|
||||
{"level-height", required_argument, 0, 'e'},
|
||||
{"editor-scale", required_argument, 0, 's'},
|
||||
{"editor-width", required_argument, 0, 'W'},
|
||||
{"editor-height", required_argument, 0, 'H'},
|
||||
{"editor-fps", required_argument, 0, 'f'},
|
||||
{"editor-off-x", required_argument, 0, 'o'},
|
||||
{"editor-off-y", required_argument, 0, 'O'},
|
||||
{"editor-bg-color", required_argument, 0, 'b'},
|
||||
{"picker-scale", required_argument, 0, 'S'},
|
||||
{"picker-fps", required_argument, 0, 'F'},
|
||||
{"picker-padding", required_argument, 0, 'p'},
|
||||
{"picker-bg-color", required_argument, 0, 'B'},
|
||||
{0, 0, 0, 0},
|
||||
};
|
||||
/* getopt_long stores the option index here */
|
||||
|
@ -133,12 +138,18 @@ static void process_arguments(int argc, char **argv,
|
|||
case 'h': /* tile height */
|
||||
options->tile_height = int_arg_min(opt, 1);
|
||||
break;
|
||||
case 'I': /* first tile index */
|
||||
options->tile_first = int_arg_min(opt, 0);
|
||||
break;
|
||||
case 'i': /* new level width */
|
||||
options->new_level_width = int_arg_min(opt, 1);
|
||||
break;
|
||||
case 'e': /* new level height */
|
||||
options->new_level_height = int_arg_min(opt, 1);
|
||||
break;
|
||||
case 's': /* editor scale */
|
||||
options->editor_scale = int_arg_min(opt, 1);
|
||||
break;
|
||||
case 'W': /* editor width */
|
||||
options->editor_width = int_arg_min(opt, 1);
|
||||
break;
|
||||
|
@ -157,6 +168,12 @@ static void process_arguments(int argc, char **argv,
|
|||
options->editor_draw_offset_y =
|
||||
strtoint(optarg);
|
||||
break;
|
||||
case 'b': /* editor background color */
|
||||
options->editor_bg_color = strtocolor(optarg);
|
||||
break;
|
||||
case 'S': /* picker scale */
|
||||
options->picker_scale = int_arg_min(opt, 1);
|
||||
break;
|
||||
case 'F': /* picker target FPS */
|
||||
options->picker_target_fps =
|
||||
int_arg_min(opt, 1);
|
||||
|
@ -164,6 +181,9 @@ static void process_arguments(int argc, char **argv,
|
|||
case 'p': /* picker padding */
|
||||
options->picker_padding = int_arg_min(opt, 0);
|
||||
break;
|
||||
case 'B': /* picker background color */
|
||||
options->picker_bg_color = strtocolor(optarg);
|
||||
break;
|
||||
case '?':
|
||||
/* getopt_long already printed an error message
|
||||
*/
|
||||
|
|
|
@ -8,19 +8,24 @@ struct Options options_defaults(void)
|
|||
.level_path = "",
|
||||
.tile_width = TILE_WIDTH,
|
||||
.tile_height = TILE_HEIGHT,
|
||||
.tile_first = TILE_FIRST,
|
||||
.tileset_width = 0,
|
||||
.tileset_height = 0,
|
||||
.new_level_width = NEW_LEVEL_WIDTH,
|
||||
.new_level_height = NEW_LEVEL_HEIGHT,
|
||||
.editor_scale = EDITOR_SCALE,
|
||||
.editor_width = EDITOR_WINDOW_WIDTH,
|
||||
.editor_height = EDITOR_WINDOW_HEIGHT,
|
||||
.editor_target_fps = EDITOR_TARGET_FPS,
|
||||
.editor_draw_offset_x = EDITOR_DRAW_OFFSET_X,
|
||||
.editor_draw_offset_y = EDITOR_DRAW_OFFSET_Y,
|
||||
.editor_bg_color = EDITOR_BACKGROUND_COLOR,
|
||||
.picker_scale = PICKER_SCALE,
|
||||
.picker_window_width = 0,
|
||||
.picker_window_height = 0,
|
||||
.picker_target_fps = PICKER_TARGET_FPS,
|
||||
.picker_padding = PICKER_PADDING,
|
||||
.picker_bg_color = PICKER_BACKGROUND_COLOR,
|
||||
.level_create = 0,
|
||||
};
|
||||
}
|
||||
|
|
|
@ -0,0 +1,46 @@
|
|||
/* SPDX-License-Identifier: GPL-3.0-or-later */
|
||||
/* Copyright (C) 2021 KikooDX */
|
||||
|
||||
#include "scale.h"
|
||||
#include "options.h"
|
||||
#include <raylib.h>
|
||||
|
||||
float scale_editor(struct Options options)
|
||||
{
|
||||
const float w_ratio =
|
||||
(float)GetScreenWidth() / options.editor_width;
|
||||
const float h_ratio =
|
||||
(float)GetScreenHeight() / options.editor_height;
|
||||
return (w_ratio < h_ratio) ? w_ratio : h_ratio;
|
||||
}
|
||||
|
||||
Vector2 offset_editor(struct Options options)
|
||||
{
|
||||
const float scaling = scale_editor(options);
|
||||
return (Vector2){
|
||||
((float)GetScreenWidth() - options.editor_width * scaling) /
|
||||
2,
|
||||
((float)GetScreenHeight() -
|
||||
options.editor_height * scaling) /
|
||||
2};
|
||||
}
|
||||
|
||||
float scale_picker(struct Options options)
|
||||
{
|
||||
const float w_ratio =
|
||||
(float)GetScreenWidth() / options.picker_window_width;
|
||||
const float h_ratio =
|
||||
(float)GetScreenHeight() / options.picker_window_height;
|
||||
return (w_ratio < h_ratio) ? w_ratio : h_ratio;
|
||||
}
|
||||
|
||||
Vector2 offset_picker(struct Options options)
|
||||
{
|
||||
const float scaling = scale_picker(options);
|
||||
return (Vector2){((float)GetScreenWidth() -
|
||||
options.picker_window_width * scaling) /
|
||||
2,
|
||||
((float)GetScreenHeight() -
|
||||
options.picker_window_height * scaling) /
|
||||
2};
|
||||
}
|
|
@ -0,0 +1,59 @@
|
|||
/* SPDX-License-Identifier: GPL-3.0-or-later */
|
||||
/* Copyright (C) 2021 KikooDX */
|
||||
|
||||
#include "strtocolor.h"
|
||||
#include "info.h"
|
||||
#include <raylib.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#define HEX_TABLE_SIZE 16
|
||||
static const int hex_table[HEX_TABLE_SIZE] = {
|
||||
'0', '1', '2', '3', '4', '5', '6', '7',
|
||||
'8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
|
||||
static const char *format_error =
|
||||
"ERROR: flag expected a color argument in the form #RRGGBB, got "
|
||||
"\"%s\"\n";
|
||||
|
||||
/* Attempt to convert a string to raylib Color. */
|
||||
Color strtocolor(char *string)
|
||||
{
|
||||
int rgb[3] = {0, 0, 0};
|
||||
char *character = string + (string[0] == '#');
|
||||
const size_t string_len = strlen(character);
|
||||
int i = 0;
|
||||
int sum = 0;
|
||||
|
||||
if (string_len != 6) {
|
||||
fprintf(stderr, format_error, string);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
while (*character != '\0') {
|
||||
int value = -1;
|
||||
int j;
|
||||
for (j = 0; j < HEX_TABLE_SIZE; j += 1) {
|
||||
if (hex_table[j] == *character) {
|
||||
value = j;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (value == -1) {
|
||||
fprintf(stderr, format_error, string);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
sum += value * (1 + 15 * (i % 2));
|
||||
INFO_VAR("%d", sum);
|
||||
if (i % 2) {
|
||||
rgb[i / 2] = sum;
|
||||
sum = 0;
|
||||
}
|
||||
i += 1;
|
||||
character += 1;
|
||||
}
|
||||
INFO_VAR("r=%d", rgb[0]);
|
||||
INFO_VAR("g=%d", rgb[1]);
|
||||
INFO_VAR("b=%d", rgb[2]);
|
||||
return (Color){rgb[0], rgb[1], rgb[2], 255};
|
||||
}
|
|
@ -9,9 +9,9 @@
|
|||
/* Attempt to convert a string to integer. */
|
||||
int strtoint(char *string)
|
||||
{
|
||||
char character;
|
||||
int i;
|
||||
const size_t string_len = strlen(string);
|
||||
int character;
|
||||
int i;
|
||||
int sum = 0;
|
||||
int multiplier = 1;
|
||||
int negative = string[0] == '-';
|
||||
|
|
|
@ -1,8 +1,11 @@
|
|||
/* SPDX-License-Identifier: GPL-3.0-or-later */
|
||||
/* Copyright (C) 2021 KikooDX */
|
||||
|
||||
#include "tile_picker/main.h"
|
||||
#include "conf.h"
|
||||
#include "mouse.h"
|
||||
#include "options.h"
|
||||
#include "scale.h"
|
||||
#include "shared_data.h"
|
||||
#include "tile_picker/draw.h"
|
||||
#include <raylib.h>
|
||||
|
@ -23,28 +26,48 @@ int tile_picker_main(struct Options options,
|
|||
Texture2D tileset;
|
||||
|
||||
/* initialize raylib */
|
||||
InitWindow(options.picker_window_width,
|
||||
options.picker_window_height,
|
||||
InitWindow(options.picker_window_width * options.picker_scale,
|
||||
options.picker_window_height * options.picker_scale,
|
||||
"SLE secondary window");
|
||||
SetTargetFPS(options.picker_target_fps);
|
||||
init_mouse(options);
|
||||
/* load textures */
|
||||
tileset = LoadTexture(options.tileset_path);
|
||||
|
||||
/* render targets used for upscaling */
|
||||
const RenderTexture2D rend_target = LoadRenderTexture(
|
||||
options.picker_window_width, options.picker_window_height);
|
||||
const RenderTexture2D flip_target = LoadRenderTexture(
|
||||
options.picker_window_width, options.picker_window_height);
|
||||
|
||||
/* only proceed if tileset is well loaded */
|
||||
if (tileset.width > 0) {
|
||||
while (!shared_data->end_child) {
|
||||
/* update */
|
||||
init_mouse(options);
|
||||
update_mouse(&mouse_x, &mouse_y, options,
|
||||
shared_data);
|
||||
|
||||
/* draw */
|
||||
BeginDrawing();
|
||||
BeginTextureMode(rend_target);
|
||||
|
||||
ClearBackground(BLACK);
|
||||
ClearBackground(options.picker_bg_color);
|
||||
tileset_draw(tileset, options,
|
||||
shared_data->selected_tile);
|
||||
|
||||
EndTextureMode();
|
||||
|
||||
/* flip texture */
|
||||
BeginTextureMode(flip_target);
|
||||
DrawTexture(rend_target.texture, 0, 0, WHITE);
|
||||
EndTextureMode();
|
||||
|
||||
/* draw upscaled render */
|
||||
ClearBackground(BLACK);
|
||||
DrawTextureEx(flip_target.texture,
|
||||
offset_picker(options), 0,
|
||||
scale_picker(options), WHITE);
|
||||
EndDrawing();
|
||||
}
|
||||
}
|
||||
|
@ -59,11 +82,15 @@ int tile_picker_main(struct Options options,
|
|||
|
||||
static void init_mouse(struct Options options)
|
||||
{
|
||||
SetMouseOffset(-options.picker_padding,
|
||||
-options.picker_padding);
|
||||
const float scaling = scale_picker(options);
|
||||
const Vector2 off = offset_picker(options);
|
||||
SetMouseOffset(-options.picker_padding - off.x,
|
||||
-options.picker_padding - off.y);
|
||||
SetMouseScale(
|
||||
1.0 / (options.tile_width + options.picker_padding),
|
||||
1.0 / (options.tile_height + options.picker_padding));
|
||||
1.0 / (options.tile_width + options.picker_padding) /
|
||||
scaling,
|
||||
1.0 / (options.tile_height + options.picker_padding) /
|
||||
scaling);
|
||||
}
|
||||
|
||||
static void update_mouse(int *mouse_x, int *mouse_y,
|
||||
|
@ -71,7 +98,7 @@ static void update_mouse(int *mouse_x, int *mouse_y,
|
|||
struct SharedData *shared_data)
|
||||
{
|
||||
const bool left_click = IsMouseButtonDown(0);
|
||||
const bool right_click = IsMouseButtonDown(1);
|
||||
/* const bool right_click = IsMouseButtonDown(1); */
|
||||
|
||||
update_mouse_position(
|
||||
mouse_x, mouse_y,
|
||||
|
|
Loading…
Reference in New Issue