fixed default resolution being highlighted
git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/branches/irrlicht@3474 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
@@ -40,8 +40,8 @@ namespace StateManager
|
||||
GUIEngine::RibbonWidget* ribbon = dynamic_cast<GUIEngine::RibbonWidget*>(widget);
|
||||
if(ribbon == NULL) return; // only interesting stuff in main menu is the ribbons
|
||||
std::string selection = ribbon->getSelectionName().c_str();
|
||||
|
||||
|
||||
|
||||
|
||||
if(selection == "new")
|
||||
{
|
||||
StateManager::pushMenu("karts.stkgui");
|
||||
@@ -60,7 +60,7 @@ namespace StateManager
|
||||
pushMenu("help1.stkgui");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Callback handling events from the kart selection menu
|
||||
*/
|
||||
@@ -71,7 +71,7 @@ namespace StateManager
|
||||
{
|
||||
GUIEngine::RibbonGridWidget* w = dynamic_cast<GUIEngine::RibbonGridWidget*>(GUIEngine::getCurrentScreen()->getWidget("karts"));
|
||||
assert( w != NULL );
|
||||
|
||||
|
||||
if(!karts_menu_inited)
|
||||
{
|
||||
w->addItem("Gnu","k1","gui/gnu.png");
|
||||
@@ -85,7 +85,7 @@ namespace StateManager
|
||||
karts_menu_inited = true;
|
||||
}
|
||||
w->updateItemDisplay();
|
||||
|
||||
|
||||
GUIEngine::SpinnerWidget* w2 = dynamic_cast<GUIEngine::SpinnerWidget*>
|
||||
(GUIEngine::getCurrentScreen()->getWidget("player"));
|
||||
assert( w2 != NULL );
|
||||
@@ -93,19 +93,19 @@ namespace StateManager
|
||||
w2->addLabel("Auria");
|
||||
w2->addLabel("Conso");
|
||||
w2->addLabel("MiniBjorn");
|
||||
|
||||
|
||||
GUIEngine::ModelViewWidget* w3 = dynamic_cast<GUIEngine::ModelViewWidget*>
|
||||
(GUIEngine::getCurrentScreen()->getWidget("modelview"));
|
||||
|
||||
|
||||
assert( w3 != NULL );
|
||||
|
||||
|
||||
// set kart model - FIXME - doesn't work very much
|
||||
IMesh* mesh = kart_properties_manager->getKart("tux")->getKartModel()->getModel();
|
||||
SAnimatedMesh* test = new SAnimatedMesh(); // FIXME - memory management
|
||||
test->addMesh(mesh);
|
||||
//test->setMaterialFlag(EMF_LIGHTING , false);
|
||||
|
||||
w3->setModel(test);
|
||||
|
||||
w3->setModel(test);
|
||||
}
|
||||
// TODO - actually check which kart was selected
|
||||
else if(name == "karts")
|
||||
@@ -113,7 +113,7 @@ namespace StateManager
|
||||
StateManager::pushMenu("racesetup.stkgui");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Callback handling events from the race setup menu
|
||||
*/
|
||||
@@ -125,7 +125,7 @@ namespace StateManager
|
||||
(GUIEngine::getCurrentScreen()->getWidget("difficulty"));
|
||||
assert( w != NULL );
|
||||
w->setSelection(user_config->getDefaultDifficulty());
|
||||
|
||||
|
||||
// TODO - if user arrived to this screen by pressing esc from teh enxt, the behaviour below might be incorrect
|
||||
// it would be better to restore previously set settings.
|
||||
race_manager->setDifficulty( (RaceManager::Difficulty)user_config->getDefaultDifficulty() );
|
||||
@@ -135,7 +135,7 @@ namespace StateManager
|
||||
GUIEngine::RibbonWidget* w = dynamic_cast<GUIEngine::RibbonWidget*>(widget);
|
||||
assert(w != NULL);
|
||||
const std::string& selection = w->getSelectionName();
|
||||
|
||||
|
||||
if(selection == "novice")
|
||||
race_manager->setDifficulty(RaceManager::RD_EASY);
|
||||
else if(selection == "intermediate")
|
||||
@@ -155,7 +155,7 @@ namespace StateManager
|
||||
/*
|
||||
289 race_manager->setDifficulty((RaceManager::Difficulty)m_difficulty);
|
||||
290 user_config->setDefaultNumDifficulty(m_difficulty);
|
||||
|
||||
|
||||
// if there is no AI, there's no point asking the player for the amount of karts.
|
||||
299 // It will always be the same as the number of human players
|
||||
300 if(RaceManager::isBattleMode( race_manager->getMinorMode() ))
|
||||
@@ -168,7 +168,7 @@ namespace StateManager
|
||||
307 race_manager->setNumKarts(m_num_karts);
|
||||
308 user_config->setDefaultNumKarts(race_manager->getNumKarts());
|
||||
309 }
|
||||
|
||||
|
||||
311 if( race_manager->getMajorMode() != RaceManager::MAJOR_MODE_GRAND_PRIX &&
|
||||
312 RaceManager::modeHasLaps( race_manager->getMinorMode() ) )
|
||||
313 {
|
||||
@@ -177,28 +177,28 @@ namespace StateManager
|
||||
316 }
|
||||
317 // Might still be set from a previous challenge
|
||||
318 race_manager->setCoinTarget(0);
|
||||
|
||||
|
||||
input_manager->setMode(InputManager::INGAME);
|
||||
|
||||
|
||||
race_manager->setLocalKartInfo(0, argv[i+1]);
|
||||
|
||||
|
||||
race_manager->setDifficulty(RaceManager::RD_EASY);
|
||||
race_manager->setDifficulty(RaceManager::RD_HARD);
|
||||
race_manager->setDifficulty(RaceManager::RD_HARD);
|
||||
|
||||
|
||||
race_manager->setTrack(argv[i+1]);
|
||||
|
||||
|
||||
user_config->setDefaultNumKarts(stk_config->m_max_karts);
|
||||
race_manager->setNumKarts(user_config->getDefaultNumKarts() );
|
||||
|
||||
|
||||
user_config->getDefaultNumKarts()
|
||||
|
||||
|
||||
StateManager::enterGameState();
|
||||
race_manager->startNew();
|
||||
*/
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Callback handling events from the track menu
|
||||
*/
|
||||
@@ -210,7 +210,7 @@ namespace StateManager
|
||||
GUIEngine::RibbonGridWidget* w = dynamic_cast<GUIEngine::RibbonGridWidget*>
|
||||
(GUIEngine::getCurrentScreen()->getWidget("tracks"));
|
||||
assert( w != NULL );
|
||||
|
||||
|
||||
if(!track_menu_inited)
|
||||
{
|
||||
w->addItem("Track 1","t1","gui/track1.png");
|
||||
@@ -233,7 +233,7 @@ namespace StateManager
|
||||
if(w2 != NULL)
|
||||
{
|
||||
std::cout << "Clicked on track " << w2->getSelectionName().c_str() << std::endl;
|
||||
|
||||
|
||||
StateManager::enterGameState();
|
||||
race_manager->setLocalKartInfo(0, "tux");
|
||||
//race_manager->setDifficulty(RaceManager::RD_HARD);
|
||||
@@ -245,7 +245,7 @@ namespace StateManager
|
||||
race_manager->setNumLocalPlayers( 1 );
|
||||
network_manager->setupPlayerKartInfo();
|
||||
//race_manager->getKartType(1) = KT_PLAYER;
|
||||
|
||||
|
||||
race_manager->startNew();
|
||||
}
|
||||
}
|
||||
@@ -254,10 +254,10 @@ namespace StateManager
|
||||
GUIEngine::RibbonWidget* w = dynamic_cast<GUIEngine::RibbonWidget*>(widget);
|
||||
if(w != NULL)
|
||||
std::cout << "Clicked on GrandPrix " << w->getSelectionName().c_str() << std::endl;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Callback handling events from the options menus
|
||||
*/
|
||||
@@ -267,7 +267,7 @@ namespace StateManager
|
||||
if(name == "init")
|
||||
{
|
||||
const std::string& screen_name = GUIEngine::getCurrentScreen()->getName();
|
||||
|
||||
|
||||
GUIEngine::RibbonWidget* ribbon = dynamic_cast<GUIEngine::RibbonWidget*>
|
||||
(GUIEngine::getCurrentScreen()->getWidget("options_choice"));
|
||||
if(ribbon != NULL)
|
||||
@@ -276,7 +276,7 @@ namespace StateManager
|
||||
else if(screen_name == "options_players.stkgui") ribbon->select( "players" );
|
||||
else if(screen_name == "options_input.stkgui") ribbon->select( "controls" );
|
||||
}
|
||||
|
||||
|
||||
// ---- init audio-video sub-screen
|
||||
if(screen_name == "options_av.stkgui")
|
||||
{
|
||||
@@ -284,35 +284,35 @@ namespace StateManager
|
||||
GUIEngine::SpinnerWidget* gauge = dynamic_cast<GUIEngine::SpinnerWidget*>
|
||||
(GUIEngine::getCurrentScreen()->getWidget("sfx_volume"));
|
||||
assert(gauge != NULL);
|
||||
|
||||
|
||||
gauge->setValue( sfx_manager->getMasterSFXVolume()*10.0f );
|
||||
|
||||
|
||||
|
||||
|
||||
gauge = dynamic_cast<GUIEngine::SpinnerWidget*>
|
||||
(GUIEngine::getCurrentScreen()->getWidget("music_volume"));
|
||||
assert(gauge != NULL);
|
||||
gauge->setValue( sound_manager->getMasterMusicVolume()*10.f );
|
||||
|
||||
|
||||
|
||||
|
||||
// ---- music volume
|
||||
GUIEngine::CheckBoxWidget* sfx = dynamic_cast<GUIEngine::CheckBoxWidget*>
|
||||
(GUIEngine::getCurrentScreen()->getWidget("sfx_enabled"));
|
||||
|
||||
|
||||
GUIEngine::CheckBoxWidget* music = dynamic_cast<GUIEngine::CheckBoxWidget*>
|
||||
(GUIEngine::getCurrentScreen()->getWidget("music_enabled"));
|
||||
|
||||
|
||||
// ---- audio enables/disables
|
||||
sfx->setState( user_config->doSFX() );
|
||||
music->setState( user_config->doMusic() );
|
||||
|
||||
|
||||
// ---- resolutinos
|
||||
{
|
||||
GUIEngine::RibbonGridWidget* res = dynamic_cast<GUIEngine::RibbonGridWidget*>
|
||||
(GUIEngine::getCurrentScreen()->getWidget("resolutions"));
|
||||
assert( res != NULL );
|
||||
|
||||
|
||||
static bool resolutions_inited = false;
|
||||
|
||||
|
||||
// --- get resolution list from irrlicht the first time
|
||||
if(!resolutions_inited)
|
||||
{
|
||||
@@ -323,12 +323,12 @@ namespace StateManager
|
||||
const int w = modes[n].width;
|
||||
const int h = modes[n].height;
|
||||
const float ratio = (float)w / h;
|
||||
|
||||
|
||||
char name[32];
|
||||
sprintf( name, "%ix%i", w, h );
|
||||
|
||||
|
||||
#define ABOUT_EQUAL(a , b) (fabsf( a - b ) < 0.01)
|
||||
|
||||
|
||||
if( ABOUT_EQUAL( ratio, (5.0f/4.0f) ) )
|
||||
res->addItem(name,name,"gui/screen54.png");
|
||||
else if( ABOUT_EQUAL( ratio, (4.0f/3.0f) ) )
|
||||
@@ -346,12 +346,12 @@ namespace StateManager
|
||||
}
|
||||
#undef ABOUT_EQUAL
|
||||
} // next resolution
|
||||
|
||||
|
||||
resolutions_inited = true;
|
||||
} // end if not inited
|
||||
|
||||
|
||||
res->updateItemDisplay();
|
||||
|
||||
|
||||
// ---- select curernt resolution every time
|
||||
const std::vector<VideoMode>& modes = irr_driver->getVideoModes();
|
||||
const int amount = modes.size();
|
||||
@@ -362,9 +362,10 @@ namespace StateManager
|
||||
|
||||
char name[32];
|
||||
sprintf( name, "%ix%i", w, h );
|
||||
|
||||
|
||||
if(w == user_config->m_width && h == user_config->m_height)
|
||||
{
|
||||
std::cout << "************* Detected right resolution!!! " << n << "\n";
|
||||
// that's the current one
|
||||
res->setSelection(n);
|
||||
break;
|
||||
@@ -378,14 +379,14 @@ namespace StateManager
|
||||
GUIEngine::RibbonGridWidget* devices = dynamic_cast<GUIEngine::RibbonGridWidget*>
|
||||
(GUIEngine::getCurrentScreen()->getWidget("devices"));
|
||||
assert( devices != NULL );
|
||||
|
||||
|
||||
static bool devices_inited = false;
|
||||
if(!devices_inited)
|
||||
{
|
||||
devices->addItem("Keyboard","keyboard","gui/keyboard.png");
|
||||
|
||||
const int gamepad_count = input_manager->getDeviceList()->getGamePadAmount();
|
||||
|
||||
|
||||
for(int i=0; i<gamepad_count; i++)
|
||||
{
|
||||
std::string name = input_manager->getDeviceList()->getGamePad(i)->m_name;
|
||||
@@ -393,18 +394,18 @@ namespace StateManager
|
||||
sprintf(internal_name, "gamepad%i", i);
|
||||
devices->addItem(name,internal_name,"gui/gamepad.png");
|
||||
}
|
||||
|
||||
|
||||
devices_inited = true;
|
||||
}
|
||||
devices->updateItemDisplay();
|
||||
}
|
||||
} // end init
|
||||
|
||||
|
||||
// -- options
|
||||
else if(name == "options_choice")
|
||||
{
|
||||
std::string selection = ((GUIEngine::RibbonWidget*)widget)->getSelectionName().c_str();
|
||||
|
||||
|
||||
if(selection == "audio_video") replaceTopMostMenu("options_av.stkgui");
|
||||
else if(selection == "players") replaceTopMostMenu("options_players.stkgui");
|
||||
else if(selection == "controls") replaceTopMostMenu("options_input.stkgui");
|
||||
@@ -414,45 +415,45 @@ namespace StateManager
|
||||
/*
|
||||
GUIEngine::GaugeWidget* w = dynamic_cast<GUIEngine::GaugeWidget*>(widget);
|
||||
assert(w != NULL);
|
||||
|
||||
|
||||
sound_manager->setMasterMusicVolume( w->getValue() );
|
||||
*/
|
||||
|
||||
|
||||
GUIEngine::SpinnerWidget* w = dynamic_cast<GUIEngine::SpinnerWidget*>(widget);
|
||||
assert(w != NULL);
|
||||
|
||||
|
||||
sound_manager->setMasterMusicVolume( w->getValue()/10.0f );
|
||||
}
|
||||
else if(name == "sfx_volume")
|
||||
{
|
||||
static SFXBase* sample_sound = NULL;
|
||||
|
||||
|
||||
GUIEngine::SpinnerWidget* w = dynamic_cast<GUIEngine::SpinnerWidget*>(widget);
|
||||
assert(w != NULL);
|
||||
|
||||
|
||||
if(sample_sound == NULL)
|
||||
sample_sound = sfx_manager->newSFX( SFXManager::SOUND_SKID );
|
||||
sample_sound->volume(1);
|
||||
|
||||
|
||||
sfx_manager->setMasterSFXVolume( w->getValue()/10.0f );
|
||||
user_config->m_sfx_volume = w->getValue()/10.0f;
|
||||
// std::cout << "w->getValue()=" << w->getValue() << std::endl;
|
||||
|
||||
|
||||
// play a sample sound to show the user what this volume is like
|
||||
sample_sound->position ( Vec3(0,0,0) );
|
||||
|
||||
|
||||
if(sample_sound->getStatus() != SFXManager::SFX_PLAYING)
|
||||
{
|
||||
sample_sound->play();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
else if(name == "music_enabled")
|
||||
{
|
||||
GUIEngine::CheckBoxWidget* w = dynamic_cast<GUIEngine::CheckBoxWidget*>(widget);
|
||||
|
||||
|
||||
user_config->setMusic(w->getState() ? UserConfig::UC_ENABLE : UserConfig::UC_DISABLE);
|
||||
|
||||
|
||||
if(w->getState() == false)
|
||||
sound_manager->stopMusic();
|
||||
else
|
||||
@@ -468,7 +469,7 @@ namespace StateManager
|
||||
{
|
||||
user_config->m_prev_width = user_config->m_width;
|
||||
user_config->m_prev_height = user_config->m_height;
|
||||
|
||||
|
||||
user_config->m_width = 800;
|
||||
user_config->m_height = 480;
|
||||
irr_driver->changeResolution();
|
||||
@@ -496,7 +497,7 @@ namespace StateManager
|
||||
else if(name == "category")
|
||||
{
|
||||
std::string selection = ((GUIEngine::RibbonWidget*)widget)->getSelectionName().c_str();
|
||||
|
||||
|
||||
if(selection == "page1") replaceTopMostMenu("help1.stkgui");
|
||||
else if(selection == "page2") replaceTopMostMenu("help2.stkgui");
|
||||
else if(selection == "page3") replaceTopMostMenu("help3.stkgui");
|
||||
@@ -507,7 +508,7 @@ namespace StateManager
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* All widget events will be dispatched to this function; arguments are
|
||||
* a pointer to the widget from which the event originates, and its internal
|
||||
@@ -518,9 +519,9 @@ namespace StateManager
|
||||
void eventCallback(GUIEngine::Widget* widget, std::string& name)
|
||||
{
|
||||
std::cout << "event!! " << name.c_str() << std::endl;
|
||||
|
||||
|
||||
const std::string& screen_name = GUIEngine::getCurrentScreen()->getName();
|
||||
|
||||
|
||||
if( screen_name == "main.stkgui" )
|
||||
menuEventMain(widget, name);
|
||||
else if( screen_name == "karts.stkgui" )
|
||||
@@ -535,21 +536,21 @@ namespace StateManager
|
||||
menuEventHelp(widget, name);
|
||||
else
|
||||
std::cerr << "Warning, unknown menu " << screen_name << " in event callback\n";
|
||||
|
||||
|
||||
}
|
||||
|
||||
#if 0
|
||||
#pragma mark -
|
||||
#pragma mark Other
|
||||
#endif
|
||||
|
||||
|
||||
void initGUI()
|
||||
{
|
||||
IrrlichtDevice* device = irr_driver->getDevice();
|
||||
video::IVideoDriver* driver = device->getVideoDriver();
|
||||
GUIEngine::init(device, driver, &eventCallback);
|
||||
}
|
||||
|
||||
|
||||
void enterGameState()
|
||||
{
|
||||
g_menu_stack.clear();
|
||||
@@ -558,12 +559,12 @@ namespace StateManager
|
||||
GUIEngine::cleanForGame();
|
||||
input_manager->setMode(InputManager::INGAME);
|
||||
}
|
||||
|
||||
|
||||
bool isGameState()
|
||||
{
|
||||
return g_game_mode;
|
||||
}
|
||||
|
||||
|
||||
void escapePressed()
|
||||
{
|
||||
if(g_game_mode)
|
||||
@@ -576,21 +577,21 @@ namespace StateManager
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
#if 0
|
||||
#pragma mark -
|
||||
#pragma mark Push/pop menus
|
||||
#endif
|
||||
|
||||
|
||||
static std::string g_init_event = "init";
|
||||
|
||||
|
||||
void pushMenu(std::string name)
|
||||
{
|
||||
input_manager->setMode(InputManager::MENU);
|
||||
g_menu_stack.push_back(name);
|
||||
g_game_mode = false;
|
||||
GUIEngine::switchToScreen(name.c_str());
|
||||
|
||||
|
||||
eventCallback(NULL, g_init_event);
|
||||
}
|
||||
void replaceTopMostMenu(std::string name)
|
||||
@@ -599,34 +600,34 @@ namespace StateManager
|
||||
g_menu_stack[g_menu_stack.size()-1] = name;
|
||||
g_game_mode = false;
|
||||
GUIEngine::switchToScreen(name.c_str());
|
||||
|
||||
|
||||
eventCallback(NULL, g_init_event);
|
||||
}
|
||||
|
||||
|
||||
void reshowTopMostMenu()
|
||||
{
|
||||
GUIEngine::switchToScreen( g_menu_stack[g_menu_stack.size()-1].c_str() );
|
||||
eventCallback(NULL, g_init_event);
|
||||
}
|
||||
|
||||
|
||||
void popMenu()
|
||||
{
|
||||
g_menu_stack.pop_back();
|
||||
|
||||
|
||||
if(g_menu_stack.size() == 0)
|
||||
{
|
||||
main_loop->abort();
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
g_game_mode = g_menu_stack[g_menu_stack.size()-1] == "race";
|
||||
|
||||
|
||||
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());
|
||||
|
||||
GUIEngine::switchToScreen(g_menu_stack[g_menu_stack.size()-1].c_str());
|
||||
|
||||
eventCallback(NULL, g_init_event);
|
||||
}
|
||||
|
||||
|
||||
void resetAndGoToMenu(std::string name)
|
||||
{
|
||||
race_manager->exitRace();
|
||||
@@ -638,5 +639,5 @@ namespace StateManager
|
||||
GUIEngine::switchToScreen(name.c_str());
|
||||
eventCallback(NULL, g_init_event);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -46,7 +46,7 @@ Widget::Widget()
|
||||
m_show_bounding_box = false;
|
||||
}
|
||||
// -----------------------------------------------------------------------------
|
||||
/**
|
||||
/**
|
||||
* Receives as string the raw property value retrieved from XML file.
|
||||
* Will try to make sense of it, as an absolute value or a percentage.
|
||||
*
|
||||
@@ -60,9 +60,9 @@ bool Widget::convertToCoord(std::string& x, int* absolute /* out */, int* percen
|
||||
int i;
|
||||
std::istringstream myStream(x);
|
||||
is_number = (myStream >> i)!=0;
|
||||
|
||||
|
||||
if(!is_number) return false;
|
||||
|
||||
|
||||
if( x[x.size()-1] == '%' ) // percentage
|
||||
{
|
||||
*percentage = i;
|
||||
@@ -86,7 +86,7 @@ void Widget::readCoords(Widget* parent)
|
||||
std::string y = m_properties[PROP_Y];
|
||||
std::string width = m_properties[PROP_WIDTH];
|
||||
std::string height = m_properties[PROP_HEIGHT];
|
||||
|
||||
|
||||
/* retrieve parent size (or screen size if none). Will be useful for layout
|
||||
and especially for percentages. */
|
||||
unsigned int parent_w, parent_h, parent_x, parent_y;
|
||||
@@ -105,7 +105,7 @@ void Widget::readCoords(Widget* parent)
|
||||
parent_x = parent->x;
|
||||
parent_y = parent->y;
|
||||
}
|
||||
|
||||
|
||||
// ---- try converting to number
|
||||
// x coord
|
||||
{
|
||||
@@ -117,7 +117,7 @@ void Widget::readCoords(Widget* parent)
|
||||
else if(percent_x > -1) this->x = parent_x + parent_w*percent_x/100;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// y coord
|
||||
{
|
||||
int abs_y = -1, percent_y = -1;
|
||||
@@ -128,10 +128,10 @@ void Widget::readCoords(Widget* parent)
|
||||
else if(percent_y > -1) this->y = parent_y + parent_h*percent_y/100;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// ---- if this widget has an icon, get icon size. this can helpful determine its optimal size
|
||||
int texture_w = -1, texture_h = -1;
|
||||
|
||||
|
||||
if(m_properties[PROP_ICON].size() > 0)
|
||||
{
|
||||
ITexture* texture = GUIEngine::getDriver()->getTexture(
|
||||
@@ -143,7 +143,7 @@ void Widget::readCoords(Widget* parent)
|
||||
texture_h = texture->getSize().Height;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// ---- if this widget has a label, get text length. this can helpful determine its optimal size
|
||||
int label_w = -1, label_h = -1;
|
||||
if(m_properties[PROP_TEXT].size() > 0)
|
||||
@@ -155,7 +155,7 @@ void Widget::readCoords(Widget* parent)
|
||||
// lines are required, we need to specify a height explicitely
|
||||
label_h = dim.Height;
|
||||
}
|
||||
|
||||
|
||||
// ---- read dimension
|
||||
// width
|
||||
{
|
||||
@@ -168,7 +168,7 @@ void Widget::readCoords(Widget* parent)
|
||||
else if(texture_w > -1) this->w = texture_w;
|
||||
else if(label_w > -1) this->w = label_w;
|
||||
}
|
||||
|
||||
|
||||
// height
|
||||
{
|
||||
int abs_h = -1, percent_h = -1;
|
||||
@@ -181,7 +181,7 @@ void Widget::readCoords(Widget* parent)
|
||||
else if(texture_h > -1) this->h = texture_h;
|
||||
else if(label_h > -1) this->h = label_h;
|
||||
}
|
||||
|
||||
|
||||
// ---- can't make widget bigger than parent
|
||||
if(this->h > (int)parent_h)
|
||||
{
|
||||
@@ -197,20 +197,20 @@ void Widget::readCoords(Widget* parent)
|
||||
this->w = (int)(this->w*ratio);
|
||||
this->h = (int)(this->h*ratio);
|
||||
}
|
||||
|
||||
|
||||
// ------ check for given max size
|
||||
if(m_properties[PROP_MAX_WIDTH].size() > 0)
|
||||
{
|
||||
const int max_width = atoi( this->m_properties[PROP_MAX_WIDTH].c_str() );
|
||||
if(this->w > max_width) this->w = max_width;
|
||||
}
|
||||
|
||||
|
||||
if(m_properties[PROP_MAX_HEIGHT].size() > 0)
|
||||
{
|
||||
const int max_height = atoi( this->m_properties[PROP_MAX_HEIGHT].c_str() );
|
||||
if(this->h > max_height) this->h = max_height;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
#if 0
|
||||
@@ -223,7 +223,7 @@ void ButtonWidget::add()
|
||||
rect<s32> widget_size = rect<s32>(x, y, x + w, y + h);
|
||||
stringw message = m_properties[PROP_TEXT].c_str();
|
||||
m_element = GUIEngine::getGUIEnv()->addButton(widget_size, NULL, ++id_counter, message.c_str(), L"");
|
||||
|
||||
|
||||
id = m_element->getID();
|
||||
m_element->setTabOrder(id);
|
||||
m_element->setTabGroup(false);
|
||||
@@ -239,16 +239,16 @@ void LabelWidget::add()
|
||||
rect<s32> widget_size = rect<s32>(x, y, x + w, y + h);
|
||||
const bool word_wrap = m_properties[PROP_WORD_WRAP] == "true";
|
||||
stringw message = m_properties[PROP_TEXT].c_str();
|
||||
|
||||
|
||||
EGUI_ALIGNMENT align = EGUIA_UPPERLEFT;
|
||||
if(m_properties[PROP_TEXT_ALIGN] == "center") align = EGUIA_CENTER;
|
||||
else if(m_properties[PROP_TEXT_ALIGN] == "right") align = EGUIA_LOWERRIGHT;
|
||||
EGUI_ALIGNMENT valign = EGUIA_CENTER ; // TODO - make confiurable through XML file?
|
||||
|
||||
|
||||
IGUIStaticText* irrwidget = GUIEngine::getGUIEnv()->addStaticText(message.c_str(), widget_size, false, word_wrap, NULL, -1);
|
||||
m_element = irrwidget;
|
||||
irrwidget->setTextAlignment( align, valign );
|
||||
|
||||
|
||||
id = m_element->getID();
|
||||
//m_element->setTabOrder(id);
|
||||
m_element->setTabStop(false);
|
||||
@@ -271,7 +271,7 @@ void CheckBoxWidget::add()
|
||||
rect<s32> widget_size = rect<s32>(x, y, x + w, y + h);
|
||||
stringw message = m_properties[PROP_TEXT].c_str();
|
||||
//m_element = GUIEngine::getGUIEnv()->addCheckBox(true /* checked */, widget_size, NULL, ++id_counter, message.c_str());
|
||||
|
||||
|
||||
m_element = GUIEngine::getGUIEnv()->addButton(widget_size, NULL, ++id_counter, L"");
|
||||
id = m_element->getID();
|
||||
m_element->setTabOrder(id);
|
||||
@@ -282,7 +282,7 @@ bool CheckBoxWidget::transmitEvent(Widget* w, std::string& originator)
|
||||
{
|
||||
/* toggle */
|
||||
m_state = !m_state;
|
||||
|
||||
|
||||
/* notify main event handler */
|
||||
return true;
|
||||
}
|
||||
@@ -308,7 +308,7 @@ void IconButtonWidget::add()
|
||||
if(w < texture_w) ... ;
|
||||
if(h < texture_h) ... ;
|
||||
*/
|
||||
rect<s32> widget_size;
|
||||
rect<s32> widget_size;
|
||||
if(clickable)
|
||||
{
|
||||
widget_size = rect<s32>(x, y, x + w, y + h);
|
||||
@@ -324,9 +324,9 @@ 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)texture_w * (float)h / texture_h);
|
||||
|
||||
|
||||
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);
|
||||
m_element = btn;
|
||||
btn->setUseAlphaChannel(true);
|
||||
@@ -343,26 +343,26 @@ void IconButtonWidget::add()
|
||||
label->setTextAlignment(EGUIA_CENTER, EGUIA_UPPERLEFT);
|
||||
label->setTabStop(false);
|
||||
}
|
||||
|
||||
|
||||
id = m_element->getID();
|
||||
if(clickable) m_element->setTabOrder(id);
|
||||
m_element->setTabGroup(false);
|
||||
|
||||
|
||||
/*
|
||||
IGUISpriteBank* sprite_bank = GUIEngine::getGUIEnv()->getSkin()->getSpriteBank();
|
||||
// GUIEngine::getDriver()->makeColorKeyTexture(GUIEngine::getDriver()->getTexture("irrlichtlogo2.png"), position2di(0,0));
|
||||
IGUISpriteBank* sprite_bank = GUIEngine::getGUIEnv()->getSkin()->getSpriteBank();
|
||||
// GUIEngine::getDriver()->makeColorKeyTexture(GUIEngine::getDriver()->getTexture("irrlichtlogo2.png"), position2di(0,0));
|
||||
sprite_bank->addTexture( GUIEngine::getDriver()->getTexture("irrlichtlogo2.png") );
|
||||
|
||||
|
||||
SGUISprite sprite;
|
||||
sprite.frameTime = 3000;
|
||||
SGUISpriteFrame frame;
|
||||
core::array<core::rect<s32> >& rectangles = sprite_bank->getPositions();
|
||||
core::array<core::rect<s32> >& rectangles = sprite_bank->getPositions();
|
||||
rectangles.push_back(rect<s32>(0,0,128,128));
|
||||
frame.rectNumber = rectangles.size()-1;
|
||||
frame.textureNumber = sprite_bank->getTextureCount() - 1;
|
||||
sprite.Frames.push_back(frame);
|
||||
sprite_bank->getSprites().push_back(sprite);
|
||||
|
||||
sprite_bank->getSprites().push_back(sprite);
|
||||
|
||||
button->setSpriteBank(sprite_bank);
|
||||
button->setSprite(EGBS_BUTTON_UP, sprite_bank->getSprites().size()-1);
|
||||
button->setSprite(EGBS_BUTTON_DOWN, sprite_bank->getSprites().size()-1);
|
||||
@@ -374,9 +374,9 @@ void IconButtonWidget::setLabel(std::string new_label)
|
||||
std::cout << "trying to set label " << new_label.c_str() << std::endl;
|
||||
|
||||
if(label == NULL) return;
|
||||
|
||||
|
||||
std::cout << "set label " << new_label.c_str() << std::endl;
|
||||
|
||||
|
||||
label->setText( stringw(new_label.c_str()).c_str() );
|
||||
}
|
||||
|
||||
@@ -395,9 +395,9 @@ RibbonWidget::RibbonWidget(const RibbonType type)
|
||||
void RibbonWidget::select(std::string item)
|
||||
{
|
||||
const int subbuttons_amount = m_children.size();
|
||||
|
||||
|
||||
for(int i=0; i<subbuttons_amount; i++)
|
||||
{
|
||||
{
|
||||
if(m_children[i].m_properties[PROP_ID] == item)
|
||||
{
|
||||
m_selection = i;
|
||||
@@ -421,7 +421,7 @@ bool RibbonWidget::rightPressed()
|
||||
else m_selection = 0;
|
||||
}
|
||||
updateSelection();
|
||||
|
||||
|
||||
return m_ribbon_type != RIBBON_TOOLBAR;
|
||||
}
|
||||
// -----------------------------------------------------------------------------
|
||||
@@ -438,7 +438,7 @@ bool RibbonWidget::leftPressed()
|
||||
else m_selection = m_children.size()-1;
|
||||
}
|
||||
updateSelection();
|
||||
|
||||
|
||||
return m_ribbon_type != RIBBON_TOOLBAR;
|
||||
}
|
||||
// -----------------------------------------------------------------------------
|
||||
@@ -450,7 +450,7 @@ void RibbonWidget::focused()
|
||||
bool RibbonWidget::mouseHovered(Widget* child)
|
||||
{
|
||||
const int subbuttons_amount = m_children.size();
|
||||
|
||||
|
||||
for(int i=0; i<subbuttons_amount; i++)
|
||||
{
|
||||
if(m_children.get(i) == child)
|
||||
@@ -467,7 +467,7 @@ bool RibbonWidget::mouseHovered(Widget* child)
|
||||
void RibbonWidget::updateSelection()
|
||||
{
|
||||
const int subbuttons_amount = m_children.size();
|
||||
|
||||
|
||||
for(int i=0; i<subbuttons_amount; i++)
|
||||
{
|
||||
m_children[i].m_selected = (i == m_selection);
|
||||
@@ -477,7 +477,7 @@ void RibbonWidget::updateSelection()
|
||||
bool RibbonWidget::transmitEvent(Widget* w, std::string& originator)
|
||||
{
|
||||
const int subbuttons_amount = m_children.size();
|
||||
|
||||
|
||||
for(int i=0; i<subbuttons_amount; i++)
|
||||
{
|
||||
if(m_children[i].m_properties[PROP_ID] == originator)
|
||||
@@ -495,20 +495,20 @@ void RibbonWidget::add()
|
||||
{
|
||||
m_labels.clearWithoutDeleting();
|
||||
|
||||
|
||||
|
||||
rect<s32> widget_size = rect<s32>(x, y, x + w, y + h);
|
||||
|
||||
IGUIButton * btn = GUIEngine::getGUIEnv()->addButton(widget_size, NULL, ++id_counter, L"");
|
||||
m_element = btn;
|
||||
|
||||
|
||||
const int subbuttons_amount = m_children.size();
|
||||
|
||||
|
||||
// ---- check how much space each child button will take and fit them within available space
|
||||
int total_needed_space = 0;
|
||||
for(int i=0; i<subbuttons_amount; i++)
|
||||
{
|
||||
m_children[i].readCoords(this);
|
||||
|
||||
|
||||
if(m_children[i].m_type != WTYPE_ICON_BUTTON && m_children[i].m_type != WTYPE_BUTTON)
|
||||
{
|
||||
std::cerr << "/!\\ Warning /!\\ : ribbon widgets can only have (icon)button widgets as children " << std::endl;
|
||||
@@ -516,34 +516,34 @@ void RibbonWidget::add()
|
||||
}
|
||||
total_needed_space += m_children[i].w;
|
||||
}
|
||||
|
||||
|
||||
int free_h_space = w - total_needed_space;
|
||||
|
||||
|
||||
int biggest_y = 0;
|
||||
const int button_y = 10;
|
||||
float global_zoom = 1;
|
||||
|
||||
|
||||
const int min_free_space = 50;
|
||||
global_zoom = (float)w / (float)( w - free_h_space + min_free_space );
|
||||
free_h_space = (int)(w - total_needed_space*global_zoom);
|
||||
|
||||
|
||||
const int one_button_space = (int)round((float)w / (float)subbuttons_amount);
|
||||
|
||||
// ---- add children
|
||||
|
||||
// ---- add children
|
||||
for(int i=0; i<subbuttons_amount; i++)
|
||||
{
|
||||
|
||||
const int widget_x = one_button_space*(i+1) - one_button_space/2;
|
||||
|
||||
|
||||
IGUIButton * subbtn;
|
||||
|
||||
|
||||
if(/*m_children[i].m_type == WTYPE_BUTTON*/ getRibbonType() == RIBBON_TABS)
|
||||
{
|
||||
rect<s32> subsize = rect<s32>(widget_x - one_button_space/2+2, 0,
|
||||
rect<s32> subsize = rect<s32>(widget_x - one_button_space/2+2, 0,
|
||||
widget_x + one_button_space/2-2, h);
|
||||
|
||||
|
||||
stringw message = m_children[i].m_properties[PROP_TEXT].c_str();
|
||||
|
||||
|
||||
if(m_children[i].m_type == WTYPE_BUTTON)
|
||||
{
|
||||
subbtn = GUIEngine::getGUIEnv()->addButton(subsize, btn, ++id_counter_2, message.c_str(), L"");
|
||||
@@ -559,19 +559,19 @@ void RibbonWidget::add()
|
||||
rect<s32> label_part = rect<s32>(subsize.getHeight()+15,
|
||||
0,
|
||||
subsize.getWidth()-15,
|
||||
subsize.getHeight());
|
||||
|
||||
subsize.getHeight());
|
||||
|
||||
// use the same ID for all subcomponents; since event handling is done per-ID, no matter
|
||||
// which one your hover, this widget will get it
|
||||
int same_id = ++id_counter_2;
|
||||
subbtn = GUIEngine::getGUIEnv()->addButton(subsize, btn, same_id, L"", L"");
|
||||
|
||||
|
||||
MyGUIButton* icon = new MyGUIButton(GUIEngine::getGUIEnv(), subbtn, same_id, icon_part, true);
|
||||
icon->setImage( GUIEngine::getDriver()->getTexture((file_manager->getDataDir() + "/" + m_children[i].m_properties[PROP_ICON]).c_str()) );
|
||||
icon->setUseAlphaChannel(true);
|
||||
icon->setDrawBorder(false);
|
||||
icon->setTabStop(false);
|
||||
|
||||
|
||||
IGUIStaticText* label = GUIEngine::getGUIEnv()->addStaticText(message.c_str(), label_part,
|
||||
false /* border */,
|
||||
true /* word wrap */,
|
||||
@@ -580,54 +580,54 @@ void RibbonWidget::add()
|
||||
label->setTabStop(false);
|
||||
label->setNotClipped(true);
|
||||
m_labels.push_back(label);
|
||||
|
||||
|
||||
subbtn->setTabStop(false);
|
||||
subbtn->setTabGroup(false);
|
||||
|
||||
}
|
||||
|
||||
|
||||
m_children[i].m_element = subbtn;
|
||||
}
|
||||
else if(m_children[i].m_type == WTYPE_ICON_BUTTON)
|
||||
{
|
||||
const bool has_label = m_children[i].m_properties[PROP_TEXT].size() > 0;
|
||||
|
||||
|
||||
// how much space to keep for the label under the button
|
||||
const int needed_space_under_button = has_label ? 30 : 10; // quite arbitrary for now
|
||||
// if button too high to fit, scale down
|
||||
float zoom = global_zoom;
|
||||
while(button_y + m_children[i].h*zoom + needed_space_under_button > h) zoom -= 0.01f;
|
||||
|
||||
|
||||
// ---- add bitmap button part
|
||||
const float image_w = m_children[i].w*zoom;
|
||||
rect<s32> subsize = rect<s32>(widget_x - (int)(image_w/2.0f), button_y,
|
||||
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));
|
||||
|
||||
|
||||
subbtn = new MyGUIButton(GUIEngine::getGUIEnv(), btn, ++id_counter_2, subsize, true);
|
||||
|
||||
|
||||
m_children[i].m_element = subbtn;
|
||||
subbtn->setUseAlphaChannel(true);
|
||||
subbtn->setImage( GUIEngine::getDriver()->getTexture((file_manager->getDataDir() + "/" + m_children[i].m_properties[PROP_ICON]).c_str()) );
|
||||
|
||||
// ---- label part
|
||||
if(has_label)
|
||||
{
|
||||
{
|
||||
subsize = rect<s32>(widget_x - one_button_space/2,
|
||||
(int)((button_y + m_children[i].h)*zoom) + 5 /* leave 5 pixels between button and label */,
|
||||
(int)((button_y + m_children[i].h)*zoom) + 5 /* leave 5 pixels between button and label */,
|
||||
widget_x + (int)(one_button_space/2.0f), h);
|
||||
|
||||
|
||||
stringw message = m_children[i].m_properties[PROP_TEXT].c_str();
|
||||
IGUIStaticText* label = GUIEngine::getGUIEnv()->addStaticText(message.c_str(), subsize, false, true, btn);
|
||||
label->setTextAlignment(EGUIA_CENTER, EGUIA_CENTER);
|
||||
label->setTabStop(false);
|
||||
label->setNotClipped(true);
|
||||
|
||||
|
||||
m_labels.push_back(label);
|
||||
|
||||
|
||||
const int final_y = subsize.getHeight() + label->getTextHeight();
|
||||
if(final_y > biggest_y) biggest_y = final_y;
|
||||
}
|
||||
|
||||
|
||||
subbtn->setTabStop(false);
|
||||
subbtn->setTabGroup(false);
|
||||
}
|
||||
@@ -635,12 +635,12 @@ void RibbonWidget::add()
|
||||
{
|
||||
std::cerr << "/!\\ Warning /!\\ : Invalid contents type in ribbon" << std::endl;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
m_children[i].id = subbtn->getID();
|
||||
m_children[i].m_event_handler = this;
|
||||
}// next sub-button
|
||||
|
||||
|
||||
id = m_element->getID();
|
||||
m_element->setTabOrder(id);
|
||||
m_element->setTabGroup(false);
|
||||
@@ -650,7 +650,7 @@ void RibbonWidget::add()
|
||||
void RibbonWidget::setLabel(const int id, std::string new_name)
|
||||
{
|
||||
if(m_labels.size() == 0) return; // ignore this call for ribbons without labels
|
||||
|
||||
|
||||
assert(id >= 0);
|
||||
assert(id < m_labels.size());
|
||||
m_labels[id].setText( stringw(new_name.c_str()).c_str() );
|
||||
@@ -671,7 +671,7 @@ void SpinnerWidget::add()
|
||||
// retrieve min and max values
|
||||
std::string min_s = m_properties[PROP_MIN_VALUE];
|
||||
std::string max_s = m_properties[PROP_MAX_VALUE];
|
||||
|
||||
|
||||
{
|
||||
int i;
|
||||
std::istringstream myStream(min_s);
|
||||
@@ -685,25 +685,25 @@ void SpinnerWidget::add()
|
||||
bool is_number = (myStream >> i)!=0;
|
||||
if(is_number) m_max = i;
|
||||
else m_max = 10;
|
||||
}
|
||||
|
||||
m_value = (m_min + m_max)/2;
|
||||
|
||||
}
|
||||
|
||||
m_value = (m_min + m_max)/2;
|
||||
|
||||
// create sub-widgets if they don't already exist
|
||||
if(m_children.size() == 0)
|
||||
{
|
||||
std::string& icon = m_properties[PROP_ICON];
|
||||
m_graphical = icon.size()>0;
|
||||
|
||||
|
||||
m_children.push_back( new Widget() );
|
||||
m_children.push_back( new Widget() );
|
||||
m_children.push_back( new Widget() );
|
||||
}
|
||||
|
||||
|
||||
rect<s32> widget_size = rect<s32>(x, y, x + w, y + h);
|
||||
IGUIButton * btn = GUIEngine::getGUIEnv()->addButton(widget_size, NULL, ++id_counter, L"");
|
||||
m_element = btn;
|
||||
|
||||
|
||||
// left arrow
|
||||
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" ");
|
||||
@@ -713,7 +713,7 @@ void SpinnerWidget::add()
|
||||
m_children[0].m_event_handler = this;
|
||||
m_children[0].m_properties[PROP_ID] = "left";
|
||||
m_children[0].id = m_children[0].m_element->getID();
|
||||
|
||||
|
||||
// label
|
||||
if(m_graphical)
|
||||
{
|
||||
@@ -723,7 +723,7 @@ void SpinnerWidget::add()
|
||||
ITexture* texture = GUIEngine::getDriver()->getTexture(imagefile);
|
||||
const int texture_width = texture->getSize().Width;
|
||||
const int free_h_space = w-h*2-texture_width; // to center image
|
||||
|
||||
|
||||
rect<s32> subsize_label = rect<s32>(h+free_h_space/2, 0, w-h+free_h_space/2, h);
|
||||
//IGUIButton* subbtn = GUIEngine::getGUIEnv()->addButton(subsize_label, btn, ++id_counter_2, L"");
|
||||
IGUIImage * subbtn = GUIEngine::getGUIEnv()->addImage(subsize_label, btn, ++id_counter_2);
|
||||
@@ -731,7 +731,7 @@ void SpinnerWidget::add()
|
||||
m_children[1].m_type = WTYPE_ICON_BUTTON;
|
||||
m_children[1].id = subbtn->getID();
|
||||
subbtn->setUseAlphaChannel(true);
|
||||
|
||||
|
||||
subbtn->setImage(texture);
|
||||
//subbtn->setScaleImage(true);
|
||||
}
|
||||
@@ -748,8 +748,8 @@ void SpinnerWidget::add()
|
||||
label->setTabStop(false);
|
||||
label->setNotClipped(true);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// right arrow
|
||||
rect<s32> subsize_right_arrow = rect<s32>(w-h, 0, w, h);
|
||||
IGUIButton * right_arrow = GUIEngine::getGUIEnv()->addButton(subsize_right_arrow, btn, ++id_counter_2, L" ");
|
||||
@@ -777,7 +777,7 @@ bool SpinnerWidget::transmitEvent(Widget* w, std::string& originator)
|
||||
{
|
||||
if(originator == "left") leftPressed();
|
||||
else if(originator == "right") rightPressed();
|
||||
|
||||
|
||||
GUIEngine::getGUIEnv()->setFocus(m_element);
|
||||
return true;
|
||||
}
|
||||
@@ -793,7 +793,7 @@ void SpinnerWidget::addLabel(std::string label)
|
||||
void SpinnerWidget::setValue(const int new_value)
|
||||
{
|
||||
m_value = new_value;
|
||||
|
||||
|
||||
if(m_graphical)
|
||||
{
|
||||
char imagefile[128];
|
||||
@@ -819,9 +819,9 @@ RibbonGridWidget::RibbonGridWidget(const int max_rows)
|
||||
m_needed_cols = 0;
|
||||
m_col_amount = 0;
|
||||
m_has_label = false;
|
||||
|
||||
|
||||
m_max_rows = max_rows;
|
||||
|
||||
|
||||
m_left_widget = NULL;
|
||||
m_right_widget = NULL;
|
||||
}
|
||||
@@ -831,35 +831,35 @@ void RibbonGridWidget::add()
|
||||
// Work-around for FIXME below... first clear children to avoid duplicates since we're adding everything again everytime
|
||||
m_children.clearAndDeleteAll();
|
||||
m_rows.clearWithoutDeleting();
|
||||
|
||||
|
||||
m_has_label = m_properties[PROP_TEXT] == "bottom";
|
||||
const int label_height = m_has_label ? 25 : 0;
|
||||
|
||||
|
||||
int child_width, child_height;
|
||||
child_width = atoi(m_properties[PROP_CHILD_WIDTH].c_str());
|
||||
child_height = atoi(m_properties[PROP_CHILD_HEIGHT].c_str());
|
||||
|
||||
|
||||
if( child_width == 0 || child_height == 0 )
|
||||
{
|
||||
std::cerr << "/!\\ Warning /!\\ : ribbon grid widgets require 'child_width' and 'child_height' arguments" << std::endl;
|
||||
child_width = 256;
|
||||
child_height = 256;
|
||||
}
|
||||
|
||||
|
||||
// decide how many rows and column we can show in the available space
|
||||
int row_amount = (int)round((h-label_height) / (float)child_height);
|
||||
//if(row_amount < 2) row_amount = 2;
|
||||
if(row_amount > m_max_rows) row_amount = m_max_rows;
|
||||
|
||||
|
||||
const float row_height = (float)(h - label_height)/(float)row_amount;
|
||||
|
||||
|
||||
float ratio_zoom = (float)row_height / (float)(child_height - label_height);
|
||||
m_col_amount = (int)round( w / ( child_width*ratio_zoom ) );
|
||||
|
||||
|
||||
// std::cout << "w=" << w << " child_width=" << child_width << " ratio_zoom="<< ratio_zoom << " m_col_amount=" << m_col_amount << std::endl;
|
||||
|
||||
|
||||
//if(m_col_amount < 5) m_col_amount = 5;
|
||||
|
||||
|
||||
// add rows
|
||||
for(int n=0; n<row_amount; n++)
|
||||
{
|
||||
@@ -875,20 +875,20 @@ void RibbonGridWidget::add()
|
||||
ribbon->m_type = WTYPE_RIBBON;
|
||||
ribbon->m_properties[PROP_ID] = this->m_properties[PROP_ID];
|
||||
ribbon->m_event_handler = this;
|
||||
|
||||
|
||||
// add columns
|
||||
for(int i=0; i<m_col_amount; i++)
|
||||
{
|
||||
IconButtonWidget* icon = new IconButtonWidget();
|
||||
icon->m_properties[PROP_ICON]="gui/track_random.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];
|
||||
if(m_properties[PROP_TEXT] == "all") icon->m_properties[PROP_TEXT] = "hello";
|
||||
|
||||
|
||||
// std::cout << "ribbon text = " << m_properties[PROP_TEXT].c_str() << std::endl;
|
||||
|
||||
|
||||
icon->m_type = WTYPE_ICON_BUTTON;
|
||||
ribbon->m_children.push_back( icon );
|
||||
}
|
||||
@@ -896,7 +896,7 @@ void RibbonGridWidget::add()
|
||||
m_rows.push_back( ribbon );
|
||||
ribbon->add();
|
||||
}
|
||||
|
||||
|
||||
// add label at bottom
|
||||
if(m_has_label)
|
||||
{
|
||||
@@ -904,7 +904,7 @@ void RibbonGridWidget::add()
|
||||
m_label = GUIEngine::getGUIEnv()->addStaticText(L"Selecte a track...", label_size, false, true /* word wrap */, NULL, -1);
|
||||
m_label->setTextAlignment( EGUIA_CENTER, EGUIA_CENTER );
|
||||
}
|
||||
|
||||
|
||||
// add arrow buttons on each side
|
||||
// FIXME? these arrow buttons are outside of the widget's boundaries
|
||||
if(m_left_widget != NULL)
|
||||
@@ -915,7 +915,7 @@ void RibbonGridWidget::add()
|
||||
}
|
||||
m_left_widget = new Widget();
|
||||
m_right_widget = new Widget();
|
||||
|
||||
|
||||
const int average_y = y + (h-label_height)/2;
|
||||
const int button_w = 30, button_h = 50;
|
||||
rect<s32> right_arrow_location = rect<s32>(x + w,
|
||||
@@ -930,7 +930,7 @@ void RibbonGridWidget::add()
|
||||
m_right_widget->m_properties[PROP_ID] = "right";
|
||||
m_right_widget->id = right_arrow->getID();
|
||||
m_children.push_back( m_right_widget );
|
||||
|
||||
|
||||
rect<s32> left_arrow_location = rect<s32>(x - button_w,
|
||||
average_y - button_h/2,
|
||||
x,
|
||||
@@ -951,7 +951,7 @@ bool RibbonGridWidget::rightPressed()
|
||||
if(w != NULL)
|
||||
{
|
||||
w->rightPressed();
|
||||
|
||||
|
||||
updateLabel();
|
||||
propagateSelection();
|
||||
}
|
||||
@@ -964,7 +964,7 @@ bool RibbonGridWidget::leftPressed()
|
||||
if(w != NULL)
|
||||
{
|
||||
w->leftPressed();
|
||||
|
||||
|
||||
updateLabel();
|
||||
propagateSelection();
|
||||
}
|
||||
@@ -983,11 +983,11 @@ bool RibbonGridWidget::transmitEvent(Widget* w, std::string& originator)
|
||||
scroll(1);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
// if it's something else, it might be a ribbon child with its own parent
|
||||
if(w->m_event_handler != NULL && w->m_event_handler != this)
|
||||
return w->m_event_handler->transmitEvent(w, originator);
|
||||
|
||||
|
||||
// if we got there, must be a ribbon itself. in this case we can just transmit the event directly
|
||||
return true;
|
||||
}
|
||||
@@ -995,12 +995,12 @@ bool RibbonGridWidget::transmitEvent(Widget* w, std::string& originator)
|
||||
void RibbonGridWidget::scroll(const int x_delta)
|
||||
{
|
||||
m_scroll_offset += x_delta;
|
||||
|
||||
|
||||
const int max_scroll = std::max(m_col_amount, m_needed_cols) - 1;
|
||||
|
||||
|
||||
if(m_scroll_offset < 0) m_scroll_offset = max_scroll;
|
||||
else if(m_scroll_offset > max_scroll) m_scroll_offset = 0;
|
||||
|
||||
|
||||
updateItemDisplay();
|
||||
}
|
||||
// -----------------------------------------------------------------------------
|
||||
@@ -1021,7 +1021,7 @@ void RibbonGridWidget::propagateSelection()
|
||||
RibbonWidget* selected_ribbon = (RibbonWidget*)getSelectedRibbon();
|
||||
if(selected_ribbon == NULL) return;
|
||||
const int i = selected_ribbon->m_selection;
|
||||
|
||||
|
||||
// set same selection in all ribbons
|
||||
const int row_amount = m_rows.size();
|
||||
for(int n=0; n<row_amount; n++)
|
||||
@@ -1043,13 +1043,13 @@ void RibbonGridWidget::focused()
|
||||
void RibbonGridWidget::updateLabel(RibbonWidget* from_this_ribbon)
|
||||
{
|
||||
if(!m_has_label) return;
|
||||
|
||||
|
||||
RibbonWidget* row = from_this_ribbon ? from_this_ribbon : (RibbonWidget*)getSelectedRibbon();
|
||||
if(row == NULL) return;
|
||||
|
||||
|
||||
|
||||
|
||||
std::string selection_id = row->getSelectionName();
|
||||
|
||||
|
||||
const int amount = m_items.size();
|
||||
for(int n=0; n<amount; n++)
|
||||
{
|
||||
@@ -1059,7 +1059,7 @@ void RibbonGridWidget::updateLabel(RibbonWidget* from_this_ribbon)
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
m_label->setText( L"Random" );
|
||||
}
|
||||
// -----------------------------------------------------------------------------
|
||||
@@ -1069,59 +1069,56 @@ void RibbonGridWidget::addItem( std::string user_name, std::string code_name, st
|
||||
desc.m_user_name = user_name;
|
||||
desc.m_code_name = code_name;
|
||||
desc.m_sshot_file = image_file;
|
||||
|
||||
|
||||
m_items.push_back(desc);
|
||||
}
|
||||
// -----------------------------------------------------------------------------
|
||||
void RibbonGridWidget::setSelection(int item_id)
|
||||
{
|
||||
setSelection(m_items[item_id].m_code_name);
|
||||
}
|
||||
void RibbonGridWidget::setSelection(const std::string& code_name)
|
||||
{
|
||||
if(m_rows.size() > 1)
|
||||
{
|
||||
std::cout << "/!\\ Warning, RibbonGridWidget::setSelection only makes sense on 1-row ribbons (since there can't logically be a selection with more than one row)\n";
|
||||
}
|
||||
|
||||
|
||||
// select the said item (mostly to get its ID)
|
||||
RibbonWidget* ribbon = m_rows.get(0);
|
||||
ribbon->select(code_name);
|
||||
|
||||
|
||||
// scroll so selection is visible
|
||||
m_scroll_offset = ribbon->m_selection;
|
||||
m_scroll_offset = item_id;
|
||||
updateItemDisplay();
|
||||
|
||||
|
||||
// set selection again, because scrolling made it wrong
|
||||
ribbon->select(code_name);
|
||||
RibbonWidget* ribbon = m_rows.get(0);
|
||||
ribbon->setSelection(0);
|
||||
}
|
||||
void RibbonGridWidget::setSelection(const std::string& code_name)
|
||||
{
|
||||
assert(false);
|
||||
}
|
||||
// -----------------------------------------------------------------------------
|
||||
void RibbonGridWidget::updateItemDisplay()
|
||||
{
|
||||
int icon_id = 0;
|
||||
|
||||
|
||||
const int row_amount = m_rows.size();
|
||||
const int item_amount = m_items.size();
|
||||
|
||||
|
||||
m_needed_cols = (int)ceil( (float)item_amount / (float)row_amount );
|
||||
|
||||
const int max_scroll = std::max(m_col_amount, m_needed_cols) - 1;
|
||||
|
||||
|
||||
for(int n=0; n<row_amount; n++)
|
||||
{
|
||||
RibbonWidget& row = m_rows[n];
|
||||
|
||||
|
||||
for(int i=0; i<m_col_amount; i++)
|
||||
{
|
||||
IconButtonWidget* icon = dynamic_cast<IconButtonWidget*>(&row.m_children[i]);
|
||||
assert(icon != NULL);
|
||||
IGUIButton* button = dynamic_cast<IGUIButton*>(icon->m_element);
|
||||
assert(button != NULL);
|
||||
|
||||
|
||||
int col_scroll = i + m_scroll_offset;
|
||||
while(col_scroll > max_scroll) col_scroll -= max_scroll+1;
|
||||
|
||||
|
||||
icon_id = (col_scroll)*row_amount + n;
|
||||
|
||||
if( icon_id < item_amount )
|
||||
@@ -1146,7 +1143,7 @@ const std::string& RibbonGridWidget::getSelectionName()
|
||||
{
|
||||
RibbonWidget* row = (RibbonWidget*)getSelectedRibbon();
|
||||
if(row != NULL) return row->getSelectionName();
|
||||
|
||||
|
||||
static const std::string nothing = "";
|
||||
return nothing;
|
||||
}
|
||||
@@ -1162,7 +1159,7 @@ RibbonWidget* RibbonGridWidget::getRowContaining(Widget* w) const
|
||||
if(m_children.contains( w ) ) return (RibbonWidget*)row;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return NULL;
|
||||
}
|
||||
// -----------------------------------------------------------------------------
|
||||
@@ -1178,7 +1175,7 @@ RibbonWidget* RibbonGridWidget::getSelectedRibbon() const
|
||||
m_element->isMyChild( GUIEngine::getGUIEnv()->getFocus() ) ) return (RibbonWidget*)row;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -1192,9 +1189,9 @@ void ModelViewWidget::add()
|
||||
{
|
||||
rect<s32> widget_size = rect<s32>(x, y, x + w, y + h);
|
||||
stringw message = m_properties[PROP_TEXT].c_str();
|
||||
|
||||
|
||||
m_element = GUIEngine::getGUIEnv()->addMeshViewer(widget_size, NULL, ++id_counter_2);
|
||||
|
||||
|
||||
id = m_element->getID();
|
||||
//m_element->setTabOrder(id);
|
||||
m_element->setTabGroup(false);
|
||||
@@ -1204,7 +1201,7 @@ void ModelViewWidget::add()
|
||||
void ModelViewWidget::setModel(SAnimatedMesh* mesh)
|
||||
{
|
||||
((IGUIMeshViewer*)m_element)->setMesh( mesh );
|
||||
|
||||
|
||||
video::SMaterial mat = mesh->getMeshBuffer(0)->getMaterial(); //mesh_view->getMaterial();
|
||||
mat.setFlag(EMF_LIGHTING , false);
|
||||
//mat.setFlag(EMF_GOURAUD_SHADING, false);
|
||||
@@ -1224,15 +1221,15 @@ void ListWidget::add()
|
||||
rect<s32> widget_size = rect<s32>(x, y, x + w, y + h);
|
||||
|
||||
IGUIListBox* list = GUIEngine::getGUIEnv()->addListBox (widget_size, NULL, ++id_counter);
|
||||
|
||||
|
||||
id = list->getID();
|
||||
list->addItem( L"Hiker" );
|
||||
list->addItem( L"Conso" );
|
||||
list->addItem( L"Auria" );
|
||||
list->addItem( L"MiniBjorn" );
|
||||
list->addItem( L"Arthur" );
|
||||
|
||||
|
||||
m_element = list;
|
||||
|
||||
|
||||
//list->setSelected(0);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user