Fixed one aspect ratio problem (when using child_width/height properties and DynamicRibbon)
git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@4315 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
@@ -109,7 +109,8 @@ void parseScreenFileDiv(irr::io::IrrXMLReader* xml, ptr_vector<Widget>& append_t
|
||||
}
|
||||
else if (!strcmp("icon", xml->getNodeName()))
|
||||
{
|
||||
append_to.push_back(new IconButtonWidget(false, false));
|
||||
append_to.push_back(new IconButtonWidget(IconButtonWidget::SCALE_MODE_KEEP_ASPECT_RATIO,
|
||||
false, false));
|
||||
}
|
||||
else if (!strcmp("checkbox", xml->getNodeName()))
|
||||
{
|
||||
|
||||
@@ -214,13 +214,17 @@ void DynamicRibbonWidget::setSubElements()
|
||||
// add columns
|
||||
for (int i=0; i<m_col_amount; i++)
|
||||
{
|
||||
IconButtonWidget* icon = new IconButtonWidget(false, true);
|
||||
// stretch the *texture* within the widget (and the widget has the right aspect ratio)
|
||||
// (Yeah, that's complicated, but screenshots are saved compressed horizontally so it's hard to be clean)
|
||||
IconButtonWidget* icon = new IconButtonWidget(IconButtonWidget::SCALE_MODE_STRETCH, false, true);
|
||||
icon->m_properties[PROP_ICON]="gui/main_help.png";
|
||||
|
||||
// set size to get proper ratio (as most textures are saved scaled down to 256x256)
|
||||
icon->m_properties[PROP_WIDTH] = m_properties[PROP_CHILD_WIDTH];
|
||||
icon->m_properties[PROP_HEIGHT] = m_properties[PROP_CHILD_HEIGHT];
|
||||
|
||||
icon->w = atoi(icon->m_properties[PROP_WIDTH].c_str());
|
||||
icon->h = atoi(icon->m_properties[PROP_HEIGHT].c_str());
|
||||
|
||||
if (m_text == "all") icon->m_text = " "; // FIXME: what's that??
|
||||
|
||||
// std::cout << "ribbon text = " << m_properties[PROP_TEXT].c_str() << std::endl;
|
||||
|
||||
@@ -24,13 +24,14 @@ using namespace irr::core;
|
||||
using namespace irr::gui;
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
IconButtonWidget::IconButtonWidget(const bool tab_stop, const bool focusable)
|
||||
IconButtonWidget::IconButtonWidget(ScaleMode scale_mode, const bool tab_stop, const bool focusable)
|
||||
{
|
||||
m_tab_stop = tab_stop;
|
||||
m_label = NULL;
|
||||
m_type = WTYPE_ICON_BUTTON;
|
||||
m_texture = NULL;
|
||||
m_focusable = focusable;
|
||||
m_scale_mode = scale_mode;
|
||||
}
|
||||
// -----------------------------------------------------------------------------
|
||||
void IconButtonWidget::add()
|
||||
@@ -43,7 +44,12 @@ void IconButtonWidget::add()
|
||||
|
||||
// irrlicht widgets don't support scaling while keeping aspect ratio
|
||||
// so, happily, let's implement it ourselves
|
||||
const int x_gap = (int)((float)w - (float)m_texture_w * (float)h / m_texture_h);
|
||||
int x_gap = 0;
|
||||
|
||||
if (m_scale_mode == SCALE_MODE_KEEP_ASPECT_RATIO)
|
||||
{
|
||||
x_gap = (int)((float)w - (float)m_texture_w * (float)h / m_texture_h);
|
||||
}
|
||||
|
||||
rect<s32> widget_size = rect<s32>(x + x_gap/2, y, x + w - x_gap/2, y + h);
|
||||
//std::cout << "Creating a IGUIButton " << widget_size.UpperLeftCorner.X << ", " << widget_size.UpperLeftCorner.Y <<
|
||||
|
||||
@@ -31,16 +31,29 @@ namespace GUIEngine
|
||||
See guiengine/engine.hpp for a detailed overview */
|
||||
class IconButtonWidget : public Widget
|
||||
{
|
||||
public:
|
||||
enum ScaleMode
|
||||
{
|
||||
SCALE_MODE_STRETCH,
|
||||
SCALE_MODE_KEEP_ASPECT_RATIO
|
||||
};
|
||||
|
||||
protected:
|
||||
friend class Skin;
|
||||
|
||||
irr::gui::IGUIStaticText* m_label;
|
||||
irr::video::ITexture* m_texture;
|
||||
int m_texture_w, m_texture_h;
|
||||
|
||||
ScaleMode m_scale_mode;
|
||||
public:
|
||||
|
||||
|
||||
|
||||
/** Whether to make the widget included in keyboard navigation order when adding */
|
||||
bool m_tab_stop;
|
||||
|
||||
IconButtonWidget(const bool tab_stop=true, const bool focusable=true);
|
||||
IconButtonWidget(ScaleMode scale_mode=SCALE_MODE_KEEP_ASPECT_RATIO, const bool tab_stop=true, const bool focusable=true);
|
||||
virtual ~IconButtonWidget() {}
|
||||
|
||||
/** Callback called when this widget needs to be added (see base class Widget) */
|
||||
|
||||
@@ -22,7 +22,7 @@ using namespace GUIEngine;
|
||||
using namespace irr::core;
|
||||
using namespace irr::gui;
|
||||
|
||||
ModelViewWidget::ModelViewWidget() : IconButtonWidget(false, false)
|
||||
ModelViewWidget::ModelViewWidget() : IconButtonWidget(IconButtonWidget::SCALE_MODE_KEEP_ASPECT_RATIO, false, false)
|
||||
{
|
||||
m_type = WTYPE_MODEL_VIEW;
|
||||
m_rtt_provider = NULL;
|
||||
|
||||
@@ -158,13 +158,13 @@ void RibbonWidget::add()
|
||||
const int needed_space_under_button = has_label ? 30 : 10; // quite arbitrary for now
|
||||
|
||||
// For now, the image stretches to keep the aspect ratio of the widget (FIXME, doesn't work)
|
||||
//float imageRatio = (float)m_children[i].w/(float)m_children[i].h;
|
||||
float imageRatio = (float)m_children[i].w/(float)m_children[i].h;
|
||||
|
||||
// size of the image
|
||||
video::ITexture* image = GUIEngine::getDriver()->getTexture((file_manager->getDataDir() + "/" + m_children[i].m_properties[PROP_ICON]).c_str());
|
||||
float image_h = (float)image->getSize().Height;
|
||||
float image_w = (float)image->getSize().Width;
|
||||
//float image_w = image_h*imageRatio;
|
||||
//float image_w = (float)image->getSize().Width;
|
||||
float image_w = image_h*imageRatio;
|
||||
|
||||
// if button too high to fit, scale down
|
||||
float zoom = global_zoom;
|
||||
@@ -174,19 +174,30 @@ void RibbonWidget::add()
|
||||
//rect<s32> subsize = rect<s32>(widget_x - (int)(image_w/2.0f), button_y,
|
||||
// widget_x + (int)(image_w/2.0f), button_y + (int)(m_children[i].h*zoom));
|
||||
|
||||
// backup and restore position in case the same object is added multiple times (FIXME: unclean)
|
||||
int old_x = m_children[i].x;
|
||||
int old_y = m_children[i].y;
|
||||
int old_w = m_children[i].w;
|
||||
int old_h = m_children[i].h;
|
||||
|
||||
m_children[i].x = widget_x - (int)(image_w*zoom/2.0f);
|
||||
m_children[i].y = button_y;
|
||||
m_children[i].w = (int)(image_w*zoom);
|
||||
m_children[i].h = (int)(image_h*zoom);
|
||||
|
||||
|
||||
//std::wcout << L"Widget has text '" << m_children[i].m_text.c_str() << "'\n";
|
||||
|
||||
|
||||
|
||||
m_children.get(i)->m_parent = btn;
|
||||
m_children.get(i)->add();
|
||||
//subbtn->setUseAlphaChannel(true);
|
||||
//subbtn->setImage( GUIEngine::getDriver()->getTexture((file_manager->getDataDir() + "/" + m_children[i].m_properties[PROP_ICON]).c_str()) );
|
||||
|
||||
m_children[i].x = old_x;
|
||||
m_children[i].y = old_y;
|
||||
m_children[i].w = old_w;
|
||||
m_children[i].h = old_h;
|
||||
|
||||
// ---- label part
|
||||
/*
|
||||
if (has_label)
|
||||
|
||||
@@ -187,7 +187,9 @@ TrackInfoDialog::TrackInfoDialog(const std::string& trackIdent, const irr::core:
|
||||
|
||||
|
||||
// ---- Track screenshot
|
||||
IconButtonWidget* screenshotWidget = new IconButtonWidget(false, false);
|
||||
// stretch the *texture* within the widget (and the widget has the right aspect ratio)
|
||||
// (Yeah, that's complicated, but screenshots are saved compressed horizontally so it's hard to be clean)
|
||||
IconButtonWidget* screenshotWidget = new IconButtonWidget(IconButtonWidget::SCALE_MODE_STRETCH, false, false);
|
||||
core::rect< s32 > area_right(m_area.getWidth()/2, y1, m_area.getWidth(), y2-10);
|
||||
screenshotWidget->x = area_right.UpperLeftCorner.X;
|
||||
screenshotWidget->y = area_right.UpperLeftCorner.Y;
|
||||
|
||||
Reference in New Issue
Block a user