forked from Mirrorlandia_minetest/minetest
Add custom colorable GUIButton implementation
This commit is contained in:
parent
41ad0f4f20
commit
d1a1c5cbf0
@ -186,6 +186,7 @@ LOCAL_SRC_FILES := \
|
|||||||
jni/src/gui/guiPasswordChange.cpp \
|
jni/src/gui/guiPasswordChange.cpp \
|
||||||
jni/src/gui/guiPathSelectMenu.cpp \
|
jni/src/gui/guiPathSelectMenu.cpp \
|
||||||
jni/src/gui/guiScrollBar.cpp \
|
jni/src/gui/guiScrollBar.cpp \
|
||||||
|
jni/src/gui/guiSkin.cpp \
|
||||||
jni/src/gui/guiTable.cpp \
|
jni/src/gui/guiTable.cpp \
|
||||||
jni/src/gui/guiVolumeChange.cpp \
|
jni/src/gui/guiVolumeChange.cpp \
|
||||||
jni/src/gui/intlGUIEditBox.cpp \
|
jni/src/gui/intlGUIEditBox.cpp \
|
||||||
|
@ -35,6 +35,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||||||
#include "render/factory.h"
|
#include "render/factory.h"
|
||||||
#include "inputhandler.h"
|
#include "inputhandler.h"
|
||||||
#include "gettext.h"
|
#include "gettext.h"
|
||||||
|
#include "../gui/guiSkin.h"
|
||||||
|
|
||||||
#if !defined(_WIN32) && !defined(__APPLE__) && !defined(__ANDROID__) && \
|
#if !defined(_WIN32) && !defined(__APPLE__) && !defined(__ANDROID__) && \
|
||||||
!defined(SERVER) && !defined(__HAIKU__)
|
!defined(SERVER) && !defined(__HAIKU__)
|
||||||
@ -44,6 +45,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||||||
#include <X11/Xlib.h>
|
#include <X11/Xlib.h>
|
||||||
#include <X11/Xutil.h>
|
#include <X11/Xutil.h>
|
||||||
#include <X11/Xatom.h>
|
#include <X11/Xatom.h>
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef __ANDROID__
|
#ifdef __ANDROID__
|
||||||
@ -52,6 +54,29 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||||||
|
|
||||||
RenderingEngine *RenderingEngine::s_singleton = nullptr;
|
RenderingEngine *RenderingEngine::s_singleton = nullptr;
|
||||||
|
|
||||||
|
|
||||||
|
static gui::GUISkin* createSkin(gui::IGUIEnvironment *environment,
|
||||||
|
gui::EGUI_SKIN_TYPE type, video::IVideoDriver *driver)
|
||||||
|
{
|
||||||
|
gui::GUISkin* skin = new gui::GUISkin(type, driver);
|
||||||
|
|
||||||
|
gui::IGUIFont* builtinfont = environment->getBuiltInFont();
|
||||||
|
gui::IGUIFontBitmap* bitfont = 0;
|
||||||
|
if (builtinfont && builtinfont->getType() == gui::EGFT_BITMAP)
|
||||||
|
bitfont = (gui::IGUIFontBitmap*)builtinfont;
|
||||||
|
|
||||||
|
gui::IGUISpriteBank* bank = 0;
|
||||||
|
skin->setFont(builtinfont);
|
||||||
|
|
||||||
|
if (bitfont)
|
||||||
|
bank = bitfont->getSpriteBank();
|
||||||
|
|
||||||
|
skin->setSpriteBank(bank);
|
||||||
|
|
||||||
|
return skin;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
RenderingEngine::RenderingEngine(IEventReceiver *receiver)
|
RenderingEngine::RenderingEngine(IEventReceiver *receiver)
|
||||||
{
|
{
|
||||||
sanity_check(!s_singleton);
|
sanity_check(!s_singleton);
|
||||||
@ -112,6 +137,11 @@ RenderingEngine::RenderingEngine(IEventReceiver *receiver)
|
|||||||
driver = m_device->getVideoDriver();
|
driver = m_device->getVideoDriver();
|
||||||
|
|
||||||
s_singleton = this;
|
s_singleton = this;
|
||||||
|
|
||||||
|
auto skin = createSkin(m_device->getGUIEnvironment(),
|
||||||
|
gui::EGST_WINDOWS_METALLIC, driver);
|
||||||
|
m_device->getGUIEnvironment()->setSkin(skin);
|
||||||
|
skin->drop();
|
||||||
}
|
}
|
||||||
|
|
||||||
RenderingEngine::~RenderingEngine()
|
RenderingEngine::~RenderingEngine()
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
set(gui_SRCS
|
set(gui_SRCS
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/guiButton.cpp
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/guiChatConsole.cpp
|
${CMAKE_CURRENT_SOURCE_DIR}/guiChatConsole.cpp
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/guiConfirmRegistration.cpp
|
${CMAKE_CURRENT_SOURCE_DIR}/guiConfirmRegistration.cpp
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/guiEditBoxWithScrollbar.cpp
|
${CMAKE_CURRENT_SOURCE_DIR}/guiEditBoxWithScrollbar.cpp
|
||||||
@ -8,6 +9,7 @@ set(gui_SRCS
|
|||||||
${CMAKE_CURRENT_SOURCE_DIR}/guiPasswordChange.cpp
|
${CMAKE_CURRENT_SOURCE_DIR}/guiPasswordChange.cpp
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/guiPathSelectMenu.cpp
|
${CMAKE_CURRENT_SOURCE_DIR}/guiPathSelectMenu.cpp
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/guiScrollBar.cpp
|
${CMAKE_CURRENT_SOURCE_DIR}/guiScrollBar.cpp
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/guiSkin.cpp
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/guiTable.cpp
|
${CMAKE_CURRENT_SOURCE_DIR}/guiTable.cpp
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/guiVolumeChange.cpp
|
${CMAKE_CURRENT_SOURCE_DIR}/guiVolumeChange.cpp
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/intlGUIEditBox.cpp
|
${CMAKE_CURRENT_SOURCE_DIR}/intlGUIEditBox.cpp
|
||||||
|
649
src/gui/guiButton.cpp
Normal file
649
src/gui/guiButton.cpp
Normal file
@ -0,0 +1,649 @@
|
|||||||
|
// Copyright (C) 2002-2012 Nikolaus Gebhardt
|
||||||
|
// This file is part of the "Irrlicht Engine".
|
||||||
|
// For conditions of distribution and use, see copyright notice in irrlicht.h
|
||||||
|
|
||||||
|
#include "guiButton.h"
|
||||||
|
|
||||||
|
|
||||||
|
#include "IGUISkin.h"
|
||||||
|
#include "IGUIEnvironment.h"
|
||||||
|
#include "IVideoDriver.h"
|
||||||
|
#include "IGUIFont.h"
|
||||||
|
#include "porting.h"
|
||||||
|
|
||||||
|
using namespace irr;
|
||||||
|
using namespace gui;
|
||||||
|
|
||||||
|
//! constructor
|
||||||
|
GUIButton::GUIButton(IGUIEnvironment* environment, IGUIElement* parent,
|
||||||
|
s32 id, core::rect<s32> rectangle, bool noclip)
|
||||||
|
: IGUIButton(environment, parent, id, rectangle),
|
||||||
|
SpriteBank(0), OverrideFont(0),
|
||||||
|
OverrideColorEnabled(false), OverrideColor(video::SColor(101,255,255,255)),
|
||||||
|
ClickTime(0), HoverTime(0), FocusTime(0),
|
||||||
|
ClickShiftState(false), ClickControlState(false),
|
||||||
|
IsPushButton(false), Pressed(false),
|
||||||
|
UseAlphaChannel(false), DrawBorder(true), ScaleImage(false)
|
||||||
|
{
|
||||||
|
setNotClipped(noclip);
|
||||||
|
|
||||||
|
// This element can be tabbed.
|
||||||
|
setTabStop(true);
|
||||||
|
setTabOrder(-1);
|
||||||
|
|
||||||
|
// PATCH
|
||||||
|
for (size_t i = 0; i < 4; i++) {
|
||||||
|
Colors[i] = Environment->getSkin()->getColor((EGUI_DEFAULT_COLOR)i);
|
||||||
|
}
|
||||||
|
// END PATCH
|
||||||
|
}
|
||||||
|
|
||||||
|
//! destructor
|
||||||
|
GUIButton::~GUIButton()
|
||||||
|
{
|
||||||
|
if (OverrideFont)
|
||||||
|
OverrideFont->drop();
|
||||||
|
|
||||||
|
if (SpriteBank)
|
||||||
|
SpriteBank->drop();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//! Sets if the images should be scaled to fit the button
|
||||||
|
void GUIButton::setScaleImage(bool scaleImage)
|
||||||
|
{
|
||||||
|
ScaleImage = scaleImage;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//! Returns whether the button scale the used images
|
||||||
|
bool GUIButton::isScalingImage() const
|
||||||
|
{
|
||||||
|
return ScaleImage;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//! Sets if the button should use the skin to draw its border
|
||||||
|
void GUIButton::setDrawBorder(bool border)
|
||||||
|
{
|
||||||
|
DrawBorder = border;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void GUIButton::setSpriteBank(IGUISpriteBank* sprites)
|
||||||
|
{
|
||||||
|
if (sprites)
|
||||||
|
sprites->grab();
|
||||||
|
|
||||||
|
if (SpriteBank)
|
||||||
|
SpriteBank->drop();
|
||||||
|
|
||||||
|
SpriteBank = sprites;
|
||||||
|
}
|
||||||
|
|
||||||
|
void GUIButton::setSprite(EGUI_BUTTON_STATE state, s32 index, video::SColor color, bool loop, bool scale)
|
||||||
|
{
|
||||||
|
ButtonSprites[(u32)state].Index = index;
|
||||||
|
ButtonSprites[(u32)state].Color = color;
|
||||||
|
ButtonSprites[(u32)state].Loop = loop;
|
||||||
|
ButtonSprites[(u32)state].Scale = scale;
|
||||||
|
}
|
||||||
|
|
||||||
|
//! Get the sprite-index for the given state or -1 when no sprite is set
|
||||||
|
s32 GUIButton::getSpriteIndex(EGUI_BUTTON_STATE state) const
|
||||||
|
{
|
||||||
|
return ButtonSprites[(u32)state].Index;
|
||||||
|
}
|
||||||
|
|
||||||
|
//! Get the sprite color for the given state. Color is only used when a sprite is set.
|
||||||
|
video::SColor GUIButton::getSpriteColor(EGUI_BUTTON_STATE state) const
|
||||||
|
{
|
||||||
|
return ButtonSprites[(u32)state].Color;
|
||||||
|
}
|
||||||
|
|
||||||
|
//! Returns if the sprite in the given state does loop
|
||||||
|
bool GUIButton::getSpriteLoop(EGUI_BUTTON_STATE state) const
|
||||||
|
{
|
||||||
|
return ButtonSprites[(u32)state].Loop;
|
||||||
|
}
|
||||||
|
|
||||||
|
//! Returns if the sprite in the given state is scaled
|
||||||
|
bool GUIButton::getSpriteScale(EGUI_BUTTON_STATE state) const
|
||||||
|
{
|
||||||
|
return ButtonSprites[(u32)state].Scale;
|
||||||
|
}
|
||||||
|
|
||||||
|
//! called if an event happened.
|
||||||
|
bool GUIButton::OnEvent(const SEvent& event)
|
||||||
|
{
|
||||||
|
if (!isEnabled())
|
||||||
|
return IGUIElement::OnEvent(event);
|
||||||
|
|
||||||
|
switch(event.EventType)
|
||||||
|
{
|
||||||
|
case EET_KEY_INPUT_EVENT:
|
||||||
|
if (event.KeyInput.PressedDown &&
|
||||||
|
(event.KeyInput.Key == KEY_RETURN || event.KeyInput.Key == KEY_SPACE))
|
||||||
|
{
|
||||||
|
if (!IsPushButton)
|
||||||
|
setPressed(true);
|
||||||
|
else
|
||||||
|
setPressed(!Pressed);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (Pressed && !IsPushButton && event.KeyInput.PressedDown && event.KeyInput.Key == KEY_ESCAPE)
|
||||||
|
{
|
||||||
|
setPressed(false);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
if (!event.KeyInput.PressedDown && Pressed &&
|
||||||
|
(event.KeyInput.Key == KEY_RETURN || event.KeyInput.Key == KEY_SPACE))
|
||||||
|
{
|
||||||
|
|
||||||
|
if (!IsPushButton)
|
||||||
|
setPressed(false);
|
||||||
|
|
||||||
|
if (Parent)
|
||||||
|
{
|
||||||
|
ClickShiftState = event.KeyInput.Shift;
|
||||||
|
ClickControlState = event.KeyInput.Control;
|
||||||
|
|
||||||
|
SEvent newEvent;
|
||||||
|
newEvent.EventType = EET_GUI_EVENT;
|
||||||
|
newEvent.GUIEvent.Caller = this;
|
||||||
|
newEvent.GUIEvent.Element = 0;
|
||||||
|
newEvent.GUIEvent.EventType = EGET_BUTTON_CLICKED;
|
||||||
|
Parent->OnEvent(newEvent);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case EET_GUI_EVENT:
|
||||||
|
if (event.GUIEvent.Caller == this)
|
||||||
|
{
|
||||||
|
if (event.GUIEvent.EventType == EGET_ELEMENT_FOCUS_LOST)
|
||||||
|
{
|
||||||
|
if (!IsPushButton)
|
||||||
|
setPressed(false);
|
||||||
|
FocusTime = (u32)porting::getTimeMs();
|
||||||
|
}
|
||||||
|
else if (event.GUIEvent.EventType == EGET_ELEMENT_FOCUSED)
|
||||||
|
{
|
||||||
|
FocusTime = (u32)porting::getTimeMs();
|
||||||
|
}
|
||||||
|
else if (event.GUIEvent.EventType == EGET_ELEMENT_HOVERED || event.GUIEvent.EventType == EGET_ELEMENT_LEFT)
|
||||||
|
{
|
||||||
|
HoverTime = (u32)porting::getTimeMs();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case EET_MOUSE_INPUT_EVENT:
|
||||||
|
if (event.MouseInput.Event == EMIE_LMOUSE_PRESSED_DOWN)
|
||||||
|
{
|
||||||
|
if (!IsPushButton)
|
||||||
|
setPressed(true);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
if (event.MouseInput.Event == EMIE_LMOUSE_LEFT_UP)
|
||||||
|
{
|
||||||
|
bool wasPressed = Pressed;
|
||||||
|
|
||||||
|
if ( !AbsoluteClippingRect.isPointInside( core::position2d<s32>(event.MouseInput.X, event.MouseInput.Y ) ) )
|
||||||
|
{
|
||||||
|
if (!IsPushButton)
|
||||||
|
setPressed(false);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!IsPushButton)
|
||||||
|
setPressed(false);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
setPressed(!Pressed);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((!IsPushButton && wasPressed && Parent) ||
|
||||||
|
(IsPushButton && wasPressed != Pressed))
|
||||||
|
{
|
||||||
|
ClickShiftState = event.MouseInput.Shift;
|
||||||
|
ClickControlState = event.MouseInput.Control;
|
||||||
|
|
||||||
|
SEvent newEvent;
|
||||||
|
newEvent.EventType = EET_GUI_EVENT;
|
||||||
|
newEvent.GUIEvent.Caller = this;
|
||||||
|
newEvent.GUIEvent.Element = 0;
|
||||||
|
newEvent.GUIEvent.EventType = EGET_BUTTON_CLICKED;
|
||||||
|
Parent->OnEvent(newEvent);
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return Parent ? Parent->OnEvent(event) : false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//! draws the element and its children
|
||||||
|
void GUIButton::draw()
|
||||||
|
{
|
||||||
|
if (!IsVisible)
|
||||||
|
return;
|
||||||
|
|
||||||
|
// PATCH
|
||||||
|
GUISkin* skin = dynamic_cast<GUISkin*>(Environment->getSkin());
|
||||||
|
video::IVideoDriver* driver = Environment->getVideoDriver();
|
||||||
|
// END PATCH
|
||||||
|
|
||||||
|
if (DrawBorder)
|
||||||
|
{
|
||||||
|
if (!Pressed)
|
||||||
|
{
|
||||||
|
// PATCH
|
||||||
|
skin->drawColored3DButtonPaneStandard(this, AbsoluteRect, &AbsoluteClippingRect, Colors);
|
||||||
|
// END PATCH
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// PATCH
|
||||||
|
skin->drawColored3DButtonPanePressed(this, AbsoluteRect, &AbsoluteClippingRect, Colors);
|
||||||
|
// END PATCH
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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 (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,
|
||||||
|
OverrideColorEnabled ? OverrideColor : skin->getColor(isEnabled() ? EGDC_BUTTON_TEXT : EGDC_GRAY_TEXT),
|
||||||
|
true, true, &AbsoluteClippingRect);
|
||||||
|
}
|
||||||
|
|
||||||
|
IGUIElement::draw();
|
||||||
|
}
|
||||||
|
|
||||||
|
void GUIButton::drawSprite(EGUI_BUTTON_STATE state, u32 startTime, const core::position2di& center)
|
||||||
|
{
|
||||||
|
u32 stateIdx = (u32)state;
|
||||||
|
|
||||||
|
if (ButtonSprites[stateIdx].Index != -1)
|
||||||
|
{
|
||||||
|
if ( ButtonSprites[stateIdx].Scale )
|
||||||
|
{
|
||||||
|
const video::SColor colors[] = {ButtonSprites[stateIdx].Color,ButtonSprites[stateIdx].Color,ButtonSprites[stateIdx].Color,ButtonSprites[stateIdx].Color};
|
||||||
|
SpriteBank->draw2DSprite(ButtonSprites[stateIdx].Index, AbsoluteRect.UpperLeftCorner,
|
||||||
|
&AbsoluteClippingRect, colors[0], // FIXME: remove [0]
|
||||||
|
porting::getTimeMs()-startTime, ButtonSprites[stateIdx].Loop);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
SpriteBank->draw2DSprite(ButtonSprites[stateIdx].Index, center,
|
||||||
|
&AbsoluteClippingRect, ButtonSprites[stateIdx].Color, startTime, porting::getTimeMs(),
|
||||||
|
ButtonSprites[stateIdx].Loop, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
EGUI_BUTTON_IMAGE_STATE GUIButton::getImageState(bool pressed) const
|
||||||
|
{
|
||||||
|
// figure state we should have
|
||||||
|
EGUI_BUTTON_IMAGE_STATE state = EGBIS_IMAGE_DISABLED;
|
||||||
|
bool focused = Environment->hasFocus((IGUIElement*)this);
|
||||||
|
bool mouseOver = static_cast<const IGUIElement*>(Environment->getHovered()) == this; // (static cast for Borland)
|
||||||
|
if (isEnabled())
|
||||||
|
{
|
||||||
|
if ( pressed )
|
||||||
|
{
|
||||||
|
if ( focused && mouseOver )
|
||||||
|
state = EGBIS_IMAGE_DOWN_FOCUSED_MOUSEOVER;
|
||||||
|
else if ( focused )
|
||||||
|
state = EGBIS_IMAGE_DOWN_FOCUSED;
|
||||||
|
else if ( mouseOver )
|
||||||
|
state = EGBIS_IMAGE_DOWN_MOUSEOVER;
|
||||||
|
else
|
||||||
|
state = EGBIS_IMAGE_DOWN;
|
||||||
|
}
|
||||||
|
else // !pressed
|
||||||
|
{
|
||||||
|
if ( focused && mouseOver )
|
||||||
|
state = EGBIS_IMAGE_UP_FOCUSED_MOUSEOVER;
|
||||||
|
else if ( focused )
|
||||||
|
state = EGBIS_IMAGE_UP_FOCUSED;
|
||||||
|
else if ( mouseOver )
|
||||||
|
state = EGBIS_IMAGE_UP_MOUSEOVER;
|
||||||
|
else
|
||||||
|
state = EGBIS_IMAGE_UP;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// find a compatible state that has images
|
||||||
|
while ( state != EGBIS_IMAGE_UP && !ButtonImages[(u32)state].Texture )
|
||||||
|
{
|
||||||
|
switch ( state )
|
||||||
|
{
|
||||||
|
case EGBIS_IMAGE_UP_FOCUSED:
|
||||||
|
state = EGBIS_IMAGE_UP_MOUSEOVER;
|
||||||
|
break;
|
||||||
|
case EGBIS_IMAGE_UP_FOCUSED_MOUSEOVER:
|
||||||
|
state = EGBIS_IMAGE_UP_FOCUSED;
|
||||||
|
break;
|
||||||
|
case EGBIS_IMAGE_DOWN_MOUSEOVER:
|
||||||
|
state = EGBIS_IMAGE_DOWN;
|
||||||
|
break;
|
||||||
|
case EGBIS_IMAGE_DOWN_FOCUSED:
|
||||||
|
state = EGBIS_IMAGE_DOWN_MOUSEOVER;
|
||||||
|
break;
|
||||||
|
case EGBIS_IMAGE_DOWN_FOCUSED_MOUSEOVER:
|
||||||
|
state = EGBIS_IMAGE_DOWN_FOCUSED;
|
||||||
|
break;
|
||||||
|
case EGBIS_IMAGE_DISABLED:
|
||||||
|
if ( pressed )
|
||||||
|
state = EGBIS_IMAGE_DOWN;
|
||||||
|
else
|
||||||
|
state = EGBIS_IMAGE_UP;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
state = EGBIS_IMAGE_UP;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
|
//! sets another skin independent font. if this is set to zero, the button uses the font of the skin.
|
||||||
|
void GUIButton::setOverrideFont(IGUIFont* font)
|
||||||
|
{
|
||||||
|
if (OverrideFont == font)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (OverrideFont)
|
||||||
|
OverrideFont->drop();
|
||||||
|
|
||||||
|
OverrideFont = font;
|
||||||
|
|
||||||
|
if (OverrideFont)
|
||||||
|
OverrideFont->grab();
|
||||||
|
}
|
||||||
|
|
||||||
|
//! Gets the override font (if any)
|
||||||
|
IGUIFont * GUIButton::getOverrideFont() const
|
||||||
|
{
|
||||||
|
return OverrideFont;
|
||||||
|
}
|
||||||
|
|
||||||
|
//! Get the font which is used right now for drawing
|
||||||
|
IGUIFont* GUIButton::getActiveFont() const
|
||||||
|
{
|
||||||
|
if ( OverrideFont )
|
||||||
|
return OverrideFont;
|
||||||
|
IGUISkin* skin = Environment->getSkin();
|
||||||
|
if (skin)
|
||||||
|
return skin->getFont(EGDF_BUTTON);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
//! Sets another color for the text.
|
||||||
|
void GUIButton::setOverrideColor(video::SColor color)
|
||||||
|
{
|
||||||
|
OverrideColor = color;
|
||||||
|
OverrideColorEnabled = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
video::SColor GUIButton::getOverrideColor() const
|
||||||
|
{
|
||||||
|
return OverrideColor;
|
||||||
|
}
|
||||||
|
|
||||||
|
void GUIButton::enableOverrideColor(bool enable)
|
||||||
|
{
|
||||||
|
OverrideColorEnabled = enable;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool GUIButton::isOverrideColorEnabled() const
|
||||||
|
{
|
||||||
|
return OverrideColorEnabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
void GUIButton::setImage(EGUI_BUTTON_IMAGE_STATE state, video::ITexture* image, const core::rect<s32>& sourceRect)
|
||||||
|
{
|
||||||
|
if ( state >= EGBIS_COUNT )
|
||||||
|
return;
|
||||||
|
|
||||||
|
if ( image )
|
||||||
|
image->grab();
|
||||||
|
|
||||||
|
u32 stateIdx = (u32)state;
|
||||||
|
if ( ButtonImages[stateIdx].Texture )
|
||||||
|
ButtonImages[stateIdx].Texture->drop();
|
||||||
|
|
||||||
|
ButtonImages[stateIdx].Texture = image;
|
||||||
|
ButtonImages[stateIdx].SourceRect = sourceRect;
|
||||||
|
}
|
||||||
|
|
||||||
|
//! Sets if the button should behave like a push button. Which means it
|
||||||
|
//! can be in two states: Normal or Pressed. With a click on the button,
|
||||||
|
//! the user can change the state of the button.
|
||||||
|
void GUIButton::setIsPushButton(bool isPushButton)
|
||||||
|
{
|
||||||
|
IsPushButton = isPushButton;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//! Returns if the button is currently pressed
|
||||||
|
bool GUIButton::isPressed() const
|
||||||
|
{
|
||||||
|
return Pressed;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//! Sets the pressed state of the button if this is a pushbutton
|
||||||
|
void GUIButton::setPressed(bool pressed)
|
||||||
|
{
|
||||||
|
if (Pressed != pressed)
|
||||||
|
{
|
||||||
|
ClickTime = porting::getTimeMs();
|
||||||
|
Pressed = pressed;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//! Returns whether the button is a push button
|
||||||
|
bool GUIButton::isPushButton() const
|
||||||
|
{
|
||||||
|
return IsPushButton;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//! Sets if the alpha channel should be used for drawing images on the button (default is false)
|
||||||
|
void GUIButton::setUseAlphaChannel(bool useAlphaChannel)
|
||||||
|
{
|
||||||
|
UseAlphaChannel = useAlphaChannel;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//! Returns if the alpha channel should be used for drawing images on the button
|
||||||
|
bool GUIButton::isAlphaChannelUsed() const
|
||||||
|
{
|
||||||
|
return UseAlphaChannel;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool GUIButton::isDrawingBorder() const
|
||||||
|
{
|
||||||
|
return DrawBorder;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//! Writes attributes of the element.
|
||||||
|
void GUIButton::serializeAttributes(io::IAttributes* out, io::SAttributeReadWriteOptions* options=0) const
|
||||||
|
{
|
||||||
|
IGUIButton::serializeAttributes(out,options);
|
||||||
|
|
||||||
|
out->addBool ("PushButton", IsPushButton );
|
||||||
|
if (IsPushButton)
|
||||||
|
out->addBool("Pressed", Pressed);
|
||||||
|
|
||||||
|
for ( u32 i=0; i<(u32)EGBIS_COUNT; ++i )
|
||||||
|
{
|
||||||
|
if ( ButtonImages[i].Texture )
|
||||||
|
{
|
||||||
|
core::stringc name( GUIButtonImageStateNames[i] );
|
||||||
|
out->addTexture(name.c_str(), ButtonImages[i].Texture);
|
||||||
|
name += "Rect";
|
||||||
|
out->addRect(name.c_str(), ButtonImages[i].SourceRect);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
out->addBool ("UseAlphaChannel", UseAlphaChannel);
|
||||||
|
out->addBool ("Border", DrawBorder);
|
||||||
|
out->addBool ("ScaleImage", ScaleImage);
|
||||||
|
|
||||||
|
for ( u32 i=0; i<(u32)EGBS_COUNT; ++i )
|
||||||
|
{
|
||||||
|
if ( ButtonSprites[i].Index >= 0 )
|
||||||
|
{
|
||||||
|
core::stringc nameIndex( GUIButtonStateNames[i] );
|
||||||
|
nameIndex += "Index";
|
||||||
|
out->addInt(nameIndex.c_str(), ButtonSprites[i].Index );
|
||||||
|
|
||||||
|
core::stringc nameColor( GUIButtonStateNames[i] );
|
||||||
|
nameColor += "Color";
|
||||||
|
out->addColor(nameColor.c_str(), ButtonSprites[i].Color );
|
||||||
|
|
||||||
|
core::stringc nameLoop( GUIButtonStateNames[i] );
|
||||||
|
nameLoop += "Loop";
|
||||||
|
out->addBool(nameLoop.c_str(), ButtonSprites[i].Loop );
|
||||||
|
|
||||||
|
core::stringc nameScale( GUIButtonStateNames[i] );
|
||||||
|
nameScale += "Scale";
|
||||||
|
out->addBool(nameScale.c_str(), ButtonSprites[i].Scale );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// out->addString ("OverrideFont", OverrideFont);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//! Reads attributes of the element
|
||||||
|
void GUIButton::deserializeAttributes(io::IAttributes* in, io::SAttributeReadWriteOptions* options=0)
|
||||||
|
{
|
||||||
|
IGUIButton::deserializeAttributes(in,options);
|
||||||
|
|
||||||
|
IsPushButton = in->getAttributeAsBool("PushButton");
|
||||||
|
Pressed = IsPushButton ? in->getAttributeAsBool("Pressed") : false;
|
||||||
|
|
||||||
|
core::rect<s32> rec = in->getAttributeAsRect("ImageRect");
|
||||||
|
if (rec.isValid())
|
||||||
|
setImage( in->getAttributeAsTexture("Image"), rec);
|
||||||
|
else
|
||||||
|
setImage( in->getAttributeAsTexture("Image") );
|
||||||
|
|
||||||
|
rec = in->getAttributeAsRect("PressedImageRect");
|
||||||
|
if (rec.isValid())
|
||||||
|
setPressedImage( in->getAttributeAsTexture("PressedImage"), rec);
|
||||||
|
else
|
||||||
|
setPressedImage( in->getAttributeAsTexture("PressedImage") );
|
||||||
|
|
||||||
|
setDrawBorder(in->getAttributeAsBool("Border"));
|
||||||
|
setUseAlphaChannel(in->getAttributeAsBool("UseAlphaChannel"));
|
||||||
|
setScaleImage(in->getAttributeAsBool("ScaleImage"));
|
||||||
|
|
||||||
|
// setOverrideFont(in->getAttributeAsString("OverrideFont"));
|
||||||
|
|
||||||
|
updateAbsolutePosition();
|
||||||
|
}
|
||||||
|
|
||||||
|
// PATCH
|
||||||
|
GUIButton* GUIButton::addButton(IGUIEnvironment *environment, const core::rect<s32>& rectangle,
|
||||||
|
IGUIElement* parent, s32 id, const wchar_t* text, const wchar_t *tooltiptext)
|
||||||
|
{
|
||||||
|
GUIButton* button = new GUIButton(environment, parent ? parent : environment->getRootGUIElement(), id, rectangle);
|
||||||
|
if (text)
|
||||||
|
button->setText(text);
|
||||||
|
|
||||||
|
if ( tooltiptext )
|
||||||
|
button->setToolTipText ( tooltiptext );
|
||||||
|
|
||||||
|
button->drop();
|
||||||
|
return button;
|
||||||
|
}
|
||||||
|
|
||||||
|
void GUIButton::setColor(video::SColor color)
|
||||||
|
{
|
||||||
|
float d = 0.65f;
|
||||||
|
for (size_t i = 0; i < 4; i++) {
|
||||||
|
video::SColor base = Environment->getSkin()->getColor((gui::EGUI_DEFAULT_COLOR)i);
|
||||||
|
Colors[i] = base.getInterpolated(color, d);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// END PATCH
|
306
src/gui/guiButton.h
Normal file
306
src/gui/guiButton.h
Normal file
@ -0,0 +1,306 @@
|
|||||||
|
// Copyright (C) 2002-2012 Nikolaus Gebhardt
|
||||||
|
// This file is part of the "Irrlicht Engine".
|
||||||
|
// For conditions of distribution and use, see copyright notice in irrlicht.h
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "IrrCompileConfig.h"
|
||||||
|
|
||||||
|
#include "IGUIButton.h"
|
||||||
|
#include "IGUISpriteBank.h"
|
||||||
|
#include "ITexture.h"
|
||||||
|
#include "SColor.h"
|
||||||
|
#include "guiSkin.h"
|
||||||
|
|
||||||
|
using namespace irr;
|
||||||
|
|
||||||
|
#if (IRRLICHT_VERSION_MAJOR > 1 || IRRLICHT_VERSION_MINOR != 8 || IRRLICHT_VERSION_REVISION < 5)
|
||||||
|
namespace irr { namespace gui {
|
||||||
|
|
||||||
|
//! State of buttons used for drawing texture images.
|
||||||
|
//! Note that only a single state is active at a time
|
||||||
|
//! Also when no image is defined for a state it will use images from another state
|
||||||
|
//! and if that state is not set from the replacement for that,etc.
|
||||||
|
//! So in many cases setting EGBIS_IMAGE_UP and EGBIS_IMAGE_DOWN is sufficient.
|
||||||
|
enum EGUI_BUTTON_IMAGE_STATE {
|
||||||
|
//! When no other states have images they will all use this one.
|
||||||
|
EGBIS_IMAGE_UP,
|
||||||
|
//! When not set EGBIS_IMAGE_UP is used.
|
||||||
|
EGBIS_IMAGE_UP_MOUSEOVER,
|
||||||
|
//! When not set EGBIS_IMAGE_UP_MOUSEOVER is used.
|
||||||
|
EGBIS_IMAGE_UP_FOCUSED,
|
||||||
|
//! When not set EGBIS_IMAGE_UP_FOCUSED is used.
|
||||||
|
EGBIS_IMAGE_UP_FOCUSED_MOUSEOVER,
|
||||||
|
//! When not set EGBIS_IMAGE_UP is used.
|
||||||
|
EGBIS_IMAGE_DOWN,
|
||||||
|
//! When not set EGBIS_IMAGE_DOWN is used.
|
||||||
|
EGBIS_IMAGE_DOWN_MOUSEOVER,
|
||||||
|
//! When not set EGBIS_IMAGE_DOWN_MOUSEOVER is used.
|
||||||
|
EGBIS_IMAGE_DOWN_FOCUSED,
|
||||||
|
//! When not set EGBIS_IMAGE_DOWN_FOCUSED is used.
|
||||||
|
EGBIS_IMAGE_DOWN_FOCUSED_MOUSEOVER,
|
||||||
|
//! When not set EGBIS_IMAGE_UP or EGBIS_IMAGE_DOWN are used (depending on button state).
|
||||||
|
EGBIS_IMAGE_DISABLED,
|
||||||
|
//! not used, counts the number of enumerated items
|
||||||
|
EGBIS_COUNT
|
||||||
|
};
|
||||||
|
|
||||||
|
//! Names for gui button image states
|
||||||
|
const c8 *const GUIButtonImageStateNames[EGBIS_COUNT + 1] =
|
||||||
|
{
|
||||||
|
"Image", // not "ImageUp" as it otherwise breaks serialization of old files
|
||||||
|
"ImageUpOver",
|
||||||
|
"ImageUpFocused",
|
||||||
|
"ImageUpFocusedOver",
|
||||||
|
"PressedImage", // not "ImageDown" as it otherwise breaks serialization of old files
|
||||||
|
"ImageDownOver",
|
||||||
|
"ImageDownFocused",
|
||||||
|
"ImageDownFocusedOver",
|
||||||
|
"ImageDisabled",
|
||||||
|
0 // count
|
||||||
|
};
|
||||||
|
|
||||||
|
}}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
class GUIButton : public gui::IGUIButton
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
//! constructor
|
||||||
|
GUIButton(gui::IGUIEnvironment* environment, gui::IGUIElement* parent,
|
||||||
|
s32 id, core::rect<s32> rectangle, bool noclip=false);
|
||||||
|
|
||||||
|
//! destructor
|
||||||
|
virtual ~GUIButton();
|
||||||
|
|
||||||
|
//! called if an event happened.
|
||||||
|
virtual bool OnEvent(const SEvent& event);
|
||||||
|
|
||||||
|
//! draws the element and its children
|
||||||
|
virtual void draw();
|
||||||
|
|
||||||
|
//! sets another skin independent font. if this is set to zero, the button uses the font of the skin.
|
||||||
|
virtual void setOverrideFont(gui::IGUIFont* font=0);
|
||||||
|
|
||||||
|
//! Gets the override font (if any)
|
||||||
|
virtual gui::IGUIFont* getOverrideFont() const;
|
||||||
|
|
||||||
|
//! Get the font which is used right now for drawing
|
||||||
|
virtual gui::IGUIFont* getActiveFont() const;
|
||||||
|
|
||||||
|
//! Sets another color for the button text.
|
||||||
|
virtual void setOverrideColor(video::SColor color);
|
||||||
|
|
||||||
|
//! Gets the override color
|
||||||
|
virtual video::SColor getOverrideColor(void) const;
|
||||||
|
|
||||||
|
//! Sets if the button text should use the override color or the color in the gui skin.
|
||||||
|
virtual void enableOverrideColor(bool enable);
|
||||||
|
|
||||||
|
//! Checks if an override color is enabled
|
||||||
|
virtual bool isOverrideColorEnabled(void) const;
|
||||||
|
|
||||||
|
//! Sets an image which should be displayed on the button when it is in the given state.
|
||||||
|
virtual void setImage(gui::EGUI_BUTTON_IMAGE_STATE state, video::ITexture* image=0, const core::rect<s32>& sourceRect=core::rect<s32>(0,0,0,0));
|
||||||
|
|
||||||
|
//! Sets an image which should be displayed on the button when it is in normal state.
|
||||||
|
virtual void setImage(video::ITexture* image=0)
|
||||||
|
{
|
||||||
|
setImage(gui::EGBIS_IMAGE_UP, image);
|
||||||
|
}
|
||||||
|
|
||||||
|
//! Sets an image which should be displayed on the button when it is in normal state.
|
||||||
|
virtual void setImage(video::ITexture* image, const core::rect<s32>& pos)
|
||||||
|
{
|
||||||
|
setImage(gui::EGBIS_IMAGE_UP, image, pos);
|
||||||
|
}
|
||||||
|
|
||||||
|
//! Sets an image which should be displayed on the button when it is in pressed state.
|
||||||
|
virtual void setPressedImage(video::ITexture* image=0)
|
||||||
|
{
|
||||||
|
setImage(gui::EGBIS_IMAGE_DOWN, image);
|
||||||
|
}
|
||||||
|
|
||||||
|
//! Sets an image which should be displayed on the button when it is in pressed state.
|
||||||
|
virtual void setPressedImage(video::ITexture* image, const core::rect<s32>& pos)
|
||||||
|
{
|
||||||
|
setImage(gui::EGBIS_IMAGE_DOWN, image, pos);
|
||||||
|
}
|
||||||
|
|
||||||
|
//! Sets the sprite bank used by the button
|
||||||
|
virtual void setSpriteBank(gui::IGUISpriteBank* bank=0);
|
||||||
|
|
||||||
|
//! Sets the animated sprite for a specific button state
|
||||||
|
/** \param index: Number of the sprite within the sprite bank, use -1 for no sprite
|
||||||
|
\param state: State of the button to set the sprite for
|
||||||
|
\param index: The sprite number from the current sprite bank
|
||||||
|
\param color: The color of the sprite
|
||||||
|
*/
|
||||||
|
virtual void setSprite(gui::EGUI_BUTTON_STATE state, s32 index,
|
||||||
|
video::SColor color=video::SColor(255,255,255,255),
|
||||||
|
bool loop=false, bool scale=false);
|
||||||
|
|
||||||
|
void setSprite(gui::EGUI_BUTTON_STATE state, s32 index, video::SColor color, bool loop) override {
|
||||||
|
setSprite(state, index, color, loop, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
//! Get the sprite-index for the given state or -1 when no sprite is set
|
||||||
|
virtual s32 getSpriteIndex(gui::EGUI_BUTTON_STATE state) const;
|
||||||
|
|
||||||
|
//! Get the sprite color for the given state. Color is only used when a sprite is set.
|
||||||
|
virtual video::SColor getSpriteColor(gui::EGUI_BUTTON_STATE state) const;
|
||||||
|
|
||||||
|
//! Returns if the sprite in the given state does loop
|
||||||
|
virtual bool getSpriteLoop(gui::EGUI_BUTTON_STATE state) const;
|
||||||
|
|
||||||
|
//! Returns if the sprite in the given state is scaled
|
||||||
|
virtual bool getSpriteScale(gui::EGUI_BUTTON_STATE state) const;
|
||||||
|
|
||||||
|
//! Sets if the button should behave like a push button. Which means it
|
||||||
|
//! can be in two states: Normal or Pressed. With a click on the button,
|
||||||
|
//! the user can change the state of the button.
|
||||||
|
virtual void setIsPushButton(bool isPushButton=true);
|
||||||
|
|
||||||
|
//! Checks whether the button is a push button
|
||||||
|
virtual bool isPushButton() const;
|
||||||
|
|
||||||
|
//! Sets the pressed state of the button if this is a pushbutton
|
||||||
|
virtual void setPressed(bool pressed=true);
|
||||||
|
|
||||||
|
//! Returns if the button is currently pressed
|
||||||
|
virtual bool isPressed() const;
|
||||||
|
|
||||||
|
//! Sets if the button should use the skin to draw its border
|
||||||
|
virtual void setDrawBorder(bool border=true);
|
||||||
|
|
||||||
|
//! Checks if the button face and border are being drawn
|
||||||
|
virtual bool isDrawingBorder() const;
|
||||||
|
|
||||||
|
//! Sets if the alpha channel should be used for drawing images on the button (default is false)
|
||||||
|
virtual void setUseAlphaChannel(bool useAlphaChannel=true);
|
||||||
|
|
||||||
|
//! Checks if the alpha channel should be used for drawing images on the button
|
||||||
|
virtual bool isAlphaChannelUsed() const;
|
||||||
|
|
||||||
|
//! Sets if the button should scale the button images to fit
|
||||||
|
virtual void setScaleImage(bool scaleImage=true);
|
||||||
|
|
||||||
|
//! Checks whether the button scales the used images
|
||||||
|
virtual bool isScalingImage() const;
|
||||||
|
|
||||||
|
//! Get if the shift key was pressed in last EGET_BUTTON_CLICKED event
|
||||||
|
virtual bool getClickShiftState() const
|
||||||
|
{
|
||||||
|
return ClickShiftState;
|
||||||
|
}
|
||||||
|
|
||||||
|
//! Get if the control key was pressed in last EGET_BUTTON_CLICKED event
|
||||||
|
virtual bool getClickControlState() const
|
||||||
|
{
|
||||||
|
return ClickControlState;
|
||||||
|
}
|
||||||
|
|
||||||
|
//! Writes attributes of the element.
|
||||||
|
virtual void serializeAttributes(io::IAttributes* out, io::SAttributeReadWriteOptions* options) const;
|
||||||
|
|
||||||
|
//! Reads attributes of the element
|
||||||
|
virtual void deserializeAttributes(io::IAttributes* in, io::SAttributeReadWriteOptions* options);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void setColor(video::SColor color);
|
||||||
|
|
||||||
|
|
||||||
|
//! Do not drop returned handle
|
||||||
|
static GUIButton* addButton(gui::IGUIEnvironment *environment, const core::rect<s32>& rectangle,
|
||||||
|
IGUIElement* parent, s32 id, const wchar_t* text, const wchar_t *tooltiptext=L"");
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void drawSprite(gui::EGUI_BUTTON_STATE state, u32 startTime, const core::position2di& center);
|
||||||
|
gui::EGUI_BUTTON_IMAGE_STATE getImageState(bool pressed) const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
struct ButtonSprite
|
||||||
|
{
|
||||||
|
ButtonSprite() : Index(-1), Loop(false), Scale(false)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
bool operator==(const ButtonSprite& other) const
|
||||||
|
{
|
||||||
|
return Index == other.Index && Color == other.Color && Loop == other.Loop && Scale == other.Scale;
|
||||||
|
}
|
||||||
|
|
||||||
|
s32 Index;
|
||||||
|
video::SColor Color;
|
||||||
|
bool Loop;
|
||||||
|
bool Scale;
|
||||||
|
};
|
||||||
|
|
||||||
|
ButtonSprite ButtonSprites[gui::EGBS_COUNT];
|
||||||
|
gui::IGUISpriteBank* SpriteBank;
|
||||||
|
|
||||||
|
struct ButtonImage
|
||||||
|
{
|
||||||
|
ButtonImage() : Texture(0), SourceRect(core::rect<s32>(0,0,0,0))
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
ButtonImage(const ButtonImage& other) : Texture(0), SourceRect(core::rect<s32>(0,0,0,0))
|
||||||
|
{
|
||||||
|
*this = other;
|
||||||
|
}
|
||||||
|
|
||||||
|
~ButtonImage()
|
||||||
|
{
|
||||||
|
if ( Texture )
|
||||||
|
Texture->drop();
|
||||||
|
}
|
||||||
|
|
||||||
|
ButtonImage& operator=(const ButtonImage& other)
|
||||||
|
{
|
||||||
|
if ( this == &other )
|
||||||
|
return *this;
|
||||||
|
|
||||||
|
if (other.Texture)
|
||||||
|
other.Texture->grab();
|
||||||
|
if ( Texture )
|
||||||
|
Texture->drop();
|
||||||
|
Texture = other.Texture;
|
||||||
|
SourceRect = other.SourceRect;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool operator==(const ButtonImage& other) const
|
||||||
|
{
|
||||||
|
return Texture == other.Texture && SourceRect == other.SourceRect;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
video::ITexture* Texture;
|
||||||
|
core::rect<s32> SourceRect;
|
||||||
|
};
|
||||||
|
|
||||||
|
ButtonImage ButtonImages[gui::EGBIS_COUNT];
|
||||||
|
|
||||||
|
gui::IGUIFont* OverrideFont;
|
||||||
|
|
||||||
|
bool OverrideColorEnabled;
|
||||||
|
video::SColor OverrideColor;
|
||||||
|
|
||||||
|
u32 ClickTime, HoverTime, FocusTime;
|
||||||
|
|
||||||
|
bool ClickShiftState;
|
||||||
|
bool ClickControlState;
|
||||||
|
|
||||||
|
bool IsPushButton;
|
||||||
|
bool Pressed;
|
||||||
|
bool UseAlphaChannel;
|
||||||
|
bool DrawBorder;
|
||||||
|
bool ScaleImage;
|
||||||
|
|
||||||
|
video::SColor Colors[4];
|
||||||
|
};
|
@ -23,6 +23,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||||||
#include <iterator>
|
#include <iterator>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <limits>
|
#include <limits>
|
||||||
|
#include "guiButton.h"
|
||||||
#include "guiFormSpecMenu.h"
|
#include "guiFormSpecMenu.h"
|
||||||
#include "guiTable.h"
|
#include "guiTable.h"
|
||||||
#include "constants.h"
|
#include "constants.h"
|
||||||
@ -698,9 +699,8 @@ void GUIFormSpecMenu::parseButton(parserData* data, const std::string &element,
|
|||||||
spec.ftype = f_Button;
|
spec.ftype = f_Button;
|
||||||
if(type == "button_exit")
|
if(type == "button_exit")
|
||||||
spec.is_exit = true;
|
spec.is_exit = true;
|
||||||
gui::IGUIButton* e = Environment->addButton(rect, this, spec.fid,
|
|
||||||
spec.flabel.c_str());
|
|
||||||
|
|
||||||
|
GUIButton *e = GUIButton::addButton(Environment, rect, this, spec.fid, spec.flabel.c_str());
|
||||||
if (spec.fname == data->focused_fieldname) {
|
if (spec.fname == data->focused_fieldname) {
|
||||||
Environment->setFocus(e);
|
Environment->setFocus(e);
|
||||||
}
|
}
|
||||||
|
1084
src/gui/guiSkin.cpp
Normal file
1084
src/gui/guiSkin.cpp
Normal file
File diff suppressed because it is too large
Load Diff
376
src/gui/guiSkin.h
Normal file
376
src/gui/guiSkin.h
Normal file
@ -0,0 +1,376 @@
|
|||||||
|
// Copyright (C) 2002-2012 Nikolaus Gebhardt
|
||||||
|
// This file is part of the "Irrlicht Engine".
|
||||||
|
// For conditions of distribution and use, see copyright notice in irrlicht.h
|
||||||
|
|
||||||
|
#ifndef __GUI_SKIN_H_INCLUDED__
|
||||||
|
#define __GUI_SKIN_H_INCLUDED__
|
||||||
|
|
||||||
|
#include "IrrCompileConfig.h"
|
||||||
|
#ifdef _IRR_COMPILE_WITH_GUI_
|
||||||
|
|
||||||
|
#include "IGUISkin.h"
|
||||||
|
#include "irrString.h"
|
||||||
|
#include <string>
|
||||||
|
#include "ITexture.h"
|
||||||
|
|
||||||
|
namespace irr
|
||||||
|
{
|
||||||
|
namespace video
|
||||||
|
{
|
||||||
|
class IVideoDriver;
|
||||||
|
}
|
||||||
|
namespace gui
|
||||||
|
{
|
||||||
|
class GUISkin : public IGUISkin
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
GUISkin(EGUI_SKIN_TYPE type, video::IVideoDriver* driver);
|
||||||
|
|
||||||
|
//! destructor
|
||||||
|
virtual ~GUISkin();
|
||||||
|
|
||||||
|
//! returns default color
|
||||||
|
virtual video::SColor getColor(EGUI_DEFAULT_COLOR color) const;
|
||||||
|
|
||||||
|
//! sets a default color
|
||||||
|
virtual void setColor(EGUI_DEFAULT_COLOR which, video::SColor newColor);
|
||||||
|
|
||||||
|
//! returns size for the given size type
|
||||||
|
virtual s32 getSize(EGUI_DEFAULT_SIZE size) const;
|
||||||
|
|
||||||
|
//! sets a default size
|
||||||
|
virtual void setSize(EGUI_DEFAULT_SIZE which, s32 size);
|
||||||
|
|
||||||
|
//! returns the default font
|
||||||
|
virtual IGUIFont* getFont(EGUI_DEFAULT_FONT which=EGDF_DEFAULT) const;
|
||||||
|
|
||||||
|
//! sets a default font
|
||||||
|
virtual void setFont(IGUIFont* font, EGUI_DEFAULT_FONT which=EGDF_DEFAULT);
|
||||||
|
|
||||||
|
//! sets the sprite bank used for drawing icons
|
||||||
|
virtual void setSpriteBank(IGUISpriteBank* bank);
|
||||||
|
|
||||||
|
//! gets the sprite bank used for drawing icons
|
||||||
|
virtual IGUISpriteBank* getSpriteBank() const;
|
||||||
|
|
||||||
|
//! Returns a default icon
|
||||||
|
/** Returns the sprite index within the sprite bank */
|
||||||
|
virtual u32 getIcon(EGUI_DEFAULT_ICON icon) const;
|
||||||
|
|
||||||
|
//! Sets a default icon
|
||||||
|
/** Sets the sprite index used for drawing icons like arrows,
|
||||||
|
close buttons and ticks in checkboxes
|
||||||
|
\param icon: Enum specifying which icon to change
|
||||||
|
\param index: The sprite index used to draw this icon */
|
||||||
|
virtual void setIcon(EGUI_DEFAULT_ICON icon, u32 index);
|
||||||
|
|
||||||
|
//! Returns a default text.
|
||||||
|
/** For example for Message box button captions:
|
||||||
|
"OK", "Cancel", "Yes", "No" and so on. */
|
||||||
|
virtual const wchar_t* getDefaultText(EGUI_DEFAULT_TEXT text) const;
|
||||||
|
|
||||||
|
//! Sets a default text.
|
||||||
|
/** For example for Message box button captions:
|
||||||
|
"OK", "Cancel", "Yes", "No" and so on. */
|
||||||
|
virtual void setDefaultText(EGUI_DEFAULT_TEXT which, const wchar_t* newText);
|
||||||
|
|
||||||
|
//! draws a standard 3d button pane
|
||||||
|
/** Used for drawing for example buttons in normal state.
|
||||||
|
It uses the colors EGDC_3D_DARK_SHADOW, EGDC_3D_HIGH_LIGHT, EGDC_3D_SHADOW and
|
||||||
|
EGDC_3D_FACE for this. See EGUI_DEFAULT_COLOR for details.
|
||||||
|
\param rect: Defining area where to draw.
|
||||||
|
\param clip: Clip area.
|
||||||
|
\param element: Pointer to the element which wishes to draw this. This parameter
|
||||||
|
is usually not used by ISkin, but can be used for example by more complex
|
||||||
|
implementations to find out how to draw the part exactly. */
|
||||||
|
virtual void draw3DButtonPaneStandard(IGUIElement* element,
|
||||||
|
const core::rect<s32>& rect,
|
||||||
|
const core::rect<s32>* clip=0)
|
||||||
|
{
|
||||||
|
drawColored3DButtonPaneStandard(element, rect,clip);
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void drawColored3DButtonPaneStandard(IGUIElement* element,
|
||||||
|
const core::rect<s32>& rect,
|
||||||
|
const core::rect<s32>* clip=0,
|
||||||
|
const video::SColor* colors=0);
|
||||||
|
|
||||||
|
//! draws a pressed 3d button pane
|
||||||
|
/** Used for drawing for example buttons in pressed state.
|
||||||
|
It uses the colors EGDC_3D_DARK_SHADOW, EGDC_3D_HIGH_LIGHT, EGDC_3D_SHADOW and
|
||||||
|
EGDC_3D_FACE for this. See EGUI_DEFAULT_COLOR for details.
|
||||||
|
\param rect: Defining area where to draw.
|
||||||
|
\param clip: Clip area.
|
||||||
|
\param element: Pointer to the element which wishes to draw this. This parameter
|
||||||
|
is usually not used by ISkin, but can be used for example by more complex
|
||||||
|
implementations to find out how to draw the part exactly. */
|
||||||
|
virtual void draw3DButtonPanePressed(IGUIElement* element,
|
||||||
|
const core::rect<s32>& rect,
|
||||||
|
const core::rect<s32>* clip=0)
|
||||||
|
{
|
||||||
|
drawColored3DButtonPanePressed(element, rect, clip);
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void drawColored3DButtonPanePressed(IGUIElement* element,
|
||||||
|
const core::rect<s32>& rect,
|
||||||
|
const core::rect<s32>* clip=0,
|
||||||
|
const video::SColor* colors=0);
|
||||||
|
|
||||||
|
//! draws a sunken 3d pane
|
||||||
|
/** Used for drawing the background of edit, combo or check boxes.
|
||||||
|
\param element: Pointer to the element which wishes to draw this. This parameter
|
||||||
|
is usually not used by ISkin, but can be used for example by more complex
|
||||||
|
implementations to find out how to draw the part exactly.
|
||||||
|
\param bgcolor: Background color.
|
||||||
|
\param flat: Specifies if the sunken pane should be flat or displayed as sunken
|
||||||
|
deep into the ground.
|
||||||
|
\param rect: Defining area where to draw.
|
||||||
|
\param clip: Clip area. */
|
||||||
|
virtual void draw3DSunkenPane(IGUIElement* element,
|
||||||
|
video::SColor bgcolor, bool flat,
|
||||||
|
bool fillBackGround,
|
||||||
|
const core::rect<s32>& rect,
|
||||||
|
const core::rect<s32>* clip=0)
|
||||||
|
{
|
||||||
|
drawColored3DSunkenPane(element, bgcolor, flat, fillBackGround, rect, clip);
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void drawColored3DSunkenPane(IGUIElement* element,
|
||||||
|
video::SColor bgcolor, bool flat,
|
||||||
|
bool fillBackGround,
|
||||||
|
const core::rect<s32>& rect,
|
||||||
|
const core::rect<s32>* clip=0,
|
||||||
|
const video::SColor* colors=0);
|
||||||
|
|
||||||
|
//! draws a window background
|
||||||
|
/** Used for drawing the background of dialogs and windows.
|
||||||
|
\param element: Pointer to the element which wishes to draw this. This parameter
|
||||||
|
is usually not used by ISkin, but can be used for example by more complex
|
||||||
|
implementations to find out how to draw the part exactly.
|
||||||
|
\param titleBarColor: Title color.
|
||||||
|
\param drawTitleBar: True to enable title drawing.
|
||||||
|
\param rect: Defining area where to draw.
|
||||||
|
\param clip: Clip area.
|
||||||
|
\param checkClientArea: When set to non-null the function will not draw anything,
|
||||||
|
but will instead return the clientArea which can be used for drawing by the calling window.
|
||||||
|
That is the area without borders and without titlebar.
|
||||||
|
\return Returns rect where it would be good to draw title bar text. This will
|
||||||
|
work even when checkClientArea is set to a non-null value.*/
|
||||||
|
virtual core::rect<s32> draw3DWindowBackground(IGUIElement* element,
|
||||||
|
bool drawTitleBar, video::SColor titleBarColor,
|
||||||
|
const core::rect<s32>& rect,
|
||||||
|
const core::rect<s32>* clip,
|
||||||
|
core::rect<s32>* checkClientArea)
|
||||||
|
{
|
||||||
|
return drawColored3DWindowBackground(element, drawTitleBar, titleBarColor,
|
||||||
|
rect, clip, checkClientArea);
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual core::rect<s32> drawColored3DWindowBackground(IGUIElement* element,
|
||||||
|
bool drawTitleBar, video::SColor titleBarColor,
|
||||||
|
const core::rect<s32>& rect,
|
||||||
|
const core::rect<s32>* clip,
|
||||||
|
core::rect<s32>* checkClientArea,
|
||||||
|
const video::SColor* colors=0);
|
||||||
|
|
||||||
|
//! draws a standard 3d menu pane
|
||||||
|
/** Used for drawing for menus and context menus.
|
||||||
|
It uses the colors EGDC_3D_DARK_SHADOW, EGDC_3D_HIGH_LIGHT, EGDC_3D_SHADOW and
|
||||||
|
EGDC_3D_FACE for this. See EGUI_DEFAULT_COLOR for details.
|
||||||
|
\param element: Pointer to the element which wishes to draw this. This parameter
|
||||||
|
is usually not used by ISkin, but can be used for example by more complex
|
||||||
|
implementations to find out how to draw the part exactly.
|
||||||
|
\param rect: Defining area where to draw.
|
||||||
|
\param clip: Clip area. */
|
||||||
|
virtual void draw3DMenuPane(IGUIElement* element,
|
||||||
|
const core::rect<s32>& rect,
|
||||||
|
const core::rect<s32>* clip=0)
|
||||||
|
{
|
||||||
|
drawColored3DMenuPane(element, rect, clip);
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void drawColored3DMenuPane(IGUIElement* element,
|
||||||
|
const core::rect<s32>& rect,
|
||||||
|
const core::rect<s32>* clip=0,
|
||||||
|
const video::SColor* colors=0);
|
||||||
|
|
||||||
|
//! draws a standard 3d tool bar
|
||||||
|
/** Used for drawing for toolbars and menus.
|
||||||
|
\param element: Pointer to the element which wishes to draw this. This parameter
|
||||||
|
is usually not used by ISkin, but can be used for example by more complex
|
||||||
|
implementations to find out how to draw the part exactly.
|
||||||
|
\param rect: Defining area where to draw.
|
||||||
|
\param clip: Clip area. */
|
||||||
|
virtual void draw3DToolBar(IGUIElement* element,
|
||||||
|
const core::rect<s32>& rect,
|
||||||
|
const core::rect<s32>* clip=0)
|
||||||
|
{
|
||||||
|
drawColored3DToolBar(element, rect, clip);
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void drawColored3DToolBar(IGUIElement* element,
|
||||||
|
const core::rect<s32>& rect,
|
||||||
|
const core::rect<s32>* clip=0,
|
||||||
|
const video::SColor* colors=0);
|
||||||
|
|
||||||
|
//! draws a tab button
|
||||||
|
/** Used for drawing for tab buttons on top of tabs.
|
||||||
|
\param element: Pointer to the element which wishes to draw this. This parameter
|
||||||
|
is usually not used by ISkin, but can be used for example by more complex
|
||||||
|
implementations to find out how to draw the part exactly.
|
||||||
|
\param active: Specifies if the tab is currently active.
|
||||||
|
\param rect: Defining area where to draw.
|
||||||
|
\param clip: Clip area. */
|
||||||
|
virtual void draw3DTabButton(IGUIElement* element, bool active,
|
||||||
|
const core::rect<s32>& rect, const core::rect<s32>* clip=0, EGUI_ALIGNMENT alignment=EGUIA_UPPERLEFT)
|
||||||
|
{
|
||||||
|
drawColored3DTabButton(element, active, rect, clip, alignment);
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void drawColored3DTabButton(IGUIElement* element, bool active,
|
||||||
|
const core::rect<s32>& rect, const core::rect<s32>* clip=0, EGUI_ALIGNMENT alignment=EGUIA_UPPERLEFT,
|
||||||
|
const video::SColor* colors=0);
|
||||||
|
|
||||||
|
//! draws a tab control body
|
||||||
|
/** \param element: Pointer to the element which wishes to draw this. This parameter
|
||||||
|
is usually not used by ISkin, but can be used for example by more complex
|
||||||
|
implementations to find out how to draw the part exactly.
|
||||||
|
\param border: Specifies if the border should be drawn.
|
||||||
|
\param background: Specifies if the background should be drawn.
|
||||||
|
\param rect: Defining area where to draw.
|
||||||
|
\param clip: Clip area. */
|
||||||
|
virtual void draw3DTabBody(IGUIElement* element, bool border, bool background,
|
||||||
|
const core::rect<s32>& rect, const core::rect<s32>* clip=0, s32 tabHeight=-1, EGUI_ALIGNMENT alignment=EGUIA_UPPERLEFT)
|
||||||
|
{
|
||||||
|
drawColored3DTabBody(element, border, background, rect, clip, tabHeight, alignment);
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void drawColored3DTabBody(IGUIElement* element, bool border, bool background,
|
||||||
|
const core::rect<s32>& rect, const core::rect<s32>* clip=0, s32 tabHeight=-1, EGUI_ALIGNMENT alignment=EGUIA_UPPERLEFT,
|
||||||
|
const video::SColor* colors=0);
|
||||||
|
|
||||||
|
//! draws an icon, usually from the skin's sprite bank
|
||||||
|
/** \param element: Pointer to the element which wishes to draw this icon.
|
||||||
|
This parameter is usually not used by IGUISkin, but can be used for example
|
||||||
|
by more complex implementations to find out how to draw the part exactly.
|
||||||
|
\param icon: Specifies the icon to be drawn.
|
||||||
|
\param position: The position to draw the icon
|
||||||
|
\param starttime: The time at the start of the animation
|
||||||
|
\param currenttime: The present time, used to calculate the frame number
|
||||||
|
\param loop: Whether the animation should loop or not
|
||||||
|
\param clip: Clip area. */
|
||||||
|
virtual void drawIcon(IGUIElement* element, EGUI_DEFAULT_ICON icon,
|
||||||
|
const core::position2di position,
|
||||||
|
u32 starttime=0, u32 currenttime=0,
|
||||||
|
bool loop=false, const core::rect<s32>* clip=0)
|
||||||
|
{
|
||||||
|
drawColoredIcon(element, icon, position, starttime, currenttime, loop, clip);
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void drawColoredIcon(IGUIElement* element, EGUI_DEFAULT_ICON icon,
|
||||||
|
const core::position2di position,
|
||||||
|
u32 starttime=0, u32 currenttime=0,
|
||||||
|
bool loop=false, const core::rect<s32>* clip=0,
|
||||||
|
const video::SColor* colors=0);
|
||||||
|
|
||||||
|
//! draws a 2d rectangle.
|
||||||
|
/** \param element: Pointer to the element which wishes to draw this icon.
|
||||||
|
This parameter is usually not used by IGUISkin, but can be used for example
|
||||||
|
by more complex implementations to find out how to draw the part exactly.
|
||||||
|
\param color: Color of the rectangle to draw. The alpha component specifies how
|
||||||
|
transparent the rectangle will be.
|
||||||
|
\param pos: Position of the rectangle.
|
||||||
|
\param clip: Pointer to rectangle against which the rectangle will be clipped.
|
||||||
|
If the pointer is null, no clipping will be performed. */
|
||||||
|
virtual void draw2DRectangle(IGUIElement* element, const video::SColor &color,
|
||||||
|
const core::rect<s32>& pos, const core::rect<s32>* clip = 0);
|
||||||
|
|
||||||
|
|
||||||
|
//! get the type of this skin
|
||||||
|
virtual EGUI_SKIN_TYPE getType() const;
|
||||||
|
|
||||||
|
//! Writes attributes of the object.
|
||||||
|
//! Implement this to expose the attributes of your scene node animator for
|
||||||
|
//! scripting languages, editors, debuggers or xml serialization purposes.
|
||||||
|
virtual void serializeAttributes(io::IAttributes* out, io::SAttributeReadWriteOptions* options=0) const;
|
||||||
|
|
||||||
|
//! Reads attributes of the object.
|
||||||
|
//! Implement this to set the attributes of your scene node animator for
|
||||||
|
//! scripting languages, editors, debuggers or xml deserialization purposes.
|
||||||
|
virtual void deserializeAttributes(io::IAttributes* in, io::SAttributeReadWriteOptions* options=0);
|
||||||
|
|
||||||
|
//! gets the colors
|
||||||
|
virtual void getColors(video::SColor* colors); // ::PATCH:
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
video::SColor Colors[EGDC_COUNT];
|
||||||
|
s32 Sizes[EGDS_COUNT];
|
||||||
|
u32 Icons[EGDI_COUNT];
|
||||||
|
IGUIFont* Fonts[EGDF_COUNT];
|
||||||
|
IGUISpriteBank* SpriteBank;
|
||||||
|
core::stringw Texts[EGDT_COUNT];
|
||||||
|
video::IVideoDriver* Driver;
|
||||||
|
bool UseGradient;
|
||||||
|
|
||||||
|
EGUI_SKIN_TYPE Type;
|
||||||
|
};
|
||||||
|
|
||||||
|
#define set3DSkinColors(skin, button_color) \
|
||||||
|
{ \
|
||||||
|
skin->setColor(EGDC_3D_FACE, button_color); \
|
||||||
|
skin->setColor(EGDC_3D_DARK_SHADOW, button_color, 0.25f); \
|
||||||
|
skin->setColor(EGDC_3D_SHADOW, button_color, 0.5f); \
|
||||||
|
skin->setColor(EGDC_3D_LIGHT, button_color); \
|
||||||
|
skin->setColor(EGDC_3D_HIGH_LIGHT, button_color, 1.5f); \
|
||||||
|
}
|
||||||
|
|
||||||
|
#define getElementSkinColor(color) \
|
||||||
|
{ \
|
||||||
|
if (!Colors) \
|
||||||
|
{ \
|
||||||
|
IGUISkin* skin = Environment->getSkin(); \
|
||||||
|
if (skin) \
|
||||||
|
return skin->getColor(color); \
|
||||||
|
} \
|
||||||
|
return Colors[color]; \
|
||||||
|
}
|
||||||
|
|
||||||
|
#define setElementSkinColor(which, newColor, shading) \
|
||||||
|
{ \
|
||||||
|
if (!Colors) \
|
||||||
|
{ \
|
||||||
|
Colors = new video::SColor[EGDC_COUNT]; \
|
||||||
|
GUISkin* skin = (GUISkin *)Environment->getSkin(); \
|
||||||
|
if (skin) \
|
||||||
|
skin->getColors(Colors); \
|
||||||
|
} \
|
||||||
|
Colors[which] = newColor; \
|
||||||
|
setShading(Colors[which],shading); \
|
||||||
|
}
|
||||||
|
} // end namespace gui
|
||||||
|
//! Sets the shading
|
||||||
|
inline void setShading(video::SColor &color,f32 s) // :PATCH:
|
||||||
|
{
|
||||||
|
if (s < 1.0f)
|
||||||
|
{
|
||||||
|
color.setRed(color.getRed() * s);
|
||||||
|
color.setGreen(color.getGreen() * s);
|
||||||
|
color.setBlue(color.getBlue() * s);
|
||||||
|
}
|
||||||
|
else if (s > 1.0f)
|
||||||
|
{
|
||||||
|
s -= 1.0f;
|
||||||
|
|
||||||
|
color.setRed(color.getRed() + (255 - color.getRed()) * s);
|
||||||
|
color.setGreen(color.getGreen() + (255 - color.getGreen()) * s);
|
||||||
|
color.setBlue(color.getBlue() + (255 - color.getBlue()) * s);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} // end namespace irr
|
||||||
|
|
||||||
|
|
||||||
|
#endif // _IRR_COMPILE_WITH_GUI_
|
||||||
|
|
||||||
|
#endif
|
@ -155,6 +155,8 @@ src/genericobject.cpp
|
|||||||
src/genericobject.h
|
src/genericobject.h
|
||||||
src/gettext.cpp
|
src/gettext.cpp
|
||||||
src/gettext.h
|
src/gettext.h
|
||||||
|
src/gui/guiButton.cpp
|
||||||
|
src/gui/guiButton.h
|
||||||
src/gui/guiChatConsole.cpp
|
src/gui/guiChatConsole.cpp
|
||||||
src/gui/guiChatConsole.h
|
src/gui/guiChatConsole.h
|
||||||
src/gui/guiConfirmRegistration.cpp
|
src/gui/guiConfirmRegistration.cpp
|
||||||
@ -170,6 +172,8 @@ src/gui/guiPasswordChange.cpp
|
|||||||
src/gui/guiPathSelectMenu.cpp
|
src/gui/guiPathSelectMenu.cpp
|
||||||
src/gui/guiPathSelectMenu.h
|
src/gui/guiPathSelectMenu.h
|
||||||
src/gui/guiScrollBar.cpp
|
src/gui/guiScrollBar.cpp
|
||||||
|
src/gui/guiSkin.cpp
|
||||||
|
src/gui/guiSkin.h
|
||||||
src/gui/guiTable.cpp
|
src/gui/guiTable.cpp
|
||||||
src/gui/guiTable.h
|
src/gui/guiTable.h
|
||||||
src/gui/guiVolumeChange.cpp
|
src/gui/guiVolumeChange.cpp
|
||||||
|
Loading…
Reference in New Issue
Block a user