Printing FColorPair to change foreground and background color

This commit is contained in:
Markus Gans 2019-01-30 12:17:48 +01:00
parent bd4d8bd3a2
commit d91cd10311
23 changed files with 323 additions and 37 deletions

View File

@ -1,3 +1,7 @@
2019-01-30 Markus Gans <guru.mail@muenster.de>
* Printing an FColorPair object can change the foreground and
background colors
2019-01-27 Markus Gans <guru.mail@muenster.de>
* The print command can now have an FPoint object as a parameter
to set the cursor position

View File

@ -32,6 +32,7 @@
using finalcut::FPoint;
using finalcut::FSize;
using finalcut::FColorPair;
constexpr lDouble PI = 3.141592653589793238L;
@ -333,13 +334,12 @@ void Calc::drawDispay()
if ( error )
display = " Error ";
setColor(finalcut::fc::Black, finalcut::fc::LightGray);
if ( isMonochron() )
setReverse(false);
print() << FPoint(3, 3) << display << ' ';
setColor(wc.dialog_fg, wc.dialog_bg);
print() << FColorPair(finalcut::fc::Black, finalcut::fc::LightGray)
<< FPoint(3, 3) << display << ' '
<< FColorPair(wc.dialog_fg, wc.dialog_bg);
if ( isMonochron() )
setReverse(true);

View File

@ -24,6 +24,7 @@
using finalcut::FPoint;
using finalcut::FSize;
using finalcut::FColorPair;
//----------------------------------------------------------------------
@ -142,9 +143,7 @@ void ColorChooser::draw()
if ( c == bg_color )
{
print (' ');
print (finalcut::fc::Times);
print (' ');
print() << ' ' << finalcut::fc::Times << ' ';
}
else
print (" ");
@ -244,8 +243,8 @@ void Brushes::draw()
int pos;
setColor();
finalcut::FWidget::drawBorder (1, 2, 8, 4);
setColor (fg_color, bg_color);
print() << FPoint(2, 3) << " "
print() << FPoint(2, 3)
<< FColorPair(fg_color, bg_color) << " "
<< finalcut::FString(3, finalcut::fc::MediumShade);
if ( brush == L' ' )

View File

@ -25,6 +25,7 @@
using finalcut::FPoint;
using finalcut::FSize;
using finalcut::FColorPair;
//----------------------------------------------------------------------
@ -260,8 +261,7 @@ void AttribDemo::printColorLine()
for (FColor color = 0; color < colors; color++)
{
setColor (color, parent->bgcolor);
print (" # ");
print() << FColorPair(color, parent->bgcolor) << " # ";
}
}

View File

@ -75,8 +75,8 @@ void Timer::onTimer (finalcut::FTimerEvent* ev)
if ( getPrintPos().getY() == int(getDesktopHeight()) )
is_last_line = true;
setColor (FColor(1 + timer_id), finalcut::fc::Default);
print() << "Timer event, id " << timer_id << '\n';
print() << finalcut::FColorPair (FColor(1 + timer_id))
<< "Timer event, id " << timer_id << '\n';
if ( is_last_line )
scrollAreaForward (vdesktop);

View File

@ -73,6 +73,7 @@ finalcutinclude_HEADERS = \
include/final/fbuttongroup.h \
include/final/fcharmap.h \
include/final/fcheckbox.h \
include/final/fcolorpair.h \
include/final/fconfig.h \
include/final/fswitch.h \
include/final/fdialog.h \

View File

@ -12,6 +12,7 @@ INCLUDE_HEADERS = \
fapplication.h \
fbuttongroup.h \
fbutton.h \
fcolorpair.h \
ftogglebutton.h \
fcheckbox.h \
fswitch.h \

View File

@ -12,6 +12,7 @@ INCLUDE_HEADERS = \
fapplication.h \
fbuttongroup.h \
fbutton.h \
fcolorpair.h \
ftogglebutton.h \
fcheckbox.h \
fswitch.h \

