Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ Template for new versions:
## New Features

## Fixes
- a safety check was added to ``Screen::doSetTile_char`` fur out of bound pen color values
- ``TextArea`` widget corrected to use ``COLOR_BLACK`` instead of ``COLOR_RESET`` as default background color

## Misc Improvements

Expand Down
3 changes: 3 additions & 0 deletions docs/dev/Lua API.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3754,6 +3754,9 @@ environment by the mandatory init file dfhack.lua:
``COLOR_GREY`` and ``COLOR_DARKGREY`` can also be spelled ``COLOR_GRAY`` and
``COLOR_DARKGRAY``.

Note: ``COLOR_RESET`` is not valid in a `Pen <lua-screen-pen>`, and using it in a Pen color field
will result in runtime warnings and may result in color flashing or other unexpected results.

* State change event codes, used by ``dfhack.onStateChange``

Available only in the `core context <lua-core-context>`, as is the event itself:
Expand Down
2 changes: 1 addition & 1 deletion library/lua/gui/widgets/text_area/text_area_content.lua
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ function TextAreaContent:init()
self.cursor = nil

self.main_pen = dfhack.pen.parse({
bg=COLOR_RESET,
bg=COLOR_BLACK,
bold=true
}, self.text_pen)

Expand Down
19 changes: 11 additions & 8 deletions library/modules/Screen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ distribution.
#include "df/renderer.h"
#include "df/plant.h"

#include <algorithm>
#include <span>
#include <string>
#include <vector>
#include <map>
Expand Down Expand Up @@ -209,14 +211,15 @@ static bool doSetTile_char(const Pen &pen, int x, int y, bool use_graphics)
*texpos_lower = df::global::init->texpos_border_interior; // basic black background
}

auto rgb_fg = &gps->uccolor[fg][0];
auto rgb_bg = &gps->uccolor[bg][0];
screen[1] = rgb_fg[0];
screen[2] = rgb_fg[1];
screen[3] = rgb_fg[2];
screen[4] = rgb_bg[0];
screen[5] = rgb_bg[1];
screen[6] = rgb_bg[2];
if (fg >= 0 && fg <= COLOR_MAX)
std::ranges::copy(gps->uccolor[fg], &screen[1]);
else
WARN(screen).print("in doSetTile_char, fg {} out of range\n", fg);

if (bg >= 0 && bg <= COLOR_MAX)
std::ranges::copy(gps->uccolor[bg], &screen[4]);
else
WARN(screen).print("in doSetTile_char, bg {} out of range\n", bg);

return true;
}
Expand Down
Loading