//! draws the element and its children
void CGUIScrollBar::draw()
{
	if (!IsVisible)
		return;

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


	SliderRect = AbsoluteRect;

	// draws the background
	skin->draw2DRectangle(this, skin->getColor(EGDC_SCROLLBAR), SliderRect, &AbsoluteClippingRect);

	if ( core::isnotzero ( range() ) )
	{
		// recalculate slider rectangle
		if (Horizontal)
		{
			SliderRect.UpperLeftCorner.X = AbsoluteRect.UpperLeftCorner.X + DrawPos + RelativeRect.getHeight() - DrawHeight/2;
			SliderRect.LowerRightCorner.X = SliderRect.UpperLeftCorner.X + DrawHeight;
		}
		else
		{
			SliderRect.UpperLeftCorner.Y = AbsoluteRect.UpperLeftCorner.Y + DrawPos + RelativeRect.getWidth() - DrawHeight/2;
			SliderRect.LowerRightCorner.Y = SliderRect.UpperLeftCorner.Y + DrawHeight;
		}

		skin->draw3DButtonPaneStandard(this, SliderRect, &AbsoluteClippingRect);
	}

	// draw buttons
	IGUIElement::draw();
}
	//! draws the element and its children
	void CGUIScrollBar::draw()
	{
		if (!IsVisible)
			return;

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


		ColourValue iconColor = skin->getColor(isEnabled() ? EGDC_WINDOW_SYMBOL : EGDC_GRAY_WINDOW_SYMBOL);
		if (iconColor != CurrentIconColor)
		{
			refreshControls();
		}


		SliderRect = AbsoluteRect;

		// draws the background
		skin->draw2DRectangle(this, skin->getColor(EGDC_SCROLLBAR), SliderRect, &AbsoluteClippingRect);

		if (!Math::iszero(range()))
		{
			// recalculate slider rectangle
			if (Horizontal)
			{
				SliderRect.UpperLeftCorner.x = AbsoluteRect.UpperLeftCorner.x + DrawPos + RelativeRect.getHeight() - DrawHeight / 2;
				SliderRect.LowerRightCorner.x = SliderRect.UpperLeftCorner.x + DrawHeight;
			}
			else
			{
				SliderRect.UpperLeftCorner.y = AbsoluteRect.UpperLeftCorner.y + DrawPos + RelativeRect.getWidth() - DrawHeight / 2;
				SliderRect.LowerRightCorner.y = SliderRect.UpperLeftCorner.y + DrawHeight;
			}

			skin->draw3DButtonPaneStandard(this, SliderRect, &AbsoluteClippingRect);
		}

		// draw buttons
		IGUIElement::draw();
	}