View File

@ -582,8 +582,8 @@ inline void FButton::drawTopBottomBackground()
inline void FButton::drawButtonTextLine (wchar_t button_text[])
{
std::size_t pos;
print() << FPoint(2 + int(indent), 1 + int(vcenter_offset));
setColor (button_fg, button_bg);
print() << FPoint(2 + int(indent), 1 + int(vcenter_offset))
<< FColorPair (button_fg, button_bg);
if ( getWidth() < txtlength + 1 )
center_offset = 0;

View File

@ -583,8 +583,7 @@ void FLabel::printLine ( wchar_t line[]
if ( length > width )
{
// Print ellipsis
setColor (ellipsis_color, getBackgroundColor());
print ("..");
print() << FColorPair(ellipsis_color, getBackgroundColor()) << "..";
setColor();
}
else if ( align_offset + to_char < width )

View File

@ -865,9 +865,8 @@ void FListBox::drawHeadline()
else
{
// Print ellipsis
print (text.left(uInt(getClientWidth() - 2)));
setColor (wc.label_ellipsis_fg, wc.label_bg);
print("..");
print() << text.left(uInt(getClientWidth() - 2))
<< FColorPair (wc.label_ellipsis_fg, wc.label_bg) << "..";
}
}

View File

@ -1849,10 +1849,10 @@ void FListView::drawColumnEllipsis ( const headerItems::const_iterator& iter
static constexpr int ellipsis_length = 2;
int width = iter->width;
headerline << ' ';
headerline << text.left(uInt(width - ellipsis_length));
setColor (wc.label_ellipsis_fg, wc.label_bg);
headerline << "..";
headerline << ' '
<< text.left(uInt(width - ellipsis_length))
<< FColorPair (wc.label_ellipsis_fg, wc.label_bg)
<< "..";
if ( iter == header.end() - 1 ) // Last element
headerline << ' ';

View File

@ -1251,8 +1251,8 @@ void FMenu::drawItems()
//----------------------------------------------------------------------
inline void FMenu::drawSeparator (int y)
{
print() << FPoint(1, 2 + y);
setColor (wc.menu_active_fg, wc.menu_active_bg);
print() << FPoint(1, 2 + y)
<< FColorPair(wc.menu_active_fg, wc.menu_active_bg);
if ( isMonochron() )
setReverse(true);

View File

@ -161,8 +161,8 @@ void FProgressbar::drawProgressLabel()
void FProgressbar::drawProgressBar()
{
std::size_t len = 0;
print() << FPoint(1, 1);
setColor (wc.progressbar_bg, wc.progressbar_fg);
print() << FPoint(1, 1)
<< FColorPair(wc.progressbar_bg, wc.progressbar_fg);
if ( percentage > 0 && percentage <= 100 )
len = drawProgressIndicator();
@ -206,8 +206,8 @@ std::size_t FProgressbar::drawProgressIndicator()
}
else
{
setColor (wc.progressbar_fg, wc.progressbar_bg);
print (fc::LeftHalfBlock); // ▌
print() << FColorPair(wc.progressbar_fg, wc.progressbar_bg)
<< fc::LeftHalfBlock; // ▌
}
len++;

View File

@ -175,8 +175,8 @@ void FSwitch::drawChecked()
if ( isMonochron() || getMaxColor() < 16 )
setBold(false);
setColor (wc.button_inactive_fg, wc.button_inactive_bg);
print (off);
print() << FColorPair(wc.button_inactive_fg, wc.button_inactive_bg)
<< off;
if ( isMonochron() )
setReverse(false);

View File

@ -3,7 +3,7 @@
* *
* This file is part of the Final Cut widget toolkit *
* *
* Copyright 2017-2018 Markus Gans *
* Copyright 2017-2019 Markus Gans *
* *
* The Final Cut is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public License *
@ -81,7 +81,7 @@ int FTermBuffer::write (const FString& s)
}
//----------------------------------------------------------------------
int FTermBuffer::write (int c)
int FTermBuffer::write (wchar_t c)
{
charData nc; // next character
nc = FVTerm::getAttribute();
@ -93,6 +93,15 @@ int FTermBuffer::write (int c)
return 1;
}
//----------------------------------------------------------------------
void FTermBuffer::write (const FColorPair& pair)
{
charData nc; // next character
nc = FVTerm::getAttribute();
nc.fg_color = pair.fg_color;
nc.bg_color = pair.bg_color;
}
// FTermBuffer non-member operators
//----------------------------------------------------------------------

View File

@ -563,6 +563,12 @@ void FVTerm::print (const FPoint& p)
setPrintCursor (p);
}
//----------------------------------------------------------------------
void FVTerm::print (const FColorPair& pair)
{
setColor (pair.fg_color, pair.bg_color);
}
// protected methods of FVTerm
//----------------------------------------------------------------------

View File

@ -300,7 +300,7 @@ bool FWidget::setFocus (bool enable)
}
//----------------------------------------------------------------------
void FWidget::setColor ()
void FWidget::setColor()
{
// Changes colors to the widget default colors
setColor (foreground_color, background_color);

View File

@ -0,0 +1,96 @@
/***********************************************************************
* fcolorpair.h - Foreground and background color of a character *
* *
* This file is part of the Final Cut widget toolkit *
* *
* Copyright 2019 Markus Gans *
* *
* The Final Cut is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public License *
* as published by the Free Software Foundation; either version 3 of *
* the License, or (at your option) any later version. *
* *
* The Final Cut is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU Lesser General Public *
* License along with this program. If not, see *
* <http://www.gnu.org/licenses/>. *
***********************************************************************/
/* Standalone class
*
*
*
* FClassName
*
*/
#ifndef FCOLORPAIR_H
#define FCOLORPAIR_H
#if !defined (USE_FINAL_H) && !defined (COMPILE_FINAL_CUT)
#error "Only <final/final.h> can be included directly."
#endif
//#include ...
namespace finalcut
{
//----------------------------------------------------------------------
// class FColorPair
//----------------------------------------------------------------------
#pragma pack(push)
#pragma pack(1)
class FColorPair
{
public:
// Constructors
FColorPair (FColor fg = fc::Default, FColor bg = fc::Default)
: fg_color(fg)
, bg_color(bg)
{ }
// Copy constructor
FColorPair (const FColorPair& pair)
: fg_color(pair.fg_color)
, bg_color(pair.bg_color)
{ }
// Destructor
~FColorPair() = default;
// Assignment operator (=)
FColorPair& operator = (const FColorPair& pair)
{
fg_color = pair.fg_color;
bg_color = pair.bg_color;
return *this;
}
// Accessor
const char* getClassName() const
{ return "FColorPair"; }
// Methods
void swap()
{
std::swap (fg_color, bg_color);
}
// Data Members
FColor fg_color; // Foreground color
FColor bg_color; // Background color
};
#pragma pack(pop)
} // namespace finalcut
#endif // FCOLORPAIR_H

View File

@ -3,7 +3,7 @@
* *
* This file is part of the Final Cut widget toolkit *
* *
* Copyright 2017-2018 Markus Gans *
* Copyright 2017-2019 Markus Gans *
* *
* The Final Cut is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public License *
@ -67,6 +67,8 @@ class FTermBuffer
// Overloaded operators
template <typename type>
FTermBuffer& operator << (const type&);
FTermBuffer& operator << (const FColorPair&);
// Non-member operators
friend std::vector<charData>& operator << ( std::vector<charData>&
, const FTermBuffer& );
@ -82,7 +84,8 @@ class FTermBuffer
void clear();
int writef (const FString, ...);
int write (const FString&);
int write (int);
int write (wchar_t);
void write (const FColorPair&);
FTermBuffer& write ();
std::vector<charData> getBuffer();
@ -104,6 +107,13 @@ inline FTermBuffer& FTermBuffer::operator << (const type& s)
return *this;
}
//----------------------------------------------------------------------
inline FTermBuffer& FTermBuffer::operator << (const FColorPair& pair)
{
write (pair);
return *this;
}
//----------------------------------------------------------------------
inline const char* FTermBuffer::getClassName() const
{ return "FTermBuffer"; }

