// ---------------------------------------------------------------------------- // void ScenePixelAnimator::genMovingDots( PixelEngine& engine ) { ColorFader fader( true ); const size_t num_pixels = engine.getNumPixels(); for ( size_t color_index=0; color_index < m_colors.size(); color_index++ ) { fader.setCurrent( m_colors[color_index] ); fader.start( 0, num_pixels / m_increment, ( m_color_fade ) ? m_colors[( color_index + 1 ) % m_colors.size()] : fader.rgbwa() ); size_t target_pixel = 0; for ( unsigned gen=0; gen < m_generations*num_pixels / m_increment; gen++ ) { size_t target_range = target_pixel+m_num_pixels-1; for ( size_t pixel=0; pixel < num_pixels; pixel++ ) { bool fill = (pixel >= target_pixel && pixel <= target_range) || (target_range >= num_pixels && pixel <= (target_range%num_pixels)); // XXXX if fading and wrap, need to use next color engine.addPixel( pixel, fill ? fader.rgbwa() : m_empty_color ); } fader.tick(); target_pixel = (target_pixel+m_increment) % num_pixels; } } }
void GenericFader_Test::writeLoop() { UniverseArray ua(512); GenericFader fader(m_doc); FadeChannel fc; fc.setFixture(0); fc.setChannel(5); fc.setStart(0); fc.setTarget(250); fc.setFadeTime(1000); fader.add(fc); QCOMPARE(ua.preGMValues()[15], (char) 0); int expected = 0; for (int i = MasterTimer::tick(); i <= 1000; i += MasterTimer::tick()) { ua.zeroIntensityChannels(); fader.write(&ua); int actual = uchar(ua.preGMValues()[15]); expected += 5; QCOMPARE(actual, expected); } }
Snake::Snake(const sf::Vector2f& position, Game* game, unsigned initialSize) : Entity(position, game, EntityType::Snake) , position_(position) , game_(game) , direction_(Direction::Up) , canShoot_(true) , life_(100) , score_(0) , FireRate(sf::seconds(0.25f)) , TakeDamageDelay(sf::seconds(0.4f)) { // The initial size should never be zero. assert(initialSize != 0); for (unsigned i = 0; i < initialSize; ++i) { nodes_.push_back(SnakeNode({ position.x, position.y + SnakeNode::Size * i }, (i == 0 ? true : false))); } srand(time(NULL)); particleSystem_.setTexture(game_->getTextureHolder().getTexture("particle")); thor::ColorGradient gradient; gradient[0.f] = sf::Color::Green; gradient[0.5f] = sf::Color::Red; gradient[1.f] = sf::Color::Black; thor::ColorAnimation colorizer(gradient); thor::FadeAnimation fader(0.1f, 0.1f); particleSystem_.addAffector(thor::AnimationAffector(colorizer)); particleSystem_.addAffector(thor::AnimationAffector(fader)); }
Cursor::Cursor() { mSystem = new thor::ParticleSystem(TextureManager::get().getTexture("assets/gfx/particle.png")); mEmitter.setEmissionRate(16.0f); mEmitter.setParticleLifetime( thor::Distributions::uniform(sf::seconds(4), sf::seconds(4)) ); mEmitter.setParticleRotation( thor::Distributions::uniform(0.f, 360.f) ); mEmitter.setParticleScale(sf::Vector2f(0.3,0.3)); mEmitter.setParticleVelocity(sf::Vector2f(0, 1000.0f)); mEmitter.setParticleScale(sf::Vector2f(4.f,4.f)); mSystem->addEmitter(thor::refEmitter(mEmitter)); thor::ColorGradient gradient; gradient[0.0f] = sf::Color::Magenta; gradient[0.1f] = sf::Color::Red; gradient[0.2f] = sf::Color::Blue; gradient[0.3f] = sf::Color::Cyan; gradient[0.4f] = sf::Color::Green; gradient[0.5f] = sf::Color::Red; gradient[0.6f] = sf::Color::Magenta; gradient[0.7f] = sf::Color::Cyan; gradient[0.8f] = sf::Color::Red; gradient[0.9f] = sf::Color::Blue; gradient[1.0f] = sf::Color::Red; thor::ColorAnimation colorizer(gradient); thor::FadeAnimation fader(0.15f, 0.15f); mSystem->addAffector( thor::AnimationAffector(colorizer) ); mSystem->addAffector( thor::AnimationAffector(fader) ); }
void GenericFader_Test::addRemove() { GenericFader fader(m_doc); FadeChannel fc; fc.setFixture(0); fc.setChannel(0); FadeChannel wrong; fc.setFixture(0); QCOMPARE(fader.m_channels.count(), 0); QVERIFY(fader.m_channels.contains(fc) == false); fader.add(fc); QVERIFY(fader.m_channels.contains(fc) == true); QCOMPARE(fader.m_channels.count(), 1); fader.remove(wrong); QVERIFY(fader.m_channels.contains(fc) == true); QCOMPARE(fader.m_channels.count(), 1); fader.remove(fc); QVERIFY(fader.m_channels.contains(fc) == false); QCOMPARE(fader.m_channels.count(), 0); fc.setChannel(0); fader.add(fc); QVERIFY(fader.m_channels.contains(fc) == true); fc.setChannel(1); fader.add(fc); QVERIFY(fader.m_channels.contains(fc) == true); fc.setChannel(2); fader.add(fc); QVERIFY(fader.m_channels.contains(fc) == true); QCOMPARE(fader.m_channels.count(), 3); fader.removeAll(); QCOMPARE(fader.m_channels.count(), 0); fc.setFixture(0); fc.setChannel(0); fc.setTarget(127); fader.add(fc); QCOMPARE(fader.m_channels.size(), 1); QCOMPARE(fader.m_channels[fc].target(), uchar(127)); fc.setTarget(63); fader.add(fc); QCOMPARE(fader.m_channels.size(), 1); QCOMPARE(fader.m_channels[fc].target(), uchar(63)); fc.setCurrent(63); fader.add(fc); QCOMPARE(fader.m_channels.size(), 1); QCOMPARE(fader.m_channels[fc].target(), uchar(63)); }
static PyObject* cAction_crossfade(PyObject* self, PyObject* args) { PyObject *objInSound1, *objInSound2; char* s_mode = NULL; // Hacky - the percentage through the crossfade that we're processing. // Allows for incremental processing of the same crossfade in chunks. long total = -1; long offset = 0; if (!PyArg_ParseTuple(args, "OO|sll", &objInSound1, &objInSound2, &s_mode, &total, &offset)) return NULL; PyArrayObject *inSound1 = get_pyarray(objInSound1); if (inSound1 == NULL) return NULL; PyArrayObject *inSound2 = get_pyarray(objInSound2); if (inSound2 == NULL) { Py_XDECREF(inSound1); return NULL; } float* inSamples1 = (float *)inSound1->data; float* inSamples2 = (float *)inSound2->data; uint numInSamples = inSound1->dimensions[0]; uint numInChannels = inSound1->dimensions[1]; npy_intp dims[DIMENSIONS]; dims[0] = numInSamples; dims[1] = numInChannels; if ( total < 0 ) { total = numInSamples; } // Allocate interlaced memory for output sound object PyArrayObject* outSound = (PyArrayObject *)PyArray_SimpleNew(DIMENSIONS, dims, NPY_FLOAT); // Get the actual array float* outSamples = (float *)outSound->data; // Figure out which crossfade to use. float (*fader)(float, float, long, long) = strcmp(s_mode, "linear") == 0 ? linear : equal_power; for (uint i = 0; i < numInChannels; i++) { for (uint j = 0; j < numInSamples; j++) { uint index = i + j*numInChannels; outSamples[index] = fader(inSamples1[index], inSamples2[index], (j + offset > total ? total : j + offset), total); } } Py_DECREF(inSound1); Py_DECREF(inSound2); return PyArray_Return(outSound); }
void MasterTimer::timerTickFader(UniverseArray* universes) { m_functionListMutex.lock(); m_dmxSourceListMutex.lock(); fader()->write(universes); m_dmxSourceListMutex.unlock(); m_functionListMutex.unlock(); }
double dsp(int tn) { double tx0 = tn / 44100.0; double amp = 0.0; double pi2 = 2.0 * acos(-1.0); int tones = 1 + ((int) tx0) / 16; for (int i = 0; i < tones; i++) { double tx = tx0 - 16.0 * i; double freq = ascender(tx); double ax = fader(tx); amp += 1.8 * ax * sin(pi2 * (0.1 * i + 20.0 * freq * tx)); } if (amp > 1.0) amp = 1.0; if (amp < -1.0) amp = -1.0; return amp; }
void GenericFader_Test::writeZeroFade() { UniverseArray ua(512); GenericFader fader(m_doc); FadeChannel fc; fc.setFixture(0); fc.setChannel(5); fc.setStart(0); fc.setTarget(255); fc.setFadeTime(0); fader.add(fc); QCOMPARE(ua.preGMValues()[15], (char) 0); fader.write(&ua); QCOMPARE(ua.preGMValues()[15], (char) 255); }
static PyObject* cAction_crossfade(PyObject* self, PyObject* args) { PyObject *objInSound1, *objInSound2; char* s_mode = NULL; if (!PyArg_ParseTuple(args, "OO|s", &objInSound1, &objInSound2, &s_mode)) return NULL; PyArrayObject *inSound1 = get_pyarray(objInSound1); if (inSound1 == NULL) return NULL; PyArrayObject *inSound2 = get_pyarray(objInSound2); if (inSound2 == NULL) { Py_XDECREF(inSound1); return NULL; } float* inSamples1 = (float *)inSound1->data; float* inSamples2 = (float *)inSound2->data; uint numInSamples = inSound1->dimensions[0]; uint numInChannels = inSound1->dimensions[1]; npy_intp dims[DIMENSIONS]; dims[0] = numInSamples; dims[1] = numInChannels; // Allocate interlaced memory for output sound object PyArrayObject* outSound = (PyArrayObject *)PyArray_SimpleNew(DIMENSIONS, dims, NPY_FLOAT); // Get the actual array float* outSamples = (float *)outSound->data; // Figure out which crossfade to use. float (*fader)(float, float, long, long) = strcmp(s_mode, "linear") == 0 ? linear : equal_power; for (uint i = 0; i < numInChannels; i++) { for (uint j = 0; j < numInSamples; j++) { uint index = i + j*numInChannels; outSamples[index] = fader(inSamples1[index], inSamples2[index], j, numInSamples); } } return PyArray_Return(outSound); }
void MasterTimer::fadeAndStopAll(int timeout) { if (timeout == 0) return; Doc* doc = qobject_cast<Doc*> (parent()); Q_ASSERT(doc != NULL); QList<FadeChannel> fcList; QList<Universe *> universes = doc->inputOutputMap()->claimUniverses(); for (int i = 0; i < universes.count(); i++) { QHashIterator <int,uchar> it(universes[i]->intensityChannels()); while (it.hasNext() == true) { it.next(); Fixture* fxi = doc->fixture(doc->fixtureForAddress(it.key())); if (fxi != NULL) { uint ch = it.key() - fxi->universeAddress(); if (fxi->channelCanFade(ch)) { FadeChannel fc(doc, fxi->id(), ch); fc.setStart(it.value()); fc.setTarget(0); fc.setFadeTime(timeout); fcList.append(fc); } } } } doc->inputOutputMap()->releaseUniverses(); // Stop all functions first stopAllFunctions(); // Instruct mastertimer to do a fade out of all // the intensity channels that can fade QMutexLocker faderLocker(&m_faderMutex); foreach(FadeChannel fade, fcList) fader()->add(fade); }
void YSE::SOUND::implementationObject::toChannels() { #pragma warning ( disable : 4258 ) for (UInt x = 0; x < buffer->size(); x++) { // calculate spread value for multichannel sounds Flt spreadAdjust = 0; if (buffer->size() > 1) spreadAdjust = (((2 * Pi / buffer->size()) * x) + (Pi / buffer->size()) - Pi) * spread; // initial panning for (UInt i = 0; i < parent->outConf.size(); i++) { parent->outConf[i].initPan = (1 + cos(parent->outConf[i].angle - (angle + spreadAdjust))) * 0.5f; parent->outConf[i].effective = 0; // effective speakers for (UInt j = 0; j < parent->outConf.size(); j++) { parent->outConf[i].effective += (1 + cos(parent->outConf[i].angle - parent->outConf[j].angle) * 0.5f); } // initial gain parent->outConf[i].initGain = parent->outConf[i].initPan / parent->outConf[i].effective; } // emitted power Flt power = 0; for (UInt i = 0; i < parent->outConf.size(); i++) { power += pow(parent->outConf[i].initGain, 2); } // calculated power Flt dist = distance - size; if (dist < 0) dist = 0; Flt correctPower = 1 / pow(dist, (2 * INTERNAL::Settings().rolloffScale)); if (correctPower > 1) correctPower = 1; // final gain assignment for (UInt j = 0; j < parent->out.size(); ++j) { parent->outConf[j].ratio = pow(parent->outConf[j].initGain, 2) / power; channelBuffer = (*buffer)[x]; parent->outConf[j].finalGain = sqrt(correctPower * parent->outConf[j].ratio); // add volume control now if (occlusionActive) parent->outConf[j].finalGain *= 1 - occlusion_dsp; dspFunc_calculateGain(j, x); channelBuffer *= fader(); parent->out[j] += channelBuffer; } } }
void GenericFader_Test::adjustIntensity() { UniverseArray ua(512); GenericFader fader(m_doc); FadeChannel fc; // HTP channel fc.setFixture(0); fc.setChannel(5); fc.setStart(0); fc.setTarget(250); fc.setFadeTime(1000); fader.add(fc); // LTP channel fc.setChannel(0); fader.add(fc); qreal intensity = 0.5; fader.adjustIntensity(intensity); QCOMPARE(fader.intensity(), intensity); int expected = 0; for (int i = MasterTimer::tick(); i <= 1000; i += MasterTimer::tick()) { ua.zeroIntensityChannels(); fader.write(&ua); expected += 5; // GenericFader should apply intensity only to HTP channels int actual = uchar(ua.preGMValues()[15]); int expectedWithIntensity = floor((qreal(expected) * intensity) + 0.5); QVERIFY(actual == expectedWithIntensity); // No intensity adjustment on LTP channels actual = uchar(ua.preGMValues()[10]); QVERIFY(actual == expected); } }
fullcircle::Sequence::Ptr mk_perlin_noise() { std::cout << "Generating Perlin noise demo sequence." << std::endl; fullcircle::ColorScheme::Ptr smash(new fullcircle::ColorSchemeSmash()); fullcircle::Sequence::Ptr seq(new fullcircle::Sequence(25,8,8)); fullcircle::FrameFader::Ptr fader(new fullcircle::FrameFader(5,25)); fullcircle::PerlinNoise::Ptr noize(new fullcircle::PerlinNoise( 3, // octaves .42, // freq 2.4, // amplitude 42 // seed )); for( uint32_t frameID = 0; frameID < 100; ++frameID) { fullcircle::Frame::Ptr frame(new fullcircle::Frame(8,8)); frame->fill_whole(smash->get_background()); for( uint16_t x = 0; x < 8; ++x) { for( uint16_t y = 0; y < 8; ++y) { float n=noize->get_3d(x/8.0f, y/8.0f, frameID/10.0f); // determine color if (0<=n && n<0.3) { frame->set_pixel(x,y,smash->get_primary()); } else if (0.3<=n && n<0.7) { frame->set_pixel(x,y,smash->get_secondary()); } else if (0.7<=n && n<=1.0) { frame->set_pixel(x,y,smash->get_background()); } else { std::cout << "Error: Unknown noise value: " << n << std::endl; } } } if (seq->size() == 0) seq->add_frame(frame); else seq = (*seq) << fader->fade(seq->get_last_frame(), frame); } return seq; }
void MasterTimer::stopAllFunctions() { m_stopAllFunctions = true; /* Wait until all functions have been stopped */ while (runningFunctions() > 0) { #ifdef WIN32 Sleep(10); #else usleep(10000); #endif } /* Remove all generic fader's channels */ m_functionListMutex.lock(); m_dmxSourceListMutex.lock(); fader()->removeAll(); m_dmxSourceListMutex.unlock(); m_functionListMutex.unlock(); m_stopAllFunctions = false; }
void MasterTimer::stopAllFunctions() { m_stopAllFunctions = true; /* Wait until all functions have been stopped */ while (runningFunctions() > 0) { #if defined(WIN32) || defined(Q_OS_WIN) Sleep(10); #else usleep(10000); #endif } // WARNING: the following brackets are fundamental for // the scope of this piece of code !! { /* Remove all generic fader's channels */ QMutexLocker faderLocker(&m_faderMutex); fader()->removeAll(); } m_stopAllFunctions = false; }
// ---------------------------------------------------------------------------- // void ScenePixelAnimator::genBeam( PixelEngine& engine ) { ColorFader fader( true ); const size_t num_pixels = engine.getNumPixels(); for ( size_t color_index=0; color_index < m_colors.size(); color_index++ ) { fader.setCurrent( m_colors[color_index] ); fader.start( 0, (num_pixels * 2 - 3), // # of ticks to get to next color (-3 = start, turn-around, end colors) ( m_color_fade ) ? m_colors[(color_index+1) % m_colors.size()] : fader.rgbwa() ); for ( size_t mover=0; mover < num_pixels; mover++ ) { for ( unsigned pixel=0; pixel < num_pixels; pixel++ ) engine.addPixel( pixel, mover == pixel ? fader.rgbwa() : m_empty_color ); fader.tick(); } for ( size_t mover=num_pixels-2; mover > 0; mover-- ) { for ( unsigned pixel=0; pixel < num_pixels; pixel++ ) engine.addPixel( pixel, mover == pixel ? fader.rgbwa() : m_empty_color ); fader.tick(); } } }
void OnMouseUp(thor::ActionContext<std::string> context) { emitter.setParticlePosition(window.mapPixelToCoords(sf::Mouse::getPosition(window))); if (selected_rune == 1) { // Build color gradient thor::ColorGradient gradient; gradient[0.f] = sf::Color::Yellow; gradient[0.5f] = sf::Color::Red; gradient[1.f] = sf::Color::Black; // Create color and fade in/out animations thor::ColorAnimation colorizer(gradient); thor::FadeAnimation fader(0.1f, 0.1f); particle_system.clearAffectors(); // Add particle affectors particle_system.addAffector(thor::AnimationAffector(colorizer)); particle_system.addAffector(thor::AnimationAffector(fader)); particle_system.addAffector(thor::TorqueAffector(100.f)); emitter.setParticlePosition(window.mapPixelToCoords(sf::Mouse::getPosition(window))); emitter.setParticleVelocity(thor::Distributions::circle(sf::Vector2f(0.0f, 0.0f), 100.f)); emitter.setEmissionRate(50.0f); particle_system.addEmitter(thor::refEmitter(emitter), sf::seconds(0.35f)); } else if (selected_rune == 2) { // Build color gradient thor::ColorGradient gradient; gradient[0.f] = sf::Color::Blue; gradient[0.5f] = sf::Color::Black; gradient[1.f] = sf::Color::Black; // Create color and fade in/out animations thor::ColorAnimation colorizer(gradient); thor::FadeAnimation fader(0.1f, 0.1f); particle_system.clearAffectors(); // Add particle affectors particle_system.addAffector(thor::AnimationAffector(colorizer)); particle_system.addAffector(thor::AnimationAffector(fader)); particle_system.addAffector(thor::TorqueAffector(100.f)); emitter.setParticlePosition(window.mapPixelToCoords(sf::Mouse::getPosition(window))); emitter.setParticleVelocity(thor::Distributions::deflect(sf::Vector2f(0.0f, -100.0f), 90.0f)); emitter.setEmissionRate(100.0f); particle_system.addEmitter(thor::refEmitter(emitter), sf::seconds(0.35f)); } else if (selected_rune == 3) { // Build color gradient thor::ColorGradient gradient; gradient[0.f] = sf::Color::Green; gradient[0.5f] = sf::Color::Cyan; gradient[1.f] = sf::Color::Black; // Create color and fade in/out animations thor::ColorAnimation colorizer(gradient); thor::FadeAnimation fader(0.1f, 0.1f); particle_system.clearAffectors(); // Add particle affectors particle_system.addAffector(thor::AnimationAffector(colorizer)); particle_system.addAffector(thor::AnimationAffector(fader)); particle_system.addAffector(thor::TorqueAffector(100.f)); emitter.setParticlePosition(window.mapPixelToCoords(sf::Mouse::getPosition(window))); emitter.setParticleVelocity(thor::Distributions::rect(sf::Vector2f(0.0f, 0.0f), sf::Vector2f(100.0f, 100.0f))); emitter.setEmissionRate(150.0f); particle_system.addEmitter(thor::refEmitter(emitter), sf::seconds(2.0f)); } else if (selected_rune == 4) { // Build color gradient thor::ColorGradient gradient; gradient[0.f] = sf::Color::Magenta; gradient[0.5f] = sf::Color::Green; gradient[1.f] = sf::Color::Black; // Create color and fade in/out animations thor::ColorAnimation colorizer(gradient); thor::FadeAnimation fader(0.1f, 0.1f); particle_system.clearAffectors(); // Add particle affectors particle_system.addAffector(thor::AnimationAffector(colorizer)); particle_system.addAffector(thor::AnimationAffector(fader)); particle_system.addAffector(thor::TorqueAffector(100.f)); emitter.setParticleVelocity(thor::Distributions::circle(sf::Vector2f(0.0f, 0.0f), 250.0f)); emitter.setEmissionRate(500.0f); particle_system.addEmitter(thor::refEmitter(emitter), sf::seconds(1.0f)); } }
/* bShowChannelList default to true, returns new bouquet or -1/-2 */ int CBouquetList::show(bool bShowChannelList) { neutrino_msg_t msg; neutrino_msg_data_t data; int res = CHANLIST_CANCEL; int icol_w, icol_h; int w_max_text = 0; int w_max_icon = 0; int h_max_icon = 0; favonly = !bShowChannelList; for(unsigned int count = 0; count < sizeof(CBouquetListButtons)/sizeof(CBouquetListButtons[0]);count++){ int w_text = g_Font[SNeutrinoSettings::FONT_TYPE_INFOBAR_SMALL]->getRenderWidth(g_Locale->getText(CBouquetListButtons[count].locale)); w_max_text = std::max(w_max_text, w_text); frameBuffer->getIconSize(CBouquetListButtons[count].button, &icol_w, &icol_h); w_max_icon = std::max(w_max_icon, icol_w); h_max_icon = std::max(h_max_icon, icol_h); } int need_width = sizeof(CBouquetListButtons)/sizeof(CBouquetListButtons[0])*(w_max_icon + w_max_text + 20); CVFD::getInstance()->setMode(CVFD::MODE_MENU_UTF8, ""); fheight = g_Font[SNeutrinoSettings::FONT_TYPE_CHANNELLIST]->getHeight(); width = w_max (need_width, 20); height = h_max (16 * fheight, 40); footerHeight = std::max(h_max_icon+8, g_Font[SNeutrinoSettings::FONT_TYPE_INFOBAR_SMALL]->getHeight()+8); theight = g_Font[SNeutrinoSettings::FONT_TYPE_MENU_TITLE]->getHeight(); listmaxshow = (height - theight - footerHeight)/fheight; height = theight + footerHeight + listmaxshow * fheight; // recalc height x = frameBuffer->getScreenX() + (frameBuffer->getScreenWidth() - width) / 2; y = frameBuffer->getScreenY() + (frameBuffer->getScreenHeight() - height) / 2; int lmaxpos= 1; int i= Bouquets.size(); while ((i= i/10)!=0) lmaxpos++; COSDFader fader(g_settings.theme.menu_Content_alpha); fader.StartFadeIn(); paintHead(); paint(); frameBuffer->blit(); int oldselected = selected; int firstselected = selected+ 1; int zapOnExit = false; unsigned int chn= 0; int pos= lmaxpos; uint64_t timeoutEnd = CRCInput::calcTimeoutEnd(g_settings.timing[SNeutrinoSettings::TIMING_CHANLIST]); bool loop=true; while (loop) { g_RCInput->getMsgAbsoluteTimeout( &msg, &data, &timeoutEnd ); if ( msg <= CRCInput::RC_MaxRC ) timeoutEnd = CRCInput::calcTimeoutEnd(g_settings.timing[SNeutrinoSettings::TIMING_CHANLIST]); if((msg == NeutrinoMessages::EVT_TIMER) && (data == fader.GetFadeTimer())) { if(fader.FadeDone()) loop = false; } else if ((msg == CRCInput::RC_timeout ) || (msg == (neutrino_msg_t)g_settings.key_channelList_cancel) || ((msg == CRCInput::RC_favorites) && (CNeutrinoApp::getInstance()->GetChannelMode() == LIST_MODE_FAV))) { selected = oldselected; if(fader.StartFadeOut()) { timeoutEnd = CRCInput::calcTimeoutEnd( 1 ); msg = 0; } else loop=false; } else if(msg == CRCInput::RC_red || msg == CRCInput::RC_favorites) { if (!favonly && CNeutrinoApp::getInstance()->GetChannelMode() != LIST_MODE_FAV) { CNeutrinoApp::getInstance()->SetChannelMode(LIST_MODE_FAV); hide(); return CHANLIST_CHANGE_MODE; } } else if(msg == CRCInput::RC_green) { if (!favonly && CNeutrinoApp::getInstance()->GetChannelMode() != LIST_MODE_PROV) { CNeutrinoApp::getInstance()->SetChannelMode(LIST_MODE_PROV); hide(); return CHANLIST_CHANGE_MODE; } } else if(msg == CRCInput::RC_yellow || msg == CRCInput::RC_sat) { if(!favonly && bShowChannelList && CNeutrinoApp::getInstance()->GetChannelMode() != LIST_MODE_SAT) { CNeutrinoApp::getInstance()->SetChannelMode(LIST_MODE_SAT); hide(); return CHANLIST_CHANGE_MODE; } } else if(msg == CRCInput::RC_blue) { if(!favonly && bShowChannelList && CNeutrinoApp::getInstance()->GetChannelMode() != LIST_MODE_ALL) { CNeutrinoApp::getInstance()->SetChannelMode(LIST_MODE_ALL); hide(); return CHANLIST_CHANGE_MODE; } } else if ( msg == CRCInput::RC_setup) { if (!favonly && !Bouquets.empty()) { int ret = doMenu(); if(ret > 0) { res = CHANLIST_NO_RESTORE; loop = false; } else if(ret < 0) { paintHead(); paint(); } } } else if ( msg == (neutrino_msg_t) g_settings.key_list_start ) { if (!Bouquets.empty()) updateSelection(0); } else if ( msg == (neutrino_msg_t) g_settings.key_list_end ) { if (!Bouquets.empty()) updateSelection(Bouquets.size()-1); } else if (msg == CRCInput::RC_up || (int) msg == g_settings.key_pageup || msg == CRCInput::RC_down || (int) msg == g_settings.key_pagedown) { int new_selected = UpDownKey(Bouquets, msg, listmaxshow, selected); updateSelection(new_selected); } else if(msg == (neutrino_msg_t)g_settings.key_bouquet_up || msg == (neutrino_msg_t)g_settings.key_bouquet_down) { if(bShowChannelList) { int mode = CNeutrinoApp::getInstance()->GetChannelMode(); mode += (msg == (neutrino_msg_t)g_settings.key_bouquet_down) ? -1 : 1; if(mode < 0) mode = LIST_MODE_LAST - 1; else if(mode >= LIST_MODE_LAST) mode = 0; CNeutrinoApp::getInstance()->SetChannelMode(mode); hide(); return CHANLIST_CHANGE_MODE; } } else if ( msg == CRCInput::RC_ok ) { if(!Bouquets.empty() /* && (!bShowChannelList || !Bouquets[selected]->channelList->isEmpty())*/) { zapOnExit = true; loop=false; } } else if (CRCInput::isNumeric(msg)) { if (!Bouquets.empty()) { if (pos == lmaxpos) { if (msg == CRCInput::RC_0) { chn = firstselected; pos = lmaxpos; } else { chn = CRCInput::getNumericValue(msg); pos = 1; } } else { chn = chn * 10 + CRCInput::getNumericValue(msg); pos++; } if (chn > Bouquets.size()) { chn = firstselected; pos = lmaxpos; } int new_selected = (chn - 1) % Bouquets.size(); // is % necessary (i.e. can firstselected be > Bouquets.size()) ? updateSelection(new_selected); } } else if (msg == NeutrinoMessages::EVT_SERVICESCHANGED || msg == NeutrinoMessages::EVT_BOUQUETSCHANGED) { g_RCInput->postMsg(msg, data); loop = false; res = CHANLIST_CANCEL_ALL; } else if (msg > CRCInput::RC_MaxRC) { if ( CNeutrinoApp::getInstance()->handleMsg( msg, data ) & messages_return::cancel_all ) { loop = false; res = CHANLIST_CANCEL_ALL; } } frameBuffer->blit(); } hide(); fader.StopFade(); CVFD::getInstance()->setMode(CVFD::MODE_TVRADIO); if (save_bouquets) { save_bouquets = false; #if 0 if (CNeutrinoApp::getInstance()->GetChannelMode() == LIST_MODE_FAV) g_bouquetManager->saveUBouquets(); else g_bouquetManager->saveBouquets(); #endif if (g_settings.epg_scan == CEpgScan::SCAN_SEL) CEpgScan::getInstance()->Start(); } if(zapOnExit) return (selected); return (res); }
int main() { // Create window sf::RenderWindow window(sf::VideoMode(800, 600), "Thor Particles"); // Load texture sf::Texture texture; if (!texture.loadFromFile("Media/particle.png")) return EXIT_FAILURE; // Create emitter thor::UniversalEmitter::Ptr emitter = thor::UniversalEmitter::create(); emitter->setEmissionRate(30.f); emitter->setParticleLifetime(sf::seconds(5.f)); // Create particle system thor::ParticleSystem system(texture); system.addEmitter(emitter); // Build color gradient (green -> teal -> blue) thor::ColorGradient gradient; gradient[0.f] = sf::Color(0, 150, 0); gradient[0.5f] = sf::Color(0, 150, 100); gradient[1.f] = sf::Color(0, 0, 150); // Create color and fade in/out animations thor::ColorAnimation colorizer(gradient); thor::FadeAnimation fader(0.1f, 0.1f); // Add particle affectors system.addAffector( thor::AnimationAffector::create(colorizer) ); system.addAffector( thor::AnimationAffector::create(fader) ); system.addAffector( thor::TorqueAffector::create(100.f) ); system.addAffector( thor::ForceAffector::create(sf::Vector2f(0.f, 100.f)) ); // Attributes that influence emitter thor::PolarVector2f velocity(200.f, -90.f); bool paused = false; sf::Font font; if (!font.loadFromFile("Media/sansation.ttf")) return 1; // Instruction text sf::Text instructions( "Left click: Pause\n" "Mouse wheel: Change direction\n", font, 12); // Create clock to measure frame time sf::Clock frameClock; // Main loop for (;;) { // Handle events sf::Event event; while (window.pollEvent(event)) { switch (event.type) { // [X]: Quit case sf::Event::Closed: return 0; // Escape: Quit case sf::Event::KeyPressed: if (event.key.code == sf::Keyboard::Escape) return 0; // Left mouse button: Enable/disable glow case sf::Event::MouseButtonPressed: if (event.mouseButton.button == sf::Mouse::Left) paused = !paused; break; // Mouse wheel: Change emission direction case sf::Event::MouseWheelMoved: velocity.phi += 12.f * event.mouseWheel.delta; break; } } // Update particle system and emitter const sf::Time frameTime = frameClock.restart(); if (!paused) system.update(frameTime); // Set initial particle position and velocity, rotate vector randomly by maximal 10 degrees emitter->setParticlePosition( window.mapPixelToCoords(sf::Mouse::getPosition(window)) ); emitter->setParticleVelocity( thor::Distributions::deflect(velocity, 10.f) ); // Draw everything window.clear(sf::Color(30, 30, 30)); window.draw(instructions); window.draw(system); window.display(); } }
int CDBoxInfoWidget::exec(CMenuTarget* parent, const std::string &) { if (parent) { parent->hide(); } COSDFader fader(g_settings.menu_Content_alpha); fader.StartFadeIn(); paint(); frameBuffer->blit(); //int res = g_RCInput->messageLoop(); neutrino_msg_t msg; neutrino_msg_data_t data; int res = menu_return::RETURN_REPAINT; bool doLoop = true; int timeout = g_settings.timing[SNeutrinoSettings::TIMING_MENU]; uint64_t timeoutEnd = CRCInput::calcTimeoutEnd( timeout == 0 ? 0xFFFF : timeout); uint32_t updateTimer = g_RCInput->addTimer(5*1000*1000, false); while (doLoop) { g_RCInput->getMsgAbsoluteTimeout( &msg, &data, &timeoutEnd ); if((msg == NeutrinoMessages::EVT_TIMER) && (data == fader.GetTimer())) { if(fader.Fade()) doLoop = false; } else if((msg == NeutrinoMessages::EVT_TIMER) && (data == updateTimer)) { paint(); } else if ( ( msg == CRCInput::RC_timeout ) || ( msg == CRCInput::RC_home ) || ( msg == CRCInput::RC_ok ) ) { if(fader.StartFadeOut()) { timeoutEnd = CRCInput::calcTimeoutEnd( 1 ); msg = 0; } else doLoop = false; } else if(msg == CRCInput::RC_setup) { res = menu_return::RETURN_EXIT_ALL; doLoop = false; } else if((msg == CRCInput::RC_sat) || (msg == CRCInput::RC_favorites)) { g_RCInput->postMsg (msg, 0); res = menu_return::RETURN_EXIT_ALL; doLoop = false; } else { int mr = CNeutrinoApp::getInstance()->handleMsg( msg, data ); if ( mr & messages_return::cancel_all ) { res = menu_return::RETURN_EXIT_ALL; doLoop = false; } else if ( mr & messages_return::unhandled ) { if ((msg <= CRCInput::RC_MaxRC) && (data == 0)) /* <- button pressed */ { timeoutEnd = CRCInput::calcTimeoutEnd( timeout ); } } } frameBuffer->blit(); } hide(); fader.Stop(); g_RCInput->killTimer(updateTimer); return res; }
void LightbulbHSWidget::renderWidget() { QStringList rows; rows<<row1<<row2<<row3<<row4; QMap<QString, int> statuses; statuses[row1] = row1presence; statuses[row2] = row2presence; statuses[row3] = row3presence; statuses[row4] = row4presence; QPixmap pixmap(312,82); QDir test; if (test.exists(skinPath+"\\background.png")) pixmap.load(skinPath+"\\background.png"); else pixmap.fill(Qt::black); painter = new QPainter( &pixmap ); painter->setRenderHint(QPainter::Antialiasing); if (showMyPresence) { switch (mPresence) { case 1: presence_online->render(painter,QRect(presencePosition,QSize(presenceSize,presenceSize))); break; case 2: presence_chatty->render(painter,QRect(presencePosition,QSize(presenceSize,presenceSize))); break; case 3: presence_away->render(painter,QRect(presencePosition,QSize(presenceSize,presenceSize))); break; case 4: presence_xa->render(painter,QRect(presencePosition,QSize(presenceSize,presenceSize))); break; case 5: presence_busy->render(painter,QRect(presencePosition,QSize(presenceSize,presenceSize))); break; default: presence_offline->render(painter,QRect(presencePosition,QSize(presenceSize,presenceSize))); break; } } else { icon_account->render(painter,QRect(presencePosition,QSize(presenceSize,presenceSize))); } QFont font = QApplication::font(); QPen pen = painter->pen(); pen.setCosmetic(true); pen.setColor(QColor(unreadColor)); painter->setPen(pen); if (unreadMsgCount > 0 && showGlobalUnreadCount) { unreadMark->render(painter,QRect(unreadMarkPosition,QSize(unreadMarkSize,unreadMarkSize))); if (showUnreadMarkText) { font.setPixelSize( unreadFontSize ); painter->setFont( font ); painter->drawText( QRect(unreadMarkTextPosition.x(), unreadMarkTextPosition.y(), unreadMarkTextWidth, unreadMarkTextHeight), Qt::AlignCenter, QString::number(unreadMsgCount)); } } pen.setColor(QColor(contactColor)); painter->setPen(pen); font.setPixelSize( contactFontSize ); painter->setFont( font ); int rowCount = rows.count(); if (rows.count() > maxRowsCount) rowCount = maxRowsCount; if (row1presence > -2) { QRect textRow = QRect(contactsPosition.x(), contactsPosition.y(), rowWidth, rowHeight); for (int i=0; i<maxRowsCount; i++) { painter->drawText( textRow, Qt::AlignLeft, rows.at(i)); textRow.translate( 0, rowHeight+spacing ); } } else painter->drawText( QRect(noDataAvailablePosition.x(),noDataAvailablePosition.y(),noDataAvailableWidth,noDataAvailableHeight), Qt::AlignVCenter, "Nothing to report, sir!"); for (int i=0; i<maxRowsCount; i++) { switch (statuses[rows.at(i)]) { case 0: indicator_online->render(painter,QRect(contactsPosition.x()+rowWidth,contactsPosition.y()+((rowHeight-indicatorSize)/2)+(i*(rowHeight+spacing)),indicatorSize,indicatorSize)); break; case 1: indicator_chatty->render(painter,QRect(contactsPosition.x()+rowWidth,contactsPosition.y()+((rowHeight-indicatorSize)/2)+(i*(rowHeight+spacing)),indicatorSize,indicatorSize)); break; case 2: indicator_away->render(painter,QRect(contactsPosition.x()+rowWidth,contactsPosition.y()+((rowHeight-indicatorSize)/2)+(i*(rowHeight+spacing)),indicatorSize,indicatorSize)); break; case 3: indicator_busy->render(painter,QRect(contactsPosition.x()+rowWidth,contactsPosition.y()+((rowHeight-indicatorSize)/2)+(i*(rowHeight+spacing)),indicatorSize,indicatorSize)); break; case 4: indicator_xa->render(painter,QRect(contactsPosition.x()+rowWidth,contactsPosition.y()+((rowHeight-indicatorSize)/2)+(i*(rowHeight+spacing)),indicatorSize,indicatorSize)); break; case 5: indicator_offline->render(painter,QRect(contactsPosition.x()+rowWidth,contactsPosition.y()+((rowHeight-indicatorSize)/2)+(i*(rowHeight+spacing)),indicatorSize,indicatorSize)); break; } } if (test.exists(skinPath+"\\fader.png")) { QImage fader(skinPath+"\\fader.png"); painter->drawImage(faderPosition.x(),faderPosition.y(),fader,faderPosition.x()+faderWidth,faderPosition.y()+faderHeight); } widget->SetItem("image1",pixmap.toSymbianCFbsBitmap()->Handle()); publishWidget(); painter->end(); }
int CTimerList::show() { neutrino_msg_t msg; neutrino_msg_data_t data; int res = menu_return::RETURN_REPAINT; uint64_t timeoutEnd = CRCInput::calcTimeoutEnd(g_settings.timing[SNeutrinoSettings::TIMING_MENU] == 0 ? 0xFFFF : g_settings.timing[SNeutrinoSettings::TIMING_MENU]); bool loop=true; bool update=true; COSDFader fader(g_settings.menu_Content_alpha); fader.StartFadeIn(); while (loop) { if (update) { hide(); updateEvents(); update=false; paint(); } g_RCInput->getMsgAbsoluteTimeout( &msg, &data, &timeoutEnd ); //ignore numeric keys if (g_RCInput->isNumeric(msg)){ msg = CRCInput::RC_nokey; } if ( msg <= CRCInput::RC_MaxRC ) timeoutEnd = CRCInput::calcTimeoutEnd(g_settings.timing[SNeutrinoSettings::TIMING_MENU] == 0 ? 0xFFFF : g_settings.timing[SNeutrinoSettings ::TIMING_MENU]); if((msg == NeutrinoMessages::EVT_TIMER) && (data == fader.GetTimer())) { if(fader.Fade()) loop = false; } else if ( ( msg == CRCInput::RC_timeout ) || ( msg == CRCInput::RC_home) || (msg == CRCInput::RC_left) || (( msg == CRCInput::RC_ok) && (timerlist.empty())) ) { //Exit after timeout or cancel key if(fader.StartFadeOut()) { timeoutEnd = CRCInput::calcTimeoutEnd( 1 ); msg = 0; } else loop=false; } else if ((msg == CRCInput::RC_up || msg == (unsigned int)g_settings.key_channelList_pageup) && !(timerlist.empty())) { int step = 0; int prev_selected = selected; step = (msg == (unsigned int)g_settings.key_channelList_pageup) ? listmaxshow : 1; // browse or step 1 selected -= step; if((prev_selected-step) < 0) // because of uint selected = timerlist.size() - 1; paintItem(prev_selected - liststart); unsigned int oldliststart = liststart; liststart = (selected/listmaxshow)*listmaxshow; if (oldliststart!=liststart) { paint(); } else { paintItem(selected - liststart); } paintFoot(); } else if ((msg == CRCInput::RC_down || msg == (unsigned int)g_settings.key_channelList_pagedown) && !(timerlist.empty())) { unsigned int step = 0; int prev_selected = selected; step = (msg == (unsigned int)g_settings.key_channelList_pagedown) ? listmaxshow : 1; // browse or step 1 selected += step; if(selected >= timerlist.size()) { if (((timerlist.size() / listmaxshow) + 1) * listmaxshow == timerlist.size() + listmaxshow) // last page has full entries selected = 0; else selected = ((step == listmaxshow) && (selected < (((timerlist.size() / listmaxshow) + 1) * listmaxshow))) ? (timerlist.size() - 1) : 0; } paintItem(prev_selected - liststart); unsigned int oldliststart = liststart; liststart = (selected/listmaxshow)*listmaxshow; if (oldliststart!=liststart) { paint(); } else { paintItem(selected - liststart); } paintFoot(); } else if ((msg == CRCInput::RC_right || msg == CRCInput::RC_ok || msg==CRCInput::RC_blue) && !(timerlist.empty())) { if (modifyTimer()==menu_return::RETURN_EXIT_ALL) { res=menu_return::RETURN_EXIT_ALL; loop=false; } else update=true; } else if ((msg == CRCInput::RC_red) && !(timerlist.empty())) { bool killTimer = true; if (CRecordManager::getInstance()->RecordingStatus(timerlist[selected].channel_id)) { CTimerd::RecordingStopInfo recinfo; recinfo.channel_id = timerlist[selected].channel_id; recinfo.eventID = timerlist[selected].eventID; if (CRecordManager::getInstance()->IsRecording(&recinfo)) { std::string title = ""; char buf1[1024]; CEPGData epgdata; CEitManager::getInstance()->getEPGid(timerlist[selected].epgID, timerlist[selected].epg_starttime, &epgdata); memset(buf1, '\0', sizeof(buf1)); if (epgdata.title != "") title = "(" + epgdata.title + ")\n"; snprintf(buf1, sizeof(buf1)-1, g_Locale->getText(LOCALE_TIMERLIST_ASK_TO_DELETE), title.c_str()); if(ShowMsg(LOCALE_RECORDINGMENU_RECORD_IS_RUNNING, buf1, CMessageBox::mbrYes, CMessageBox::mbYes | CMessageBox::mbNo, NULL, 450, 30, false) == CMessageBox::mbrNo) { killTimer = false; update = false; } } } if (killTimer) { Timer->removeTimerEvent(timerlist[selected].eventID); skipEventID=timerlist[selected].eventID; update = true; } } else if (msg==CRCInput::RC_green) { if (newTimer()==menu_return::RETURN_EXIT_ALL) { res=menu_return::RETURN_EXIT_ALL; loop=false; } else update=true; } else if (msg==CRCInput::RC_yellow) { update=true; } #if 0 else if ((msg==CRCInput::RC_blue)|| (CRCInput::isNumeric(msg)) ) { //pushback key if... g_RCInput->postMsg( msg, data ); loop=false; } #endif else if (msg==CRCInput::RC_setup) { res=menu_return::RETURN_EXIT_ALL; loop=false; } else if ( msg == CRCInput::RC_help || msg == CRCInput::RC_info) { CTimerd::responseGetTimer* timer=&timerlist[selected]; if (timer!=NULL) { if (timer->eventType == CTimerd::TIMER_RECORD || timer->eventType == CTimerd::TIMER_ZAPTO) { hide(); if (timer->epgID != 0) res = g_EpgData->show(timer->channel_id, timer->epgID, &timer->epg_starttime); else ShowHint(LOCALE_MESSAGEBOX_INFO, LOCALE_EPGVIEWER_NOTFOUND); if (res==menu_return::RETURN_EXIT_ALL) loop=false; else paint(); } } // help key } else if (msg == CRCInput::RC_sat || msg == CRCInput::RC_favorites) { g_RCInput->postMsg (msg, 0); loop = false; res = menu_return::RETURN_EXIT_ALL; } else { if ( CNeutrinoApp::getInstance()->handleMsg( msg, data ) & messages_return::cancel_all ) { loop = false; res = menu_return::RETURN_EXIT_ALL; } } } hide(); fader.Stop(); return(res); }
QString Script::handleSetFixture(const QList<QStringList>& tokens, QList<Universe *> universes) { qDebug() << Q_FUNC_INFO; if (tokens.size() > 4) return QString("Too many arguments"); bool ok = false; quint32 id = 0; quint32 ch = 0; uchar value = 0; double time = 0; id = tokens[0][1].toUInt(&ok); if (ok == false) return QString("Invalid fixture (ID: %1)").arg(tokens[0][1]); for (int i = 1; i < tokens.size(); i++) { QStringList list = tokens[i]; list[0] = list[0].toLower().trimmed(); if (list.size() == 2) { ok = false; if (list[0] == "val" || list[0] == "value") value = uchar(list[1].toUInt(&ok)); else if (list[0] == "ch" || list[0] == "channel") ch = list[1].toUInt(&ok); else if (list[0] == "time") time = list[1].toDouble(&ok); else return QString("Unrecognized keyword: %1").arg(list[0]); if (ok == false) return QString("Invalid value (%1) for keyword: %2").arg(list[1]).arg(list[0]); } } Doc* doc = qobject_cast<Doc*> (parent()); Q_ASSERT(doc != NULL); Fixture* fxi = doc->fixture(id); if (fxi != NULL) { if (ch < fxi->channels()) { int address = fxi->address() + ch; if (address < 512) { GenericFader* gf = fader(); Q_ASSERT(gf != NULL); FadeChannel fc; fc.setFixture(doc, fxi->id()); fc.setChannel(ch); fc.setTarget(value); fc.setFadeTime(time); // If the script has used the channel previously, it might still be in // the bowels of GenericFader so get the starting value from there. // Otherwise get it from universes (HTP channels are always 0 then). quint32 uni = fc.universe(); if (gf->channels().contains(fc) == true) fc.setStart(gf->channels()[fc].current()); else fc.setStart(universes[uni]->preGMValue(address)); fc.setCurrent(fc.start()); gf->add(fc); return QString(); } else { return QString("Invalid address: %1").arg(address); } } else { return QString("Fixture (%1) has no channel number %2").arg(fxi->name()).arg(ch); } } else { return QString("No such fixture (ID: %1)").arg(id); } }