Improved main menu appearance
git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/branches/irrlicht@3368 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
parent
309528a7fc
commit
060720c454
BIN
data/gui/background.jpg
Normal file
BIN
data/gui/background.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 22 KiB |
@ -1,6 +1,6 @@
|
|||||||
<div x="5%" y="2%" width="90%" height="96%" layout="vertical-row" >
|
<div x="5%" y="2%" width="90%" height="96%" layout="vertical-row" >
|
||||||
|
|
||||||
<icon id="logo" align="center" icon="gui/logo.png"/>
|
<icon id="logo" align="center" proportion="3" width="100%" icon="gui/logo.png"/>
|
||||||
|
|
||||||
<spacer proportion="1" width="10"/>
|
<spacer proportion="1" width="10"/>
|
||||||
|
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
#include "gui/skin.hpp"
|
#include "gui/skin.hpp"
|
||||||
#include "gui/widget.hpp"
|
#include "gui/widget.hpp"
|
||||||
#include "io/file_manager.hpp"
|
#include "io/file_manager.hpp"
|
||||||
|
#include "gui/state_manager.hpp"
|
||||||
|
|
||||||
namespace GUIEngine
|
namespace GUIEngine
|
||||||
{
|
{
|
||||||
@ -112,6 +113,50 @@ void transmitEvent(Widget* widget, std::string& name)
|
|||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
void render()
|
void render()
|
||||||
{
|
{
|
||||||
|
// on one end, making these static is not too clean.
|
||||||
|
// on another end, these variables are really only used locally,
|
||||||
|
// and making them static avoids doing the same stupid computations every frame
|
||||||
|
// FIXME - not totally true, resolution switches need to be handled
|
||||||
|
static ITexture* bg_image = NULL;
|
||||||
|
|
||||||
|
static core::rect<s32> dest;
|
||||||
|
static core::rect<s32> source_area;
|
||||||
|
|
||||||
|
if(bg_image == NULL)
|
||||||
|
{
|
||||||
|
int texture_w, texture_h;
|
||||||
|
// TODO/FIXME? - user preferences still include a background image choice
|
||||||
|
bg_image = GUIEngine::getDriver()->getTexture( (file_manager->getGUIDir() + "/background.jpg").c_str() );
|
||||||
|
assert(bg_image != NULL);
|
||||||
|
texture_w = bg_image->getSize().Width;
|
||||||
|
texture_h = bg_image->getSize().Height;
|
||||||
|
|
||||||
|
source_area = core::rect<s32>(0, 0, texture_w, texture_h);
|
||||||
|
|
||||||
|
core::dimension2d<s32> frame_size = GUIEngine::getDriver()->getCurrentRenderTargetSize();
|
||||||
|
const int screen_w = frame_size.Width;
|
||||||
|
const int screen_h = frame_size.Height;
|
||||||
|
|
||||||
|
// stretch image vertically to fit
|
||||||
|
float ratio = (float)screen_h / texture_h;
|
||||||
|
|
||||||
|
// check that with the vertical stretching, it still fits horizontally
|
||||||
|
while(texture_w*ratio < screen_w) ratio += 0.1;
|
||||||
|
|
||||||
|
texture_w *= ratio;
|
||||||
|
texture_h *= ratio;
|
||||||
|
|
||||||
|
const int clipped_x_space = (texture_w - screen_w);
|
||||||
|
|
||||||
|
dest = core::rect<s32>(-clipped_x_space/2, 0, screen_w+clipped_x_space/2, texture_h);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!StateManager::isGameState())
|
||||||
|
GUIEngine::getDriver()->draw2DImage(bg_image, dest, source_area,
|
||||||
|
0 /* no clipping */, 0, false /* alpha */);
|
||||||
|
|
||||||
|
//GUIEngine::getDriver()->draw2DRectangle( SColor(255, 0, 150, 0), rect );
|
||||||
|
|
||||||
g_env->drawAll();
|
g_env->drawAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -279,14 +279,15 @@ IconButtonWidget::IconButtonWidget(const bool clickable)
|
|||||||
void IconButtonWidget::add()
|
void IconButtonWidget::add()
|
||||||
{
|
{
|
||||||
ITexture* texture = GUIEngine::getDriver()->getTexture((file_manager->getDataDir() + "/" +m_properties[PROP_ICON]).c_str());
|
ITexture* texture = GUIEngine::getDriver()->getTexture((file_manager->getDataDir() + "/" +m_properties[PROP_ICON]).c_str());
|
||||||
//const int texture_w = texture->getSize().Width, texture_h = texture->getSize().Height;
|
const int texture_w = texture->getSize().Width, texture_h = texture->getSize().Height;
|
||||||
/*
|
/*
|
||||||
if(w < texture_w) ... ;
|
if(w < texture_w) ... ;
|
||||||
if(h < texture_h) ... ;
|
if(h < texture_h) ... ;
|
||||||
*/
|
*/
|
||||||
rect<s32> widget_size = rect<s32>(x, y, x + w, y + h);
|
rect<s32> widget_size;
|
||||||
if(clickable)
|
if(clickable)
|
||||||
{
|
{
|
||||||
|
widget_size = rect<s32>(x, y, x + w, y + h);
|
||||||
IGUIButton* btn = GUIEngine::getGUIEnv()->addButton(widget_size, NULL, ++id_counter, L"");
|
IGUIButton* btn = GUIEngine::getGUIEnv()->addButton(widget_size, NULL, ++id_counter, L"");
|
||||||
m_element = btn;
|
m_element = btn;
|
||||||
btn->setUseAlphaChannel(true);
|
btn->setUseAlphaChannel(true);
|
||||||
@ -296,6 +297,14 @@ void IconButtonWidget::add()
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
// irrlicht widgets don't support scaling while keeping aspect ratio
|
||||||
|
// so, happily, let's implement it ourselves
|
||||||
|
const int x_gap = (float)w - (float)texture_w * (float)h / texture_h;
|
||||||
|
|
||||||
|
std::cout << "x_gap = " << x_gap << std::endl;
|
||||||
|
|
||||||
|
widget_size = rect<s32>(x + x_gap/2, y, x + w - x_gap/2, y + h);
|
||||||
|
|
||||||
IGUIImage* btn = GUIEngine::getGUIEnv()->addImage(widget_size, NULL, ++id_counter_2);
|
IGUIImage* btn = GUIEngine::getGUIEnv()->addImage(widget_size, NULL, ++id_counter_2);
|
||||||
m_element = btn;
|
m_element = btn;
|
||||||
btn->setUseAlphaChannel(true);
|
btn->setUseAlphaChannel(true);
|
||||||
|
Loading…
Reference in New Issue
Block a user