Patches #1932

darkplaces:terencehill/color_code_editing: a S merge request: Console edit line: make the color code visible when the cursor is inside...

Added by git-manager 5 months ago. Updated 2 months ago.

Status:NewStart date:03/17/2014
Priority:NormalDue date:
Assignee:divVerent% Done:

0%

Category:-
Target version:-

Description

Console edit line: make the color code visible when the cursor is inside it and r_font_disable_freetype is 0

Repository: xonotic/darkplaces.git
Commit: c0c7f7241bb474a3965645a28255f92314d8d4df
Branch: terencehill/color_code_editing

Merge commands:

cd darkplaces
git checkout master
git reset --hard origin/master
git pull && git diff 'c0c7f7241bb474a3965645a28255f92314d8d4df'..'origin/terencehill/color_code_editing'

# please check that the diff you just saw did not contain anything complex that
# needs a new merge request, and review these changes

git reset --hard 'origin/terencehill/color_code_editing'
git rebase -i --onto origin/master origin/master

# please make sure that this rebase did not cause any conflicts; if it did, fix
# them and repeatedly use git rebase --continue till the rebase is complete
#
# also, THIS is the point to do final pre-merge testing
#
# use git rebase --abort; git reset --hard 'origin/terencehill/color_code_editing' to bail out

git svn dcommit --add-author-from && git push --delete origin 'terencehill/color_code_editing'

Diffstat:

 console.c |   34 ++++++++++++++++++++++++++++++++++
 1 files changed, 34 insertions(+), 0 deletions(-)

Revision log:

commit c0c7f7241bb474a3965645a28255f92314d8d4df
Author: terencehill <piuntn@gmail.com>
Commit: terencehill <piuntn@gmail.com>

    Console edit line: make the color code visible when the cursor is inside it and r_font_disable_freetype is 0

    Signed-off-by: terencehill <piuntn@gmail.com>

User agreed to the license.

Diff:

diff --git a/console.c b/console.c
index 1bf3790..c1e6e96 100644
--- a/console.c
+++ b/console.c
@@ -1561,6 +1561,40 @@ static void Con_DrawInput (void)

 //    text[key_linepos + 1] = 0;

+    // make the color code visible when the cursor is inside it
+    if(!r_font_disable_freetype.integer)
+    if(text[key_linepos] != 0)
+    {
+        for(i=1; i < 5 && key_linepos - i > 0; ++i)
+            if(text[key_linepos-i] == STRING_COLOR_TAG)
+            {
+                int caret_pos, carets, ofs;
+                caret_pos = key_linepos - i;
+                if(i == 1 && text[caret_pos+1] == STRING_COLOR_TAG)
+                    ofs = 1;
+                else if(i == 1 && isdigit(text[caret_pos+1]))
+                    ofs = 2;
+                else if(text[caret_pos+1] == STRING_COLOR_RGB_TAG_CHAR && isxdigit(text[caret_pos+2]) && isxdigit(text[caret_pos+3]) && isxdigit(text[caret_pos+4]))
+                    ofs = 5;
+                if(ofs && y + ofs + 1 < (int)sizeof(editlinecopy) - 1)
+                {
+                    carets = 1;
+                    while(caret_pos - carets >= 1 && text[caret_pos - carets] == STRING_COLOR_TAG)
+                        ++carets;
+                    if(carets & 1)
+                    {
+                        // str^2ing (displayed as string) --> str^2^^2ing (displayed as str^2ing)
+                        // str^^ing (displayed as str^ing) --> str^^^^ing (displayed as str^^ing)
+                        memmove(&text[caret_pos + ofs + 1], &text[caret_pos], y - caret_pos);
+                        text[caret_pos + ofs] = STRING_COLOR_TAG;
+                        y += ofs + 1;
+                        text[y] = 0;
+                    }
+                }
+                break;
+            }
+    }
+
     len_out = key_linepos;
     col_out = -1;
     xo = DrawQ_TextWidth_UntilWidth_TrackColors(text, &len_out, con_textsize.value, con_textsize.value, &col_out, false, FONT_CONSOLE, 1000000000);

History

#1 Updated by terencehill 5 months ago

  • Assignee set to divVerent

I also suggest another easy change, I can add it to this branch if it's wanted.

Currently when r_font_disable_freetype is 1 the cursor is drawn by replacing the character under it with the cursor char directly in the edit line, but this system has these drawbacks:
  • the text after the cursor is shown alternatively with a slightly different offset (due to the cursor char being slightly larger)
  • in the middle of a color code, the color code is shown one out of two times for half a second in a very unpleasant manner

I suggest to use the system used when r_font_disable_freetype is 0, that is, put the cursor on top of the edit line even when r_font_disable_freetype is 1, since it doesn't suffer of the above described issues. It also simplifies a lot Con_DrawInput code.

#2 Updated by terencehill 5 months ago

Branch updated with the change I suggested, ready to be merged

#3 Updated by Mario 2 months ago

Been using this for a month, it works well.

Also available in: Atom PDF