void QButton::setGroup( QButtonGroup* g ) { #ifndef QT_NO_BUTTONGROUP ensureData(); d->group = g; #endif }
Any::Any(Type t, const std::string& name) : m_type(t), m_data(NULL) { alwaysAssertM(t == ARRAY || t == TABLE, "Can only create ARRAY or TABLE from Type enum."); ensureData(); if (name != "") { m_data->name = name; } }
Any::Any(const char* s) : m_type(STRING), m_data(NULL) { if (s == NULL) { m_type = NONE; } else { ensureData(); *(m_data->value.s) = s; } }
void QButton::setAccel(const QKeySequence& key) { if (d && d->a) d->a->clear(); if (key.isEmpty()) return; ensureData(); if (!d->a) { d->a = new QAccel(this, "buttonAccel"); connect(d->a, SIGNAL( activated(int) ), this, SLOT( animateClick() ) ); connect(d->a, SIGNAL( activatedAmbiguously(int) ), this, SLOT( setFocus() ) ); }
void InterpolatedVector::startPath(float time, float ease) { InterpolatedVectorData *data = ensureData(); if (data->path.getNumPathNodes()==0) return; data->pathTimer = 0; data->pathTime = time; data->followingPath = true; data->loopType = 0; data->pingPong = false; // get the right values to start off with updatePath(0); }
void QButton::setAccel( int key ) { #ifndef QT_NO_ACCEL if ( d && d->a ) d->a->clear(); if ( !key ) return; ensureData(); if ( !d->a ) d->a = new QAccel( this, "buttonAccel" ); d->a->connectItem( d->a->insertItem( key, 0 ), this, SLOT(animateClick()) ); #endif }
void InterpolatedVector::updatePath(float dt) { InterpolatedVectorData *data = ensureData(); if (data->pathTimer > data->pathTime) { Vector value = data->path.getPathNode(data->path.getNumPathNodes()-1)->value; this->x = value.x; this->y = value.y; this->z = value.z; if (data->loopType != 0) { if (data->loopType > 0) data->loopType -= 1; int oldLoopType = data->loopType; if (data->pingPong) { // flip path data->path.flip(); startPath(data->pathTime); data->loopType = oldLoopType; } else { startPath(data->pathTime); data->loopType = oldLoopType; } } else { stopPath(); } } else { data->pathTimer += dt * data->pathTimeMultiplier; float perc = data->pathTimer/data->pathTime; Vector value = data->path.getValue(perc); this->x = value.x; this->y = value.y; this->z = value.z; } }
float InterpolatedVector::interpolateTo(Vector vec, float timePeriod, int loopType, bool pingPong, bool ease, InterpolateToFlag flag) { if (timePeriod == 0) { this->x = vec.x; this->y = vec.y; this->z = vec.z; return 0; } InterpolatedVectorData *data = ensureData(); data->ease = ease; data->timePassed = 0; //data->fakeTimePassed = 0; if (timePeriod < 0) { timePeriod = -timePeriod; timePeriod = (vec-Vector(x,y,z)).getLength3D() / timePeriod; /* std::ostringstream os; os << "calced: " << timePeriod; debugLog(os.str()); */ } data->timePeriod = timePeriod; data->from = Vector (this->x, this->y, this->z); data->target = vec; data->loopType = loopType; data->pingPong = pingPong; data->interpolating = true; return data->timePeriod; }
void InterpolatedVector::resumePath() { InterpolatedVectorData *data = ensureData(); data->followingPath = true; }
void JSONArray::append( const QString& str) { ensureData(); data()->arr.append(JSONConstant(str)); }
void Any::deserialize(TextInput& ti, Token& token) { // Deallocate old data dropReference(); m_type = NONE; m_simpleValue.b = false; // Skip leading newlines while (token.type() == Token::NEWLINE) { token = ti.read(); } std::string comment; if (token.type() == Token::COMMENT) { deserializeComment(ti, token, comment); } if (token.type() == Token::END) { // There should never be a comment without an Any following it; even // if the file ends with some commented out stuff, // that should not happen after a comma, so we'd never read that // far in a proper file. throw ParseError(ti.filename(), token.line(), token.character(), "File ended without a properly formed Any"); } switch (token.type()) { case Token::STRING: m_type = STRING; ensureData(); *(m_data->value.s) = token.string(); m_data->source.set(ti, token); break; case Token::NUMBER: m_type = NUMBER; m_simpleValue.n = token.number(); ensureData(); m_data->source.set(ti, token); break; case Token::BOOLEAN: m_type = BOOLEAN; m_simpleValue.b = token.boolean(); ensureData(); m_data->source.set(ti, token); break; case Token::SYMBOL: // Named Array, Named Table, Array, Table, or NONE if (toUpper(token.string()) == "NONE") { // Nothing left to do; we initialized to NONE originally ensureData(); m_data->source.set(ti, token); } else { // Array or Table // Parse the name // s must have at least one element or this would not have // been parsed as a symbol std::string name; deserializeName(ti, token, name); if (token.type() != Token::SYMBOL) { throw ParseError(ti.filename(), token.line(), token.character(), "Malformed Any TABLE or ARRAY; must start with [, (, or {"); } if (isOpen(token.string()[0])) { // Array or table deserializeBody(ti, token); } else { throw ParseError(ti.filename(), token.line(), token.character(), "Malformed Any TABLE or ARRAY; must start with [, (, or {"); } if (!name.empty()) { ensureData(); m_data->name = name; } } // if NONE break; default: throw ParseError(ti.filename(), token.line(), token.character(), "Unexpected token"); } // switch if (!comment.empty()) { ensureData(); m_data->comment = comment; } if (m_type != ARRAY && m_type != TABLE) { // Array and table already consumed their last token token = ti.read(); } }
void Any::deserializeBody(TextInput& ti, Token& token) { char closeSymbol = '}'; m_type = TABLE; const char c = token.string()[0]; if (c != '{') { m_type = ARRAY; // Chose the appropriate close symbol closeSymbol = (c == '(') ? ')' : ']'; } // Allocate the underlying data structure ensureData(); m_data->source.set(ti, token); // Consume the open token token = ti.read(); while (!((token.type() == Token::SYMBOL) && (token.string()[0] == closeSymbol))) { // Read any leading comment. This must be done here (and not in the recursive deserialize // call) in case the body contains only a comment. std::string comment; deserializeComment(ti, token, comment); if ((token.type() == Token::SYMBOL) && (token.string()[0] == closeSymbol)) { // We're done; this catches the case where the array is empty break; } // Pointer the value being read Any a; std::string key; if (m_type == TABLE) { // Read the key if (token.type() != Token::SYMBOL && token.type() != Token::STRING) { throw ParseError(ti.filename(), token.line(), token.character(), "Expected a name"); } key = token.string(); // Consume everything up to the = sign token = ti.readSignificant(); if ((token.type() != Token::SYMBOL) || (token.string() != "=")) { throw ParseError(ti.filename(), token.line(), token.character(), "Expected ="); } else { // Consume (don't consume comments--we want the value pointed to by a to get those). token = ti.read(); } } a.deserialize(ti, token); if (!comment.empty()) { // Prepend the comment we read earlier a.ensureData(); a.m_data->comment = trimWhitespace(comment + "\n" + a.m_data->comment); } if (m_type == TABLE) { set(key, a); } else { append(a); } // Read until the comma or close paren, discarding trailing comments and newlines readUntilCommaOrClose(ti, token); // Consume the comma if (isSeparator(token.string()[0])) { token = ti.read(); } } // Consume the close paren (to match other deserialize methods) token = ti.read(); }
void Any::setComment(const std::string& c) { beforeRead(); ensureData(); m_data->comment = c; }
void JSONArray::append( bool b) { ensureData(); data()->arr.append(JSONConstant(b)); }
void JSONArray::append( const JSONAbstractObject& obj) { ensureData(); data()->arr.append(obj); }
void JSONArray::append( const char* str) { ensureData(); data()->arr.append(JSONConstant(QString(str))); }
QTimer *QButton::timer() { ensureData(); return &d->timer; }
void JSONArray::append( int i) { ensureData(); data()->arr.append(JSONConstant(i)); }
JSONArray::JSONArray(bool create_empty) : JSONAbstractObject() { if ( create_empty ) ensureData(); }
float InterpolatedVector::getPercentDone() { InterpolatedVectorData *data = ensureData(); return data->timePassed/data->timePeriod; }
void Any::setName(const std::string& n) { beforeRead(); ensureData(); m_data->name = n; }
void InterpolatedVector::doInterpolate(float dt) { InterpolatedVectorData *data = ensureData(); //errorLog ("gothere"); /* // old method if (data->ease) { float diff = data->timePassed / data->timePeriod; if (diff > 0.5f) diff = 1.0f - diff; diff /= 0.5f; diff *= 2; //diff += 0.5f; data->fakeTimePassed += dt*diff; } */ data->timePassed += dt; if (data->timePassed >= data->timePeriod) { this->x = data->target.x; this->y = data->target.y; this->z = data->target.z; data->interpolating = false; if (data->loopType != 0) { if (data->loopType > 0) data->loopType -= 1; if (data->pingPong) { interpolateTo (data->from, data->timePeriod, data->loopType, data->pingPong, data->ease, IS_LOOPING); } else { this->x = data->from.x; this->y = data->from.y; this->z = data->from.z; interpolateTo (data->target, data->timePeriod, data->loopType, data->pingPong, data->ease, IS_LOOPING); } } } else { Vector v; /* // old method if (data->ease) { v = lerp(data->from, data->target, (data->timePassed / data->timePeriod), data->ease); //v = (data->target - data->from) * //v = (data->target - data->from) * (data->fakeTimePassed / data->timePeriod); } else { float perc = data->timePassed / data->timePeriod; v = (data->target - data->from) * perc; } v += data->from; */ v = lerp(data->from, data->target, (data->timePassed / data->timePeriod), data->ease ? LERP_EASE : LERP_LINEAR); this->x = v.x; this->y = v.y; this->z = v.z; //*updatee += data->from; } }
void JSONArray::append( double d) { ensureData(); data()->arr.append(JSONConstant(d)); }