diff --git a/src/sfx.c b/src/sfx.c index b8efdba..8dc0efb 100644 --- a/src/sfx.c +++ b/src/sfx.c @@ -625,7 +625,7 @@ static void copyFromClipboard(Sfx* sfx) { tic_sound_effect* effect = getEffect(sfx); - if(fromClipboard(effect, sizeof(tic_sound_effect), true)) + if(fromClipboard(effect, sizeof(tic_sound_effect), true, false)) history_add(sfx->history.envelope); } @@ -633,7 +633,7 @@ static void copyWaveFromClipboard(Sfx* sfx) { tic_waveform* wave = getWaveform(sfx); - if(fromClipboard(wave, sizeof(tic_waveform), true)) + if(fromClipboard(wave, sizeof(tic_waveform), true, false)) history_add(sfx->history.waveform); } diff --git a/src/sprite.c b/src/sprite.c index 6366f36..b06f95f 100644 --- a/src/sprite.c +++ b/src/sprite.c @@ -648,8 +648,8 @@ static void drawRGBSlider(Sprite* sprite, s32 x, s32 y, u8* value) static void pasteColor(Sprite* sprite) { - fromClipboard(sprite->tic->cart.palette.data, sizeof(tic_palette), false); - fromClipboard(&sprite->tic->cart.palette.colors[sprite->color], sizeof(tic_rgb), false); + fromClipboard(sprite->tic->cart.palette.data, sizeof(tic_palette), false, true); + fromClipboard(&sprite->tic->cart.palette.colors[sprite->color], sizeof(tic_rgb), false, true); } static void drawRGBTools(Sprite* sprite, s32 x, s32 y) @@ -1240,7 +1240,7 @@ static void copyFromClipboard(Sprite* sprite) if(buffer) { - if(fromClipboard(buffer, size, true)) + if(fromClipboard(buffer, size, true, false)) { SDL_Rect rect = getSpriteRect(sprite); s32 r = rect.x + rect.w; diff --git a/src/studio.c b/src/studio.c index c8eb9e8..6829724 100644 --- a/src/studio.c +++ b/src/studio.c @@ -373,7 +373,24 @@ void str2buf(const char* str, s32 size, void* buf, bool flip) } } -bool fromClipboard(void* data, s32 size, bool flip) +void removeWhiteSpaces(char* str) +{ + int i = 0; + int len = strlen(str); + + for (int j = 0; j < len; j++) { + if (!isspace(str[j])) { + str[i] = str[j]; + i++; + } + } + + if (i < len - 1) { + str[i] = '\0'; + } +} + +bool fromClipboard(void* data, s32 size, bool flip, bool remove_white_spaces) { if(data) { @@ -383,6 +400,10 @@ bool fromClipboard(void* data, s32 size, bool flip) if(clipboard) { + if (remove_white_spaces) + removeWhiteSpaces(clipboard); + + bool valid = strlen(clipboard) == size * 2; if(valid) str2buf(clipboard, strlen(clipboard), data, flip); diff --git a/src/studio.h b/src/studio.h index 6cece04..d285898 100644 --- a/src/studio.h +++ b/src/studio.h @@ -154,8 +154,9 @@ void exitStudio(); u32 unzip(u8** dest, const u8* source, size_t size); void str2buf(const char* str, s32 size, void* buf, bool flip); +void removeWhiteSpaces(char* str); void toClipboard(const void* data, s32 size, bool flip); -bool fromClipboard(void* data, s32 size, bool flip); +bool fromClipboard(void* data, s32 size, bool flip, bool remove_white_spaces); typedef enum {