diff --git a/ChangeLog b/ChangeLog index 9c91fa54..407ef531 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2016-12-26 Markus Gans + * Add the ability to stream text into a widget's virtual window + with print() << '#' << 5; or *this << ... + 2016-12-22 Markus Gans * VTerm marks printed characters for a correct determination of unchanged characters diff --git a/src/fvterm.cpp b/src/fvterm.cpp index 59bf447e..4e7c1e3c 100644 --- a/src/fvterm.cpp +++ b/src/fvterm.cpp @@ -403,8 +403,7 @@ void FVTerm::updateTerminalLine (uInt y) print_char->printed = true; // skip character with no changes - if ( ! terminal_update_pending - && print_char->no_changes ) + if ( print_char->no_changes ) { uInt count = 1; diff --git a/src/fvterm.h b/src/fvterm.h index bbdd26d6..8068e4c1 100644 --- a/src/fvterm.h +++ b/src/fvterm.h @@ -27,6 +27,7 @@ #define _FVTERM_H #include "fterm.h" +#include // std::stringstream // class forward declaration class FWidget; @@ -85,6 +86,9 @@ class FVTerm : public FObject, public FTerm // Destructor ~FVTerm(); + // Overloaded operators + template FVTerm& operator << (const type&); + // Accessors virtual const char* getClassName() const; static short getTermForegroundColor(); @@ -218,6 +222,7 @@ class FVTerm : public FObject, public FTerm int print (term_area*, FString&); int print (int); int print (term_area*, int); + FVTerm& print(); static void newFontChanges (char_data*&); static void charsetChanges (char_data*&); static void appendCharacter (char_data*&); @@ -350,6 +355,16 @@ class FVTerm : public FObject, public FTerm #pragma pack(pop) // FVTerm inline functions +//---------------------------------------------------------------------- +template +inline FVTerm& FVTerm::operator << (const type& s) +{ + std::ostringstream outstream; + outstream << s; + print (outstream.str()); + return *this; +} + //---------------------------------------------------------------------- inline const char* FVTerm::getClassName() const { return "FVTerm"; } @@ -672,6 +687,10 @@ inline bool FVTerm::isTransShadow() inline bool FVTerm::isInheritBackground() { return next_attribute.inherit_bg; } +//---------------------------------------------------------------------- +inline FVTerm& FVTerm::print() +{ return *this; } + //---------------------------------------------------------------------- inline void FVTerm::setPrintArea (term_area* area) { print_area = area; } diff --git a/test/keyboard.cpp b/test/keyboard.cpp index d4dc3f83..caa6ce42 100644 --- a/test/keyboard.cpp +++ b/test/keyboard.cpp @@ -39,7 +39,8 @@ void keyboard::onKeyPress (FKeyEvent* ev) if ( getPrintPos().getY() == getLineNumber() ) is_last_line = true; - printf ("Key %s (id %d)\n", getKeyName(key_id).c_str(), key_id); + print() << "Key " << getKeyName(key_id).c_str() + << " (id " << key_id << ")\n"; if ( is_last_line ) scrollAreaForward (vdesktop); @@ -58,9 +59,9 @@ void keyboard::onAccel (FAccelEvent* ev) void keyboard::draw() { setPrintPos (1,1); - print ("---------------\n"); - print ("Press Q to quit\n"); - print ("---------------\n"); + print() << "---------------\n" + << "Press Q to quit\n" + << "---------------\n"; setAreaCursor (1, 4, true, vdesktop); } diff --git a/test/timer.cpp b/test/timer.cpp index 064411f3..3dea44d5 100644 --- a/test/timer.cpp +++ b/test/timer.cpp @@ -41,9 +41,9 @@ timer::timer (FWidget* parent) void timer::draw() { setPrintPos (1,1); - print ("---------------\n"); - print ("Press Q to quit\n"); - print ("---------------\n"); + print() << "---------------\n" + << "Press Q to quit\n" + << "---------------\n"; setAreaCursor (1, 4, true, vdesktop); } @@ -57,7 +57,7 @@ void timer::onTimer (FTimerEvent* ev) is_last_line = true; setColor (short(1 + timer_id), fc::Default); - printf ("timer event, id %d\n", timer_id ); + print() << "Timer event, id " << timer_id << '\n'; if ( is_last_line ) scrollAreaForward (vdesktop);