Esempio n. 1
0
//! draws the element and its children
void CGUIFileOpenDialog::draw()
{
	if (!IsVisible)
		return;

	IGUISkin* skin = Environment->getSkin();

	core::rect<s32> rect = AbsoluteRect;

	rect = skin->draw3DWindowBackground(this, true, skin->getColor(EGDC_ACTIVE_BORDER),
		rect, &AbsoluteClippingRect);

	if (Text.size())
	{
		rect.UpperLeftCorner.X += 2;
		rect.LowerRightCorner.X -= skin->getSize(EGDS_WINDOW_BUTTON_WIDTH) + 5;

		IGUIFont* font = skin->getFont(EGDF_WINDOW);
		if (font)
			font->draw(Text.c_str(), rect,
					skin->getColor(EGDC_ACTIVE_CAPTION),
					false, true, &AbsoluteClippingRect);
	}

	IGUIElement::draw();
}
Esempio n. 2
0
//! draws the element and its children
void CGUIWindow::draw()
{
	if ( IsVisible )
	{
		IGUISkin* skin = Environment->getSkin();

		core::rect<s32> rect = AbsoluteRect;

		// draw body fast
        if ( DrawBackground )
        {
            rect = skin->draw3DWindowBackground(this, DrawTitlebar, skin->getColor(EGDC_ACTIVE_BORDER),
                AbsoluteRect, &AbsoluteClippingRect);

            if (DrawTitlebar && Text.size())
            {
                rect.UpperLeftCorner.X += skin->getSize(EGDS_TEXT_DISTANCE_X);
                rect.UpperLeftCorner.Y += skin->getSize(EGDS_TEXT_DISTANCE_Y);
                rect.LowerRightCorner.X -= skin->getSize(EGDS_WINDOW_BUTTON_WIDTH) + 5;

                IGUIFont* font = skin->getFont(EGDF_WINDOW);
                if (font)
                {
                    font->draw(Text.c_str(), rect,
                        skin->getColor(EGDC_ACTIVE_CAPTION), false, true, &AbsoluteClippingRect);
                }
            }
        }
	}

	IGUIElement::draw();
}
Esempio n. 3
0
void CGUITabControl::selectTab(core::position2d<s32> p)
{
	IGUISkin* skin = Environment->getSkin();
	IGUIFont* font = skin->getFont();

	core::rect<s32> frameRect(AbsoluteRect);

	s32 tabheight = skin->getSize(gui::EGDS_BUTTON_HEIGHT);
	frameRect.UpperLeftCorner.Y += 2;
	frameRect.LowerRightCorner.Y = frameRect.UpperLeftCorner.Y + tabheight;
	s32 pos = frameRect.UpperLeftCorner.X + 2;

	for (u32 i=0; i<Tabs.size(); ++i)
	{
		// get Text
		const wchar_t* text = 0;
		if (Tabs[i])
			text = Tabs[i]->getText();

		// get text length
		s32 len = 20;
		if (font)
			len += font->getDimension(text).Width;

		frameRect.UpperLeftCorner.X = pos;
		frameRect.LowerRightCorner.X = frameRect.UpperLeftCorner.X + len;
		pos += len;

		if (frameRect.isPointInside(p))
		{
			setActiveTab(i);
			return;
		}
	}
}
Esempio n. 4
0
s32 StaticText::getTextWidth() const
{
	IGUIFont * font = getActiveFont();
	if(!font)
		return 0;

	if(WordWrap)
	{
		s32 widest = 0;

		for(u32 line = 0; line < BrokenText.size(); ++line)
		{
			s32 width = font->getDimension(BrokenText[line].c_str()).Width;

			if(width > widest)
				widest = width;
		}

		return widest;
	}
	else
	{
		return font->getDimension(cText.c_str()).Width;
	}
}
void CGUITextureCacheBrowser::draw()
{
	if (!IsVisible)
		return;

	IGUISkin* skin = Environment->getSkin();

	core::rect<s32> rect = AbsoluteRect;
	core::rect<s32> *cl = &AbsoluteClippingRect;

	// draw body fast
	rect = skin->draw3DWindowBackground(this, true, skin->getColor(EGDC_ACTIVE_BORDER),
		AbsoluteRect, &AbsoluteClippingRect);

	// draw window text
	if (Text.size())
	{
		rect.UpperLeftCorner.X += skin->getSize(EGDS_TEXT_DISTANCE_X);
		rect.UpperLeftCorner.Y += skin->getSize(EGDS_TEXT_DISTANCE_Y);
		rect.LowerRightCorner.X -= skin->getSize(EGDS_WINDOW_BUTTON_WIDTH) + 5;

		IGUIFont* font = skin->getFont();
		if (font)
			font->draw(Text.c_str(), rect, skin->getColor(EGDC_ACTIVE_CAPTION), false, true, cl);
	}

	IGUIElement::draw();
}
Esempio n. 6
0
s32 CGUIStaticText::getTextWidth() const
{
	IGUIFont * font = OverrideFont;

	if(!OverrideFont)
	{
		IGUISkin * skin = Environment->getSkin();
		if(skin)
			font = skin->getFont();
	}

	if(!font)
		return 0;

	if(WordWrap)
	{
		s32 widest = 0;

		for(u32 line = 0; line < BrokenText.size(); ++line)
		{
			s32 width = font->getDimension(BrokenText[line].c_str()).Width;

			if(width > widest)
				widest = width;
		}

		return widest;
	}
	else
	{
		return font->getDimension(Text.c_str()).Width;
	}
}
Esempio n. 7
0
bool CGUIEditBox::processIMEEvent(const SEvent& event)
{
    switch(event.InputMethodEvent.Event)
    {
    case EIME_CHAR_INPUT:
        inputChar(event.InputMethodEvent.Char);
        return true;
    case EIME_CHANGE_POS:
    {
        core::position2di pos = calculateICPos();

        IGUIFont* font = OverrideFont;
        IGUISkin* skin = Environment->getSkin();

        if (!OverrideFont)
            font = skin->getFont();

        irr::updateICPos(event.InputMethodEvent.Handle, pos.X,pos.Y, font->getDimension(L"|").Height);

        return true;
    }
    default:
        break;
    }

    return false;
}
Esempio n. 8
0
void CGUIContextMenu::recalculateSize()
{
	IGUISkin* skin = Environment->getSkin();
	IGUIFont* font = skin->getFont(EGDF_MENU);

	if (!font)
		return;

	core::rect<s32> rect;
	rect.UpperLeftCorner = RelativeRect.UpperLeftCorner;
	s32 width = 100;
	s32 height = 3;

	u32 i;
	for (i=0; i<Items.size(); ++i)
	{
		if (Items[i].IsSeparator)
		{
			Items[i].Dim.Width = 100;
			Items[i].Dim.Height = 10;
		}
		else
		{
			Items[i].Dim = font->getDimension(Items[i].Text.c_str());
			Items[i].Dim.Width += 40;

			if (Items[i].Dim.Width > width)
				width = Items[i].Dim.Width;
		}

		Items[i].PosY = height;
		height += Items[i].Dim.Height;
	}

	height += 5;

	if (height < 10)
		height = 10;

	rect.LowerRightCorner.X = RelativeRect.UpperLeftCorner.X + width;
	rect.LowerRightCorner.Y = RelativeRect.UpperLeftCorner.Y + height;

	setRelativePosition(rect);

	// recalculate submenus
	for (i=0; i<Items.size(); ++i)
	{
		if (Items[i].SubMenu)
		{
			// move submenu
			const s32 w = Items[i].SubMenu->getAbsolutePosition().getWidth();
			const s32 h = Items[i].SubMenu->getAbsolutePosition().getHeight();

			Items[i].SubMenu->setRelativePosition(
				core::rect<s32>(width-5, Items[i].PosY,
					width+w-5, Items[i].PosY+h));
		}
	}
}
Esempio n. 9
0
//! draws the element and its children
void CGUIMenu::draw()
{
	if (!IsVisible)
		return;

	IGUISkin* skin = Environment->getSkin();
	IGUIFont* font = skin->getFont(EGDF_MENU);
	
	if (font != LastFont)
	{
		if (LastFont)
			LastFont->drop();
		LastFont = font;
		if (LastFont)
			LastFont->grab();

		recalculateSize();
	}

	core::rect<s32> rect = AbsoluteRect;

	// draw frame

	skin->draw3DToolBar(this, rect, &AbsoluteClippingRect);

	// loop through all menu items

	rect = AbsoluteRect;

	for (s32 i=0; i<(s32)Items.size(); ++i)
	{
		if (!Items[i].IsSeparator)
		{
			rect = getRect(Items[i], AbsoluteRect);

			// draw highlighted
			if (i == HighLighted && Items[i].Enabled)
			{
				skin->draw3DSunkenPane(this, skin->getColor(EGDC_3D_DARK_SHADOW),
					true, true, rect, &AbsoluteClippingRect);
			}
			// draw text

			EGUI_DEFAULT_COLOR c = EGDC_BUTTON_TEXT;

			if (i == HighLighted)
				c = EGDC_HIGH_LIGHT_TEXT;

			if (!Items[i].Enabled)
				c = EGDC_GRAY_TEXT;

			if (font)
				font->draw(Items[i].Text.c_str(), rect, 
					skin->getColor(c), true, true, &AbsoluteClippingRect);
		}
	}

	IGUIElement::draw();
}
Esempio n. 10
0
void CGUIEditBox::calculateScrollPos()
{
#ifndef SERVER_ONLY
    if (!AutoScroll)
        return;

    // calculate horizontal scroll position
    s32 cursLine = getLineFromPos(CursorPos);
    setTextRect(cursLine);

    // don't do horizontal scrolling when wordwrap is enabled.
    if (!WordWrap)
    {
        // get cursor position
        IGUISkin* skin = Environment->getSkin();
        if (!skin)
            return;
        IGUIFont* font = OverrideFont ? OverrideFont : skin->getFont();
        if (!font)
            return;

        core::stringw *txtLine = MultiLine ? &BrokenText[cursLine] : &Text;
        s32 cPos = MultiLine ? CursorPos - BrokenTextPositions[cursLine] : CursorPos;

        s32 cStart = CurrentTextRect.UpperLeftCorner.X + HScrollPos +
            font->getDimension(txtLine->subString(0, cPos).c_str()).Width;

        s32 cEnd = cStart + font->getDimension(L"_ ").Width;

        if (FrameRect.LowerRightCorner.X < cEnd)
            HScrollPos = cEnd - FrameRect.LowerRightCorner.X;
        else if (FrameRect.UpperLeftCorner.X > cStart)
            HScrollPos = cStart - FrameRect.UpperLeftCorner.X;
        else
            HScrollPos = 0;

        // todo: adjust scrollbar
    }

    // vertical scroll position
    if (FrameRect.LowerRightCorner.Y < CurrentTextRect.LowerRightCorner.Y + VScrollPos)
        VScrollPos = CurrentTextRect.LowerRightCorner.Y - FrameRect.LowerRightCorner.Y + VScrollPos;

    else if (FrameRect.UpperLeftCorner.Y > CurrentTextRect.UpperLeftCorner.Y + VScrollPos)
        VScrollPos = CurrentTextRect.UpperLeftCorner.Y - FrameRect.UpperLeftCorner.Y + VScrollPos;
    else
        VScrollPos = 0;

    // todo: adjust scrollbar
#if defined(_IRR_COMPILE_WITH_X11_DEVICE_)
    CIrrDeviceLinux* dl = dynamic_cast<CIrrDeviceLinux*>(irr_driver->getDevice());
    if (dl)
    {
        dl->setIMELocation(calculateICPos());
    }
#endif
#endif   // SERVER_ONLY
}
Esempio n. 11
0
	void Java_zte_irrlib_scene_Scene_nativeDrawText(
		JNIEnv *env, jobject defaultObj,jstring text, jint left, jint up, jint r, jint g, jint b, jint a)
	{
		IGUIFont* font = device->getGUIEnvironment()->getFont(_builtInFontPath);
		if (!font){
			LOGE("Font not found.");
			return;
		}
		const char *msg = env->GetStringUTFChars(text,0);
		font->draw(msg, rect<s32>(left,up,left+100,up+100), SColor(a,r,g,b));
		env->ReleaseStringUTFChars(text, msg);
	}
Esempio n. 12
0
	//! Adds a button to the tool bar
	IGUIButton* CGUIToolBar::addButton(SINT32 id, const wchar_t* text, const wchar_t* tooltiptext,
		ITexture* img, ITexture* pressed, bool isPushButton,
		bool useAlphaChannel)
	{
		ButtonX += 3;

		rect<SINT32> rectangle(ButtonX, 2, ButtonX + 1, 3);
		if (img)
		{
			const dimension2du &size = img->getOriginalSize();
			rectangle.LowerRightCorner.x = rectangle.UpperLeftCorner.x + size.Width + 8;
			rectangle.LowerRightCorner.y = rectangle.UpperLeftCorner.y + size.Height + 6;
		}

		if (text)
		{
			IGUISkin* skin = Environment->getSkin();
			IGUIFont * font = skin->getFont(EGDF_BUTTON);
			if (font)
			{
				dimension2d<UINT32> dim = font->getDimension(text);
				if ((SINT32)dim.Width > rectangle.getWidth())
					rectangle.LowerRightCorner.x = rectangle.UpperLeftCorner.x + dim.Width + 8;
				if ((SINT32)dim.Height > rectangle.getHeight())
					rectangle.LowerRightCorner.y = rectangle.UpperLeftCorner.y + dim.Height + 6;
			}
		}

		ButtonX += rectangle.getWidth();

		IGUIButton* button = new CGUIButton(Environment, this, id, rectangle);
		button->drop();

		if (text)
			button->setText(text);

		if (tooltiptext)
			button->setToolTipText(tooltiptext);

		if (img)
			button->setImage(img);

		if (pressed)
			button->setPressedImage(pressed);

		if (isPushButton)
			button->setIsPushButton(isPushButton);

		if (useAlphaChannel)
			button->setUseAlphaChannel(useAlphaChannel);

		return button;
	}
Esempio n. 13
0
//! Returns the height of the text in pixels when it is drawn.
s32 StaticText::getTextHeight() const
{
	IGUIFont* font = getActiveFont();
	if (!font)
		return 0;

	s32 height = font->getDimension(L"A").Height + font->getKerningHeight();

	if (WordWrap)
		height *= BrokenText.size();

	return height;
}
Esempio n. 14
0
bool CGUITabControl::needScrollControl(s32 startIndex, bool withScrollControl)
{
	if ( startIndex >= (s32)Tabs.size() )
		startIndex -= 1;

	if ( startIndex < 0 )
		startIndex = 0;

	IGUISkin* skin = Environment->getSkin();
	if (!skin)
		return false;

	IGUIFont* font = skin->getFont();

	core::rect<s32> frameRect(AbsoluteRect);

	if (Tabs.empty())
		return false;

	if (!font)
		return false;

	s32 pos = frameRect.UpperLeftCorner.X + 2;

	for (s32 i=startIndex; i<(s32)Tabs.size(); ++i)
	{
		// get Text
		const wchar_t* text = 0;
		if (Tabs[i])
			text = Tabs[i]->getText();

		// get text length
		s32 len = font->getDimension(text).Width + TabExtraWidth;

		frameRect.LowerRightCorner.X += len;

		frameRect.UpperLeftCorner.X = pos;
		frameRect.LowerRightCorner.X = frameRect.UpperLeftCorner.X + len;
		pos += len;

		if ( withScrollControl && pos > AbsoluteRect.LowerRightCorner.X - TabMaxWidth)
			return true;

		if ( !withScrollControl && pos > AbsoluteRect.LowerRightCorner.X )
			return true;
	}

	return false;
}
Esempio n. 15
0
void CGUIComboBox::openCloseMenu()
{
	if (ListBox)
	{
		// close list box
		Environment->setFocus(this);
		ListBox->remove();
		ListBox = 0;
	}
	else
	{
		if (Parent)
			Parent->bringToFront(this);

		IGUISkin* skin = Environment->getSkin();
		s32 h = Items.size();

		if (h > 5)
			h = 5;
		if (h == 0)
			h = 1;

		IGUIFont* font = skin->getFont();
		if (font)
			h *= (font->getDimension(L"A").Height + 4);

		// open list box
		core::rect<s32> r(0, AbsoluteRect.getHeight(),
			AbsoluteRect.getWidth(), AbsoluteRect.getHeight() + h);

		ListBox = new CGUIListBox(Environment, this, -1, r, false, true, true);
		ListBox->setSubElement(true);
		ListBox->setNotClipped(true);
		ListBox->drop();

		// ensure that list box is always completely visible
		if (ListBox->getAbsolutePosition().LowerRightCorner.Y > Environment->getRootGUIElement()->getAbsolutePosition().getHeight())
			ListBox->setRelativePosition( core::rect<s32>(0, -ListBox->getAbsolutePosition().getHeight(), AbsoluteRect.getWidth(), 0) );

		for (s32 i=0; i<(s32)Items.size(); ++i)
			ListBox->addItem(Items[i].Name.c_str());

		ListBox->setSelected(Selected);

		// set focus
		Environment->setFocus(ListBox);
	}
}
Esempio n. 16
0
bool CGUITabControl::selectTab(core::position2d<s32> p)
{
	IGUISkin* skin = Environment->getSkin();
	IGUIFont* font = skin->getFont();

	core::rect<s32> frameRect(AbsoluteRect);

	if ( VerticalAlignment == EGUIA_UPPERLEFT )
	{
		frameRect.UpperLeftCorner.Y += 2;
		frameRect.LowerRightCorner.Y = frameRect.UpperLeftCorner.Y + TabHeight;
	}
	else
	{
		frameRect.UpperLeftCorner.Y = frameRect.LowerRightCorner.Y - TabHeight;
	}

	s32 pos = frameRect.UpperLeftCorner.X + 2;

	if (!frameRect.isPointInside(p))
		return false;

	for (s32 i=CurrentScrollTabIndex; i<(s32)Tabs.size(); ++i)
	{
		// get Text
		const wchar_t* text = 0;
		if (Tabs[i])
			text = Tabs[i]->getText();

		// get text length
		s32 len = font->getDimension(text).Width + TabExtraWidth;
		frameRect.UpperLeftCorner.X = pos;
		frameRect.LowerRightCorner.X = frameRect.UpperLeftCorner.X + len;

		if ( ScrollControl && pos > AbsoluteRect.LowerRightCorner.X)
			return false;

		pos += len;

		if (frameRect.isPointInside(p))
		{
			setActiveTab(i);
			return true;
		}
	}
	return false;
}
Esempio n. 17
0
//! draws the element and its children
void CGUICheckBox::draw()
{
	if (!IsVisible)
		return;

	IGUISkin* skin = Environment->getSkin();
	if (skin)
	{
		const core::rect<s32> rect = AbsoluteRect;
		const s32 height = skin->getSize(EGDS_CHECK_BOX_WIDTH);

		core::rect<s32> checkRect(AbsoluteRect.UpperLeftCorner.X,
					((AbsoluteRect.getHeight() - height) / 2) + AbsoluteRect.UpperLeftCorner.Y,
					0, 0);

		checkRect.LowerRightCorner.X = checkRect.UpperLeftCorner.X + height;
		checkRect.LowerRightCorner.Y = checkRect.UpperLeftCorner.Y + height;

		EGUI_DEFAULT_COLOR col = EGDC_GRAY_EDITABLE;
		if ( isEnabled() )
			col = Pressed ? EGDC_FOCUSED_EDITABLE : EGDC_EDITABLE;
		skin->draw3DSunkenPane(this, skin->getColor(col),
			false, true, checkRect, &AbsoluteClippingRect);

		if (Checked)
		{
			skin->drawIcon(this, EGDI_CHECK_BOX_CHECKED, checkRect.getCenter(),
				checkTime, os::Timer::getTime(), false, &AbsoluteClippingRect);
		}
		if (Text.size())
		{
			checkRect = AbsoluteRect;
			checkRect.UpperLeftCorner.X += height + 5;

			IGUIFont* font = skin->getFont();
			if (font)
			{
				font->draw(Text.c_str(), checkRect,
						skin->getColor(isEnabled() ? EGDC_BUTTON_TEXT : EGDC_GRAY_TEXT), false, true, &AbsoluteClippingRect);
			}
		}
	}
	IGUIElement::draw();
}
Esempio n. 18
0
void CGUIComboBox::openCloseMenu()
{
	if (ListBox)
	{
		// close list box
		Environment->setFocus(this);
		ListBox->remove();
		ListBox = 0;
	}
	else
	{
		if (Parent)
			Parent->bringToFront(this);

		IGUISkin* skin = Environment->getSkin();		
		s32 h = Items.size();

		if (h > 5)
			h = 5;
		if (h == 0)
			h = 1;

		IGUIFont* font = skin->getFont();
		if (font)
			h *= (font->getDimension(L"A").Height + 4);

		// open list box
		core::rect<s32> r(0, AbsoluteRect.getHeight(),
			AbsoluteRect.getWidth(), AbsoluteRect.getHeight() + h);

		ListBox = new CGUIListBox(Environment, this, -1, r, false, true, true);
		ListBox->setSubElement(true);
		ListBox->drop();

		for (s32 i=0; i<(s32)Items.size(); ++i)
			ListBox->addItem(Items[i].c_str());

		ListBox->setSelected(Selected);

		// set focus
		Environment->setFocus(ListBox);
	}
}
Esempio n. 19
0
s32 CGUIEditBox::getCursorPos(s32 x, s32 y)
{
    IGUIFont* font = OverrideFont;
    IGUISkin* skin = Environment->getSkin();
    if (!OverrideFont)
        font = skin->getFont();

    const u32 lineCount = (WordWrap || MultiLine) ? BrokenText.size() : 1;

    core::stringw *txtLine=0;
    s32 startPos=0;
    x+=3;

    for (u32 i=0; i < lineCount; ++i)
    {
        setTextRect(i);
        if (i == 0 && y < CurrentTextRect.UpperLeftCorner.Y)
            y = CurrentTextRect.UpperLeftCorner.Y;
        if (i == lineCount - 1 && y > CurrentTextRect.LowerRightCorner.Y )
            y = CurrentTextRect.LowerRightCorner.Y;

        // is it inside this region?
        if (y >= CurrentTextRect.UpperLeftCorner.Y && y <= CurrentTextRect.LowerRightCorner.Y)
        {
            // we've found the clicked line
            txtLine = (WordWrap || MultiLine) ? &BrokenText[i] : &Text;
            startPos = (WordWrap || MultiLine) ? BrokenTextPositions[i] : 0;
            break;
        }
    }

    if (x < CurrentTextRect.UpperLeftCorner.X)
        x = CurrentTextRect.UpperLeftCorner.X;

    s32 idx = txtLine ? font->getCharacterFromPos(txtLine->c_str(), x - CurrentTextRect.UpperLeftCorner.X) : -1;

    // click was on or left of the line
    if (idx != -1)
        return idx + startPos;

    // click was off the right edge of the line, go to end.
    return txtLine->size() + startPos;
}
Esempio n. 20
0
//! draws the element and its children
void CGUIComboBox::draw()
{
	if (!IsVisible)
		return;

	IGUISkin* skin = Environment->getSkin();
	IGUIElement *currentFocus = Environment->getFocus();
	if (currentFocus != LastFocus)
	{
		HasFocus = currentFocus == this || isMyChild(currentFocus);
		LastFocus = currentFocus;
	}

	core::rect<s32> frameRect(AbsoluteRect);

	// draw the border

	skin->draw3DSunkenPane(this, skin->getColor(EGDC_3D_HIGH_LIGHT),
		true, true, frameRect, &AbsoluteClippingRect);

	// Draw text

	if (Selected != -1)
	{
		frameRect = AbsoluteRect;
		frameRect.UpperLeftCorner.X += 2;
		frameRect.UpperLeftCorner.Y += 2;
		frameRect.LowerRightCorner.X -= ListButton->getAbsolutePosition().getWidth() + 2;
		frameRect.LowerRightCorner.Y -= 2;
		if (HasFocus)
			skin->draw2DRectangle(this, skin->getColor(EGDC_HIGH_LIGHT), frameRect, &AbsoluteClippingRect);

		IGUIFont* font = skin->getFont();
		if (font)
			font->draw(Items[Selected].c_str(), frameRect, 
				skin->getColor(HasFocus ? EGDC_HIGH_LIGHT_TEXT : EGDC_BUTTON_TEXT),
				false, true, &AbsoluteClippingRect);
	}

	// draw buttons
	IGUIElement::draw();
}
Esempio n. 21
0
//! draws the element and its children
void CGUIWindow::draw()
{
    if (IsVisible)
    {
        IGUISkin* skin = Environment->getSkin();


        // update each time because the skin is allowed to change this always.
        updateClientRect();

        if ( CurrentIconColor != skin->getColor(EGDC_WINDOW_SYMBOL) )
            refreshSprites();

        core::rect<s32> rect = AbsoluteRect;

        // draw body fast
        if (DrawBackground)
        {
            rect = skin->draw3DWindowBackground(this, DrawTitlebar,
                                                skin->getColor(IsActive ? EGDC_ACTIVE_BORDER : EGDC_INACTIVE_BORDER),
                                                AbsoluteRect, &AbsoluteClippingRect);

            if (DrawTitlebar && Text.size())
            {
                rect.UpperLeftCorner.X += skin->getSize(EGDS_TITLEBARTEXT_DISTANCE_X);
                rect.UpperLeftCorner.Y += skin->getSize(EGDS_TITLEBARTEXT_DISTANCE_Y);
                rect.LowerRightCorner.X -= skin->getSize(EGDS_WINDOW_BUTTON_WIDTH) + 5;

                IGUIFont* font = skin->getFont(EGDF_WINDOW);
                if (font)
                {
                    font->draw(Text.c_str(), rect,
                               skin->getColor(IsActive ? EGDC_ACTIVE_CAPTION:EGDC_INACTIVE_CAPTION),
                               false, true, &AbsoluteClippingRect);
                }
            }
        }
    }

    IGUIElement::draw();
}
Esempio n. 22
0
//! Returns the height of the text in pixels when it is drawn.
s32 CGUIStaticText::getTextHeight()
{
	IGUISkin* skin = Environment->getSkin();

	if (!skin)
		return 0;

	IGUIFont* font = OverrideFont;
	if (!OverrideFont)
		font = skin->getFont();

	if (!font)
		return 0;

	s32 height = font->getDimension(L"A").Height;

	if (WordWrap)
		height *= BrokenText.size();

	return height;
}
Esempio n. 23
0
//! draws the element and its children
void CGUIColorSelectDialog::draw()
{
	if (!IsVisible)
		return;

	IGUISkin* skin = Environment->getSkin();
	core::rect<s32> rect = skin->draw3DWindowBackground(this, true, skin->getColor(EGDC_ACTIVE_BORDER),
		AbsoluteRect, &AbsoluteClippingRect);

	if (Text.size())
	{
		rect.UpperLeftCorner.X += 2;
		rect.LowerRightCorner.X -= skin->getSize(EGDS_WINDOW_BUTTON_WIDTH) + 5;

		IGUIFont* font = skin->getFont(EGDF_WINDOW);
		if (font)
			font->draw(Text.c_str(), rect, skin->getColor(EGDC_ACTIVE_CAPTION), false, true,
			&AbsoluteClippingRect);
	}

	IGUIElement::draw();

	// draw color selector after the window elements
	core::vector2di pos(ColorRing.Control->getAbsolutePosition().UpperLeftCorner);
	pos.X += ColorRing.Texture->getOriginalSize().Width/2;
	pos.Y += ColorRing.Texture->getOriginalSize().Height/2;
#if 0
	const f32 h = Battery[4]->getValue();
	const f32 s = Battery[5]->getValue();
	const f32 l = Battery[6]->getValue();
	const f32 factor = 58.f*(((s==0)&&(l<50))?(l*0.33f/50):(
		(s<100)?((.33f+(s*0.33f/100))):((0.66f+(l-50)*0.33f/50))));

#else
	const f32 factor = 44;
#endif
	pos.X += core::round32(sinf(Battery[4]->getValue()*core::DEGTORAD)*factor);
	pos.Y -= core::round32(cosf(Battery[4]->getValue()*core::DEGTORAD)*factor);
	Environment->getVideoDriver()->draw2DPolygon(pos, 4, 0xffffffff, 4);
}
Esempio n. 24
0
//! draws the element and its children
void CGUICheckBox::draw()
{
	if (!IsVisible)
		return;

	IGUISkin* skin = Environment->getSkin();

	core::rect<s32> rect = AbsoluteRect;

	s32 height = skin->getSize(EGDS_CHECK_BOX_WIDTH);

	core::rect<s32> checkRect(AbsoluteRect.UpperLeftCorner.X,
				((AbsoluteRect.getHeight() - height) / 2) + AbsoluteRect.UpperLeftCorner.Y,
				0, 0);

	checkRect.LowerRightCorner.X = checkRect.UpperLeftCorner.X + height;
	checkRect.LowerRightCorner.Y = checkRect.UpperLeftCorner.Y + height;

	skin->draw3DSunkenPane(this, skin->getColor(Pressed || !IsEnabled ? EGDC_3D_FACE : EGDC_ACTIVE_CAPTION),
		false, true, checkRect, &AbsoluteClippingRect);

	if (Checked && Environment->getSkin())
		Environment->getSkin()->drawIcon(this, EGDI_CHECK_BOX_CHECKED, checkRect.getCenter(),
			checkTime, os::Timer::getTime(), false, &AbsoluteClippingRect);

	if (Text.size())
	{
		checkRect = AbsoluteRect;
		checkRect.UpperLeftCorner.X += height + 5;

		IGUIFont* font = skin->getFont();
		if (font)
			font->draw(Text.c_str(), checkRect,
					skin->getColor(IsEnabled ? EGDC_BUTTON_TEXT : EGDC_GRAY_TEXT), false, true, &AbsoluteClippingRect);
	}

	IGUIElement::draw();
}
Esempio n. 25
0
//! calculate the position of input composition window
core::position2di CGUIEditBox::calculateICPos()
{
    core::position2di pos;
    IGUIFont* font = OverrideFont;
    IGUISkin* skin = Environment->getSkin();
    if (!OverrideFont)
        font = skin->getFont();

    //drop the text that clipping on the right side
    if (WordWrap | MultiLine)
    {
        // todo : It looks like a heavy drinker. Strange!!
        pos.X = CurrentTextRect.LowerRightCorner.X - font->getDimension(Text.subString(CursorPos, BrokenTextPositions[getLineFromPos(CursorPos)] + BrokenText[getLineFromPos(CursorPos)].size() - CursorPos).c_str()).Width;
        pos.Y = CurrentTextRect.UpperLeftCorner.Y + font->getDimension(L"|").Height + (Border ? 3 : 0) - ((MultiLine | WordWrap) ? 3 : 0);
    }
    else
    {
        pos.X = CurrentTextRect.LowerRightCorner.X - font->getDimension(Text.subString(CursorPos, Text.size() - CursorPos).c_str()).Width;
        pos.Y = AbsoluteRect.getCenter().Y + (Border ? 3 : 0); //bug? The text is always drawn in the height of the center. SetTextAlignment() doesn't influence.
    }

    return pos;
}
Esempio n. 26
0
void CGUIMenu::recalculateSize()
{
	IGUISkin* skin = Environment->getSkin();
	IGUIFont* font = skin->getFont(EGDF_MENU);

	if (!font)
	{
		if (Parent && skin)
			RelativeRect = core::rect<s32>(0,0,
					Parent->getAbsolutePosition().LowerRightCorner.X,
					skin->getSize(EGDS_MENU_HEIGHT));
		return;
	}

	core::rect<s32> rect;
	rect.UpperLeftCorner.X = 0;
	rect.UpperLeftCorner.Y = 0;
	s32 height = font->getDimension(L"A").Height + 5;
	//if (skin && height < skin->getSize ( EGDS_MENU_HEIGHT ))
	//	height = skin->getSize(EGDS_MENU_HEIGHT);
	s32 width = 0;
	s32 i;

	for (i=0; i<(s32)Items.size(); ++i)
	{
		if (Items[i].IsSeparator)
		{
			Items[i].Dim.Width = 0;
			Items[i].Dim.Height = height;
		}
		else
		{
			Items[i].Dim = font->getDimension(Items[i].Text.c_str());
			Items[i].Dim.Width += 20;
		}

		Items[i].PosY = width;
		width += Items[i].Dim.Width;
	}

	if (Parent)
		width = Parent->getAbsolutePosition().getWidth();

	rect.LowerRightCorner.X = width;
	rect.LowerRightCorner.Y = height;

	setRelativePosition(rect);

	// recalculate submenus
	for (i=0; i<(s32)Items.size(); ++i)
		if (Items[i].SubMenu)
		{
			// move submenu
			s32 w = Items[i].SubMenu->getAbsolutePosition().getWidth();
			s32 h = Items[i].SubMenu->getAbsolutePosition().getHeight();

			Items[i].SubMenu->setRelativePosition(
				core::rect<s32>(Items[i].PosY, height ,
					Items[i].PosY+w-5, height+h));
		}
}
Esempio n. 27
0
//! draws the element and its children
void CGUIButton::draw()
{
	if (!IsVisible)
		return;

	IGUISkin* skin = Environment->getSkin();
	video::IVideoDriver* driver = Environment->getVideoDriver();

	if (DrawBorder)
	{
		if (!Pressed)
		{
			skin->draw3DButtonPaneStandard(this, AbsoluteRect, &AbsoluteClippingRect);
		}
		else
		{
			skin->draw3DButtonPanePressed(this, AbsoluteRect, &AbsoluteClippingRect);
		}
	}


	const core::position2di buttonCenter(AbsoluteRect.getCenter());

	EGUI_BUTTON_IMAGE_STATE imageState = getImageState(Pressed);
	if ( ButtonImages[(u32)imageState].Texture )
	{
		core::position2d<s32> pos(buttonCenter);
		core::rect<s32> sourceRect(ButtonImages[(u32)imageState].SourceRect);
		if ( sourceRect.getWidth() == 0 && sourceRect.getHeight() == 0 )
			sourceRect = core::rect<s32>(core::position2di(0,0), ButtonImages[(u32)imageState].Texture->getOriginalSize());

		pos.X -= sourceRect.getWidth() / 2;
		pos.Y -= sourceRect.getHeight() / 2;

		if ( Pressed )
		{
			// Create a pressed-down effect by moving the image when it looks identical to the unpressed state image
			EGUI_BUTTON_IMAGE_STATE unpressedState = getImageState(false);
			if ( unpressedState == imageState || ButtonImages[(u32)imageState] == ButtonImages[(u32)unpressedState] )
			{
				pos.X += skin->getSize(EGDS_BUTTON_PRESSED_IMAGE_OFFSET_X);
				pos.Y += skin->getSize(EGDS_BUTTON_PRESSED_IMAGE_OFFSET_Y);
			}
		}

		driver->draw2DImage(ButtonImages[(u32)imageState].Texture,
				ScaleImage? AbsoluteRect : core::rect<s32>(pos, sourceRect.getSize()),
				sourceRect, &AbsoluteClippingRect,
				0, UseAlphaChannel);
	}

	if (SpriteBank)
	{
		core::position2di pos(buttonCenter);
		if ( Pressed )
		{
			IGUISkin* skin = Environment->getSkin();
			pos.X += skin->getSize(EGDS_BUTTON_PRESSED_SPRITE_OFFSET_X);
			pos.Y += skin->getSize(EGDS_BUTTON_PRESSED_SPRITE_OFFSET_Y);
		}

		if (isEnabled())
		{
			// pressed / unpressed animation
			EGUI_BUTTON_STATE state = Pressed ? EGBS_BUTTON_DOWN : EGBS_BUTTON_UP;
			drawSprite(state, ClickTime, pos);

			// focused / unfocused animation
			state = Environment->hasFocus(this) ? EGBS_BUTTON_FOCUSED : EGBS_BUTTON_NOT_FOCUSED;
			drawSprite(state, FocusTime, pos);

			// mouse over / off animation
			state = Environment->getHovered() == this ? EGBS_BUTTON_MOUSE_OVER : EGBS_BUTTON_MOUSE_OFF;
			drawSprite(state, HoverTime, pos);
		}
		else
		{
			// draw disabled
			drawSprite(EGBS_BUTTON_DISABLED, 0, pos);
		}
	}

	if (Text.size())
	{
		IGUIFont* font = getActiveFont();

		core::rect<s32> rect = AbsoluteRect;
		if (Pressed)
		{
			rect.UpperLeftCorner.X += skin->getSize(EGDS_BUTTON_PRESSED_TEXT_OFFSET_X);
			rect.UpperLeftCorner.Y += skin->getSize(EGDS_BUTTON_PRESSED_TEXT_OFFSET_Y);
		}

		if (font)
			font->draw(Text.c_str(), rect,
				skin->getColor(isEnabled() ? EGDC_BUTTON_TEXT : EGDC_GRAY_TEXT),
				true, true, &AbsoluteClippingRect);
	}

	IGUIElement::draw();
}
Esempio n. 28
0
/** Changes this dialog to confirm the changes.
 */
void PlayerInfoDialog::showConfirmDialog()
{
    clearWindow();

    IGUIFont* font = GUIEngine::getFont();
    const int textHeight = GUIEngine::getFontHeight();
    const int buttonHeight = textHeight + 10;

    irr::core::stringw message =
        //I18N: In the player info dialog (when deleting)
        _("Do you really want to delete player '%s' ?", m_player->getName());


    if (PlayerManager::getCurrentPlayer() == m_player)
    {
        message = _("You cannot delete this player "
                    "because it is currently in use.");
    }

    core::rect< s32 > area_left(5, 0, m_area.getWidth()-5, m_area.getHeight()/2);

    // When there is no need to tab through / click on images/labels,
    // we can add irrlicht labels directly
    // (more complicated uses require the use of our widget set)
    IGUIStaticText* a = GUIEngine::getGUIEnv()->addStaticText( message.c_str(),
                                              area_left, false /* border */,
                                              true /* word wrap */,
                                              m_irrlicht_window);
    a->setTextAlignment(EGUIA_CENTER, EGUIA_CENTER);

    if (PlayerManager::getCurrentPlayer() != m_player)
    {
        ButtonWidget* widget = new ButtonWidget();
        widget->m_properties[PROP_ID] = "confirmremove";

        //I18N: In the player info dialog (when deleting)
        widget->setText( _("Confirm Remove") );

        const int textWidth =
            font->getDimension(widget->getText().c_str()).Width + 40;

        widget->m_x = m_area.getWidth()/2 - textWidth/2;
        widget->m_y = m_area.getHeight()/2;
        widget->m_w = textWidth;
        widget->m_h = buttonHeight;
        widget->setParent(m_irrlicht_window);
        m_widgets.push_back(widget);
        widget->add();
    }

    {
        ButtonWidget* widget = new ButtonWidget();
        widget->m_properties[PROP_ID] = "cancelremove";

        //I18N: In the player info dialog (when deleting)
        widget->setText( _("Cancel Remove") );

        const int textWidth =
            font->getDimension( widget->getText().c_str() ).Width + 40;

        widget->m_x = m_area.getWidth()/2 - textWidth/2;
        widget->m_y = m_area.getHeight()*3/4;
        widget->m_w = textWidth;
        widget->m_h = buttonHeight;
        widget->setParent(m_irrlicht_window);
        m_widgets.push_back(widget);
        widget->add();

        widget->setFocusForPlayer( PLAYER_ID_GAME_MASTER );
    }

}   // showConfirmDialog
Esempio n. 29
0
//! draws the element and its children
void CGUIStaticText::draw()
{
	if (!IsVisible)
		return;

	IGUISkin* skin = Environment->getSkin();
	irr::video::IVideoDriver* driver = Environment->getVideoDriver();

	core::rect<s32> frameRect(AbsoluteRect);

	// draw background

	if (Background)
	{
		driver->draw2DRectangle( skin->getColor(gui::EGDC_3D_FACE),
			frameRect, &AbsoluteClippingRect);
	}

	// draw the border

	if (Border)
	{
		skin->draw3DSunkenPane(this, 0, true, false, frameRect, &AbsoluteClippingRect);	
		frameRect.UpperLeftCorner.X += 3;
	}

	// draw the text
	if (Text.size())
	{
		IGUIFont* font = OverrideFont;
		if (!OverrideFont)
			font = skin->getFont();

		if (font)
		{
			if (!WordWrap)
				font->draw(Text.c_str(), frameRect, 
					OverrideColorEnabled ? OverrideColor : skin->getColor(EGDC_BUTTON_TEXT),
					false, true, &AbsoluteClippingRect);
			else
			{
				if (font != LastBreakFont)
					breakText();

				core::rect<s32> r = frameRect;
				s32 height = font->getDimension(L"A").Height;

				for (u32 i=0; i<BrokenText.size(); ++i)
				{
					font->draw(BrokenText[i].c_str(), r,
						OverrideColorEnabled ? OverrideColor : skin->getColor(EGDC_BUTTON_TEXT),
						false, false, &AbsoluteClippingRect);

					r.LowerRightCorner.Y += height;
					r.UpperLeftCorner.Y += height;
				}
			}
		}
	}

	IGUIElement::draw();
}
Esempio n. 30
0
//! Breaks the single text line.
void CGUIStaticText::breakText()
{
	IGUISkin* skin = Environment->getSkin();

	if (!WordWrap || !skin)
		return;

	BrokenText.clear();

	IGUIFont* font = OverrideFont;
	if (!OverrideFont)
		font = skin->getFont();

	if (!font)
		return;

	LastBreakFont = font;

	core::stringw line;
	core::stringw word;
	core::stringw whitespace;
	s32 size = Text.size();
	s32 length = 0;
	s32 elWidth = RelativeRect.getWidth() - 6;
	wchar_t c;

	for (s32 i=0; i<size; ++i)
	{
		c = Text[i];
		bool lineBreak = false;

		if (c == L'\n')
		{
			lineBreak = true;
			c = ' ';
		}
		
		if (c == L' ' || c == 0 || i == (size-1))
		{
			
			if (word.size())
			{
				// here comes the next whitespace, look if 
				// we can break the last word to the next line.
				s32 whitelgth = font->getDimension(whitespace.c_str()).Width;
				s32 worldlgth = font->getDimension(word.c_str()).Width;

				if (length + worldlgth + whitelgth > elWidth)
				{
					// break to next line
					length = worldlgth;
					BrokenText.push_back(line);
					line = word;
				}
				else
				{
					// add word to line
					line += whitespace;
					line += word;
					length += whitelgth + worldlgth;
				}

				word = L"";
				whitespace = L"";
			}

			whitespace += c;

			// compute line break
			if (lineBreak)
			{
				line += whitespace;
				line += word;
				BrokenText.push_back(line);
				line = L"";
				word = L"";
				whitespace = L"";
				length = 0;
			}
		}
		else
		{
			// yippee this is a word..
			word += c;
		}
	}

	line += whitespace; 
	line += word; 
	BrokenText.push_back(line);
}