void printAlignedText(double dbHorizontalAlign,double dbVerticalAlign,u8 chMinRow,u8 chMinColumn,u8 chMaxRow,u8 chMaxColumn,bool blnMultiLine,bool blnHideOverflowText,struct stConsoleCursorLocation *stTexteLocation,const char *strTexteFormat,...) { static char strTextBuffer[1024]; va_list pArguments; unsigned int intBreakLinesCount; char **strBreakLines; double dbTextContainerX[2]={0,0},dbTextContainerY[2]={0,0}; va_start(pArguments,strTexteFormat); vsnprintf(strTextBuffer,sizeof(strTextBuffer),strTexteFormat,pArguments); va_end(pArguments); if (chMinColumn>chMaxColumn) { permutePointers((void *) &chMinColumn,(void *) &chMaxColumn); } if (chMinRow>chMaxRow) { permutePointers((void *) &chMinRow,(void *) &chMaxRow); } dbTextContainerX[1]=strlen(strTextBuffer)-1; if (blnMultiLine) { intBreakLinesCount=chMaxRow-chMinRow+1; if ((strBreakLines=getBreakStrings(strTextBuffer,' ',chMaxColumn-chMinColumn+1,&intBreakLinesCount))!=NULL) { dbTextContainerY[1]=intBreakLinesCount-1; dbHorizontalAlign=getRoundNumber(getPolyContainerPosition(&dbTextContainerX[0],2,chMinColumn,chMaxColumn,dbHorizontalAlign)); dbVerticalAlign=getRoundNumber(getPolyContainerPosition(&dbTextContainerY[0],2,chMinRow,chMaxRow,dbVerticalAlign)); if (blnHideOverflowText) { while ((intBreakLinesCount) && (isInRange(dbVerticalAlign,chMinRow,chMaxRow,true,true))) { printTextInColumnsRange(dbVerticalAlign,dbHorizontalAlign,chMinColumn,chMaxColumn,stTexteLocation,"%s",strTextBuffer); dbVerticalAlign++; intBreakLinesCount--; } } else { while (intBreakLinesCount) { printLocatedText(dbVerticalAlign,dbHorizontalAlign,stTexteLocation,"%s",strTextBuffer); resetSavedPreviousCursorPosition(); dbVerticalAlign++; intBreakLinesCount--; } } free(strBreakLines); strBreakLines=NULL; } } else { dbHorizontalAlign=getRoundNumber(getPolyContainerPosition(&dbTextContainerX[0],2,chMinColumn,chMaxColumn,dbHorizontalAlign)); dbVerticalAlign=getRoundNumber(getPolyContainerPosition(&dbTextContainerY[0],2,chMinRow,chMaxRow,dbVerticalAlign)); if (blnHideOverflowText) { if (isInRange(dbVerticalAlign,chMinRow,chMaxRow,true,true)) { printTextInColumnsRange(dbVerticalAlign,dbHorizontalAlign,chMinColumn,chMaxColumn,stTexteLocation,"%s",strTextBuffer); } } else { printLocatedText(dbVerticalAlign,dbHorizontalAlign,stTexteLocation,"%s",strTextBuffer); resetSavedPreviousCursorPosition(); } } }
void drawCommandsBar(unsigned char chCommandsCount,bool blnStatusBar,struct stCommandsBar *stCommandsBarSettings) { int intConsoleColumnsCount,intConsoleRowsCount; CON_GetMetrics(&intConsoleColumnsCount,&intConsoleRowsCount); stCommandsBarSettings->chCommandsCount=chCommandsCount; stCommandsBarSettings->chCommandItemsCount=0; stCommandsBarSettings->stStatusBarLocation.intColumn=0; intConsoleColumnsCount--; saveCursorPosition(); if (blnStatusBar) { intConsoleRowsCount--; stCommandsBarSettings->stStatusBarLocation.intRow=intConsoleRowsCount; setCursorPosition(intConsoleRowsCount,0); printf("%*s",intConsoleColumnsCount,""); intConsoleRowsCount--; setCursorPosition(intConsoleRowsCount,0); printRepeatString(intConsoleColumnsCount,"%c",HORIZONTAL_SINGLE_BORDER); } else { stCommandsBarSettings->stStatusBarLocation.intRow=-1; } if (chCommandsCount) { stCommandsBarSettings->stCommandsBarLocation.intRow=intConsoleRowsCount-getRoundNumber(((double)chCommandsCount)/2); stCommandsBarSettings->stCommandsBarLocation.intColumn=0; while (intConsoleRowsCount>stCommandsBarSettings->stCommandsBarLocation.intRow) { intConsoleRowsCount--; setCursorPosition(intConsoleRowsCount,0); printf("%*s",intConsoleColumnsCount,""); } setCursorPosition(stCommandsBarSettings->stCommandsBarLocation.intRow-1,0); printRepeatString(intConsoleColumnsCount,"%c",HORIZONTAL_SINGLE_BORDER); } resetSavedCursorPosition(); }
void StudentWorld::updateDisplayText() { int score = getScore(); int round = getRoundNumber(); double energyPercent = ptrToShip->getEnergyPct(); int torpedos = ptrToShip->getNumTorpedos(); int shipsLeft = getLives(); string s = formatDisplay(score, round, energyPercent, torpedos, shipsLeft); setGameStatText(s); }
void drawAlignedTable(double dbHorizontalAlign,double dbVerticalAlign,u8 chMinRow,u8 chMinColumn,u8 chMaxRow,u8 chMaxColumn,u8 chColumnsCount,u8 chRowsCount,u8 chCellWidth,u8 chCellHeight,enum BORDER_STYLES BORDER_STYLE,enum CONSOLE_FONT_COLORS BORDER_COLOR,enum CONSOLE_FONT_COLORS BGCOLOR,struct stTable *stTableSettings) { double dbTextContainerX[2]={0,chCellWidth*chColumnsCount},dbTextContainerY[2]={0,chRowsCount*chCellHeight}; if (chMinColumn>chMaxColumn) { permutePointers((void *) &chMinColumn,(void *) &chMaxColumn); } if (chMinRow>chMaxRow) { permutePointers((void *) &chMinRow,(void *) &chMaxRow); } drawTable(getRoundNumber(getPolyContainerPosition(&dbTextContainerY[0],2,chMinRow,chMaxRow,dbVerticalAlign)),getRoundNumber(getPolyContainerPosition(&dbTextContainerX[0],2,chMinColumn,chMaxColumn,dbHorizontalAlign)),chColumnsCount,chRowsCount,chCellWidth,chCellHeight,BORDER_STYLE,BORDER_COLOR,BGCOLOR,stTableSettings); }
void initConsole(const void *imgBgData,enum CONSOLE_COLORS CONSOLE_COLOR,const char *strSplashScreenMessage,double dbLeft,double dbTop,double dbWidth,double dbHeight) { PNGUPROP imgProperties; IMGCTX imgContext; void *pFramebuffer=NULL; GXRModeObj *pRmode=NULL; double dbConsoleFrameX[2]={dbLeft,dbLeft},dbConsoleFrameY[2]={dbTop,dbTop},dbBgImgXScaleFactor=1,dbBgImgYScaleFactor=1,dbReferenceWidth,dbReferenceHeight; int intConsoleColumnsCount,intConsoleRowsCount; struct stConsoleCursorLocation stTexteLocation; VIDEO_Init(); pRmode=VIDEO_GetPreferredMode(NULL); pFramebuffer=MEM_K0_TO_K1(SYS_AllocateFramebuffer(pRmode)); VIDEO_ClearFrameBuffer(pRmode,pFramebuffer,CONSOLE_COLOR); VIDEO_Configure(pRmode); VIDEO_SetNextFramebuffer(pFramebuffer); VIDEO_SetBlack(FALSE); VIDEO_Flush(); VIDEO_WaitVSync(); if(pRmode->viTVMode&VI_NON_INTERLACE) { VIDEO_WaitVSync(); } dbWidth=fabs(dbWidth); dbHeight=fabs(dbHeight); if ((imgContext=getPngImageRessources(imgBgData,&imgProperties))) { dbReferenceWidth=imgProperties.imgWidth; dbReferenceHeight=imgProperties.imgHeight; dbBgImgXScaleFactor=pRmode->fbWidth/imgProperties.imgWidth; dbBgImgYScaleFactor=pRmode->xfbHeight/imgProperties.imgHeight; } else { dbReferenceWidth=pRmode->fbWidth; dbReferenceHeight=pRmode->xfbHeight; } if (dbWidth<=1) { dbWidth=dbReferenceWidth*dbWidth; dbConsoleFrameX[0]=0; dbConsoleFrameX[1]=dbWidth; } if (dbHeight<=1) { dbHeight=dbReferenceHeight*dbHeight; dbConsoleFrameY[0]=0; dbConsoleFrameY[1]=dbHeight; } CON_InitEx(pRmode,(s32) getRoundNumber(getPolyContainerPosition(&dbConsoleFrameX[0],2,0,dbReferenceWidth,dbLeft)*dbBgImgXScaleFactor),(s32) getRoundNumber(getPolyContainerPosition(&dbConsoleFrameY[0],2,0,dbReferenceHeight,dbTop)*dbBgImgYScaleFactor),(s32) getRoundNumber(dbWidth*dbBgImgXScaleFactor),(s32) getRoundNumber(dbHeight*dbBgImgYScaleFactor)); if (imgContext) { PNGU_DECODE_TO_COORDS_YCbYCr(imgContext,0,0,imgProperties.imgWidth,imgProperties.imgHeight,pRmode->fbWidth,pRmode->xfbHeight,pFramebuffer); PNGU_ReleaseImageContext(imgContext); } resetDefaultFontSyle(); if (*strSplashScreenMessage) { CON_GetMetrics(&intConsoleColumnsCount,&intConsoleRowsCount); printAlignedText(ALIGN_CENTER,ALIGN_MIDDLE,0,0,intConsoleRowsCount-1,intConsoleColumnsCount-1,true,true,&stTexteLocation,"%s",strSplashScreenMessage); } }
void printAlignedTextBox(u8 chFrameMinRow,u8 chFrameMinColumn,u8 chFrameMaxRow,u8 chFrameMaxColumn,double dbRow,double dbColumn,double dbHeight,double dbWidth,double dbHorizontalAlign,double dbVerticalAlign,enum BORDERS BORDER_TYPE,enum BORDER_STYLES BORDER_STYLE,enum CONSOLE_FONT_COLORS BORDER_COLOR,enum FRAME_JUNCTIONS TOP_LEFT_JUNCTION,enum FRAME_JUNCTIONS TOP_RIGHT_JUNCTION,enum FRAME_JUNCTIONS BOTTOM_LEFT_JUNCTION,enum FRAME_JUNCTIONS BOTTOM_RIGHT_JUNCTION,enum CONSOLE_FONT_COLORS BGCOLOR,enum CONSOLE_FONT_COLORS FONT_FGCOLOR,enum CONSOLE_FONT_WEIGHTS FONT_WEIGHT,bool blnMultiLine,bool blnHideOverflowText,struct stConsoleCursorLocation *stTexteLocation,const char *strFormatValue,...) { static char strTextBuffer[1024]; va_list pArguments; double dbTextContainerX[2]={dbColumn,dbColumn},dbTextContainerY[2]={dbRow,dbRow}; va_start(pArguments,strFormatValue); vsnprintf(strTextBuffer,sizeof(strTextBuffer),strFormatValue,pArguments); va_end(pArguments); if (chFrameMinRow>chFrameMaxRow) { permutePointers((void *) &chFrameMinRow,(void *) &chFrameMaxRow); } if (chFrameMinColumn>chFrameMaxColumn) { permutePointers((void *) &chFrameMinColumn,(void *) &chFrameMaxColumn); } dbWidth=fabs(dbWidth); dbHeight=fabs(dbHeight); if (dbWidth<=1) { dbWidth=(double) (chFrameMaxColumn-chFrameMinColumn+1)*dbWidth; dbTextContainerX[0]=0; dbTextContainerX[1]=dbWidth; } if (dbHeight<=1) { dbHeight=(double) (chFrameMaxRow-chFrameMinRow+1)*dbHeight; dbTextContainerY[0]=0; dbTextContainerY[1]=dbHeight; } if (dbWidth==AUTOSIZE) { dbWidth=getTextBoxAutoWidth(BORDER_TYPE,"%s",strTextBuffer); dbTextContainerX[0]=0; dbTextContainerX[1]=dbWidth; } if (dbHeight==AUTOSIZE) { dbHeight=getTextBoxAutoHeight(BORDER_TYPE,"%s",strTextBuffer); dbTextContainerY[0]=0; dbTextContainerY[1]=dbHeight; } dbColumn=getRoundNumber(getPolyContainerPosition(&dbTextContainerX[0],2,chFrameMinColumn,chFrameMaxColumn,dbColumn)); dbRow=getRoundNumber(getPolyContainerPosition(&dbTextContainerY[0],2,chFrameMinRow,chFrameMaxRow,dbRow)); printTextBox(dbRow,dbColumn,getRoundNumber(dbRow+dbHeight-1),getRoundNumber(dbColumn+dbWidth-1),dbHorizontalAlign,dbVerticalAlign,BORDER_TYPE,BORDER_STYLE,BORDER_COLOR,TOP_LEFT_JUNCTION,TOP_RIGHT_JUNCTION,BOTTOM_LEFT_JUNCTION,BOTTOM_RIGHT_JUNCTION,BGCOLOR,FONT_FGCOLOR,FONT_WEIGHT,blnMultiLine,blnHideOverflowText,stTexteLocation,"%s",strTextBuffer); }
void updateProgressBar(struct stProgressBar *stProgressBarSettings,enum CONSOLE_FONT_COLORS FONT_BGCOLOR,enum CONSOLE_FONT_COLORS FONT_FGCOLOR,enum CONSOLE_FONT_WEIGHTS FONT_WEIGHT,const char *strFormatProgressBarText,...) { static char strProgressBarText[256]; struct stConsoleCursorLocation stTexteLocation; va_list pArguments; if (stProgressBarSettings->intValue<stProgressBarSettings->intOperationsCount) { saveCursorPosition(); stProgressBarSettings->intValue=stProgressBarSettings->intValue+1; setCursorPosition(stProgressBarSettings->stProgressBarLocation.intRow,stProgressBarSettings->stProgressBarLocation.intColumn); setFontBgColor(stProgressBarSettings->PROGRESSBAR_COLOR); printf("%*s",(unsigned int) getRoundNumber((double)stProgressBarSettings->intValue*(double) stProgressBarSettings->chProgressBarSize/(double) stProgressBarSettings->intOperationsCount),""); resetPreviousBgColor(); resetSavedCursorPosition(); va_start(pArguments,strFormatProgressBarText); vsnprintf(strProgressBarText,stProgressBarSettings->chProgressBarTextSize+1,strFormatProgressBarText,pArguments); va_end(pArguments); printLabel(stProgressBarSettings->stProgressBarTextLocation.intRow,stProgressBarSettings->stProgressBarTextLocation.intColumn,FONT_BGCOLOR,FONT_FGCOLOR,FONT_WEIGHT,stProgressBarSettings->chProgressBarTextSize,&stTexteLocation,"%s",strProgressBarText); } }
int BaseAI::roundNumber() { return getRoundNumber(c); }
double getPolyContainerPosition(const double *dbPolyPointsPositions,unsigned int intPointsCount,double dbContainerMinPosition,double dbContainerMaxPosition,double dbPositionType) { double varout=dbContainerMinPosition+dbPolyPointsPositions[getArrayMinValueIndex((const void *) dbPolyPointsPositions,intPointsCount,sizeof(double))]; if (fabs(dbPositionType)<1) { varout=dbContainerMinPosition+dbPositionType*(dbContainerMaxPosition-dbContainerMinPosition); } else if (isInRange(dbPositionType,ALIGN_NONE,-1,true,true)) { varout=getAlignedPolyContainerPosition(dbPolyPointsPositions,intPointsCount,dbContainerMinPosition,dbContainerMaxPosition,(enum ALIGNEMENTS) (int) getRoundNumber(dbPositionType)); } return varout; }