//! draws the element and its children
void CGUIScrollBar::draw()
{
	if (!IsVisible)
		return;

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

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

	core::rect<s32> rect = AbsoluteRect;
	core::rect<s32>* clip = 0;

	if (!NoClip)
		clip = &AbsoluteClippingRect;

	// draws the background
	driver->draw2DRectangle(skin->getColor(EGDC_SCROLLBAR), rect, clip);

	if (Max!=0)
	{
		// draw thumb
		if (Horizontal)
		{
			rect.UpperLeftCorner.X = AbsoluteRect.UpperLeftCorner.X + DrawPos + RelativeRect.getHeight() - DrawHeight/2;
			rect.LowerRightCorner.X = rect.UpperLeftCorner.X + DrawHeight;	
		}
		else
		{
			rect.UpperLeftCorner.Y = AbsoluteRect.UpperLeftCorner.Y + DrawPos + RelativeRect.getWidth() - DrawHeight/2;
			rect.LowerRightCorner.Y = rect.UpperLeftCorner.Y + DrawHeight;	
		}

		skin->draw3DButtonPaneStandard(this, rect, clip);
	}

	// draw buttons
	IGUIElement::draw();
}
//! 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();
}
	//! draws the element and its children
	void CGUIButton::draw()
	{
		if (!IsVisible)
			return;

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

		// todo:	move sprite up and text down if the pressed state has a sprite
		const Position2d spritePos = AbsoluteRect.getCenter();

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

			if (Image)
			{
				Position2d pos = spritePos;
				pos.x -= ImageRect.getWidth() / 2;
				pos.y -= ImageRect.getHeight() / 2;

				driver->draw2DImage(Image,
					ScaleImage ? AbsoluteRect :
					recti(pos, ImageRect.getSize()),
					ImageRect, &AbsoluteClippingRect,
					0, UseAlphaChannel);
			}
		}
		else
		{
			if (DrawBorder)
				skin->draw3DButtonPanePressed(this, AbsoluteRect, &AbsoluteClippingRect);

			if (PressedImage)
			{
				Position2d pos = spritePos;
				pos.x -= PressedImageRect.getWidth() / 2;
				pos.y -= PressedImageRect.getHeight() / 2;

				if (Image == PressedImage && PressedImageRect == ImageRect)
				{
					pos.x += skin->getSize(EGDS_BUTTON_PRESSED_IMAGE_OFFSET_X);
					pos.y += skin->getSize(EGDS_BUTTON_PRESSED_IMAGE_OFFSET_Y);
				}
				driver->draw2DImage(PressedImage,
					ScaleImage ? AbsoluteRect :
					recti(pos, PressedImageRect.getSize()),
					PressedImageRect, &AbsoluteClippingRect,
					0, UseAlphaChannel);
			}
		}

		if (SpriteBank)
		{
			// pressed / unpressed animation
			UINT32 state = Pressed ? (UINT32)EGBS_BUTTON_DOWN : (UINT32)EGBS_BUTTON_UP;
			if (ButtonSprites[state].Index != -1)
			{
				SpriteBank->draw2DSprite(ButtonSprites[state].Index, spritePos,
					&AbsoluteClippingRect, ButtonSprites[state].Color, ClickTime, Timer::getTime(),
					ButtonSprites[state].Loop, true);
			}

			// focused / unfocused animation
			state = Environment->hasFocus(this) ? (UINT32)EGBS_BUTTON_FOCUSED : (UINT32)EGBS_BUTTON_NOT_FOCUSED;
			if (ButtonSprites[state].Index != -1)
			{
				SpriteBank->draw2DSprite(ButtonSprites[state].Index, spritePos,
					&AbsoluteClippingRect, ButtonSprites[state].Color, FocusTime, Timer::getTime(),
					ButtonSprites[state].Loop, true);
			}

			// mouse over / off animation
			if (isEnabled())
			{
				state = Environment->getHovered() == this ? (UINT32)EGBS_BUTTON_MOUSE_OVER : (UINT32)EGBS_BUTTON_MOUSE_OFF;
				if (ButtonSprites[state].Index != -1)
				{
					SpriteBank->draw2DSprite(ButtonSprites[state].Index, spritePos,
						&AbsoluteClippingRect, ButtonSprites[state].Color, HoverTime, Timer::getTime(),
						ButtonSprites[state].Loop, true);
				}
			}
		}

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

			rect<SINT32> 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, rect,
				skin->getColor(isEnabled() ? EGDC_BUTTON_TEXT : EGDC_GRAY_TEXT),
				true, true, &AbsoluteClippingRect);
		}

		IGUIElement::draw();
	}
