shithub: ft²

Download patch

ref: 08c115d1dfd6fd7e11ba6e4f66d77f43268a4bb4
parent: 493bce54779a18331ff9c000c59ae2a5be5f22c0
author: Olav Sørensen <olav.sorensen@live.no>
date: Sat Apr 16 15:03:41 EDT 2022

Fix text mark bug when clicking on a new instrument/sample

--- a/src/ft2_header.h
+++ b/src/ft2_header.h
@@ -12,7 +12,7 @@
 #endif
 #include "ft2_replayer.h"
 
-#define PROG_VER_STR "1.53"
+#define PROG_VER_STR "1.54"
 
 // do NOT change these! It will only mess things up...
 
--- a/src/ft2_textboxes.c
+++ b/src/ft2_textboxes.c
@@ -515,45 +515,48 @@
 	if (t->textPtr == NULL)
 		return;
 
-	// draw text mark background
-	if (textIsMarked())
+	// draw text mark background (if this is the textbox we last interacted with)
+	if (mouse.lastEditBox == textBoxID)
 	{
-		hideSprite(SPRITE_TEXT_CURSOR);
+		if (textIsMarked())
+		{
+			hideSprite(SPRITE_TEXT_CURSOR);
 
-		int32_t start = getTextMarkStart();
-		int32_t end = getTextMarkEnd();
+			int32_t start = getTextMarkStart();
+			int32_t end = getTextMarkEnd();
 
-		assert(start < t->maxChars && end <= t->maxChars);
+			assert(start < t->maxChars && end <= t->maxChars);
 
-		// find pixel start/length from markX1 and markX2
+			// find pixel start/length from markX1 and markX2
 
-		int32_t x1 = 0;
-		int32_t x2 = 0;
+			int32_t x1 = 0;
+			int32_t x2 = 0;
 
-		for (int32_t i = 0; i < end; i++)
-		{
-			const char ch = t->textPtr[i];
-			if (ch == '\0')
-				break;
+			for (int32_t i = 0; i < end; i++)
+			{
+				const char ch = t->textPtr[i];
+				if (ch == '\0')
+					break;
 
-			cw = charWidth(ch);
-			if (i < start)
-				x1 += cw;
+				cw = charWidth(ch);
+				if (i < start)
+					x1 += cw;
 
-			x2 += cw;
-		}
+				x2 += cw;
+			}
 
-		// render text mark background
-		if (x1 != x2)
-		{
-			start = x1;
-			const int32_t length = x2 - x1;
+			// render text mark background
+			if (x1 != x2)
+			{
+				start = x1;
+				const int32_t length = x2 - x1;
 
-			assert(start+length <= t->renderBufW);
+				assert(start+length <= t->renderBufW);
 
-			uint8_t *ptr32 = &t->renderBuf[start];
-			for (uint16_t y = 0; y < t->renderBufH; y++, ptr32 += t->renderBufW)
-				memset(ptr32, PAL_TEXTMRK, length);
+				uint8_t *ptr32 = &t->renderBuf[start];
+				for (uint16_t y = 0; y < t->renderBufH; y++, ptr32 += t->renderBufW)
+					memset(ptr32, PAL_TEXTMRK, length);
+			}
 		}
 	}