From 4a697e7c9aff537b1b1d8f6d5f17ba046ec3d3d2 Mon Sep 17 00:00:00 2001 From: Markus Gans Date: Thu, 24 Dec 2015 02:37:01 +0100 Subject: [PATCH] example program to test video attributes --- .gitignore | 1 + ChangeLog | 4 + test/Makefile.am | 3 + test/Makefile.in | 21 ++-- test/term-attributes.cpp | 227 +++++++++++++++++++++++++++++++++++++++ 5 files changed, 250 insertions(+), 6 deletions(-) create mode 100644 test/term-attributes.cpp diff --git a/.gitignore b/.gitignore index 2f1ce971..8e2bedb6 100644 --- a/.gitignore +++ b/.gitignore @@ -29,6 +29,7 @@ test/string-operations test/hello test/watch test/menu +test/term-attributes test/input-dialog test/mandelbrot test/keyboard diff --git a/ChangeLog b/ChangeLog index b48a4dae..b5379777 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2015-12-23 Markus Gans + * Add video attribute support for dim (half-bright) and italic + * An example program to test video attributes on your terminal + 2015-12-20 Markus Gans * Add the possibility to switch off the cursor optimization for bad ANSI-terminal implementations like HyperTerminal diff --git a/test/Makefile.am b/test/Makefile.am index 5bd3e913..855185ec 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -13,6 +13,7 @@ noinst_PROGRAMS = \ mandelbrot \ calculator \ watch \ + term-attributes \ keyboard \ timer \ menu \ @@ -25,7 +26,9 @@ string_operations_SOURCES = string-operations.cpp mandelbrot_SOURCES = mandelbrot.cpp calculator_SOURCES = calculator.cpp watch_SOURCES = watch.cpp +term_attributes_SOURCES = term-attributes.cpp keyboard_SOURCES = keyboard.cpp timer_SOURCES = timer.cpp menu_SOURCES = menu.cpp ui_SOURCES = ui.cpp + diff --git a/test/Makefile.in b/test/Makefile.in index 1cb6d315..49c9789c 100644 --- a/test/Makefile.in +++ b/test/Makefile.in @@ -84,8 +84,8 @@ build_triplet = @build@ host_triplet = @host@ noinst_PROGRAMS = hello$(EXEEXT) dialog$(EXEEXT) input-dialog$(EXEEXT) \ string-operations$(EXEEXT) mandelbrot$(EXEEXT) \ - calculator$(EXEEXT) watch$(EXEEXT) keyboard$(EXEEXT) \ - timer$(EXEEXT) menu$(EXEEXT) ui$(EXEEXT) + calculator$(EXEEXT) watch$(EXEEXT) term-attributes$(EXEEXT) \ + keyboard$(EXEEXT) timer$(EXEEXT) menu$(EXEEXT) ui$(EXEEXT) subdir = test DIST_COMMON = $(srcdir)/Makefile.in $(srcdir)/Makefile.am \ $(top_srcdir)/depcomp @@ -129,6 +129,9 @@ menu_LDADD = $(LDADD) am_string_operations_OBJECTS = string-operations.$(OBJEXT) string_operations_OBJECTS = $(am_string_operations_OBJECTS) string_operations_LDADD = $(LDADD) +am_term_attributes_OBJECTS = term-attributes.$(OBJEXT) +term_attributes_OBJECTS = $(am_term_attributes_OBJECTS) +term_attributes_LDADD = $(LDADD) am_timer_OBJECTS = timer.$(OBJEXT) timer_OBJECTS = $(am_timer_OBJECTS) timer_LDADD = $(LDADD) @@ -175,13 +178,13 @@ am__v_CXXLD_1 = SOURCES = $(calculator_SOURCES) $(dialog_SOURCES) $(hello_SOURCES) \ $(input_dialog_SOURCES) $(keyboard_SOURCES) \ $(mandelbrot_SOURCES) $(menu_SOURCES) \ - $(string_operations_SOURCES) $(timer_SOURCES) $(ui_SOURCES) \ - $(watch_SOURCES) + $(string_operations_SOURCES) $(term_attributes_SOURCES) \ + $(timer_SOURCES) $(ui_SOURCES) $(watch_SOURCES) DIST_SOURCES = $(calculator_SOURCES) $(dialog_SOURCES) \ $(hello_SOURCES) $(input_dialog_SOURCES) $(keyboard_SOURCES) \ $(mandelbrot_SOURCES) $(menu_SOURCES) \ - $(string_operations_SOURCES) $(timer_SOURCES) $(ui_SOURCES) \ - $(watch_SOURCES) + $(string_operations_SOURCES) $(term_attributes_SOURCES) \ + $(timer_SOURCES) $(ui_SOURCES) $(watch_SOURCES) am__can_run_installinfo = \ case $$AM_UPDATE_INFO_DIR in \ n|no|NO) false;; \ @@ -337,6 +340,7 @@ string_operations_SOURCES = string-operations.cpp mandelbrot_SOURCES = mandelbrot.cpp calculator_SOURCES = calculator.cpp watch_SOURCES = watch.cpp +term_attributes_SOURCES = term-attributes.cpp keyboard_SOURCES = keyboard.cpp timer_SOURCES = timer.cpp menu_SOURCES = menu.cpp @@ -417,6 +421,10 @@ string-operations$(EXEEXT): $(string_operations_OBJECTS) $(string_operations_DEP @rm -f string-operations$(EXEEXT) $(AM_V_CXXLD)$(CXXLINK) $(string_operations_OBJECTS) $(string_operations_LDADD) $(LIBS) +term-attributes$(EXEEXT): $(term_attributes_OBJECTS) $(term_attributes_DEPENDENCIES) $(EXTRA_term_attributes_DEPENDENCIES) + @rm -f term-attributes$(EXEEXT) + $(AM_V_CXXLD)$(CXXLINK) $(term_attributes_OBJECTS) $(term_attributes_LDADD) $(LIBS) + timer$(EXEEXT): $(timer_OBJECTS) $(timer_DEPENDENCIES) $(EXTRA_timer_DEPENDENCIES) @rm -f timer$(EXEEXT) $(AM_V_CXXLD)$(CXXLINK) $(timer_OBJECTS) $(timer_LDADD) $(LIBS) @@ -443,6 +451,7 @@ distclean-compile: @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/mandelbrot.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/menu.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/string-operations.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/term-attributes.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/timer.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ui.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/watch.Po@am__quote@ diff --git a/test/term-attributes.cpp b/test/term-attributes.cpp new file mode 100644 index 00000000..43d8247b --- /dev/null +++ b/test/term-attributes.cpp @@ -0,0 +1,227 @@ +// File: term-attributes.cpp + +#include "fapp.h" +#include "fdialog.h" +#include "fmessagebox.h" + +//---------------------------------------------------------------------- +// class AttribDlg +//---------------------------------------------------------------------- + +#pragma pack(push) +#pragma pack(1) + +class AttribDlg : public FDialog +{ + private: + void adjustSize(); + + public: + explicit AttribDlg (FWidget* = 0); // constructor + ~AttribDlg(); // destructor + void onAccel (FAccelEvent*); + void onClose (FCloseEvent*); +}; +#pragma pack(pop) + +//---------------------------------------------------------------------- +AttribDlg::AttribDlg (FWidget* parent) + : FDialog(parent) +{ + setText ("A terminal attributes test"); +} + +//---------------------------------------------------------------------- +AttribDlg::~AttribDlg() +{ } + +//---------------------------------------------------------------------- +void AttribDlg::onAccel (FAccelEvent* ev) +{ + close(); + ev->accept(); +} + +//---------------------------------------------------------------------- +void AttribDlg::onClose (FCloseEvent* ev) +{ + int ret = FMessageBox::info ( this, "Quit" + , "Do you really want\n" + "to quit the program ?" + , FMessageBox::Yes + , FMessageBox::No ); + if ( ret == FMessageBox::Yes ) + ev->accept(); + else + ev->ignore(); +} + +//---------------------------------------------------------------------- +void AttribDlg::adjustSize() +{ + int h = parentWidget()->getHeight() - 2; + int x = ((parentWidget()->getWidth() - getWidth()) / 2 ); + setGeometry(x, 2, 62, h, false); + FDialog::adjustSize(); +} + + +//---------------------------------------------------------------------- +// class AttribDemo +//---------------------------------------------------------------------- + +#pragma pack(push) +#pragma pack(1) + +class AttribDemo : public FWidget +{ + private: + int colors; + + private: + void printColorLine(); + void draw(); + + public: + explicit AttribDemo (FWidget* parent = 0) // constructor + : FWidget(parent) + , colors(getMaxColor()) + { + if ( isMonochron() ) + colors = 1; + else if ( colors > 16 ) + colors = 16; + } + + ~AttribDemo() // destructor + { } +}; +#pragma pack(pop) + +//---------------------------------------------------------------------- +void AttribDemo::printColorLine() +{ + int bg = getTermBackgroundColor(); + for (int color=0; color < colors; color++) + { + setColor(color, bg); + print (" # "); + } +} + +//---------------------------------------------------------------------- +void AttribDemo::draw() +{ + setUpdateVTerm(false); + int color_loop = 0; + std::vector background; + std::vector::iterator iter; + background.push_back(fc::White); + background.push_back(fc::Black); + background.push_back(-1); + iter = background.begin(); + + while ( iter != background.end() ) + { + for (int y=color_loop*7; y < parentWidget()->getHeight()-3; y++) + { + if ( *iter == -1 ) + break; + else if ( *iter == fc::Black ) + { + if ( colors < 16 ) + setColor(fc::LightGray, fc::Black); + else + setColor(fc::White, fc::Black); + } + else + setColor(fc::Black, *iter); + + gotoxy ( xpos + xmin - 1, + ypos + ymin - 1 + y ); + + switch (y - (color_loop*7)) + { + case 0: + print(" Dim: "); + setDim(); + printColorLine(); + unsetDim(); + break; + + case 1: + print(" Normal: "); + printColorLine(); + break; + + case 2: + print(" Bold: "); + setBold(); + printColorLine(); + unsetBold(); + break; + + case 3: + print(" Bold+Dim: "); + setBold(); + setDim(); + printColorLine(); + unsetDim(); + unsetBold(); + break; + + case 4: + print(" Italic: "); + setItalic(); + printColorLine(); + unsetItalic(); + break; + + case 5: + print(" Underline: "); + setUnderline(); + printColorLine(); + unsetUnderline(); + break; + + case 6: + print(" Reverse: "); + setReverse(); + printColorLine(); + unsetReverse(); + break; + } + } + color_loop++; + ++iter; + } + + setUpdateVTerm(true); +} + +//---------------------------------------------------------------------- +// main part +//---------------------------------------------------------------------- +int main (int argc, char* argv[]) +{ + // Create the application object + FApplication app (argc, argv); + + // Create a dialog box object. + // This object will be automatically deleted by + // the parent object "app" (FObject destructor). + AttribDlg* dialog = new AttribDlg(&app); + + dialog->setGeometry (6, 2, 62, 22); + dialog->addAccelerator('q'); // press 'q' to quit + dialog->setShadow(); + + AttribDemo* demo = new AttribDemo(dialog); + demo->ignorePadding(false); + demo->setGeometry (1,1,63,20); + + app.setMainWidget(dialog); + dialog->show(); + + return app.exec(); +}