Exemple #6
0
//! draws the element and its children
void CGUIButton::draw()
{
    if (!IsVisible)
        return;

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

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

    core::rect<s32> rect = AbsoluteRect;

    // todo:	move sprite up and text down if the pressed state has a sprite
    //			draw sprites for focused and mouse-over
    core::position2di spritePos = AbsoluteRect.getCenter();

    if (!Pressed)
    {
        if (Border)
            skin->draw3DButtonPaneStandard(this, rect, &AbsoluteClippingRect);

        if (Image)
        {
            core::position2d<s32> pos = AbsoluteRect.getCenter();
            pos.X -= ImageRect.getWidth() / 2;
            pos.Y -= ImageRect.getHeight() / 2;

            driver->draw2DImage(Image, pos, ImageRect, &AbsoluteClippingRect,
                                video::SColor(255,255,255,255), UseAlphaChannel);
        }
        if (SpriteBank && ButtonSprites[EGBS_BUTTON_UP].Index != -1)
        {
            // draw pressed sprite
            SpriteBank->draw2DSprite(ButtonSprites[EGBS_BUTTON_UP].Index, spritePos,
                                     &AbsoluteClippingRect, ButtonSprites[EGBS_BUTTON_UP].Color, ClickTime, os::Timer::getTime(),
                                     ButtonSprites[EGBS_BUTTON_UP].Loop, true);
        }
    }
    else
    {
        if (Border)
            skin->draw3DButtonPanePressed(this, rect, &AbsoluteClippingRect);

        if (PressedImage)
        {
            core::position2d<s32> pos = AbsoluteRect.getCenter();
            pos.X -= PressedImageRect.getWidth() / 2;
            pos.Y -= PressedImageRect.getHeight() / 2;
            // patch by Alan Tyndall/Jonas Petersen
            if (Image == PressedImage && PressedImageRect == ImageRect)
            {
                pos.X += 1;
                pos.Y += 1;
            }
            driver->draw2DImage(PressedImage, pos, PressedImageRect, &AbsoluteClippingRect,
                                video::SColor(255,255,255,255), UseAlphaChannel);
        }

        if (SpriteBank && ButtonSprites[EGBS_BUTTON_DOWN].Index != -1)
        {
            // draw sprite
            SpriteBank->draw2DSprite(ButtonSprites[EGBS_BUTTON_DOWN].Index, spritePos,
                                     &AbsoluteClippingRect, ButtonSprites[EGBS_BUTTON_DOWN].Color, ClickTime, os::Timer::getTime(),
                                     ButtonSprites[EGBS_BUTTON_DOWN].Loop, true);
        }

    }

    if (Text.size())
    {
        rect = AbsoluteRect;
        if (Pressed)
            rect.UpperLeftCorner.Y += 2;

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

    IGUIElement::draw();
}
//! draws the element and its children
void CGUIScrollBar::draw()
{
	if (!IsVisible)
		return;

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

	u32 now = os::Timer::getRealTime();

	if (Dragging && !DraggedBySlider && TrayClick && now > LastChange + 200)
	{
		LastChange = now;

		const s32 oldPos = Pos;

		if (DesiredPos >= Pos + LargeStep)
			setPos(Pos + LargeStep);
		else
		if (DesiredPos <= Pos - LargeStep)
			setPos(Pos - LargeStep);
		else
		if (DesiredPos >= Pos - LargeStep && DesiredPos <= Pos + LargeStep)
			setPos(DesiredPos);

		if (Pos != oldPos && Parent)
		{
			SEvent newEvent;
			newEvent.EventType = EET_GUI_EVENT;
			newEvent.GUIEvent.Caller = this;
			newEvent.GUIEvent.Element = 0;
			newEvent.GUIEvent.EventType = EGET_SCROLL_BAR_CHANGED;
			Parent->OnEvent(newEvent);
		}
	}

	SliderRect = AbsoluteRect;

	// draws the background
	skin->draw2DRectangle(this, skin->getColor(EGDC_SCROLLBAR), SliderRect, &AbsoluteClippingRect);

	if (Max!=0)
	{
		// recalculate slider rectangle
		if (Horizontal)
		{
			SliderRect.UpperLeftCorner.X = AbsoluteRect.UpperLeftCorner.X + DrawPos + RelativeRect.getHeight() - DrawHeight/2;
			SliderRect.LowerRightCorner.X = SliderRect.UpperLeftCorner.X + DrawHeight;
		}
		else
		{
			SliderRect.UpperLeftCorner.Y = AbsoluteRect.UpperLeftCorner.Y + DrawPos + RelativeRect.getWidth() - DrawHeight/2;
			SliderRect.LowerRightCorner.Y = SliderRect.UpperLeftCorner.Y + DrawHeight;
		}

		skin->draw3DButtonPaneStandard(this, SliderRect, &AbsoluteClippingRect);
	}

	// draw buttons
	IGUIElement::draw();
}