Beispiel #1
0
//--------------------------------------------------------------------------------------------
void ui_drawImage( ui_id_t id, oglx_texture_t *img, float vx, float vy, float vwidth, float vheight, GLXvector4f image_tint )
{
    GLXvector4f tmp_tint = {1, 1, 1, 1};

    float vw, vh;
    float tx, ty;
    float x1, x2, y1, y2;

    // handle optional parameters
    if ( NULL == image_tint ) image_tint = tmp_tint;

    if ( img )
    {
        if ( 0 == vwidth || 0 == vheight )
        {
            vw = img->imgW;
            vh = img->imgH;
        }
        else
        {
            vw = vwidth;
            vh = vheight;
        }

        tx = ( float ) oglx_texture_GetImageWidth( img )  / ( float ) oglx_texture_GetTextureWidth( img );
        ty = ( float ) oglx_texture_GetImageHeight( img ) / ( float ) oglx_texture_GetTextureHeight( img );

        // convert the virtual coordinates to screen coordinates
        ui_virtual_to_screen( vx, vy, &x1, &y1 );
        ui_virtual_to_screen( vx + vw, vy + vh, &x2, &y2 );

        // Draw the image
        oglx_texture_Bind( img );

        GL_DEBUG( glColor4fv )( image_tint );

        GL_DEBUG( glBegin )( GL_QUADS );
        {
            GL_DEBUG( glTexCoord2f )( 0,  0 );  GL_DEBUG( glVertex2f )( x1, y1 );
            GL_DEBUG( glTexCoord2f )( tx,  0 );  GL_DEBUG( glVertex2f )( x2, y1 );
            GL_DEBUG( glTexCoord2f )( tx, ty );  GL_DEBUG( glVertex2f )( x2, y2 );
            GL_DEBUG( glTexCoord2f )( 0, ty );  GL_DEBUG( glVertex2f )( x1, y2 );
        }
        GL_DEBUG_END();
    }
}
Beispiel #2
0
//--------------------------------------------------------------------------------------------
// Drawing
void ui_drawButton( ui_id_t id, float vx, float vy, float vwidth, float vheight, GLXvector4f pcolor )
{
    float x1, x2, y1, y2;

    GLXvector4f color_1 = { 0.0f, 0.0f, 0.9f, 0.6f };
    GLXvector4f color_2 = { 0.54f, 0.0f, 0.0f, 1.0f };
    GLXvector4f color_3 = { 0.66f, 0.0f, 0.0f, 0.6f };

    // Draw the button
    GL_DEBUG( glDisable )( GL_TEXTURE_2D );

    if ( NULL == pcolor )
    {
        if ( ui_context.active != UI_Nothing && ui_context.active == id && ui_context.hot == id )
        {
            pcolor = color_1;
        }
        else if ( ui_context.hot != UI_Nothing && ui_context.hot == id )
        {
            pcolor = color_2;
        }
        else
        {
            pcolor = color_3;
        }
    }

    // convert the virtual coordinates to screen coordinates
    ui_virtual_to_screen( vx, vy, &x1, &y1 );
    ui_virtual_to_screen( vx + vwidth, vy + vheight, &x2, &y2 );

    GL_DEBUG( glColor4fv )( pcolor );
    GL_DEBUG( glBegin )( GL_QUADS );
    {
        GL_DEBUG( glVertex2f )( x1, y1 );
        GL_DEBUG( glVertex2f )( x1, y2 );
        GL_DEBUG( glVertex2f )( x2, y2 );
        GL_DEBUG( glVertex2f )( x2, y1 );
    }
    GL_DEBUG_END();

    GL_DEBUG( glEnable )( GL_TEXTURE_2D );
}
Beispiel #3
0
bool Console::draw()
{
	int windowHeight = sdl_scr.y;

	if (!windowHeight || !this->on)
	{
		return false;
	}

	SDL_Rect *pwin = &(this->rect);

	auto& renderer = Ego::Renderer::get();
	renderer.getTextureUnit().setActivated(nullptr);
	auto white = Ego::Math::Colour4f::white();
	auto black = Ego::Math::Colour4f::black();

	renderer.setColour(white);
	GL_DEBUG(glLineWidth)(5);
	GL_DEBUG(glBegin)(GL_LINE_LOOP);
	{
		GL_DEBUG(glVertex2i)(pwin->x, pwin->y);
		GL_DEBUG(glVertex2i)(pwin->x + pwin->w, pwin->y);
		GL_DEBUG(glVertex2i)(pwin->x + pwin->w, pwin->y + pwin->h);
		GL_DEBUG(glVertex2i)(pwin->x, pwin->y + pwin->h);
	}
	GL_DEBUG_END();

	GL_DEBUG(glLineWidth)(1);

	renderer.setColour(black);
	GL_DEBUG(glBegin)(GL_QUADS);
	{
		GL_DEBUG(glVertex2i)(pwin->x, pwin->y);
		GL_DEBUG(glVertex2i)(pwin->x + pwin->w, pwin->y);
		GL_DEBUG(glVertex2i)(pwin->x + pwin->w, pwin->y + pwin->h);
		GL_DEBUG(glVertex2i)(pwin->x, pwin->y + pwin->h);
	}
	GL_DEBUG_END();

	ATTRIB_PUSH(__FUNCTION__, GL_SCISSOR_BIT | GL_ENABLE_BIT);
	{
		int textWidth, textHeight, height;

		// clip the viewport
		renderer.setScissorTestEnabled(true);
		renderer.setScissorRectangle(pwin->x, windowHeight - (pwin->y + pwin->h), pwin->w, pwin->h);

		height = pwin->h;

		char buffer[EGOBOO_CONSOLE_WRITE_LEN];

		// draw the current command line
		buffer[0] = EGOBOO_CONSOLE_PROMPT;
		buffer[1] = ' ';
		buffer[2] = CSTR_END;

		strncat(buffer, this->buffer, 1022);
		buffer[1022] = CSTR_END;

		this->pfont->_font->getTextSize(buffer, &textWidth, &textHeight);
		height -= textHeight;
		this->pfont->_font->drawText(buffer, pwin->x, height - textHeight, white);

		if (CSTR_END != this->output_buffer[0])
		{
			// grab the line offsets
			size_t console_line_count = 0;
			size_t console_line_offsets[1024];
			size_t console_line_lengths[1024];
			char *pstr = this->output_buffer;
			while (pstr)
			{
				size_t len = strcspn(pstr, "\n");

				console_line_offsets[console_line_count] = pstr - this->output_buffer;
				console_line_lengths[console_line_count] = len;

				if (0 == len)
				{
					break;
				}

				pstr += len + 1;
				console_line_count++;
			}

			// draw the last output line and work backwards
			for (size_t i = console_line_count; i >= 1 && height > 0; --i)
			{
				size_t j = i - 1;
				size_t len = std::min((size_t)1023, console_line_lengths[j]);

				strncpy(buffer, this->output_buffer + console_line_offsets[j], len);
				buffer[len] = CSTR_END;

				this->pfont->_font->getTextSize(buffer, &textWidth, &textHeight);
				height -= textHeight;
				this->pfont->_font->drawText(buffer, pwin->x, height - textHeight, white);
			}
		}
	}
	ATTRIB_POP(__FUNCTION__);

	return true;
}