mirror of
https://github.com/FunKey-Project/RetroFE.git
synced 2026-03-19 10:22:42 +01:00
Setting code formatting standard to allman.
This commit is contained in:
@@ -11,360 +11,360 @@ std::map<std::string, TweenAlgorithm> Tween::TweenTypeMap;
|
||||
std::map<std::string, TweenProperty> Tween::TweenPropertyMap;
|
||||
|
||||
Tween::Tween(TweenProperty property, TweenAlgorithm type, double start, double end, double duration)
|
||||
: Property(property)
|
||||
, Type(type)
|
||||
, Start(start)
|
||||
, End(end)
|
||||
, Duration(duration)
|
||||
: Property(property)
|
||||
, Type(type)
|
||||
, Start(start)
|
||||
, End(end)
|
||||
, Duration(duration)
|
||||
{
|
||||
}
|
||||
|
||||
TweenProperty Tween::GetProperty() const
|
||||
{
|
||||
return Property;
|
||||
return Property;
|
||||
}
|
||||
|
||||
|
||||
bool Tween::GetTweenProperty(std::string name, TweenProperty &property)
|
||||
{
|
||||
bool retVal = false;
|
||||
bool retVal = false;
|
||||
|
||||
if(TweenPropertyMap.size() == 0)
|
||||
{
|
||||
TweenPropertyMap["x"] = TWEEN_PROPERTY_X;
|
||||
TweenPropertyMap["y"] = TWEEN_PROPERTY_Y;
|
||||
TweenPropertyMap["angle"] = TWEEN_PROPERTY_ANGLE;
|
||||
TweenPropertyMap["transparency"] = TWEEN_PROPERTY_TRANSPARENCY;
|
||||
TweenPropertyMap["width"] = TWEEN_PROPERTY_WIDTH;
|
||||
TweenPropertyMap["height"] = TWEEN_PROPERTY_HEIGHT;
|
||||
TweenPropertyMap["xorigin"] = TWEEN_PROPERTY_X_ORIGIN;
|
||||
TweenPropertyMap["yorigin"] = TWEEN_PROPERTY_Y_ORIGIN;
|
||||
TweenPropertyMap["xoffset"] = TWEEN_PROPERTY_X_OFFSET;
|
||||
TweenPropertyMap["yoffset"] = TWEEN_PROPERTY_Y_OFFSET;
|
||||
TweenPropertyMap["fontSize"] = TWEEN_PROPERTY_FONT_SIZE;
|
||||
}
|
||||
if(TweenPropertyMap.size() == 0)
|
||||
{
|
||||
TweenPropertyMap["x"] = TWEEN_PROPERTY_X;
|
||||
TweenPropertyMap["y"] = TWEEN_PROPERTY_Y;
|
||||
TweenPropertyMap["angle"] = TWEEN_PROPERTY_ANGLE;
|
||||
TweenPropertyMap["transparency"] = TWEEN_PROPERTY_TRANSPARENCY;
|
||||
TweenPropertyMap["width"] = TWEEN_PROPERTY_WIDTH;
|
||||
TweenPropertyMap["height"] = TWEEN_PROPERTY_HEIGHT;
|
||||
TweenPropertyMap["xorigin"] = TWEEN_PROPERTY_X_ORIGIN;
|
||||
TweenPropertyMap["yorigin"] = TWEEN_PROPERTY_Y_ORIGIN;
|
||||
TweenPropertyMap["xoffset"] = TWEEN_PROPERTY_X_OFFSET;
|
||||
TweenPropertyMap["yoffset"] = TWEEN_PROPERTY_Y_OFFSET;
|
||||
TweenPropertyMap["fontSize"] = TWEEN_PROPERTY_FONT_SIZE;
|
||||
}
|
||||
|
||||
std::transform(name.begin(), name.end(), name.begin(), ::tolower);
|
||||
std::transform(name.begin(), name.end(), name.begin(), ::tolower);
|
||||
|
||||
if(TweenPropertyMap.find(name) != TweenPropertyMap.end())
|
||||
{
|
||||
property = TweenPropertyMap[name];
|
||||
retVal = true;
|
||||
}
|
||||
if(TweenPropertyMap.find(name) != TweenPropertyMap.end())
|
||||
{
|
||||
property = TweenPropertyMap[name];
|
||||
retVal = true;
|
||||
}
|
||||
|
||||
return retVal;
|
||||
return retVal;
|
||||
}
|
||||
|
||||
|
||||
TweenAlgorithm Tween::GetTweenType(std::string name)
|
||||
{
|
||||
if(TweenTypeMap.size() == 0)
|
||||
{
|
||||
TweenTypeMap["easeinquadratic"] = EASE_IN_QUADRATIC;
|
||||
TweenTypeMap["easeoutquadratic"] = EASE_OUT_QUADRATIC;
|
||||
TweenTypeMap["easeinoutquadratic"] = EASE_INOUT_QUADRATIC;
|
||||
TweenTypeMap["easeincubic"] = EASE_IN_CUBIC;
|
||||
TweenTypeMap["easeoutcubic"] = EASE_OUT_CUBIC;
|
||||
TweenTypeMap["easeinoutcubic"] = EASE_INOUT_CUBIC;
|
||||
TweenTypeMap["easeinquartic"] = EASE_IN_QUARTIC;
|
||||
TweenTypeMap["easeoutquartic"] = EASE_OUT_QUARTIC;
|
||||
TweenTypeMap["easeinoutquartic"] = EASE_INOUT_QUARTIC;
|
||||
TweenTypeMap["easeinquintic"] = EASE_IN_QUINTIC;
|
||||
TweenTypeMap["easeoutquintic"] = EASE_OUT_QUINTIC;
|
||||
TweenTypeMap["easeinoutquintic"] = EASE_INOUT_QUINTIC;
|
||||
TweenTypeMap["easeinsine"] = EASE_IN_SINE;
|
||||
TweenTypeMap["easeoutsine"] = EASE_OUT_SINE;
|
||||
TweenTypeMap["easeinoutsine"] = EASE_INOUT_SINE;
|
||||
TweenTypeMap["easeinexponential"] = EASE_IN_EXPONENTIAL;
|
||||
TweenTypeMap["easeoutexponential"] = EASE_OUT_EXPONENTIAL;
|
||||
TweenTypeMap["easeinoutexponential"] = EASE_INOUT_EXPONENTIAL;
|
||||
TweenTypeMap["easeincircular"] = EASE_IN_CIRCULAR;
|
||||
TweenTypeMap["easeoutcircular"] = EASE_OUT_CIRCULAR;
|
||||
TweenTypeMap["easeinoutcircular"] = EASE_INOUT_CIRCULAR;
|
||||
TweenTypeMap["linear"] = LINEAR;
|
||||
}
|
||||
if(TweenTypeMap.size() == 0)
|
||||
{
|
||||
TweenTypeMap["easeinquadratic"] = EASE_IN_QUADRATIC;
|
||||
TweenTypeMap["easeoutquadratic"] = EASE_OUT_QUADRATIC;
|
||||
TweenTypeMap["easeinoutquadratic"] = EASE_INOUT_QUADRATIC;
|
||||
TweenTypeMap["easeincubic"] = EASE_IN_CUBIC;
|
||||
TweenTypeMap["easeoutcubic"] = EASE_OUT_CUBIC;
|
||||
TweenTypeMap["easeinoutcubic"] = EASE_INOUT_CUBIC;
|
||||
TweenTypeMap["easeinquartic"] = EASE_IN_QUARTIC;
|
||||
TweenTypeMap["easeoutquartic"] = EASE_OUT_QUARTIC;
|
||||
TweenTypeMap["easeinoutquartic"] = EASE_INOUT_QUARTIC;
|
||||
TweenTypeMap["easeinquintic"] = EASE_IN_QUINTIC;
|
||||
TweenTypeMap["easeoutquintic"] = EASE_OUT_QUINTIC;
|
||||
TweenTypeMap["easeinoutquintic"] = EASE_INOUT_QUINTIC;
|
||||
TweenTypeMap["easeinsine"] = EASE_IN_SINE;
|
||||
TweenTypeMap["easeoutsine"] = EASE_OUT_SINE;
|
||||
TweenTypeMap["easeinoutsine"] = EASE_INOUT_SINE;
|
||||
TweenTypeMap["easeinexponential"] = EASE_IN_EXPONENTIAL;
|
||||
TweenTypeMap["easeoutexponential"] = EASE_OUT_EXPONENTIAL;
|
||||
TweenTypeMap["easeinoutexponential"] = EASE_INOUT_EXPONENTIAL;
|
||||
TweenTypeMap["easeincircular"] = EASE_IN_CIRCULAR;
|
||||
TweenTypeMap["easeoutcircular"] = EASE_OUT_CIRCULAR;
|
||||
TweenTypeMap["easeinoutcircular"] = EASE_INOUT_CIRCULAR;
|
||||
TweenTypeMap["linear"] = LINEAR;
|
||||
}
|
||||
|
||||
std::transform(name.begin(), name.end(), name.begin(), ::tolower);
|
||||
std::transform(name.begin(), name.end(), name.begin(), ::tolower);
|
||||
|
||||
if(TweenTypeMap.find(name) != TweenTypeMap.end())
|
||||
{
|
||||
return TweenTypeMap[name];
|
||||
}
|
||||
else
|
||||
{
|
||||
return TweenTypeMap["linear"];
|
||||
}
|
||||
if(TweenTypeMap.find(name) != TweenTypeMap.end())
|
||||
{
|
||||
return TweenTypeMap[name];
|
||||
}
|
||||
else
|
||||
{
|
||||
return TweenTypeMap["linear"];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
float Tween::Animate(double elapsedTime)
|
||||
{
|
||||
return AnimateSingle(Type, Start, End, Duration, elapsedTime);
|
||||
return AnimateSingle(Type, Start, End, Duration, elapsedTime);
|
||||
}
|
||||
|
||||
//todo: SDL likes floats, consider having casting being performed elsewhere
|
||||
float Tween::AnimateSingle(TweenAlgorithm type, double start, double end, double duration, double elapsedTime)
|
||||
{
|
||||
double a = start;
|
||||
double b = end - start;
|
||||
double result = 0;
|
||||
double a = start;
|
||||
double b = end - start;
|
||||
double result = 0;
|
||||
|
||||
switch(type)
|
||||
{
|
||||
case EASE_IN_QUADRATIC:
|
||||
result = EaseInQuadratic(elapsedTime, duration, a, b);
|
||||
break;
|
||||
switch(type)
|
||||
{
|
||||
case EASE_IN_QUADRATIC:
|
||||
result = EaseInQuadratic(elapsedTime, duration, a, b);
|
||||
break;
|
||||
|
||||
case EASE_OUT_QUADRATIC:
|
||||
result = EaseOutQuadratic(elapsedTime, duration, a, b);
|
||||
break;
|
||||
case EASE_OUT_QUADRATIC:
|
||||
result = EaseOutQuadratic(elapsedTime, duration, a, b);
|
||||
break;
|
||||
|
||||
case EASE_INOUT_QUADRATIC:
|
||||
result = EaseInOutQuadratic(elapsedTime, duration, a, b);
|
||||
break;
|
||||
case EASE_INOUT_QUADRATIC:
|
||||
result = EaseInOutQuadratic(elapsedTime, duration, a, b);
|
||||
break;
|
||||
|
||||
case EASE_IN_CUBIC:
|
||||
result = EaseInCubic(elapsedTime, duration, a, b);
|
||||
break;
|
||||
case EASE_IN_CUBIC:
|
||||
result = EaseInCubic(elapsedTime, duration, a, b);
|
||||
break;
|
||||
|
||||
case EASE_OUT_CUBIC:
|
||||
result = EaseOutCubic(elapsedTime, duration, a, b);
|
||||
break;
|
||||
case EASE_OUT_CUBIC:
|
||||
result = EaseOutCubic(elapsedTime, duration, a, b);
|
||||
break;
|
||||
|
||||
case EASE_INOUT_CUBIC:
|
||||
result = EaseInOutCubic(elapsedTime, duration, a, b);
|
||||
break;
|
||||
case EASE_INOUT_CUBIC:
|
||||
result = EaseInOutCubic(elapsedTime, duration, a, b);
|
||||
break;
|
||||
|
||||
case EASE_IN_QUARTIC:
|
||||
result = EaseInQuartic(elapsedTime, duration, a, b);
|
||||
break;
|
||||
case EASE_IN_QUARTIC:
|
||||
result = EaseInQuartic(elapsedTime, duration, a, b);
|
||||
break;
|
||||
|
||||
case EASE_OUT_QUARTIC:
|
||||
result = EaseOutQuartic(elapsedTime, duration, a, b);
|
||||
break;
|
||||
case EASE_OUT_QUARTIC:
|
||||
result = EaseOutQuartic(elapsedTime, duration, a, b);
|
||||
break;
|
||||
|
||||
case EASE_INOUT_QUARTIC:
|
||||
result = EaseInOutQuartic(elapsedTime, duration, a, b);
|
||||
break;
|
||||
case EASE_INOUT_QUARTIC:
|
||||
result = EaseInOutQuartic(elapsedTime, duration, a, b);
|
||||
break;
|
||||
|
||||
case EASE_IN_QUINTIC:
|
||||
result = EaseInQuintic(elapsedTime, duration, a, b);
|
||||
break;
|
||||
case EASE_IN_QUINTIC:
|
||||
result = EaseInQuintic(elapsedTime, duration, a, b);
|
||||
break;
|
||||
|
||||
case EASE_OUT_QUINTIC:
|
||||
result = EaseOutQuintic(elapsedTime, duration, a, b);
|
||||
break;
|
||||
case EASE_OUT_QUINTIC:
|
||||
result = EaseOutQuintic(elapsedTime, duration, a, b);
|
||||
break;
|
||||
|
||||
case EASE_INOUT_QUINTIC:
|
||||
result = EaseInOutQuintic(elapsedTime, duration, a, b);
|
||||
break;
|
||||
case EASE_INOUT_QUINTIC:
|
||||
result = EaseInOutQuintic(elapsedTime, duration, a, b);
|
||||
break;
|
||||
|
||||
case EASE_IN_SINE:
|
||||
result = EaseInSine(elapsedTime, duration, a, b);
|
||||
break;
|
||||
case EASE_IN_SINE:
|
||||
result = EaseInSine(elapsedTime, duration, a, b);
|
||||
break;
|
||||
|
||||
case EASE_OUT_SINE:
|
||||
result = EaseOutSine(elapsedTime, duration, a, b);
|
||||
break;
|
||||
case EASE_OUT_SINE:
|
||||
result = EaseOutSine(elapsedTime, duration, a, b);
|
||||
break;
|
||||
|
||||
case EASE_INOUT_SINE:
|
||||
result = EaseInOutSine(elapsedTime, duration, a, b);
|
||||
break;
|
||||
case EASE_INOUT_SINE:
|
||||
result = EaseInOutSine(elapsedTime, duration, a, b);
|
||||
break;
|
||||
|
||||
case EASE_IN_EXPONENTIAL:
|
||||
result = EaseInExponential(elapsedTime, duration, a, b);
|
||||
break;
|
||||
case EASE_IN_EXPONENTIAL:
|
||||
result = EaseInExponential(elapsedTime, duration, a, b);
|
||||
break;
|
||||
|
||||
case EASE_OUT_EXPONENTIAL:
|
||||
result = EaseOutExponential(elapsedTime, duration, a, b);
|
||||
break;
|
||||
case EASE_OUT_EXPONENTIAL:
|
||||
result = EaseOutExponential(elapsedTime, duration, a, b);
|
||||
break;
|
||||
|
||||
case EASE_INOUT_EXPONENTIAL:
|
||||
result = EaseInOutExponential(elapsedTime, duration, a, b);
|
||||
break;
|
||||
case EASE_INOUT_EXPONENTIAL:
|
||||
result = EaseInOutExponential(elapsedTime, duration, a, b);
|
||||
break;
|
||||
|
||||
case EASE_IN_CIRCULAR:
|
||||
result = EaseInCircular(elapsedTime, duration, a, b);
|
||||
break;
|
||||
case EASE_IN_CIRCULAR:
|
||||
result = EaseInCircular(elapsedTime, duration, a, b);
|
||||
break;
|
||||
|
||||
case EASE_OUT_CIRCULAR:
|
||||
result = EaseOutCircular(elapsedTime, duration, a, b);
|
||||
break;
|
||||
case EASE_OUT_CIRCULAR:
|
||||
result = EaseOutCircular(elapsedTime, duration, a, b);
|
||||
break;
|
||||
|
||||
case EASE_INOUT_CIRCULAR:
|
||||
result = EaseInOutCircular(elapsedTime, duration, a, b);
|
||||
break;
|
||||
case EASE_INOUT_CIRCULAR:
|
||||
result = EaseInOutCircular(elapsedTime, duration, a, b);
|
||||
break;
|
||||
|
||||
case LINEAR:
|
||||
default:
|
||||
result = Linear(elapsedTime, duration, a, b);
|
||||
break;
|
||||
}
|
||||
case LINEAR:
|
||||
default:
|
||||
result = Linear(elapsedTime, duration, a, b);
|
||||
break;
|
||||
}
|
||||
|
||||
return static_cast<float>(result);
|
||||
return static_cast<float>(result);
|
||||
|
||||
}
|
||||
|
||||
double Tween::Linear(double t, double d, double b, double c)
|
||||
{
|
||||
if(d == 0) return b;
|
||||
return c*t/d + b;
|
||||
if(d == 0) return b;
|
||||
return c*t/d + b;
|
||||
};
|
||||
|
||||
double Tween::EaseInQuadratic(double t, double d, double b, double c)
|
||||
{
|
||||
if(d == 0) return b;
|
||||
t /= d;
|
||||
return c*t*t + b;
|
||||
if(d == 0) return b;
|
||||
t /= d;
|
||||
return c*t*t + b;
|
||||
};
|
||||
|
||||
double Tween::EaseOutQuadratic(double t, double d, double b, double c)
|
||||
{
|
||||
if(d == 0) return b;
|
||||
t /= d;
|
||||
return -c * t*(t-2) + b;
|
||||
if(d == 0) return b;
|
||||
t /= d;
|
||||
return -c * t*(t-2) + b;
|
||||
};
|
||||
|
||||
double Tween::EaseInOutQuadratic(double t, double d, double b, double c)
|
||||
{
|
||||
if(d == 0) return b;
|
||||
t /= d/2;
|
||||
if (t < 1) return c/2*t*t + b;
|
||||
t--;
|
||||
return -c/2 * (t*(t-2) - 1) + b;
|
||||
if(d == 0) return b;
|
||||
t /= d/2;
|
||||
if (t < 1) return c/2*t*t + b;
|
||||
t--;
|
||||
return -c/2 * (t*(t-2) - 1) + b;
|
||||
};
|
||||
|
||||
double Tween::EaseInCubic(double t, double d, double b, double c)
|
||||
{
|
||||
if(d == 0) return b;
|
||||
t /= d;
|
||||
return c*t*t*t + b;
|
||||
if(d == 0) return b;
|
||||
t /= d;
|
||||
return c*t*t*t + b;
|
||||
};
|
||||
|
||||
double Tween::EaseOutCubic(double t, double d, double b, double c)
|
||||
{
|
||||
if(d == 0) return b;
|
||||
t /= d;
|
||||
t--;
|
||||
return c*(t*t*t + 1) + b;
|
||||
if(d == 0) return b;
|
||||
t /= d;
|
||||
t--;
|
||||
return c*(t*t*t + 1) + b;
|
||||
};
|
||||
|
||||
double Tween::EaseInOutCubic(double t, double d, double b, double c)
|
||||
{
|
||||
if(d == 0) return b;
|
||||
t /= d/2;
|
||||
if (t < 1) return c/2*t*t*t + b;
|
||||
t -= 2;
|
||||
return c/2*(t*t*t + 2) + b;
|
||||
if(d == 0) return b;
|
||||
t /= d/2;
|
||||
if (t < 1) return c/2*t*t*t + b;
|
||||
t -= 2;
|
||||
return c/2*(t*t*t + 2) + b;
|
||||
};
|
||||
|
||||
double Tween::EaseInQuartic(double t, double d, double b, double c)
|
||||
{
|
||||
if(d == 0) return b;
|
||||
t /= d;
|
||||
return c*t*t*t*t + b;
|
||||
if(d == 0) return b;
|
||||
t /= d;
|
||||
return c*t*t*t*t + b;
|
||||
};
|
||||
|
||||
double Tween::EaseOutQuartic(double t, double d, double b, double c)
|
||||
{
|
||||
if(d == 0) return b;
|
||||
t /= d;
|
||||
t--;
|
||||
return -c * (t*t*t*t - 1) + b;
|
||||
if(d == 0) return b;
|
||||
t /= d;
|
||||
t--;
|
||||
return -c * (t*t*t*t - 1) + b;
|
||||
};
|
||||
|
||||
double Tween::EaseInOutQuartic(double t, double d, double b, double c)
|
||||
{
|
||||
if(d == 0) return b;
|
||||
t /= d/2;
|
||||
if (t < 1) return c/2*t*t*t*t + b;
|
||||
t -= 2;
|
||||
return -c/2 * (t*t*t*t - 2) + b;
|
||||
if(d == 0) return b;
|
||||
t /= d/2;
|
||||
if (t < 1) return c/2*t*t*t*t + b;
|
||||
t -= 2;
|
||||
return -c/2 * (t*t*t*t - 2) + b;
|
||||
};
|
||||
|
||||
double Tween::EaseInQuintic(double t, double d, double b, double c)
|
||||
{
|
||||
if(d == 0) return b;
|
||||
t /= d;
|
||||
return c*t*t*t*t*t + b;
|
||||
if(d == 0) return b;
|
||||
t /= d;
|
||||
return c*t*t*t*t*t + b;
|
||||
};
|
||||
|
||||
|
||||
double Tween::EaseOutQuintic(double t, double d, double b, double c)
|
||||
{
|
||||
if(d == 0) return b;
|
||||
t /= d;
|
||||
t--;
|
||||
return c*(t*t*t*t*t + 1) + b;
|
||||
if(d == 0) return b;
|
||||
t /= d;
|
||||
t--;
|
||||
return c*(t*t*t*t*t + 1) + b;
|
||||
};
|
||||
|
||||
double Tween::EaseInOutQuintic(double t, double d, double b, double c)
|
||||
{
|
||||
if(d == 0) return b;
|
||||
t /= d/2;
|
||||
if (t < 1) return c/2*t*t*t*t*t + b;
|
||||
t -= 2;
|
||||
return c/2*(t*t*t*t*t + 2) + b;
|
||||
if(d == 0) return b;
|
||||
t /= d/2;
|
||||
if (t < 1) return c/2*t*t*t*t*t + b;
|
||||
t -= 2;
|
||||
return c/2*(t*t*t*t*t + 2) + b;
|
||||
};
|
||||
|
||||
double Tween::EaseInSine(double t, double d, double b, double c)
|
||||
{
|
||||
return -c * cos(t/d * (M_PI/2)) + c + b;
|
||||
return -c * cos(t/d * (M_PI/2)) + c + b;
|
||||
};
|
||||
|
||||
double Tween::EaseOutSine(double t, double d, double b, double c)
|
||||
{
|
||||
return c * sin(t/d * (M_PI/2)) + b;
|
||||
return c * sin(t/d * (M_PI/2)) + b;
|
||||
};
|
||||
|
||||
double Tween::EaseInOutSine(double t, double d, double b, double c)
|
||||
{
|
||||
return -c/2 * (cos( M_PI*t/d) - 1) + b;
|
||||
return -c/2 * (cos( M_PI*t/d) - 1) + b;
|
||||
};
|
||||
|
||||
double Tween::EaseInExponential(double t, double d, double b, double c)
|
||||
{
|
||||
return c * pow( 2, 10 * (t/d - 1) ) + b;
|
||||
return c * pow( 2, 10 * (t/d - 1) ) + b;
|
||||
};
|
||||
|
||||
double Tween::EaseOutExponential(double t, double d, double b, double c)
|
||||
{
|
||||
return c * ( - pow( 2, -10 * t/d ) + 1 ) + b;
|
||||
return c * ( - pow( 2, -10 * t/d ) + 1 ) + b;
|
||||
};
|
||||
|
||||
double Tween::EaseInOutExponential(double t, double d, double b, double c)
|
||||
{
|
||||
t /= d/2;
|
||||
if (t < 1) return c/2 * pow( 2, 10 * (t - 1) ) + b;
|
||||
t--;
|
||||
return c/2 * ( -1* pow( 2, -10 * t) + 2 ) + b;
|
||||
t /= d/2;
|
||||
if (t < 1) return c/2 * pow( 2, 10 * (t - 1) ) + b;
|
||||
t--;
|
||||
return c/2 * ( -1* pow( 2, -10 * t) + 2 ) + b;
|
||||
};
|
||||
|
||||
double Tween::EaseInCircular(double t, double d, double b, double c)
|
||||
{
|
||||
t /= d;
|
||||
return -c * (sqrt(1 - t*t) - 1) + b;
|
||||
t /= d;
|
||||
return -c * (sqrt(1 - t*t) - 1) + b;
|
||||
};
|
||||
|
||||
|
||||
double Tween::EaseOutCircular(double t, double d, double b, double c)
|
||||
{
|
||||
t /= d;
|
||||
t--;
|
||||
return c * sqrt(1 - t*t) + b;
|
||||
t /= d;
|
||||
t--;
|
||||
return c * sqrt(1 - t*t) + b;
|
||||
};
|
||||
|
||||
double Tween::EaseInOutCircular(double t, double d, double b, double c)
|
||||
{
|
||||
t /= d/2;
|
||||
if (t < 1) return -c/2 * (sqrt(1 - t*t) - 1) + b;
|
||||
t -= 2;
|
||||
return c/2 * (sqrt(1 - t*t) + 1) + b;
|
||||
t /= d/2;
|
||||
if (t < 1) return -c/2 * (sqrt(1 - t*t) - 1) + b;
|
||||
t -= 2;
|
||||
return c/2 * (sqrt(1 - t*t) + 1) + b;
|
||||
}
|
||||
;
|
||||
|
||||
//todo: sdl requires floats, should the casting be done at this layer?
|
||||
float Tween::GetDuration() const
|
||||
{
|
||||
return static_cast<float>(Duration);
|
||||
return static_cast<float>(Duration);
|
||||
}
|
||||
|
||||
@@ -13,43 +13,43 @@ class Tween
|
||||
{
|
||||
public:
|
||||
|
||||
Tween(TweenProperty name, TweenAlgorithm type, double start, double end, double duration);
|
||||
float Animate(double elapsedTime);
|
||||
static float AnimateSingle(TweenAlgorithm type, double start, double end, double duration, double elapsedTime);
|
||||
static TweenAlgorithm GetTweenType(std::string name);
|
||||
static bool GetTweenProperty(std::string name, TweenProperty &property);
|
||||
TweenProperty GetProperty() const;
|
||||
float GetDuration() const;
|
||||
Tween(TweenProperty name, TweenAlgorithm type, double start, double end, double duration);
|
||||
float Animate(double elapsedTime);
|
||||
static float AnimateSingle(TweenAlgorithm type, double start, double end, double duration, double elapsedTime);
|
||||
static TweenAlgorithm GetTweenType(std::string name);
|
||||
static bool GetTweenProperty(std::string name, TweenProperty &property);
|
||||
TweenProperty GetProperty() const;
|
||||
float GetDuration() const;
|
||||
|
||||
private:
|
||||
static double EaseInQuadratic(double elapsedTime, double duration, double b, double c);
|
||||
static double EaseOutQuadratic(double elapsedTime, double duration, double b, double c);
|
||||
static double EaseInOutQuadratic(double elapsedTime, double duration, double b, double c);
|
||||
static double EaseInCubic(double elapsedTime, double duration, double b, double c);
|
||||
static double EaseOutCubic(double elapsedTime, double duration, double b, double c);
|
||||
static double EaseInOutCubic(double elapsedTime, double duration, double b, double c);
|
||||
static double EaseInQuartic(double elapsedTime, double duration, double b, double c);
|
||||
static double EaseOutQuartic(double elapsedTime, double duration, double b, double c);
|
||||
static double EaseInOutQuartic(double elapsedTime, double duration, double b, double c);
|
||||
static double EaseInQuintic(double elapsedTime, double duration, double b, double c);
|
||||
static double EaseOutQuintic(double elapsedTime, double duration, double b, double c);
|
||||
static double EaseInOutQuintic(double elapsedTime, double duration, double b, double c);
|
||||
static double EaseInSine(double elapsedTime, double duration, double b, double c);
|
||||
static double EaseOutSine(double elapsedTime, double duration, double b, double c);
|
||||
static double EaseInOutSine(double elapsedTime, double duration, double b, double c);
|
||||
static double EaseInExponential(double elapsedTime, double duration, double b, double c);
|
||||
static double EaseOutExponential(double elapsedTime, double duration, double b, double c);
|
||||
static double EaseInOutExponential(double elapsedTime, double duration, double b, double c);
|
||||
static double EaseInCircular(double elapsedTime, double duration, double b, double c);
|
||||
static double EaseOutCircular(double elapsedTime, double duration, double b, double c);
|
||||
static double EaseInOutCircular(double elapsedTime, double duration, double b, double c);
|
||||
static double Linear(double elapsedTime, double duration, double b, double c);
|
||||
static double EaseInQuadratic(double elapsedTime, double duration, double b, double c);
|
||||
static double EaseOutQuadratic(double elapsedTime, double duration, double b, double c);
|
||||
static double EaseInOutQuadratic(double elapsedTime, double duration, double b, double c);
|
||||
static double EaseInCubic(double elapsedTime, double duration, double b, double c);
|
||||
static double EaseOutCubic(double elapsedTime, double duration, double b, double c);
|
||||
static double EaseInOutCubic(double elapsedTime, double duration, double b, double c);
|
||||
static double EaseInQuartic(double elapsedTime, double duration, double b, double c);
|
||||
static double EaseOutQuartic(double elapsedTime, double duration, double b, double c);
|
||||
static double EaseInOutQuartic(double elapsedTime, double duration, double b, double c);
|
||||
static double EaseInQuintic(double elapsedTime, double duration, double b, double c);
|
||||
static double EaseOutQuintic(double elapsedTime, double duration, double b, double c);
|
||||
static double EaseInOutQuintic(double elapsedTime, double duration, double b, double c);
|
||||
static double EaseInSine(double elapsedTime, double duration, double b, double c);
|
||||
static double EaseOutSine(double elapsedTime, double duration, double b, double c);
|
||||
static double EaseInOutSine(double elapsedTime, double duration, double b, double c);
|
||||
static double EaseInExponential(double elapsedTime, double duration, double b, double c);
|
||||
static double EaseOutExponential(double elapsedTime, double duration, double b, double c);
|
||||
static double EaseInOutExponential(double elapsedTime, double duration, double b, double c);
|
||||
static double EaseInCircular(double elapsedTime, double duration, double b, double c);
|
||||
static double EaseOutCircular(double elapsedTime, double duration, double b, double c);
|
||||
static double EaseInOutCircular(double elapsedTime, double duration, double b, double c);
|
||||
static double Linear(double elapsedTime, double duration, double b, double c);
|
||||
|
||||
static std::map<std::string, TweenAlgorithm> TweenTypeMap;
|
||||
static std::map<std::string, TweenProperty> TweenPropertyMap;
|
||||
TweenProperty Property;
|
||||
TweenAlgorithm Type;
|
||||
double Start;
|
||||
double End;
|
||||
double Duration;
|
||||
static std::map<std::string, TweenAlgorithm> TweenTypeMap;
|
||||
static std::map<std::string, TweenProperty> TweenPropertyMap;
|
||||
TweenProperty Property;
|
||||
TweenAlgorithm Type;
|
||||
double Start;
|
||||
double End;
|
||||
double Duration;
|
||||
};
|
||||
|
||||
@@ -1,45 +1,45 @@
|
||||
/* This file is subject to the terms and conditions defined in
|
||||
* file 'LICENSE.txt', which is part of this source code package.
|
||||
/* This file is subject to the terms and conditions defined in
|
||||
* file 'LICENSE.txt', which is part of this source code package.
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
enum TweenAlgorithm
|
||||
{
|
||||
LINEAR,
|
||||
EASE_IN_QUADRATIC,
|
||||
EASE_OUT_QUADRATIC,
|
||||
EASE_INOUT_QUADRATIC,
|
||||
EASE_IN_CUBIC,
|
||||
EASE_OUT_CUBIC,
|
||||
EASE_INOUT_CUBIC,
|
||||
EASE_IN_QUARTIC,
|
||||
EASE_OUT_QUARTIC,
|
||||
EASE_INOUT_QUARTIC,
|
||||
EASE_IN_QUINTIC,
|
||||
EASE_OUT_QUINTIC,
|
||||
EASE_INOUT_QUINTIC,
|
||||
EASE_IN_SINE,
|
||||
EASE_OUT_SINE,
|
||||
EASE_INOUT_SINE,
|
||||
EASE_IN_EXPONENTIAL,
|
||||
EASE_OUT_EXPONENTIAL,
|
||||
EASE_INOUT_EXPONENTIAL,
|
||||
EASE_IN_CIRCULAR,
|
||||
EASE_OUT_CIRCULAR,
|
||||
EASE_INOUT_CIRCULAR,
|
||||
LINEAR,
|
||||
EASE_IN_QUADRATIC,
|
||||
EASE_OUT_QUADRATIC,
|
||||
EASE_INOUT_QUADRATIC,
|
||||
EASE_IN_CUBIC,
|
||||
EASE_OUT_CUBIC,
|
||||
EASE_INOUT_CUBIC,
|
||||
EASE_IN_QUARTIC,
|
||||
EASE_OUT_QUARTIC,
|
||||
EASE_INOUT_QUARTIC,
|
||||
EASE_IN_QUINTIC,
|
||||
EASE_OUT_QUINTIC,
|
||||
EASE_INOUT_QUINTIC,
|
||||
EASE_IN_SINE,
|
||||
EASE_OUT_SINE,
|
||||
EASE_INOUT_SINE,
|
||||
EASE_IN_EXPONENTIAL,
|
||||
EASE_OUT_EXPONENTIAL,
|
||||
EASE_INOUT_EXPONENTIAL,
|
||||
EASE_IN_CIRCULAR,
|
||||
EASE_OUT_CIRCULAR,
|
||||
EASE_INOUT_CIRCULAR,
|
||||
};
|
||||
|
||||
enum TweenProperty
|
||||
{
|
||||
TWEEN_PROPERTY_HEIGHT,
|
||||
TWEEN_PROPERTY_WIDTH,
|
||||
TWEEN_PROPERTY_ANGLE,
|
||||
TWEEN_PROPERTY_TRANSPARENCY,
|
||||
TWEEN_PROPERTY_X,
|
||||
TWEEN_PROPERTY_Y,
|
||||
TWEEN_PROPERTY_X_ORIGIN,
|
||||
TWEEN_PROPERTY_Y_ORIGIN,
|
||||
TWEEN_PROPERTY_X_OFFSET,
|
||||
TWEEN_PROPERTY_Y_OFFSET,
|
||||
TWEEN_PROPERTY_FONT_SIZE
|
||||
TWEEN_PROPERTY_HEIGHT,
|
||||
TWEEN_PROPERTY_WIDTH,
|
||||
TWEEN_PROPERTY_ANGLE,
|
||||
TWEEN_PROPERTY_TRANSPARENCY,
|
||||
TWEEN_PROPERTY_X,
|
||||
TWEEN_PROPERTY_Y,
|
||||
TWEEN_PROPERTY_X_ORIGIN,
|
||||
TWEEN_PROPERTY_Y_ORIGIN,
|
||||
TWEEN_PROPERTY_X_OFFSET,
|
||||
TWEEN_PROPERTY_Y_OFFSET,
|
||||
TWEEN_PROPERTY_FONT_SIZE
|
||||
};
|
||||
|
||||
@@ -8,34 +8,34 @@
|
||||
|
||||
Component::Component()
|
||||
{
|
||||
OnEnterTweens = NULL;
|
||||
OnExitTweens = NULL;
|
||||
OnIdleTweens = NULL;
|
||||
OnHighlightEnterTweens = NULL;
|
||||
OnHighlightExitTweens = NULL;
|
||||
SelectedItem = NULL;
|
||||
NewItemSelectedSinceEnter = false;
|
||||
FreeGraphicsMemory();
|
||||
OnEnterTweens = NULL;
|
||||
OnExitTweens = NULL;
|
||||
OnIdleTweens = NULL;
|
||||
OnHighlightEnterTweens = NULL;
|
||||
OnHighlightExitTweens = NULL;
|
||||
SelectedItem = NULL;
|
||||
NewItemSelectedSinceEnter = false;
|
||||
FreeGraphicsMemory();
|
||||
|
||||
}
|
||||
|
||||
Component::~Component()
|
||||
{
|
||||
FreeGraphicsMemory();
|
||||
FreeGraphicsMemory();
|
||||
}
|
||||
|
||||
void Component::FreeGraphicsMemory()
|
||||
{
|
||||
CurrentAnimationState = HIDDEN;
|
||||
EnterRequested = false;
|
||||
ExitRequested = false;
|
||||
NewItemSelected = false;
|
||||
HighlightExitComplete = false;
|
||||
CurrentTweens = NULL;
|
||||
CurrentTweenIndex = 0;
|
||||
CurrentTweenComplete = false;
|
||||
ElapsedTweenTime =0;
|
||||
ScrollActive = false;
|
||||
CurrentAnimationState = HIDDEN;
|
||||
EnterRequested = false;
|
||||
ExitRequested = false;
|
||||
NewItemSelected = false;
|
||||
HighlightExitComplete = false;
|
||||
CurrentTweens = NULL;
|
||||
CurrentTweenIndex = 0;
|
||||
CurrentTweenComplete = false;
|
||||
ElapsedTweenTime =0;
|
||||
ScrollActive = false;
|
||||
}
|
||||
void Component::AllocateGraphicsMemory()
|
||||
{
|
||||
@@ -43,240 +43,240 @@ void Component::AllocateGraphicsMemory()
|
||||
|
||||
void Component::TriggerEnterEvent()
|
||||
{
|
||||
EnterRequested = true;
|
||||
EnterRequested = true;
|
||||
}
|
||||
|
||||
void Component::TriggerExitEvent()
|
||||
{
|
||||
ExitRequested = true;
|
||||
ExitRequested = true;
|
||||
}
|
||||
|
||||
void Component::TriggerHighlightEvent(Item *selectedItem)
|
||||
{
|
||||
NewItemSelected = true;
|
||||
this->SelectedItem = selectedItem;
|
||||
NewItemSelected = true;
|
||||
this->SelectedItem = selectedItem;
|
||||
}
|
||||
|
||||
|
||||
bool Component::IsIdle()
|
||||
{
|
||||
return (CurrentAnimationState == IDLE);
|
||||
return (CurrentAnimationState == IDLE);
|
||||
}
|
||||
|
||||
bool Component::IsHidden()
|
||||
{
|
||||
return (CurrentAnimationState == HIDDEN);
|
||||
return (CurrentAnimationState == HIDDEN);
|
||||
}
|
||||
bool Component::IsWaiting()
|
||||
{
|
||||
return (CurrentAnimationState == HIGHLIGHT_WAIT);
|
||||
return (CurrentAnimationState == HIGHLIGHT_WAIT);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Component::Update(float dt)
|
||||
{
|
||||
ElapsedTweenTime += dt;
|
||||
HighlightExitComplete = false;
|
||||
if(IsHidden() || IsWaiting() || (IsIdle() && ExitRequested))
|
||||
{
|
||||
CurrentTweenComplete = true;
|
||||
}
|
||||
ElapsedTweenTime += dt;
|
||||
HighlightExitComplete = false;
|
||||
if(IsHidden() || IsWaiting() || (IsIdle() && ExitRequested))
|
||||
{
|
||||
CurrentTweenComplete = true;
|
||||
}
|
||||
|
||||
if(CurrentTweenComplete)
|
||||
{
|
||||
CurrentTweens = NULL;
|
||||
if(CurrentTweenComplete)
|
||||
{
|
||||
CurrentTweens = NULL;
|
||||
|
||||
// There was no request to override our state path. Continue on as normal.
|
||||
switch(CurrentAnimationState)
|
||||
{
|
||||
case ENTER:
|
||||
// There was no request to override our state path. Continue on as normal.
|
||||
switch(CurrentAnimationState)
|
||||
{
|
||||
case ENTER:
|
||||
CurrentTweens = OnHighlightEnterTweens;
|
||||
CurrentAnimationState = HIGHLIGHT_ENTER;
|
||||
break;
|
||||
|
||||
case EXIT:
|
||||
case EXIT:
|
||||
CurrentTweens = NULL;
|
||||
CurrentAnimationState = HIDDEN;
|
||||
|
||||
break;
|
||||
|
||||
case HIGHLIGHT_ENTER:
|
||||
case HIGHLIGHT_ENTER:
|
||||
CurrentTweens = OnIdleTweens;
|
||||
CurrentAnimationState = IDLE;
|
||||
break;
|
||||
|
||||
case IDLE:
|
||||
case IDLE:
|
||||
// prevent us from automatically jumping to the exit tween upon enter
|
||||
if(EnterRequested)
|
||||
{
|
||||
EnterRequested = false;
|
||||
NewItemSelected = false;
|
||||
EnterRequested = false;
|
||||
NewItemSelected = false;
|
||||
}
|
||||
else if(IsScrollActive() || NewItemSelected || ExitRequested)
|
||||
{
|
||||
CurrentTweens = OnHighlightExitTweens;
|
||||
CurrentAnimationState = HIGHLIGHT_EXIT;
|
||||
CurrentTweens = OnHighlightExitTweens;
|
||||
CurrentAnimationState = HIGHLIGHT_EXIT;
|
||||
}
|
||||
else
|
||||
{
|
||||
CurrentTweens = OnIdleTweens;
|
||||
CurrentAnimationState = IDLE;
|
||||
CurrentTweens = OnIdleTweens;
|
||||
CurrentAnimationState = IDLE;
|
||||
}
|
||||
break;
|
||||
|
||||
case HIGHLIGHT_EXIT:
|
||||
case HIGHLIGHT_EXIT:
|
||||
|
||||
// intentionally break down
|
||||
case HIGHLIGHT_WAIT:
|
||||
// intentionally break down
|
||||
case HIGHLIGHT_WAIT:
|
||||
|
||||
if(ExitRequested && (CurrentAnimationState == HIGHLIGHT_WAIT))
|
||||
{
|
||||
CurrentTweens = OnHighlightExitTweens;
|
||||
CurrentAnimationState = HIGHLIGHT_EXIT;
|
||||
CurrentTweens = OnHighlightExitTweens;
|
||||
CurrentAnimationState = HIGHLIGHT_EXIT;
|
||||
|
||||
}
|
||||
else if(ExitRequested && (CurrentAnimationState == HIGHLIGHT_EXIT))
|
||||
{
|
||||
|
||||
CurrentTweens = OnExitTweens;
|
||||
CurrentAnimationState = EXIT;
|
||||
ExitRequested = false;
|
||||
CurrentTweens = OnExitTweens;
|
||||
CurrentAnimationState = EXIT;
|
||||
ExitRequested = false;
|
||||
}
|
||||
else if(IsScrollActive())
|
||||
{
|
||||
CurrentTweens = NULL;
|
||||
CurrentAnimationState = HIGHLIGHT_WAIT;
|
||||
CurrentTweens = NULL;
|
||||
CurrentAnimationState = HIGHLIGHT_WAIT;
|
||||
}
|
||||
else if(NewItemSelected)
|
||||
{
|
||||
CurrentTweens = OnHighlightEnterTweens;
|
||||
CurrentAnimationState = HIGHLIGHT_ENTER;
|
||||
HighlightExitComplete = true;
|
||||
NewItemSelected = false;
|
||||
CurrentTweens = OnHighlightEnterTweens;
|
||||
CurrentAnimationState = HIGHLIGHT_ENTER;
|
||||
HighlightExitComplete = true;
|
||||
NewItemSelected = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
CurrentTweens = NULL;
|
||||
CurrentAnimationState = HIGHLIGHT_WAIT;
|
||||
CurrentTweens = NULL;
|
||||
CurrentAnimationState = HIGHLIGHT_WAIT;
|
||||
}
|
||||
break;
|
||||
|
||||
case HIDDEN:
|
||||
case HIDDEN:
|
||||
if(EnterRequested || ExitRequested)
|
||||
{
|
||||
CurrentTweens = OnEnterTweens;
|
||||
CurrentAnimationState = ENTER;
|
||||
CurrentTweens = OnEnterTweens;
|
||||
CurrentAnimationState = ENTER;
|
||||
}
|
||||
else
|
||||
{
|
||||
CurrentTweens = NULL;
|
||||
CurrentAnimationState = HIDDEN;
|
||||
CurrentTweens = NULL;
|
||||
CurrentAnimationState = HIDDEN;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
CurrentTweenIndex = 0;
|
||||
CurrentTweenComplete = false;
|
||||
CurrentTweenIndex = 0;
|
||||
CurrentTweenComplete = false;
|
||||
|
||||
ElapsedTweenTime = 0;
|
||||
}
|
||||
ElapsedTweenTime = 0;
|
||||
}
|
||||
|
||||
CurrentTweenComplete = Animate(IsIdle());
|
||||
CurrentTweenComplete = Animate(IsIdle());
|
||||
}
|
||||
|
||||
|
||||
bool Component::Animate(bool loop)
|
||||
{
|
||||
bool completeDone = false;
|
||||
if(!CurrentTweens || CurrentTweenIndex >= CurrentTweens->size())
|
||||
{
|
||||
completeDone = true;
|
||||
}
|
||||
else if(CurrentTweens)
|
||||
{
|
||||
bool currentDone = true;
|
||||
std::vector<Tween *> *tweenSet = CurrentTweens->at(CurrentTweenIndex);
|
||||
bool completeDone = false;
|
||||
if(!CurrentTweens || CurrentTweenIndex >= CurrentTweens->size())
|
||||
{
|
||||
completeDone = true;
|
||||
}
|
||||
else if(CurrentTweens)
|
||||
{
|
||||
bool currentDone = true;
|
||||
std::vector<Tween *> *tweenSet = CurrentTweens->at(CurrentTweenIndex);
|
||||
|
||||
for(unsigned int i = 0; i < tweenSet->size(); i++)
|
||||
{
|
||||
Tween *tween = tweenSet->at(i);
|
||||
float elapsedTime = ElapsedTweenTime;
|
||||
for(unsigned int i = 0; i < tweenSet->size(); i++)
|
||||
{
|
||||
Tween *tween = tweenSet->at(i);
|
||||
float elapsedTime = ElapsedTweenTime;
|
||||
|
||||
//todo: too many levels of nesting
|
||||
if(elapsedTime < tween->GetDuration())
|
||||
{
|
||||
currentDone = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
elapsedTime = tween->GetDuration();
|
||||
}
|
||||
//todo: too many levels of nesting
|
||||
if(elapsedTime < tween->GetDuration())
|
||||
{
|
||||
currentDone = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
elapsedTime = tween->GetDuration();
|
||||
}
|
||||
|
||||
float value = tween->Animate(elapsedTime);
|
||||
float value = tween->Animate(elapsedTime);
|
||||
|
||||
switch(tween->GetProperty())
|
||||
{
|
||||
case TWEEN_PROPERTY_X:
|
||||
GetBaseViewInfo()->SetX(value);
|
||||
break;
|
||||
switch(tween->GetProperty())
|
||||
{
|
||||
case TWEEN_PROPERTY_X:
|
||||
GetBaseViewInfo()->SetX(value);
|
||||
break;
|
||||
|
||||
case TWEEN_PROPERTY_Y:
|
||||
GetBaseViewInfo()->SetY(value);
|
||||
break;
|
||||
case TWEEN_PROPERTY_Y:
|
||||
GetBaseViewInfo()->SetY(value);
|
||||
break;
|
||||
|
||||
case TWEEN_PROPERTY_HEIGHT:
|
||||
GetBaseViewInfo()->SetHeight(value);
|
||||
break;
|
||||
case TWEEN_PROPERTY_HEIGHT:
|
||||
GetBaseViewInfo()->SetHeight(value);
|
||||
break;
|
||||
|
||||
case TWEEN_PROPERTY_WIDTH:
|
||||
GetBaseViewInfo()->SetWidth(value);
|
||||
break;
|
||||
case TWEEN_PROPERTY_WIDTH:
|
||||
GetBaseViewInfo()->SetWidth(value);
|
||||
break;
|
||||
|
||||
case TWEEN_PROPERTY_ANGLE:
|
||||
GetBaseViewInfo()->SetAngle(value);
|
||||
break;
|
||||
case TWEEN_PROPERTY_ANGLE:
|
||||
GetBaseViewInfo()->SetAngle(value);
|
||||
break;
|
||||
|
||||
case TWEEN_PROPERTY_TRANSPARENCY:
|
||||
GetBaseViewInfo()->SetTransparency(value);
|
||||
break;
|
||||
case TWEEN_PROPERTY_TRANSPARENCY:
|
||||
GetBaseViewInfo()->SetTransparency(value);
|
||||
break;
|
||||
|
||||
case TWEEN_PROPERTY_X_ORIGIN:
|
||||
GetBaseViewInfo()->SetXOrigin(value);
|
||||
break;
|
||||
case TWEEN_PROPERTY_X_ORIGIN:
|
||||
GetBaseViewInfo()->SetXOrigin(value);
|
||||
break;
|
||||
|
||||
case TWEEN_PROPERTY_Y_ORIGIN:
|
||||
GetBaseViewInfo()->SetYOrigin(value);
|
||||
break;
|
||||
case TWEEN_PROPERTY_Y_ORIGIN:
|
||||
GetBaseViewInfo()->SetYOrigin(value);
|
||||
break;
|
||||
|
||||
case TWEEN_PROPERTY_X_OFFSET:
|
||||
GetBaseViewInfo()->SetXOffset(value);
|
||||
break;
|
||||
case TWEEN_PROPERTY_X_OFFSET:
|
||||
GetBaseViewInfo()->SetXOffset(value);
|
||||
break;
|
||||
|
||||
case TWEEN_PROPERTY_Y_OFFSET:
|
||||
GetBaseViewInfo()->SetYOffset(value);
|
||||
break;
|
||||
case TWEEN_PROPERTY_Y_OFFSET:
|
||||
GetBaseViewInfo()->SetYOffset(value);
|
||||
break;
|
||||
|
||||
case TWEEN_PROPERTY_FONT_SIZE:
|
||||
GetBaseViewInfo()->SetFontSize(value);
|
||||
break;
|
||||
}
|
||||
}
|
||||
case TWEEN_PROPERTY_FONT_SIZE:
|
||||
GetBaseViewInfo()->SetFontSize(value);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(currentDone)
|
||||
{
|
||||
CurrentTweenIndex++;
|
||||
ElapsedTweenTime = 0;
|
||||
}
|
||||
}
|
||||
if(currentDone)
|
||||
{
|
||||
CurrentTweenIndex++;
|
||||
ElapsedTweenTime = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if(!CurrentTweens || CurrentTweenIndex >= CurrentTweens->size())
|
||||
{
|
||||
if(loop)
|
||||
{
|
||||
CurrentTweenIndex = 0;
|
||||
}
|
||||
completeDone = true;
|
||||
}
|
||||
if(!CurrentTweens || CurrentTweenIndex >= CurrentTweens->size())
|
||||
{
|
||||
if(loop)
|
||||
{
|
||||
CurrentTweenIndex = 0;
|
||||
}
|
||||
completeDone = true;
|
||||
}
|
||||
|
||||
return completeDone;
|
||||
return completeDone;
|
||||
}
|
||||
|
||||
@@ -13,110 +13,110 @@
|
||||
class Component
|
||||
{
|
||||
public:
|
||||
Component();
|
||||
virtual ~Component();
|
||||
virtual void FreeGraphicsMemory();
|
||||
virtual void AllocateGraphicsMemory();
|
||||
virtual void LaunchEnter() {}
|
||||
virtual void LaunchExit() {}
|
||||
void TriggerEnterEvent();
|
||||
void TriggerExitEvent();
|
||||
void TriggerHighlightEvent(Item *selectedItem);
|
||||
bool IsIdle();
|
||||
bool IsHidden();
|
||||
bool IsWaiting();
|
||||
typedef std::vector<std::vector<Tween *> *> TweenSets;
|
||||
Component();
|
||||
virtual ~Component();
|
||||
virtual void FreeGraphicsMemory();
|
||||
virtual void AllocateGraphicsMemory();
|
||||
virtual void LaunchEnter() {}
|
||||
virtual void LaunchExit() {}
|
||||
void TriggerEnterEvent();
|
||||
void TriggerExitEvent();
|
||||
void TriggerHighlightEvent(Item *selectedItem);
|
||||
bool IsIdle();
|
||||
bool IsHidden();
|
||||
bool IsWaiting();
|
||||
typedef std::vector<std::vector<Tween *> *> TweenSets;
|
||||
|
||||
void SetOnEnterTweens(TweenSets *tweens)
|
||||
{
|
||||
this->OnEnterTweens = tweens;
|
||||
}
|
||||
void SetOnEnterTweens(TweenSets *tweens)
|
||||
{
|
||||
this->OnEnterTweens = tweens;
|
||||
}
|
||||
|
||||
void SetOnExitTweens(TweenSets *tweens)
|
||||
{
|
||||
this->OnExitTweens = tweens;
|
||||
}
|
||||
void SetOnExitTweens(TweenSets *tweens)
|
||||
{
|
||||
this->OnExitTweens = tweens;
|
||||
}
|
||||
|
||||
void SetOnIdleTweens(TweenSets *tweens)
|
||||
{
|
||||
this->OnIdleTweens = tweens;
|
||||
}
|
||||
void SetOnIdleTweens(TweenSets *tweens)
|
||||
{
|
||||
this->OnIdleTweens = tweens;
|
||||
}
|
||||
|
||||
void SetOnHighlightEnterTweens(TweenSets *tweens)
|
||||
{
|
||||
this->OnHighlightEnterTweens = tweens;
|
||||
}
|
||||
void SetOnHighlightEnterTweens(TweenSets *tweens)
|
||||
{
|
||||
this->OnHighlightEnterTweens = tweens;
|
||||
}
|
||||
|
||||
void SetOnHighlightExitTweens(TweenSets *tweens)
|
||||
{
|
||||
this->OnHighlightExitTweens = tweens;
|
||||
}
|
||||
virtual void Update(float dt);
|
||||
void SetOnHighlightExitTweens(TweenSets *tweens)
|
||||
{
|
||||
this->OnHighlightExitTweens = tweens;
|
||||
}
|
||||
virtual void Update(float dt);
|
||||
|
||||
virtual void Draw() = 0;
|
||||
virtual void Draw() = 0;
|
||||
|
||||
ViewInfo *GetBaseViewInfo()
|
||||
{
|
||||
return &BaseViewInfo;
|
||||
}
|
||||
void UpdateBaseViewInfo(ViewInfo &info)
|
||||
{
|
||||
BaseViewInfo = info;
|
||||
}
|
||||
ViewInfo *GetBaseViewInfo()
|
||||
{
|
||||
return &BaseViewInfo;
|
||||
}
|
||||
void UpdateBaseViewInfo(ViewInfo &info)
|
||||
{
|
||||
BaseViewInfo = info;
|
||||
}
|
||||
|
||||
bool IsScrollActive() const
|
||||
{
|
||||
return ScrollActive;
|
||||
}
|
||||
bool IsScrollActive() const
|
||||
{
|
||||
return ScrollActive;
|
||||
}
|
||||
|
||||
void SetScrollActive(bool scrollActive)
|
||||
{
|
||||
ScrollActive = scrollActive;
|
||||
}
|
||||
void SetScrollActive(bool scrollActive)
|
||||
{
|
||||
ScrollActive = scrollActive;
|
||||
}
|
||||
|
||||
|
||||
|
||||
protected:
|
||||
Item *GetSelectedItem()
|
||||
{
|
||||
return SelectedItem;
|
||||
}
|
||||
enum AnimationState
|
||||
{
|
||||
IDLE,
|
||||
ENTER,
|
||||
HIGHLIGHT_EXIT,
|
||||
HIGHLIGHT_WAIT,
|
||||
HIGHLIGHT_ENTER,
|
||||
EXIT,
|
||||
HIDDEN
|
||||
};
|
||||
Item *GetSelectedItem()
|
||||
{
|
||||
return SelectedItem;
|
||||
}
|
||||
enum AnimationState
|
||||
{
|
||||
IDLE,
|
||||
ENTER,
|
||||
HIGHLIGHT_EXIT,
|
||||
HIGHLIGHT_WAIT,
|
||||
HIGHLIGHT_ENTER,
|
||||
EXIT,
|
||||
HIDDEN
|
||||
};
|
||||
|
||||
AnimationState CurrentAnimationState;
|
||||
bool EnterRequested;
|
||||
bool ExitRequested;
|
||||
bool NewItemSelected;
|
||||
bool HighlightExitComplete;
|
||||
bool NewItemSelectedSinceEnter;
|
||||
AnimationState CurrentAnimationState;
|
||||
bool EnterRequested;
|
||||
bool ExitRequested;
|
||||
bool NewItemSelected;
|
||||
bool HighlightExitComplete;
|
||||
bool NewItemSelectedSinceEnter;
|
||||
private:
|
||||
bool Animate(bool loop);
|
||||
bool IsTweenSequencingComplete();
|
||||
void ResetTweenSequence(std::vector<ViewInfo *> *tweens);
|
||||
bool Animate(bool loop);
|
||||
bool IsTweenSequencingComplete();
|
||||
void ResetTweenSequence(std::vector<ViewInfo *> *tweens);
|
||||
|
||||
TweenSets *OnEnterTweens;
|
||||
TweenSets *OnExitTweens;
|
||||
TweenSets *OnIdleTweens;
|
||||
TweenSets *OnHighlightEnterTweens;
|
||||
TweenSets *OnHighlightExitTweens;
|
||||
TweenSets *OnEnterTweens;
|
||||
TweenSets *OnExitTweens;
|
||||
TweenSets *OnIdleTweens;
|
||||
TweenSets *OnHighlightEnterTweens;
|
||||
TweenSets *OnHighlightExitTweens;
|
||||
|
||||
TweenSets *CurrentTweens;
|
||||
unsigned int CurrentTweenIndex;
|
||||
TweenSets *CurrentTweens;
|
||||
unsigned int CurrentTweenIndex;
|
||||
|
||||
bool CurrentTweenComplete;
|
||||
ViewInfo BaseViewInfo;
|
||||
bool CurrentTweenComplete;
|
||||
ViewInfo BaseViewInfo;
|
||||
|
||||
float ElapsedTweenTime;
|
||||
Tween *TweenInst;
|
||||
Item *SelectedItem;
|
||||
bool ScrollActive;
|
||||
float ElapsedTweenTime;
|
||||
Tween *TweenInst;
|
||||
Item *SelectedItem;
|
||||
bool ScrollActive;
|
||||
};
|
||||
|
||||
@@ -8,68 +8,68 @@
|
||||
#include <SDL2/SDL_image.h>
|
||||
|
||||
Image::Image(std::string file, float scaleX, float scaleY)
|
||||
: Texture(NULL)
|
||||
, File(file)
|
||||
, ScaleX(scaleX)
|
||||
, ScaleY(scaleY)
|
||||
: Texture(NULL)
|
||||
, File(file)
|
||||
, ScaleX(scaleX)
|
||||
, ScaleY(scaleY)
|
||||
{
|
||||
AllocateGraphicsMemory();
|
||||
AllocateGraphicsMemory();
|
||||
}
|
||||
|
||||
Image::~Image()
|
||||
{
|
||||
FreeGraphicsMemory();
|
||||
FreeGraphicsMemory();
|
||||
}
|
||||
|
||||
void Image::FreeGraphicsMemory()
|
||||
{
|
||||
Component::FreeGraphicsMemory();
|
||||
Component::FreeGraphicsMemory();
|
||||
|
||||
SDL_LockMutex(SDL::GetMutex());
|
||||
if (Texture != NULL)
|
||||
{
|
||||
SDL_DestroyTexture(Texture);
|
||||
Texture = NULL;
|
||||
}
|
||||
SDL_UnlockMutex(SDL::GetMutex());
|
||||
SDL_LockMutex(SDL::GetMutex());
|
||||
if (Texture != NULL)
|
||||
{
|
||||
SDL_DestroyTexture(Texture);
|
||||
Texture = NULL;
|
||||
}
|
||||
SDL_UnlockMutex(SDL::GetMutex());
|
||||
}
|
||||
|
||||
void Image::AllocateGraphicsMemory()
|
||||
{
|
||||
int width;
|
||||
int height;
|
||||
int width;
|
||||
int height;
|
||||
|
||||
Component::AllocateGraphicsMemory();
|
||||
Component::AllocateGraphicsMemory();
|
||||
|
||||
if(!Texture)
|
||||
{
|
||||
SDL_LockMutex(SDL::GetMutex());
|
||||
Texture = IMG_LoadTexture(SDL::GetRenderer(), File.c_str());
|
||||
if(!Texture)
|
||||
{
|
||||
SDL_LockMutex(SDL::GetMutex());
|
||||
Texture = IMG_LoadTexture(SDL::GetRenderer(), File.c_str());
|
||||
|
||||
if (Texture != NULL)
|
||||
{
|
||||
SDL_SetTextureBlendMode(Texture, SDL_BLENDMODE_BLEND);
|
||||
SDL_QueryTexture(Texture, NULL, NULL, &width, &height);
|
||||
GetBaseViewInfo()->SetImageWidth(width * ScaleX);
|
||||
GetBaseViewInfo()->SetImageHeight(height * ScaleY);
|
||||
}
|
||||
SDL_UnlockMutex(SDL::GetMutex());
|
||||
if (Texture != NULL)
|
||||
{
|
||||
SDL_SetTextureBlendMode(Texture, SDL_BLENDMODE_BLEND);
|
||||
SDL_QueryTexture(Texture, NULL, NULL, &width, &height);
|
||||
GetBaseViewInfo()->SetImageWidth(width * ScaleX);
|
||||
GetBaseViewInfo()->SetImageHeight(height * ScaleY);
|
||||
}
|
||||
SDL_UnlockMutex(SDL::GetMutex());
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Image::Draw()
|
||||
{
|
||||
if(Texture)
|
||||
{
|
||||
ViewInfo *info = GetBaseViewInfo();
|
||||
SDL_Rect rect;
|
||||
if(Texture)
|
||||
{
|
||||
ViewInfo *info = GetBaseViewInfo();
|
||||
SDL_Rect rect;
|
||||
|
||||
rect.x = static_cast<int>(info->GetXRelativeToOrigin());
|
||||
rect.y = static_cast<int>(info->GetYRelativeToOrigin());
|
||||
rect.h = static_cast<int>(info->GetHeight());
|
||||
rect.w = static_cast<int>(info->GetWidth());
|
||||
rect.x = static_cast<int>(info->GetXRelativeToOrigin());
|
||||
rect.y = static_cast<int>(info->GetYRelativeToOrigin());
|
||||
rect.h = static_cast<int>(info->GetHeight());
|
||||
rect.w = static_cast<int>(info->GetWidth());
|
||||
|
||||
SDL::RenderCopy(Texture, static_cast<char>((info->GetTransparency() * 255)), NULL, &rect, info->GetAngle());
|
||||
}
|
||||
SDL::RenderCopy(Texture, static_cast<char>((info->GetTransparency() * 255)), NULL, &rect, info->GetAngle());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,15 +10,15 @@
|
||||
class Image : public Component
|
||||
{
|
||||
public:
|
||||
Image(std::string file, float scaleX, float scaleY);
|
||||
virtual ~Image();
|
||||
void FreeGraphicsMemory();
|
||||
void AllocateGraphicsMemory();
|
||||
void Draw();
|
||||
Image(std::string file, float scaleX, float scaleY);
|
||||
virtual ~Image();
|
||||
void FreeGraphicsMemory();
|
||||
void AllocateGraphicsMemory();
|
||||
void Draw();
|
||||
|
||||
protected:
|
||||
SDL_Texture *Texture;
|
||||
std::string File;
|
||||
float ScaleX;
|
||||
float ScaleY;
|
||||
SDL_Texture *Texture;
|
||||
std::string File;
|
||||
float ScaleX;
|
||||
float ScaleY;
|
||||
};
|
||||
|
||||
@@ -8,23 +8,23 @@
|
||||
|
||||
Image * ImageBuilder::CreateImage(std::string path, std::string name, float scaleX, float scaleY)
|
||||
{
|
||||
Image *image = NULL;
|
||||
std::vector<std::string> extensions;
|
||||
Image *image = NULL;
|
||||
std::vector<std::string> extensions;
|
||||
|
||||
extensions.push_back("png");
|
||||
extensions.push_back("PNG");
|
||||
extensions.push_back("jpg");
|
||||
extensions.push_back("JPG");
|
||||
extensions.push_back("jpeg");
|
||||
extensions.push_back("JPEG");
|
||||
extensions.push_back("png");
|
||||
extensions.push_back("PNG");
|
||||
extensions.push_back("jpg");
|
||||
extensions.push_back("JPG");
|
||||
extensions.push_back("jpeg");
|
||||
extensions.push_back("JPEG");
|
||||
|
||||
std::string prefix = path + "/" + name;
|
||||
std::string file;
|
||||
std::string prefix = path + "/" + name;
|
||||
std::string file;
|
||||
|
||||
if(Utils::FindMatchingFile(prefix, extensions, file))
|
||||
{
|
||||
image = new Image(file, scaleX, scaleY);
|
||||
}
|
||||
if(Utils::FindMatchingFile(prefix, extensions, file))
|
||||
{
|
||||
image = new Image(file, scaleX, scaleY);
|
||||
}
|
||||
|
||||
return image;
|
||||
return image;
|
||||
}
|
||||
|
||||
@@ -11,5 +11,5 @@
|
||||
class ImageBuilder
|
||||
{
|
||||
public:
|
||||
Image * CreateImage(std::string path, std::string name, float scaleX, float scaleY);
|
||||
Image * CreateImage(std::string path, std::string name, float scaleX, float scaleY);
|
||||
};
|
||||
|
||||
@@ -15,158 +15,158 @@
|
||||
#include <iostream>
|
||||
|
||||
ReloadableMedia::ReloadableMedia(std::string imagePath, std::string videoPath, bool isVideo, float scaleX, float scaleY)
|
||||
: LoadedComponent(NULL)
|
||||
, ImagePath(imagePath)
|
||||
, VideoPath(videoPath)
|
||||
, ReloadRequested(false)
|
||||
, FirstLoad(true)
|
||||
, IsVideo(isVideo)
|
||||
, ScaleX(scaleX)
|
||||
, ScaleY(scaleY)
|
||||
: LoadedComponent(NULL)
|
||||
, ImagePath(imagePath)
|
||||
, VideoPath(videoPath)
|
||||
, ReloadRequested(false)
|
||||
, FirstLoad(true)
|
||||
, IsVideo(isVideo)
|
||||
, ScaleX(scaleX)
|
||||
, ScaleY(scaleY)
|
||||
{
|
||||
AllocateGraphicsMemory();
|
||||
AllocateGraphicsMemory();
|
||||
}
|
||||
|
||||
ReloadableMedia::~ReloadableMedia()
|
||||
{
|
||||
if (LoadedComponent != NULL)
|
||||
{
|
||||
delete LoadedComponent;
|
||||
}
|
||||
if (LoadedComponent != NULL)
|
||||
{
|
||||
delete LoadedComponent;
|
||||
}
|
||||
}
|
||||
|
||||
void ReloadableMedia::Update(float dt)
|
||||
{
|
||||
if(NewItemSelected)
|
||||
{
|
||||
ReloadRequested = true;
|
||||
}
|
||||
// wait for the right moment to reload the image
|
||||
if (ReloadRequested && (HighlightExitComplete || FirstLoad))
|
||||
{
|
||||
ReloadTexture();
|
||||
ReloadRequested = false;
|
||||
FirstLoad = false;
|
||||
}
|
||||
if(NewItemSelected)
|
||||
{
|
||||
ReloadRequested = true;
|
||||
}
|
||||
// wait for the right moment to reload the image
|
||||
if (ReloadRequested && (HighlightExitComplete || FirstLoad))
|
||||
{
|
||||
ReloadTexture();
|
||||
ReloadRequested = false;
|
||||
FirstLoad = false;
|
||||
}
|
||||
|
||||
if(LoadedComponent)
|
||||
{
|
||||
LoadedComponent->Update(dt);
|
||||
}
|
||||
if(LoadedComponent)
|
||||
{
|
||||
LoadedComponent->Update(dt);
|
||||
}
|
||||
|
||||
// needs to be ran at the end to prevent the NewItemSelected flag from being detected
|
||||
Component::Update(dt);
|
||||
Component::Update(dt);
|
||||
|
||||
}
|
||||
|
||||
void ReloadableMedia::AllocateGraphicsMemory()
|
||||
{
|
||||
FirstLoad = true;
|
||||
FirstLoad = true;
|
||||
|
||||
if(LoadedComponent)
|
||||
{
|
||||
LoadedComponent->AllocateGraphicsMemory();
|
||||
}
|
||||
if(LoadedComponent)
|
||||
{
|
||||
LoadedComponent->AllocateGraphicsMemory();
|
||||
}
|
||||
|
||||
// NOTICE! needs to be done last to prevent flags from being missed
|
||||
Component::AllocateGraphicsMemory();
|
||||
// NOTICE! needs to be done last to prevent flags from being missed
|
||||
Component::AllocateGraphicsMemory();
|
||||
}
|
||||
|
||||
void ReloadableMedia::LaunchEnter()
|
||||
{
|
||||
if(LoadedComponent)
|
||||
{
|
||||
LoadedComponent->LaunchEnter();
|
||||
}
|
||||
if(LoadedComponent)
|
||||
{
|
||||
LoadedComponent->LaunchEnter();
|
||||
}
|
||||
}
|
||||
|
||||
void ReloadableMedia::LaunchExit()
|
||||
{
|
||||
if(LoadedComponent)
|
||||
{
|
||||
LoadedComponent->LaunchExit();
|
||||
}
|
||||
if(LoadedComponent)
|
||||
{
|
||||
LoadedComponent->LaunchExit();
|
||||
}
|
||||
}
|
||||
|
||||
void ReloadableMedia::FreeGraphicsMemory()
|
||||
{
|
||||
Component::FreeGraphicsMemory();
|
||||
Component::FreeGraphicsMemory();
|
||||
|
||||
if(LoadedComponent)
|
||||
{
|
||||
LoadedComponent->FreeGraphicsMemory();
|
||||
}
|
||||
if(LoadedComponent)
|
||||
{
|
||||
LoadedComponent->FreeGraphicsMemory();
|
||||
}
|
||||
}
|
||||
void ReloadableMedia::ReloadTexture()
|
||||
{
|
||||
bool found = false;
|
||||
bool found = false;
|
||||
|
||||
if(LoadedComponent)
|
||||
{
|
||||
delete LoadedComponent;
|
||||
LoadedComponent = NULL;
|
||||
}
|
||||
if(LoadedComponent)
|
||||
{
|
||||
delete LoadedComponent;
|
||||
LoadedComponent = NULL;
|
||||
}
|
||||
|
||||
Item *selectedItem = GetSelectedItem();
|
||||
Item *selectedItem = GetSelectedItem();
|
||||
|
||||
if (selectedItem != NULL)
|
||||
{
|
||||
if(IsVideo)
|
||||
{
|
||||
std::vector<std::string> names;
|
||||
if (selectedItem != NULL)
|
||||
{
|
||||
if(IsVideo)
|
||||
{
|
||||
std::vector<std::string> names;
|
||||
|
||||
names.push_back(selectedItem->GetName());
|
||||
names.push_back(selectedItem->GetName());
|
||||
|
||||
if(selectedItem->GetCloneOf().length() > 0)
|
||||
{
|
||||
names.push_back(selectedItem->GetCloneOf());
|
||||
}
|
||||
|
||||
for(unsigned int n = 0; n < names.size() && !found; ++n)
|
||||
{
|
||||
std::string filePrefix;
|
||||
filePrefix.append(VideoPath);
|
||||
filePrefix.append("/");
|
||||
filePrefix.append(names[n]);
|
||||
|
||||
std::string file;
|
||||
|
||||
VideoBuilder videoBuild;
|
||||
|
||||
LoadedComponent = videoBuild.CreateVideo(VideoPath, names[n], ScaleX, ScaleY);
|
||||
|
||||
if(LoadedComponent)
|
||||
if(selectedItem->GetCloneOf().length() > 0)
|
||||
{
|
||||
LoadedComponent->AllocateGraphicsMemory();
|
||||
found = true;
|
||||
names.push_back(selectedItem->GetCloneOf());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(!LoadedComponent)
|
||||
{
|
||||
ImageBuilder imageBuild;
|
||||
LoadedComponent = imageBuild.CreateImage(ImagePath, selectedItem->GetFullTitle(), ScaleX, ScaleY);
|
||||
for(unsigned int n = 0; n < names.size() && !found; ++n)
|
||||
{
|
||||
std::string filePrefix;
|
||||
filePrefix.append(VideoPath);
|
||||
filePrefix.append("/");
|
||||
filePrefix.append(names[n]);
|
||||
|
||||
if (LoadedComponent != NULL)
|
||||
{
|
||||
LoadedComponent->AllocateGraphicsMemory();
|
||||
GetBaseViewInfo()->SetImageWidth(LoadedComponent->GetBaseViewInfo()->GetImageWidth());
|
||||
GetBaseViewInfo()->SetImageHeight(LoadedComponent->GetBaseViewInfo()->GetImageHeight());
|
||||
}
|
||||
}
|
||||
}
|
||||
std::string file;
|
||||
|
||||
VideoBuilder videoBuild;
|
||||
|
||||
LoadedComponent = videoBuild.CreateVideo(VideoPath, names[n], ScaleX, ScaleY);
|
||||
|
||||
if(LoadedComponent)
|
||||
{
|
||||
LoadedComponent->AllocateGraphicsMemory();
|
||||
found = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(!LoadedComponent)
|
||||
{
|
||||
ImageBuilder imageBuild;
|
||||
LoadedComponent = imageBuild.CreateImage(ImagePath, selectedItem->GetFullTitle(), ScaleX, ScaleY);
|
||||
|
||||
if (LoadedComponent != NULL)
|
||||
{
|
||||
LoadedComponent->AllocateGraphicsMemory();
|
||||
GetBaseViewInfo()->SetImageWidth(LoadedComponent->GetBaseViewInfo()->GetImageWidth());
|
||||
GetBaseViewInfo()->SetImageHeight(LoadedComponent->GetBaseViewInfo()->GetImageHeight());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ReloadableMedia::Draw()
|
||||
{
|
||||
ViewInfo *info = GetBaseViewInfo();
|
||||
ViewInfo *info = GetBaseViewInfo();
|
||||
|
||||
if(LoadedComponent)
|
||||
{
|
||||
info->SetImageHeight(LoadedComponent->GetBaseViewInfo()->GetImageHeight());
|
||||
info->SetImageWidth(LoadedComponent->GetBaseViewInfo()->GetImageWidth());
|
||||
LoadedComponent->UpdateBaseViewInfo(*info);
|
||||
LoadedComponent->Draw();
|
||||
}
|
||||
if(LoadedComponent)
|
||||
{
|
||||
info->SetImageHeight(LoadedComponent->GetBaseViewInfo()->GetImageHeight());
|
||||
info->SetImageWidth(LoadedComponent->GetBaseViewInfo()->GetImageWidth());
|
||||
LoadedComponent->UpdateBaseViewInfo(*info);
|
||||
LoadedComponent->Draw();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,25 +14,25 @@ class Image;
|
||||
class ReloadableMedia : public Component
|
||||
{
|
||||
public:
|
||||
ReloadableMedia(std::string imagePath, std::string videoPath, bool isVideo, float scaleX, float scaleY);
|
||||
virtual ~ReloadableMedia();
|
||||
void Update(float dt);
|
||||
void Draw();
|
||||
void FreeGraphicsMemory();
|
||||
void AllocateGraphicsMemory();
|
||||
void LaunchEnter();
|
||||
void LaunchExit();
|
||||
ReloadableMedia(std::string imagePath, std::string videoPath, bool isVideo, float scaleX, float scaleY);
|
||||
virtual ~ReloadableMedia();
|
||||
void Update(float dt);
|
||||
void Draw();
|
||||
void FreeGraphicsMemory();
|
||||
void AllocateGraphicsMemory();
|
||||
void LaunchEnter();
|
||||
void LaunchExit();
|
||||
|
||||
private:
|
||||
void ReloadTexture();
|
||||
Component *LoadedComponent;
|
||||
std::string ImagePath;
|
||||
std::string VideoPath;
|
||||
bool ReloadRequested;
|
||||
bool FirstLoad;
|
||||
IVideo *VideoInst;
|
||||
void ReloadTexture();
|
||||
Component *LoadedComponent;
|
||||
std::string ImagePath;
|
||||
std::string VideoPath;
|
||||
bool ReloadRequested;
|
||||
bool FirstLoad;
|
||||
IVideo *VideoInst;
|
||||
|
||||
bool IsVideo;
|
||||
float ScaleX;
|
||||
float ScaleY;
|
||||
bool IsVideo;
|
||||
float ScaleX;
|
||||
float ScaleY;
|
||||
};
|
||||
|
||||
@@ -11,80 +11,80 @@
|
||||
#include <iostream>
|
||||
|
||||
ReloadableText::ReloadableText(std::string type, Font *font, SDL_Color color, std::string layoutKey, std::string collection, float scaleX, float scaleY)
|
||||
: ImageInst(NULL)
|
||||
, LayoutKey(layoutKey)
|
||||
, Collection(collection)
|
||||
, ReloadRequested(false)
|
||||
, FirstLoad(true)
|
||||
, FontInst(font)
|
||||
, FontColor(color)
|
||||
, ScaleX(scaleX)
|
||||
, ScaleY(scaleY)
|
||||
: ImageInst(NULL)
|
||||
, LayoutKey(layoutKey)
|
||||
, Collection(collection)
|
||||
, ReloadRequested(false)
|
||||
, FirstLoad(true)
|
||||
, FontInst(font)
|
||||
, FontColor(color)
|
||||
, ScaleX(scaleX)
|
||||
, ScaleY(scaleY)
|
||||
{
|
||||
|
||||
Type = TextTypeUnknown;
|
||||
Type = TextTypeUnknown;
|
||||
|
||||
if(type == "numberButtons")
|
||||
{
|
||||
Type = TextTypeNumberButtons;
|
||||
}
|
||||
else if(type == "numberPlayers")
|
||||
{
|
||||
Type = TextTypeNumberPlayers;
|
||||
}
|
||||
else if(type == "year")
|
||||
{
|
||||
Type = TextTypeYear;
|
||||
}
|
||||
else if(type == "title")
|
||||
{
|
||||
Type = TextTypeTitle;
|
||||
}
|
||||
else if(type == "manufacturer")
|
||||
{
|
||||
Type = TextTypeManufacturer;
|
||||
}
|
||||
if(type == "numberButtons")
|
||||
{
|
||||
Type = TextTypeNumberButtons;
|
||||
}
|
||||
else if(type == "numberPlayers")
|
||||
{
|
||||
Type = TextTypeNumberPlayers;
|
||||
}
|
||||
else if(type == "year")
|
||||
{
|
||||
Type = TextTypeYear;
|
||||
}
|
||||
else if(type == "title")
|
||||
{
|
||||
Type = TextTypeTitle;
|
||||
}
|
||||
else if(type == "manufacturer")
|
||||
{
|
||||
Type = TextTypeManufacturer;
|
||||
}
|
||||
|
||||
AllocateGraphicsMemory();
|
||||
AllocateGraphicsMemory();
|
||||
}
|
||||
|
||||
|
||||
|
||||
ReloadableText::~ReloadableText()
|
||||
{
|
||||
if (ImageInst != NULL)
|
||||
{
|
||||
delete ImageInst;
|
||||
}
|
||||
if (ImageInst != NULL)
|
||||
{
|
||||
delete ImageInst;
|
||||
}
|
||||
}
|
||||
|
||||
void ReloadableText::Update(float dt)
|
||||
{
|
||||
if(NewItemSelected)
|
||||
{
|
||||
ReloadRequested = true;
|
||||
}
|
||||
// wait for the right moment to reload the image
|
||||
if (ReloadRequested && (HighlightExitComplete || FirstLoad))
|
||||
{
|
||||
ReloadTexture();
|
||||
ReloadRequested = false;
|
||||
FirstLoad = false;
|
||||
}
|
||||
if(NewItemSelected)
|
||||
{
|
||||
ReloadRequested = true;
|
||||
}
|
||||
// wait for the right moment to reload the image
|
||||
if (ReloadRequested && (HighlightExitComplete || FirstLoad))
|
||||
{
|
||||
ReloadTexture();
|
||||
ReloadRequested = false;
|
||||
FirstLoad = false;
|
||||
}
|
||||
|
||||
// needs to be ran at the end to prevent the NewItemSelected flag from being detected
|
||||
Component::Update(dt);
|
||||
// needs to be ran at the end to prevent the NewItemSelected flag from being detected
|
||||
Component::Update(dt);
|
||||
|
||||
}
|
||||
|
||||
void ReloadableText::AllocateGraphicsMemory()
|
||||
{
|
||||
FirstLoad = true;
|
||||
FirstLoad = true;
|
||||
|
||||
ReloadTexture();
|
||||
ReloadTexture();
|
||||
|
||||
// NOTICE! needs to be done last to prevent flags from being missed
|
||||
Component::AllocateGraphicsMemory();
|
||||
// NOTICE! needs to be done last to prevent flags from being missed
|
||||
Component::AllocateGraphicsMemory();
|
||||
}
|
||||
|
||||
void ReloadableText::LaunchEnter()
|
||||
@@ -97,61 +97,61 @@ void ReloadableText::LaunchExit()
|
||||
|
||||
void ReloadableText::FreeGraphicsMemory()
|
||||
{
|
||||
Component::FreeGraphicsMemory();
|
||||
Component::FreeGraphicsMemory();
|
||||
|
||||
if (ImageInst != NULL)
|
||||
{
|
||||
delete ImageInst;
|
||||
ImageInst = NULL;
|
||||
}
|
||||
if (ImageInst != NULL)
|
||||
{
|
||||
delete ImageInst;
|
||||
ImageInst = NULL;
|
||||
}
|
||||
}
|
||||
void ReloadableText::ReloadTexture()
|
||||
{
|
||||
if (ImageInst != NULL)
|
||||
{
|
||||
delete ImageInst;
|
||||
ImageInst = NULL;
|
||||
}
|
||||
if (ImageInst != NULL)
|
||||
{
|
||||
delete ImageInst;
|
||||
ImageInst = NULL;
|
||||
}
|
||||
|
||||
Item *selectedItem = GetSelectedItem();
|
||||
Item *selectedItem = GetSelectedItem();
|
||||
|
||||
if (selectedItem != NULL)
|
||||
{
|
||||
std::stringstream ss;
|
||||
std::string text;
|
||||
switch(Type)
|
||||
{
|
||||
case TextTypeNumberButtons:
|
||||
ss << selectedItem->GetNumberButtons();
|
||||
break;
|
||||
case TextTypeNumberPlayers:
|
||||
ss << selectedItem->GetNumberPlayers();
|
||||
break;
|
||||
case TextTypeYear:
|
||||
ss << selectedItem->GetYear();
|
||||
break;
|
||||
case TextTypeTitle:
|
||||
ss << selectedItem->GetTitle();
|
||||
break;
|
||||
case TextTypeManufacturer:
|
||||
ss << selectedItem->GetManufacturer();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
if (selectedItem != NULL)
|
||||
{
|
||||
std::stringstream ss;
|
||||
std::string text;
|
||||
switch(Type)
|
||||
{
|
||||
case TextTypeNumberButtons:
|
||||
ss << selectedItem->GetNumberButtons();
|
||||
break;
|
||||
case TextTypeNumberPlayers:
|
||||
ss << selectedItem->GetNumberPlayers();
|
||||
break;
|
||||
case TextTypeYear:
|
||||
ss << selectedItem->GetYear();
|
||||
break;
|
||||
case TextTypeTitle:
|
||||
ss << selectedItem->GetTitle();
|
||||
break;
|
||||
case TextTypeManufacturer:
|
||||
ss << selectedItem->GetManufacturer();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
ImageInst = new Text(ss.str(), FontInst, FontColor, ScaleX, ScaleY);
|
||||
}
|
||||
ImageInst = new Text(ss.str(), FontInst, FontColor, ScaleX, ScaleY);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ReloadableText::Draw()
|
||||
{
|
||||
ViewInfo *info = GetBaseViewInfo();
|
||||
ViewInfo *info = GetBaseViewInfo();
|
||||
|
||||
if(ImageInst)
|
||||
{
|
||||
ImageInst->UpdateBaseViewInfo(*info);
|
||||
ImageInst->Draw();
|
||||
}
|
||||
if(ImageInst)
|
||||
{
|
||||
ImageInst->UpdateBaseViewInfo(*info);
|
||||
ImageInst->Draw();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,37 +12,37 @@
|
||||
class ReloadableText : public Component
|
||||
{
|
||||
public:
|
||||
ReloadableText(std::string type, Font *font, SDL_Color color, std::string layoutKey, std::string collectionName, float scaleX, float scaleY);
|
||||
virtual ~ReloadableText();
|
||||
void Update(float dt);
|
||||
void Draw();
|
||||
void FreeGraphicsMemory();
|
||||
void AllocateGraphicsMemory();
|
||||
void LaunchEnter();
|
||||
void LaunchExit();
|
||||
ReloadableText(std::string type, Font *font, SDL_Color color, std::string layoutKey, std::string collectionName, float scaleX, float scaleY);
|
||||
virtual ~ReloadableText();
|
||||
void Update(float dt);
|
||||
void Draw();
|
||||
void FreeGraphicsMemory();
|
||||
void AllocateGraphicsMemory();
|
||||
void LaunchEnter();
|
||||
void LaunchExit();
|
||||
|
||||
private:
|
||||
enum TextType
|
||||
{
|
||||
TextTypeUnknown = 0,
|
||||
TextTypeNumberButtons,
|
||||
TextTypeNumberPlayers,
|
||||
TextTypeYear,
|
||||
TextTypeTitle,
|
||||
TextTypeManufacturer,
|
||||
};
|
||||
enum TextType
|
||||
{
|
||||
TextTypeUnknown = 0,
|
||||
TextTypeNumberButtons,
|
||||
TextTypeNumberPlayers,
|
||||
TextTypeYear,
|
||||
TextTypeTitle,
|
||||
TextTypeManufacturer,
|
||||
};
|
||||
|
||||
void ReloadTexture();
|
||||
void ReloadTexture();
|
||||
|
||||
Text *ImageInst;
|
||||
TextType Type;
|
||||
std::string LayoutKey;
|
||||
std::string Collection;
|
||||
bool ReloadRequested;
|
||||
bool FirstLoad;
|
||||
Font *FontInst;
|
||||
SDL_Color FontColor;
|
||||
Text *ImageInst;
|
||||
TextType Type;
|
||||
std::string LayoutKey;
|
||||
std::string Collection;
|
||||
bool ReloadRequested;
|
||||
bool FirstLoad;
|
||||
Font *FontInst;
|
||||
SDL_Color FontColor;
|
||||
|
||||
float ScaleX;
|
||||
float ScaleY;
|
||||
float ScaleX;
|
||||
float ScaleY;
|
||||
};
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -23,83 +23,83 @@ class Font;
|
||||
class ScrollingList : public Component
|
||||
{
|
||||
public:
|
||||
enum ScrollDirection
|
||||
{
|
||||
ScrollDirectionBack,
|
||||
ScrollDirectionForward,
|
||||
ScrollDirectionIdle,
|
||||
enum ScrollDirection
|
||||
{
|
||||
ScrollDirectionBack,
|
||||
ScrollDirectionForward,
|
||||
ScrollDirectionIdle,
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
ScrollingList(Configuration *c, float scaleX, float scaleY, Font *font, SDL_Color fontColor, std::string layoutKey, std::string CollectionName, std::string imageType);
|
||||
virtual ~ScrollingList();
|
||||
void AllocateTexture(ComponentItemBinding *s);
|
||||
void DeallocateTexture(ComponentItemBinding *s);
|
||||
void SetItems(std::vector<ComponentItemBinding *> *spriteList);
|
||||
void SetPoints(std::vector<ViewInfo *> *scrollPoints);
|
||||
void SetScrollDirection(ScrollDirection direction);
|
||||
void PageUp();
|
||||
void PageDown();
|
||||
bool IsIdle();
|
||||
void SetSelectedIndex(int selectedIndex);
|
||||
ComponentItemBinding *GetSelectedCollectionItemSprite();
|
||||
ComponentItemBinding *GetPendingCollectionItemSprite();
|
||||
ComponentItemBinding *GetPendingSelectedCollectionItemSprite();
|
||||
void AddComponentForNotifications(MenuNotifierInterface *c);
|
||||
void RemoveComponentForNotifications(MenuNotifierInterface *c);
|
||||
std::vector<ComponentItemBinding *> *GetCollectionItemSprites();
|
||||
void RemoveSelectedItem();
|
||||
void FreeGraphicsMemory();
|
||||
void Update(float dt);
|
||||
void Draw();
|
||||
void Draw(unsigned int layer);
|
||||
ScrollingList(Configuration *c, float scaleX, float scaleY, Font *font, SDL_Color fontColor, std::string layoutKey, std::string CollectionName, std::string imageType);
|
||||
virtual ~ScrollingList();
|
||||
void AllocateTexture(ComponentItemBinding *s);
|
||||
void DeallocateTexture(ComponentItemBinding *s);
|
||||
void SetItems(std::vector<ComponentItemBinding *> *spriteList);
|
||||
void SetPoints(std::vector<ViewInfo *> *scrollPoints);
|
||||
void SetScrollDirection(ScrollDirection direction);
|
||||
void PageUp();
|
||||
void PageDown();
|
||||
bool IsIdle();
|
||||
void SetSelectedIndex(int selectedIndex);
|
||||
ComponentItemBinding *GetSelectedCollectionItemSprite();
|
||||
ComponentItemBinding *GetPendingCollectionItemSprite();
|
||||
ComponentItemBinding *GetPendingSelectedCollectionItemSprite();
|
||||
void AddComponentForNotifications(MenuNotifierInterface *c);
|
||||
void RemoveComponentForNotifications(MenuNotifierInterface *c);
|
||||
std::vector<ComponentItemBinding *> *GetCollectionItemSprites();
|
||||
void RemoveSelectedItem();
|
||||
void FreeGraphicsMemory();
|
||||
void Update(float dt);
|
||||
void Draw();
|
||||
void Draw(unsigned int layer);
|
||||
|
||||
private:
|
||||
void Click();
|
||||
unsigned int GetNextTween(unsigned int currentIndex, std::vector<ViewInfo *> *list);
|
||||
bool IsScrollChangedStarted;
|
||||
bool IsScrollChangedSignalled;
|
||||
bool IsScrollChangedComplete;
|
||||
void Click();
|
||||
unsigned int GetNextTween(unsigned int currentIndex, std::vector<ViewInfo *> *list);
|
||||
bool IsScrollChangedStarted;
|
||||
bool IsScrollChangedSignalled;
|
||||
bool IsScrollChangedComplete;
|
||||
|
||||
enum ScrollState
|
||||
{
|
||||
ScrollStateActive,
|
||||
ScrollStatePageChange,
|
||||
ScrollStateStopping,
|
||||
ScrollStateIdle
|
||||
};
|
||||
enum ScrollState
|
||||
{
|
||||
ScrollStateActive,
|
||||
ScrollStatePageChange,
|
||||
ScrollStateStopping,
|
||||
ScrollStateIdle
|
||||
};
|
||||
|
||||
std::vector<ComponentItemBinding *> *SpriteList;
|
||||
std::vector<ViewInfo *> *ScrollPoints;
|
||||
std::vector<MenuNotifierInterface *> NotificationComponents;
|
||||
float TweenEnterTime;
|
||||
std::vector<ComponentItemBinding *> *SpriteList;
|
||||
std::vector<ViewInfo *> *ScrollPoints;
|
||||
std::vector<MenuNotifierInterface *> NotificationComponents;
|
||||
float TweenEnterTime;
|
||||
|
||||
unsigned int FirstSpriteIndex;
|
||||
unsigned int SelectedSpriteListIndex;
|
||||
float CurrentAnimateTime;
|
||||
float ScrollTime;
|
||||
unsigned int FirstSpriteIndex;
|
||||
unsigned int SelectedSpriteListIndex;
|
||||
float CurrentAnimateTime;
|
||||
float ScrollTime;
|
||||
|
||||
ScrollDirection CurrentScrollDirection;
|
||||
ScrollDirection RequestedScrollDirection;
|
||||
ScrollState CurrentScrollState;
|
||||
float ScrollAcceleration;
|
||||
float ScrollVelocity;
|
||||
ScrollDirection CurrentScrollDirection;
|
||||
ScrollDirection RequestedScrollDirection;
|
||||
ScrollState CurrentScrollState;
|
||||
float ScrollAcceleration;
|
||||
float ScrollVelocity;
|
||||
|
||||
void CircularIncrement(unsigned &index, std::vector<ComponentItemBinding *> *list);
|
||||
void CircularDecrement(unsigned &index, std::vector<ComponentItemBinding *> *list);
|
||||
void CircularIncrement(unsigned &index, std::vector<ViewInfo *> *list);
|
||||
void CircularDecrement(unsigned &index, std::vector<ViewInfo *> *list);
|
||||
void UpdateOffset(float dt);
|
||||
void CircularIncrement(unsigned &index, std::vector<ComponentItemBinding *> *list);
|
||||
void CircularDecrement(unsigned &index, std::vector<ComponentItemBinding *> *list);
|
||||
void CircularIncrement(unsigned &index, std::vector<ViewInfo *> *list);
|
||||
void CircularDecrement(unsigned &index, std::vector<ViewInfo *> *list);
|
||||
void UpdateOffset(float dt);
|
||||
|
||||
std::string Collection;
|
||||
Configuration *Config;
|
||||
float ScaleX;
|
||||
float ScaleY;
|
||||
Font *FontInst;
|
||||
SDL_Color FontColor;
|
||||
std::string LayoutKey;
|
||||
std::string CollectionName;
|
||||
std::string ImageType;
|
||||
unsigned int MaxLayer;
|
||||
std::string Collection;
|
||||
Configuration *Config;
|
||||
float ScaleX;
|
||||
float ScaleY;
|
||||
Font *FontInst;
|
||||
SDL_Color FontColor;
|
||||
std::string LayoutKey;
|
||||
std::string CollectionName;
|
||||
std::string ImageType;
|
||||
unsigned int MaxLayer;
|
||||
};
|
||||
|
||||
|
||||
@@ -8,96 +8,96 @@
|
||||
#include <sstream>
|
||||
|
||||
Text::Text(std::string text, Font *font, SDL_Color fontColor, float scaleX, float scaleY)
|
||||
: TextData(text)
|
||||
, FontInst(font)
|
||||
, FontColor(fontColor)
|
||||
, ScaleX(scaleX)
|
||||
, ScaleY(scaleY)
|
||||
: TextData(text)
|
||||
, FontInst(font)
|
||||
, FontColor(fontColor)
|
||||
, ScaleX(scaleX)
|
||||
, ScaleY(scaleY)
|
||||
{
|
||||
AllocateGraphicsMemory();
|
||||
AllocateGraphicsMemory();
|
||||
}
|
||||
|
||||
Text::~Text()
|
||||
{
|
||||
FreeGraphicsMemory();
|
||||
FreeGraphicsMemory();
|
||||
}
|
||||
|
||||
|
||||
void Text::FreeGraphicsMemory()
|
||||
{
|
||||
Component::FreeGraphicsMemory();
|
||||
Component::FreeGraphicsMemory();
|
||||
}
|
||||
|
||||
void Text::AllocateGraphicsMemory()
|
||||
{
|
||||
//todo: make the font blend color a parameter that is passed in
|
||||
Component::AllocateGraphicsMemory();
|
||||
//todo: make the font blend color a parameter that is passed in
|
||||
Component::AllocateGraphicsMemory();
|
||||
}
|
||||
|
||||
void Text::Draw()
|
||||
{
|
||||
SDL_Texture *t = FontInst->GetTexture();
|
||||
SDL_Texture *t = FontInst->GetTexture();
|
||||
|
||||
ViewInfo *info = GetBaseViewInfo();
|
||||
float imageHeight = 0;
|
||||
float imageWidth = 0;
|
||||
ViewInfo *info = GetBaseViewInfo();
|
||||
float imageHeight = 0;
|
||||
float imageWidth = 0;
|
||||
|
||||
// determine image width
|
||||
for(unsigned int i = 0; i < TextData.size(); ++i)
|
||||
{
|
||||
Font::GlyphInfo glyph;
|
||||
if(FontInst->GetRect(TextData[i], glyph))
|
||||
{
|
||||
imageWidth += glyph.Advance;
|
||||
imageHeight = (imageHeight >= glyph.Rect.h) ? imageHeight : glyph.Rect.h;
|
||||
}
|
||||
}
|
||||
// determine image width
|
||||
for(unsigned int i = 0; i < TextData.size(); ++i)
|
||||
{
|
||||
Font::GlyphInfo glyph;
|
||||
if(FontInst->GetRect(TextData[i], glyph))
|
||||
{
|
||||
imageWidth += glyph.Advance;
|
||||
imageHeight = (imageHeight >= glyph.Rect.h) ? imageHeight : glyph.Rect.h;
|
||||
}
|
||||
}
|
||||
|
||||
float scale = (float)info->GetFontSize() / (float)imageHeight;
|
||||
float scale = (float)info->GetFontSize() / (float)imageHeight;
|
||||
|
||||
|
||||
float width = info->GetRawWidth();
|
||||
float height = info->GetRawHeight();
|
||||
float width = info->GetRawWidth();
|
||||
float height = info->GetRawHeight();
|
||||
|
||||
info->SetWidth(imageWidth*scale);
|
||||
info->SetHeight(imageHeight*scale);
|
||||
info->SetWidth(imageWidth*scale);
|
||||
info->SetHeight(imageHeight*scale);
|
||||
|
||||
float xOrigin = info->GetXRelativeToOrigin();
|
||||
float yOrigin = info->GetYRelativeToOrigin();
|
||||
float xOrigin = info->GetXRelativeToOrigin();
|
||||
float yOrigin = info->GetYRelativeToOrigin();
|
||||
|
||||
info->SetWidth(width);
|
||||
info->SetHeight(height);
|
||||
info->SetWidth(width);
|
||||
info->SetHeight(height);
|
||||
|
||||
|
||||
SDL_Rect rect;
|
||||
rect.x = static_cast<int>(xOrigin);
|
||||
SDL_Rect rect;
|
||||
rect.x = static_cast<int>(xOrigin);
|
||||
|
||||
for(unsigned int i = 0; i < TextData.size(); ++i)
|
||||
{
|
||||
Font::GlyphInfo glyph;
|
||||
for(unsigned int i = 0; i < TextData.size(); ++i)
|
||||
{
|
||||
Font::GlyphInfo glyph;
|
||||
|
||||
if(FontInst->GetRect(TextData[i], glyph) && glyph.Rect.h > 0)
|
||||
{
|
||||
SDL_Rect charRect = glyph.Rect;
|
||||
float h = static_cast<float>(charRect.h * scale);
|
||||
float w = static_cast<float>(charRect.w * scale);
|
||||
rect.h = static_cast<int>(h);
|
||||
rect.w = static_cast<int>(w);
|
||||
rect.y = static_cast<int>(yOrigin);
|
||||
/*
|
||||
std::stringstream ss;
|
||||
ss << " cx:" << charRect.x << " cy:" << charRect.y << " cw:" << charRect.w << " ch:" << charRect.h;
|
||||
ss << " x:" << rect.x << " y:" << rect.y << " w:" << rect.w << " h:" << rect.h;
|
||||
Logger::Write(Logger::ZONE_DEBUG, "Text", ss.str());
|
||||
*/
|
||||
if(FontInst->GetRect(TextData[i], glyph) && glyph.Rect.h > 0)
|
||||
{
|
||||
SDL_Rect charRect = glyph.Rect;
|
||||
float h = static_cast<float>(charRect.h * scale);
|
||||
float w = static_cast<float>(charRect.w * scale);
|
||||
rect.h = static_cast<int>(h);
|
||||
rect.w = static_cast<int>(w);
|
||||
rect.y = static_cast<int>(yOrigin);
|
||||
/*
|
||||
std::stringstream ss;
|
||||
ss << " cx:" << charRect.x << " cy:" << charRect.y << " cw:" << charRect.w << " ch:" << charRect.h;
|
||||
ss << " x:" << rect.x << " y:" << rect.y << " w:" << rect.w << " h:" << rect.h;
|
||||
Logger::Write(Logger::ZONE_DEBUG, "Text", ss.str());
|
||||
*/
|
||||
|
||||
SDL_LockMutex(SDL::GetMutex());
|
||||
SDL_SetTextureColorMod(t, FontColor.r, FontColor.g, FontColor.b);
|
||||
SDL_UnlockMutex(SDL::GetMutex());
|
||||
SDL_LockMutex(SDL::GetMutex());
|
||||
SDL_SetTextureColorMod(t, FontColor.r, FontColor.g, FontColor.b);
|
||||
SDL_UnlockMutex(SDL::GetMutex());
|
||||
|
||||
SDL::RenderCopy(t, static_cast<char>(info->GetTransparency() * 255), &charRect, &rect, info->GetAngle());
|
||||
rect.x += static_cast<int>(glyph.Advance * scale);
|
||||
}
|
||||
}
|
||||
SDL::RenderCopy(t, static_cast<char>(info->GetTransparency() * 255), &charRect, &rect, info->GetAngle());
|
||||
rect.x += static_cast<int>(glyph.Advance * scale);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -13,17 +13,17 @@ class Font;
|
||||
class Text : public Component
|
||||
{
|
||||
public:
|
||||
//todo: should have a Font flass that references fontcache, pass that in as an argument
|
||||
Text(std::string text, Font *font, SDL_Color fontColor, float scaleX, float scaleY);
|
||||
virtual ~Text();
|
||||
void AllocateGraphicsMemory();
|
||||
void FreeGraphicsMemory();
|
||||
void Draw();
|
||||
//todo: should have a Font flass that references fontcache, pass that in as an argument
|
||||
Text(std::string text, Font *font, SDL_Color fontColor, float scaleX, float scaleY);
|
||||
virtual ~Text();
|
||||
void AllocateGraphicsMemory();
|
||||
void FreeGraphicsMemory();
|
||||
void Draw();
|
||||
|
||||
private:
|
||||
std::string TextData;
|
||||
Font *FontInst;
|
||||
SDL_Color FontColor;
|
||||
float ScaleX;
|
||||
float ScaleY;
|
||||
std::string TextData;
|
||||
Font *FontInst;
|
||||
SDL_Color FontColor;
|
||||
float ScaleX;
|
||||
float ScaleY;
|
||||
};
|
||||
|
||||
@@ -10,27 +10,27 @@
|
||||
|
||||
VideoComponent * VideoBuilder::CreateVideo(std::string path, std::string name, float scaleX, float scaleY)
|
||||
{
|
||||
VideoComponent *component = NULL;
|
||||
std::vector<std::string> extensions;
|
||||
VideoComponent *component = NULL;
|
||||
std::vector<std::string> extensions;
|
||||
|
||||
extensions.push_back("mp4");
|
||||
extensions.push_back("MP4");
|
||||
extensions.push_back("avi");
|
||||
extensions.push_back("AVI");
|
||||
extensions.push_back("mp4");
|
||||
extensions.push_back("MP4");
|
||||
extensions.push_back("avi");
|
||||
extensions.push_back("AVI");
|
||||
|
||||
std::string prefix = path + "/" + name;
|
||||
std::string file;
|
||||
std::string prefix = path + "/" + name;
|
||||
std::string file;
|
||||
|
||||
if(Utils::FindMatchingFile(prefix, extensions, file))
|
||||
{
|
||||
IVideo *video = Factory.CreateVideo();
|
||||
if(Utils::FindMatchingFile(prefix, extensions, file))
|
||||
{
|
||||
IVideo *video = Factory.CreateVideo();
|
||||
|
||||
if(video)
|
||||
{
|
||||
component = new VideoComponent(video, file, scaleX, scaleY);
|
||||
}
|
||||
}
|
||||
if(video)
|
||||
{
|
||||
component = new VideoComponent(video, file, scaleX, scaleY);
|
||||
}
|
||||
}
|
||||
|
||||
return component;
|
||||
return component;
|
||||
}
|
||||
|
||||
|
||||
@@ -11,8 +11,8 @@
|
||||
class VideoBuilder
|
||||
{
|
||||
public:
|
||||
VideoComponent * CreateVideo(std::string path, std::string name, float scaleX, float scaleY);
|
||||
VideoComponent * CreateVideo(std::string path, std::string name, float scaleX, float scaleY);
|
||||
|
||||
private:
|
||||
VideoFactory Factory;
|
||||
VideoFactory Factory;
|
||||
};
|
||||
|
||||
@@ -8,77 +8,77 @@
|
||||
#include "../../SDL.h"
|
||||
|
||||
VideoComponent::VideoComponent(IVideo *videoInst, std::string videoFile, float scaleX, float scaleY)
|
||||
: VideoTexture(NULL)
|
||||
, VideoFile(videoFile)
|
||||
, VideoInst(videoInst)
|
||||
, ScaleX(scaleX)
|
||||
, ScaleY(scaleY)
|
||||
, IsPlaying(false)
|
||||
: VideoTexture(NULL)
|
||||
, VideoFile(videoFile)
|
||||
, VideoInst(videoInst)
|
||||
, ScaleX(scaleX)
|
||||
, ScaleY(scaleY)
|
||||
, IsPlaying(false)
|
||||
{
|
||||
// AllocateGraphicsMemory();
|
||||
}
|
||||
|
||||
VideoComponent::~VideoComponent()
|
||||
{
|
||||
FreeGraphicsMemory();
|
||||
FreeGraphicsMemory();
|
||||
|
||||
if(VideoInst)
|
||||
{
|
||||
VideoInst->Stop();
|
||||
}
|
||||
if(VideoInst)
|
||||
{
|
||||
VideoInst->Stop();
|
||||
}
|
||||
}
|
||||
|
||||
void VideoComponent::Update(float dt)
|
||||
{
|
||||
if(IsPlaying)
|
||||
{
|
||||
VideoInst->Update(dt);
|
||||
}
|
||||
if(IsPlaying)
|
||||
{
|
||||
VideoInst->Update(dt);
|
||||
}
|
||||
|
||||
Component::Update(dt);
|
||||
Component::Update(dt);
|
||||
|
||||
}
|
||||
|
||||
void VideoComponent::AllocateGraphicsMemory()
|
||||
{
|
||||
Component::AllocateGraphicsMemory();
|
||||
Component::AllocateGraphicsMemory();
|
||||
|
||||
if(!IsPlaying)
|
||||
{
|
||||
IsPlaying = VideoInst->Play(VideoFile);
|
||||
}
|
||||
if(!IsPlaying)
|
||||
{
|
||||
IsPlaying = VideoInst->Play(VideoFile);
|
||||
}
|
||||
}
|
||||
|
||||
void VideoComponent::FreeGraphicsMemory()
|
||||
{
|
||||
VideoInst->Stop();
|
||||
IsPlaying = false;
|
||||
VideoInst->Stop();
|
||||
IsPlaying = false;
|
||||
|
||||
if (VideoTexture != NULL)
|
||||
{
|
||||
SDL_LockMutex(SDL::GetMutex());
|
||||
SDL_DestroyTexture(VideoTexture);
|
||||
SDL_UnlockMutex(SDL::GetMutex());
|
||||
}
|
||||
if (VideoTexture != NULL)
|
||||
{
|
||||
SDL_LockMutex(SDL::GetMutex());
|
||||
SDL_DestroyTexture(VideoTexture);
|
||||
SDL_UnlockMutex(SDL::GetMutex());
|
||||
}
|
||||
|
||||
Component::FreeGraphicsMemory();
|
||||
Component::FreeGraphicsMemory();
|
||||
}
|
||||
|
||||
void VideoComponent::Draw()
|
||||
{
|
||||
ViewInfo *info = GetBaseViewInfo();
|
||||
SDL_Rect rect;
|
||||
ViewInfo *info = GetBaseViewInfo();
|
||||
SDL_Rect rect;
|
||||
|
||||
rect.x = static_cast<int>(info->GetXRelativeToOrigin());
|
||||
rect.y = static_cast<int>(info->GetYRelativeToOrigin());
|
||||
rect.h = static_cast<int>(info->GetHeight());
|
||||
rect.w = static_cast<int>(info->GetWidth());
|
||||
rect.x = static_cast<int>(info->GetXRelativeToOrigin());
|
||||
rect.y = static_cast<int>(info->GetYRelativeToOrigin());
|
||||
rect.h = static_cast<int>(info->GetHeight());
|
||||
rect.w = static_cast<int>(info->GetWidth());
|
||||
|
||||
VideoInst->Draw();
|
||||
SDL_Texture *texture = VideoInst->GetTexture();
|
||||
VideoInst->Draw();
|
||||
SDL_Texture *texture = VideoInst->GetTexture();
|
||||
|
||||
if(texture)
|
||||
{
|
||||
SDL::RenderCopy(texture, static_cast<int>(info->GetTransparency() * 255), NULL, &rect, info->GetAngle());
|
||||
}
|
||||
if(texture)
|
||||
{
|
||||
SDL::RenderCopy(texture, static_cast<int>(info->GetTransparency() * 255), NULL, &rect, info->GetAngle());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,21 +12,27 @@
|
||||
class VideoComponent : public Component
|
||||
{
|
||||
public:
|
||||
VideoComponent(IVideo *videoInst, std::string videoFile, float scaleX, float scaleY);
|
||||
virtual ~VideoComponent();
|
||||
void Update(float dt);
|
||||
void Draw();
|
||||
void FreeGraphicsMemory();
|
||||
void AllocateGraphicsMemory();
|
||||
void LaunchEnter() {FreeGraphicsMemory(); }
|
||||
void LaunchExit() { AllocateGraphicsMemory(); }
|
||||
VideoComponent(IVideo *videoInst, std::string videoFile, float scaleX, float scaleY);
|
||||
virtual ~VideoComponent();
|
||||
void Update(float dt);
|
||||
void Draw();
|
||||
void FreeGraphicsMemory();
|
||||
void AllocateGraphicsMemory();
|
||||
void LaunchEnter()
|
||||
{
|
||||
FreeGraphicsMemory();
|
||||
}
|
||||
void LaunchExit()
|
||||
{
|
||||
AllocateGraphicsMemory();
|
||||
}
|
||||
|
||||
private:
|
||||
SDL_Texture *VideoTexture;
|
||||
std::string VideoFile;
|
||||
std::string Name;
|
||||
IVideo *VideoInst;
|
||||
float ScaleX;
|
||||
float ScaleY;
|
||||
bool IsPlaying;
|
||||
SDL_Texture *VideoTexture;
|
||||
std::string VideoFile;
|
||||
std::string Name;
|
||||
IVideo *VideoInst;
|
||||
float ScaleX;
|
||||
float ScaleY;
|
||||
bool IsPlaying;
|
||||
};
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
/* This file is subject to the terms and conditions defined in
|
||||
* file 'LICENSE.txt', which is part of this source code package.
|
||||
/* This file is subject to the terms and conditions defined in
|
||||
* file 'LICENSE.txt', which is part of this source code package.
|
||||
*/
|
||||
#include "ComponentItemBinding.h"
|
||||
|
||||
ComponentItemBinding::ComponentItemBinding( Component *c, Item *item)
|
||||
: CollectionComponent(c)
|
||||
, CollectionItem(item)
|
||||
: CollectionComponent(c)
|
||||
, CollectionItem(item)
|
||||
{
|
||||
}
|
||||
|
||||
ComponentItemBinding::ComponentItemBinding(Item *item)
|
||||
: CollectionComponent(NULL)
|
||||
, CollectionItem(item)
|
||||
: CollectionComponent(NULL)
|
||||
, CollectionItem(item)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -21,15 +21,15 @@ ComponentItemBinding::~ComponentItemBinding()
|
||||
|
||||
Item* ComponentItemBinding::GetCollectionItem() const
|
||||
{
|
||||
return CollectionItem;
|
||||
return CollectionItem;
|
||||
}
|
||||
|
||||
void ComponentItemBinding::SetComponent(Component *c)
|
||||
{
|
||||
CollectionComponent = c;
|
||||
CollectionComponent = c;
|
||||
}
|
||||
|
||||
Component* ComponentItemBinding::GetComponent() const
|
||||
{
|
||||
return CollectionComponent;
|
||||
return CollectionComponent;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/* This file is subject to the terms and conditions defined in
|
||||
* file 'LICENSE.txt', which is part of this source code package.
|
||||
/* This file is subject to the terms and conditions defined in
|
||||
* file 'LICENSE.txt', which is part of this source code package.
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
@@ -9,15 +9,15 @@
|
||||
class ComponentItemBinding
|
||||
{
|
||||
public:
|
||||
ComponentItemBinding(Component *c, Item *item);
|
||||
ComponentItemBinding(Item *item);
|
||||
virtual ~ComponentItemBinding();
|
||||
Item* GetCollectionItem() const;
|
||||
ComponentItemBinding(Component *c, Item *item);
|
||||
ComponentItemBinding(Item *item);
|
||||
virtual ~ComponentItemBinding();
|
||||
Item* GetCollectionItem() const;
|
||||
|
||||
void SetComponent(Component *c);
|
||||
Component* GetComponent() const;
|
||||
void SetComponent(Component *c);
|
||||
Component* GetComponent() const;
|
||||
|
||||
private:
|
||||
Component *CollectionComponent;
|
||||
Item *CollectionItem;
|
||||
Component *CollectionComponent;
|
||||
Item *CollectionItem;
|
||||
};
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/* This file is subject to the terms and conditions defined in
|
||||
* file 'LICENSE.txt', which is part of this source code package.
|
||||
/* This file is subject to the terms and conditions defined in
|
||||
* file 'LICENSE.txt', which is part of this source code package.
|
||||
*/
|
||||
#include "ComponentItemBindingBuilder.h"
|
||||
#include "ComponentItemBinding.h"
|
||||
@@ -16,14 +16,14 @@ ComponentItemBindingBuilder::~ComponentItemBindingBuilder()
|
||||
|
||||
std::vector<ComponentItemBinding *> *ComponentItemBindingBuilder::BuildCollectionItems(std::vector<Item *> *infoList)
|
||||
{
|
||||
std::vector<ComponentItemBinding *> *sprites = new std::vector<ComponentItemBinding *>();
|
||||
std::vector<Item *>::iterator it;
|
||||
std::vector<ComponentItemBinding *> *sprites = new std::vector<ComponentItemBinding *>();
|
||||
std::vector<Item *>::iterator it;
|
||||
|
||||
for(it = infoList->begin(); it != infoList->end(); ++it)
|
||||
{
|
||||
ComponentItemBinding *s = new ComponentItemBinding(*it);
|
||||
sprites->push_back(s);
|
||||
}
|
||||
for(it = infoList->begin(); it != infoList->end(); ++it)
|
||||
{
|
||||
ComponentItemBinding *s = new ComponentItemBinding(*it);
|
||||
sprites->push_back(s);
|
||||
}
|
||||
|
||||
return sprites;
|
||||
return sprites;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/* This file is subject to the terms and conditions defined in
|
||||
* file 'LICENSE.txt', which is part of this source code package.
|
||||
/* This file is subject to the terms and conditions defined in
|
||||
* file 'LICENSE.txt', which is part of this source code package.
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
@@ -12,7 +12,7 @@ class ComponentItemBinding;
|
||||
class ComponentItemBindingBuilder
|
||||
{
|
||||
public:
|
||||
ComponentItemBindingBuilder();
|
||||
virtual ~ComponentItemBindingBuilder();
|
||||
static std::vector<ComponentItemBinding *> *BuildCollectionItems(std::vector<Item *> *infoList);
|
||||
ComponentItemBindingBuilder();
|
||||
virtual ~ComponentItemBindingBuilder();
|
||||
static std::vector<ComponentItemBinding *> *BuildCollectionItems(std::vector<Item *> *infoList);
|
||||
};
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* This file is subject to the terms and conditions defined in
|
||||
* file 'LICENSE.txt', which is part of this source code package.
|
||||
*/
|
||||
*/
|
||||
#include "Font.h"
|
||||
#include "../SDL.h"
|
||||
#include "../Utility/Log.h"
|
||||
@@ -8,138 +8,138 @@
|
||||
#include <SDL2/SDL_ttf.h>
|
||||
|
||||
Font::Font()
|
||||
: Texture(NULL)
|
||||
: Texture(NULL)
|
||||
{
|
||||
}
|
||||
|
||||
Font::~Font()
|
||||
{
|
||||
DeInitialize();
|
||||
DeInitialize();
|
||||
}
|
||||
|
||||
SDL_Texture *Font::GetTexture()
|
||||
{
|
||||
return Texture;
|
||||
return Texture;
|
||||
}
|
||||
|
||||
bool Font::GetRect(unsigned int charCode, GlyphInfo &glyph)
|
||||
{
|
||||
std::map<unsigned int, GlyphInfoBuild *>::iterator it = Atlas.find(charCode);
|
||||
std::map<unsigned int, GlyphInfoBuild *>::iterator it = Atlas.find(charCode);
|
||||
|
||||
if(it != Atlas.end())
|
||||
{
|
||||
GlyphInfoBuild *info = it->second;
|
||||
if(it != Atlas.end())
|
||||
{
|
||||
GlyphInfoBuild *info = it->second;
|
||||
|
||||
glyph = info->Glyph;
|
||||
glyph = info->Glyph;
|
||||
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Font::Initialize(std::string fontPath, SDL_Color color)
|
||||
{
|
||||
TTF_Font *font = TTF_OpenFont(fontPath.c_str(), 128);
|
||||
TTF_Font *font = TTF_OpenFont(fontPath.c_str(), 128);
|
||||
|
||||
if (!font)
|
||||
{
|
||||
Logger::Write(Logger::ZONE_ERROR, "FontCache", "TTF_OpenFont failed");
|
||||
return false;
|
||||
}
|
||||
if (!font)
|
||||
{
|
||||
Logger::Write(Logger::ZONE_ERROR, "FontCache", "TTF_OpenFont failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
int x = 0;
|
||||
int y = 0;
|
||||
int atlasHeight = 0;
|
||||
int atlasWidth = 0;
|
||||
int x = 0;
|
||||
int y = 0;
|
||||
int atlasHeight = 0;
|
||||
int atlasWidth = 0;
|
||||
|
||||
for(unsigned short int i = 32; i < 128; ++i)
|
||||
{
|
||||
GlyphInfoBuild *info = new GlyphInfoBuild;
|
||||
memset(info, sizeof(GlyphInfoBuild), 0);
|
||||
for(unsigned short int i = 32; i < 128; ++i)
|
||||
{
|
||||
GlyphInfoBuild *info = new GlyphInfoBuild;
|
||||
memset(info, sizeof(GlyphInfoBuild), 0);
|
||||
|
||||
info->Surface = TTF_RenderGlyph_Blended(font, i, color);
|
||||
TTF_GlyphMetrics(font, i, &info->Glyph.MinX, &info->Glyph.MaxX, &info->Glyph.MinY, &info->Glyph.MaxY, &info->Glyph.Advance);
|
||||
info->Surface = TTF_RenderGlyph_Blended(font, i, color);
|
||||
TTF_GlyphMetrics(font, i, &info->Glyph.MinX, &info->Glyph.MaxX, &info->Glyph.MinY, &info->Glyph.MaxY, &info->Glyph.Advance);
|
||||
|
||||
if(x + info->Surface->w >= 1024)
|
||||
{
|
||||
atlasHeight += y;
|
||||
atlasWidth = (atlasWidth >= x) ? atlasWidth : x;
|
||||
x = 0;
|
||||
y = 0;
|
||||
}
|
||||
if(x + info->Surface->w >= 1024)
|
||||
{
|
||||
atlasHeight += y;
|
||||
atlasWidth = (atlasWidth >= x) ? atlasWidth : x;
|
||||
x = 0;
|
||||
y = 0;
|
||||
}
|
||||
|
||||
info->Glyph.Rect.w = info->Surface->w;
|
||||
info->Glyph.Rect.h = info->Surface->h;
|
||||
info->Glyph.Rect.x = x;
|
||||
info->Glyph.Rect.y = atlasHeight;
|
||||
Atlas[i] = info;
|
||||
info->Glyph.Rect.w = info->Surface->w;
|
||||
info->Glyph.Rect.h = info->Surface->h;
|
||||
info->Glyph.Rect.x = x;
|
||||
info->Glyph.Rect.y = atlasHeight;
|
||||
Atlas[i] = info;
|
||||
|
||||
x += info->Glyph.Rect.w;
|
||||
y = (y > info->Glyph.Rect.h) ? y : info->Glyph.Rect.h;
|
||||
/*
|
||||
std::stringstream ss;
|
||||
ss << " tw:" << atlasWidth << " th:" << atlasHeight << " x:" << x << " y:" << y << " w:" << info->Glyph.Rect.w << " h:" << info->Glyph.Rect.h;
|
||||
Logger::Write(Logger::ZONE_ERROR, "FontCache", ss.str());
|
||||
*/
|
||||
}
|
||||
x += info->Glyph.Rect.w;
|
||||
y = (y > info->Glyph.Rect.h) ? y : info->Glyph.Rect.h;
|
||||
/*
|
||||
std::stringstream ss;
|
||||
ss << " tw:" << atlasWidth << " th:" << atlasHeight << " x:" << x << " y:" << y << " w:" << info->Glyph.Rect.w << " h:" << info->Glyph.Rect.h;
|
||||
Logger::Write(Logger::ZONE_ERROR, "FontCache", ss.str());
|
||||
*/
|
||||
}
|
||||
|
||||
atlasWidth = (atlasWidth >= x) ? atlasWidth : x;
|
||||
atlasHeight += y;
|
||||
atlasWidth = (atlasWidth >= x) ? atlasWidth : x;
|
||||
atlasHeight += y;
|
||||
|
||||
unsigned int rmask;
|
||||
unsigned int gmask;
|
||||
unsigned int bmask;
|
||||
unsigned int amask;
|
||||
unsigned int rmask;
|
||||
unsigned int gmask;
|
||||
unsigned int bmask;
|
||||
unsigned int amask;
|
||||
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
|
||||
rmask = 0xff000000;
|
||||
gmask = 0x00ff0000;
|
||||
bmask = 0x0000ff00;
|
||||
amask = 0x000000ff;
|
||||
rmask = 0xff000000;
|
||||
gmask = 0x00ff0000;
|
||||
bmask = 0x0000ff00;
|
||||
amask = 0x000000ff;
|
||||
#else
|
||||
rmask = 0x000000ff;
|
||||
gmask = 0x0000ff00;
|
||||
bmask = 0x00ff0000;
|
||||
amask = 0xff000000;
|
||||
rmask = 0x000000ff;
|
||||
gmask = 0x0000ff00;
|
||||
bmask = 0x00ff0000;
|
||||
amask = 0xff000000;
|
||||
#endif
|
||||
SDL_Surface *atlasSurface = SDL_CreateRGBSurface(0, atlasWidth, atlasHeight, 24, rmask, gmask, bmask, amask);
|
||||
SDL_Surface *atlasSurface = SDL_CreateRGBSurface(0, atlasWidth, atlasHeight, 24, rmask, gmask, bmask, amask);
|
||||
|
||||
std::map<unsigned int, GlyphInfoBuild *>::iterator it;
|
||||
for(it = Atlas.begin(); it != Atlas.end(); it++)
|
||||
{
|
||||
GlyphInfoBuild *info = it->second;
|
||||
SDL_BlitSurface(info->Surface, NULL, atlasSurface, &info->Glyph.Rect);
|
||||
SDL_FreeSurface(info->Surface);
|
||||
info->Surface = NULL;
|
||||
}
|
||||
std::map<unsigned int, GlyphInfoBuild *>::iterator it;
|
||||
for(it = Atlas.begin(); it != Atlas.end(); it++)
|
||||
{
|
||||
GlyphInfoBuild *info = it->second;
|
||||
SDL_BlitSurface(info->Surface, NULL, atlasSurface, &info->Glyph.Rect);
|
||||
SDL_FreeSurface(info->Surface);
|
||||
info->Surface = NULL;
|
||||
}
|
||||
|
||||
SDL_LockMutex(SDL::GetMutex());
|
||||
SDL_SetColorKey(atlasSurface, SDL_TRUE, SDL_MapRGB(atlasSurface->format, 0, 0, 0));
|
||||
Texture = SDL_CreateTextureFromSurface(SDL::GetRenderer(), atlasSurface);
|
||||
SDL_FreeSurface(atlasSurface);
|
||||
SDL_UnlockMutex(SDL::GetMutex());
|
||||
SDL_LockMutex(SDL::GetMutex());
|
||||
SDL_SetColorKey(atlasSurface, SDL_TRUE, SDL_MapRGB(atlasSurface->format, 0, 0, 0));
|
||||
Texture = SDL_CreateTextureFromSurface(SDL::GetRenderer(), atlasSurface);
|
||||
SDL_FreeSurface(atlasSurface);
|
||||
SDL_UnlockMutex(SDL::GetMutex());
|
||||
|
||||
TTF_CloseFont(font);
|
||||
TTF_CloseFont(font);
|
||||
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
|
||||
void Font::DeInitialize()
|
||||
{
|
||||
if(Texture)
|
||||
{
|
||||
SDL_LockMutex(SDL::GetMutex());
|
||||
SDL_DestroyTexture(Texture);
|
||||
Texture = NULL;
|
||||
SDL_UnlockMutex(SDL::GetMutex());
|
||||
}
|
||||
if(Texture)
|
||||
{
|
||||
SDL_LockMutex(SDL::GetMutex());
|
||||
SDL_DestroyTexture(Texture);
|
||||
Texture = NULL;
|
||||
SDL_UnlockMutex(SDL::GetMutex());
|
||||
}
|
||||
|
||||
std::map<unsigned int, GlyphInfoBuild *>::iterator atlasIt = Atlas.begin();
|
||||
while(atlasIt != Atlas.end())
|
||||
{
|
||||
delete atlasIt->second;
|
||||
Atlas.erase(atlasIt);
|
||||
atlasIt = Atlas.begin();
|
||||
}
|
||||
std::map<unsigned int, GlyphInfoBuild *>::iterator atlasIt = Atlas.begin();
|
||||
while(atlasIt != Atlas.end())
|
||||
{
|
||||
delete atlasIt->second;
|
||||
Atlas.erase(atlasIt);
|
||||
atlasIt = Atlas.begin();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* This file is subject to the terms and conditions defined in
|
||||
* file 'LICENSE.txt', which is part of this source code package.
|
||||
*/
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <SDL2/SDL.h>
|
||||
@@ -10,33 +10,33 @@
|
||||
class Font
|
||||
{
|
||||
public:
|
||||
struct GlyphInfo
|
||||
{
|
||||
int MinX;
|
||||
int MaxX;
|
||||
int MinY;
|
||||
int MaxY;
|
||||
int Advance;
|
||||
SDL_Rect Rect;
|
||||
};
|
||||
struct GlyphInfo
|
||||
{
|
||||
int MinX;
|
||||
int MaxX;
|
||||
int MinY;
|
||||
int MaxY;
|
||||
int Advance;
|
||||
SDL_Rect Rect;
|
||||
};
|
||||
|
||||
Font();
|
||||
virtual ~Font();
|
||||
bool Initialize(std::string fontPath, SDL_Color color);
|
||||
void DeInitialize();
|
||||
SDL_Texture *GetTexture();
|
||||
bool GetRect(unsigned int charCode, GlyphInfo &glyph);
|
||||
Font();
|
||||
virtual ~Font();
|
||||
bool Initialize(std::string fontPath, SDL_Color color);
|
||||
void DeInitialize();
|
||||
SDL_Texture *GetTexture();
|
||||
bool GetRect(unsigned int charCode, GlyphInfo &glyph);
|
||||
|
||||
|
||||
private:
|
||||
struct GlyphInfoBuild
|
||||
{
|
||||
Font::GlyphInfo Glyph;
|
||||
SDL_Surface *Surface;
|
||||
};
|
||||
struct GlyphInfoBuild
|
||||
{
|
||||
Font::GlyphInfo Glyph;
|
||||
SDL_Surface *Surface;
|
||||
};
|
||||
|
||||
std::map<unsigned int, GlyphInfoBuild *> Atlas;
|
||||
SDL_Texture *Texture;
|
||||
std::map<unsigned int, GlyphInfoBuild *> Atlas;
|
||||
SDL_Texture *Texture;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* This file is subject to the terms and conditions defined in
|
||||
* file 'LICENSE.txt', which is part of this source code package.
|
||||
*/
|
||||
*/
|
||||
#include "FontCache.h"
|
||||
#include "Font.h"
|
||||
#include "../Utility/Log.h"
|
||||
@@ -10,63 +10,63 @@
|
||||
|
||||
//todo: memory leak when launching games
|
||||
FontCache::FontCache()
|
||||
: IsInitialized(false)
|
||||
: IsInitialized(false)
|
||||
{
|
||||
}
|
||||
|
||||
FontCache::~FontCache()
|
||||
{
|
||||
DeInitialize();
|
||||
DeInitialize();
|
||||
}
|
||||
|
||||
void FontCache::DeInitialize()
|
||||
{
|
||||
IsInitialized = false;
|
||||
std::map<std::string, Font *>::iterator it = FontFaceMap.begin();
|
||||
while(it != FontFaceMap.end())
|
||||
{
|
||||
delete it->second;
|
||||
FontFaceMap.erase(it);
|
||||
it = FontFaceMap.begin();
|
||||
}
|
||||
IsInitialized = false;
|
||||
std::map<std::string, Font *>::iterator it = FontFaceMap.begin();
|
||||
while(it != FontFaceMap.end())
|
||||
{
|
||||
delete it->second;
|
||||
FontFaceMap.erase(it);
|
||||
it = FontFaceMap.begin();
|
||||
}
|
||||
|
||||
SDL_LockMutex(SDL::GetMutex());
|
||||
TTF_Quit();
|
||||
SDL_UnlockMutex(SDL::GetMutex());
|
||||
SDL_LockMutex(SDL::GetMutex());
|
||||
TTF_Quit();
|
||||
SDL_UnlockMutex(SDL::GetMutex());
|
||||
}
|
||||
|
||||
|
||||
void FontCache::Initialize()
|
||||
{
|
||||
//todo: make bool
|
||||
TTF_Init();
|
||||
IsInitialized = true;
|
||||
//todo: make bool
|
||||
TTF_Init();
|
||||
IsInitialized = true;
|
||||
}
|
||||
Font *FontCache::GetFont(std::string fontPath)
|
||||
{
|
||||
Font *t = NULL;
|
||||
Font *t = NULL;
|
||||
|
||||
std::map<std::string, Font *>::iterator it = FontFaceMap.find(fontPath);
|
||||
std::map<std::string, Font *>::iterator it = FontFaceMap.find(fontPath);
|
||||
|
||||
if(it != FontFaceMap.end())
|
||||
{
|
||||
t = it->second;
|
||||
}
|
||||
if(it != FontFaceMap.end())
|
||||
{
|
||||
t = it->second;
|
||||
}
|
||||
|
||||
return t;
|
||||
return t;
|
||||
}
|
||||
|
||||
bool FontCache::LoadFont(std::string fontPath, SDL_Color color)
|
||||
{
|
||||
std::map<std::string, Font *>::iterator it = FontFaceMap.find(fontPath);
|
||||
std::map<std::string, Font *>::iterator it = FontFaceMap.find(fontPath);
|
||||
|
||||
if(it == FontFaceMap.end())
|
||||
{
|
||||
Font *f = new Font();
|
||||
f->Initialize(fontPath, color);
|
||||
FontFaceMap[fontPath] = f;
|
||||
}
|
||||
if(it == FontFaceMap.end())
|
||||
{
|
||||
Font *f = new Font();
|
||||
f->Initialize(fontPath, color);
|
||||
FontFaceMap[fontPath] = f;
|
||||
}
|
||||
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* This file is subject to the terms and conditions defined in
|
||||
* file 'LICENSE.txt', which is part of this source code package.
|
||||
*/
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include "Font.h"
|
||||
@@ -10,17 +10,17 @@
|
||||
class FontCache
|
||||
{
|
||||
public:
|
||||
void Initialize();
|
||||
void DeInitialize();
|
||||
FontCache();
|
||||
bool LoadFont(std::string font, SDL_Color color);
|
||||
Font *GetFont(std::string font);
|
||||
void Initialize();
|
||||
void DeInitialize();
|
||||
FontCache();
|
||||
bool LoadFont(std::string font, SDL_Color color);
|
||||
Font *GetFont(std::string font);
|
||||
|
||||
virtual ~FontCache();
|
||||
virtual ~FontCache();
|
||||
private:
|
||||
bool IsInitialized;
|
||||
bool IsInitialized;
|
||||
|
||||
std::map<std::string, Font *> FontFaceMap;
|
||||
std::map<std::string, Font *> FontFaceMap;
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* This file is subject to the terms and conditions defined in
|
||||
* file 'LICENSE.txt', which is part of this source code package.
|
||||
*/
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include "../Collection/Item.h"
|
||||
@@ -8,7 +8,7 @@
|
||||
class MenuNotifierInterface
|
||||
{
|
||||
public:
|
||||
virtual ~MenuNotifierInterface() {}
|
||||
virtual void OnNewItemSelected(Item *) = 0;
|
||||
virtual ~MenuNotifierInterface() {}
|
||||
virtual void OnNewItemSelected(Item *) = 0;
|
||||
};
|
||||
|
||||
|
||||
@@ -11,145 +11,145 @@
|
||||
#include <sstream>
|
||||
|
||||
Page::Page(std::string collectionName)
|
||||
: CollectionName(collectionName)
|
||||
, Menu(NULL)
|
||||
, Items(NULL)
|
||||
, ScrollActive(false)
|
||||
, SelectedItem(NULL)
|
||||
, SelectedItemChanged(false)
|
||||
, LoadSoundChunk(NULL)
|
||||
, UnloadSoundChunk(NULL)
|
||||
, HighlightSoundChunk(NULL)
|
||||
, SelectSoundChunk(NULL)
|
||||
, HasSoundedWhenActive(false)
|
||||
, FirstSoundPlayed(false)
|
||||
: CollectionName(collectionName)
|
||||
, Menu(NULL)
|
||||
, Items(NULL)
|
||||
, ScrollActive(false)
|
||||
, SelectedItem(NULL)
|
||||
, SelectedItemChanged(false)
|
||||
, LoadSoundChunk(NULL)
|
||||
, UnloadSoundChunk(NULL)
|
||||
, HighlightSoundChunk(NULL)
|
||||
, SelectSoundChunk(NULL)
|
||||
, HasSoundedWhenActive(false)
|
||||
, FirstSoundPlayed(false)
|
||||
{
|
||||
}
|
||||
|
||||
Page::~Page()
|
||||
{
|
||||
if(Menu)
|
||||
{
|
||||
Menu->RemoveComponentForNotifications(this);
|
||||
}
|
||||
if(Menu)
|
||||
{
|
||||
Menu->RemoveComponentForNotifications(this);
|
||||
}
|
||||
|
||||
for(unsigned int i = 0; i < sizeof(LayerComponents)/sizeof(LayerComponents[0]); ++i)
|
||||
{
|
||||
for(std::vector<Component *>::iterator it = LayerComponents[i].begin(); it != LayerComponents[i].end(); ++it)
|
||||
{
|
||||
delete *it;
|
||||
}
|
||||
for(unsigned int i = 0; i < sizeof(LayerComponents)/sizeof(LayerComponents[0]); ++i)
|
||||
{
|
||||
for(std::vector<Component *>::iterator it = LayerComponents[i].begin(); it != LayerComponents[i].end(); ++it)
|
||||
{
|
||||
delete *it;
|
||||
}
|
||||
|
||||
LayerComponents[i].clear();
|
||||
}
|
||||
LayerComponents[i].clear();
|
||||
}
|
||||
|
||||
if(Menu)
|
||||
{
|
||||
delete Menu;
|
||||
}
|
||||
if(Menu)
|
||||
{
|
||||
delete Menu;
|
||||
}
|
||||
|
||||
if(LoadSoundChunk)
|
||||
{
|
||||
delete LoadSoundChunk;
|
||||
LoadSoundChunk = NULL;
|
||||
}
|
||||
if(LoadSoundChunk)
|
||||
{
|
||||
delete LoadSoundChunk;
|
||||
LoadSoundChunk = NULL;
|
||||
}
|
||||
|
||||
if(UnloadSoundChunk)
|
||||
{
|
||||
delete UnloadSoundChunk;
|
||||
UnloadSoundChunk = NULL;
|
||||
}
|
||||
if(UnloadSoundChunk)
|
||||
{
|
||||
delete UnloadSoundChunk;
|
||||
UnloadSoundChunk = NULL;
|
||||
}
|
||||
|
||||
|
||||
if(HighlightSoundChunk)
|
||||
{
|
||||
delete HighlightSoundChunk;
|
||||
HighlightSoundChunk = NULL;
|
||||
}
|
||||
if(HighlightSoundChunk)
|
||||
{
|
||||
delete HighlightSoundChunk;
|
||||
HighlightSoundChunk = NULL;
|
||||
}
|
||||
|
||||
if(SelectSoundChunk)
|
||||
{
|
||||
delete SelectSoundChunk;
|
||||
SelectSoundChunk = NULL;
|
||||
}
|
||||
if(SelectSoundChunk)
|
||||
{
|
||||
delete SelectSoundChunk;
|
||||
SelectSoundChunk = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
void Page::OnNewItemSelected(Item *item)
|
||||
{
|
||||
SelectedItem = item;
|
||||
SelectedItemChanged = true;
|
||||
SelectedItem = item;
|
||||
SelectedItemChanged = true;
|
||||
}
|
||||
|
||||
void Page::SetMenu(ScrollingList *s)
|
||||
{
|
||||
// todo: delete the old menu
|
||||
Menu = s;
|
||||
// todo: delete the old menu
|
||||
Menu = s;
|
||||
|
||||
if(Menu)
|
||||
{
|
||||
Menu->AddComponentForNotifications(this);
|
||||
}
|
||||
if(Menu)
|
||||
{
|
||||
Menu->AddComponentForNotifications(this);
|
||||
}
|
||||
}
|
||||
|
||||
bool Page::AddComponent(Component *c)
|
||||
{
|
||||
bool retVal = false;
|
||||
bool retVal = false;
|
||||
|
||||
unsigned int layer = c->GetBaseViewInfo()->GetLayer();
|
||||
unsigned int layer = c->GetBaseViewInfo()->GetLayer();
|
||||
|
||||
|
||||
if(layer < NUM_LAYERS)
|
||||
{
|
||||
LayerComponents[layer].push_back(c);
|
||||
if(layer < NUM_LAYERS)
|
||||
{
|
||||
LayerComponents[layer].push_back(c);
|
||||
|
||||
retVal = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << "Component layer too large Layer: " << layer;
|
||||
Logger::Write(Logger::ZONE_ERROR, "Page", ss.str());
|
||||
}
|
||||
retVal = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << "Component layer too large Layer: " << layer;
|
||||
Logger::Write(Logger::ZONE_ERROR, "Page", ss.str());
|
||||
}
|
||||
|
||||
return retVal;
|
||||
return retVal;
|
||||
}
|
||||
|
||||
bool Page::IsIdle()
|
||||
{
|
||||
bool idle = true;
|
||||
bool idle = true;
|
||||
|
||||
if(Menu != NULL && !Menu->IsIdle())
|
||||
{
|
||||
idle = false;
|
||||
}
|
||||
if(Menu != NULL && !Menu->IsIdle())
|
||||
{
|
||||
idle = false;
|
||||
}
|
||||
|
||||
for(unsigned int i = 0; i < NUM_LAYERS && idle; ++i)
|
||||
{
|
||||
for(std::vector<Component *>::iterator it = LayerComponents[i].begin(); it != LayerComponents[i].end() && idle; ++it)
|
||||
{
|
||||
idle = (*it)->IsIdle();
|
||||
}
|
||||
}
|
||||
for(unsigned int i = 0; i < NUM_LAYERS && idle; ++i)
|
||||
{
|
||||
for(std::vector<Component *>::iterator it = LayerComponents[i].begin(); it != LayerComponents[i].end() && idle; ++it)
|
||||
{
|
||||
idle = (*it)->IsIdle();
|
||||
}
|
||||
}
|
||||
|
||||
return idle;
|
||||
return idle;
|
||||
}
|
||||
|
||||
|
||||
bool Page::IsHidden()
|
||||
{
|
||||
bool hidden = true;
|
||||
bool hidden = true;
|
||||
|
||||
if(Menu != NULL)
|
||||
{
|
||||
hidden = Menu->IsHidden();
|
||||
hidden = Menu->IsHidden();
|
||||
}
|
||||
|
||||
for(unsigned int i = 0; hidden && i < NUM_LAYERS; ++i)
|
||||
{
|
||||
for(std::vector<Component *>::iterator it = LayerComponents[i].begin(); hidden && it != LayerComponents[i].end(); ++it)
|
||||
{
|
||||
hidden = (*it)->IsHidden();
|
||||
}
|
||||
for(std::vector<Component *>::iterator it = LayerComponents[i].begin(); hidden && it != LayerComponents[i].end(); ++it)
|
||||
{
|
||||
hidden = (*it)->IsHidden();
|
||||
}
|
||||
}
|
||||
|
||||
return hidden;
|
||||
@@ -157,250 +157,250 @@ bool Page::IsHidden()
|
||||
|
||||
void Page::Start()
|
||||
{
|
||||
Menu->TriggerEnterEvent();
|
||||
Menu->TriggerEnterEvent();
|
||||
|
||||
if(LoadSoundChunk)
|
||||
{
|
||||
LoadSoundChunk->Play();
|
||||
}
|
||||
if(LoadSoundChunk)
|
||||
{
|
||||
LoadSoundChunk->Play();
|
||||
}
|
||||
|
||||
for(unsigned int i = 0; i < NUM_LAYERS; ++i)
|
||||
{
|
||||
for(std::vector<Component *>::iterator it = LayerComponents[i].begin(); it != LayerComponents[i].end(); ++it)
|
||||
{
|
||||
(*it)->TriggerEnterEvent();
|
||||
}
|
||||
}
|
||||
for(unsigned int i = 0; i < NUM_LAYERS; ++i)
|
||||
{
|
||||
for(std::vector<Component *>::iterator it = LayerComponents[i].begin(); it != LayerComponents[i].end(); ++it)
|
||||
{
|
||||
(*it)->TriggerEnterEvent();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Page::Stop()
|
||||
{
|
||||
Menu->TriggerExitEvent();
|
||||
Menu->TriggerExitEvent();
|
||||
|
||||
if(UnloadSoundChunk)
|
||||
{
|
||||
UnloadSoundChunk->Play();
|
||||
}
|
||||
if(UnloadSoundChunk)
|
||||
{
|
||||
UnloadSoundChunk->Play();
|
||||
}
|
||||
|
||||
for(unsigned int i = 0; i < NUM_LAYERS; ++i)
|
||||
{
|
||||
for(std::vector<Component *>::iterator it = LayerComponents[i].begin(); it != LayerComponents[i].end(); ++it)
|
||||
{
|
||||
(*it)->TriggerExitEvent();
|
||||
}
|
||||
}
|
||||
for(unsigned int i = 0; i < NUM_LAYERS; ++i)
|
||||
{
|
||||
for(std::vector<Component *>::iterator it = LayerComponents[i].begin(); it != LayerComponents[i].end(); ++it)
|
||||
{
|
||||
(*it)->TriggerExitEvent();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Item *Page::GetSelectedItem()
|
||||
{
|
||||
return SelectedItem;
|
||||
return SelectedItem;
|
||||
}
|
||||
|
||||
void Page::RemoveSelectedItem()
|
||||
{
|
||||
if(Menu)
|
||||
{
|
||||
//todo: change method to RemoveItem() and pass in SelectedItem
|
||||
Menu->RemoveSelectedItem();
|
||||
SelectedItem = NULL;
|
||||
}
|
||||
if(Menu)
|
||||
{
|
||||
//todo: change method to RemoveItem() and pass in SelectedItem
|
||||
Menu->RemoveSelectedItem();
|
||||
SelectedItem = NULL;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
void Page::Highlight()
|
||||
{
|
||||
Item *item = SelectedItem;
|
||||
Item *item = SelectedItem;
|
||||
|
||||
if(item)
|
||||
{
|
||||
if(Menu)
|
||||
{
|
||||
Menu->TriggerHighlightEvent(item);
|
||||
Menu->SetScrollActive(ScrollActive);
|
||||
}
|
||||
if(item)
|
||||
{
|
||||
if(Menu)
|
||||
{
|
||||
Menu->TriggerHighlightEvent(item);
|
||||
Menu->SetScrollActive(ScrollActive);
|
||||
}
|
||||
|
||||
for(unsigned int i = 0; i < NUM_LAYERS; ++i)
|
||||
{
|
||||
for(std::vector<Component *>::iterator it = LayerComponents[i].begin(); it != LayerComponents[i].end(); ++it)
|
||||
{
|
||||
(*it)->TriggerHighlightEvent(item);
|
||||
(*it)->SetScrollActive(ScrollActive);
|
||||
}
|
||||
}
|
||||
}
|
||||
for(unsigned int i = 0; i < NUM_LAYERS; ++i)
|
||||
{
|
||||
for(std::vector<Component *>::iterator it = LayerComponents[i].begin(); it != LayerComponents[i].end(); ++it)
|
||||
{
|
||||
(*it)->TriggerHighlightEvent(item);
|
||||
(*it)->SetScrollActive(ScrollActive);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Page::SetScrolling(ScrollDirection direction)
|
||||
{
|
||||
ScrollingList::ScrollDirection menuDirection;
|
||||
ScrollingList::ScrollDirection menuDirection;
|
||||
|
||||
switch(direction)
|
||||
{
|
||||
case ScrollDirectionForward:
|
||||
menuDirection = ScrollingList::ScrollDirectionForward;
|
||||
ScrollActive = true;
|
||||
break;
|
||||
case ScrollDirectionBack:
|
||||
menuDirection = ScrollingList::ScrollDirectionBack;
|
||||
ScrollActive = true;
|
||||
break;
|
||||
case ScrollDirectionIdle:
|
||||
default:
|
||||
menuDirection = ScrollingList::ScrollDirectionIdle;
|
||||
ScrollActive = false;
|
||||
break;
|
||||
}
|
||||
if(Menu)
|
||||
{
|
||||
Menu->SetScrollDirection(menuDirection);
|
||||
}
|
||||
switch(direction)
|
||||
{
|
||||
case ScrollDirectionForward:
|
||||
menuDirection = ScrollingList::ScrollDirectionForward;
|
||||
ScrollActive = true;
|
||||
break;
|
||||
case ScrollDirectionBack:
|
||||
menuDirection = ScrollingList::ScrollDirectionBack;
|
||||
ScrollActive = true;
|
||||
break;
|
||||
case ScrollDirectionIdle:
|
||||
default:
|
||||
menuDirection = ScrollingList::ScrollDirectionIdle;
|
||||
ScrollActive = false;
|
||||
break;
|
||||
}
|
||||
if(Menu)
|
||||
{
|
||||
Menu->SetScrollDirection(menuDirection);
|
||||
}
|
||||
}
|
||||
|
||||
void Page::PageScroll(ScrollDirection direction)
|
||||
{
|
||||
if(Menu)
|
||||
{
|
||||
if(direction == ScrollDirectionForward)
|
||||
{
|
||||
Menu->PageDown();
|
||||
}
|
||||
if(direction == ScrollDirectionBack)
|
||||
{
|
||||
Menu->PageUp();
|
||||
}
|
||||
}
|
||||
if(Menu)
|
||||
{
|
||||
if(direction == ScrollDirectionForward)
|
||||
{
|
||||
Menu->PageDown();
|
||||
}
|
||||
if(direction == ScrollDirectionBack)
|
||||
{
|
||||
Menu->PageUp();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Page::SetItems(std::vector<Item *> *items)
|
||||
{
|
||||
std::vector<ComponentItemBinding *> *sprites = ComponentItemBindingBuilder::BuildCollectionItems(items);
|
||||
std::vector<ComponentItemBinding *> *sprites = ComponentItemBindingBuilder::BuildCollectionItems(items);
|
||||
|
||||
if(Menu != NULL)
|
||||
{
|
||||
Menu->SetItems(sprites);
|
||||
}
|
||||
if(Menu != NULL)
|
||||
{
|
||||
Menu->SetItems(sprites);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Page::Update(float dt)
|
||||
{
|
||||
if(Menu != NULL)
|
||||
{
|
||||
Menu->Update(dt);
|
||||
}
|
||||
if(SelectedItemChanged && !HasSoundedWhenActive && HighlightSoundChunk)
|
||||
{
|
||||
// skip the first sound being played (as it is part of the on-enter)
|
||||
if(FirstSoundPlayed)
|
||||
{
|
||||
HighlightSoundChunk->Play();
|
||||
HasSoundedWhenActive = true;
|
||||
}
|
||||
FirstSoundPlayed = true;
|
||||
}
|
||||
if(Menu != NULL)
|
||||
{
|
||||
Menu->Update(dt);
|
||||
}
|
||||
if(SelectedItemChanged && !HasSoundedWhenActive && HighlightSoundChunk)
|
||||
{
|
||||
// skip the first sound being played (as it is part of the on-enter)
|
||||
if(FirstSoundPlayed)
|
||||
{
|
||||
HighlightSoundChunk->Play();
|
||||
HasSoundedWhenActive = true;
|
||||
}
|
||||
FirstSoundPlayed = true;
|
||||
}
|
||||
|
||||
if(SelectedItemChanged && !ScrollActive)
|
||||
{
|
||||
Highlight();
|
||||
SelectedItemChanged = false;
|
||||
HasSoundedWhenActive = false;
|
||||
}
|
||||
if(SelectedItemChanged && !ScrollActive)
|
||||
{
|
||||
Highlight();
|
||||
SelectedItemChanged = false;
|
||||
HasSoundedWhenActive = false;
|
||||
}
|
||||
|
||||
for(unsigned int i = 0; i < NUM_LAYERS; ++i)
|
||||
{
|
||||
for(std::vector<Component *>::iterator it = LayerComponents[i].begin(); it != LayerComponents[i].end(); ++it)
|
||||
{
|
||||
(*it)->Update(dt);
|
||||
}
|
||||
}
|
||||
for(unsigned int i = 0; i < NUM_LAYERS; ++i)
|
||||
{
|
||||
for(std::vector<Component *>::iterator it = LayerComponents[i].begin(); it != LayerComponents[i].end(); ++it)
|
||||
{
|
||||
(*it)->Update(dt);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Page::Draw()
|
||||
{
|
||||
for(unsigned int i = 0; i < NUM_LAYERS; ++i)
|
||||
{
|
||||
for(std::vector<Component *>::iterator it = LayerComponents[i].begin(); it != LayerComponents[i].end(); ++it)
|
||||
{
|
||||
(*it)->Draw();
|
||||
}
|
||||
for(unsigned int i = 0; i < NUM_LAYERS; ++i)
|
||||
{
|
||||
for(std::vector<Component *>::iterator it = LayerComponents[i].begin(); it != LayerComponents[i].end(); ++it)
|
||||
{
|
||||
(*it)->Draw();
|
||||
}
|
||||
|
||||
Menu->Draw(i);
|
||||
}
|
||||
Menu->Draw(i);
|
||||
}
|
||||
}
|
||||
|
||||
const std::string& Page::GetCollectionName() const
|
||||
{
|
||||
return CollectionName;
|
||||
return CollectionName;
|
||||
}
|
||||
|
||||
void Page::FreeGraphicsMemory()
|
||||
{
|
||||
Logger::Write(Logger::ZONE_DEBUG, "Page", "Free");
|
||||
Menu->FreeGraphicsMemory();
|
||||
Logger::Write(Logger::ZONE_DEBUG, "Page", "Free");
|
||||
Menu->FreeGraphicsMemory();
|
||||
|
||||
if(LoadSoundChunk) LoadSoundChunk->Free();
|
||||
if(UnloadSoundChunk) UnloadSoundChunk->Free();
|
||||
if(HighlightSoundChunk) HighlightSoundChunk->Free();
|
||||
if(SelectSoundChunk) SelectSoundChunk->Free();
|
||||
if(LoadSoundChunk) LoadSoundChunk->Free();
|
||||
if(UnloadSoundChunk) UnloadSoundChunk->Free();
|
||||
if(HighlightSoundChunk) HighlightSoundChunk->Free();
|
||||
if(SelectSoundChunk) SelectSoundChunk->Free();
|
||||
|
||||
for(unsigned int i = 0; i < NUM_LAYERS; ++i)
|
||||
{
|
||||
for(std::vector<Component *>::iterator it = LayerComponents[i].begin(); it != LayerComponents[i].end(); ++it)
|
||||
{
|
||||
(*it)->FreeGraphicsMemory();
|
||||
}
|
||||
}
|
||||
for(unsigned int i = 0; i < NUM_LAYERS; ++i)
|
||||
{
|
||||
for(std::vector<Component *>::iterator it = LayerComponents[i].begin(); it != LayerComponents[i].end(); ++it)
|
||||
{
|
||||
(*it)->FreeGraphicsMemory();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Page::AllocateGraphicsMemory()
|
||||
{
|
||||
FirstSoundPlayed = false;
|
||||
Logger::Write(Logger::ZONE_DEBUG, "Page", "Allocating graphics memory");
|
||||
Menu->AllocateGraphicsMemory();
|
||||
FirstSoundPlayed = false;
|
||||
Logger::Write(Logger::ZONE_DEBUG, "Page", "Allocating graphics memory");
|
||||
Menu->AllocateGraphicsMemory();
|
||||
|
||||
if(LoadSoundChunk) LoadSoundChunk->Allocate();
|
||||
if(UnloadSoundChunk) UnloadSoundChunk->Allocate();
|
||||
if(HighlightSoundChunk) HighlightSoundChunk->Allocate();
|
||||
if(SelectSoundChunk) SelectSoundChunk->Allocate();
|
||||
if(LoadSoundChunk) LoadSoundChunk->Allocate();
|
||||
if(UnloadSoundChunk) UnloadSoundChunk->Allocate();
|
||||
if(HighlightSoundChunk) HighlightSoundChunk->Allocate();
|
||||
if(SelectSoundChunk) SelectSoundChunk->Allocate();
|
||||
|
||||
for(unsigned int i = 0; i < NUM_LAYERS; ++i)
|
||||
{
|
||||
for(std::vector<Component *>::iterator it = LayerComponents[i].begin(); it != LayerComponents[i].end(); ++it)
|
||||
{
|
||||
(*it)->AllocateGraphicsMemory();
|
||||
}
|
||||
}
|
||||
Logger::Write(Logger::ZONE_DEBUG, "Page", "Allocate graphics memory complete");
|
||||
for(unsigned int i = 0; i < NUM_LAYERS; ++i)
|
||||
{
|
||||
for(std::vector<Component *>::iterator it = LayerComponents[i].begin(); it != LayerComponents[i].end(); ++it)
|
||||
{
|
||||
(*it)->AllocateGraphicsMemory();
|
||||
}
|
||||
}
|
||||
Logger::Write(Logger::ZONE_DEBUG, "Page", "Allocate graphics memory complete");
|
||||
}
|
||||
|
||||
void Page::LaunchEnter()
|
||||
{
|
||||
Menu->LaunchEnter();
|
||||
Menu->LaunchEnter();
|
||||
|
||||
for(unsigned int i = 0; i < NUM_LAYERS; ++i)
|
||||
{
|
||||
for(std::vector<Component *>::iterator it = LayerComponents[i].begin(); it != LayerComponents[i].end(); ++it)
|
||||
{
|
||||
(*it)->LaunchEnter();
|
||||
}
|
||||
}
|
||||
for(unsigned int i = 0; i < NUM_LAYERS; ++i)
|
||||
{
|
||||
for(std::vector<Component *>::iterator it = LayerComponents[i].begin(); it != LayerComponents[i].end(); ++it)
|
||||
{
|
||||
(*it)->LaunchEnter();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Page::LaunchExit()
|
||||
{
|
||||
Menu->LaunchExit();
|
||||
Menu->LaunchExit();
|
||||
|
||||
for(unsigned int i = 0; i < NUM_LAYERS; ++i)
|
||||
{
|
||||
for(std::vector<Component *>::iterator it = LayerComponents[i].begin(); it != LayerComponents[i].end(); ++it)
|
||||
{
|
||||
(*it)->LaunchExit();
|
||||
}
|
||||
}
|
||||
for(unsigned int i = 0; i < NUM_LAYERS; ++i)
|
||||
{
|
||||
for(std::vector<Component *>::iterator it = LayerComponents[i].begin(); it != LayerComponents[i].end(); ++it)
|
||||
{
|
||||
(*it)->LaunchExit();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -16,56 +16,68 @@ class Sound;
|
||||
class Page : public MenuNotifierInterface
|
||||
{
|
||||
public:
|
||||
enum ScrollDirection
|
||||
{
|
||||
ScrollDirectionForward,
|
||||
ScrollDirectionBack,
|
||||
ScrollDirectionIdle
|
||||
enum ScrollDirection
|
||||
{
|
||||
ScrollDirectionForward,
|
||||
ScrollDirectionBack,
|
||||
ScrollDirectionIdle
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
Page(std::string collectionName);
|
||||
virtual ~Page();
|
||||
virtual void OnNewItemSelected(Item *);
|
||||
void SetItems(std::vector<Item *> *items);
|
||||
void SetMenu(ScrollingList *s);
|
||||
void SetLoadSound(Sound *chunk) { LoadSoundChunk = chunk; }
|
||||
void SetUnloadSound(Sound *chunk) { UnloadSoundChunk = chunk; }
|
||||
void SetHighlightSound(Sound *chunk) { HighlightSoundChunk = chunk; }
|
||||
void SetSelectSound(Sound *chunk) { SelectSoundChunk = chunk; }
|
||||
bool AddComponent(Component *c);
|
||||
void PageScroll(ScrollDirection direction);
|
||||
void Start();
|
||||
void Stop();
|
||||
void SetScrolling(ScrollDirection direction);
|
||||
Item *GetSelectedItem();
|
||||
Item *GetPendingSelectedItem();
|
||||
void RemoveSelectedItem();
|
||||
bool IsIdle();
|
||||
bool IsHidden();
|
||||
void Update(float dt);
|
||||
void Draw();
|
||||
void FreeGraphicsMemory();
|
||||
void AllocateGraphicsMemory();
|
||||
void LaunchEnter();
|
||||
void LaunchExit();
|
||||
const std::string& GetCollectionName() const;
|
||||
Page(std::string collectionName);
|
||||
virtual ~Page();
|
||||
virtual void OnNewItemSelected(Item *);
|
||||
void SetItems(std::vector<Item *> *items);
|
||||
void SetMenu(ScrollingList *s);
|
||||
void SetLoadSound(Sound *chunk)
|
||||
{
|
||||
LoadSoundChunk = chunk;
|
||||
}
|
||||
void SetUnloadSound(Sound *chunk)
|
||||
{
|
||||
UnloadSoundChunk = chunk;
|
||||
}
|
||||
void SetHighlightSound(Sound *chunk)
|
||||
{
|
||||
HighlightSoundChunk = chunk;
|
||||
}
|
||||
void SetSelectSound(Sound *chunk)
|
||||
{
|
||||
SelectSoundChunk = chunk;
|
||||
}
|
||||
bool AddComponent(Component *c);
|
||||
void PageScroll(ScrollDirection direction);
|
||||
void Start();
|
||||
void Stop();
|
||||
void SetScrolling(ScrollDirection direction);
|
||||
Item *GetSelectedItem();
|
||||
Item *GetPendingSelectedItem();
|
||||
void RemoveSelectedItem();
|
||||
bool IsIdle();
|
||||
bool IsHidden();
|
||||
void Update(float dt);
|
||||
void Draw();
|
||||
void FreeGraphicsMemory();
|
||||
void AllocateGraphicsMemory();
|
||||
void LaunchEnter();
|
||||
void LaunchExit();
|
||||
const std::string& GetCollectionName() const;
|
||||
|
||||
private:
|
||||
void Highlight();
|
||||
std::string CollectionName;
|
||||
ScrollingList *Menu;
|
||||
static const unsigned int NUM_LAYERS = 8;
|
||||
std::vector<Component *> LayerComponents[NUM_LAYERS];
|
||||
std::vector<Item *> *Items;
|
||||
bool ScrollActive;
|
||||
Item *SelectedItem;
|
||||
bool SelectedItemChanged;
|
||||
Sound *LoadSoundChunk;
|
||||
Sound *UnloadSoundChunk;
|
||||
Sound *HighlightSoundChunk;
|
||||
Sound *SelectSoundChunk;
|
||||
bool HasSoundedWhenActive;
|
||||
bool FirstSoundPlayed;
|
||||
void Highlight();
|
||||
std::string CollectionName;
|
||||
ScrollingList *Menu;
|
||||
static const unsigned int NUM_LAYERS = 8;
|
||||
std::vector<Component *> LayerComponents[NUM_LAYERS];
|
||||
std::vector<Item *> *Items;
|
||||
bool ScrollActive;
|
||||
Item *SelectedItem;
|
||||
bool SelectedItemChanged;
|
||||
Sound *LoadSoundChunk;
|
||||
Sound *UnloadSoundChunk;
|
||||
Sound *HighlightSoundChunk;
|
||||
Sound *SelectSoundChunk;
|
||||
bool HasSoundedWhenActive;
|
||||
bool FirstSoundPlayed;
|
||||
|
||||
};
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -18,42 +18,42 @@ class Configuration;
|
||||
class PageBuilder
|
||||
{
|
||||
public:
|
||||
PageBuilder(std::string layoutKey, std::string collection, Configuration *c, FontCache *fc);
|
||||
virtual ~PageBuilder();
|
||||
Page *BuildPage();
|
||||
PageBuilder(std::string layoutKey, std::string collection, Configuration *c, FontCache *fc);
|
||||
virtual ~PageBuilder();
|
||||
Page *BuildPage();
|
||||
|
||||
private:
|
||||
std::string LayoutKey;
|
||||
std::string LayoutPath;
|
||||
std::string Collection;
|
||||
Configuration *Config;
|
||||
float ScaleX;
|
||||
float ScaleY;
|
||||
int ScreenHeight;
|
||||
int ScreenWidth;
|
||||
SDL_Color FontColor;
|
||||
std::string Font;
|
||||
FontCache *FC; //todo: don't need Font itself, just need cache instances
|
||||
void LoadReloadableImages(rapidxml::xml_node<> *layout, std::string tagName, Page *page);
|
||||
std::string LayoutKey;
|
||||
std::string LayoutPath;
|
||||
std::string Collection;
|
||||
Configuration *Config;
|
||||
float ScaleX;
|
||||
float ScaleY;
|
||||
int ScreenHeight;
|
||||
int ScreenWidth;
|
||||
SDL_Color FontColor;
|
||||
std::string Font;
|
||||
FontCache *FC; //todo: don't need Font itself, just need cache instances
|
||||
void LoadReloadableImages(rapidxml::xml_node<> *layout, std::string tagName, Page *page);
|
||||
|
||||
float GetVerticalAlignment(rapidxml::xml_attribute<> *attribute, float valueIfNull);
|
||||
float GetHorizontalAlignment(rapidxml::xml_attribute<> *attribute, float valueIfNull);
|
||||
void BuildViewInfo(rapidxml::xml_node<> *componentXml, ViewInfo *info);
|
||||
bool BuildComponents(rapidxml::xml_node<> *layout, Page *page);
|
||||
void LoadTweens(Component *c, rapidxml::xml_node<> *componentXml);
|
||||
ScrollingList * BuildCustomMenu(rapidxml::xml_node<> *menuXml);
|
||||
rapidxml::xml_attribute<> *FindRecursiveAttribute(rapidxml::xml_node<> *componentXml, std::string attribute);
|
||||
float GetVerticalAlignment(rapidxml::xml_attribute<> *attribute, float valueIfNull);
|
||||
float GetHorizontalAlignment(rapidxml::xml_attribute<> *attribute, float valueIfNull);
|
||||
void BuildViewInfo(rapidxml::xml_node<> *componentXml, ViewInfo *info);
|
||||
bool BuildComponents(rapidxml::xml_node<> *layout, Page *page);
|
||||
void LoadTweens(Component *c, rapidxml::xml_node<> *componentXml);
|
||||
ScrollingList * BuildCustomMenu(rapidxml::xml_node<> *menuXml);
|
||||
rapidxml::xml_attribute<> *FindRecursiveAttribute(rapidxml::xml_node<> *componentXml, std::string attribute);
|
||||
|
||||
void GetTweenSets(rapidxml::xml_node<> *node, std::vector<std::vector<Tween *> *> *tweenSets);
|
||||
void GetTweenSet(rapidxml::xml_node<> *node, std::vector<Tween *> &tweens);
|
||||
void GetTweenSets(rapidxml::xml_node<> *node, std::vector<std::vector<Tween *> *> *tweenSets);
|
||||
void GetTweenSet(rapidxml::xml_node<> *node, std::vector<Tween *> &tweens);
|
||||
|
||||
|
||||
void LoadLayoutXml();
|
||||
void LoadAnimations(std::string keyPrefix, Component &component, ViewInfo *defaults);
|
||||
std::vector<ViewInfo *> *BuildTweenPoints(std::string iteratorPrefix, ViewInfo *defaults);
|
||||
Component * LoadComponent(std::string keyPrefix);
|
||||
ScrollingList * LoadMenu();
|
||||
void LoadLayoutXml();
|
||||
void LoadAnimations(std::string keyPrefix, Component &component, ViewInfo *defaults);
|
||||
std::vector<ViewInfo *> *BuildTweenPoints(std::string iteratorPrefix, ViewInfo *defaults);
|
||||
Component * LoadComponent(std::string keyPrefix);
|
||||
ScrollingList * LoadMenu();
|
||||
|
||||
void LoadListItems(std::string keyPrefix, std::vector<ViewInfo *> *tweenPointList, ViewInfo *defaults, int &selectedItemIndex);
|
||||
void UpdateViewInfoFromTag(std::string keyPrefix, ViewInfo *p, ViewInfo *defaults);
|
||||
void LoadListItems(std::string keyPrefix, std::vector<ViewInfo *> *tweenPointList, ViewInfo *defaults, int &selectedItemIndex);
|
||||
void UpdateViewInfoFromTag(std::string keyPrefix, ViewInfo *p, ViewInfo *defaults);
|
||||
};
|
||||
|
||||
@@ -7,24 +7,24 @@
|
||||
#include <cfloat>
|
||||
|
||||
ViewInfo::ViewInfo()
|
||||
: X(0)
|
||||
, Y(0)
|
||||
, XOrigin(0)
|
||||
, YOrigin(0)
|
||||
, XOffset(0)
|
||||
, YOffset(0)
|
||||
, Width(-1)
|
||||
, MinWidth(0)
|
||||
, MaxWidth(FLT_MAX)
|
||||
, Height(-1)
|
||||
, MinHeight(0)
|
||||
, MaxHeight(FLT_MAX)
|
||||
, ImageWidth(0)
|
||||
, ImageHeight(0)
|
||||
, FontSize(-1)
|
||||
, Angle(0)
|
||||
, Transparency(1)
|
||||
, Layer(0)
|
||||
: X(0)
|
||||
, Y(0)
|
||||
, XOrigin(0)
|
||||
, YOrigin(0)
|
||||
, XOffset(0)
|
||||
, YOffset(0)
|
||||
, Width(-1)
|
||||
, MinWidth(0)
|
||||
, MaxWidth(FLT_MAX)
|
||||
, Height(-1)
|
||||
, MinHeight(0)
|
||||
, MaxHeight(FLT_MAX)
|
||||
, ImageWidth(0)
|
||||
, ImageHeight(0)
|
||||
, FontSize(-1)
|
||||
, Angle(0)
|
||||
, Transparency(1)
|
||||
, Layer(0)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -35,266 +35,266 @@ ViewInfo::~ViewInfo()
|
||||
|
||||
float ViewInfo::GetXRelativeToOrigin() const
|
||||
{
|
||||
return X + XOffset - XOrigin*GetWidth();
|
||||
return X + XOffset - XOrigin*GetWidth();
|
||||
}
|
||||
|
||||
float ViewInfo::GetYRelativeToOrigin() const
|
||||
{
|
||||
return Y + YOffset - YOrigin*GetHeight();
|
||||
return Y + YOffset - YOrigin*GetHeight();
|
||||
}
|
||||
|
||||
float ViewInfo::GetHeight() const
|
||||
{
|
||||
float value = Height;
|
||||
float value = Height;
|
||||
|
||||
if(Height == -1 && Width == -1)
|
||||
{
|
||||
value = ImageHeight;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (Height == -1 && ImageWidth != 0)
|
||||
{
|
||||
value = ImageHeight * Width / ImageWidth;
|
||||
}
|
||||
if(Height == -1 && Width == -1)
|
||||
{
|
||||
value = ImageHeight;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (Height == -1 && ImageWidth != 0)
|
||||
{
|
||||
value = ImageHeight * Width / ImageWidth;
|
||||
}
|
||||
|
||||
if (value < MinHeight)
|
||||
{
|
||||
value = MinHeight;
|
||||
}
|
||||
else if (value > MaxHeight)
|
||||
{
|
||||
value = MaxHeight;
|
||||
}
|
||||
}
|
||||
if (value < MinHeight)
|
||||
{
|
||||
value = MinHeight;
|
||||
}
|
||||
else if (value > MaxHeight)
|
||||
{
|
||||
value = MaxHeight;
|
||||
}
|
||||
}
|
||||
|
||||
return value;
|
||||
return value;
|
||||
}
|
||||
|
||||
float ViewInfo::GetWidth() const
|
||||
{
|
||||
float value = Width;
|
||||
float value = Width;
|
||||
|
||||
if(Height == -1 && Width == -1)
|
||||
{
|
||||
value = ImageWidth;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (Width == -1 && ImageHeight != 0)
|
||||
{
|
||||
value = ImageWidth * Height / ImageHeight;
|
||||
}
|
||||
if (value < MinWidth)
|
||||
{
|
||||
value = MinWidth;
|
||||
}
|
||||
else if (value > MaxWidth)
|
||||
{
|
||||
value = MaxWidth;
|
||||
}
|
||||
}
|
||||
if(Height == -1 && Width == -1)
|
||||
{
|
||||
value = ImageWidth;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (Width == -1 && ImageHeight != 0)
|
||||
{
|
||||
value = ImageWidth * Height / ImageHeight;
|
||||
}
|
||||
if (value < MinWidth)
|
||||
{
|
||||
value = MinWidth;
|
||||
}
|
||||
else if (value > MaxWidth)
|
||||
{
|
||||
value = MaxWidth;
|
||||
}
|
||||
}
|
||||
|
||||
return value;
|
||||
return value;
|
||||
}
|
||||
|
||||
float ViewInfo::GetXOffset() const
|
||||
{
|
||||
return XOffset;
|
||||
return XOffset;
|
||||
}
|
||||
|
||||
|
||||
float ViewInfo::GetXOrigin() const
|
||||
{
|
||||
return XOrigin;
|
||||
return XOrigin;
|
||||
}
|
||||
|
||||
|
||||
float ViewInfo::GetYOffset() const
|
||||
{
|
||||
return YOffset;
|
||||
return YOffset;
|
||||
}
|
||||
|
||||
|
||||
float ViewInfo::GetYOrigin() const
|
||||
{
|
||||
return YOrigin;
|
||||
return YOrigin;
|
||||
}
|
||||
|
||||
float ViewInfo::GetAngle() const
|
||||
{
|
||||
return Angle;
|
||||
return Angle;
|
||||
}
|
||||
|
||||
void ViewInfo::SetAngle(float angle)
|
||||
{
|
||||
Angle = angle;
|
||||
Angle = angle;
|
||||
}
|
||||
|
||||
float ViewInfo::GetImageHeight() const
|
||||
{
|
||||
return ImageHeight;
|
||||
return ImageHeight;
|
||||
}
|
||||
|
||||
void ViewInfo::SetImageHeight(float imageheight)
|
||||
{
|
||||
ImageHeight = imageheight;
|
||||
ImageHeight = imageheight;
|
||||
}
|
||||
|
||||
float ViewInfo::GetImageWidth() const
|
||||
{
|
||||
return ImageWidth;
|
||||
return ImageWidth;
|
||||
}
|
||||
|
||||
void ViewInfo::SetImageWidth(float imagewidth)
|
||||
{
|
||||
ImageWidth = imagewidth;
|
||||
ImageWidth = imagewidth;
|
||||
}
|
||||
|
||||
unsigned int ViewInfo::GetLayer() const
|
||||
{
|
||||
return Layer;
|
||||
return Layer;
|
||||
}
|
||||
|
||||
void ViewInfo::SetLayer(unsigned int layer)
|
||||
{
|
||||
Layer = layer;
|
||||
Layer = layer;
|
||||
}
|
||||
|
||||
float ViewInfo::GetMaxHeight() const
|
||||
{
|
||||
return MaxHeight;
|
||||
return MaxHeight;
|
||||
}
|
||||
|
||||
void ViewInfo::SetMaxHeight(float maxheight)
|
||||
{
|
||||
MaxHeight = maxheight;
|
||||
MaxHeight = maxheight;
|
||||
}
|
||||
|
||||
float ViewInfo::GetMaxWidth() const
|
||||
{
|
||||
return MaxWidth;
|
||||
return MaxWidth;
|
||||
}
|
||||
|
||||
void ViewInfo::SetMaxWidth(float maxwidth)
|
||||
{
|
||||
MaxWidth = maxwidth;
|
||||
MaxWidth = maxwidth;
|
||||
}
|
||||
|
||||
float ViewInfo::GetMinHeight() const
|
||||
{
|
||||
return MinHeight;
|
||||
return MinHeight;
|
||||
}
|
||||
|
||||
void ViewInfo::SetMinHeight(float minheight)
|
||||
{
|
||||
MinHeight = minheight;
|
||||
MinHeight = minheight;
|
||||
}
|
||||
|
||||
float ViewInfo::GetMinWidth() const
|
||||
{
|
||||
return MinWidth;
|
||||
return MinWidth;
|
||||
}
|
||||
|
||||
void ViewInfo::SetMinWidth(float minwidth)
|
||||
{
|
||||
MinWidth = minwidth;
|
||||
MinWidth = minwidth;
|
||||
}
|
||||
|
||||
float ViewInfo::GetTransparency() const
|
||||
{
|
||||
return Transparency;
|
||||
return Transparency;
|
||||
}
|
||||
|
||||
void ViewInfo::SetTransparency(float transparency)
|
||||
{
|
||||
Transparency = transparency;
|
||||
Transparency = transparency;
|
||||
}
|
||||
|
||||
float ViewInfo::GetX() const
|
||||
{
|
||||
return X;
|
||||
return X;
|
||||
}
|
||||
|
||||
void ViewInfo::SetX(float x)
|
||||
{
|
||||
X = x;
|
||||
X = x;
|
||||
}
|
||||
|
||||
void ViewInfo::SetXOffset(float offset)
|
||||
{
|
||||
XOffset = offset;
|
||||
XOffset = offset;
|
||||
}
|
||||
|
||||
|
||||
void ViewInfo::SetXOrigin(float origin)
|
||||
{
|
||||
XOrigin = origin;
|
||||
XOrigin = origin;
|
||||
}
|
||||
|
||||
float ViewInfo::GetY() const
|
||||
{
|
||||
return Y;
|
||||
return Y;
|
||||
}
|
||||
|
||||
void ViewInfo::SetY(float y)
|
||||
{
|
||||
Y = y;
|
||||
Y = y;
|
||||
}
|
||||
|
||||
void ViewInfo::SetYOffset(float offset)
|
||||
{
|
||||
YOffset = offset;
|
||||
YOffset = offset;
|
||||
}
|
||||
|
||||
|
||||
void ViewInfo::SetYOrigin(float origin)
|
||||
{
|
||||
YOrigin = origin;
|
||||
YOrigin = origin;
|
||||
}
|
||||
|
||||
float ViewInfo::GetRawYOrigin()
|
||||
{
|
||||
return YOrigin;
|
||||
return YOrigin;
|
||||
}
|
||||
float ViewInfo::GetRawXOrigin()
|
||||
{
|
||||
return XOrigin;
|
||||
return XOrigin;
|
||||
}
|
||||
|
||||
float ViewInfo::GetRawWidth()
|
||||
{
|
||||
return Width;
|
||||
return Width;
|
||||
}
|
||||
|
||||
float ViewInfo::GetRawHeight()
|
||||
{
|
||||
return Height;
|
||||
return Height;
|
||||
}
|
||||
|
||||
void ViewInfo::SetHeight(float height)
|
||||
{
|
||||
Height = height;
|
||||
Height = height;
|
||||
}
|
||||
|
||||
void ViewInfo::SetWidth(float width)
|
||||
{
|
||||
Width = width;
|
||||
Width = width;
|
||||
}
|
||||
|
||||
float ViewInfo::GetFontSize() const
|
||||
{
|
||||
if(FontSize == -1)
|
||||
{
|
||||
return GetHeight();
|
||||
}
|
||||
else
|
||||
{
|
||||
return FontSize;
|
||||
}
|
||||
if(FontSize == -1)
|
||||
{
|
||||
return GetHeight();
|
||||
}
|
||||
else
|
||||
{
|
||||
return FontSize;
|
||||
}
|
||||
}
|
||||
|
||||
void ViewInfo::SetFontSize(float fontSize)
|
||||
{
|
||||
FontSize = fontSize;
|
||||
FontSize = fontSize;
|
||||
}
|
||||
|
||||
@@ -11,79 +11,79 @@ class ViewInfo
|
||||
{
|
||||
public:
|
||||
|
||||
ViewInfo();
|
||||
virtual ~ViewInfo();
|
||||
ViewInfo();
|
||||
virtual ~ViewInfo();
|
||||
|
||||
float GetXRelativeToOrigin() const;
|
||||
float GetYRelativeToOrigin() const;
|
||||
float GetXRelativeToOrigin() const;
|
||||
float GetYRelativeToOrigin() const;
|
||||
|
||||
float GetHeight() const;
|
||||
float GetWidth() const;
|
||||
float GetAngle() const;
|
||||
void SetAngle(float angle);
|
||||
float GetImageHeight() const;
|
||||
void SetImageHeight(float imageheight);
|
||||
float GetImageWidth() const;
|
||||
void SetImageWidth(float imagewidth);
|
||||
unsigned int GetLayer() const;
|
||||
void SetLayer(unsigned int layer);
|
||||
float GetMaxHeight() const;
|
||||
void SetMaxHeight(float maxheight);
|
||||
float GetMaxWidth() const;
|
||||
void SetMaxWidth(float maxwidth);
|
||||
float GetMinHeight() const;
|
||||
void SetMinHeight(float minheight);
|
||||
float GetMinWidth() const;
|
||||
void SetMinWidth(float minwidth);
|
||||
float GetTransparency() const;
|
||||
void SetTransparency(float transparency);
|
||||
float GetX() const;
|
||||
void SetX(float x);
|
||||
float GetXOffset() const;
|
||||
void SetXOffset(float offset);
|
||||
float GetXOrigin() const;
|
||||
void SetXOrigin(float origin);
|
||||
float GetY() const;
|
||||
void SetY(float y);
|
||||
float GetYOffset() const;
|
||||
void SetYOffset(float offset);
|
||||
float GetYOrigin() const;
|
||||
void SetYOrigin(float origin);
|
||||
float GetRawYOrigin();
|
||||
float GetRawXOrigin();
|
||||
float GetRawWidth();
|
||||
float GetRawHeight();
|
||||
float GetHeight() const;
|
||||
float GetWidth() const;
|
||||
float GetAngle() const;
|
||||
void SetAngle(float angle);
|
||||
float GetImageHeight() const;
|
||||
void SetImageHeight(float imageheight);
|
||||
float GetImageWidth() const;
|
||||
void SetImageWidth(float imagewidth);
|
||||
unsigned int GetLayer() const;
|
||||
void SetLayer(unsigned int layer);
|
||||
float GetMaxHeight() const;
|
||||
void SetMaxHeight(float maxheight);
|
||||
float GetMaxWidth() const;
|
||||
void SetMaxWidth(float maxwidth);
|
||||
float GetMinHeight() const;
|
||||
void SetMinHeight(float minheight);
|
||||
float GetMinWidth() const;
|
||||
void SetMinWidth(float minwidth);
|
||||
float GetTransparency() const;
|
||||
void SetTransparency(float transparency);
|
||||
float GetX() const;
|
||||
void SetX(float x);
|
||||
float GetXOffset() const;
|
||||
void SetXOffset(float offset);
|
||||
float GetXOrigin() const;
|
||||
void SetXOrigin(float origin);
|
||||
float GetY() const;
|
||||
void SetY(float y);
|
||||
float GetYOffset() const;
|
||||
void SetYOffset(float offset);
|
||||
float GetYOrigin() const;
|
||||
void SetYOrigin(float origin);
|
||||
float GetRawYOrigin();
|
||||
float GetRawXOrigin();
|
||||
float GetRawWidth();
|
||||
float GetRawHeight();
|
||||
|
||||
void SetHeight(float height);
|
||||
void SetWidth(float width);
|
||||
float GetFontSize() const;
|
||||
void SetFontSize(float fontSize);
|
||||
void SetHeight(float height);
|
||||
void SetWidth(float width);
|
||||
float GetFontSize() const;
|
||||
void SetFontSize(float fontSize);
|
||||
|
||||
static const int AlignCenter = -1;
|
||||
static const int AlignLeft = -2;
|
||||
static const int AlignTop = -3;
|
||||
static const int AlignRight = -4;
|
||||
static const int AlignBottom = -5;
|
||||
static const int AlignCenter = -1;
|
||||
static const int AlignLeft = -2;
|
||||
static const int AlignTop = -3;
|
||||
static const int AlignRight = -4;
|
||||
static const int AlignBottom = -5;
|
||||
|
||||
private:
|
||||
float X;
|
||||
float Y;
|
||||
float XOrigin;
|
||||
float YOrigin;
|
||||
float XOffset;
|
||||
float YOffset;
|
||||
float Width;
|
||||
float MinWidth;
|
||||
float MaxWidth;
|
||||
float Height;
|
||||
float MinHeight;
|
||||
float MaxHeight;
|
||||
float ImageWidth;
|
||||
float ImageHeight;
|
||||
float FontSize;
|
||||
float Angle;
|
||||
float Transparency;
|
||||
unsigned int Layer;
|
||||
float HorizontalScale;
|
||||
float VerticalScale;
|
||||
float X;
|
||||
float Y;
|
||||
float XOrigin;
|
||||
float YOrigin;
|
||||
float XOffset;
|
||||
float YOffset;
|
||||
float Width;
|
||||
float MinWidth;
|
||||
float MaxWidth;
|
||||
float Height;
|
||||
float MinHeight;
|
||||
float MaxHeight;
|
||||
float ImageWidth;
|
||||
float ImageHeight;
|
||||
float FontSize;
|
||||
float Angle;
|
||||
float Transparency;
|
||||
unsigned int Layer;
|
||||
float HorizontalScale;
|
||||
float VerticalScale;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user