From 43713098d6b34eccd0a10ba4e9f1d05a7b717915 Mon Sep 17 00:00:00 2001 From: Yvo Date: Sun, 29 Apr 2018 13:11:26 +0200 Subject: [PATCH] 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 --- plugins/text-freetype2/data/locale/en-US.ini | 3 ++- plugins/text-freetype2/text-freetype2.c | 10 ++++++++++ plugins/text-freetype2/text-freetype2.h | 1 + plugins/text-freetype2/text-functionality.c | 5 +++-- 4 files changed, 16 insertions(+), 3 deletions(-) diff --git a/plugins/text-freetype2/data/locale/en-US.ini b/plugins/text-freetype2/data/locale/en-US.ini index 4a41f6faa..b352775fa 100644 --- a/plugins/text-freetype2/data/locale/en-US.ini +++ b/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" diff --git a/plugins/text-freetype2/text-freetype2.c b/plugins/text-freetype2/text-freetype2.c index 6fd85716c..bd011742d 100644 --- a/plugins/text-freetype2/text-freetype2.c +++ b/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); diff --git a/plugins/text-freetype2/text-freetype2.h b/plugins/text-freetype2/text-freetype2.h index df2dee16c..a3fd49bb7 100644 --- a/plugins/text-freetype2/text-freetype2.h +++ b/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; }; diff --git a/plugins/text-freetype2/text-functionality.c b/plugins/text-freetype2/text-functionality.c index 0755c27a9..36c972126 100644 --- a/plugins/text-freetype2/text-functionality.c +++ b/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);