highlight ribbon arrows as requested by Joerg

git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@8594 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
auria
2011-05-15 23:08:15 +00:00
parent 41bded8917
commit 2ed8f0f6d2
20 changed files with 110 additions and 23 deletions

View File

@@ -2,6 +2,7 @@
Glass skin by Marianne Gagnon, released under creative-commons BY-SA 3.0+
Except background.jpg, by elisee
Except left_arrow and right_arrow by Dakal
To make your own skin, I suggest simply duplicating this file and modifying it as needed.
There are two types of images : some will be simply stretched as a whole, others will
@@ -171,6 +172,11 @@ when the border that intersect at this corner are enabled.
<element type="scrollbar_button" image="glass/scrollbar_btn.png" />
<element type="scrollbar_button" state="down" image="glass/scrollbar_btn_down.png" />
<element type="left_arrow" state="neutrual" image="glass/left_arrow.png" />
<element type="right_arrow" state="neutrual" image="glass/right_arrow.png" />
<element type="left_arrow" state="focus" image="glass/left_arrow_focus.png" />
<element type="right_arrow" state="focus" image="glass/right_arrow_focus.png" />
<!-- Stateless -->
<element type="section" image="glass/glass_section.png"
left_border="15" right_border="15" top_border="15" bottom_border="15"

View File

@@ -171,6 +171,11 @@ when the border that intersect at this corner are enabled.
<element type="scrollbar_button" image="ocean/scrollbar_btn.png" />
<element type="scrollbar_button" state="down" image="ocean/scrollbar_btn_down.png" />
<element type="left_arrow" state="neutral" image="ocean/left_arrow.png" />
<element type="right_arrow" state="neutral" image="ocean/right_arrow.png" />
<element type="left_arrow" state="focus" image="ocean/left_arrow_focus.png" />
<element type="right_arrow" state="focus" image="ocean/right_arrow_focus.png" />
<!-- Stateless -->
<element type="section" image="ocean/glass_section.png"
left_border="15" right_border="15" top_border="15" bottom_border="15"

View File

@@ -171,6 +171,11 @@ when the border that intersect at this corner are enabled.
<element type="scrollbar_button" image="peach/scrollbar_btn.png" />
<element type="scrollbar_button" state="down" image="peach/scrollbar_btn_down.png" />
<element type="left_arrow" state="neutral" image="peach/left_arrow.png" />
<element type="right_arrow" state="neutral" image="peach/right_arrow.png" />
<element type="left_arrow" state="focus" image="peach/left_arrow_focus.png" />
<element type="right_arrow" state="focus" image="peach/right_arrow_focus.png" />
<!-- Stateless -->
<element type="section" image="peach/glass_section.png"
left_border="15" right_border="15" top_border="15" bottom_border="15"

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.0 KiB

View File

