Пример #1
0
void IGUIScrollBar::UpdatePosBoundaries()
{
	if (m_Pos < 0.f ||
		m_ScrollRange < m_ScrollSpace) // <= scrolling not applicable
		m_Pos = 0.f;
	else
	if (m_Pos > GetMaxPos())
		m_Pos = GetMaxPos();
}
Пример #2
0
void CGUIScrollBarVertical::SetPosFromMousePos(const CPos &mouse)
{
	if (!GetStyle())
		return;

	/**
	 * Calculate the position for the top of the item being scrolled
	 */
	m_Pos = m_PosWhenPressed + GetMaxPos() * (mouse.y - m_BarPressedAtPos.y) / (m_Length - GetStyle()->m_Width * 2 - m_BarSize);
}
Пример #3
0
void InsertItem(int o,int L,int R,int u,int v,long long a,long long b)
{
    if ((u<=L)&&(R<=v))
    if (!Tree[o].has_item)
    {
        Tree[o].has_item=true;
        Tree[o].a1=a+(long long)(L-u)*b;Tree[o].b1=b;
        return;
    }
    else
    {
        long long new_max,old_max;
        new_max=(long long)(R-u)*b+a;
        old_max=(long long)(R-L)*Tree[o].b1+Tree[o].a1;
        if (Tree[o].a1>=a+(long long)(L-u)*b)
        {
            if (old_max>=new_max) return;
            int new_u=GetMaxPos(L,R,Tree[o].a1,Tree[o].b1,a+(long long)(L-u)*b,b,0)+1;
            a=(long long)(new_u-u)*b+a;
            u=new_u;
        } else
        if (old_max>=new_max)
        {
            v=GetMaxPos(L,R,Tree[o].a1,Tree[o].b1,a+(long long)(L-u)*b,b,1);
        } else
        {
            Tree[o].a1=a+(long long)(L-u)*b;
            Tree[o].b1=b;
            return;
        }
    }
    int mid=(L+R)/2;
    if (u<=mid)
    {
        if (Tree[o].left==0) Tree[o].left=CreateNewNode();
        InsertItem(Tree[o].left,L,mid,u,v,a,b);
    }
    if (v>mid)
    {
        if (Tree[o].right==0) Tree[o].right=CreateNewNode();
        InsertItem(Tree[o].right,mid+1,R,u,v,a,b);
    }
}
Пример #4
0
UInt32 TextInputMenu::SeekPosition(UInt32 fromPos, bool bBackwards, bool bSeekWordStart) const
{
	if ((fromPos <= GetMinPos() && bBackwards) || (fromPos > GetMaxPos() && !bBackwards))
		return fromPos;						//bounds check

	char curChar = bBackwards ? m_inputText[fromPos - 1] : m_inputText[fromPos];
	if (bSeekWordStart || curChar == '<' || curChar == '>')
		return FindWordBoundary(fromPos, bBackwards);

	return fromPos + (bBackwards ? -1 : 1);
}
Пример #5
0
void CGUIScrollBarVertical::SetPosFromMousePos(const CPos& mouse)
{
	if (!GetStyle())
		return;

	/**
	 * Calculate the position for the top of the item being scrolled
	 */
	float emptyBackground = m_Length - m_BarSize;
	if (GetStyle()->m_UseEdgeButtons)
		emptyBackground -= GetStyle()->m_Width * 2;
	m_Pos = m_PosWhenPressed + GetMaxPos() * (mouse.y - m_BarPressedAtPos.y) / emptyBackground;
}
Пример #6
0
//returns -1 if code not handled, otherwise returns new insertion pos
UInt32 TextInputJournal::ResolveControlCode(UInt8 controlCode, UInt32 insertPos)
{
	if (IsFull())
		return -1;

	UInt32 newPos = insertPos;

	switch (controlCode)
	{
	case DIK_RETURN: //line break
		newPos = InsertText(insertPos, kTagStrings[kHTMLTag_BR].c_str());
		break;
	case DIK_UP:	//move to end of previous line
		newPos = FindLineStart(insertPos);
		if (newPos > GetMinPos())
			newPos = SeekPosition(newPos, true, true);

		break;
	case DIK_DOWN:	//move to start of next line
		newPos = FindLineEnd(insertPos);
		if (newPos <= GetMaxPos())
			newPos = SeekPosition(newPos, false, true);

		break;
	case DIK_C:		//align center
		newPos = SetLineStartingTag(insertPos, kHTMLTag_DIV_Center);
		break;
	case DIK_L:		//align left
		newPos = SetLineStartingTag(insertPos, kHTMLTag_DIV_Left);
		break;
	case DIK_R:		//align right
		newPos = SetLineStartingTag(insertPos, kHTMLTag_DIV_Right);
		break;
	case DIK_1:
	case DIK_2:
	case DIK_3:
	case DIK_4:
	case DIK_5:		//Change font
		{
			char fontNum = controlCode - DIK_1 + '1';
			m_inputText[12] = fontNum;
			break;
		}
	default:
		newPos = -1;
	}

	return newPos;
}
Пример #7
0
UInt32 TextInputMenu::FindLineEnd(UInt32 fromPos) const
{
	if (fromPos >= GetMaxPos())
		return GetInputLength();

	UInt32 lBracPos = fromPos;
	while ( (lBracPos = m_inputText.find('<', lBracPos)) != std::string::npos )
	{
		if (GetHTMLTagType(lBracPos) != kHTMLTag_Other)
			return lBracPos;

		lBracPos++;
	}

	return GetInputLength();
}
Пример #8
0
UInt32 TextInputMenu::FindHTMLMatchedBracket(UInt32 startBracketPos, bool bBackwards) const
{
	UInt32 endBracketPos;

	if (bBackwards)
	{
		endBracketPos = m_inputText.rfind('<', startBracketPos);
		if (endBracketPos == std::string::npos)
			endBracketPos = m_minPos;
	}
	else
	{
		endBracketPos = m_inputText.find('>', startBracketPos);
		if (endBracketPos == std::string::npos)
			endBracketPos = GetMaxPos();
	}

	return endBracketPos;
}
Пример #9
0
CRect CGUIScrollBarVertical::GetBarRect() const
{
	CRect ret;
	if (!GetStyle())
		return ret;

	// Get from where the scroll area begins to where it ends
	float from = m_Y;
	float to = m_Y + m_Length - m_BarSize;

	if (GetStyle()->m_UseEdgeButtons)
	{
		from += GetStyle()->m_Width;
		to -= GetStyle()->m_Width;
	}

	// Setup rectangle
	ret.top = from + (to - from) * (m_Pos / GetMaxPos());
	ret.bottom = ret.top + m_BarSize;
	ret.right = m_X + ((m_RightAligned)?(0.f):(GetStyle()->m_Width));
	ret.left = ret.right - GetStyle()->m_Width;

	return ret;
}
Пример #10
0
void CGUIScrollBarVertical::Draw()
{
	if (!GetStyle())
	{
		LOGWARNING(L"Attempt to draw scrollbar without a style.");
		return;
	}

	// Only draw the scrollbar if the GUI exists and there is something to scroll.
	if (GetGUI() && GetMaxPos() != 1)
	{
		CRect outline = GetOuterRect();

		// Draw background
		GetGUI()->DrawSprite(GetStyle()->m_SpriteBackVertical,
							 0,
							 m_Z+0.1f, 
							 CRect(outline.left,
								   outline.top+(m_UseEdgeButtons?GetStyle()->m_Width:0),
								   outline.right,
								   outline.bottom-(m_UseEdgeButtons?GetStyle()->m_Width:0))
							 );

		if (m_UseEdgeButtons)
		{
			// Get Appropriate sprites
			const CGUISpriteInstance *button_top, *button_bottom;

			// figure out what sprite to use for top button
			if (m_ButtonMinusHovered)
			{
				if (m_ButtonMinusPressed)
					button_top = &GUI<>::FallBackSprite(GetStyle()->m_SpriteButtonTopPressed, GetStyle()->m_SpriteButtonTop);
				else
					button_top = &GUI<>::FallBackSprite(GetStyle()->m_SpriteButtonTopOver, GetStyle()->m_SpriteButtonTop);
			}
			else button_top = &GetStyle()->m_SpriteButtonTop;

			// figure out what sprite to use for bottom button
			if (m_ButtonPlusHovered)
			{
				if (m_ButtonPlusPressed)
					button_bottom = &GUI<>::FallBackSprite(GetStyle()->m_SpriteButtonBottomPressed, GetStyle()->m_SpriteButtonBottom);
				else
					button_bottom = &GUI<>::FallBackSprite(GetStyle()->m_SpriteButtonBottomOver, GetStyle()->m_SpriteButtonBottom);
			}
			else button_bottom = &GetStyle()->m_SpriteButtonBottom;
			
			// Draw top button
			GetGUI()->DrawSprite(*button_top,
								 0,
								 m_Z+0.2f,
								 CRect(outline.left,
									   outline.top,
									   outline.right,
									   outline.top+GetStyle()->m_Width)
								);
			
			// Draw bottom button
			GetGUI()->DrawSprite(*button_bottom,
								 0,
								 m_Z+0.2f,
								 CRect(outline.left,
									   outline.bottom-GetStyle()->m_Width,
									   outline.right,
									   outline.bottom)
								);
		}

		// Draw bar
		GetGUI()->DrawSprite(GetStyle()->m_SpriteBarVertical,
							 0,
							 m_Z + 0.2f,
							 GetBarRect());
	}
}