コード例 #1
0
ファイル: textbox.cpp プロジェクト: IkarusDowned/ValyriaTear
void TextBox::Draw()
{
    if(_text.empty())
        return;

    if(_initialized == false) {
        IF_PRINT_WARNING(VIDEO_DEBUG) << "function failed because the textbox was not initialized:\n" << _initialization_errors << std::endl;
        return;
    }

    // Don't draw text window if parent window is hidden
    if(_owner && _owner->GetState() == VIDEO_MENU_STATE_HIDDEN)
        return;

    VideoManager->PushState();

    VideoManager->SetDrawFlags(_xalign, _yalign, VIDEO_BLEND, 0);

    /*
    // TODO: this block of code (scissoring for textboxes) does not work properly

    if (_owner) {
    	rect.Intersect(_owner->GetScissorRect());
    }
    rect.Intersect(VideoManager->GetScissorRect());
    VideoManager->EnableScissoring(_owner || VideoManager->IsScissoringEnabled());
    if (VideoManager->IsScissoringEnabled()) {
    	VideoManager->SetScissorRect(_scissor_rect);
    }
    */

    // Set the draw cursor, draw flags, and draw the text
    VideoManager->Move(0.0f, _text_ypos);
    VideoManager->SetDrawFlags(VIDEO_X_LEFT, VIDEO_Y_TOP, VIDEO_BLEND, 0);
    _DrawTextLines(_text_xpos, _text_ypos, _scissor_rect);

    if(GUIManager->DEBUG_DrawOutlines())
        _DEBUG_DrawOutline();

    VideoManager->PopState();
} // void TextBox::Draw()
コード例 #2
0
ファイル: textbox.cpp プロジェクト: segafan/Hero-of-Allacrost
void TextBox::Draw() {
	if (_text.empty())
		return;

	if (_initialized == false) {
		IF_PRINT_WARNING(VIDEO_DEBUG) << "function failed because the textbox was not initialized:\n" << _initialization_errors << endl;
		return;
	}

	// Don't draw text window if parent window is hidden
	if (_owner && _owner->GetState() == VIDEO_MENU_STATE_HIDDEN)
		return;

	// Take the following steps to draw the text:
	//  (1): Save the video engine's context and enable appropriate draw settings
	//  (2): Determine the coordinates of the textbox rectangle to draw
	//  (3): Create a ScreenRect for the textbox area and apply scissoring if its enabled
	//  (4): Determine the text draw position from the alignment flags
	//  (5): Draw each line of text to the screen
	//  (6): Restore the original video engine context
	VideoManager->PushState();

	VideoManager->SetDrawFlags(_xalign, _yalign, VIDEO_BLEND, 0);

	// Stores the positions of the four sides of the rectangle
	float left   = 0.0f;
	float right  = _width;
	float bottom = 0.0f;
	float top    = _height;

	CalculateAlignedRect(left, right, bottom, top);

	// Create a screen rectangle for the position and apply any scissoring
	int32 x, y, w, h;

	x = static_cast<int32>(left < right ? left : right);
	y = static_cast<int32>(top < bottom ? top : bottom);
	w = static_cast<int32>(right - left);
	h = static_cast<int32>(top - bottom);

	if (w < 0)
		w = -w;
	if (h < 0)
		h = -h;

	ScreenRect rect(x, y, w, h);

	// TODO: this block of code (scissoring for textboxes) does not work properly
	/*
	if (_owner) {
		rect.Intersect(_owner->GetScissorRect());
	}
	rect.Intersect(VideoManager->GetScissorRect());
	VideoManager->EnableScissoring(_owner || VideoManager->IsScissoringEnabled());
	if (VideoManager->IsScissoringEnabled()) {
		VideoManager->SetScissorRect(rect);
	}
	*/

	// Holds the height of the text to be drawn
	float text_height = static_cast<float>(CalculateTextHeight());
	// Holds the x and y position where the text should be drawn
	float text_xpos, text_ypos;

	// Determine the vertical position of the text based on the alignment
	if (_text_yalign == VIDEO_Y_TOP) {
		text_ypos = top;
	}
	else if (_text_yalign == VIDEO_Y_CENTER) {
		text_ypos = top - (VideoManager->_current_context.coordinate_system.GetVerticalDirection() * (_height - text_height) * 0.5f);
	}
	else { // (_yalign == VIDEO_Y_BOTTOM)
		text_ypos = top - (VideoManager->_current_context.coordinate_system.GetVerticalDirection() * (_height - text_height));
	}

	// Determine the horizontal position of the text based on the alignment
	if (_text_xalign == VIDEO_X_LEFT) {
		text_xpos = left;
	}
	else if (_text_xalign == VIDEO_X_CENTER) {
		text_xpos = (left + right) * 0.5f; // TODO: Is this logic right? It doesn't seem so...
	}
	else { // (_text_xalign == VIDEO_X_RIGHT)
		text_xpos = right;
	}

	// Set the draw cursor, draw flags, and draw the text
	VideoManager->Move(0.0f, text_ypos);
	VideoManager->SetDrawFlags(VIDEO_X_LEFT, VIDEO_Y_TOP, VIDEO_BLEND, 0);
	_DrawTextLines(text_xpos, text_ypos, rect);

	if (GUIManager->DEBUG_DrawOutlines() == true)
		_DEBUG_DrawOutline(text_ypos);

	VideoManager->PopState();
} // void TextBox::Draw()