From 1f8d16791a7fddae69bd62161acfc6b16f58dcdc Mon Sep 17 00:00:00 2001 From: Markus Gans Date: Sat, 3 Nov 2018 01:32:51 +0100 Subject: [PATCH] New method rgb2ColorIndex() to converts a 24-bit RGB color to a 256-color compatible approximation --- ChangeLog | 4 ++++ README.md | 2 +- doc/faq.md | 4 ++-- doc/first-steps.md | 8 ++++---- src/fvterm.cpp | 14 ++++++++++++++ src/include/final/fvterm.h | 1 + 6 files changed, 26 insertions(+), 7 deletions(-) diff --git a/ChangeLog b/ChangeLog index 403ccae7..afd69b0d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2018-11-03 Markus Gans + * New method rgb2ColorIndex() to converts a 24-bit RGB color + to a 256-color compatible approximation + 2018-11-01 Markus Gans * Moved FTerm debug access methods to FTermDebugData diff --git a/README.md b/README.md index 762234a7..2e804149 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@      [![documented](https://codedocs.xyz/gansm/finalcut.svg)](https://codedocs.xyz/gansm/finalcut/hierarchy.html) The FINAL CUT is a C++ class library and widget toolkit with full mouse support for creating a [text-based user interface](https://en.wikipedia.org/wiki/Text-based_user_interface). The library supports the programmer to develop an application for the text console. It allows the simultaneous handling of multiple text windows on the screen. -The C++ class design was inspired by the Qt framework. It provides common controls like dialog boxes, push buttons, check boxes, radio buttons, input lines, list boxes, status bars and so on. +The structure of the Qt framework was originally the inspiration for the C++ class design of FINAL CUT. It provides common controls like dialog boxes, push buttons, check boxes, radio buttons, input lines, list boxes, status bars and so on. ### Installation ```bash diff --git a/doc/faq.md b/doc/faq.md index 9ebc3626..b288744a 100644 --- a/doc/faq.md +++ b/doc/faq.md @@ -87,8 +87,8 @@ How can I fix display problems? * Make sure that the environment variable TERM has the right terminal name. -* With the command "`msgcat --color=test`" you can test whether - the colors are displayed correctly in the terminal +* Use the command "`msgcat --color=test`" to test whether the terminal + displays colors correctly in the terminal. * If characters are not displayed in the right place on the screen, it may help to disable cursor optimization for your program with diff --git a/doc/first-steps.md b/doc/first-steps.md index e3870ba7..b84fcfaa 100644 --- a/doc/first-steps.md +++ b/doc/first-steps.md @@ -72,7 +72,7 @@ The title bar of the dialog box gets the text "A dialog". dialog.setGeometry (25, 5, 30, 10); ``` The dialog window gets a width of 30 and a height of 10 characters. -The window in the terminal is located at the positions x=25 and +The position of the window in the terminal is at x=25 and y=5 (note: x=1 and y=1 represents the upper left corner). ```cpp @@ -93,7 +93,7 @@ if available) visible. return app.exec(); ``` The last line calls `exec()` to start the application and return -the result to the operating system. When the application starts, -it enters the main event loop. This loop doesn't end until the -window/application is closed. +the result to the operating system. The started application enters +the main event loop. This loop does not end until the window is +not closed. diff --git a/src/fvterm.cpp b/src/fvterm.cpp index e75beb9b..943674ec 100644 --- a/src/fvterm.cpp +++ b/src/fvterm.cpp @@ -163,6 +163,20 @@ void FVTerm::setPrintCursor (int x, int y) } } +//---------------------------------------------------------------------- +short FVTerm::rgb2ColorIndex (short r, short g, short b) +{ + // Converts a 24-bit RGB color to a 256-color compatible approximation + + if ( r < 0 || g < 0 || b < 0 || r > 0xff || g > 0xff || b > 0xff ) + return 0; + + short ri = (((r * 5) + 127) / 255) * 36; + short gi = (((g * 5) + 127) / 255) * 6; + short bi = (((b * 5) + 127) / 255); + return 16 + ri + gi + bi; +} + //---------------------------------------------------------------------- void FVTerm::clearArea (int fillchar) { diff --git a/src/include/final/fvterm.h b/src/include/final/fvterm.h index f31af555..33f1f62c 100644 --- a/src/include/final/fvterm.h +++ b/src/include/final/fvterm.h @@ -153,6 +153,7 @@ class FVTerm void showCursor(); void setPrintCursor (const FPoint&); void setPrintCursor (int, int); + short rgb2ColorIndex (short, short, short); void setColor (short, short); static void setNormal();