skin work (only in code, no visible change yet, but I'm preparing the way for visible changes :] )
git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/branches/irrlicht@3372 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
@@ -11,6 +11,8 @@ main_race.png created by Andreas Bilng (c) 2008, with Tuxicon by Enrico Billing
|
||||
|
||||
mode_normal.png released under CC-BY-SA 3.0, based on work by MiniBjorn
|
||||
|
||||
FIXME - background.jpg is NOT under an appropriate license, replace
|
||||
|
||||
FIXME - fonthaettenschweiler.bmp, gnu.png, kart*.png?, track*.png are temporary and should be [re]moved
|
||||
|
||||
FIXME - mode_ftl.png has an unclear license, it combines a GPL kart and a CC kart. How does those licenses deal with this?
|
||||
|
||||
176
src/gui/skin.cpp
176
src/gui/skin.cpp
@@ -26,98 +26,156 @@ Skin::~Skin()
|
||||
*/
|
||||
void Skin::draw2DRectangle (IGUIElement *element, const video::SColor &color, const core::rect< s32 > &pos, const core::rect< s32 > *clip)
|
||||
{
|
||||
|
||||
|
||||
// scrollbar backgound
|
||||
|
||||
//printf("draw rectangle\n");
|
||||
GUIEngine::getDriver()->draw2DRectangle( SColor(255, 0, 150, 150), pos );
|
||||
}
|
||||
|
||||
void Skin::draw3DButtonPanePressed (IGUIElement *element, const core::rect< s32 > &rect, const core::rect< s32 > *clip)
|
||||
void Skin::drawButton(const core::rect< s32 > &rect, const bool pressed, const bool focused)
|
||||
{
|
||||
const bool focused = GUIEngine::getGUIEnv()->hasFocus(element);
|
||||
|
||||
if(focused)
|
||||
GUIEngine::getDriver()->draw2DRectangle( SColor(255, 100, 0, 0), rect );
|
||||
else
|
||||
GUIEngine::getDriver()->draw2DRectangle( SColor(255, 0, 100, 0), rect );
|
||||
}
|
||||
|
||||
void Skin::draw3DButtonPaneStandard (IGUIElement *element, const core::rect< s32 > &rect, const core::rect< s32 > *clip)
|
||||
void Skin::drawRibbon(const core::rect< s32 > &rect, const Widget* widget, const bool pressed, bool focused)
|
||||
{
|
||||
//printf("draw 3D button pane\n");
|
||||
bool focused = GUIEngine::getGUIEnv()->hasFocus(element);
|
||||
bool draw_border = focused;
|
||||
|
||||
bool draw_border = true;
|
||||
bool mark_selected = false;
|
||||
|
||||
// buttons are used for other uses than plain clickable buttons because irrLicht
|
||||
// does not have widgets for everything we need. so at render time, we just check
|
||||
// which type this button represents and set render options accordingly
|
||||
if(element->getType() == EGUIET_BUTTON)
|
||||
// check if one of its children has focus (will happen when directly clicking on them)
|
||||
const int amount = widget->m_children.size();
|
||||
for(int n=0; n<amount; n++)
|
||||
{
|
||||
const int id = element->getID();
|
||||
if(id != -1)
|
||||
if(GUIEngine::getGUIEnv()->hasFocus(widget->m_children[n].m_element))
|
||||
{
|
||||
//std::cout << "searching for a widget in screen " << GUIEngine::getCurrentScreen()->getName().c_str() << std::endl;
|
||||
Widget* widget = GUIEngine::getCurrentScreen()->getWidget(id);
|
||||
|
||||
if(widget != NULL)
|
||||
{
|
||||
// don't draw border around bitmaps
|
||||
if(widget->m_type == WTYPE_ICON_BUTTON && !focused) draw_border = false;
|
||||
|
||||
// draw border around ribbon only if focused.
|
||||
if(widget->m_type == WTYPE_RIBBON && !focused) draw_border = false;
|
||||
|
||||
// check if one of its children has focus (will happen when directly clicking on them)
|
||||
if(widget->m_type == WTYPE_RIBBON)
|
||||
{
|
||||
const int amount = widget->m_children.size();
|
||||
for(int n=0; n<amount; n++)
|
||||
{
|
||||
if(GUIEngine::getGUIEnv()->hasFocus(widget->m_children[n].m_element))
|
||||
{
|
||||
draw_border = true;
|
||||
focused = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// for ribbon children
|
||||
if(widget->isSelected()) mark_selected = true;
|
||||
if(widget->m_parent != NULL && widget->m_parent->m_type == WTYPE_RIBBON &&
|
||||
((RibbonWidget*)widget->m_parent)->getRibbonType() == RIBBON_TOOLBAR &&
|
||||
!GUIEngine::getGUIEnv()->hasFocus(widget->m_parent->m_element)) mark_selected = false;
|
||||
}
|
||||
draw_border = true;
|
||||
focused = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(!draw_border && !mark_selected) return;
|
||||
|
||||
if(mark_selected)
|
||||
if(!draw_border) return;
|
||||
|
||||
if(focused)
|
||||
GUIEngine::getDriver()->draw2DRectangle( SColor(255, 150, 0, 0), rect );
|
||||
else
|
||||
GUIEngine::getDriver()->draw2DRectangle( SColor(255, 0, 150, 0), rect );
|
||||
}
|
||||
|
||||
void Skin::drawRibbonChild(const core::rect< s32 > &rect, const Widget* widget, const bool pressed, bool focused)
|
||||
{
|
||||
bool mark_selected = widget->isSelected();
|
||||
|
||||
if(widget->m_type == WTYPE_BUTTON)
|
||||
{
|
||||
const core::rect< s32 > rect2 = core::rect< s32 >(rect.UpperLeftCorner.X - 5, rect.UpperLeftCorner.Y - 5,
|
||||
rect.UpperLeftCorner.X + rect.getWidth() + 5,
|
||||
rect.UpperLeftCorner.Y + rect.getHeight() + 5);
|
||||
GUIEngine::getDriver()->draw2DRectangle( SColor(2555, 0, 175, 255), rect2 );
|
||||
// ribbons containing buttons are actually tabs
|
||||
if(mark_selected)
|
||||
GUIEngine::getDriver()->draw2DRectangle( SColor(255, 0, 150, 150), rect );
|
||||
else
|
||||
GUIEngine::getDriver()->draw2DRectangle( SColor(255, 150, 0, 0), rect );
|
||||
}
|
||||
else
|
||||
{
|
||||
if(widget->m_parent != NULL && widget->m_parent->m_type == WTYPE_RIBBON &&
|
||||
((RibbonWidget*)widget->m_parent)->getRibbonType() == RIBBON_TOOLBAR &&
|
||||
!GUIEngine::getGUIEnv()->hasFocus(widget->m_parent->m_element)) mark_selected = false;
|
||||
|
||||
if(mark_selected)
|
||||
{
|
||||
const core::rect< s32 > rect2 = core::rect< s32 >(rect.UpperLeftCorner.X - 5, rect.UpperLeftCorner.Y - 5,
|
||||
rect.UpperLeftCorner.X + rect.getWidth() + 5,
|
||||
rect.UpperLeftCorner.Y + rect.getHeight() + 5);
|
||||
GUIEngine::getDriver()->draw2DRectangle( SColor(2555, 0, 175, 255), rect2 );
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void Skin::drawSpinnerBody(const core::rect< s32 > &rect, const Widget* widget, const bool pressed, const bool focused)
|
||||
{
|
||||
if(focused)
|
||||
GUIEngine::getDriver()->draw2DRectangle( SColor(255, 255, 0, 0), rect );
|
||||
else
|
||||
GUIEngine::getDriver()->draw2DRectangle( SColor(255, 150, 0, 0), rect );
|
||||
}
|
||||
|
||||
void Skin::drawSpinnerChild(const core::rect< s32 > &rect, const Widget* widget, const bool pressed, bool focused)
|
||||
{
|
||||
if(pressed)
|
||||
GUIEngine::getDriver()->draw2DRectangle( SColor(255, 255, 0, 0), rect );
|
||||
else if(focused)
|
||||
GUIEngine::getDriver()->draw2DRectangle( SColor(255, 150, 0, 0), rect );
|
||||
else
|
||||
GUIEngine::getDriver()->draw2DRectangle( SColor(255, 0, 150, 0), rect );
|
||||
}
|
||||
|
||||
void Skin::process3DPane(IGUIElement *element, const core::rect< s32 > &rect, const bool pressed)
|
||||
{
|
||||
const bool focused = GUIEngine::getGUIEnv()->hasFocus(element);
|
||||
|
||||
const int id = element->getID();
|
||||
|
||||
//std::cout << "searching for a widget in screen " << GUIEngine::getCurrentScreen()->getName().c_str() << std::endl;
|
||||
Widget* widget = GUIEngine::getCurrentScreen()->getWidget(id);
|
||||
|
||||
if(widget == NULL) return;
|
||||
|
||||
const WidgetType type = widget->m_type;
|
||||
|
||||
|
||||
// buttons are used for other uses than plain clickable buttons because irrLicht
|
||||
// does not have widgets for everything we need. so at render time, we just check
|
||||
// which type this button represents and render accordingly
|
||||
|
||||
if(widget->m_parent != NULL && widget->m_parent->m_type == WTYPE_RIBBON)
|
||||
{
|
||||
drawRibbonChild(rect, widget, pressed /* pressed */, true /* focused */);
|
||||
}
|
||||
else if(widget->m_parent != NULL && widget->m_parent->m_type == WTYPE_SPINNER)
|
||||
{
|
||||
drawSpinnerChild(rect, widget, pressed /* pressed */, true /* focused */);
|
||||
}
|
||||
else if(type == WTYPE_ICON_BUTTON)
|
||||
{
|
||||
if(!focused) return; /* don't draw any border in this case */
|
||||
else drawButton(rect, pressed /* pressed */, true /* focused */);
|
||||
}
|
||||
else if(type == WTYPE_BUTTON)
|
||||
{
|
||||
drawButton(rect, pressed, focused);
|
||||
}
|
||||
else if(type == WTYPE_RIBBON)
|
||||
{
|
||||
drawRibbon(rect, widget, pressed, focused);
|
||||
}
|
||||
else if(widget->m_type == WTYPE_SPINNER)
|
||||
{
|
||||
drawSpinnerBody(rect, widget, pressed, focused);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void Skin::draw3DButtonPanePressed (IGUIElement *element, const core::rect< s32 > &rect, const core::rect< s32 > *clip)
|
||||
{
|
||||
process3DPane(element, rect, true /* pressed */ );
|
||||
}
|
||||
|
||||
void Skin::draw3DButtonPaneStandard (IGUIElement *element, const core::rect< s32 > &rect, const core::rect< s32 > *clip)
|
||||
{
|
||||
process3DPane(element, rect, false /* pressed */ );
|
||||
}
|
||||
|
||||
void Skin::draw3DMenuPane (IGUIElement *element, const core::rect< s32 > &rect, const core::rect< s32 > *clip)
|
||||
{
|
||||
//printf("draw menu pane\n");
|
||||
//printf("draw menu pane\n");
|
||||
}
|
||||
|
||||
void Skin::draw3DSunkenPane (IGUIElement *element, video::SColor bgcolor, bool flat, bool fillBackGround, const core::rect< s32 > &rect, const core::rect< s32 > *clip)
|
||||
{
|
||||
// e.g. the checkbox square
|
||||
//printf("draw sunken pane\n");
|
||||
//printf("draw sunken pane\n");
|
||||
const bool focused = GUIEngine::getGUIEnv()->getFocus() == element;
|
||||
|
||||
if(focused)
|
||||
@@ -128,7 +186,7 @@ void Skin::draw3DSunkenPane (IGUIElement *element, video::SColor bgcolor, bool f
|
||||
|
||||
void Skin::draw3DTabBody (IGUIElement *element, bool border, bool background, const core::rect< s32 > &rect, const core::rect< s32 > *clip, s32 tabHeight, gui::EGUI_ALIGNMENT alignment)
|
||||
{
|
||||
//printf("draw tab body\n");
|
||||
//printf("draw tab body\n");
|
||||
}
|
||||
|
||||
void Skin::draw3DTabButton (IGUIElement *element, bool active, const core::rect< s32 > &rect, const core::rect< s32 > *clip, gui::EGUI_ALIGNMENT alignment)
|
||||
|
||||
@@ -12,6 +12,8 @@ using namespace gui;
|
||||
namespace GUIEngine
|
||||
{
|
||||
|
||||
class Widget;
|
||||
|
||||
class Skin : public IGUISkin
|
||||
{
|
||||
IGUISkin* m_fallback_skin;
|
||||
@@ -19,50 +21,37 @@ public:
|
||||
Skin(IGUISkin* fallback_skin);
|
||||
~Skin();
|
||||
|
||||
// my utility methods, to work around irrlicht's very Windows-95-like-look-enforcing skin system
|
||||
void process3DPane(IGUIElement *element, const core::rect< s32 > &rect, const bool pressed);
|
||||
void drawButton(const core::rect< s32 > &rect, const bool pressed, const bool focused);
|
||||
void drawRibbon(const core::rect< s32 > &rect, const Widget* widget, const bool pressed, bool focused);
|
||||
void drawRibbonChild(const core::rect< s32 > &rect, const Widget* widget, const bool pressed, bool focused);
|
||||
void drawSpinnerChild(const core::rect< s32 > &rect, const Widget* widget, const bool pressed, bool focused);
|
||||
void drawSpinnerBody(const core::rect< s32 > &rect, const Widget* widget, const bool pressed, const bool focused);
|
||||
|
||||
// irrlicht's callbacks
|
||||
virtual void draw2DRectangle (IGUIElement *element, const video::SColor &color, const core::rect< s32 > &pos, const core::rect< s32 > *clip);
|
||||
|
||||
virtual void draw3DButtonPanePressed (IGUIElement *element, const core::rect< s32 > &rect, const core::rect< s32 > *clip);
|
||||
|
||||
virtual void draw3DButtonPaneStandard (IGUIElement *element, const core::rect< s32 > &rect, const core::rect< s32 > *clip);
|
||||
|
||||
virtual void draw3DMenuPane (IGUIElement *element, const core::rect< s32 > &rect, const core::rect< s32 > *clip);
|
||||
|
||||
virtual void draw3DSunkenPane (IGUIElement *element, video::SColor bgcolor, bool flat, bool fillBackGround, const core::rect< s32 > &rect, const core::rect< s32 > *clip);
|
||||
|
||||
virtual void draw3DTabBody (IGUIElement *element, bool border, bool background, const core::rect< s32 > &rect, const core::rect< s32 > *clip, s32 tabHeight=-1, gui::EGUI_ALIGNMENT alignment=EGUIA_UPPERLEFT);
|
||||
|
||||
virtual void draw3DTabButton (IGUIElement *element, bool active, const core::rect< s32 > &rect, const core::rect< s32 > *clip, gui::EGUI_ALIGNMENT alignment=EGUIA_UPPERLEFT);
|
||||
|
||||
virtual void draw3DToolBar (IGUIElement *element, const core::rect< s32 > &rect, const core::rect< s32 > *clip);
|
||||
|
||||
virtual core::rect< s32 > draw3DWindowBackground (IGUIElement *element, bool drawTitleBar, video::SColor titleBarColor, const core::rect< s32 > &rect, const core::rect< s32 > *clip);
|
||||
|
||||
virtual void drawIcon (IGUIElement *element, EGUI_DEFAULT_ICON icon, const core::position2di position, u32 starttime, u32 currenttime, bool loop=false, const core::rect< s32 > *clip=NULL);
|
||||
|
||||
virtual video::SColor getColor (EGUI_DEFAULT_COLOR color) const;
|
||||
|
||||
virtual const wchar_t * getDefaultText (EGUI_DEFAULT_TEXT text) const;
|
||||
|
||||
virtual IGUIFont * getFont (EGUI_DEFAULT_FONT which=EGDF_DEFAULT) const ;
|
||||
|
||||
virtual u32 getIcon (EGUI_DEFAULT_ICON icon) const ;
|
||||
|
||||
virtual s32 getSize (EGUI_DEFAULT_SIZE size) const ;
|
||||
|
||||
virtual IGUISpriteBank * getSpriteBank () const ;
|
||||
|
||||
//virtual EGUI_SKIN_TYPE getType () const;
|
||||
|
||||
virtual void setColor (EGUI_DEFAULT_COLOR which, video::SColor newColor);
|
||||
|
||||
virtual void setDefaultText (EGUI_DEFAULT_TEXT which, const wchar_t *newText);
|
||||
|
||||
virtual void setFont (IGUIFont *font, EGUI_DEFAULT_FONT which=EGDF_DEFAULT);
|
||||
|
||||
virtual void setIcon (EGUI_DEFAULT_ICON icon, u32 index);
|
||||
|
||||
virtual void setSize (EGUI_DEFAULT_SIZE which, s32 size);
|
||||
|
||||
virtual void setSpriteBank (IGUISpriteBank *bank);
|
||||
|
||||
};
|
||||
|
||||
@@ -424,7 +424,6 @@ namespace StateManager
|
||||
|
||||
std::cout << "-- switching to screen " << g_menu_stack[g_menu_stack.size()-1].c_str() << std::endl;
|
||||
GUIEngine::switchToScreen(g_menu_stack[g_menu_stack.size()-1].c_str());
|
||||
std::cout << "-- switched to screen " << g_menu_stack[g_menu_stack.size()-1].c_str() << std::endl;
|
||||
|
||||
eventCallback(NULL, g_init_event);
|
||||
}
|
||||
|
||||
@@ -612,6 +612,7 @@ void SpinnerWidget::add()
|
||||
rect<s32> subsize_left_arrow = rect<s32>(0 ,0, h, h);
|
||||
IGUIButton * left_arrow = GUIEngine::getGUIEnv()->addButton(subsize_left_arrow, btn, ++id_counter_2, L"<<");
|
||||
m_children[0].m_element = left_arrow;
|
||||
m_children[0].m_type = WTYPE_BUTTON;
|
||||
left_arrow->setTabStop(false);
|
||||
m_children[0].m_parent = this;
|
||||
m_children[0].m_properties[PROP_ID] = "left";
|
||||
@@ -631,6 +632,7 @@ void SpinnerWidget::add()
|
||||
//IGUIButton* subbtn = GUIEngine::getGUIEnv()->addButton(subsize_label, btn, ++id_counter_2, L"");
|
||||
IGUIImage * subbtn = GUIEngine::getGUIEnv()->addImage(subsize_label, btn, ++id_counter_2);
|
||||
m_children[1].m_element = subbtn;
|
||||
m_children[1].m_type = WTYPE_ICON_BUTTON;
|
||||
subbtn->setUseAlphaChannel(true);
|
||||
|
||||
subbtn->setImage(texture);
|
||||
@@ -641,6 +643,7 @@ void SpinnerWidget::add()
|
||||
rect<s32> subsize_label = rect<s32>(h, 0, w-h, h);
|
||||
IGUIStaticText* label = GUIEngine::getGUIEnv()->addStaticText(stringw(m_value).c_str(), subsize_label, false, true, btn);
|
||||
m_children[1].m_element = label;
|
||||
m_children[1].m_type = WTYPE_LABEL;
|
||||
label->setTextAlignment(EGUIA_CENTER, EGUIA_CENTER);
|
||||
label->setTabStop(false);
|
||||
label->setNotClipped(true);
|
||||
@@ -652,6 +655,7 @@ void SpinnerWidget::add()
|
||||
IGUIButton * right_arrow = GUIEngine::getGUIEnv()->addButton(subsize_right_arrow, btn, ++id_counter_2, L">>");
|
||||
right_arrow->setTabStop(false);
|
||||
m_children[2].m_element = right_arrow;
|
||||
m_children[2].m_type = WTYPE_BUTTON;
|
||||
m_children[2].m_parent = this;
|
||||
m_children[2].m_properties[PROP_ID] = "right";
|
||||
m_children[2].id = m_children[2].m_element->getID();
|
||||
@@ -796,6 +800,7 @@ void RibbonGridWidget::add()
|
||||
// create sub-widgets if they don't already exist
|
||||
//if(m_left_widget == NULL)
|
||||
//{
|
||||
// FIXME - memory leak, irrlicht will probably delete its own widget; I don't delete mine however.
|
||||
m_left_widget = new Widget();
|
||||
m_right_widget = new Widget();
|
||||
//}
|
||||
|
||||
Reference in New Issue
Block a user