float WI_Number::DrawPercent(float x, float y, int n) { if (n < 0) return x; pcent->Draw(x, y, FB); return Draw(x, y, n, -1); }
void Sprite_Draw(SpriteObj* sprite, const Sprite::DrawParams* params) { if (!SpriteResource_CheckCreated(sprite->resource)) return; // Get animation instance SpriteObj::AnimationInstance* animationInstance = NULL; for (std::vector<SpriteObj::AnimationInstance>::iterator it = sprite->animationInstances.begin(); it != sprite->animationInstances.end(); ++it) if (it->mode != Sprite::AnimationMode_OnceWhenDone && it->mode != Sprite::AnimationMode_LoopWhenDone && (!animationInstance || it->weight > animationInstance->weight)) animationInstance = &(*it); Assert(animationInstance); // Determine textures to draw Texture* texture0 = NULL; Texture* texture1 = NULL; Shape::DrawParams texParams; float lerp = 0.0f; float uv[8] = { 0, 0, 1, 0, 1, 1, 0, 1 }; if (params->texCoordRect) { uv[0] = params->texCoordRect->left; uv[1] = params->texCoordRect->top; uv[2] = params->texCoordRect->Right(); uv[3] = params->texCoordRect->top; uv[4] = params->texCoordRect->Right(); uv[5] = params->texCoordRect->Bottom(); uv[6] = params->texCoordRect->left; uv[7] = params->texCoordRect->Bottom(); } if (params->flipX) for (int i = 0; i < 8; i += 2) uv[i] = 1.0f - uv[i]; if (params->flipY) for (int i = 1; i < 8; i += 2) uv[i] = 1.0f - uv[i]; SpriteResource::Animation* animation = animationInstance->animation; if (animation->frames.size() == 1) { texture0 = &animation->frames[0].texture; texParams.color = params->color; texParams.SetNumVerts(4); texParams.SetTexCoord(uv); } else { const float numFramesF = (float) animation->frames.size(); const float frameIndexF = numFramesF * (animationInstance->time / animation->totalTime); const float firstFrameIndexF = floorf(frameIndexF); const int firstFrameIndex = clamp((int) firstFrameIndexF, (int) 0, (int) animation->frames.size() - 1); const int nextFrameIndex = (firstFrameIndex + 1) % animation->frames.size(); SpriteResource::Frame& firstFrame = animation->frames[firstFrameIndex]; SpriteResource::Frame& nextFrame = animation->frames[nextFrameIndex]; texture0 = &firstFrame.texture; texture1 = &nextFrame.texture; texParams.SetNumVerts(4); texParams.SetTexCoord(uv, 0); texParams.SetTexCoord(uv, 1); lerp = frameIndexF - firstFrameIndexF; } float xy[8] = { params->position.x, params->position.y, params->position.x + sprite->resource->width * params->scale, params->position.y, params->position.x + sprite->resource->width * params->scale, params->position.y + sprite->resource->height * params->scale, params->position.x, params->position.y + sprite->resource->height * params->scale }; if (params->rect) { xy[0] = params->rect->left; xy[1] = params->rect->top; xy[2] = params->rect->Right(); xy[3] = params->rect->top; xy[4] = params->rect->Right(); xy[5] = params->rect->Bottom(); xy[6] = params->rect->left; xy[7] = params->rect->Bottom(); } if (params->rotation != 0) { const float centerX = (xy[0] + xy[2]) * 0.5f; const float centerY = (xy[1] + xy[5]) * 0.5f; const float rotationSin = sinf(params->rotation); const float rotationCos = cosf(params->rotation); float* xyPtr = xy; for (int i = 0; i < 4; i++, xyPtr += 2) Vertex_Rotate(xyPtr[0], xyPtr[1], centerX, centerY, rotationSin, rotationCos); } texParams.SetPosition(xy); // Draw #if 0 if (texture1) Texture_DrawBlended(texture0, texture1, &texParams, lerp); else Texture_Draw(texture0, &texParams); #else Material* material = &sprite->resource->material; if (!material->IsValid()) material = &App::GetDefaultMaterial(); material->SetFloatParameter("Color", (const float*) &texParams.color, 4); if (texture1) { material->SetTechnique("tex_lerp_col"); material->SetTextureParameter("ColorMap0", *texture0); material->SetTextureParameter("ColorMap1", *texture1); material->SetFloatParameter("Scale", &lerp); material->Draw(&texParams); } else { material->SetTechnique("tex_col"); material->SetTextureParameter("ColorMap", *texture0); material->Draw(&texParams); } #endif }