Implement chop_background_layer
parent
2568c76a63
commit
9f47008ae0
11
src/color.c
11
src/color.c
|
@ -83,6 +83,17 @@ Color hexstr(const char *hexstr)
|
|||
1.0f);
|
||||
}
|
||||
|
||||
Color hexs(String input)
|
||||
{
|
||||
if (input.count < 6) return COLOR_BLACK;
|
||||
|
||||
return rgba(
|
||||
parse_color_component(input.data) / 255.0f,
|
||||
parse_color_component(input.data + 2) / 255.0f,
|
||||
parse_color_component(input.data + 4) / 255.0f,
|
||||
1.0f);
|
||||
}
|
||||
|
||||
SDL_Color color_for_sdl(Color color)
|
||||
{
|
||||
const SDL_Color result = {
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
#include <stdio.h>
|
||||
#include <SDL.h>
|
||||
#include "./system/s.h"
|
||||
|
||||
#define COLOR_BLACK rgba(0.0f, 0.0f, 0.0f, 1.0f)
|
||||
#define COLOR_WHITE rgba(1.0f, 1.0f, 1.0f, 1.0f)
|
||||
|
@ -16,6 +17,7 @@ Color rgba(float r, float g, float b, float a);
|
|||
Color hsla(float h, float s, float l, float a);
|
||||
Color rgba_to_hsla(Color color);
|
||||
Color hexstr(const char *hexstr);
|
||||
Color hexs(String input);
|
||||
SDL_Color color_for_sdl(Color color);
|
||||
|
||||
int color_hex_to_stream(Color color, FILE *stream);
|
||||
|
|
|
@ -31,6 +31,12 @@ int background_layer_read_from_line_stream(BackgroundLayer *layer,
|
|||
return 0;
|
||||
}
|
||||
|
||||
BackgroundLayer chop_background_layer(String *input)
|
||||
{
|
||||
String line = trim(chop_by_delim(input, '\n'));
|
||||
return create_background_layer(hexs(line));
|
||||
}
|
||||
|
||||
int background_layer_render(BackgroundLayer *layer,
|
||||
const Camera *camera,
|
||||
int active)
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
#define BACKGROUND_LAYER_H_
|
||||
|
||||
#include "color_picker.h"
|
||||
#include "system/s.h"
|
||||
|
||||
typedef struct {
|
||||
ColorPicker color_picker;
|
||||
|
@ -11,6 +12,7 @@ typedef struct {
|
|||
BackgroundLayer create_background_layer(Color color);
|
||||
int background_layer_read_from_line_stream(BackgroundLayer *layer,
|
||||
LineStream *line_stream);
|
||||
BackgroundLayer chop_background_layer(String *input);
|
||||
|
||||
static inline
|
||||
LayerPtr background_layer_as_layer(BackgroundLayer *layer)
|
||||
|
|
|
@ -62,4 +62,31 @@ int string_equal(String a, String b)
|
|||
return memcmp(a.data, b.data, a.count) == 0;
|
||||
}
|
||||
|
||||
static inline
|
||||
String trim_begin(String input)
|
||||
{
|
||||
while (input.count > 0 && isspace(*input.data)) {
|
||||
input.data += 1;
|
||||
input.count -= 1;
|
||||
}
|
||||
|
||||
return input;
|
||||
}
|
||||
|
||||
static inline
|
||||
String trim_end(String input)
|
||||
{
|
||||
while (input.count > 0 && isspace(*(input.data + input.count - 1))) {
|
||||
input.count -= 1;
|
||||
}
|
||||
|
||||
return input;
|
||||
}
|
||||
|
||||
static inline
|
||||
String trim(String input)
|
||||
{
|
||||
return trim_end(trim_begin(input));
|
||||
}
|
||||
|
||||
#endif // S_H_
|
||||
|
|
Loading…
Reference in New Issue