Make track screenshot keep right aspect ratio, and clarify a bit existing aspect capbilities in icon widget

git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@4371 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
auria 2009-12-30 18:43:28 +00:00
parent f5cec6b741
commit ebe6dc5521
5 changed files with 26 additions and 9 deletions

View File

@ -109,7 +109,7 @@ void parseScreenFileDiv(irr::io::IrrXMLReader* xml, ptr_vector<Widget>& append_t
}
else if (!strcmp("icon", xml->getNodeName()))
{
append_to.push_back(new IconButtonWidget(IconButtonWidget::SCALE_MODE_KEEP_ASPECT_RATIO,
append_to.push_back(new IconButtonWidget(IconButtonWidget::SCALE_MODE_KEEP_TEXTURE_ASPECT_RATIO,
false, false));
}
else if (!strcmp("checkbox", xml->getNodeName()))

View File

@ -46,7 +46,7 @@ void IconButtonWidget::add()
// so, happily, let's implement it ourselves
int x_gap = 0;
if (m_scale_mode == SCALE_MODE_KEEP_ASPECT_RATIO)
if (m_scale_mode == SCALE_MODE_KEEP_TEXTURE_ASPECT_RATIO)
{
x_gap = (int)((float)w - (float)m_texture_w * (float)h / m_texture_h);
}

View File

@ -35,7 +35,7 @@ namespace GUIEngine
enum ScaleMode
{
SCALE_MODE_STRETCH,
SCALE_MODE_KEEP_ASPECT_RATIO
SCALE_MODE_KEEP_TEXTURE_ASPECT_RATIO
};
protected:
@ -53,7 +53,7 @@ namespace GUIEngine
/** Whether to make the widget included in keyboard navigation order when adding */
bool m_tab_stop;
IconButtonWidget(ScaleMode scale_mode=SCALE_MODE_KEEP_ASPECT_RATIO, const bool tab_stop=true, const bool focusable=true);
IconButtonWidget(ScaleMode scale_mode=SCALE_MODE_KEEP_TEXTURE_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) */

View File

@ -22,7 +22,7 @@ using namespace GUIEngine;
using namespace irr::core;
using namespace irr::gui;
ModelViewWidget::ModelViewWidget() : IconButtonWidget(IconButtonWidget::SCALE_MODE_KEEP_ASPECT_RATIO, false, false)
ModelViewWidget::ModelViewWidget() : IconButtonWidget(IconButtonWidget::SCALE_MODE_KEEP_TEXTURE_ASPECT_RATIO, false, false)
{
m_type = WTYPE_MODEL_VIEW;
m_rtt_provider = NULL;

View File

@ -157,10 +157,27 @@ TrackInfoDialog::TrackInfoDialog(const std::string& trackIdent, const irr::core:
// (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;
screenshotWidget->w = area_right.getWidth();
screenshotWidget->h = area_right.getHeight();
const int x_from = area_right.UpperLeftCorner.X;
const int y_from = area_right.UpperLeftCorner.Y;
const int available_w = area_right.getWidth();
const int available_h = area_right.getHeight();
// TODO: move that "custom aspect ratio" code into the Image widget
// find a size that has the right aspect ratio (4:3) and fits within available space
int suggested_h = available_h;
int suggested_w = (4.0f / 3.0f) * suggested_h;
if (suggested_w > available_w)
{
const float needed_scale_factor = (float)available_w / (float)suggested_w;
suggested_w *= needed_scale_factor;
suggested_h *= needed_scale_factor;
}
screenshotWidget->x = x_from + (available_w - suggested_w)/2; // center horizontally
screenshotWidget->y = y_from + (available_h - suggested_h)/2; // center vertically
screenshotWidget->w = suggested_w;
screenshotWidget->h = suggested_h;
screenshotWidget->m_properties[PROP_ICON] = "gui/main_help.png"; // temporary icon, will replace it just after
screenshotWidget->setParent(m_irrlicht_window);
screenshotWidget->add();