示例#1
0
void GlowLabelWidget::OnWidgetPaint()
{
	GLOW_DEBUGSCOPE("GlowLabelWidget::OnWidgetPaint");
	
	if (_opaque)
	{
		_backColor.Apply();
		::glRectf(-1.0f, -1.0f, 1.0f, 1.0f);
	}
	
	int vPos = _font.BaselinePos()+_vIndent;
	GLfloat x, y;
	
	if (IsActive())
	{
		_textColor.Apply();
	}
	else
	{
		_disableTextColor.Apply();
	}
	NormalizeCoordinates(_hIndent, vPos, x, y);
	::glRasterPos2f(x, y);
	int textlen = (_text == 0) ? 0 : GLOW_CSTD::strlen(_text);
	for (int i=0; i<textlen; i++)
	{
		if (_text[i] == '\n' ||
			(_text[i] == '\r' && i+1 < textlen && _text[i+1] != '\n'))
		{
			vPos += _font.Leading();
			NormalizeCoordinates(_hIndent, vPos, x, y);
			::glRasterPos2f(x, y);
		}
		else
		{
			::glutBitmapCharacter(_font, _text[i]);
		}
	}
}
示例#2
0
//Stack copy contructor
_SimpleList::_SimpleList (_SimpleList& l, long from, long to)
{
    if (from == 0 && to == -1) { // copy the whole thing
        Duplicate (&l);
    } else {
        Initialize           ();
        NormalizeCoordinates (from, to, l.lLength);
        RequestSpace(to-from);
        long upto = to-from ; 
        for (long k = 0; k < upto; k++) {
            lData[k] = l.lData[from+k];
        }
        /*
        for (long i = from; i < to; i++) {
            (*this) << l.lData[i];
        }
        */
    }
}
示例#3
0
void GlowTextFieldWidget::OnWidgetPaint()
{
	GLOW_DEBUGSCOPE("GlowTextFieldWidget::OnWidgetPaint");
	
	// Backing
	if (!IsActive())
	{
		_disableBackColor.Apply();
	}
	else if (HasKeyboardFocus())
	{
		_focusBackColor.Apply();
	}
	else
	{
		_backColor.Apply();
	}
	::glRectf(-1.0f, -1.0f, 1.0f, 1.0f);
	
	// Bevels for backing
	float bevelHeight = float(4)/float(Height());
	float bevelWidth = float(4)/float(Width());
	float etchHeight = float(2)/float(Height());
	float etchWidth = float(2)/float(Width());
	if (IsActive())
	{
		if (_style == etchedStyle)
		{
			_lightBevelColor.Apply();
			::glBegin(GL_LINE_LOOP);
			::glVertex2f(-1.0f+etchWidth, -1.0f);
			::glVertex2f(-1.0f+etchWidth, 1.0f-etchHeight-etchHeight);
			::glVertex2f(1.0f-etchWidth, 1.0f-etchHeight-etchHeight);
			::glVertex2f(1.0f-etchWidth, -1.0f);
			::glEnd();
			_darkBevelColor.Apply();
			::glBegin(GL_LINE_LOOP);
			::glVertex2f(-1.0f, -1.0f+etchHeight);
			::glVertex2f(-1.0f, 1.0f-etchHeight);
			::glVertex2f(1.0f-etchWidth-etchWidth, 1.0f-etchHeight);
			::glVertex2f(1.0f-etchWidth-etchWidth, -1.0f+etchHeight);
			::glEnd();
		}
		else if (_style == raisedStyle || _style == loweredStyle)
		{
			if (_style == raisedStyle)
			{
				_lightBevelColor.Apply();
			}
			else
			{
				_darkBevelColor.Apply();
			}
			::glBegin(GL_QUAD_STRIP);
			::glVertex2f(-1.0f, -1.0f);
			::glVertex2f(-1.0f+bevelWidth, -1.0f+bevelHeight);
			::glVertex2f(-1.0f, 1.0f);
			::glVertex2f(-1.0f+bevelWidth, 1.0f-bevelHeight);
			::glVertex2f(1.0f, 1.0f);
			::glVertex2f(1.0f-bevelWidth, 1.0f-bevelHeight);
			::glEnd();

			if (_style == raisedStyle)
			{
				_darkBevelColor.Apply();
			}
			else
			{
				_lightBevelColor.Apply();
			}
			::glBegin(GL_QUAD_STRIP);
			::glVertex2f(-1.0f, -1.0f);
			::glVertex2f(-1.0f+bevelWidth, -1.0f+bevelHeight);
			::glVertex2f(1.0f, -1.0f);
			::glVertex2f(1.0f-bevelWidth, -1.0f+bevelHeight);
			::glVertex2f(1.0f, 1.0f);
			::glVertex2f(1.0f-bevelWidth, 1.0f-bevelHeight);
			::glEnd();
		}
	}
	else
	{
		_disableOutlineColor.Apply();
		::glBegin(GL_LINE_LOOP);
		::glVertex2f(-1.0f, -1.0f);
		::glVertex2f(-1.0f, 1.0f-etchHeight);
		::glVertex2f(1.0f-etchWidth, 1.0f-etchHeight);
		::glVertex2f(1.0f-etchWidth, -1.0f);
		::glEnd();
	}
	
	// Everything else gets scissored
	GLint oldScissor[4];
	::glGetIntegerv(GL_SCISSOR_BOX, oldScissor);
	::glScissor(RootPositionX()+_inset,
		Root()->Subwindow()->Height()-Height()-RootPositionY()+_inset,
		Width()-_inset-_inset, Height()-_inset-_inset);
	
	// Highlight backing
	if (_data.SelectionLength() > 0 && HasKeyboardFocus())
	{
		_hiliteBackColor.Apply();
		float left = 0;
		float top = 0;
		float right = 0;
		float bottom = 0;
		NormalizeCoordinates(_inset-_hpos+
			_data.PixelPosOf(_font, _data.SelectionStart(), 0),
			_inset, left, top);
		NormalizeCoordinates(_inset-_hpos+
			_data.PixelPosOf(_font, _data.SelectionEnd(), 0),
			_inset+_font.Leading(), right, bottom);
		::glRectf(left, bottom, right, top);
	}
	
	// Text
	if (!IsActive())
	{
		_disableTextColor.Apply();
	}
	else if (HasKeyboardFocus())
	{
		_focusTextColor.Apply();
	}
	else
	{
		_textColor.Apply();
	}
	int startpos = 0;
	int endpos = 0;
	int pixoffset = 0;
	_data.CalcLineDrawInfo(_font, 0, _hpos, Width()-_inset-_inset,
		startpos, endpos, pixoffset);
	const char* dat = _data.data();
	while (pixoffset > _inset)
	{
		pixoffset -= ::glutBitmapWidth(_font, dat[startpos]);
		++startpos;
	}
	float x = 0;
	float y = 0;
	NormalizeCoordinates(_inset-pixoffset,
		_inset+_font.BaselinePos(), x, y);
	::glRasterPos2f(x, y);
	for (int i=startpos; i<endpos; i++)
	{
		::glutBitmapCharacter(_font, dat[i]);
	}
	
	// Insertion caret
	// Special scissoring
	if (_blink || !HasKeyboardFocus() || !IsActive())
	{
		::glScissor(RootPositionX()+_caretInset,
			Root()->Subwindow()->Height()-Height()-RootPositionY()+_caretInset,
			Width()-_caretInset-_caretInset, Height()-_caretInset-_caretInset);
		if (!IsActive())
		{
			_disableCaretColor.Apply();
		}
		else if (HasKeyboardFocus())
		{
			_focusCaretColor.Apply();
		}
		else
		{
			_caretColor.Apply();
		}
		float horiz = 0;
		float top = 0;
		float bottom = 0;
		NormalizeCoordinates(_inset-_hpos+_data.PixelPosOf(_font, _dragEnd, 0),
			_inset, horiz, top);
		NormalizeCoordinates(_inset-_hpos+_data.PixelPosOf(_font, _dragEnd, 0),
			_inset+_font.Leading(), horiz, bottom);
		float hBump = float(2)/float(Width());
		float vBump = float(2)/float(Height());
		::glBegin(GL_LINES);
		::glVertex2f(horiz, bottom);
		::glVertex2f(horiz, top-vBump);
		::glVertex2f(horiz-bevelWidth, bottom);
		::glVertex2f(horiz+bevelWidth+hBump, bottom);
		::glVertex2f(horiz-bevelWidth, top-vBump);
		::glVertex2f(horiz+bevelWidth+hBump, top-vBump);
		::glEnd();
	}
	
	// Unscissor
	::glScissor(oldScissor[0], oldScissor[1], oldScissor[2], oldScissor[3]);
	
	// Activate autoscroll timer
	if (_toggleAutoScroll)
	{
		_toggleAutoScroll = false;
		_autoScrollTimer->SetTextField(this);
		_autoScrollTimerID = Glow::RegisterTimer(_autoScrollInterval, _autoScrollTimer);
	}
}
示例#4
0
void GlowLabelWidget::OnWidgetPaint()
{
	GLOW_DEBUGSCOPE("GlowLabelWidget::OnWidgetPaint");
	
	if (opaque_)
	{
		backColor_.Apply();
		::glRectf(-1.0f, -1.0f, 1.0f, 1.0f);
	}
	
	if (IsActive())
	{
		textColor_.Apply();
	}
	else
	{
		disableTextColor_.Apply();
	}
	
	int vPos = font_.BaselinePos()+vIndent_;
	int textlen = (text_ == 0) ? 0 : GLOW_CSTD::strlen(text_);
	for (int i=-1; i<textlen; ++i)
	{
		if (i == -1 || text_[i] == '\n' ||
			(text_[i] == '\r' && i+1 < textlen && text_[i+1] != '\n'))
		{
			GLfloat x, y;
			
			// Next v position
			if (i >= 0)
			{
				vPos += font_.Leading();
			}
			
			// Set alignment raster position
			int hPos = (alignment_ == alignLeft) ? hIndent_ :
				((alignment_ == alignRight) ? Width()-hIndent_ : Width()/2);
			NormalizeCoordinates(hPos, vPos, x, y);
			::glRasterPos2f(x, y);
			
			// Now we need to align the text (if center or right).
			// This means we need to subtract the length of the line if
			// aligned right, or half the length if aligned center
			if (alignment_ != alignLeft)
			{
				// First, find the length of the line.
				int thisLineWidth = 0;
				for (int j=i+1; j<textlen && text_[j] != '\r' &&
					text_[j] != '\n'; ++j)
				{
					thisLineWidth += font_.CharWidth(text_[j]);
				}
				
				// Offset
				::glBitmap(0, 0, 0, 0, (alignment_ == alignRight) ?
					-thisLineWidth : -thisLineWidth/2, 0, 0);
			}
		}
		else
		{
			::glutBitmapCharacter(font_, text_[i]);
		}
	}
}