Exemple #1
0
void Fl_MIDIKeyboard::kbd_position(short pos){
    if( _type == MKB_HORIZONTAL)
        position(pos, yposition());
    else {
        position(xposition(),  pos);
    }
    visible_keys();                                         // calls redraw()
}
void CqCenterScroll::resize(int x, int y, int w, int h)
{
	int dw = w - this->w();
	int dh = h - this->h();
	Fl_Scroll::resize(x,y,w,h);
	// Scroll the widget so that the window seems to expand equally around the
	// contained widget.  This keeps the widget more centred than the default.
	position(xposition()-dw/2, yposition()-dh/2);
}
void CqCenterScroll::setImage(const boost::shared_ptr<CqImage>& image)
{
	int oldW = m_imageWidget.w();
	int oldH = m_imageWidget.h();
	m_imageWidget.setImage(image);
	// Scroll the position such that the centre of the child widget remains in
	// the same place.
	position(xposition() + (m_imageWidget.w() - oldW)/2,
			 yposition() + (m_imageWidget.h() - oldH)/2);
}
int CqCenterScroll::handle(int event)
{
	switch(event)
	{
		case FL_PUSH:
			if(Fl::event_button() == FL_MIDDLE_MOUSE)
			{
				m_prevDragX = Fl::event_x();
				m_prevDragY = Fl::event_y();
				return 1;
			}
			break;
		case FL_RELEASE:
			if(Fl::event_button() == FL_MIDDLE_MOUSE)
				return 1;
			break;
		case FL_DRAG:
			if(Fl::event_button() == FL_MIDDLE_MOUSE)
			{
				position(xposition() - (Fl::event_x() - m_prevDragX),
						yposition() - (Fl::event_y() - m_prevDragY));
				m_prevDragX = Fl::event_x();
				m_prevDragY = Fl::event_y();
				return 1;
			}
			break;
		case FL_KEYDOWN:
		case FL_SHORTCUT:
			int key = Fl::event_key();
			switch(key)
			{
				case 'h':
					if(Fl::event_alt())
						return 0;
						// passthrough
				case FL_Home:
					centerImageWidget();
					return 1;
					break;

				// Ignore cursors, so that the browser gets them.
				case FL_Up:
				case FL_Down:
				case FL_Left:
				case FL_Right:
					return 0;
			}
			break;
	}
	if(m_imageWidget.handle(event))
		return(1);
	else
		return Fl_Scroll::handle(event);
}
Exemple #5
0
void ParticleSystem::fuel(int particles, sf::Vector2f ySpawnRange, sf::Vector2f xSpawnRange) {
  for (int i = 0; i < particles; i++) {

    /* Randomizer initialization */
    std::random_device rd;
    std::mt19937 gen(rd());

    UniRealDist yposition(ySpawnRange.x, ySpawnRange.y);
    UniRealDist xposition(xSpawnRange.x, xSpawnRange.y);
    UniRealDist yspeed(10.0f, 40.0f);
    m_particleSpeed = yspeed(gen);
    /* Generate a new particle and put it at the generation point */
    Particle *particle;
    particle = new Particle();
    particle->drawVertex.position.x = xposition(gen);
    particle->drawVertex.position.y = yposition(gen);
    particle->vel.x = 0.0f;
    particle->vel.y = 1.0f;
    /*
        switch (m_shape) {
        case Shape::CIRCLE: {
          // Generate a random angle
          UniRealDist randomAngle(0.0f, (2.0f * 3.14159265));
          float angle = randomAngle(gen);

          // Use the random angle as a thrust vector for the particle
          // UniRealDist randomAngleCos(0.0f, cos(angle));
          // UniRealDist randomAngleSin(0.0f, sin(angle));
          particle->vel.x = (float)(rand() % 100) * 0.01f; // randomAngleCos(gen);
          particle->vel.y = (float)(rand() % 100) * 0.01f; // randomAngleSin(gen);

          break;
        }
        case Shape::SQUARE: {
          // Square generation
          UniRealDist randomSide(-1.0f, 1.0f);
          particle->vel.x = randomSide(gen);
          particle->vel.y = randomSide(gen);

          break;
        }
        default: {
          particle->vel.x = 0.5f; // Easily detected
          particle->vel.y = 0.5f; // Easily detected
        }
        }
    */

    // We don't want lame particles. Reject, start over.
    if (particle->vel.x == 0.0f && particle->vel.y == 0.0f) {
      delete particle;
      continue;
    }

    /* Randomly change the colors of the particles */
    const auto a = (((m_particleSpeed - 10.0f) / 30.0f) * 255.0f) + 0;
    particle->drawVertex.color.r = 255;
    particle->drawVertex.color.g = 255 - a;
    particle->drawVertex.color.b = 255 - a;
    particle->drawVertex.color.a = 255;

    m_particles.push_back(ParticlePtr(particle));
  }

  return;
}