Add the ability to stream text into a widget's virtual window with print() or *this

This commit is contained in:
Markus Gans 2016-12-26 01:15:32 +01:00
parent f67537fba4
commit 386e91563a
5 changed files with 33 additions and 10 deletions

View File

@ -1,3 +1,7 @@
2016-12-26 Markus Gans <guru.mail@muenster.de>
* Add the ability to stream text into a widget's virtual window
with print() << '#' << 5; or *this << ...
2016-12-22 Markus Gans <guru.mail@muenster.de> 2016-12-22 Markus Gans <guru.mail@muenster.de>
* VTerm marks printed characters for a correct determination * VTerm marks printed characters for a correct determination
of unchanged characters of unchanged characters

View File

@ -403,8 +403,7 @@ void FVTerm::updateTerminalLine (uInt y)
print_char->printed = true; print_char->printed = true;
// skip character with no changes // skip character with no changes
if ( ! terminal_update_pending if ( print_char->no_changes )
&& print_char->no_changes )
{ {
uInt count = 1; uInt count = 1;

View File

@ -27,6 +27,7 @@
#define _FVTERM_H #define _FVTERM_H
#include "fterm.h" #include "fterm.h"
#include <sstream> // std::stringstream
// class forward declaration // class forward declaration
class FWidget; class FWidget;
@ -85,6 +86,9 @@ class FVTerm : public FObject, public FTerm
// Destructor // Destructor
~FVTerm(); ~FVTerm();
// Overloaded operators
template<class type> FVTerm& operator << (const type&);
// Accessors // Accessors
virtual const char* getClassName() const; virtual const char* getClassName() const;
static short getTermForegroundColor(); static short getTermForegroundColor();
@ -218,6 +222,7 @@ class FVTerm : public FObject, public FTerm
int print (term_area*, FString&); int print (term_area*, FString&);
int print (int); int print (int);
int print (term_area*, int); int print (term_area*, int);
FVTerm& print();
static void newFontChanges (char_data*&); static void newFontChanges (char_data*&);
static void charsetChanges (char_data*&); static void charsetChanges (char_data*&);
static void appendCharacter (char_data*&); static void appendCharacter (char_data*&);
@ -350,6 +355,16 @@ class FVTerm : public FObject, public FTerm
#pragma pack(pop) #pragma pack(pop)
// FVTerm inline functions // FVTerm inline functions
//----------------------------------------------------------------------
template<class type>
inline FVTerm& FVTerm::operator << (const type& s)
{
std::ostringstream outstream;
outstream << s;
print (outstream.str());
return *this;
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline const char* FVTerm::getClassName() const inline const char* FVTerm::getClassName() const
{ return "FVTerm"; } { return "FVTerm"; }
@ -672,6 +687,10 @@ inline bool FVTerm::isTransShadow()
inline bool FVTerm::isInheritBackground() inline bool FVTerm::isInheritBackground()
{ return next_attribute.inherit_bg; } { return next_attribute.inherit_bg; }
//----------------------------------------------------------------------
inline FVTerm& FVTerm::print()
{ return *this; }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline void FVTerm::setPrintArea (term_area* area) inline void FVTerm::setPrintArea (term_area* area)
{ print_area = area; } { print_area = area; }

View File

@ -39,7 +39,8 @@ void keyboard::onKeyPress (FKeyEvent* ev)
if ( getPrintPos().getY() == getLineNumber() ) if ( getPrintPos().getY() == getLineNumber() )
is_last_line = true; 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 ) if ( is_last_line )
scrollAreaForward (vdesktop); scrollAreaForward (vdesktop);
@ -58,9 +59,9 @@ void keyboard::onAccel (FAccelEvent* ev)
void keyboard::draw() void keyboard::draw()
{ {
setPrintPos (1,1); setPrintPos (1,1);
print ("---------------\n"); print() << "---------------\n"
print ("Press Q to quit\n"); << "Press Q to quit\n"
print ("---------------\n"); << "---------------\n";
setAreaCursor (1, 4, true, vdesktop); setAreaCursor (1, 4, true, vdesktop);
} }

View File

@ -41,9 +41,9 @@ timer::timer (FWidget* parent)
void timer::draw() void timer::draw()
{ {
setPrintPos (1,1); setPrintPos (1,1);
print ("---------------\n"); print() << "---------------\n"
print ("Press Q to quit\n"); << "Press Q to quit\n"
print ("---------------\n"); << "---------------\n";
setAreaCursor (1, 4, true, vdesktop); setAreaCursor (1, 4, true, vdesktop);
} }
@ -57,7 +57,7 @@ void timer::onTimer (FTimerEvent* ev)
is_last_line = true; is_last_line = true;
setColor (short(1 + timer_id), fc::Default); 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 ) if ( is_last_line )
scrollAreaForward (vdesktop); scrollAreaForward (vdesktop);