/** Wheel callback */ static void GLFWCALL orxMouse_GLFW_MouseWheelCallback(int _iWheel) { /* Updates wheel moves */ sstMouse.fWheelMove += orxS2F(_iWheel - sstMouse.s32WheelPos); sstMouse.fInternalWheelMove += orxS2F(_iWheel - sstMouse.s32WheelPos); /* Stores last wheel position */ sstMouse.s32WheelPos = _iWheel; /* Done! */ return; }
/** Position callback */ static void GLFWCALL orxMouse_GLFW_MousePositionCallback(int _iX, int _iY) { /* Updates mouse move */ sstMouse.vMouseMove.fX += orxS2F(_iX) - sstMouse.vMouseBackup.fX + sstMouse.vMouseAcc.fX; sstMouse.vMouseMove.fY += orxS2F(_iY) - sstMouse.vMouseBackup.fY + sstMouse.vMouseAcc.fY; /* Stores last mouse position */ sstMouse.vMouseBackup.fX = orxS2F(_iX); sstMouse.vMouseBackup.fY = orxS2F(_iY); /* Clears mouse accumulator */ sstMouse.vMouseAcc.fX = sstMouse.vMouseAcc.fY = orxFLOAT_0; /* Done! */ return; }
orxSTATUS orxFASTCALL orxDisplay_SDL_GetBitmapSize(const orxBITMAP *_pstBitmap, orxFLOAT *_pfWidth, orxFLOAT *_pfHeight) { orxSTATUS eResult = orxSTATUS_SUCCESS; /* Checks */ orxASSERT((sstDisplay.u32Flags & orxDISPLAY_KU32_STATIC_FLAG_READY) == orxDISPLAY_KU32_STATIC_FLAG_READY); orxASSERT(_pstBitmap != orxNULL); orxASSERT(_pfWidth != orxNULL); orxASSERT(_pfHeight != orxNULL); /* Gets size */ *_pfWidth = orxS2F(((SDL_Surface *)_pstBitmap)->w); *_pfHeight = orxS2F(((SDL_Surface *)_pstBitmap)->h); /* Done! */ return eResult; }
static orxSTATUS orxFASTCALL ProcessFontParams(orxU32 _u32ParamCount, const orxSTRING _azParams[]) { orxSTATUS eResult = orxSTATUS_FAILURE; // Has a valid font parameter? if(_u32ParamCount > 1) { // Inits FreeType if(!FT_Init_FreeType(&sstFontGen.pstFontLibrary)) { // Loads font's default face if(!FT_New_Face(sstFontGen.pstFontLibrary, _azParams[1], 0, &sstFontGen.pstFontFace)) { // Sets unicode map if(!FT_Select_Charmap(sstFontGen.pstFontFace, ft_encoding_unicode)) { // Updates character size sstFontGen.vCharacterSize.fX = sstFontGen.vCharacterSize.fY; // Updates character spacing sstFontGen.vCharacterSpacing.fX = orx2F(2.0f); sstFontGen.vCharacterSpacing.fY = orx2F(2.0f); // Stores scale sstFontGen.fFontScale = sstFontGen.vCharacterSize.fY / orxS2F(sstFontGen.pstFontFace->bbox.yMax - sstFontGen.pstFontFace->bbox.yMin); // Sets pixel's size eResult = FT_Set_Pixel_Sizes(sstFontGen.pstFontFace, (FT_UInt)orxF2U(sstFontGen.vCharacterSize.fX) - 2, (FT_UInt)orxF2U(sstFontGen.vCharacterSize.fY) - 2) ? orxSTATUS_FAILURE : orxSTATUS_SUCCESS; } } } // Success? if(eResult != orxSTATUS_FAILURE) { // Updates status orxFLAG_SET(sstFontGen.u32Flags, orxFONTGEN_KU32_STATIC_FLAG_FONT, orxFONTGEN_KU32_STATIC_FLAG_NONE); // Logs message orxFONTGEN_LOG(FONT, "Using font '%s'.", _azParams[1]); } else { // Logs message orxFONTGEN_LOG(FONT, "Couldn't load font '%s'.", _azParams[1]); } } else { // Logs message orxFONTGEN_LOG(FONT, "No font specified, aborting."); } // Done! return eResult; }
orxVECTOR *orxFASTCALL orxMouse_GLFW_GetPosition(orxVECTOR *_pvPosition) { orxS32 s32X, s32Y; orxVECTOR *pvResult = _pvPosition; /* Checks */ orxASSERT((sstMouse.u32Flags & orxMOUSE_KU32_STATIC_FLAG_READY) == orxMOUSE_KU32_STATIC_FLAG_READY); orxASSERT(_pvPosition != orxNULL); /* Gets mouse position */ glfwGetMousePos((int *)&s32X, (int *)&s32Y); /* Updates result */ _pvPosition->fX = orxS2F(s32X); _pvPosition->fY = orxS2F(s32Y); _pvPosition->fZ = orxFLOAT_0; /* Done! */ return pvResult; }
orxSTATUS orxFASTCALL orxMouse_GLFW_SetPosition(const orxVECTOR *_pvPosition) { orxS32 s32X, s32Y; orxSTATUS eResult = orxSTATUS_SUCCESS; /* Checks */ orxASSERT((sstMouse.u32Flags & orxMOUSE_KU32_STATIC_FLAG_READY) == orxMOUSE_KU32_STATIC_FLAG_READY); /* Gets mouse position */ glfwGetMousePos((int *)&s32X, (int *)&s32Y); /* Updates accumulator */ sstMouse.vMouseAcc.fX += orxS2F(s32X) - _pvPosition->fX; sstMouse.vMouseAcc.fY += orxS2F(s32Y) - _pvPosition->fY; /* Moves mouse */ glfwSetMousePos((int)orxF2S(_pvPosition->fX), (int)orxF2S(_pvPosition->fY)); /* Done! */ return eResult; }
{ // Gets character width s32CharacterWidth = sstFontGen.pstFontFace->glyph->advance.x >> 6; } else { // Gets character width s32CharacterWidth = orxMAX((orxS32)sstFontGen.pstFontFace->glyph->bitmap_left, 0) + (orxS32)sstFontGen.pstFontFace->glyph->bitmap.width; } // Updates largest character width s32LargestWidth = orxMAX(s32LargestWidth, s32CharacterWidth); } // Updates character width sstFontGen.vCharacterSize.fX = orxS2F(s32LargestWidth); } // Gets width & height fWidth = orxMath_Floor(orxMath_Sqrt(orxU2F(u32Counter))); fHeight = orxMath_Ceil(orxU2F(u32Counter) / fWidth); s32Width = orxF2S((fWidth * (sstFontGen.vCharacterSize.fX + sstFontGen.fPadding)) + (sstFontGen.vCharacterSpacing.fX * orxMAX(fWidth - orxFLOAT_1, orxFLOAT_0))); s32Height = orxF2S((fHeight * (sstFontGen.vCharacterSize.fY + sstFontGen.fPadding)) + (sstFontGen.vCharacterSpacing.fY * orxMAX(fHeight - orxFLOAT_1, orxFLOAT_0))); // Is not monospaced? if(!orxFLAG_TEST(sstFontGen.u32Flags, orxFONTGEN_KU32_STATIC_FLAG_MONOSPACE)) { orxS32 s32X, s32Y; orxFONTGEN_GLYPH *pstGlyph; // For all defined glyphs
/** Displays trail */ static void orxBounce_DisplayTrail(const orxBITMAP *_pstBitmap) { #define STORE_VERTEX(INDEX, X, Y, U, V, RGBA) astVertexList[INDEX].fX = X; astVertexList[INDEX].fY = Y; astVertexList[INDEX].fU = U; astVertexList[INDEX].fV = V; astVertexList[INDEX].stRGBA = RGBA; orxDISPLAY_VERTEX astVertexList[TRAIL_POINT_NUMBER * 2]; orxVECTOR vOffset; orxU32 i; /* For all points */ for(i = 0; i < TRAIL_POINT_NUMBER; i++) { orxVECTOR vVertex1, vVertex2; orxU32 u32Index, u32NextIndex; /* Gets barrel indices */ u32Index = (i + su32TrailIndex) % TRAIL_POINT_NUMBER; u32NextIndex = (i + 1 + su32TrailIndex) % TRAIL_POINT_NUMBER; /* Not at the end? */ if(i < TRAIL_POINT_NUMBER - 1) { /* Gets offset vector */ orxVector_Mulf(&vOffset, orxVector_Normalize(&vOffset, orxVector_2DRotate(&vOffset, orxVector_Sub(&vOffset, &savTrailPointList[u32NextIndex], &savTrailPointList[u32Index]), orxMATH_KF_PI_BY_2)), orx2F(40.0f) / orxMath_Pow(orxS2F(i), orx2F(0.6f))); } /* Computes vertices positions */ orxVector_Add(&vVertex1, &savTrailPointList[u32Index], &vOffset); orxVector_Sub(&vVertex2, &savTrailPointList[u32Index], &vOffset); /* Stores vertices */ STORE_VERTEX(i * 2, vVertex1.fX, vVertex1.fY, orxFLOAT_0, orxU2F(i) / orxU2F(TRAIL_POINT_NUMBER - 1), orx2RGBA(0xFF, 0xFF, 0xFF, 0xFF * i / (TRAIL_POINT_NUMBER + 50))); STORE_VERTEX(i * 2 + 1, vVertex2.fX, vVertex2.fY, orxFLOAT_1, orxU2F(i) / orxU2F(TRAIL_POINT_NUMBER - 1), orx2RGBA(0xFF, 0xFF, 0xFF, 0xFF * i / (TRAIL_POINT_NUMBER + 50))); } /* Draws trail */ orxDisplay_DrawMesh(_pstBitmap, orxDISPLAY_SMOOTHING_ON, orxDISPLAY_BLEND_MODE_ALPHA, TRAIL_POINT_NUMBER * 2, astVertexList); }
/** Gets a random orxS32 value * @param[in] _s32Min Minimum boundary * @param[in] _s32Max Maximum boundary * @return Random value */ orxS32 orxFASTCALL orxMath_GetRandomS32(orxS32 _s32Min, orxS32 _s32Max) { orxU32 u32Rand; /* Gets raw random number */ u32Rand = rand(); /* Done! */ return (u32Rand == RAND_MAX) ? _s32Max : (orxF2S((orx2F(u32Rand) * (orx2F(1.0f / RAND_MAX)) * (orxS2F(_s32Max) + 1 - orxS2F(_s32Min))) + orxS2F(_s32Min))); }