void TextParticlesApp::mouseDrag( MouseEvent event )
{
	Rectf r	= Rectf( 0, 0, getWindowWidth(), getWindowHeight() );
	if ( r.contains( event.getPos() )) {
		mCamUi.mouseDrag( event );
	}
}
Example #2
0
void Fluid2DTextureApp::draw()
{
	// clear out the window with black
	gl::clear( Color( 0, 0, 0 ) ); 
	gl::setMatricesWindow( getWindowWidth(), getWindowHeight() );

	// Update the positions and tex coords
	Rectf drawRect = getWindowBounds();
	int limX = mFluid2D.resX() - 1;
	int limY = mFluid2D.resY() - 1;
	float dx = drawRect.getWidth()/(float)limX;
	float dy = drawRect.getHeight()/(float)limY;
	
	for( int j = 0; j < mFluid2D.resY(); ++j ) {
		for( int i = 0; i < mFluid2D.resX(); ++i ) {
			vec2 P = vec2( i*dx, j*dy );
			vec2 uv = mFluid2D.texCoordAt( i, j );

			int idx = j*mFluid2D.resX() + i;
			mTriMesh->getPositions<2>()[idx] = P;
			mTriMesh->getTexCoords0<2>()[idx] = uv;
			
		}
	}

	mTex->bind();
	gl::bindStockShader( gl::ShaderDef().color().texture() );
	gl::draw( gl::VboMesh::create(*mTriMesh) );
	mTex->unbind();
	
	mParams.draw();	
}
//----------------------------------------------------------------------------//
void NullGeometryBuffer::setClippingRegion(const Rectf& region)
{
    d_clipRect.top(ceguimax(0.0f, region.top()));
    d_clipRect.bottom(ceguimax(0.0f, region.bottom()));
    d_clipRect.left(ceguimax(0.0f, region.left()));
    d_clipRect.right(ceguimax(0.0f, region.right()));
}
Example #4
0
	///////////////////////////////////////////////////////////
	//
	// TRANSFORMATIONS
	//
	// Fit src inside dst
	Rectf rectToFit( Rectf src, Rectf dst )
	{
		float sw = src.getWidth();
		float sh = src.getHeight();
		float sa = (sw / sh);	// aspect ratio
		float dw = dst.getWidth();
		float dh = dst.getHeight();
		float da = (dw / dh);	// aspect ratio
		// different ratio
		if (da > sa)
		{
			float scale = (dh / sh);
			float gap = (dw - (sw * scale)) / 2.0f;
			return Rectf( gap, 0, dw-gap, dh);
		}
		else if (da < sa)
		{
			float scale = (dw / sw);
			float gap = (dh - (sh * scale)) / 2.0f;
			return Rectf( 0, gap, dw, dh-gap );
		}
		// Same ratio
		else
			return dst;
	}
