diff options
author | Andreas Baumann <abaumann@yahoo.com> | 2011-01-30 22:48:53 +0100 |
---|---|---|
committer | Andreas Baumann <abaumann@yahoo.com> | 2011-01-30 22:48:53 +0100 |
commit | 4a050a5c9dc7088649fc498c72fd068e57f81e62 (patch) | |
tree | 4421d63ab46cb6ec95ec13d6d451e5840da64db2 | |
parent | f23bf6acb325ee5ac901e5f9719b59ebe988588d (diff) | |
download | tvisiontest-4a050a5c9dc7088649fc498c72fd068e57f81e62.tar.gz tvisiontest-4a050a5c9dc7088649fc498c72fd068e57f81e62.tar.bz2 |
-
-rw-r--r-- | src/newt/test1.cpp | 34 |
1 files changed, 24 insertions, 10 deletions
diff --git a/src/newt/test1.cpp b/src/newt/test1.cpp index cbaa2ec..b130a87 100644 --- a/src/newt/test1.cpp +++ b/src/newt/test1.cpp @@ -2,6 +2,7 @@ extern "C" { #include <newt.h> +#include <cstdio> } using namespace std; @@ -14,7 +15,7 @@ int main( void ) // impressum on root window newtDrawRootText( 0, 0, "SMERP newt client" ); - newtDrawRootText( 75, 0, "(C)2011" ); + newtDrawRootText( 70, 0, "(C)2011" ); // context sensitive help text newtPushHelpLine( "<Tab>/<Shift-Tab> between elements | <Space> selects" ); @@ -22,11 +23,20 @@ int main( void ) // a window containing our form newtOpenWindow( 10, 3, 60, 18, "form1" ); + // a spinner to indicate network activity + const char *spinner = "-\\|/"; + const char *spinState = spinner; + char spinBuffer[3]; + newtDrawRootText( -1, 0, "*" ); + // construct the components of the form and the form itself newtComponent form, label1, inputline1, label2, inputline2, ok, cancel; form = newtForm( NULL, NULL, 0 ); + + newtFormSetTimer( form, 1000 ); + label1 = newtLabel( 2, 1, "First name:" ); const char *str1 = ""; inputline1 = newtEntry( 20, 1, str1, 20, NULL, @@ -39,16 +49,17 @@ int main( void ) cancel = newtCompactButton( 20, 12, "Cancel" ); newtFormAddComponents( form, label1, inputline1, label2, inputline2, ok, cancel, NULL ); - // set timeout - newtFormSetTimer( form, 10000 ); - // run the form + // run the form up to exit states struct newtExitStruct result; - newtFormRun( form, &result ); - - // cleanup - newtPopWindow( ); - newtFinished( ); + do { + newtFormRun( form, &result ); + if( result.reason == newtExitStruct::NEWT_EXIT_TIMER ) { + if( !*spinState ) spinState = spinner; + sprintf( spinBuffer, "%c", *spinState ); + newtDrawRootText( -1, 0, spinBuffer ); + } + } while( result.reason == newtExitStruct::NEWT_EXIT_TIMER ); switch( result.reason ) { case newtExitStruct::NEWT_EXIT_COMPONENT: @@ -67,12 +78,15 @@ int main( void ) case newtExitStruct::NEWT_EXIT_FDREADY: cout << "FDREADY(" << result.u.watch << ")" << endl; break; + case newtExitStruct::NEWT_EXIT_TIMER: - cout << "TIMER" << endl; break; } + // cleanup newtFormDestroy( form ); + newtPopWindow( ); + newtFinished( ); return 0; } |