Exemplo n.º 1
0
BBStr *_bbReadStr(){
	switch( dataPtr->fieldType ){
	case BBTYPE_END:RTEX( "Out of data" );return 0;
	case BBTYPE_INT:return d_new BBStr( itoa( dataPtr++->field.INT ) );
	case BBTYPE_FLT:return d_new BBStr( ftoa( dataPtr++->field.FLT ) );
	case BBTYPE_CSTR:return d_new BBStr( dataPtr++->field.CSTR );
	default:RTEX( "Bad data type" );return 0;
	}
}
Exemplo n.º 2
0
BBStr *bbCurrentTime(){
	time_t t;
	time( &t );
	char buff[256];
	strftime( buff,256,"%H:%M:%S",localtime( &t ) );
	return d_new BBStr( buff );
}
Exemplo n.º 3
0
BBStr *bbCurrentDate(){
	time_t t;
	time( &t );
	char buff[256];
	strftime( buff,256,"%d %b %Y",localtime( &t ) );
	return d_new BBStr( buff );
}
Exemplo n.º 4
0
BBStr *bbBin( int n ){
	char buff[36];
	for( int k=31;k>=0;n>>=1,--k ){
		buff[k]=n&1 ? '1' : '0';
	}
	buff[32]=0;
	return d_new BBStr( buff );
}
Exemplo n.º 5
0
BBStr *bbHex( int n ){
	char buff[12];
	for( int k=7;k>=0;n>>=4,--k ){
		int t=(n&15)+'0';
		buff[k]=t>'9' ? t+='A'-'9'-1 : t;
	}
	buff[8]=0;
	return d_new BBStr( buff );
}
Exemplo n.º 6
0
BBStr *_bbObjToStr( BBObj *obj ){
	if( !obj || !obj->fields ) return d_new BBStr( "[NULL]" );

	static BBObj *root;
	static int recurs_cnt;

	if( obj==root ) return d_new BBStr( "[ROOT]" );
	if( recurs_cnt==8 ) return d_new BBStr( "...." );

	++recurs_cnt;
	BBObj *oldRoot=root;
	if( !root ) root=obj;

	BBObjType *type=obj->type;
	BBField *fields=obj->fields;
	BBStr *s=d_new BBStr("["),*t;
	for( int k=0;k<type->fieldCnt;++k ){
		if( k ) *s+=',';
		switch( type->fieldTypes[k]->type ){
		case BBTYPE_INT:
			t=_bbStrFromInt( fields[k].INT );*s+=*t;delete t;
			break;
		case BBTYPE_FLT:
			t=_bbStrFromFloat( fields[k].FLT );*s+=*t;delete t;
			break;
		case BBTYPE_STR:
			if( fields[k].STR ) *s+='\"'+*fields[k].STR+'\"';
			else *s+="\"\"";
			break;
		case BBTYPE_OBJ:
			t=_bbObjToStr( fields[k].OBJ );*s+=*t;delete t;
			break;
		default:
			*s+="???";
		}
	}
	*s+=']';
	root=oldRoot;
	--recurs_cnt;
	return s;
}
Exemplo n.º 7
0
BBStr *_bbStrConst( const char *s ){
	return d_new BBStr( s );
}
Exemplo n.º 8
0
BBStr *_bbStrFromFloat( float n ){
	return d_new BBStr( ftoa( n ) );
}
Exemplo n.º 9
0
BBStr *_bbStrFromInt( int n ){
	return d_new BBStr( itoa( n ) );
}
Exemplo n.º 10
0
BBStr *_bbStrLoad( BBStr **var ){
	return *var ? d_new BBStr( **var ) : d_new BBStr();
}
Exemplo n.º 11
0
BBStr *bbCurrentDir(){
	return d_new BBStr( gx_filesys->getCurrentDir() );
}
Exemplo n.º 12
0
BBStr *bbNextFile( gxDir *d ){
	debugDir( d );
	return d_new BBStr( d->getNextFile() );
}
Exemplo n.º 13
0
BBStr *bbChr( int n ){
	BBStr *t=d_new BBStr();
	*t+=(char)n;return t;
}
Exemplo n.º 14
0
BBStr *bbString( BBStr *s,int n ){
	BBStr *t=d_new BBStr();
	while( n-->0 ) *t+=*s;
	delete s;return t;
}
Exemplo n.º 15
0
BBStr *	bbGfxDriverName( int n ){
	debugDriver( n );
	string t;int caps;
	gx_runtime->graphicsDriverInfo( n-1,&t,&caps );
	return d_new BBStr( t );
}
Exemplo n.º 16
0
BBStr *bbInput( BBStr *prompt ){
	gxCanvas *c=startPrinting();
	string t=*prompt;delete prompt;

	//get temp canvas
	if( !p_canvas || p_canvas->getWidth()<c->getWidth() || p_canvas->getHeight()<curr_font->getHeight()*2 ){
		if( p_canvas ) gx_graphics->freeCanvas( p_canvas );
		p_canvas=gx_graphics->createCanvas( c->getWidth(),curr_font->getHeight()*2,0 );
		if( !p_canvas ){
			endPrinting(c);
			return d_new BBStr();
		}
	}
	//draw prompt
	c->text( curs_x,curs_y,t );
	curs_x+=curr_font->getWidth( t );

	p_canvas->setFont( curr_font );
	p_canvas->setColor( curr_color );
	p_canvas->blit( 0,0,c,0,curs_y,c->getWidth(),curr_font->getHeight(),true );

	string str;
	bool go=true;
	int curs=0,last_key=0,last_time,rep_delay;

	while( go ){

		//render all text
		//calc curs x and width
		int cx=curs_x+curr_font->getWidth( str.substr( 0,curs ) );
		int cw=curr_font->getWidth( curs<str.size() ? str.substr( curs,1 ) : "X" );

		//wait for a key
		int key=0,st=gx_runtime->getMilliSecs(),tc=-1;

		while( gx_runtime->idle() ){
			int t=gx_runtime->getMilliSecs();
			int n=(t-st)/320;
			if( n!=tc ){
				tc=n;
				if( !(tc&1) ){	//cursor ON
					c->setColor( curr_clsColor^0xffffff );
					c->rect( cx,curs_y,cw,curr_font->getHeight(),true );
					c->setColor( curr_clsColor );
				}else{			//cursor OFF
					c->blit( cx,curs_y,p_canvas,cx,0,cw,curr_font->getHeight(),true );
					c->setColor( curr_color );
				}
				c->text( cx,curs_y,str.substr( curs,1 ) );
			}
			if( key=gx_keyboard->getKey() ){
				if( int asc=gx_input->toAscii( key ) ){
					rep_delay=280;
					last_key=key;
					last_time=t;
					key=asc;
					break;
				}
			}
			if( last_key && gx_keyboard->keyDown( last_key ) ){
				if( t-last_time>rep_delay ){
					if( key=gx_input->toAscii( last_key ) ){
						last_time+=rep_delay;
						rep_delay=40;
						break;
					}
				}
			}else last_key=0;
			gx_runtime->delay( 20 );
		}

		//check the key
		switch( key ){
		case 0:
			go=false;
			str="";
			break;
		case 8:
			if( curs ){
				str=str.substr( 0,curs-1 )+str.substr( curs );
				--curs;
			}
			break;
		case 27:
			curs=0;str="";
			break;
		case gxInput::ASC_DELETE:
			if( curs<str.size() ) str=str.substr( 0,curs )+str.substr( curs+1 );
			break;
		case gxInput::ASC_HOME:
			curs=0;
			break;
		case gxInput::ASC_END:
			curs=str.size();
			break;
		case gxInput::ASC_LEFT:
			if( curs ) --curs;
			break;
		case gxInput::ASC_RIGHT:
			if( curs<str.size() ) ++curs;
			break;
		case '\r':
			go=false;
			break;
		default:
			if( curr_font->isPrintable( key ) ){
				str=str.substr(0,curs)+char(key)+str.substr(curs);
				++curs;
			}
		}

		//render text
		p_canvas->blit( 0,curr_font->getHeight(),p_canvas,0,0,c->getWidth(),curr_font->getHeight(),true );
		p_canvas->text( curs_x,curr_font->getHeight(),str );
		c->blit( 0,curs_y,p_canvas,0,curr_font->getHeight(),c->getWidth(),curr_font->getHeight(),true );
	}

	curs_x=0;
	curs_y+=curr_font->getHeight();
	endPrinting( c );
	return d_new BBStr( str );
}