Beispiel #1
0
//------------------------------------------------------------------------------
void
Background2D::SetScroll( const Ogre::Vector2& position )
{
    m_Position = position;
    Ogre::Vector3 pos_3d( m_Position.x, m_Position.y, 0 );

    if( !m_range.contains( pos_3d ) )
    {
        Ogre::Vector3 max_3d( m_range.getMaximum() );
        Ogre::Vector3 min_3d( m_range.getMinimum() );
        Ogre::Vector2 max( max_3d.x, max_3d.y );
        Ogre::Vector2 min( min_3d.x, min_3d.y );
        m_Position.makeCeil( min );
        m_Position.makeFloor( max );
    }

    applyScroll();
}
Beispiel #2
0
//------------------------------------------------------------------------------
void
Background2D::UpdateDebug()
{
    // is this necessary? does it cost to apply camera 2d Scroll?
    // if so maybe move this check to applyScroll
    if( m_PositionReal != GetScreenScroll() )
    {
        applyScroll();
    }

    if( cv_debug_background2d.GetB() == true )
    {
        DEBUG_DRAW.SetTextAlignment( DEBUG_DRAW.LEFT );
        DEBUG_DRAW.SetScreenSpace( true );
        DEBUG_DRAW.SetColour( Ogre::ColourValue( 0.0, 0.8, 0.8, 1 ) );
        for( unsigned int i = 0; i < m_AnimationPlayed.size(); ++i )
        {
            DEBUG_DRAW.Text( 150, 34 + i * 12, "Background 2D animation: " + m_AnimationPlayed[ i ].name );
        }
    }
}
Beispiel #3
0
void TextField::paint() {

	if (font == 0) {
		return;
	}

	g_rectangle bounds = getBounds();
	g_painter p(graphics);

	// Background
	p.setColor(RGB(255, 255, 255));
	p.fill(g_rectangle(0, 0, bounds.width, bounds.height));

	// Border
	if (focused) {
		p.setColor(RGB(55, 155, 255));
	} else if (visualStatus == TextFieldVisualStatus::HOVERED) {
		p.setColor(RGB(150, 150, 150));
	} else {
		p.setColor(RGB(180, 180, 180));
	}
	p.draw(g_rectangle(0, 0, bounds.width - 1, bounds.height - 1));

	// Scroll
	applyScroll();

	int pos = 0;
	int first = marker < cursor ? marker : cursor;
	int second = marker > cursor ? marker : cursor;

	// Paint marking
	if (focused) {
		pos = 0;
		for (g_positioned_glyph& g : viewModel.positions) {

			g_color_argb color = textColor;
			if (first != second && pos >= first && pos < second) {
				p.setColor(RGB(55, 155, 255));
				g_rectangle before = positionToCursorBounds(pos);
				g_rectangle after = positionToCursorBounds(pos + 1);
				p.fill(g_rectangle(before.x, before.y, after.x - before.x, before.height));

				color = RGB(255, 255, 255);
			}
			++pos;
		}
	}

	// Paint glyphs
	pos = 0;
	for (g_positioned_glyph& g : viewModel.positions) {

		g_rectangle onView = glyphToView(g);
		g_color_argb color = textColor;
		if (focused && first != second && pos >= first && pos < second) {
			color = RGB(255, 255, 255);
		}

		p.drawColoredBitmap(onView.x, onView.y, g.glyph->getBitmap(), color, onView.width, onView.height);
		++pos;
	}

	// Paint cursor
	if (focused) {
		p.setColor(RGB(60, 60, 60));
		p.fill(positionToCursorBounds(cursor));
	}
}
Beispiel #4
0
//------------------------------------------------------------------------------
void
Background2D::OnResize()
{
    calculateScreenScale();

    for( unsigned int i = 0; i < m_Tiles.size(); ++i )
    {
        Tile &tile( m_Tiles[ i ] );
        Ogre::Vector2   top_left ( tile.x, -tile.y );
        Ogre::Vector2   top_right( tile.x + tile.width, top_left.y );
        Ogre::Vector2   bottom_right( top_right.x, -( tile.y + tile.height ) );
        Ogre::Vector2   bottom_left( top_left.x, bottom_right.y );

        virtualScreenToWorldSpace( top_left );
        virtualScreenToWorldSpace( top_right );
        virtualScreenToWorldSpace( bottom_right );
        virtualScreenToWorldSpace( bottom_left );

        float new_x1 = top_left.x;
        float new_y1 = top_left.y;

        float new_x2 = top_right.x;
        float new_y2 = top_right.y;

        float new_x3 = bottom_right.x;
        float new_y3 = bottom_right.y;

        float new_x4 = bottom_left.x;
        float new_y4 = bottom_left.y;

        Ogre::HardwareVertexBufferSharedPtr vertex_buffer;

        if( m_Tiles[ i ].blending == QGears::B_ALPHA )
        {
            vertex_buffer = m_AlphaVertexBuffer;
        }
        else if( m_Tiles[ i ].blending == QGears::B_ADD )
        {
            vertex_buffer = m_AddVertexBuffer;
        }

        float* writeIterator = ( float* )vertex_buffer->lock( Ogre::HardwareBuffer::HBL_NORMAL );

        writeIterator += m_Tiles[ i ].start_vertex_index * TILE_VERTEX_INDEX_SIZE;

        *writeIterator++ = new_x1;
        *writeIterator++ = new_y1;
        writeIterator += 7;

        *writeIterator++ = new_x2;
        *writeIterator++ = new_y2;
        writeIterator += 7;

        *writeIterator++ = new_x3;
        *writeIterator++ = new_y3;
        writeIterator += 7;

        ///*
        *writeIterator++ = new_x1;
        *writeIterator++ = new_y1;
        writeIterator += 7;

        *writeIterator++ = new_x3;
        *writeIterator++ = new_y3;
        writeIterator += 7;
        //*/

        *writeIterator++ = new_x4;
        *writeIterator++ = new_y4;

        vertex_buffer->unlock();
    }

    applyScroll();
}