/* Depends on drawRectangle , clearDisplay
zindex = overlap priority , lowest trumps
*/
#define DISPLAYOBJECTDATAMAX 34
typedef struct displayobjectT displayobject ;
typedef displayobject* displayobjectptr;
struct displayobjectT
{ int id;
wchar_t data[ DISPLAYOBJECTDATAMAX];
int actionlist [ 10 ];
rectangle location;
int zindex;
displayobjectptr prev;
displayobjectptr next ;
};
displayobjectptr displayobjectAlloc( VOID )
{
return( (displayobjectptr)malloc( sizeof( displayobject ) ) );
}/* end displayobjectAlloc( ) */
displayobjectptr initializedisplayobject( VOID )
{
displayobjectptr temp;
temp = displayobjectAlloc( );
if( temp == NULL )
{ printf( "error allocating memory");
exit( 1 );
}
temp -> id = 0;
wmemset( temp ->data , 0 , _countof( temp ->data) );
memset( temp ->actionlist , 0 , sizeof ( temp ->actionlist ) );
temp -> location.left = 0;
temp -> location.top = 0;
temp -> location.right = 0;
temp -> location.bottom = 0;
temp -> location.color = RGB( 0 , 0 , 0 );
temp -> zindex = 0;
temp -> prev = NULL ;
temp -> next = NULL ;
return temp ;
}/* end initializedisplayobject( ) */
displayobjectptr appenddisplayobjectList( displayobjectptr listend , displayobjectptr newobject )
{
if ( listend != NULL && newobject != NULL)
{
listend -> next = newobject ;
newobject ->id = ( listend ->id ) +1;
newobject ->prev = listend ;
return newobject ;
}
return NULL ;
}/* end appenddisplayobjectList( ) */
void showdisplayobjectWinGUI ( HWND hwnd , displayobjectptr displaytemp )
{
while( displaytemp != NULL)
{
drawTextW( hwnd , displaytemp -> location.left , displaytemp -> location.top , displaytemp -> data );
drawRectangle ( hwnd ,
displaytemp -> location.left ,
displaytemp -> location.top ,
displaytemp -> location.right ,
displaytemp -> location.bottom ,
displaytemp -> location.color );
displaytemp = displaytemp -> next ;
}/* end while */
}/* end showdisplayobjectWinGUI */
void showdisplayobjectConsole( displayobjectptr temp )
{ int i=0;
if( temp != NULL)
{
for( i =0 ; i< DISPLAYOBJECTDATAMAX ; i++)
{ printf("%c", temp->data[ i ] );
}
}
}/* end showdisplayobjectConsole */
void showdisplayobjectListConsole( displayobjectptr temp )
{
printf(" \n*displayobject LIST* \n");
while( temp != NULL)
{
showdisplayobjectConsole( temp );
printf("\n");
temp = temp-> next ;
}
}/* end showdisplayobjectListConsole */
displayobjectptr deletedisplayobjectList( displayobjectptr t )
{
displayobjectptr temp;
while( t != NULL)
{
temp = t;
t = t->next;
free( temp );
}
return NULL;
}/* end function deletedisplayobjectList( ) */
int displayobjectClickCheck ( displayobjectptr temp , int x , int y )
{
if ( temp != NULL)
{
if( (x > temp->location.left )
&& (x < temp->location.right )
&& ( y > temp->location.top )
&& (y < temp->location.bottom )
)
{
return 1 ;
}
} /* end if NOT NULL */
return 0 ;
} /* end function displayobjectClickCheck */
void displayobjectRectangleClear ( HWND hwnd , displayobjectptr target )
{
if ( target != NULL )
{
clearRectangle ( hwnd , target -> location ) ;
}
}/* end clearRectangle function */
void displayobjectClearData ( displayobjectptr target )
{
if ( target != NULL)
{
wmemset( target ->data , 0 , _countof( target ->data) );
}
}/* end function displayobjectChangeData */
int displayobjectChangeData ( displayobjectptr target , wchar_t newdata[ DISPLAYOBJECTDATAMAX ] )
{
if ( target != NULL)
{
wmemset( target ->data , 0 , _countof( target ->data) );
wcscpy( target -> data , newdata );
}
return ( 0 );
}/* end function displayobjectChangeData */
int displayobjectChangeColor ( displayobjectptr target , long newcolor )
{
if ( target != NULL)
{ target -> location.color = newcolor ;
}
return ( 0 );
}/* end function displayobjectChangeData */
/* fill filldisplayObject with solid color */
VOID filldisplayObject ( HWND hwnd , displayobjectptr target , long color )
{
int width ;
int height ;
if ( target != NULL)
{
width = target -> location.right
- target -> location.left ;
height = target -> location.bottom - target -> location.top ;
drawRectangleSolid ( hwnd , target ->location.left , target ->location.top , width , height , color ) ;
} /* end if NOT NULL */
} /* end filldisplayObject function */
/*
int displayobjectGetData ( char* buffer[ DISPLAYOBJECTDATAMAX ] , displayobjectptr temp )
{
if ( temp != NULL)
{
memset( buffer , 0 , sizeof( buffer ) );
strcpy( buffer , temp ->data );
return ( 0 );
}
return ( 1 );
} end function displayobjectGetData */