Ever wanted to paste some text straight into the texture of an entity or a sprite?

NOW YOU CAN! With the amazing new product by EvilSOB services...


The new
"string_onto_tex" function! (Version 2.00)
Only for A8 as far as I know. Maybe only Commercial and above.(ONLY been tested with A8.30.3 so far)


void string_onto_tex(ENTITY* targ, STRING* text, VECTOR* pos, VECTOR* size, FONT* font, COLOR* FGcol, COLOR* BGcol, long flags, var time );

Yes, yes, I know there are a LOT of parameters, but thats to control the !!POWER!!

They break down like so....

ENTITY* targ....(required)The entity that the string is going to get pasted onto.
STRING* text....(required)The actual test data to get pasted.
VECTOR* pos....The X,Y pixel position within the Entities Skin1 Texture. .................(NULL defaults to 0,0)
......pos.z.......Skin number for the string to get pasted onto. ............................(defaults to 1)
VECTOR* size...The X,y size in pixels of the rectangle that will get pasted. ..............(NULL defaults to 128x32)
.....size.z.......Alpha value to apply to the panel when using TRANSLUCENT flag. .......(defaults to 50)
FONT* font......The FONT that the string will be displayed as. ..............................(NULL defaults to Arial#16b)
COLOR* FGcol...The COLOR that the ForeGround(text) will be. ............................(NULL defaults to COLOR_WHITE)
COLOR* BGcol...The COLOR that the BackGround will be. ..................................(NULL defaults to COLOR_BLACK)
long flags........Standard Panel Flags to 'tweak' the display with.
var time.........'wait()' delay between updates to texture. Only updates on changes. ...(ZERO defaults to STATIC Snapshot)

That will do for the sales-hype.. I feel so dirty...

As normal, with any EvilSOB services product, feel free to ask questions,
report bugs, heap praise upon me, or even make suggestions...

Current Version 2.0
Click to reveal..
Code:
//
//-----------------------------------------------------------------------------------------
//
void still_alive(ENTITY* ent)		//entity monitoring function used by string_onto_tex
{	if(proc_status2(still_alive,(me=ent)))	{	return;	}			while(1)	wait(-999);		}
//
//-----------------------------------------------------------------------------------------
//
void string_onto_tex(ENTITY*	targ, STRING* text,	VECTOR* pos,	VECTOR* size, 
							FONT* 	font, COLOR*  FGcol, COLOR*  BGcol, long flags, var time	)
{	if((targ==NULL)||(text==NULL)||(str_len(text)<1))		return;	//invalid core parameters
	//--------------------------------------------------------------------------------------
	STRING *_text,*_last=NULL;		BMAP *ent_skin,*targ_map,*pan_back;		var x,y,_time=time;
	PANEL *pan;				FONT* _font;	VECTOR _pos, _size, size2;		COLOR _FGcol, _BGcol;
	//--------------------------------------------------------------------------------------
	if(text.length!=0)	{	_text = text;	}	else	{	_text=str_create(text);		time=0;	}
	if(pos==NULL)	{	vec_set(_pos, nullvector);	}				else	{	vec_set(_pos, pos);	}
	if(size==NULL)	{	vec_set(_size, vector(128,32,0));	}	else	{	vec_set(_size,size);	}
	if(font==NULL)	{	_font = font_create("Arial#16b");	}	else	{	_font = font;			}
	if(FGcol==NULL)	{	vec_set(_FGcol, COLOR_WHITE);	}	else	{	vec_set(_FGcol, FGcol);	}
	if(BGcol==NULL)	{	vec_set(_BGcol, COLOR_BLACK);	}	else	{	vec_set(_BGcol, BGcol);	}
	if(_pos.z==0)		{	_pos.z = 1;	}						if(_size.z==0)		{	_size.z = 50;	}
	//--------------------------------------------------------------------------------------
	//calculate 'power of 2' size based on _size
	size2.x=_size.x;	size2.z=2;	while((size2.x/=2)>1)  { size2.z*=2; }		size2.x=size2.z;
	size2.y=_size.y;	size2.z=2;	while((size2.y/=2)>1)  { size2.z*=2; }		size2.y=size2.z;
	//--------------------------------------------------------------------------------------
	//setup CLONED skin of original model
	ent_cloneskin(targ);		ent_skin=ent_getskin(targ,_pos.z);
	ent_skin = bmap_createblack(ent_skin.width, ent_skin.height, ent_skin.bytespp*8);
	bmap_blit(ent_skin, ent_getskin(targ,_pos.z), NULL, NULL);		
	pan_back = bmap_createblack(size2.x, size2.y, ent_skin.bytespp*8);
	bmap_blitpart(pan_back, ent_getskin(targ,_pos.z), NULL, NULL, _pos, size2);	
	ent_setskin(targ,ent_skin, _pos.z);
	//--------------------------------------------------------------------------------------
	//'compress' middle of text if ( str_width() > size.width )
	var font_x=str_width(_str("~"),_font), font_y=font_x*2;
	var font_avg = str_width(_text,_font)/str_len(_text);
	if(str_width(_text, _font) > (_size.x-2))
	{	var str_ends = integer(size.x/3/font_avg);	STRING* tmp = str_create(_chr(_text));
		str_trunc(_text,str_len(_text)-str_ends);		str_cat(_text, "...");	
		str_clip(tmp,str_len(tmp)-str_ends-3);	str_cat(_text,tmp);	str_remove(tmp);			}
	//--------------------------------------------------------------------------------------
	//setup PANEL and necessary BMAPs
	pan=pan_create("flags=SHOW;",10000);		pan.bmap= pan_back;		pan.alpha = _size.z;
	targ_map = bmap_createblack(size2.x,size2.y,24);						set(pan, flags);
	if(is(pan,CENTER_X))	{	x=_size.x/2;	} 	else	{	x=2;	}
	if(is(pan,ARIGHT))	{	x=_size.x-2;	} 
	if(is(pan,CENTER_Y))	{	y=_size.y/2;	} 	else	{	y=2;	}
	if(!is(pan,OVERLAY))	{	bmap_fill(pan_back, _BGcol, 100);	}
	pan_setstring(pan,0, x,y , _font, _text);					pan_setcolor(pan,1,1, _FGcol);
	//--------------------------------------------------------------------------------------
	still_alive(targ);	while(proc_status2(still_alive, targ))
	{	if(_last==NULL)	{	_last = str_create("");	}
		if(str_cmp(_text, _last)==0)
		{	pan.target_map=targ_map;	set(pan, SHOW);	
			proc_mode=PROC_GLOBAL;		wait(1);		
			proc_mode=PROC_GLOBAL;		str_cpy(_last, _text);	}
		if(!proc_status2(still_alive, targ))	{	break;	}
		//-----------------------------------------------------------
		pan.target_map=NULL;			reset(pan, SHOW);
		bmap_blitpart(ent_skin,targ_map,_pos,NULL,NULL,_size);
		proc_mode=PROC_GLOBAL;		
		if(time)	{	wait(time);	}	else	{	break;	}					}
	//--------------------------------------------------------------------------------------
	//cleanup temporary workspace
	if(font==NULL)			{	font_remove(_font);	}
	if(text.length==0)	{	str_remove(_text);	}		if(_last)	{	str_remove(_last);	}
	bmap_purge(pan_back);	bmap_remove(pan_back);		
	bmap_purge(targ_map);	bmap_remove(targ_map);		pan_remove(pan);	
}
//
//-----------------------------------------------------------------------------------------
//



Changelog::
Click to reveal..

Code:
Version 1.0  (09/12/2011) :: Initial release


Code:
Version 1.01 (10/12/2011) :: Minor bugfix that prevented string-render on some occasions.


Code:
Version 1.1  (10/12/2011) :: Major improvement to OVERLAY flag functionality.
                             Implemented TRANSLUCENT flag functionality.
                             Implemented new parameter to support TRANSLUCENT flag. 
                             Implemented new parameter to support Skin-Number selection.


Code:
Version 2.0  (11/12/2011) :: Major change. Function is now capable of DYNAMIC updates.
                             Implemented TIME parameter for 'potential' update timing.
                             Added string-data retrieval from a POINTER.





Old OBSOLETE Version 1.1 (kept for historical reasons)
Click to reveal..
Code:
//
//-----------------------------------------------------------------------------------------
//
void still_alive(ENTITY* ent)		//entity monitoring function used by string_onto_tex
{	if(proc_status2(still_alive,(me=ent)))	{	return;	}			while(1)	wait(-999);		}
//
//-----------------------------------------------------------------------------------------
//
void string_onto_tex(ENTITY*	targ, STRING* text,	VECTOR* pos,	VECTOR* size, 
							FONT* 	font, COLOR*  FGcol, COLOR*  BGcol, long flags	)
{	if((targ==NULL)||(text==NULL)||(str_len(text)<1))		return;	//invalid core parameters
	//--------------------------------------------------------------------------------------
	STRING* _text=str_create(text);		BMAP *ent_skin, *targ_map, *pan_back;		var x,y;
	PANEL *pan;		FONT* _font;			VECTOR _pos, _size, size2;		COLOR _FGcol, _BGcol;
	//--------------------------------------------------------------------------------------
	if(pos==NULL)	{	vec_set(_pos, nullvector);	}				else	{	vec_set(_pos, pos);	}
	if(size==NULL)	{	vec_set(_size, vector(128,32,0));	}	else	{	vec_set(_size,size);	}
	if(font==NULL)	{	_font = font_create("Arial#16b");	}	else	{	_font = font;			}
	if(FGcol==NULL)	{	vec_set(_FGcol, COLOR_WHITE);	}	else	{	vec_set(_FGcol, FGcol);	}
	if(BGcol==NULL)	{	vec_set(_BGcol, COLOR_BLACK);	}	else	{	vec_set(_BGcol, BGcol);	}
	if(_pos.z==0)		{	_pos.z = 1;	}						if(_size.z==0)		{	_size.z = 50;	}
	//--------------------------------------------------------------------------------------
	//calculate 'power of 2' size based on _size
	size2.x=_size.x;	size2.z=2;	while((size2.x/=2)>1)  { size2.z*=2; }		size2.x=size2.z;
	size2.y=_size.y;	size2.z=2;	while((size2.y/=2)>1)  { size2.z*=2; }		size2.y=size2.z;
	//--------------------------------------------------------------------------------------
	//setup CLONED skin of original model
	ent_cloneskin(targ);		ent_skin=ent_getskin(targ,_pos.z);
	ent_skin = bmap_createblack(ent_skin.width, ent_skin.height, ent_skin.bytespp*8);
	bmap_blit(ent_skin, ent_getskin(targ,_pos.z), NULL, NULL);		
	pan_back = bmap_createblack(size2.x, size2.y, ent_skin.bytespp*8);
	bmap_blitpart(pan_back, ent_getskin(targ,_pos.z), NULL, NULL, _pos, size2);	
	ent_setskin(targ,ent_skin, _pos.z);
	//--------------------------------------------------------------------------------------
	//'compress' middle of text if ( str_width() > size.width )
	var font_x=str_width(_str("~"),_font), font_y=font_x*2;
	var font_avg = str_width(_text,_font)/str_len(_text);
	if(str_width(_text, _font) > (_size.x-2))
	{	var str_ends = integer(size.x/3/font_avg);	STRING* tmp = str_create(_chr(_text));
		str_trunc(_text,str_len(_text)-str_ends);		str_cat(_text, "...");	
		str_clip(tmp,str_len(tmp)-str_ends-3);	str_cat(_text,tmp);	str_remove(tmp);			}
	//--------------------------------------------------------------------------------------
	//setup PANEL and necessary BMAPs
	pan=pan_create("flags=SHOW;",10000);		pan.bmap= pan_back;		pan.alpha = _size.z;
	pan.target_map = targ_map = bmap_createblack(size2.x,size2.y,24);		set(pan, flags);
	if(is(pan,CENTER_X))	{	x=_size.x/2;	} 	else	{	x=2;	}
	if(is(pan,ARIGHT))	{	x=_size.x-2;	} 
	if(is(pan,CENTER_Y))	{	y=_size.y/2;	} 	else	{	y=2;	}
	if(!is(pan,OVERLAY))	{	bmap_fill(pan_back, _BGcol, 100);	}
	pan_setstring(pan,0, x,y , _font, _text);					pan_setcolor(pan,1,1, _FGcol);
	//--------------------------------------------------------------------------------------
	wait(1);		/*wait for render into targ_map*/			pan.target_map=NULL;
	bmap_blitpart(ent_skin,targ_map,_pos,NULL,NULL,_size);	//bmap_blit onto entity's skin
	//--------------------------------------------------------------------------------------
	//cleanup temporary workspace
	if(font==NULL)	{	font_remove(_font);	}				str_remove(_text);
	bmap_purge(pan_back);	bmap_remove(pan_back);		
	bmap_purge(targ_map);	bmap_remove(targ_map);		pan_remove(pan);		
	//--------------------------------------------------------------------------------------
	//cleanup custom-texture workspace once entity no longer exists
	//#### not necessary on STATIC entities.  ent_remove DOES release ent_cloneskin skins
	still_alive(targ);		
	while(proc_status2(still_alive, targ))		{	proc_mode=PROC_GLOBAL;	wait(-5);	}
	bmap_purge(ent_skin);	bmap_remove(ent_skin);
}
//
//-----------------------------------------------------------------------------------------
//




Last edited by EvilSOB; 12/11/11 02:12. Reason: Version 2.00 !!

"There is no fate but what WE make." - CEO Cyberdyne Systems Corp.
A8.30.5 Commercial