View File

@ -58,6 +58,7 @@
#include <vector>
#include "final/fterm.h"
#include "final/fcolorpair.h"
// Preprocessing handler macro
@ -133,6 +134,7 @@ class FVTerm
FVTerm& operator << (const type&);
FVTerm& operator << (const std::vector<charData>&);
FVTerm& operator << (const FPoint&);
FVTerm& operator << (const FColorPair&);
// Accessors
virtual const char* getClassName() const;
@ -296,6 +298,7 @@ class FVTerm
int print (charData&);
int print (term_area*, charData&);
virtual void print (const FPoint&);
virtual void print (const FColorPair&);
virtual FVTerm& print();
static void beep();
static void redefineDefaultColors (bool);
@ -559,6 +562,13 @@ inline FVTerm& FVTerm::operator << (const FPoint& pos)
return *this;
}
//----------------------------------------------------------------------
inline FVTerm& FVTerm::operator << (const FColorPair& pair)
{
print (pair);
return *this;
}
//----------------------------------------------------------------------
inline const char* FVTerm::getClassName() const
{ return "FVTerm"; }

View File

@ -15,6 +15,7 @@ noinst_PROGRAMS = \
ftermcapquirks_test \
foptimove_test \
foptiattr_test \
fcolorpair_test \
fstring_test \
fsize_test \
fpoint_test \
@ -28,6 +29,7 @@ ftermdetection_test_SOURCES = ftermdetection-test.cpp
ftermcapquirks_test_SOURCES = ftermcapquirks-test.cpp
foptimove_test_SOURCES = foptimove-test.cpp
foptiattr_test_SOURCES = foptiattr-test.cpp
fcolorpair_test_SOURCES = fcolorpair-test.cpp
fstring_test_SOURCES = fstring-test.cpp
fsize_test_SOURCES = fsize-test.cpp
fpoint_test_SOURCES = fpoint-test.cpp
@ -41,6 +43,7 @@ TESTS = fobject_test \
ftermcapquirks_test \
foptimove_test \
foptiattr_test \
fcolorpair_test \
fstring_test \
fsize_test \
fpoint_test \

