Skip to content

TextAreaContent: remove COLOR_RESET uses with Pen - #5874

Open
ChrisJohnsen wants to merge 1 commit into
DFHack:developfrom
ChrisJohnsen:cj/TextAreaContent-COLOR_RESET
Open

TextAreaContent: remove COLOR_RESET uses with Pen#5874
ChrisJohnsen wants to merge 1 commit into
DFHack:developfrom
ChrisJohnsen:cj/TextAreaContent-COLOR_RESET

Conversation

@ChrisJohnsen

Copy link
Copy Markdown
Contributor

Ref: #5864

There are a couple of Pen uses of COLOR_RESET remaining in TextAreaContent. Both are used as background colors in onRenderBody and neither is normally used to draw anything.


The first use of COLOR_RESET had a slight change in 17c1dc0, but nothing significant with respect to how COLOR_RESET was being used.

This use looks to be intended to "restore" the Painter's Pen state. This "restored" Pen is never actually used anywhere though:

  • The following debug code sets its own colors.
  • The Painter passed (here, as dc) to onRenderBody would be reused and passed to subviews' onRenderFrame (see View:render()), but TextAreaContent has no subviews.

(In general, I don't think widgets/views should assume anything about the Pen state of the Painter they are given (unless they are highly coupled).)

Suggestion: Remove the "restore" adjustment.


The second use of COLOR_RESET seems to be unchanged since it was introduced.

This use of COLOR_RESET only happens when self.debug is enabled (it doesn't seem to be enabled in any normal situation). The value of the debug field is inherited from its parent TextArea at initialization time. TextArea's debug defaults to false and doesn't seem to be set by any other Lua code. Setting debug=true in the TextArea of (e.g.) gui/journal is a quick way to see this debug code activated.

Suggestion: Simplify to just specifying a foreground color. The default background color (black) will be used. It probably doesn't really matter much what the background color is (since it is only for debug). This can produce no visible changes unless debug is enabled.

COLOR_RESET should not be used with Pen.

The first use looks like it could be a "restore Pen before ending" kind
of action; but that should be unnecessary.

- The only other drawing done after this in this function is debug-only
  drawing that sets its own colors.
- Any subsequently rendered Views should fully establish their own Pen
  settings before drawing. A view's `onRenderBody`'s Painter (`dc`,
  here) *is* normally reused (primarily for the clipping rectangle?)
  with the subview's `onRenderFrame`, but it would be terribly fragile
  for a subview to rely on the Pen state left by its parent view (or
  earlier-rendered sibling views's frame).
  - TextAreaContent does not have any subviews.

The second use is only used when `self.debug` is active, the background
color is probably unimportant; use Pen's default background color:
black.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant