float Animator::_calculateValue(float k) { if (this->delay > 0.0f) { return (this->discreteStep != 0 ? (float)((int)(this->offset / this->discreteStep) * this->discreteStep) : this->offset); } float time = this->timer; if (this->isExpired()) { if (this->reset) { return (this->discreteStep != 0 ? (float)((int)(this->offset / this->discreteStep) * this->discreteStep) : this->offset); } time = this->periods / habs(this->speed); } float result = 0.0f; switch (this->animationFunction) { case Object::Linear: result = time * this->speed * this->amplitude; break; case Object::Sine: result = (float)dsin(time * this->speed * 360) * this->amplitude; break; case Object::Square: result = (hmodf(time * this->speed, 1.0f) < 0.5f ? this->amplitude : -this->amplitude); break; case Object::Saw: result = (hmodf(time * this->speed + 0.5f, 1.0f) - 0.5f) * 2 * this->amplitude; break; case Object::Triangle: result = hmodf(time * this->speed, 1.0f); if (!is_in_range(result, 0.25f, 0.75f)) { result = (hmodf(time * this->speed + 0.5f, 1.0f) - 0.5f) * 4 * this->amplitude; } else { result = -(hmodf(time * this->speed - 0.25f, 1.0f) - 0.25f) * 4 * this->amplitude; } break; case Object::Random: result = hrandf(-this->speed * this->amplitude, this->speed * this->amplitude); break; case Object::Hover: if ((this->amplitude >= 0.0f) == this->parent->isCursorInside()) { result = hmin(this->value - this->offset + k * this->speed, (float)habs(this->amplitude)); } else { result = hmax(this->value - this->offset - k * this->speed, -(float)habs(this->amplitude)); } break; case Object::Custom: result = (this->customFunction != NULL ? this->customFunction(this, time) : this->value); break; } return (this->discreteStep != 0 ? (float)((int)((result + this->offset) / this->discreteStep) * this->discreteStep) : (result + this->offset)); }
void ProgressCircle::OnDraw() { ImageBox::OnDraw(); float progress = hclamp(this->progress, 0.0f, 1.0f); april::Color color = this->_getDrawColor(); color.a = (unsigned char)(color.a * this->_getDisabledAlphaFactor()); if (this->progressImage != NULL) { grect rect = this->_getDrawRect(); if (progress == 1.0f) { this->progressImage->draw(rect, color); } else if (progress > 0.0f) { gvec2 p0; gvec2 p1; gvec2 splitCenter; gvec2 topLeft; gvec2 topRight; gvec2 bottomLeft; gvec2 bottomRight; switch (this->direction) { case Clockwise: splitCenter.set(1.0f, 0.5f); topLeft.set(0.0f, 1.0f); topRight.set(1.0f, 1.0f); bottomLeft.set(0.0f, 0.0f); bottomRight.set(1.0f, 0.0f); break; case Clockwise90: splitCenter.set(0.5f, 0.0f); topLeft.set(1.0f, 1.0f); topRight.set(1.0f, 0.0f); bottomLeft.set(0.0f, 1.0f); bottomRight.set(0.0f, 0.0f); break; case Clockwise180: splitCenter.set(0.0f, 0.5f); topLeft.set(1.0f, 0.0f); topRight.set(0.0f, 0.0f); bottomLeft.set(1.0f, 1.0f); bottomRight.set(0.0f, 1.0f); break; case Clockwise270: splitCenter.set(0.5f, 1.0f); topLeft.set(0.0f, 0.0f); topRight.set(0.0f, 1.0f); bottomLeft.set(1.0f, 0.0f); bottomRight.set(1.0f, 1.0f); break; case Counterclockwise: splitCenter.set(1.0f, 0.5f); topLeft.set(0.0f, 0.0f); topRight.set(1.0f, 0.0f); bottomLeft.set(0.0f, 1.0f); bottomRight.set(1.0f, 1.0f); break; case Counterclockwise90: splitCenter.set(0.5f, 0.0f); topLeft.set(0.0f, 1.0f); topRight.set(0.0f, 0.0f); bottomLeft.set(1.0f, 1.0f); bottomRight.set(1.0f, 0.0f); break; case Counterclockwise180: splitCenter.set(0.0f, 0.5f); topLeft.set(1.0f, 1.0f); topRight.set(0.0f, 1.0f); bottomLeft.set(1.0f, 0.0f); bottomRight.set(0.0f, 0.0f); break; case Counterclockwise270: splitCenter.set(0.5f, 1.0f); topLeft.set(1.0f, 0.0f); topRight.set(1.0f, 1.0f); bottomLeft.set(0.0f, 0.0f); bottomRight.set(0.0f, 1.0f); break; } harray<april::TexturedVertex> vertices; vertices += MAKE_VERTEX(gvec2(0.5f, 0.5f)); vertices += MAKE_VERTEX(splitCenter); april::TexturedVertex vertex; p0 = bottomRight; p1 = topRight; if (progress > 0.125f) { vertex = MAKE_VERTEX(topRight); vertices += vertex; vertices += vertices.first(); vertices += vertex; p0 = topRight; p1 = topLeft; } if (progress > 0.375f) { vertex = MAKE_VERTEX(topLeft); vertices += vertex; vertices += vertices.first(); vertices += vertex; p0 = topLeft; p1 = bottomLeft; } if (progress > 0.625f) { vertex = MAKE_VERTEX(bottomLeft); vertices += vertex; vertices += vertices.first(); vertices += vertex; p0 = bottomLeft; p1 = bottomRight; } if (progress > 0.875f) { vertex = MAKE_VERTEX(bottomRight); vertices += vertex; vertices += vertices.first(); vertices += vertex; p0 = bottomRight; p1 = topRight; } double angle = hmodf(progress * 360.0f + 45.0f, 90.0f) - 45.0f; // angle will always be between -45° and 45° so there is no risk here float ratio = (float)dtan(angle) * 0.5f + 0.5f; p0 += (p1 - p0) * ratio; vertices += MAKE_VERTEX(p0); this->progressImage->draw(vertices, color); } } if (this->maskImage != NULL) { this->maskImage->draw(this->_getDrawRect(), color); } }