Printing FStyle object to change attributes

This commit is contained in:
Markus Gans 2020-02-16 00:01:36 +01:00
parent 43bda37f71
commit a33a9e1b6b
20 changed files with 463 additions and 89 deletions

View File

@ -1,3 +1,6 @@
2020-02-16 Markus Gans <guru.mail@muenster.de>
* Printing a FStyle object allows you to change video attributes
2020-02-13 Markus Gans <guru.mail@muenster.de>
* Rename setTransShadow() to setColorOverlay()

View File

@ -23,8 +23,10 @@
#include <final/final.h>
namespace fc = finalcut::fc;
using finalcut::FColorPair;
using finalcut::FPoint;
using finalcut::FSize;
using finalcut::FStyle;
//----------------------------------------------------------------------
@ -90,37 +92,31 @@ void Transparent::draw()
if ( type == shadow )
{
const auto& wc = getFWidgetColors();
setColor(wc.shadow_bg, wc.shadow_fg);
setColorOverlay();
print() << FColorPair (wc.shadow_bg, wc.shadow_fg)
<< FStyle (fc::ColorOverlay);
}
else if ( type == inherit_background )
{
if ( getMaxColor() > 8 )
setColor(fc::Blue, fc::Black);
print() << FColorPair (fc::Blue, fc::Black);
else
setColor(fc::Green, fc::Black);
print() << FColorPair (fc::Green, fc::Black);
setInheritBackground();
print() << FStyle (fc::InheritBackground);
}
else
setTransparent();
print() << FStyle (fc::Transparent);
const finalcut::FString line(getClientWidth(), '.');
// Fill window area
for (int n{1}; n <= int(getClientHeight()); n++)
{
print() << FPoint(2, 2 + n) << line;
print() << FPoint(2, 2 + n)
<< line;
}
if ( type == shadow )
unsetColorOverlay();
else if ( type == inherit_background )
unsetInheritBackground();
else
unsetTransparent();
if ( isMonochron() )
setReverse(false);
print() << FStyle (fc::Reset);
}
//----------------------------------------------------------------------

View File

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

View File

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

View File

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

View File

@ -40,7 +40,7 @@ FOptiAttr::FOptiAttr()
// Set bits that must not be reset
reset_byte_mask.attr.bit.transparent = true;
reset_byte_mask.attr.bit.color_overlay = true;
reset_byte_mask.attr.bit.inherit_bg = true;
reset_byte_mask.attr.bit.inherit_background = true;
reset_byte_mask.attr.bit.no_changes = true;
reset_byte_mask.attr.bit.printed = true;
}

View File

