Skip to content

Commit

Permalink
add optional true-color attribute (using DM_SETTRUECOLOR message) for…
Browse files Browse the repository at this point in the history
… all controls and refactor related code
  • Loading branch information
elfmz committed Jul 23, 2023
1 parent 652157e commit 53ba7d9
Show file tree
Hide file tree
Showing 11 changed files with 208 additions and 104 deletions.
6 changes: 5 additions & 1 deletion HACKING.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,12 @@ Can be used to interract with plugin that renders other panel.
far2l asks plugin if it can exit now. If plugin has some background tasks pending it may block exiting of far2l, however it highly recommended to give user choice using UI prompt.

### Added following dialog messages:
* `DM_SETREADONLY` - changes readonly-ness of selected dialog edit control item
* `DM_GETCOLOR` - retrieves current color attributes of selected dialog item
* `DM_SETCOLOR` - changes current color attributes of selected dialog item
* `DM_SETREADONLY` - changes readonly-ness of selected dialog edit control item
* `DM_SETTRUECOLOR` - sets 24-bit RGB colors to selected dialog item, can be used within DN_CTLCOLORDLGITEM handler to provide extra coloring.
* `DM_GETTRUECOLOR` - retrieves 24-bit RGB colors of selected dialog item, if they were set before by DM_SETTRUECOLOR.
* `ECTL_ADDTRUECOLOR` - applies coloring to editor like ECTL_ADDCOLOR does but allows to specify 24 RGB color using EditorTrueColor structure.
* `ECTL_GETTRUECOLOR` - retrieves coloring of editor like ECTL_GETCOLOR does but gets 24 RGB color using EditorTrueColor structure.

Note that all true-colore capable messages still contains 'base' 16 paletter colors support. This is done intentionally as far2l may run in terminal that doesn't support true color palette, and in such case 24bit colors will be ignored and base palette attributes will be used instead.
54 changes: 27 additions & 27 deletions colorer/src/pcolorer2/FarEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -626,11 +626,11 @@ int FarEditor::editorEvent(int event, void *param)
bool vertCrossDone = false;

