You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
tdetoys/ktux/spritemisc.cpp

70 lines
1.0 KiB

//-----------------------------------------------------------------------------
//
// spritemisc
//
// Copyright (c) Martin R. Jones 1999
//
#include <kapplication.h>
#include "spritemisc.h"
TQSize SpriteRange::mFieldSize;
SpriteRange::SpriteRange(const TQString &str)
{
set(str);
}
int SpriteRange::random() const
{
int val = mMin;
if (mMax != mMin)
{
val = (KApplication::random()%(mMax-mMin)) + mMin;
}
return val;
}
void SpriteRange::set(const TQString &str)
{
int r = str.find("..");
if (r > 0)
{
mMin = parse(str.left(r));
mMax = parse(str.mid(r+2, 10));
}
else
{
mMin = mMax = parse(str);
}
}
void SpriteRange::setFieldSize(const TQSize &size)
{
mFieldSize = size;
}
int SpriteRange::parse(const TQString &str)
{
int val = 0;
if (str == "WIDTH")
{
val = mFieldSize.width();
}
else if (str == "HEIGHT")
{
val = mFieldSize.height();
}
else
{
val = str.toInt();
}
return val;
}