From 8414effc04aea76036f6be595649e82e4ab7a1ad Mon Sep 17 00:00:00 2001 From: Alexander Batalov Date: Wed, 19 Jul 2023 12:01:20 +0300 Subject: [PATCH] Fix GNW color indexes --- src/window_manager.cc | 20 ++++++++++---------- src/window_manager_private.cc | 5 ++--- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/src/window_manager.cc b/src/window_manager.cc index e0f170a..ba460c0 100644 --- a/src/window_manager.cc +++ b/src/window_manager.cc @@ -549,9 +549,9 @@ void windowDrawText(int win, const char* str, int width, int x, int y, int color } } - if (color & 0xFF00) { - int t = (color & 0xFF00) >> 8; - textColor = (color & ~0xFFFF) | _colorTable[_GNW_wcolor[t]]; + if ((color & 0xFF00) != 0) { + int colorIndex = (color & 0xFF) - 1; + textColor = (color & ~0xFFFF) | _colorTable[_GNW_wcolor[colorIndex]]; } else { textColor = color; } @@ -582,9 +582,9 @@ void windowDrawLine(int win, int left, int top, int right, int bottom, int color return; } - if (color & 0xFF00) { - int t = (color & 0xFF00) >> 8; - color = (color & ~0xFFFF) | _colorTable[_GNW_wcolor[t]]; + if ((color & 0xFF00) != 0) { + int colorIndex = (color & 0xFF) - 1; + color = (color & ~0xFFFF) | _colorTable[_GNW_wcolor[colorIndex]]; } bufferDrawLine(window->buffer, window->width, left, top, right, bottom, color); @@ -604,8 +604,8 @@ void windowDrawRect(int win, int left, int top, int right, int bottom, int color } if ((color & 0xFF00) != 0) { - int v1 = (color & 0xFF00) >> 8; - color = (color & ~0xFFFF) | _colorTable[_GNW_wcolor[v1]]; + int colorIndex = (color & 0xFF) - 1; + color = (color & ~0xFFFF) | _colorTable[_GNW_wcolor[colorIndex]]; } if (right < left) { @@ -643,8 +643,8 @@ void windowFill(int win, int x, int y, int width, int height, int color) color = _colorTable[_GNW_wcolor[0]] & 0xFF; } } else if ((color & 0xFF00) != 0) { - int v1 = (color & 0xFF00) >> 8; - color = (color & ~0xFFFF) | _colorTable[_GNW_wcolor[v1]]; + int colorIndex = (color & 0xFF) - 1; + color = (color & ~0xFFFF) | _colorTable[_GNW_wcolor[colorIndex]]; } if (color < 256) { diff --git a/src/window_manager_private.cc b/src/window_manager_private.cc index af94de7..bd0b3ff 100644 --- a/src/window_manager_private.cc +++ b/src/window_manager_private.cc @@ -645,9 +645,8 @@ int _win_msg(const char* string, int x, int y, int color) int textColor; if ((color & 0xFF00) != 0) { - int index = (color & 0xFF) - 1; - textColor = _colorTable[_GNW_wcolor[index]]; - textColor |= color & ~0xFFFF; + int colorIndex = (color & 0xFF) - 1; + textColor = (color & ~0xFFFF) | _colorTable[_GNW_wcolor[colorIndex]]; } else { textColor = color; }