// File : fwText.c // Author : John Wojcik ( QuietBloke ) // Created : December 2000 // Desc : 2d Game Framework Text Manager. // This manager controls the displaying of text. Functions allow text // strings to be defined and positioned on the display. Its a bit of a // bodge at the moment as I just want to get it workign for my current // game. // #include #include #include "fw.h" typedef struct { int OnStageFlag; int Length; int ActorID; // Actor ID of first character in the string int XPos; int YPos; } Text; Text TextList[MAX_TEXTS]; int TextFirstCostume; int TextFirstChar; int NextText = 0; void fwTextReset ( void ) { NextText = 0; } void fwTextSetFont ( int CostumeID, char FirstChar ) { TextFirstCostume = CostumeID; TextFirstChar = FirstChar; } int fwTextAdd ( char Text[], int xpos, int ypos ) { int textLen = 0; int currentActor; int currentCostume; int firstActor; int currentXPos; int currentText; // We have been given a pointer to a string currentXPos = xpos; while ( Text[textLen] != 0 ) { currentCostume = (int)(Text[textLen] ) - TextFirstChar + TextFirstCostume; currentActor = fwActorAdd ( currentCostume ); fwActorPos ( currentActor, currentXPos, ypos ); if ( textLen == 0 ) { firstActor = currentActor; } textLen++; currentXPos += ( fwActorGetPixelWidth( currentActor ) << fwStageGetPixelShift () ); } TextList[NextText].OnStageFlag = ON_STAGE; TextList[NextText].Length = textLen; TextList[NextText].ActorID = firstActor; TextList[NextText].XPos = xpos; TextList[NextText].YPos = ypos; currentText = NextText; NextText++; if (NextText >= MAX_TEXTS ) { printf ( "Max texts exceeded" ); } return ( currentText ); } void fwTextPos ( int TextID, int xpos, int ypos ) { int currentActor; int currentXPos; int currentYPos; TextList[TextID].XPos = xpos; TextList[TextID].YPos = ypos; currentActor = TextList[TextID].ActorID; currentXPos = xpos; currentYPos = ypos; // Now move the positions of each of this strings actors while ( currentActor < TextList[TextID].Length ) { fwActorPos ( currentActor, currentXPos, currentYPos ); currentXPos += ( fwActorGetPixelWidth( currentActor ) << fwStageGetPixelShift () ); currentActor++; } } void fwTextChange ( int textID, char Text[] ) { int textLen = 0; int currentActor; int currentCostume; // We have been given a pointer to a string currentActor = TextList[textID].ActorID; while ( Text[textLen] != 0 && textLen < TextList[textID].Length ) { currentCostume = (int)(Text[textLen] ) - TextFirstChar + TextFirstCostume; fwActorChangeCostume ( currentActor, currentCostume ); fwActorSetOnStage ( currentActor, ON_STAGE ); textLen++; currentActor++; } TextList[textID].OnStageFlag = ON_STAGE; // remember to mark any remaining actors in this string off stage while( textLen < TextList[textID].Length ) { fwActorSetOnStage ( currentActor, OFF_STAGE ); currentActor++; textLen++; } } void fwTextHide ( int textID ) { int currentActor; int textPos; currentActor = TextList[textID].ActorID; for ( textPos = 0; textPos < TextList[textID].Length; textPos++) { fwActorSetOnStage ( currentActor, OFF_STAGE ); currentActor++; } } void fwTextShow ( int textID ) { int currentActor; int textPos; currentActor = TextList[textID].ActorID; for ( textPos = 0; textPos < TextList[textID].Length; textPos++) { fwActorSetOnStage ( currentActor, ON_STAGE ); currentActor++; } } void fwTextSetRGB ( int textID, int red, int green, int blue ) { int currentActor; int textPos; currentActor = TextList[textID].ActorID; for ( textPos = 0; textPos < TextList[textID].Length; textPos++) { fwActorSetRGB ( currentActor, red, green, blue ); currentActor++; } }