Example #5
0
//----------------------------------------------------------------------------//
float UnifiedDim::getValue(const Window&, const Rectf& container) const
{
    switch (d_what)
    {
        case DT_LEFT_EDGE:
        case DT_RIGHT_EDGE:
        case DT_X_POSITION:
        case DT_X_OFFSET:
        case DT_WIDTH:
            return CoordConverter::asAbsolute(d_value, container.getWidth());
            break;

        case DT_TOP_EDGE:
        case DT_BOTTOM_EDGE:
        case DT_Y_POSITION:
        case DT_Y_OFFSET:
        case DT_HEIGHT:
            return CoordConverter::asAbsolute(d_value, container.getHeight());
            break;

        default:
            CEGUI_THROW(InvalidRequestException(
                "unknown or unsupported DimensionType encountered."));
            break;
    }
}
Example #6
0
void
TitleScreen::make_tux_jump()
{
  static bool jumpWasReleased = true;
  Sector& sector  = m_titlesession->get_current_sector();
  Player& tux = sector.get_player();

  m_controller->update();
  m_controller->press(Control::RIGHT);

  // Check if we should press the jump button
  Rectf lookahead = tux.get_bbox();
  lookahead.set_right(lookahead.get_right() + 96);
  bool pathBlocked = !sector.is_free_of_statics(lookahead);
  if ((pathBlocked && jumpWasReleased) || !tux.on_ground()) {
    m_controller->press(Control::JUMP);
    jumpWasReleased = false;
  } else {
    jumpWasReleased = true;
  }

  // Wrap around at the end of the level back to the beginning
  if (sector.get_width() - 320 < tux.get_pos().x) {
    sector.activate("main");
    sector.get_camera().reset(tux.get_pos());
  }
}
Example #7
0
//----------------------------------------------------------------------------
bool SizeNode::IsIntersectSizeRange(const SizeNode *node) const
{
	Rectf worldRect = GetWorldRect();
	Rectf nodeWorldRect = node->GetWorldRect();

	return  worldRect.IsIntersect(nodeWorldRect);
}
void drawGrid(const Rectf &bounds, float sx, float sy, const Vec2f &offset)
{
    float x1 = bounds.x1 - utils::math::boundf(bounds.x1 - offset.x, sx);
    float y1 = bounds.y1 - utils::math::boundf(bounds.y1 - offset.y, sy);

    int nx = int(ci::math<float>::ceil(bounds.getWidth() / sx)) + 1;
    int ny = int(ci::math<float>::ceil(bounds.getHeight() / sy)) + 1;

    vector<Vec2f> vertices;
    vertices.reserve((nx + ny) * 4);

    for (int iy = 0; iy < ny; iy++)
    {
        float y = y1 + iy * sy;
        vertices.emplace_back(bounds.x1, y);
        vertices.emplace_back(bounds.x2, y);
    }

    for (int ix = 0; ix < nx; ix++)
    {
        float x = x1 + ix * sx;
        vertices.emplace_back(x, bounds.y1);
        vertices.emplace_back(x, bounds.y2);
    }

    glEnableClientState(GL_VERTEX_ARRAY);
    glVertexPointer(2, GL_FLOAT, 0, vertices.data());
    glDrawArrays(GL_LINES, 0, vertices.size());
    glDisableClientState(GL_VERTEX_ARRAY);
}
Example #9
0
void MultiSlider::setup()
{
	float numSliders = (float)mData.size();
	vec2 size = getSize();
	size.y = mSliderHeight = std::max( size.y - mPadding.mTop - mPadding.mBottom,
		( (float)FontSize::SMALL + mPadding.mBottom + mPadding.mTop ) );
	mSliderSpacing = mPadding.mTop;
	size.y = mSliderHeight * numSliders + mPadding.mTop * 2.0f + mPadding.mBottom * 2.0f;
	if( mData.size() > 1 ) size.y += mSliderSpacing * ( numSliders - 1.0f );
	setSize( size );

	vec2 hitRectSize = mHitRect.getSize();
	float width = hitRectSize.x - ( mPadding.mLeft + mPadding.mRight );
	Rectf rect = mHitRect;
	int index = 0;
	for( auto &it : mData ) {
		rect.y1 = mHitRect.y1 + mPadding.mTop + ( mSliderSpacing + mSliderHeight ) * index;
		rect.y2 = rect.y1 + mSliderHeight;

		rect.x1 = mHitRect.x1 + mPadding.mLeft;
		rect.x2 = rect.x1 + width;

		string sliderName = it.mKey;
		LabelRef label = Label::create( sliderName + "_LABEL", sliderName, FontSize::SMALL );
		mLabelsMap[sliderName] = label;
		addSubView( label );

		float labelHeight = label->getHeight();
		float offset = ( rect.getHeight() - labelHeight ) / 2.0f;
		label->setOrigin( vec2( rect.x1, rect.y1 + offset ) );
		index++;
	}
	View::setup();
}
Example #10
0
void ClientApp::mouseDown( MouseEvent event )
{
	// fake "buttons" to trigger events
	if( infoRect.contains( event.getPos() ) )
	{
		LOG( "testing info logging" );
	}

	if( warnRect.contains( event.getPos() ) )
	{
		LOG_WARN( "testing warn logging" );
	}

	if( errorRect.contains( event.getPos() ) )
	{
		LOG_ERR( "testing error logging" );
	}

	if( eventRect.contains( event.getPos() ) )
	{
		AMPMClient::get()->sendEvent( "category", "action", "label", 10 );
	}

	if( crashRect.contains( event.getPos() ) )
	{
		quit();
	}
}
void ParticleSystem::update(Timer* timer )
{
	static float prevTime = (float) timer->getSeconds();
	float curTime = (float) timer->getSeconds();
	float dt = curTime - prevTime;
	prevTime = curTime;

	Rectf bounds = mBounds;
	float minX = -kBorder;
	float minY = -kBorder;
	float maxX = bounds.getWidth();
	float maxY = bounds.getHeight();

	// Avoid the borders in the remap because the velocity might be zero.
	// Nothing interesting happens where velocity is zero.
	float dx = (float)(mFluid->resX() - 4) / (float) bounds.getWidth();
	float dy = (float)(mFluid->resY() - 4) / (float) bounds.getHeight();
	for( int i = 0; i < numParticles(); ++i ) {
		Particle& part = mParticles.at( i );
		if( part.pos().x < minX || part.pos().y < minY || part.pos().x >= maxX || part.pos().y >= maxY ) {
			part.reset( newParticleVec(), Rand::randFloat( 0.0f, 1.0f ), mColor );
		}

		float x = part.pos().x * dx + 2.0f;
		float y = part.pos().y * dy + 2.0f;

		Vec2f vel = mFluid->velocity().bilinearSampleChecked( x, y, Vec2f( 0.0f, 0.0f ) );
		part.addForce( vel );

		part.update( mFluid->dt(), dt );
	}
}
void SmilesApp::setup()
{	
    mSmileLimit = 4.0f;
    mSmileAverageNumOfFrames = 10;
    mCamIndex = 0;
    mFps = getAverageFps();
    
    try {
		mCapture = Capture( CAMWIDTH, CAMHEIGHT );
		mCapture.start();
	}
	catch( ... ) {
		console() << "Failed to initialize capture" << std::endl;
	}
    
    mSmileRect = Rectf(300,100,600,400);
    setupSmileDetector(mSmileRect.getInteriorArea().getWidth(), mSmileRect.getInteriorArea().getHeight());
    console()<< mSmileRect.getInteriorArea().getWidth() << mSmileRect.getInteriorArea().getHeight() << endl;
	mSmileThreshold = 0;
	mSmileAverageIndex = 0;
    
    mParams = params::InterfaceGl( "Parameters", Vec2i( 220, 170 ) );
    mParams.addParam( "FPS", &mFps,"", true );
    mParams.addSeparator();
	mParams.addParam( "SmileResponse", &mSmileResponse, "", true );
    mParams.addParam( "SmileThreshold", &mSmileThreshold, "", true );
    
    mParams.addParam( "mSmileLimit", &mSmileLimit );
    mParams.addParam( "mSmileAverageNumOfFrames", &mSmileAverageNumOfFrames );
    
}
Example #13
0
	void X11Window::process_window_resize(const Rect &new_rect)
	{
		Rect old_client_area = client_area;
		client_area = new_rect;

		if (site)
		{
			if (old_client_area.left != client_area.left || old_client_area.top != client_area.top)
			{
				(site->sig_window_moved)();
			}

			if (old_client_area.get_width() != client_area.get_width() || old_client_area.get_height() != client_area.get_height())
			{
				Rectf rectf = client_area;
				rectf.left   /= pixel_ratio;
				rectf.top    /= pixel_ratio;
				rectf.right  /= pixel_ratio;
				rectf.bottom /= pixel_ratio;

				if (callback_on_resized)
					callback_on_resized(); // OpenGLWindowProvider::on_window_resized

				(site->sig_resize)(rectf.get_width(), rectf.get_height()); // TopLevelWindow_Impl::on_resize

				if (site->func_window_resize)
					(site->func_window_resize)(rectf);
			}
		}
	}
