colourpicker

Simple Colour Picker written in C
git clone anongit@rnpnr.xyz:colourpicker.git
Log | Files | Refs | Feed | Submodules | README | LICENSE

Commit: 671d3053c84fa25aab1a163ed961fa7ae4edeb6c
Parent: 2f5924ee8b5f496bccfa79b88544d8a8a8480d6d
Author: Randy Palamar
Date:   Tue,  6 Aug 2024 06:35:06 -0600

drop memmove/string.h

Diffstat:
Mcolourpicker.c | 29+++++++++++++++++------------
Mgen_incs.c | 1-
2 files changed, 17 insertions(+), 13 deletions(-)

diff --git a/colourpicker.c b/colourpicker.c @@ -1,7 +1,6 @@ /* See LICENSE for copyright details */ #include <raylib.h> #include <stdio.h> -#include <string.h> /* memmove */ #include "util.c" @@ -10,6 +9,13 @@ static const char *mode_labels[CM_LAST][4] = { [CM_HSV] = { "H", "S", "V", "A" }, }; +static void +mem_move(char *src, char *dest, size n) +{ + if (dest < src) while (n) { *dest++ = *src++; n--; } + else while (n) { n--; dest[n] = src[n]; } +} + static f32 move_towards_f32(f32 current, f32 target, f32 delta) { @@ -254,10 +260,11 @@ get_slider_subrects(Rect r, Rect *label, Rect *slider, Rect *value) static void parse_and_store_text_input(ColourPickerCtx *ctx) { - v4 new_colour = {0}; enum colour_mode new_mode = CM_LAST; - if (ctx->is.idx == INPUT_HEX) { + if (ctx->is.idx == -1) { + return; + } else if (ctx->is.idx == INPUT_HEX) { new_colour = normalize_colour(parse_hex_u32(ctx->is.buf)); new_mode = CM_RGB; } else { @@ -391,10 +398,9 @@ do_text_input(ColourPickerCtx *ctx, Rect r, Color colour) break; } - /* TODO: remove memmove */ - memmove(ctx->is.buf + ctx->is.cursor + 1, - ctx->is.buf + ctx->is.cursor, - ctx->is.buf_len - ctx->is.cursor + 1); + mem_move(ctx->is.buf + ctx->is.cursor, + ctx->is.buf + ctx->is.cursor + 1, + ctx->is.buf_len - ctx->is.cursor + 1); ctx->is.buf[ctx->is.cursor++] = key; ctx->is.buf_len++; @@ -410,12 +416,11 @@ do_text_input(ColourPickerCtx *ctx, Rect r, Color colour) if ((IsKeyPressed(KEY_BACKSPACE) || IsKeyPressedRepeat(KEY_BACKSPACE)) && ctx->is.cursor > 0) { - /* TODO: remove memmove */ ctx->is.cursor--; - memmove(ctx->is.buf + ctx->is.cursor, - ctx->is.buf + ctx->is.cursor + 1, - ctx->is.buf_len - ctx->is.cursor - 1); - ctx->is.buf[--ctx->is.buf_len] = 0; + mem_move(ctx->is.buf + ctx->is.cursor + 1, + ctx->is.buf + ctx->is.cursor, + ctx->is.buf_len - ctx->is.cursor); + ctx->is.buf_len--; } if (IsKeyPressed(KEY_ENTER)) { diff --git a/gen_incs.c b/gen_incs.c @@ -4,7 +4,6 @@ #include <stdint.h> #include <stdio.h> #include <stdlib.h> -#include <string.h> #include "config.h"