@@ -1174,7 +1174,15 @@ void Skin::drawIconButton(const core::rect< s32 > &rect, Widget* widget, const b
}
else
{
GUIEngine::getDriver()->draw2DImage(icon_widget->m_texture, sized_rect,
video::ITexture* t = icon_widget->m_texture;
const bool mouseInside = rect.isPointInside(irr_driver->getDevice()->getCursorControl()->getPosition());
if (icon_widget->m_highlight_texture != NULL && (focused || mouseInside))
{
t = icon_widget->m_highlight_texture;
}
GUIEngine::getDriver()->draw2DImage(t, sized_rect,
core::rect<s32>(0,0,icon_widget->m_texture_w, icon_widget->m_texture_h),
0 /* no clipping */, 0, true /* alpha */);
}
@@ -1834,6 +1842,14 @@ void Skin::draw3DToolBar (IGUIElement *element, const core::rect< s32 > &rect, c
// -----------------------------------------------------------------------------
ITexture* Skin::getImage(const char* name)
{
BoxRenderParams& p = SkinConfig::m_render_params[name];
return p.getImage();
}
// -----------------------------------------------------------------------------
void Skin::drawIcon (IGUIElement *element, EGUI_DEFAULT_ICON icon, const core::position2di position, u32 starttime, u32 currenttime, bool loop, const core::rect< s32 > *clip)
{
// we won't let irrLicht decide when to call this, we draw them ourselves.

View File

@@ -325,6 +325,8 @@ namespace GUIEngine
void drawTooltips();
irr::video::ITexture* getImage(const char* name);
static irr::video::SColor getColor(const std::string name);
};

View File

@@ -636,6 +636,8 @@ namespace GUIEngine
/**
* \}
*/
bool ok() const { return (m_magic_number == 0xCAFEC001); }
};

View File

@@ -15,6 +15,7 @@
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "graphics/irr_driver.hpp"
#include "guiengine/engine.hpp"
#include "guiengine/widgets/dynamic_ribbon_widget.hpp"
#include "io/file_manager.hpp"
@@ -131,11 +132,11 @@ void DynamicRibbonWidget::add()
delete m_left_widget;
delete m_right_widget;
}
m_left_widget = new Widget(WTYPE_NONE);
m_right_widget = new Widget(WTYPE_NONE);
m_left_widget = new IconButtonWidget(IconButtonWidget::SCALE_MODE_KEEP_TEXTURE_ASPECT_RATIO, false);
m_right_widget = new IconButtonWidget(IconButtonWidget::SCALE_MODE_KEEP_TEXTURE_ASPECT_RATIO, false);
const int average_y = m_y + (m_h - m_label_height)/2;
m_arrows_w = 30;
m_arrows_w = 40;
const int button_h = 50;
// right arrow
@@ -143,14 +144,27 @@ void DynamicRibbonWidget::add()
average_y - button_h/2,
m_x + m_w,
average_y + button_h/2);
/*
stringw rmessage = ">>";
IGUIButton* right_arrow = GUIEngine::getGUIEnv()->addButton(right_arrow_location, NULL, getNewNoFocusID(), rmessage.c_str(), L"");
IGUIButton* right_arrow = GUIEngine::getGUIEnv()->addButton(right_arrow_location, NULL, getNewNoFocusID());//, rmessage.c_str(), L"");
right_arrow->setTabStop(false);
m_right_widget->m_element = right_arrow;
right_arrow->setImage( GUIEngine::getSkin()->getImage("right_arrow::neutral") );
right_arrow->setScaleImage(true);
right_arrow->setUseAlphaChannel(true);
*/
//m_right_widget->m_element = right_arrow;
m_right_widget->m_x = right_arrow_location.UpperLeftCorner.X;
m_right_widget->m_y = right_arrow_location.UpperLeftCorner.Y;
m_right_widget->m_w = right_arrow_location.getWidth();
m_right_widget->m_h = right_arrow_location.getHeight();
m_right_widget->m_event_handler = this;
m_right_widget->m_focusable = false;
m_right_widget->m_properties[PROP_ID] = "right";
m_right_widget->m_id = right_arrow->getID();
//m_right_widget->m_id = right_arrow->getID();
m_right_widget->setImage(GUIEngine::getSkin()->getImage("right_arrow::neutral"));
m_right_widget->add();
m_right_widget->setHighlightedImage(GUIEngine::getSkin()->getImage("right_arrow::focus"));
m_children.push_back( m_right_widget );
// left arrow
@@ -159,15 +173,30 @@ void DynamicRibbonWidget::add()
m_x + m_arrows_w,
average_y + button_h/2);
stringw lmessage = "<<";
IGUIButton* left_arrow = GUIEngine::getGUIEnv()->addButton(left_arrow_location, NULL, getNewNoFocusID(), lmessage.c_str(), L"");
left_arrow->setTabStop(false);
m_left_widget->m_element = left_arrow;
//IGUIButton* left_arrow = GUIEngine::getGUIEnv()->addButton(left_arrow_location, NULL, getNewNoFocusID()); //, lmessage.c_str(), L"");
//left_arrow->setTabStop(false);
//left_arrow->setImage( GUIEngine::getSkin()->getImage("left_arrow::neutral") );
//left_arrow->setScaleImage(true);
//left_arrow->setUseAlphaChannel(true);
//m_left_widget->m_element = left_arrow;
m_left_widget->m_x = left_arrow_location.UpperLeftCorner.X;
m_left_widget->m_y = left_arrow_location.UpperLeftCorner.Y;
m_left_widget->m_w = left_arrow_location.getWidth();
m_left_widget->m_h = left_arrow_location.getHeight();
m_left_widget->m_event_handler = this;
m_left_widget->m_focusable = false;
m_left_widget->m_properties[PROP_ID] = "left";
m_left_widget->m_id = left_arrow->getID();
//m_left_widget->m_id = left_arrow->getID();
m_left_widget->setImage( GUIEngine::getSkin()->getImage("left_arrow::neutral") );
m_left_widget->add();
m_left_widget->setHighlightedImage(GUIEngine::getSkin()->getImage("left_arrow::focus"));
m_children.push_back( m_left_widget );
assert( m_left_widget->ok() );
assert( m_right_widget->ok() );
m_left_widget->m_element->setVisible(true);
// ---- Determine number of rows
// Find children size (and ratio)
@@ -251,6 +280,10 @@ void DynamicRibbonWidget::add()
m_row_amount = 1;
}
assert( m_left_widget->ok() );
assert( m_right_widget->ok() );
m_left_widget->m_element->setVisible(true);
// get and build a list of IDs (by now we may not yet know everything about items,
// but we need to get IDs *now* in order for tabbing to work.
m_ids.resize(m_row_amount);
@@ -281,12 +314,15 @@ void DynamicRibbonWidget::buildInternalStructure()
}
m_rows.clearWithoutDeleting(); // rows already deleted above, don't double-delete
m_left_widget->m_element->setVisible(true);
assert( m_left_widget->ok() );
assert( m_right_widget->ok() );
// ---- determine column amount
const float row_height = (float)(m_h - m_label_height)/(float)m_row_amount;
float ratio_zoom = (float)row_height / (float)(m_child_height - m_label_height);
m_col_amount = (int)round( m_w / ( m_child_width*ratio_zoom ) );
// ajust column amount to not add more item slots than we actually need
const int item_count = m_items.size();
//std::cout << "item_count=" << item_count << ", row_amount*m_col_amount=" << m_row_amount*m_col_amount << std::endl;
@@ -295,7 +331,10 @@ void DynamicRibbonWidget::buildInternalStructure()
m_col_amount = (int)ceil((float)item_count/(float)m_row_amount);
//std::cout << "Adjusting m_col_amount to be " << m_col_amount << std::endl;
}
assert( m_left_widget->ok() );
assert( m_right_widget->ok() );
// Hide arrows when everything is visible
if (item_count <= m_row_amount*m_col_amount)
{

View File

@@ -28,6 +28,8 @@
namespace GUIEngine
{
class IconButtonWidget;
/**
* Even if you have a ribbon that only acts on click/enter, you may wish to know which
* item is currently highlighted. In this case, create a listener and pass it to the ribbon.
@@ -129,8 +131,8 @@ namespace GUIEngine
bool m_combo;
/* reference pointers only, the actual instances are owned by m_children */
Widget* m_left_widget;
Widget* m_right_widget;
IconButtonWidget* m_left_widget;
IconButtonWidget* m_right_widget;
/** Returns the currently selected row */
RibbonWidget* getSelectedRibbon(const int playerID);

View File

@@ -33,6 +33,7 @@ IconButtonWidget::IconButtonWidget(ScaleMode scale_mode, const bool tab_stop,
{
m_label = NULL;
m_texture = NULL;
m_highlight_texture = NULL;
m_custom_aspect_ratio = 1.0f;
m_tab_stop = tab_stop;
@@ -45,14 +46,17 @@ IconButtonWidget::IconButtonWidget(ScaleMode scale_mode, const bool tab_stop,
void IconButtonWidget::add()
{
// ---- Icon
if (m_icon_path_type == ICON_PATH_TYPE_ABSOLUTE)
if (m_texture == NULL)
{
m_texture = irr_driver->getTexture(m_properties[PROP_ICON].c_str());
}
else if (m_icon_path_type == ICON_PATH_TYPE_RELATIVE)
{
m_texture = irr_driver->getTexture((file_manager->getDataDir() + "/" +
m_properties[PROP_ICON]).c_str());
if (m_icon_path_type == ICON_PATH_TYPE_ABSOLUTE)
{
m_texture = irr_driver->getTexture(m_properties[PROP_ICON].c_str());
}
else if (m_icon_path_type == ICON_PATH_TYPE_RELATIVE)
{
m_texture = irr_driver->getTexture((file_manager->getDataDir() + "/" +
m_properties[PROP_ICON]).c_str());
}
}
if (m_texture == NULL)
@@ -60,7 +64,6 @@ void IconButtonWidget::add()
std::cerr << "IconButtonWidget::add() : error, cannot find texture "
<< m_properties[PROP_ICON].c_str() << std::endl;
m_texture = irr_driver->getTexture((file_manager->getDataDir() + "/gui/main_help.png").c_str());
return;
}
m_texture_w = m_texture->getSize().Width;
m_texture_h = m_texture->getSize().Height;

View File

@@ -57,6 +57,8 @@ namespace GUIEngine
irr::gui::IGUIStaticText* m_label;
irr::video::ITexture* m_texture;
irr::video::ITexture* m_highlight_texture;
int m_texture_w, m_texture_h;
ScaleMode m_scale_mode;
@@ -107,6 +109,11 @@ namespace GUIEngine
* \note May safely be called no matter if the widget is add()ed or not
*/
void setImage(irr::video::ITexture* texture);
void setHighlightedImage(irr::video::ITexture* texture)
{
m_highlight_texture = texture;
}
};
}