소스 검색

text-freetype2: Add chat line count property

Allows the ability to choose the number of chat lines when using the
"Chat log mode" feature.

Closes obsproject/obs-studio#1280
Yvo 7 년 전
부모
커밋
43713098d6

+ 2 - 1
plugins/text-freetype2/data/locale/en-US.ini

@@ -3,7 +3,8 @@ Font="Font"
 Text="Text"
 TextFile="Text File (UTF-8 or UTF-16)"
 TextFileFilter="Text Files (*.txt);;"
-ChatLogMode="Chat log mode (last 6 lines)"
+ChatLogMode="Chat log mode"
+ChatLogLines="Chat log lines"
 Color1="Color 1"
 Color2="Color 2"
 Outline="Outline"

+ 10 - 0
plugins/text-freetype2/text-freetype2.c

@@ -136,6 +136,9 @@ static obs_properties_t *ft2_source_properties(void *unused)
 	obs_properties_add_bool(props, "log_mode",
 		obs_module_text("ChatLogMode"));
 
+	obs_properties_add_int(props, "log_lines",
+		obs_module_text("ChatLogLines"), 1, 1000, 1);
+
 	obs_properties_add_path(props,
 		"text_file", obs_module_text("TextFile"),
 		OBS_PATH_FILE, obs_module_text("TextFileFilter"), NULL);
@@ -324,7 +327,12 @@ static void ft2_source_update(void *data, obs_data_t *settings)
 
 	bool from_file = obs_data_get_bool(settings, "from_file");
 	bool chat_log_mode = obs_data_get_bool(settings, "log_mode");
+	uint32_t log_lines = (uint32_t)obs_data_get_int(settings, "log_lines");
 
+	if (srcdata->log_lines != log_lines) {
+		srcdata->log_lines = log_lines;
+		vbuf_needs_update = true;
+	}
 	srcdata->log_mode = chat_log_mode;
 
 	if (ft2_lib == NULL) goto error;
@@ -468,6 +476,8 @@ static void *ft2_source_create(obs_data_t *settings, obs_source_t *source)
 	obs_data_set_default_int(font_obj, "size", 32);
 	obs_data_set_default_obj(settings, "font", font_obj);
 
+	obs_data_set_default_int(settings, "log_lines", 6);
+
 	obs_data_set_default_int(settings, "color1", 0xFFFFFFFF);
 	obs_data_set_default_int(settings, "color2", 0xFFFFFFFF);
 

+ 1 - 0
plugins/text-freetype2/text-freetype2.h

@@ -60,6 +60,7 @@ struct ft2_source {
 	gs_effect_t *draw_effect;
 	bool outline_text, drop_shadow;
 	bool log_mode, word_wrap;
+	uint32_t log_lines;
 
 	obs_source_t *src;
 };

+ 3 - 2
plugins/text-freetype2/text-functionality.c

@@ -404,7 +404,7 @@ void load_text_from_file(struct ft2_source *srcdata, const char *filename)
 void read_from_end(struct ft2_source *srcdata, const char *filename)
 {
 	FILE *tmp_file = NULL;
-	uint32_t filesize = 0, cur_pos = 0;
+	uint32_t filesize = 0, cur_pos = 0, log_lines = 0;
 	char *tmp_read = NULL;
 	uint16_t value = 0, line_breaks = 0;
 	size_t bytes_read;
@@ -428,8 +428,9 @@ void read_from_end(struct ft2_source *srcdata, const char *filename)
 	fseek(tmp_file, 0, SEEK_END);
 	filesize = (uint32_t)ftell(tmp_file);
 	cur_pos = filesize;
+	log_lines = srcdata->log_lines;
 
-	while (line_breaks <= 6 && cur_pos != 0) {
+	while (line_breaks <= log_lines && cur_pos != 0) {
 		if (!utf16) cur_pos--;
 		else cur_pos -= 2;
 		fseek(tmp_file, cur_pos, SEEK_SET);