Example #14
0
void Camera::buildOrthographicProjectionMatrix(Matrix4x4& mat, const Rectf& viewport, float size, float zNear, float zFar, bool flipY)
{
	const float wideSize = (size * viewport.width() ) / viewport.height();
	const float left = -wideSize;
	const float right = wideSize;
	const float top = flipY ? - size : size;
	const float bottom = flipY ? size : -size;
	const float far = -zFar;
	const float near = zNear;

	const float a = 2.0f / (right - left);
	const float b = 2.0f / (top - bottom);
	const float c = -2.0f / (far - near);

	const float tx = -(right + left) / (right - left);
	const float ty = -(top + bottom) / (top - bottom);
	const float tz = -(far + near) / (far - near);

	mat.set(
		a, 0, 0, 0,
		0, b, 0, 0,
		0, 0, c, 0,
		tx, ty, tz, 1,
		false);
}
Example #15
0
float CoordConverter::getBaseYValue(const Window& window)
{
    const Window* parent = window.getParent();

    const Rectf parent_rect(parent ?
        parent->getChildContentArea(window.isNonClient()).get() :
        Rectf(Vector2f(0, 0), window.getRootContainerSize())
    );

    const float parent_height = parent_rect.getHeight();
    float baseY = parent_rect.d_min.d_y;

    baseY += asAbsolute(window.getArea().d_min.d_y, parent_height);

    switch(window.getVerticalAlignment())
    {
        case VA_CENTRE:
            baseY += (parent_height - window.getPixelSize().d_height) * 0.5f;
            break;
        case VA_BOTTOM:
            baseY += parent_height - window.getPixelSize().d_height;
            break;
        default:
            break;
    }

    return alignToPixels(baseY);
}
Example #16
0
void ParticleSoup::update()
{
	static float prevTime = (float)app::getElapsedSeconds();
	float curTime = (float)app::getElapsedSeconds();
	float dt = curTime - prevTime;
	prevTime = curTime;

	Rectf bounds = ci::app::getWindowBounds();
	float minX = -kBorder;
	float minY = -kBorder;
	float maxX = bounds.getWidth();
	float maxY = bounds.getHeight();

	// Avoid the borders in the remap because the velocity might be zero.
	// Nothing interesting happens where velocity is zero.
	float dx = (float)(mFluid->resX() - 4)/(float)bounds.getWidth();
	float dy = (float)(mFluid->resY() - 4)/(float)bounds.getHeight();
	for( int i = 0; i < numParticles(); ++i ) {
		Particle& part = mParticles.at( i );
		if( part.pos().x < minX || part.pos().y < minY || part.pos().x >= maxX || part.pos().y >= maxY ) {
			vec2 P;
			P.x = Rand::randFloat( bounds.x1 + 5.0f, bounds.x2 - 5.0f );
			P.y = Rand::randFloat( bounds.y1 + 5.0f, bounds.y2 - 5.0f );
			float life = Rand::randFloat( 2.0f, 3.0f );
			part.reset( P, life, mColor );
		}

		float x = part.pos().x*dx + 2.0f;
		float y = part.pos().y*dy + 2.0f;
		vec2 vel = mFluid->velocity().bilinearSampleChecked( x, y, vec2( 0.0f, 0.0f ) );
		part.addForce( vel );
		part.update( mFluid->dt(), dt );
	}
}
Example #17
0
void Layer::updateView( View *view )
{
	view->mIsIteratingSubviews = true;

	for( auto &subview : view->getSubviews() ) {
		if( subview->mMarkedForRemoval )
			continue;

		if( ! subview->mGraph )
			subview->mGraph = mGraph;

		updateView( subview.get() );
	}

	view->updateImpl();

	if( view->mLayer && view->mLayer.get() != this && ! view->mMarkedForRemoval ) {
		view->mLayer->update();
	}

	// make sure we have the right FrameBuffer size
	if( mRootView->mRendersToFrameBuffer ) {
		Rectf frameBufferBounds = view->getBoundsForFrameBuffer();
		if( mFrameBufferBounds.getWidth() < frameBufferBounds.getWidth() && mFrameBufferBounds.getHeight() < frameBufferBounds.getHeight() ) {
			mFrameBufferBounds = ceil( frameBufferBounds );
			LOG_LAYER( "mFrameBufferBounds: " << mFrameBufferBounds );
		}
	}

	view->mIsIteratingSubviews = false;
	view->clearViewsMarkedForRemoval();
}
Example #18
0
void drawAudioBuffer( const audio::Buffer &buffer, const Rectf &bounds, bool drawFrame, const ci::ColorA &color )
{
	gl::ScopedGlslProg glslScope( getStockShader( gl::ShaderDef().color() ) );

	gl::color( color );

	const float waveHeight = bounds.getHeight() / (float)buffer.getNumChannels();
	const float xScale = bounds.getWidth() / (float)buffer.getNumFrames();

	float yOffset = bounds.y1;
	for( size_t ch = 0; ch < buffer.getNumChannels(); ch++ ) {
		PolyLine2f waveform;
		const float *channel = buffer.getChannel( ch );
		float x = bounds.x1;
		for( size_t i = 0; i < buffer.getNumFrames(); i++ ) {
			x += xScale;
			float y = ( 1 - ( channel[i] * 0.5f + 0.5f ) ) * waveHeight + yOffset;
			waveform.push_back( vec2( x, y ) );
		}

		if( ! waveform.getPoints().empty() )
			gl::draw( waveform );

		yOffset += waveHeight;
	}

	if( drawFrame ) {
		gl::color( color.r, color.g, color.b, color.a * 0.6f );
		gl::drawStrokedRect( bounds );
	}
}
TutorialApp::TutorialApp()
{
	// Set square size
	mSize = 100.0f;
	const vec2 sz( mSize );

	// We are going to create two UiTrees for each type of transform:
	// one which uses velocity and one that does not.
	for ( size_t i = Transform_None + 1; i < Transform_Count; ++i ) {
		for ( size_t j = 0; j < 2; ++j ) {
			
			// Define the data structure.
			UiData data;
			data.mColor			= Colorf( randFloat(), randFloat(), randFloat() );
			data.mTransform		= (Transform)i;
			data.mUseVelocity	= j == 1;


			// Create the node and set its data.
			UiTree& node = mUiTree.createAndReturnChild()
				.data( data )
				.scale( sz );
			const Rectf bounds	= calcBounds( node );
			const vec2 p		= bounds.getCenter() - sz * 0.5f;
			node.translate( p );
		}
	}
}
//----------------------------------------------------------------------------
std::pair<float, float> EU_CanvasStage::CalPixelToWorld()
{
	Rectf viewPort = mViewPort;
	if (viewPort.IsEmpty())
		viewPort = Rectf(0.0f, 0.0f, mSize.Width, mSize.Height);

	std::pair<float, float> pixelToWorld;

	if (mStageCameraNode)
	{
		Camera *camera = mStageCameraNode->GetCamera();

		float rMin = camera->GetRMin();
		float uMin = camera->GetUMin();
		float viewPortWidth = viewPort.Width();
		float viewPortHeight = viewPort.Height();

		float worldW = 2.0f * -rMin;
		float worldH = 2.0f * -uMin;
		
		worldW *= 1000.0f;
		worldH *= 1000.0f;

		pixelToWorld.first = worldW / (float)viewPortWidth;
		pixelToWorld.second = worldH / (float)viewPortHeight;
	}

	mPixelToWorld = pixelToWorld;

	return mPixelToWorld;
}
Example #21
0
void
EditorInputCenter::update_tile_selection() {
  Rectf select = tile_drag_rect();
  auto tiles = Editor::current()->tileselect.tiles.get();
  auto tilemap = dynamic_cast<TileMap*>(Editor::current()->layerselect.selected_tilemap);
  if ( !tilemap ) {
    return;
  }

  tiles->tiles.clear();
  tiles->width = select.get_width() + 1;
  tiles->height = select.get_height() + 1;

  int w = tilemap->get_width();
  int h = tilemap->get_height();
  for (int y = select.p1.y; y <= select.p2.y; y++) {
    for (int x = select.p1.x; x <= select.p2.x; x++) {
      if ( x < 0 || y < 0 || x >= w || y >= h) {
        tiles->tiles.push_back(0);
      } else {
        tiles->tiles.push_back(tilemap->get_tile_id(x, y));
      }
    }
  }
}
Example #22
0
//----------------------------------------------------------------------------
Vector2f RenderStep::PointWorldToViewPort(const APoint &point,
	bool *isInBack)
{
	Rectf viewPort = mViewPort;
	if (viewPort.IsEmpty())
		viewPort = Rectf(0.0f, 0.0f, mSize.Width, mSize.Height);

	HMatrix matProjView = mCamera->GetProjectionMatrix() * mCamera->GetViewMatrix();
	HPoint hPoint(point.X(), point.Y(), point.Z(), point.W());
	HPoint tempPoint = matProjView * hPoint;

	if (isInBack)
	{
		if (tempPoint.Z() <= 0)
			*isInBack = true;
		else
			*isInBack = false;
	}

	float wInv = 1.0f / tempPoint.W();

	//投影坐标范围为[-1,1]要变成[0,1]
	Vector2f screenPoint;
	screenPoint.X() = (1.0f + tempPoint.X()*wInv) / 2.0f;
	screenPoint.Y() = (1.0f + tempPoint.Y()*wInv) / 2.0f;

	//投影坐标范围为[0,1]要变成视口内坐标
	screenPoint.X() = viewPort.Left + screenPoint.X()*viewPort.Width();
	screenPoint.Y() = viewPort.Bottom + screenPoint.Y()*viewPort.Height();

	return screenPoint;
}
//----------------------------------------------------------------------------//
void NullTextureTarget::declareRenderSize(const Sizef& sz)
{
	Rectf r;
	r.setSize(sz);
    r.setPosition(glm::vec2(0, 0));
    setArea(r);
}
Example #24
0
float FalagardSlider::getValueFromThumb(void) const
{
    Slider* w = (Slider*)d_window;
    // get area the thumb is supposed to use as it's area.
    const WidgetLookFeel& wlf = getLookNFeel();
    const Rectf area(wlf.getNamedArea("ThumbTrackArea").getArea().getPixelRect(*w));
    // get accesss to the thumb
    Thumb* theThumb = w->getThumb();

    // slider is vertical
    if (d_vertical)
    {
        // pixel extent of total available area the thumb moves in
        float slideExtent = area.getHeight() - theThumb->getPixelSize().d_height;
        // calculate value represented by current thumb position
        float thumbValue = (CoordConverter::asAbsolute(
                                theThumb->getYPosition(), w->getPixelSize().d_height) - area.top()) / (slideExtent / w->getMaxValue());
        // return final thumb value according to slider settings
        return d_reversed ? thumbValue : w->getMaxValue() - thumbValue;
    }
    // slider is horizontal
    else
    {
        // pixel extent of total available area the thumb moves in
        float slideExtent = area.getWidth() - theThumb->getPixelSize().d_width;
        // calculate value represented by current thumb position
        float thumbValue = (CoordConverter::asAbsolute(
                                theThumb->getXPosition(), w->getPixelSize().d_width) - area.left()) / (slideExtent / w->getMaxValue());
        // return final thumb value according to slider settings
        return d_reversed ? w->getMaxValue() - thumbValue : thumbValue;
    }
}
Example #25
0
//----------------------------------------------------------------------------//
void IrrlichtTexture::blitFromMemory(const void* sourceData, const Rectf& area)
{
    if (!d_texture)
        return;

    const size_t pitch = d_texture->getPitch();
    const std::uint32_t* src = static_cast<const std::uint32_t*>(sourceData);
    std::uint32_t* dst = static_cast<std::uint32_t*>(d_texture->lock());

    if (!dst)
        throw RendererException(
            "[IrrlichtRenderer] ITexture::lock failed.");

    dst += static_cast<size_t>(area.top()) * (pitch / 4) +
        static_cast<size_t>(area.left());

    const Sizef sz(area.getSize());

    for (int j = 0; j < sz.d_height; ++j)
    {
        for (int i = 0; i < sz.d_width; ++i)
        {
            dst[i] = src[i];
        }

        src += static_cast<int>(sz.d_width);
        dst += pitch / 4;
    }
    
    d_texture->unlock();
}
Example #26
0
//----------------------------------------------------------------------------//
float FalagardEditbox::calculateTextOffset(const Rectf& text_area,
                                           const float text_extent,
                                           const float caret_width,
                                           const float extent_to_caret)
{
    // if caret is to the left of the box
    if ((d_lastTextOffset + extent_to_caret) < 0)
        return -extent_to_caret;

    // if caret is off to the right.
    if ((d_lastTextOffset + extent_to_caret) >= (text_area.getWidth() - caret_width))
        return text_area.getWidth() - extent_to_caret - caret_width;

    // handle formatting of text when it's shorter than the available space
    if (text_extent < text_area.getWidth())
    {
        if (d_textFormatting == HTF_CENTRE_ALIGNED)
            return (text_area.getWidth() - text_extent) / 2;

        if (d_textFormatting == HTF_RIGHT_ALIGNED)
            return text_area.getWidth() - text_extent;
    }

    // no change to text position; re-use last offset value.
    return d_lastTextOffset;
}
void drawBuffer(const std::deque<int8_t>& buffer, const Rectf &bounds, bool drawFrame, const ci::ColorA &color, float scaleFactor )
{
  gl::ScopedGlslProg glslScope( getStockShader( gl::ShaderDef().color() ) );
  
  gl::color( color );
  
  const float waveHeight = bounds.getHeight();
  const float xScale = bounds.getWidth() / (float)buffer.size();
  
  float yOffset = bounds.y1;
  PolyLine2f waveform;
  float x = bounds.x1;
  for( size_t i = 0; i < buffer.size(); i++ ) {
    x += xScale;
    float y = ( 1.0f - ( buffer[i] * scaleFactor + 0.5f) ) * waveHeight + yOffset;
    waveform.push_back( vec2( x, y ) );
  }
  
  if( ! waveform.getPoints().empty() )
    gl::draw( waveform );
  
  if( drawFrame ) {
    gl::color( color.r, color.g, color.b, color.a * 0.6f );
    gl::drawStrokedRect( bounds );
  }
}
Example #28
0
float CoordConverter::getBaseXValue(const Window& window)
{
    const Window* parent = window.getParent();

    const Rectf parent_rect(parent ?
        parent->getChildContentArea(window.isNonClient()).get() :
        Rectf(Vector2f(0, 0), window.getRootContainerSize())
    );

    const float parent_width = parent_rect.getWidth();
    float baseX = parent_rect.d_min.d_x;

    baseX += asAbsolute(window.getArea().d_min.d_x, parent_width);

    switch(window.getHorizontalAlignment())
    {
        case HA_CENTRE:
            baseX += (parent_width - window.getPixelSize().d_width) * 0.5f;
            break;
        case HA_RIGHT:
            baseX += parent_width - window.getPixelSize().d_width;
            break;
        default:
            break;
    }

    return alignToPixels(baseX);
}
Example #29
0
// gets bounding box of element
Rectf DXFBlockRef::GetBoundingBox(void) const
{
	Rectf res;
	
	// get dxf object
	DXF const &dxf = GetDXF();

	// get block data by name; if none, returns
	if(!dxf.HasBlock(name))
		return Rectf(1e99, -1e99, -1e99, 1e99);
	DXFBlock const &blk = dxf.GetBlock(name);

	// get the bounding box of included entities
	Rectf bbe = blk.entities.GetBoundingBox();
	
	// now we need to apply transformation to bbox points
	TransMatrix M;
	M.Translate(insertPoint).Rotate(angle).Scale(scale);
	Pointf bl = M(bbe.BottomLeft());
	Pointf tl = M(bbe.TopLeft());
	Pointf br = M(bbe.BottomRight());
	Pointf tr = M(bbe.TopRight());
	
	// and now get the minimum and maximum coordinate values
	res.left	= min(min(bl.x, tl.x), min(br.x, tr.x));
	res.right	= max(max(bl.x, tl.x), max(br.x, tr.x));
	res.bottom	= min(min(bl.y, tl.y), min(br.y, tr.y));
	res.top		= max(max(bl.y, tl.y), max(br.y, tr.y));

	return res;
}
void Fluid2DTextureApp::draw()
{
	// clear out the window with black
	gl::clear( Color( 0, 0, 0 ) ); 
	gl::setMatricesWindow( getWindowWidth(), getWindowHeight() );

	// Update the positions and tex coords
	Rectf drawRect = getWindowBounds();
	int limX = mFluid2D.resX() - 1;
	int limY = mFluid2D.resY() - 1;
	float dx = drawRect.getWidth()/(float)limX;
	float dy = drawRect.getHeight()/(float)limY;
	
	for( int j = 0; j < mFluid2D.resY(); ++j ) {
		for( int i = 0; i < mFluid2D.resX(); ++i ) {
			Vec2f P = Vec2f( i*dx, j*dy );
			Vec2f uv = mFluid2D.texCoordAt( i, j );

			int idx = j*mFluid2D.resX() + i;
			mTriMesh.getVertices()[idx] = P;
			mTriMesh.getTexCoords()[idx] = uv;
			
		}
	}

	mTex.bind();
	gl::draw( mTriMesh ); 
	mTex.unbind();
	
	mParams.draw();	
}