if (drawSyntax){
for (; l1; l1 = l1->next){
if (l1->special){
continue;
}
if (l1->start == l1->end){
for (; l1; l1 = l1->next){
if (l1->special){
continue;
}
if (l1->start == l1->end){
continue;
}
if (l1->start > ei.LeftPos+ei.WindowSizeX){
Expand Down Expand Up @@ -1310,28 +1310,28 @@ void FarEditor::addFARColor(int lno, int s, int e, color col)
ec.Base.StringNumber = lno;
ec.Base.StartPos = s;
ec.Base.EndPos = e-1;
if (col.fg || col.bk) {
ec.TrueFore.R = ((col.fg >> 16) & 0xFF);
ec.TrueFore.G = ((col.fg >> 8) & 0xFF);
ec.TrueFore.B = ((col.fg) & 0xFF);
ec.TrueFore.Flags = 1;
ec.TrueBack.R = ((col.bk >> 16) & 0xFF);
ec.TrueBack.G = ((col.bk >> 8) & 0xFF);
ec.TrueBack.B = ((col.bk) & 0xFF);
ec.TrueBack.Flags = 1;

if (ec.TrueFore.R > 0x10) ec.Base.Color|= FOREGROUND_RED;
if (ec.TrueFore.G > 0x10) ec.Base.Color|= FOREGROUND_GREEN;
if (ec.TrueFore.B > 0x10) ec.Base.Color|= FOREGROUND_BLUE;

if (ec.TrueBack.R > 0x10) ec.Base.Color|= BACKGROUND_RED;
if (ec.TrueBack.G > 0x10) ec.Base.Color|= BACKGROUND_GREEN;
if (ec.TrueBack.B > 0x10) ec.Base.Color|= BACKGROUND_BLUE;

if (ec.TrueFore.R > 0x80 || ec.TrueFore.G > 0x80 || ec.TrueFore.B > 0x80) {
if (col.fg || col.bk) {
ec.TrueColor.Fore.R = ((col.fg >> 16) & 0xFF);
ec.TrueColor.Fore.G = ((col.fg >> 8) & 0xFF);
ec.TrueColor.Fore.B = ((col.fg) & 0xFF);
ec.TrueColor.Fore.Flags = 1;
ec.TrueColor.Back.R = ((col.bk >> 16) & 0xFF);
ec.TrueColor.Back.G = ((col.bk >> 8) & 0xFF);
ec.TrueColor.Back.B = ((col.bk) & 0xFF);
ec.TrueColor.Back.Flags = 1;

if (ec.TrueColor.Fore.R > 0x10) ec.Base.Color|= FOREGROUND_RED;
if (ec.TrueColor.Fore.G > 0x10) ec.Base.Color|= FOREGROUND_GREEN;
if (ec.TrueColor.Fore.B > 0x10) ec.Base.Color|= FOREGROUND_BLUE;

if (ec.TrueColor.Back.R > 0x10) ec.Base.Color|= BACKGROUND_RED;
if (ec.TrueColor.Back.G > 0x10) ec.Base.Color|= BACKGROUND_GREEN;
if (ec.TrueColor.Back.B > 0x10) ec.Base.Color|= BACKGROUND_BLUE;

if (ec.TrueColor.Fore.R > 0x80 || ec.TrueColor.Fore.G > 0x80 || ec.TrueColor.Fore.B > 0x80) {
ec.Base.Color = FOREGROUND_INTENSITY;
}
if (ec.Base.Color == 0 || ec.TrueBack.R > 0x80 || ec.TrueBack.G > 0x80 || ec.TrueBack.B > 0x80) {
if (ec.Base.Color == 0 || ec.TrueColor.Back.R > 0x80 || ec.TrueColor.Back.G > 0x80 || ec.TrueColor.Back.B > 0x80) {
ec.Base.Color = BACKGROUND_INTENSITY;
}
if (col.style & AI_STYLE_UNDERLINE) {
Expand All @@ -1340,7 +1340,7 @@ void FarEditor::addFARColor(int lno, int s, int e, color col)
if (col.style & AI_STYLE_STRIKEOUT) {
ec.Base.Color|= COMMON_LVB_STRIKEOUT;
}
}
}

#if 0
CLR_TRACE("FarEditor", "line:%d, %d-%d, color:%x", lno, s, e, col);
Expand Down Expand Up @@ -1375,7 +1375,7 @@ void FarEditor::addAnnotation(int lno, int s, int e, AnnotationInfo &ai)
ea.EndPos = e-1;
memcpy(ea.annotation_raw, ai.raw, sizeof(ai.raw));
info->EditorControl(ECTL_ADDANNOTATION, &ea);*/
}
}

const wchar_t *FarEditor::GetMsg(int msg)
{
Expand Down
37 changes: 27 additions & 10 deletions far2l/far2sdk/farplug-wide.h
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,10 @@ enum FarMessagesProc

DM_SETREADONLY,

DM_GETTRUECOLOR, // Param1 - Item ID, Param2 - DialogItemTrueColors *
DM_SETTRUECOLOR, // Param1 - Item ID, Param2 - const DialogItemTrueColors *


DN_FIRST=0x1000,
DN_BTNCLICK,
DN_CTLCOLORDIALOG,
Expand Down Expand Up @@ -1349,6 +1353,28 @@ struct FarSetColors
LPBYTE Colors;
};

struct FarTrueColor
{
unsigned char R;
unsigned char G;
unsigned char B;
unsigned char Flags; // bit one - 'active' flag, others - ignored and must be set to zero
};

struct FarTrueColorForeAndBack
{
struct FarTrueColor Fore;
struct FarTrueColor Back;
};

struct DialogItemTrueColors
{
struct FarTrueColorForeAndBack Normal;
struct FarTrueColorForeAndBack Hilighted;
struct FarTrueColorForeAndBack Frame;
struct FarTrueColorForeAndBack Reserved;
};

enum WINDOWINFO_TYPE
{
#ifdef FAR_USE_INTERNALS
Expand Down Expand Up @@ -1766,19 +1792,10 @@ struct EditorColor
int Color;
};

struct FarTrueColor
{
unsigned char R;
unsigned char G;
unsigned char B;
unsigned char Flags; // bit one - 'active' flag, others - ignored and must be set to zero
};

struct EditorTrueColor
{
struct EditorColor Base;
struct FarTrueColor TrueFore;
struct FarTrueColor TrueBack;
struct FarTrueColorForeAndBack TrueColor;
};

struct EditorSaveFile
Expand Down
51 changes: 49 additions & 2 deletions far2l/src/console/interf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "headers.hpp"

#include <stdarg.h>
#include <VT256ColorTable.h>

#include "interf.hpp"
#include "keyboard.hpp"
Expand Down Expand Up @@ -561,10 +562,10 @@ void VText(const WCHAR *Str)
}
}

void HiText(const wchar_t *Str, int HiColor, int isVertText)
void HiText(const wchar_t *Str, DWORD64 HiColor, int isVertText)
{
FARString strTextStr;
int SaveColor;
DWORD64 SaveColor;
size_t pos;
strTextStr = Str;

Expand Down Expand Up @@ -717,6 +718,52 @@ void SetColor(DWORD64 Color, bool ApplyToConsole)
}
}

void FarTrueColorFromRGB(FarTrueColor &out, DWORD rgb, bool used)
{
out.Flags = used ? 1 : 0;
out.R = rgb & 0xff;
out.G = (rgb >> 8) & 0xff;
out.B = (rgb >> 16) & 0xff;
}

void FarTrueColorFromAttributes(FarTrueColorForeAndBack &TFB, DWORD64 Attrs)
{
FarTrueColorFromRGB(TFB.Fore, (Attrs >> 16) & 0xffffff, (Attrs & FOREGROUND_TRUECOLOR) != 0);
FarTrueColorFromRGB(TFB.Back, (Attrs >> 40) & 0xffffff, (Attrs & BACKGROUND_TRUECOLOR) != 0);
}

void FarTrueColorToAttributes(DWORD64 &Attrs, const FarTrueColorForeAndBack &TFB)
{
if (TFB.Fore.Flags & 1) {
SET_RGB_FORE(Attrs, COMPOSE_RGB(TFB.Fore.R, TFB.Fore.G, TFB.Fore.B));
}
if (TFB.Back.Flags & 1) {
SET_RGB_BACK(Attrs, COMPOSE_RGB(TFB.Back.R, TFB.Back.G, TFB.Back.B));
}
}

void FarTrueColorFromRGB(FarTrueColor &out, DWORD rgb)
{
FarTrueColorFromRGB(out, rgb, rgb != 0);
}

DWORD64 ComposeColor(WORD BaseColor, const FarTrueColorForeAndBack *TFB)
{
DWORD64 Attrs = FarColorToReal(BaseColor);
if (TFB) {
FarTrueColorToAttributes(Attrs, *TFB);
}
return Attrs;
}

void ComposeAndSetColor(WORD BaseColor, const FarTrueColorForeAndBack *TrueColor, bool ApplyToConsole)
{
CurColor = ComposeColor(BaseColor, TrueColor);
if (ApplyToConsole) {
Console.SetTextAttributes(CurColor);
}
}

void SetRealColor(DWORD64 wAttributes, bool ApplyToConsole)
{
CurColor = wAttributes;
Expand Down
8 changes: 7 additions & 1 deletion far2l/src/console/interf.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ void Text(int X, int Y, int Color, const WCHAR *Str);
void Text(const WCHAR *Str, size_t Length = (size_t)-1);
void Text(FarLangMsg MsgId);
void VText(const WCHAR *Str);
void HiText(const WCHAR *Str, int HiColor, int isVertText = 0);
void HiText(const WCHAR *Str, DWORD64 HiColor, int isVertText = 0);
void mprintf(const wchar_t *fmt, ...);
void vmprintf(const wchar_t *fmt, ...);
void PutText(int X1, int Y1, int X2, int Y2, const void *Src);
Expand All @@ -100,6 +100,12 @@ void SetScreen(int X1, int Y1, int X2, int Y2, wchar_t Ch, int Color);
void MakeShadow(int X1, int Y1, int X2, int Y2);
void ChangeBlockColor(int X1, int Y1, int X2, int Y2, int Color);
void SetColor(DWORD64 Color, bool ApplyToConsole = false);
void FarTrueColorFromRGB(FarTrueColor &out, DWORD rgb, bool used);
void FarTrueColorFromRGB(FarTrueColor &out, DWORD rgb);
void FarTrueColorFromAttributes(FarTrueColorForeAndBack &TFB, DWORD64 Attrs);
void FarTrueColorToAttributes(DWORD64 &Attrs, const FarTrueColorForeAndBack &TFB);
DWORD64 ComposeColor(WORD BaseColor, const FarTrueColorForeAndBack *TFB);
void ComposeAndSetColor(WORD BaseColor, const FarTrueColorForeAndBack *TFB, bool ApplyToConsole = false);
void SetRealColor(DWORD64 wAttributes, bool ApplyToConsole = false);
DWORD64 GetRealColor();
void ClearScreen(int Color);
Expand Down

0 comments on commit 53ba7d9

Please sign in to comment.