mirror of https://git.sr.ht/~kikoodx/sle
Flags for background color configuration
This commit is contained in:
parent
5d556f5f21
commit
a66aaf9bdc
|
@ -9,6 +9,7 @@ set(SOURCES
|
|||
src/options.c
|
||||
src/mouse.c
|
||||
src/strtoint.c
|
||||
src/strtocolor.c
|
||||
src/editing_area/main.c
|
||||
src/editing_area/level.c
|
||||
src/editing_area/draw.c
|
||||
|
|
10
README
10
README
|
@ -59,7 +59,7 @@ 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
|
||||
|
@ -72,6 +72,11 @@ All these flags take integers as argument.
|
|||
-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 +95,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
|
||||
=====================
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
/* Copyright (C) 2021 KikooDX */
|
||||
#pragma once
|
||||
|
||||
#include <raylib.h>
|
||||
|
||||
#define BUFFER_SIZE 256
|
||||
|
||||
struct Options {
|
||||
|
@ -18,8 +20,10 @@ struct Options {
|
|||
int editor_target_fps;
|
||||
int editor_draw_offset_x;
|
||||
int editor_draw_offset_y;
|
||||
Color editor_bg_color;
|
||||
int picker_target_fps;
|
||||
int picker_padding;
|
||||
Color picker_bg_color;
|
||||
/* determined after previous options */
|
||||
int tileset_width;
|
||||
int tileset_height;
|
||||
|
|
|
@ -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);
|
|
@ -61,7 +61,7 @@ int editing_area_main(struct Options options,
|
|||
/* draw */
|
||||
BeginDrawing();
|
||||
|
||||
ClearBackground(EDITOR_BACKGROUND_COLOR);
|
||||
ClearBackground(options.editor_bg_color);
|
||||
level_draw(level, options, tileset);
|
||||
editor_mouse_draw(options, mouse_x, mouse_y);
|
||||
|
||||
|
|
|
@ -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>
|
||||
|
@ -105,8 +106,10 @@ static void process_arguments(int argc, char **argv,
|
|||
{"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-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 */
|
||||
|
@ -157,6 +160,9 @@ 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 'F': /* picker target FPS */
|
||||
options->picker_target_fps =
|
||||
int_arg_min(opt, 1);
|
||||
|
@ -164,6 +170,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
|
||||
*/
|
||||
|
|
|
@ -17,10 +17,12 @@ struct Options options_defaults(void)
|
|||
.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_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,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>
|
||||
|
||||
static const int 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] == '-';
|
||||
|
|
|
@ -42,7 +42,7 @@ int tile_picker_main(struct Options options,
|
|||
/* draw */
|
||||
BeginDrawing();
|
||||
|
||||
ClearBackground(PICKER_BACKGROUND_COLOR);
|
||||
ClearBackground(options.picker_bg_color);
|
||||
tileset_draw(tileset, options,
|
||||
shared_data->selected_tile);
|
||||
|
||||
|
|
Loading…
Reference in New Issue