@ -26,6 +26,7 @@
#include "final/fc.h"
#include "final/fcolorpair.h"
#include "final/fstring.h"
#include "final/fstyle.h"
#include "final/ftermbuffer.h"
#include "final/fvterm.h"
#include "final/ftypes.h"
@ -85,6 +86,43 @@ int FTermBuffer::write (wchar_t ch)
return 1;
}
//----------------------------------------------------------------------
void FTermBuffer::write (const FStyle& style)
{
FAttribute attr = style.getStyle();
if ( attr == 0 )
FVTerm::setNormal();
else if ( (attr & fc::Bold) != 0 )
FVTerm::setBold();
else if ( (attr & fc::Dim) != 0 )
FVTerm::setDim();
else if ( (attr & fc::Italic) != 0 )
FVTerm::setItalic();
else if ( (attr & fc::Underline) != 0 )
FVTerm::setUnderline();
else if ( (attr & fc::Blink) != 0 )
FVTerm::setBlink();
else if ( (attr & fc::Reverse) != 0 )
FVTerm::setReverse();
else if ( (attr & fc::Standout) != 0 )
FVTerm::setStandout();
else if ( (attr & fc::Invisible) != 0 )
FVTerm::setInvisible();
else if ( (attr & fc::Protected) != 0 )
FVTerm::setProtected();
else if ( (attr & fc::CrossedOut) != 0 )
FVTerm::setCrossedOut();
else if ( (attr & fc::DoubleUnderline) != 0 )
FVTerm::setDoubleUnderline();
else if ( (attr & fc::Transparent) != 0 )
FVTerm::setTransparent();
else if ( (attr & fc::ColorOverlay) != 0 )
FVTerm::setColorOverlay();
else if ( (attr & fc::InheritBackground) != 0 )
FVTerm::setInheritBackground();
}
//----------------------------------------------------------------------
void FTermBuffer::write (const FColorPair& pair)
{

View File

@ -3,7 +3,7 @@
* *
* This file is part of the Final Cut widget toolkit *
* *
* Copyright 2019 Markus Gans *
* Copyright 2019-2020 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 *
@ -35,10 +35,10 @@ FTermData* FTermDebugData::data {nullptr};
FTermDetection* FTermDebugData::term_detection {nullptr};
//----------------------------------------------------------------------
// class FClassName
// class FTermDebugData
//----------------------------------------------------------------------
// public methods of FClassName
// public methods of FTermDebugData
//----------------------------------------------------------------------
void FTermDebugData::init()
{

View File

@ -31,6 +31,7 @@
#include "final/fkeyboard.h"
#include "final/foptiattr.h"
#include "final/foptimove.h"
#include "final/fstyle.h"
#include "final/fsystem.h"
#include "final/fterm.h"
#include "final/ftermdata.h"
@ -530,7 +531,7 @@ int FVTerm::print (FTermArea* area, FChar& term_char)
{
if ( ( ! ac->attr.bit.transparent && nc.attr.bit.transparent )
|| ( ! ac->attr.bit.color_overlay && nc.attr.bit.color_overlay )
|| ( ! ac->attr.bit.inherit_bg && nc.attr.bit.inherit_bg ) )
|| ( ! ac->attr.bit.inherit_background && nc.attr.bit.inherit_background ) )
{
// add one transparent character form line
area->changes[ay].trans_count++;
@ -538,7 +539,7 @@ int FVTerm::print (FTermArea* area, FChar& term_char)
if ( ( ac->attr.bit.transparent && ! nc.attr.bit.transparent )
|| ( ac->attr.bit.color_overlay && ! nc.attr.bit.color_overlay )
|| ( ac->attr.bit.inherit_bg && ! nc.attr.bit.inherit_bg ) )
|| ( ac->attr.bit.inherit_background && ! nc.attr.bit.inherit_background ) )
{
// remove one transparent character from line
area->changes[ay].trans_count--;
@ -583,6 +584,43 @@ void FVTerm::print (const FPoint& p)
setPrintCursor (p);
}
//----------------------------------------------------------------------
void FVTerm::print (const FStyle& style)
{
FAttribute attr = style.getStyle();
if ( attr == 0 )
setNormal();
else if ( (attr & fc::Bold) != 0 )
setBold();
else if ( (attr & fc::Dim) != 0 )
setDim();
else if ( (attr & fc::Italic) != 0 )
setItalic();
else if ( (attr & fc::Underline) != 0 )
setUnderline();
else if ( (attr & fc::Blink) != 0 )
setBlink();
else if ( (attr & fc::Reverse) != 0 )
setReverse();
else if ( (attr & fc::Standout) != 0 )
setStandout();
else if ( (attr & fc::Invisible) != 0 )
setInvisible();
else if ( (attr & fc::Protected) != 0 )
setProtected();
else if ( (attr & fc::CrossedOut) != 0 )
setCrossedOut();
else if ( (attr & fc::DoubleUnderline) != 0 )
setDoubleUnderline();
else if ( (attr & fc::Transparent) != 0 )
setTransparent();
else if ( (attr & fc::ColorOverlay) != 0 )
setColorOverlay();
else if ( (attr & fc::InheritBackground) != 0 )
setInheritBackground();
}
//----------------------------------------------------------------------
void FVTerm::print (const FColorPair& pair)
{
@ -1232,7 +1270,7 @@ void FVTerm::clearArea (FTermArea* area, int fillchar)
if ( nc.attr.bit.transparent
|| nc.attr.bit.color_overlay
|| nc.attr.bit.inherit_bg )
|| nc.attr.bit.inherit_background )
area->changes[i].trans_count = w;
else if ( area->right_shadow != 0 )
area->changes[i].trans_count = uInt(area->right_shadow);
@ -1593,7 +1631,7 @@ bool FVTerm::updateVTermCharacter ( FTermArea* area
{
updateShadedCharacter (area, area_pos, terminal_pos);
}
else if ( ac->attr.bit.inherit_bg )
else if ( ac->attr.bit.inherit_background )
{
updateInheritBackground (area, area_pos, terminal_pos);
}
@ -1758,7 +1796,7 @@ FChar FVTerm::generateCharacter (const FPoint& pos)
sc = &s_ch;
}
else if ( tmp->attr.bit.inherit_bg )
else if ( tmp->attr.bit.inherit_background )
{
// Add the covered background to this character
std::memcpy (&i_ch, tmp, sizeof(i_ch));
@ -1988,7 +2026,7 @@ void FVTerm::putAreaCharacter ( const FPoint& pos, FVTerm* obj
std::memcpy (tc, &ch, sizeof(*tc));
}
else if ( ac->attr.bit.inherit_bg )
else if ( ac->attr.bit.inherit_background )
{
// Add the covered background to this character
FChar ch{};
@ -2026,7 +2064,7 @@ void FVTerm::getAreaCharacter ( const FPoint& pos, FTermArea* area
s_ch.attr.bit.standout = false;
cc = &s_ch;
}
else if ( tmp->attr.bit.inherit_bg )
else if ( tmp->attr.bit.inherit_background )
{
// Add the covered background to this character
std::memcpy (&i_ch, tmp, sizeof(i_ch));

View File

@ -20,6 +20,8 @@
* <http://www.gnu.org/licenses/>. *
***********************************************************************/
#include "final/fcolorpair.h"
#include "final/fstyle.h"
#include "final/fwidget.h"
#include "final/fwidgetcolors.h"
@ -152,26 +154,26 @@ void drawTransparentShadow (FWidget* w)
const std::size_t width = w->getWidth();
const std::size_t height = w->getHeight();
w->setTransparent();
w->print() << FPoint(int(width) + 1, 1) << " ";
w->unsetTransparent();
w->setColor (w->wcolors.shadow_bg, w->wcolors.shadow_fg);
w->setColorOverlay();
w->print() << FStyle (fc::Transparent)
<< FPoint (int(width) + 1, 1)
<< " "
<< FStyle (fc::Reset)
<< FColorPair (w->wcolors.shadow_bg, w->wcolors.shadow_fg)
<< FStyle (fc::ColorOverlay);
for (std::size_t y{1}; y < height; y++)
{
w->print() << FPoint(int(width) + 1, int(y) + 1) << " ";
}
w->unsetColorOverlay();
w->setTransparent();
w->print() << FPoint(1, int(height) + 1) << " ";
w->unsetTransparent();
w->setColor (w->wcolors.shadow_bg, w->wcolors.shadow_fg);
w->setColorOverlay();
w->print() << FString(width, L' ');
w->unsetColorOverlay();
w->print() << FStyle (fc::Transparent)
<< FPoint (1, int(height) + 1)
<< " "
<< FStyle (fc::Reset)
<< FColorPair (w->wcolors.shadow_bg, w->wcolors.shadow_fg)
<< FStyle (fc::ColorOverlay)
<< FString (width, L' ')
<< FStyle (fc::Reset);
if ( w->isMonochron() )
w->setReverse(false);
@ -191,31 +193,32 @@ void drawBlockShadow (FWidget* w)
if ( w->isWindowWidget() )
{
w->setColor (w->wcolors.shadow_fg, w->wcolors.shadow_bg);
w->setInheritBackground(); // current background color will be ignored
w->print() << FColorPair (w->wcolors.shadow_fg, w->wcolors.shadow_bg)
<< FStyle (fc::InheritBackground); // current background color will be ignored
}
else if ( auto p = w->getParentWidget() )
w->setColor (w->wcolors.shadow_fg, p->getBackgroundColor());
w->print() << FColorPair (w->wcolors.shadow_fg, p->getBackgroundColor());
w->print (fc::LowerHalfBlock); // ▄
if ( w->isWindowWidget() )
w->unsetInheritBackground();
w->print() << FStyle (fc::InheritBackground);
for (std::size_t y{1}; y < height; y++)
{
w->print() << FPoint(int(width) + 1, int(y) + 1) << fc::FullBlock; // █
w->print() << FPoint(int(width) + 1, int(y) + 1)
<< fc::FullBlock; // █
}
w->print() << FPoint(2, int(height) + 1);
if ( w->isWindowWidget() )
w->setInheritBackground();
w->print() << FStyle (fc::InheritBackground);
w->print() << FString(width, fc::UpperHalfBlock); // ▀
if ( w->isWindowWidget() )
w->unsetInheritBackground();
w->print() << FStyle (fc::Reset);
}
//----------------------------------------------------------------------
@ -229,17 +232,18 @@ void clearShadow (FWidget* w)
if ( w->isWindowWidget() )
{
w->setColor (w->wcolors.shadow_fg, w->wcolors.shadow_bg);
w->setInheritBackground(); // current background color will be ignored
w->print() << FColorPair (w->wcolors.shadow_fg, w->wcolors.shadow_bg)
<< FStyle (fc::InheritBackground); // current background color will be ignored
}
else if ( auto p = w->getParentWidget() )
w->setColor (w->wcolors.shadow_fg, p->getBackgroundColor());
w->print() << FColorPair (w->wcolors.shadow_fg, p->getBackgroundColor());
if ( int(width) <= w->woffset.getX2() )
{
for (std::size_t y{1}; y <= height; y++)
{
w->print() << FPoint(int(width) + 1, int(y)) << ' '; // clear █
w->print() << FPoint(int(width) + 1, int(y))
<< ' '; // clear █
}
}
@ -250,7 +254,7 @@ void clearShadow (FWidget* w)
}
if ( w->isWindowWidget() )
w->unsetInheritBackground();
w->print() << FStyle (fc::Reset);
}
//----------------------------------------------------------------------

View File

@ -3,7 +3,7 @@
* *
* This file is part of the Final Cut widget toolkit *
* *
* Copyright 2015-2019 Markus Gans *
* Copyright 2015-2020 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 *
@ -936,6 +936,26 @@ enum colornames : FColor
Default = static_cast<FColor>(-1)
};
// Console style names
enum stylenames : FAttribute
{
Reset = 0,
Bold = 1,
Dim = 2,
Italic = 4,
Underline = 8,
Blink = 16,
Reverse = 32,
Standout = 64,
Invisible = 128,
Protected = 256,
CrossedOut = 512,
DoubleUnderline = 1024,
Transparent = 2048,
ColorOverlay = 4096,
InheritBackground = 8192
};
// Mouse/keyboard state values
enum ButtonState
{

View File

@ -3,7 +3,7 @@
* *
* This file is part of the Final Cut widget toolkit *
* *
* Copyright 2019 Markus Gans *
* Copyright 2019-2020 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 *
@ -24,7 +24,7 @@
*
*
*
* FClassName
* FColorPair
*
*/
@ -116,5 +116,3 @@ class FColorPair
} // namespace finalcut
#endif // FCOLORPAIR_H

View File

@ -4,7 +4,7 @@
* *
* This file is part of the Final Cut widget toolkit *
* *
* Copyright 2014-2019 Markus Gans *
* Copyright 2014-2020 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 *
@ -68,6 +68,7 @@
#include <final/fstartoptions.h>
#include <final/fstatusbar.h>
#include <final/fstring.h>
#include <final/fstyle.h>
#include <final/fswitch.h>
#include <final/fsystem.h>
#include <final/fterm.h>

View File

@ -0,0 +1,93 @@
/***********************************************************************
* fstyle.h - Style attribute of a character *
* *
* This file is part of the Final Cut widget toolkit *
* *
* Copyright 2020 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
*
*
*
* FStyle
*
*/
#ifndef FSTYLE_H
#define FSTYLE_H
#if !defined (USE_FINAL_H) && !defined (COMPILE_FINAL_CUT)
#error "Only <final/final.h> can be included directly."
#endif
#include "final/fc.h"
#include "final/fstring.h"
#include "final/ftypes.h"
namespace finalcut
{
//----------------------------------------------------------------------
// class FStyle
//----------------------------------------------------------------------
class FStyle
{
public:
// Constructors
explicit FStyle (FAttribute attr = fc::Reset)
: attribute{attr}
{ }
// Copy constructor
FStyle (const FStyle& style)
: attribute{style.attribute}
{ }
// Destructor
~FStyle() = default;
// Assignment operator (=)
FStyle& operator = (const FStyle& style)
{
attribute = style.attribute;
return *this;
}
// Accessor
const FString getClassName() const
{ return "FStyle"; }
FColor getStyle() const
{ return attribute; }
// Mutators
void setStyle (const FStyle& style)
{ attribute = style.attribute; }
void setStyle (FAttribute attr)
{ attribute = attr; }
private:
// Data members
FAttribute attribute; // Save character attributes
};
} // namespace finalcut
#endif // FSTYLE_H

View File

@ -3,7 +3,7 @@
* *
* This file is part of the Final Cut widget toolkit *
* *
* Copyright 2017-2019 Markus Gans *
* Copyright 2017-2020 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 *
@ -44,6 +44,7 @@ namespace finalcut
{
// class forward declaration
class FStyle;
class FColorPair;
//----------------------------------------------------------------------
@ -72,6 +73,7 @@ class FTermBuffer
FTermBuffer& operator << (const FCharVector&);
FTermBuffer& operator << (const std::string&);
FTermBuffer& operator << (const std::wstring&);
FTermBuffer& operator << (const FStyle&);
FTermBuffer& operator << (const FColorPair&);
// Accessors
@ -95,6 +97,7 @@ class FTermBuffer
int writef (const FString&, Args&&...);
int write (const FString&);
int write (wchar_t);
void write (const FStyle&);
void write (const FColorPair&);
FTermBuffer& write ();
@ -149,6 +152,13 @@ inline FTermBuffer& FTermBuffer::operator << (const std::wstring& wstring)
return *this;
}
//----------------------------------------------------------------------
inline FTermBuffer& FTermBuffer::operator << (const FStyle& style)
{
write (style);
return *this;
}
//----------------------------------------------------------------------
inline FTermBuffer& FTermBuffer::operator << (const FColorPair& pair)
{

View File

@ -3,7 +3,7 @@
* *
* This file is part of the Final Cut widget toolkit *
* *
* Copyright 2017-2019 Markus Gans *
* Copyright 2017-2020 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 *
@ -59,6 +59,7 @@ typedef std::int64_t sInt64;
typedef long double lDouble;
typedef uInt16 FColor;
typedef uInt16 FAttribute;
typedef uInt32 FKey;
typedef void* FDataPtr;
@ -134,7 +135,7 @@ typedef struct
uInt8 pc_charset : 1; // pc character set (CP437)
uInt8 transparent : 1; // transparent
uInt8 color_overlay : 1; // color overlay
uInt8 inherit_bg : 1; // inherit background
uInt8 inherit_background : 1; // inherit background
// Attribute byte #2
uInt8 no_changes : 1; // no changes required
uInt8 printed : 1; // is printed to VTerm

View File

@ -77,6 +77,7 @@ class FSystem;
class FTerm;
class FTermBuffer;
class FTermDebugData;
class FStyle;
class FWidget;
//----------------------------------------------------------------------
@ -141,6 +142,7 @@ class FVTerm
FVTerm& operator << (const FTermBuffer&);
FVTerm& operator << (const std::vector<FChar>&);
FVTerm& operator << (const FPoint&);
FVTerm& operator << (const FStyle&);
FVTerm& operator << (const FColorPair&);
// Accessors
@ -305,6 +307,7 @@ class FVTerm
int print (FChar&);
int print (FTermArea*, FChar&);
virtual void print (const FPoint&);
virtual void print (const FStyle&);
virtual void print (const FColorPair&);
virtual FVTerm& print();
static void flush();
@ -579,6 +582,13 @@ inline FVTerm& FVTerm::operator << (const FPoint& pos)
return *this;
}
//----------------------------------------------------------------------
inline FVTerm& FVTerm::operator << (const FStyle& t_style)
{
print (t_style);
return *this;
}
//----------------------------------------------------------------------
inline FVTerm& FVTerm::operator << (const FColorPair& pair)
{
@ -851,7 +861,7 @@ inline bool FVTerm::unsetColorOverlay()
//----------------------------------------------------------------------
inline bool FVTerm::setInheritBackground (bool enable)
{ return (next_attribute.attr.bit.inherit_bg = enable); }
{ return (next_attribute.attr.bit.inherit_background = enable); }
//----------------------------------------------------------------------
inline bool FVTerm::setInheritBackground()
@ -943,7 +953,7 @@ inline bool FVTerm::isTransShadow()
//----------------------------------------------------------------------
inline bool FVTerm::isInheritBackground()
{ return next_attribute.attr.bit.inherit_bg; }
{ return next_attribute.attr.bit.inherit_background; }
//----------------------------------------------------------------------
inline bool FVTerm::isMonochron()

View File

@ -19,6 +19,7 @@ noinst_PROGRAMS = \
foptimove_test \
foptiattr_test \
fcolorpair_test \
fstyle_test \
fstring_test \
fsize_test \
fpoint_test \
@ -36,6 +37,7 @@ ftermfreebsd_test_SOURCES = ftermfreebsd-test.cpp
foptimove_test_SOURCES = foptimove-test.cpp
foptiattr_test_SOURCES = foptiattr-test.cpp
fcolorpair_test_SOURCES = fcolorpair-test.cpp
fstyle_test_SOURCES = fstyle-test.cpp
fstring_test_SOURCES = fstring-test.cpp
fsize_test_SOURCES = fsize-test.cpp
fpoint_test_SOURCES = fpoint-test.cpp
@ -53,6 +55,7 @@ TESTS = fobject_test \
foptimove_test \
foptiattr_test \
fcolorpair_test \
fstyle_test \
fstring_test \
fsize_test \
fpoint_test \

View File

@ -3,7 +3,7 @@
* *
* This file is part of the Final Cut widget toolkit *
* *
* Copyright 2019 Markus Gans *
* Copyright 2019-2020 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 *

156
test/fstyle-test.cpp Normal file
View File

@ -0,0 +1,156 @@
/***********************************************************************
* fstyle-test.cpp - FStyle 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 FStyleTest
//----------------------------------------------------------------------
class FStyleTest : public CPPUNIT_NS::TestFixture
{
public:
FStyleTest()
{ }
protected:
void classNameTest();
void noArgumentTest();
void copyConstructorTest();
void assignmentTest();
void setColorTest();
void swapTest();
private:
// Adds code needed to register the test suite
CPPUNIT_TEST_SUITE (FStyleTest);
// Add a methods to the test suite
CPPUNIT_TEST (classNameTest);
CPPUNIT_TEST (noArgumentTest);
CPPUNIT_TEST (copyConstructorTest);
CPPUNIT_TEST (assignmentTest);
CPPUNIT_TEST (setColorTest);
// End of test suite definition
CPPUNIT_TEST_SUITE_END();
};
//----------------------------------------------------------------------
void FStyleTest::classNameTest()
{
const finalcut::FStyle s;
const finalcut::FString& classname = s.getClassName();
CPPUNIT_ASSERT ( classname == "FStyle" );
}
//----------------------------------------------------------------------
void FStyleTest::noArgumentTest()
{
const finalcut::FStyle style{};
CPPUNIT_ASSERT ( style.getStyle() == finalcut::fc::Reset );
}
//----------------------------------------------------------------------
void FStyleTest::copyConstructorTest()
{
const finalcut::FStyle style1a;
CPPUNIT_ASSERT ( style1a.getStyle() == finalcut::fc::Reset );
finalcut::FStyle style1b (style1a);
CPPUNIT_ASSERT ( style1b.getStyle() == finalcut::fc::Reset );
const finalcut::FStyle style2a (finalcut::fc::Bold );
CPPUNIT_ASSERT ( style2a.getStyle() == finalcut::fc::Bold );
const finalcut::FStyle style2b (style2a);
CPPUNIT_ASSERT ( style2b.getStyle() == finalcut::fc::Bold );
const finalcut::FStyle style3a (finalcut::fc::Bold + finalcut::fc::Dim);
CPPUNIT_ASSERT ( style3a.getStyle() == (finalcut::fc::Bold | finalcut::fc::Dim) );
const finalcut::FStyle style3b (style3a);
CPPUNIT_ASSERT ( style3b.getStyle() == (finalcut::fc::Bold | finalcut::fc::Dim) );
}
//----------------------------------------------------------------------
void FStyleTest::assignmentTest()
{
const finalcut::FStyle style1a;
const finalcut::FStyle style1b = style1a;
CPPUNIT_ASSERT ( style1b.getStyle() == finalcut::fc::Reset );
const finalcut::FStyle style2a (finalcut::fc::Italic );
const finalcut::FStyle style2b = style2a;
CPPUNIT_ASSERT ( style2b.getStyle() == finalcut::fc::Italic );
const finalcut::FStyle style3a (finalcut::fc::Underline | finalcut::fc::Blink);
const finalcut::FStyle style3b = style3a;
CPPUNIT_ASSERT ( style3b.getStyle() == (finalcut::fc::Underline + finalcut::fc::Blink) );
finalcut::FStyle style4 = finalcut::FStyle();
CPPUNIT_ASSERT ( style4.getStyle() == finalcut::fc::Reset );
style4 = finalcut::FStyle(finalcut::fc::Bold | finalcut::fc::Dim);
CPPUNIT_ASSERT ( style4.getStyle() == (finalcut::fc::Bold | finalcut::fc::Dim) );
}
//----------------------------------------------------------------------
void FStyleTest::setColorTest()
{
finalcut::FStyle style1;
style1.setStyle (finalcut::fc::Reverse);
CPPUNIT_ASSERT ( style1.getStyle() == finalcut::fc::Reverse );
finalcut::FStyle style2 (finalcut::fc::Reverse);
style2.setStyle (finalcut::fc::Standout);
CPPUNIT_ASSERT ( style2.getStyle() == finalcut::fc::Standout );
finalcut::FStyle style3 (finalcut::fc::Protected | finalcut::fc::CrossedOut);
style3.setStyle (finalcut::fc::Invisible);
CPPUNIT_ASSERT ( style3.getStyle() == finalcut::fc::Invisible );
finalcut::FStyle style4 (finalcut::fc::DoubleUnderline);
style3.setStyle (style4);
CPPUNIT_ASSERT ( style3.getStyle() == finalcut::fc::DoubleUnderline );
finalcut::FStyle style5 (finalcut::fc::Transparent);
CPPUNIT_ASSERT ( style5.getStyle() == finalcut::fc::Transparent );
style5.setStyle (finalcut::fc::Reset);
CPPUNIT_ASSERT ( style5.getStyle() == finalcut::fc::Reset );
style5.setStyle (finalcut::fc::ColorOverlay);
CPPUNIT_ASSERT ( style5.getStyle() == finalcut::fc::ColorOverlay );
style5.setStyle (finalcut::fc::InheritBackground);
CPPUNIT_ASSERT ( style5.getStyle() == finalcut::fc::InheritBackground );
}
// Put the test suite in the registry
CPPUNIT_TEST_SUITE_REGISTRATION (FStyleTest);
// The general unit test main part
#include <main-test.inc>