jrincayc / ucblogo-code

Berkeley Logo interpreter
https://people.eecs.berkeley.edu/~bh/logo.html
GNU General Public License v3.0
182 stars 34 forks source link

Text cursor invisible in editor mode - black on black background #180

Open rmunn opened 7 months ago

rmunn commented 7 months ago

if you type EDIT to get to the built-in editor, the text cursor is black no matter what the text foreground and background colors are set to. With the default white text on black background, that results in an invisible cursor. Changing the text background with SETTEXTCOLOR to something non-black worked, and allowed me to have a visible cursor in EDIT mode, but I'd rather find a permanent solution.

I've looked through the wxWidgets documentation and can't find any way to set the text cursor color (!), so for now in my own copy of UCBLogo I've applied the following patch to change the editor colors to black text on gray background:

--- TextEditor.cpp.orig 2024-01-26 10:05:33.421553166 +0700
+++ TextEditor.cpp  2024-01-26 10:05:40.518482194 +0700
@@ -46,31 +46,31 @@

 void TextEditor::SetFont(wxFont font){
    this->font = font;
-   SetForegroundColour(TurtleCanvas::colors[wxTerminal::terminal->m_curFG]);
-   SetDefaultStyle(wxTextAttr(TurtleCanvas::colors[wxTerminal::terminal->m_curFG],
-                  TurtleCanvas::colors[wxTerminal::terminal->m_curBG], font));
+   SetForegroundColour(TurtleCanvas::colors[SPECIAL_COLORS+0]);
+   SetDefaultStyle(wxTextAttr(TurtleCanvas::colors[SPECIAL_COLORS+0],
+                  TurtleCanvas::colors[SPECIAL_COLORS+15], font));
    if(this->IsShown()){
        SetStyle(0,GetLastPosition(),
-            wxTextAttr(TurtleCanvas::colors[wxTerminal::terminal->m_curFG],
-                   TurtleCanvas::colors[wxTerminal::terminal->m_curBG],font));
+            wxTextAttr(TurtleCanvas::colors[SPECIAL_COLORS+0],
+                   TurtleCanvas::colors[SPECIAL_COLORS+15],font));
     SetBackgroundColour(
-       TurtleCanvas::colors[wxTerminal::terminal->m_curBG]);
+       TurtleCanvas::colors[SPECIAL_COLORS+15]);
        Refresh();
        Update();
    }
 }

 void TextEditor::SetThisFont(wxCommandEvent& event) {
-   SetDefaultStyle(wxTextAttr(TurtleCanvas::colors[wxTerminal::terminal->m_curFG],
-                  TurtleCanvas::colors[wxTerminal::terminal->m_curBG], this->font));
+   SetDefaultStyle(wxTextAttr(TurtleCanvas::colors[SPECIAL_COLORS+0],
+                  TurtleCanvas::colors[SPECIAL_COLORS+15], this->font));
    if(this->IsShown()){
        wxTextPos lastPosition = GetLastPosition();

        SetStyle(lastPosition > 0 ? lastPosition - 1 : 0, lastPosition,
-            wxTextAttr(TurtleCanvas::colors[wxTerminal::terminal->m_curFG],
-                   TurtleCanvas::colors[wxTerminal::terminal->m_curBG],this->font));
+            wxTextAttr(TurtleCanvas::colors[SPECIAL_COLORS+0],
+                   TurtleCanvas::colors[SPECIAL_COLORS+15],this->font));
        SetBackgroundColour(
-           TurtleCanvas::colors[wxTerminal::terminal->m_curBG]);
+           TurtleCanvas::colors[SPECIAL_COLORS+15]);
        Refresh();
        Update();
        Refresh();

That works for what I need it for, but it's less than ideal as a general-purpose as it removes the possibility of customizing the colors in the editor via SETTEXTCOLOR. If anyone knows how to change the color of the blinking text cursor that wxWidgets draws, that would be a better solution to this issue. (Note that https://github.com/jrincayc/ucblogo-code/issues/11 would probably also have been fixed by this and https://github.com/jrincayc/ucblogo-code/pull/12 would have been unnecessary; the cursor was probably invisible because it was being drawn in black against a black background).

rmunn commented 7 months ago

Probably caused by https://github.com/wxWidgets/wxWidgets/issues/18722. My current system has wxWidgets 3.0.5 on it, where that bug exists. I see that https://github.com/wxWidgets/wxWidgets/commit/2197f9d10e8841ab97d919ff6fcde5bb9721c6ce fixes the bug, at least for the wxGTK version (which is what I have), and that commit was incorporated into wxWidgets 3.1.4. So there are probably no code changes needed in UCBLogo, as long as a suitably recent version of wxWidgets is installed.

I'll leave this bug report open until I can confirm that wxWidgets 3.1.4 or later fixes the bug, then I'll close the issue once I'm certain that no change in UCBLogo will be necessary.