148
test/fcolorpair-test.cpp Normal file
View File

@ -0,0 +1,148 @@
/***********************************************************************
* fcolorpair-test.cpp - FColorPair unit tests *
* *
* This file is part of the Final Cut widget toolkit *
* *
* Copyright 2019 Markus Gans *
* *
* The Final Cut is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public License *
* as published by the Free Software Foundation; either version 3 of *
* the License, or (at your option) any later version. *
* *
* The Final Cut is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU Lesser General Public *
* License along with this program. If not, see *
* <http://www.gnu.org/licenses/>. *
***********************************************************************/
#include <limits>
#include <cppunit/BriefTestProgressListener.h>
#include <cppunit/CompilerOutputter.h>
#include <cppunit/extensions/HelperMacros.h>
#include <cppunit/TestFixture.h>
#include <cppunit/TestResult.h>
#include <cppunit/TestResultCollector.h>
#include <cppunit/TestRunner.h>
#include <final/final.h>
//----------------------------------------------------------------------
// class FColorPairTest
//----------------------------------------------------------------------
#pragma pack(push)
#pragma pack(1)
class FColorPairTest : public CPPUNIT_NS::TestFixture
{
public:
FColorPairTest()
{ }
protected:
void classNameTest();
void noArgumentTest();
void copyConstructorTest();
void assignmentTest();
void swapTest();
private:
// Adds code needed to register the test suite
CPPUNIT_TEST_SUITE (FColorPairTest);
// Add a methods to the test suite
CPPUNIT_TEST (classNameTest);
CPPUNIT_TEST (noArgumentTest);
CPPUNIT_TEST (copyConstructorTest);
CPPUNIT_TEST (assignmentTest);
CPPUNIT_TEST (swapTest);
// End of test suite definition
CPPUNIT_TEST_SUITE_END();
};
#pragma pack(pop)
//----------------------------------------------------------------------
void FColorPairTest::classNameTest()
{
const finalcut::FColorPair p;
const char* const classname = p.getClassName();
CPPUNIT_ASSERT ( std::strcmp(classname, "FColorPair") == 0 );
}
//----------------------------------------------------------------------
void FColorPairTest::noArgumentTest()
{
const finalcut::FColorPair pair{};
CPPUNIT_ASSERT ( pair.fg_color == finalcut::fc::Default );
CPPUNIT_ASSERT ( pair.bg_color == finalcut::fc::Default );
}
//----------------------------------------------------------------------
void FColorPairTest::copyConstructorTest()
{
const finalcut::FColorPair p1a;
finalcut::FColorPair p1b (p1a);
CPPUNIT_ASSERT ( p1b.fg_color == finalcut::fc::Default );
CPPUNIT_ASSERT ( p1b.bg_color == finalcut::fc::Default );
const finalcut::FColorPair p2a (finalcut::fc::Yellow );
const finalcut::FColorPair p2b (p2a);
CPPUNIT_ASSERT ( p2b.fg_color == finalcut::fc::Yellow );
CPPUNIT_ASSERT ( p2b.bg_color == finalcut::fc::Default );
const finalcut::FColorPair p3a (finalcut::fc::Red, finalcut::fc::Black);
const finalcut::FColorPair p3b (p3a);
CPPUNIT_ASSERT ( p3b.fg_color == finalcut::fc::Red );
CPPUNIT_ASSERT ( p3b.bg_color == finalcut::fc::Black );
}
//----------------------------------------------------------------------
void FColorPairTest::assignmentTest()
{
const finalcut::FColorPair p1a;
const finalcut::FColorPair p1b = p1a;
CPPUNIT_ASSERT ( p1b.fg_color == finalcut::fc::Default );
CPPUNIT_ASSERT ( p1b.bg_color == finalcut::fc::Default );
const finalcut::FColorPair p2a (finalcut::fc::Yellow );
const finalcut::FColorPair p2b = p2a;
CPPUNIT_ASSERT ( p2b.fg_color == finalcut::fc::Yellow );
CPPUNIT_ASSERT ( p2b.bg_color == finalcut::fc::Default );
const finalcut::FColorPair p3a (finalcut::fc::Red, finalcut::fc::Black);
const finalcut::FColorPair p3b = p3a;
CPPUNIT_ASSERT ( p3b.fg_color == finalcut::fc::Red );
CPPUNIT_ASSERT ( p3b.bg_color == finalcut::fc::Black );
}
//----------------------------------------------------------------------
void FColorPairTest::swapTest()
{
finalcut::FColorPair p1;
p1.swap();
CPPUNIT_ASSERT ( p1.fg_color == finalcut::fc::Default );
CPPUNIT_ASSERT ( p1.bg_color == finalcut::fc::Default );
finalcut::FColorPair p2 (finalcut::fc::LightBlue );
p2.swap();
CPPUNIT_ASSERT ( p2.fg_color == finalcut::fc::Default );
CPPUNIT_ASSERT ( p2.bg_color == finalcut::fc::LightBlue );
finalcut::FColorPair p3 (finalcut::fc::Cyan, finalcut::fc::White);
p3.swap();
CPPUNIT_ASSERT ( p3.fg_color == finalcut::fc::White );
CPPUNIT_ASSERT ( p3.bg_color == finalcut::fc::Cyan );
}
// Put the test suite in the registry
CPPUNIT_TEST_SUITE_REGISTRATION (FColorPairTest);
// The general unit test main part
#include <main-test.inc>