Example #1
0
void CameraController::setResolution( const Imath::V2i &resolution, ScreenWindowAdjustment adjustment )
{
	const V2i oldResolution = m_data->resolution->readable();
	const Box2f oldScreenWindow = m_data->screenWindow->readable();
	
	m_data->resolution->writable() = resolution;

	Box2f newScreenWindow;
	if( adjustment == ScaleScreenWindow )
	{
		const float oldAspect = (float)oldResolution.x/(float)oldResolution.y;
		const float badAspect = (float)resolution.x/(float)resolution.y;
		const float yScale = oldAspect / badAspect;

		newScreenWindow = oldScreenWindow;
		newScreenWindow.min.y *= yScale;
		newScreenWindow.max.y *= yScale;
	}
	else
	{
		const V2f screenWindowCenter = oldScreenWindow.center();
		const V2f scale = V2f( resolution ) / V2f( oldResolution );
		newScreenWindow.min = (oldScreenWindow.min - screenWindowCenter) * scale;
		newScreenWindow.max = (oldScreenWindow.max - screenWindowCenter) * scale;
	}
	
	m_data->screenWindow->writable() = newScreenWindow;
}
Example #2
0
bool LayersDialog::handle_event(SDL_Event const &event, Vector2f local_mouse) {
	mouse_pos = local_mouse;
	if (layering() == NULL) return false;

	if (event.type == SDL_MOUSEBUTTONDOWN) {
		vector< DialogBin > const &bins = layering()->bins;
		ListGraph &stacking = layering()->stacking;
		const float dialog_tween = layering()->dialog_tween;
		const vector< vector< uint32_t > > &layers = layering()->layers;
		const Vector2ui dialog_point = layering()->dialog_point;
		const vector< uint32_t > &tags = layering()->tags;
		const unsigned int width = layering()->width;
		const unsigned int height = layering()->height;
		for (unsigned int b = 0; b < bins.size(); ++b) {
			Box2f box = bins[b].get_box(dialog_tween);
			if (box.contains(local_mouse)) {
				if (bins[b].layer >= layers.size()) continue;
				bool up = local_mouse.y > box.center().y;
				if (dialog_point.x < width && dialog_point.y < height && tags.size() == width * height) {
					unsigned int t = tags[dialog_point.y * width + dialog_point.x];
					assert(t < stacking.lists.size());
					for (unsigned int i = 0; i < stacking.lists[t].size(); ++i) {
						if (stacking.lists[t][i] == bins[b].layer) {
							if (up && i + 1 < stacking.lists[t].size()) {
								stacking.flip_rel(t, bins[b].layer, stacking.lists[t][i+1], true);
								layering()->update_image();
							}
							if (!up && i - 1 < stacking.lists[t].size()) {
								stacking.flip_rel(t, bins[b].layer, stacking.lists[t][i-1], false);
								layering()->update_image();
							}
							break;
						}
					}
				}
				return true;
			}
		}
	}
	return false;
}
Example #3
0
void BackdropNodeGadget::doRender( const Style *style ) const
{
	// this is our bound in gadget space
	Box2f bound = boundPlug()->getValue();
	
	// but because we're going to draw our contents at an arbitrary scale,
	// we need to compute a modified bound which will be in the right place
	// following scaling. 
	
	const Backdrop *backdrop = static_cast<const Backdrop *>( node() );
	const float scale = backdrop->scalePlug()->getValue();
	
	bound.min /= scale;
	bound.max /= scale;
	
	glPushMatrix();
	
	glScalef( scale, scale, scale );

	const Box3f titleCharacterBound = style->characterBound( Style::HeadingText );
	const float titleBaseline = bound.max.y - g_margin - titleCharacterBound.max.y;

	if( IECoreGL::Selector::currentSelector() )
	{
		// when selecting we render in a simplified form.
		// we only draw a thin strip around the edge of the backdrop
		// to allow the edges to be grabbed for dragging, and a strip
		// at the top to allow the title header to be grabbed for moving
		// around. leaving the main body of the backdrop as a hole is
		// necessary to allow the GraphGadget to continue to perform
		// drag selection on the nodes on top of the backdrop.
		
		const float width = hoverWidth() / scale;
			
		style->renderSolidRectangle( Box2f( bound.min, V2f( bound.min.x + width, bound.max.y ) ) ); // left
		style->renderSolidRectangle( Box2f( V2f( bound.max.x - width, bound.min.y ), bound.max ) ); // right
		style->renderSolidRectangle( Box2f( bound.min, V2f( bound.max.x, bound.min.y + width ) ) ); // bottom
		style->renderSolidRectangle( Box2f( V2f( bound.min.x, bound.max.y - width ), bound.max ) ); // top
		style->renderSolidRectangle( Box2f( V2f( bound.min.x, titleBaseline - g_margin ), bound.max ) ); // heading
	}
	else
	{
		// normal drawing mode
	
		style->renderBackdrop( bound, getHighlighted() ? Style::HighlightedState : Style::NormalState );

		const std::string title = backdrop->titlePlug()->getValue();
		if( title.size() )
		{
			Box3f titleBound = style->textBound( Style::HeadingText, title );
			glPushMatrix();
				glTranslatef( bound.center().x - titleBound.size().x / 2.0f, titleBaseline, 0.0f );
				style->renderText( Style::HeadingText, title );
			glPopMatrix();
		}

		if( m_hovered )
		{
			style->renderHorizontalRule(
				V2f( bound.center().x, titleBaseline - g_margin / 2.0f ),
				bound.size().x - g_margin * 2.0f,
				Style::HighlightedState
			);
		}

		Box2f textBound = bound;
		textBound.min += V2f( g_margin );
		textBound.max = V2f( textBound.max.x - g_margin, titleBaseline - g_margin );
		if( textBound.hasVolume() )
		{
			std::string description = backdrop->descriptionPlug()->getValue();
			style->renderWrappedText( Style::BodyText, description, textBound );
		}
	}
	
	glPopMatrix();
}
Example #4
0
void ImageGadget::doRender( const GafferUI::Style *style ) const
{
	if( IECoreGL::Selector::currentSelector() )
	{
		return;
	}

	// Compute what we need, and abort rendering if
	// there are any computation errors.

	Format format;
	Box2i dataWindow;
	try
	{
		format = this->format();
		dataWindow = this->dataWindow();
		updateTiles();
	}
	catch( ... )
	{
		return;
	}

	// Early out if the image has no size.

	const Box2i &displayWindow = format.getDisplayWindow();
	if( BufferAlgo::empty( displayWindow ) )
	{
		return;
	}

	// Render a black background the size of the image.
	// We need to account for the pixel aspect ratio here
	// and in all our drawing. Variables ending in F denote
	// windows corrected for pixel aspect.

	const Box2f displayWindowF(
		V2f( displayWindow.min ) * V2f( format.getPixelAspect(), 1.0f ),
		V2f( displayWindow.max ) * V2f( format.getPixelAspect(), 1.0f )
	);

	const Box2f dataWindowF(
		V2f( dataWindow.min ) * V2f( format.getPixelAspect(), 1.0f ),
		V2f( dataWindow.max ) * V2f( format.getPixelAspect(), 1.0f )
	);

	glColor3f( 0.0f, 0.0f, 0.0f );
	style->renderSolidRectangle( displayWindowF );
	if( !BufferAlgo::empty( dataWindow ) )
	{
		style->renderSolidRectangle( dataWindowF );
	}

	// Draw the image tiles over the top.

	renderTiles();

	// And add overlays for the display and data windows.

	glColor3f( 0.1f, 0.1f, 0.1f );
	style->renderRectangle( displayWindowF );

	string formatText = Format::name( format );
	const string dimensionsText = lexical_cast<string>( displayWindow.size().x ) + " x " +  lexical_cast<string>( displayWindow.size().y );
	if( formatText.empty() )
	{
		formatText = dimensionsText;
	}
	else
	{
		formatText += " ( " + dimensionsText + " )";
	}

	renderText( formatText, V2f( displayWindowF.center().x, displayWindowF.min.y ), V2f( 0.5, 1.5 ), style );

	if( displayWindow.min != V2i( 0 ) )
	{
		renderText( lexical_cast<string>( displayWindow.min ), displayWindowF.min, V2f( 1, 1.5 ), style );
		renderText( lexical_cast<string>( displayWindow.max ), displayWindowF.max, V2f( 0, -0.5 ), style );
	}

	if( !BufferAlgo::empty( dataWindow ) && dataWindow != displayWindow )
	{
		glColor3f( 0.5f, 0.5f, 0.5f );
		style->renderRectangle( dataWindowF );

		if( dataWindow.min != displayWindow.min )
		{
			renderText( lexical_cast<string>( dataWindow.min ), dataWindowF.min, V2f( 1, 1.5 ), style );
			renderText( lexical_cast<string>( dataWindow.max ), dataWindowF.max, V2f( 0, -0.5 ), style );
		}
	}
}
Example #5
0
void LayersDialog::draw(Box2f viewport, Box2f screen_viewport, float scale, unsigned int recurse) {

	if (!subpixel_shader.ref) {
		Graphics::ShaderObjectRef frag = Graphics::get_shader_object("ll_shaders/ll_subpixel.glsl", GL_FRAGMENT_SHADER_ARB);
		assert(frag.ref);
		subpixel_shader = Graphics::get_program_object(frag);
		assert(subpixel_shader.ref);
		glUseProgramObjectARB(subpixel_shader->handle);
		glUniform1iARB(glGetUniformLocationARB(subpixel_shader->handle, "image"), 0);
		glUseProgramObjectARB(0);
	}


	glMatrixMode(GL_PROJECTION);
	glPushMatrix();
	glBoxToBox(viewport, screen_viewport);
	glMatrixMode(GL_MODELVIEW);
	glPushMatrix();

	glBegin(GL_QUADS);
	glColor3f(0.4f, 0.2f, 0.2f);
	glVertex2f(-size().x*0.5f, -size().y*0.5f);
	glVertex2f( size().x*0.5f, -size().y*0.5f);
	glVertex2f( size().x*0.5f,  size().y*0.5f);
	glVertex2f(-size().x*0.5f,  size().y*0.5f);
	glEnd();

	if (!layering()) {
		glMatrixMode(GL_PROJECTION);
		glPopMatrix();
		glMatrixMode(GL_MODELVIEW);
		glPopMatrix();
		return;
	}

	vector< DialogBin > const &bins = layering()->bins;
	const float dialog_tween = layering()->dialog_tween;
	const unsigned int width = layering()->width;
	const unsigned int height = layering()->height;
	vector< GLuint > const &textures = layering()->textures;

	for (unsigned int b = 0; b < bins.size(); ++b) {
		float alpha = bins[b].active?1.0f:0.3f;
		Box2f box = bins[b].get_box(dialog_tween);
		glBegin(GL_QUADS);
		glColor4f(0.5f, 0.5f, 0.6f, alpha * 0.8f);
		glVertex2f(box.min.x, box.min.y);
		glVertex2f(box.max.x, box.min.y);
		glColor4f(0.9f, 0.85f, 0.83f, alpha * 0.8f);
		glVertex2f(box.max.x, box.max.y);
		glVertex2f(box.min.x, box.max.y);
		glEnd();
		Box2f tex = bins[b].get_tex_box(dialog_tween);
		Vector3f show = bins[b].get_show(dialog_tween, make_vector(width * 0.5f, height * 0.5f, width * 0.5f));
		show += bins[b].zoom_out * (make_vector(0.5f * width, 0.5f * height, 0.5f * width) - show);
		if (bins[b].layer < textures.size()) {
			float px_size = 2.0f / Graphics::screen_y * viewport.size().x / screen_viewport.size().x * show.z / (tex.max.y - tex.min.y);

			glUseProgramObjectARB(subpixel_shader->handle);
			glUniform1fARB(glGetUniformLocationARB(subpixel_shader->handle, "px_size"), px_size);

			glBindTexture(GL_TEXTURE_RECTANGLE_ARB, textures[bins[b].layer]);
		}
		glColor4f(1.0f, 1.0f, 1.0f, alpha);
		glBegin(GL_QUADS);
		glTexCoord2f(show.x-show.z,show.y-show.z);
		glVertex2f(tex.min.x, tex.min.y);
		glTexCoord2f(show.x+show.z,show.y-show.z);
		glVertex2f(tex.max.x, tex.min.y);
		glTexCoord2f(show.x+show.z,show.y+show.z);
		glVertex2f(tex.max.x, tex.max.y);
		glTexCoord2f(show.x-show.z,show.y+show.z);
		glVertex2f(tex.min.x, tex.max.y);
		glEnd();
		glBindTexture(GL_TEXTURE_RECTANGLE_ARB, 0);
		glUseProgramObjectARB(0);

		//arrows:
		float s = box.size().y * (1.0f / 3.0f);
		glEnable(GL_POLYGON_SMOOTH);
		glBegin(GL_TRIANGLES);
		glColor4f(1.0f, 1.0f, 1.0f, 0.5f * alpha * bins[b].arrows);
		glVertex2f(box.max.x - s * 1.5f, box.max.y - 0.25 * s);
		glVertex2f(box.max.x - s * 0.75f, box.max.y - 1.25 * s);
		glVertex2f(box.max.x - s * 2.25f, box.max.y - 1.25 * s);

		glVertex2f(box.max.x - s * 1.5f, box.min.y + 0.25 * s);
		glVertex2f(box.max.x - s * 0.75f, box.min.y + 1.25 * s);
		glVertex2f(box.max.x - s * 2.25f, box.min.y + 1.25 * s);
		glEnd();
		glDisable(GL_POLYGON_SMOOTH);
		glBegin(GL_LINES);
		glColor4f(1.0f, 1.0f, 1.0f, 0.5f * alpha * bins[b].arrows);
		glVertex2f(tex.max.x + box.size().x * 0.05f, box.center().y);
		glVertex2f(box.max.x - box.size().x * 0.05f, box.center().y);
		glEnd();
	}

	glMatrixMode(GL_PROJECTION);
	glPopMatrix();
	glMatrixMode(GL_MODELVIEW);
	glPopMatrix();

}