/** Creates a text from config * @param[in] _zConfigID Config ID * @return orxTEXT / orxNULL */ orxTEXT *orxFASTCALL orxText_CreateFromConfig(const orxSTRING _zConfigID) { orxTEXT *pstResult; /* Checks */ orxASSERT(sstText.u32Flags & orxTEXT_KU32_STATIC_FLAG_READY); orxASSERT((_zConfigID != orxNULL) && (_zConfigID != orxSTRING_EMPTY)); /* Pushes section */ if((orxConfig_HasSection(_zConfigID) != orxFALSE) && (orxConfig_PushSection(_zConfigID) != orxSTATUS_FAILURE)) { /* Creates text */ pstResult = orxText_Create(); /* Valid? */ if(pstResult != orxNULL) { /* Stores its reference key */ pstResult->zReference = orxString_Store(orxConfig_GetCurrentSection()); /* Processes its config data */ if(orxText_ProcessConfigData(pstResult) == orxSTATUS_FAILURE) { /* Logs message */ orxDEBUG_PRINT(orxDEBUG_LEVEL_DISPLAY, "Couldn't process config data for text <%s>.", _zConfigID); /* Deletes it */ orxText_Delete(pstResult); /* Updates result */ pstResult = orxNULL; } } /* Pops previous section */ orxConfig_PopSection(); } else { /* Logs message */ orxDEBUG_PRINT(orxDEBUG_LEVEL_DISPLAY, "Couldn't find config section named (%s).", _zConfigID); /* Updates result */ pstResult = orxNULL; } /* Done! */ return pstResult; }
/** Deletes all texts */ static orxINLINE void orxText_DeleteAll() { orxTEXT *pstText; /* Gets first text */ pstText = orxTEXT(orxStructure_GetFirst(orxSTRUCTURE_ID_TEXT)); /* Non empty? */ while(pstText != orxNULL) { /* Deletes text */ orxText_Delete(pstText); /* Gets first text */ pstText = orxTEXT(orxStructure_GetFirst(orxSTRUCTURE_ID_TEXT)); } return; }
/** Sets graphic data * @param[in] _pstGraphic Graphic concerned * @param[in] _pstData Data structure to set / orxNULL * @return orxSTATUS_SUCCESS / orxSTATUS_FAILURE */ orxSTATUS orxFASTCALL orxGraphic_SetData(orxGRAPHIC *_pstGraphic, orxSTRUCTURE *_pstData) { orxSTATUS eResult = orxSTATUS_SUCCESS; /* Checks */ orxASSERT(sstGraphic.u32Flags & orxGRAPHIC_KU32_STATIC_FLAG_READY); orxSTRUCTURE_ASSERT(_pstGraphic); /* Had previous data? */ if(_pstGraphic->pstData != orxNULL) { /* Updates structure reference counter */ orxStructure_DecreaseCounter(_pstGraphic->pstData); /* Internally handled? */ if(orxStructure_TestFlags(_pstGraphic, orxGRAPHIC_KU32_FLAG_INTERNAL)) { /* Removes its owner */ orxStructure_SetOwner(_pstGraphic->pstData, orxNULL); /* 2D data? */ if(orxStructure_TestFlags(_pstGraphic, orxGRAPHIC_KU32_FLAG_2D)) { /* Deletes it */ orxTexture_Delete(orxTEXTURE(_pstGraphic->pstData)); } /* Text data? */ else if(orxStructure_TestFlags(_pstGraphic, orxGRAPHIC_KU32_FLAG_TEXT)) { /* Deletes it */ orxText_Delete(orxTEXT(_pstGraphic->pstData)); } else { /* Logs message */ orxDEBUG_PRINT(orxDEBUG_LEVEL_DISPLAY, "Non-2d (texture/text) graphics not supported yet."); /* Updates result */ eResult = orxSTATUS_FAILURE; } /* Updates flags */ orxStructure_SetFlags(_pstGraphic, orxGRAPHIC_KU32_FLAG_NONE, orxGRAPHIC_KU32_FLAG_INTERNAL); } /* Cleans reference */ _pstGraphic->pstData = orxNULL; } /* Valid & sets new data? */ if((eResult != orxSTATUS_FAILURE) && (_pstData != orxNULL)) { /* Stores it */ _pstGraphic->pstData = _pstData; /* Updates structure reference counter */ orxStructure_IncreaseCounter(_pstData); /* Is data a texture? */ if(orxTEXTURE(_pstData) != orxNULL) { /* Updates flags */ orxStructure_SetFlags(_pstGraphic, orxGRAPHIC_KU32_FLAG_2D, orxGRAPHIC_KU32_MASK_TYPE); } /* Is data a text? */ else if(orxTEXT(_pstData) != orxNULL) { /* Updates flags */ orxStructure_SetFlags(_pstGraphic, orxGRAPHIC_KU32_FLAG_TEXT, orxGRAPHIC_KU32_MASK_TYPE); } else { /* Logs message */ orxDEBUG_PRINT(orxDEBUG_LEVEL_DISPLAY, "Data given is not a texture nor a text."); /* Updates flags */ orxStructure_SetFlags(_pstGraphic, orxGRAPHIC_KU32_FLAG_NONE, orxGRAPHIC_KU32_MASK_TYPE); /* Updates result */ eResult = orxSTATUS_FAILURE; } } else { /* Updates flags */ orxStructure_SetFlags(_pstGraphic, orxGRAPHIC_KU32_FLAG_NONE, orxGRAPHIC_KU32_MASK_TYPE); } /* Done! */ return eResult; }
/** Creates a graphic from config * @param[in] _zConfigID Config ID * @ return orxGRAPHIC / orxNULL */ orxGRAPHIC *orxFASTCALL orxGraphic_CreateFromConfig(const orxSTRING _zConfigID) { orxGRAPHIC *pstResult; /* Checks */ orxASSERT(sstGraphic.u32Flags & orxGRAPHIC_KU32_STATIC_FLAG_READY); orxASSERT((_zConfigID != orxNULL) && (_zConfigID != orxSTRING_EMPTY)); /* Pushes section */ if((orxConfig_HasSection(_zConfigID) != orxFALSE) && (orxConfig_PushSection(_zConfigID) != orxSTATUS_FAILURE)) { /* Creates graphic */ pstResult = orxGraphic_Create(); /* Valid? */ if(pstResult != orxNULL) { const orxSTRING zName; orxU32 u32Flags = orxGRAPHIC_KU32_FLAG_NONE; /* Gets texture name */ zName = orxConfig_GetString(orxGRAPHIC_KZ_CONFIG_TEXTURE_NAME); /* Valid? */ if((zName != orxNULL) && (zName != orxSTRING_EMPTY)) { orxTEXTURE *pstTexture; /* Creates texture */ pstTexture = orxTexture_CreateFromFile(zName); /* Valid? */ if(pstTexture != orxNULL) { /* Links it */ if(orxGraphic_SetData(pstResult, (orxSTRUCTURE *)pstTexture) != orxSTATUS_FAILURE) { orxVECTOR vTextureSize; /* Updates its owner */ orxStructure_SetOwner(pstTexture, pstResult); /* Inits default 2D flags */ u32Flags = orxGRAPHIC_KU32_FLAG_INTERNAL | orxGRAPHIC_KU32_FLAG_2D; /* Has size? */ if(orxConfig_GetVector(orxGRAPHIC_KZ_CONFIG_TEXTURE_SIZE, &vTextureSize) != orxNULL) { orxVECTOR vTextureOrigin; /* Has origin? */ if(orxConfig_GetVector(orxGRAPHIC_KZ_CONFIG_TEXTURE_ORIGIN, &vTextureOrigin) != orxNULL) { /* Stores them */ pstResult->fLeft = vTextureOrigin.fX; pstResult->fTop = vTextureOrigin.fY; pstResult->fWidth = vTextureSize.fX; pstResult->fHeight = vTextureSize.fY; } /* Has corner? */ else if(orxConfig_GetVector(orxGRAPHIC_KZ_CONFIG_TEXTURE_CORNER, &vTextureOrigin) != orxNULL) { /* Stores them */ pstResult->fLeft = vTextureOrigin.fX; pstResult->fTop = vTextureOrigin.fY; pstResult->fWidth = vTextureSize.fX; pstResult->fHeight = vTextureSize.fY; } else { /* Updates size */ orxGraphic_UpdateSize(pstResult); } } else { /* Updates size */ orxGraphic_UpdateSize(pstResult); } } else { /* Logs message */ orxDEBUG_PRINT(orxDEBUG_LEVEL_DISPLAY, "Couldn't link texture (%s) data to graphic (%s).", zName, _zConfigID); /* Deletes structures */ orxTexture_Delete(pstTexture); } } } /* Still no data? */ if(pstResult->pstData == orxNULL) { /* Gets text name */ zName = orxConfig_GetString(orxGRAPHIC_KZ_CONFIG_TEXT_NAME); /* Valid? */ if((zName != orxNULL) && (zName != orxSTRING_EMPTY)) { orxTEXT *pstText; /* Creates text */ pstText = orxText_CreateFromConfig(zName); /* Valid? */ if(pstText != orxNULL) { /* Links it */ if(orxGraphic_SetData(pstResult, (orxSTRUCTURE *)pstText) != orxSTATUS_FAILURE) { /* Sets its owner */ orxStructure_SetOwner(pstText, pstResult); /* Inits default text flags */ u32Flags = orxGRAPHIC_KU32_FLAG_INTERNAL | orxGRAPHIC_KU32_FLAG_TEXT; /* Updates size */ orxGraphic_UpdateSize(pstResult); } else { /* Logs message */ orxDEBUG_PRINT(orxDEBUG_LEVEL_DISPLAY, "Couldn't link text (%s) data to graphic (%s).", zName, _zConfigID); /* Deletes structures */ orxText_Delete(pstText); } } } } /* Has data? */ if(pstResult->pstData != orxNULL) { const orxSTRING zFlipping; orxVECTOR vPivot; /* Gets pivot value */ if(orxConfig_GetVector(orxGRAPHIC_KZ_CONFIG_PIVOT, &vPivot) != orxNULL) { /* Updates it */ orxGraphic_SetPivot(pstResult, &vPivot); } /* Has relative pivot point? */ else if(orxConfig_HasValue(orxGRAPHIC_KZ_CONFIG_PIVOT) != orxFALSE) { orxCHAR acBuffer[64]; orxSTRING zRelativePos; orxU32 u32AlignmentFlags = orxGRAPHIC_KU32_FLAG_ALIGN_CENTER; /* Gets lower case value */ acBuffer[sizeof(acBuffer) - 1] = orxCHAR_NULL; zRelativePos = orxString_LowerCase(orxString_NCopy(acBuffer, orxConfig_GetString(orxGRAPHIC_KZ_CONFIG_PIVOT), sizeof(acBuffer) - 1)); /* Left? */ if(orxString_SearchString(zRelativePos, orxGRAPHIC_KZ_LEFT_PIVOT) != orxNULL) { /* Updates alignment flags */ u32AlignmentFlags |= orxGRAPHIC_KU32_FLAG_ALIGN_LEFT; } /* Right? */ else if(orxString_SearchString(zRelativePos, orxGRAPHIC_KZ_RIGHT_PIVOT) != orxNULL) { /* Updates alignment flags */ u32AlignmentFlags |= orxGRAPHIC_KU32_FLAG_ALIGN_RIGHT; } /* Top? */ if(orxString_SearchString(zRelativePos, orxGRAPHIC_KZ_TOP_PIVOT) != orxNULL) { /* Updates alignment flags */ u32AlignmentFlags |= orxGRAPHIC_KU32_FLAG_ALIGN_TOP; } /* Bottom? */ else if(orxString_SearchString(zRelativePos, orxGRAPHIC_KZ_BOTTOM_PIVOT) != orxNULL) { /* Updates alignment flags */ u32AlignmentFlags |= orxGRAPHIC_KU32_FLAG_ALIGN_BOTTOM; } /* Truncate? */ if(orxString_SearchString(zRelativePos, orxGRAPHIC_KZ_TRUNCATE_PIVOT) != orxNULL) { /* Updates alignment flags */ u32AlignmentFlags |= orxGRAPHIC_KU32_FLAG_ALIGN_TRUNCATE; } /* Round? */ else if(orxString_SearchString(zRelativePos, orxGRAPHIC_KZ_ROUND_PIVOT) != orxNULL) { /* Updates alignment flags */ u32AlignmentFlags |= orxGRAPHIC_KU32_FLAG_ALIGN_ROUND; } /* Valid? */ if((u32AlignmentFlags != orxGRAPHIC_KU32_FLAG_ALIGN_CENTER) || (orxString_SearchString(zRelativePos, orxGRAPHIC_KZ_CENTERED_PIVOT) != orxNULL)) { /* Applies it */ orxGraphic_SetRelativePivot(pstResult, u32AlignmentFlags); } } /* Gets flipping value */ zFlipping = orxConfig_GetString(orxGRAPHIC_KZ_CONFIG_FLIP); /* X flipping? */ if(orxString_ICompare(zFlipping, orxGRAPHIC_KZ_X) == 0) { /* Updates frame flags */ u32Flags |= orxGRAPHIC_KU32_FLAG_FLIP_X; } /* Y flipping? */ else if(orxString_ICompare(zFlipping, orxGRAPHIC_KZ_Y) == 0) { /* Updates frame flags */ u32Flags |= orxGRAPHIC_KU32_FLAG_FLIP_Y; } /* Both flipping? */ else if(orxString_ICompare(zFlipping, orxGRAPHIC_KZ_BOTH) == 0) { /* Updates frame flags */ u32Flags |= orxGRAPHIC_KU32_FLAG_FLIP_X | orxGRAPHIC_KU32_FLAG_FLIP_Y; } /* Has color? */ if(orxConfig_HasValue(orxGRAPHIC_KZ_CONFIG_COLOR) != orxFALSE) { orxVECTOR vColor; /* Gets its value */ orxConfig_GetVector(orxGRAPHIC_KZ_CONFIG_COLOR, &vColor); /* Normalizes and applies it */ orxVector_Mulf(&(pstResult->stColor.vRGB), &vColor, orxCOLOR_NORMALIZER); /* Updates status */ orxStructure_SetFlags(pstResult, orxGRAPHIC_KU32_FLAG_HAS_COLOR, orxGRAPHIC_KU32_FLAG_NONE); } /* Has RGB values? */ else if(orxConfig_HasValue(orxGRAPHIC_KZ_CONFIG_RGB) != orxFALSE) { /* Gets its value */ orxConfig_GetVector(orxGRAPHIC_KZ_CONFIG_RGB, &(pstResult->stColor.vRGB)); /* Updates status */ orxStructure_SetFlags(pstResult, orxGRAPHIC_KU32_FLAG_HAS_COLOR, orxGRAPHIC_KU32_FLAG_NONE); } /* Has HSL values? */ else if(orxConfig_HasValue(orxGRAPHIC_KZ_CONFIG_HSL) != orxFALSE) { /* Gets its value */ orxConfig_GetVector(orxGRAPHIC_KZ_CONFIG_HSL, &(pstResult->stColor.vHSL)); /* Stores its RGB equivalent */ orxColor_FromHSLToRGB(&(pstResult->stColor), &(pstResult->stColor)); /* Updates status */ orxStructure_SetFlags(pstResult, orxGRAPHIC_KU32_FLAG_HAS_COLOR, orxGRAPHIC_KU32_FLAG_NONE); } /* Has HSV values? */ else if(orxConfig_HasValue(orxGRAPHIC_KZ_CONFIG_HSV) != orxFALSE) { /* Gets its value */ orxConfig_GetVector(orxGRAPHIC_KZ_CONFIG_HSV, &(pstResult->stColor.vHSV)); /* Stores its RGB equivalent */ orxColor_FromHSVToRGB(&(pstResult->stColor), &(pstResult->stColor)); /* Updates status */ orxStructure_SetFlags(pstResult, orxGRAPHIC_KU32_FLAG_HAS_COLOR, orxGRAPHIC_KU32_FLAG_NONE); } /* Has alpha? */ if(orxConfig_HasValue(orxGRAPHIC_KZ_CONFIG_ALPHA) != orxFALSE) { /* Applies it */ orxColor_SetAlpha(&(pstResult->stColor), orxConfig_GetFloat(orxGRAPHIC_KZ_CONFIG_ALPHA)); /* Updates status */ orxStructure_SetFlags(pstResult, orxGRAPHIC_KU32_FLAG_HAS_COLOR, orxGRAPHIC_KU32_FLAG_NONE); } /* Should repeat? */ if(orxConfig_HasValue(orxGRAPHIC_KZ_CONFIG_REPEAT) != orxFALSE) { orxVECTOR vRepeat; /* Gets its value */ orxConfig_GetVector(orxGRAPHIC_KZ_CONFIG_REPEAT, &vRepeat); /* Stores it */ orxGraphic_SetRepeat(pstResult, vRepeat.fX, vRepeat.fY); } /* Has smoothing value? */ if(orxConfig_HasValue(orxGRAPHIC_KZ_CONFIG_SMOOTHING) != orxFALSE) { /* Updates flags */ u32Flags |= (orxConfig_GetBool(orxGRAPHIC_KZ_CONFIG_SMOOTHING) != orxFALSE) ? orxGRAPHIC_KU32_FLAG_SMOOTHING_ON : orxGRAPHIC_KU32_FLAG_SMOOTHING_OFF; } /* Has blend mode? */ if(orxConfig_HasValue(orxGRAPHIC_KZ_CONFIG_BLEND_MODE) != orxFALSE) { const orxSTRING zBlendMode; orxDISPLAY_BLEND_MODE eBlendMode; /* Gets blend mode value */ zBlendMode = orxConfig_GetString(orxGRAPHIC_KZ_CONFIG_BLEND_MODE); eBlendMode = orxDisplay_GetBlendModeFromString(zBlendMode); /* Depending on blend mode */ switch(eBlendMode) { case orxDISPLAY_BLEND_MODE_ALPHA: { /* Updates flags */ u32Flags |= orxGRAPHIC_KU32_FLAG_BLEND_MODE_ALPHA; break; } case orxDISPLAY_BLEND_MODE_MULTIPLY: { /* Updates flags */ u32Flags |= orxGRAPHIC_KU32_FLAG_BLEND_MODE_MULTIPLY; break; } case orxDISPLAY_BLEND_MODE_ADD: { /* Updates flags */ u32Flags |= orxGRAPHIC_KU32_FLAG_BLEND_MODE_ADD; break; } case orxDISPLAY_BLEND_MODE_PREMUL: { /* Updates flags */ u32Flags |= orxGRAPHIC_KU32_FLAG_BLEND_MODE_PREMUL; break; } default: { } } } else { /* Defaults to alpha */ u32Flags |= orxGRAPHIC_KU32_FLAG_BLEND_MODE_ALPHA; } /* Stores its reference key */ pstResult->zReference = orxConfig_GetCurrentSection(); /* Protects it */ orxConfig_ProtectSection(pstResult->zReference, orxTRUE); /* Updates status flags */ orxStructure_SetFlags(pstResult, u32Flags, orxGRAPHIC_KU32_FLAG_NONE); } else { /* Logs message */ orxDEBUG_PRINT(orxDEBUG_LEVEL_DISPLAY, "Couldn't get text or texture for graphic (%s).", _zConfigID); /* Deletes structures */ orxGraphic_Delete(pstResult); /* Updates result */ pstResult = orxNULL; } } /* Pops previous section */ orxConfig_PopSection(); } else { /* Logs message */ orxDEBUG_PRINT(orxDEBUG_LEVEL_DISPLAY, "Couldn't find config section named (%s).", _zConfigID); /* Updates result */ pstResult = orxNULL; } /* Done! */ return pstResult; }