From 4a050a5c9dc7088649fc498c72fd068e57f81e62 Mon Sep 17 00:00:00 2001 From: Andreas Baumann Date: Sun, 30 Jan 2011 22:48:53 +0100 Subject: - --- src/newt/test1.cpp | 34 ++++++++++++++++++++++++---------- 1 file 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 +#include } 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( "/ between elements | 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; } -- cgit v1.2.3-54-g00ecf