Rework MeshViewer:
- Break up EventHandler into more functions - Add enums for all ID's - Fix scaling display - Add quick-scale buttons for *10 and * 0.01 git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@2953 dfc29bdd-3216-0410-991c-e03cc46cb475master
parent
be53718e91
commit
ffe43a25e9
|
@ -76,11 +76,24 @@ enum
|
|||
GUI_ID_ABOUT,
|
||||
GUI_ID_QUIT,
|
||||
|
||||
GUI_ID_TEXTUREFILTER,
|
||||
GUI_ID_SKIN_TRANSPARENCY,
|
||||
GUI_ID_SKIN_ANIMATION_FPS,
|
||||
|
||||
GUI_ID_BUTTON_SET_SCALE,
|
||||
GUI_ID_BUTTON_SCALE_MUL10,
|
||||
GUI_ID_BUTTON_SCALE_DIV10,
|
||||
GUI_ID_BUTTON_OPEN_MODEL,
|
||||
GUI_ID_BUTTON_SHOW_ABOUT,
|
||||
GUI_ID_BUTTON_SHOW_TOOLBOX,
|
||||
GUI_ID_BUTTON_SELECT_ARCHIVE,
|
||||
|
||||
// And some magic numbers
|
||||
MAX_FRAMERATE = 1000,
|
||||
DEFAULT_FRAMERATE = 30
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
Toggle between various cameras
|
||||
*/
|
||||
|
@ -96,6 +109,40 @@ void setActiveCamera(scene::ICameraSceneNode* newActive)
|
|||
Device->getSceneManager()->setActiveCamera(newActive);
|
||||
}
|
||||
|
||||
/*
|
||||
Set the skin transparency by changing the alpha values of all skin-colors
|
||||
*/
|
||||
void SetSkinTransparency(s32 alpha, irr::gui::IGUISkin * skin)
|
||||
{
|
||||
for (s32 i=0; i<irr::gui::EGDC_COUNT ; ++i)
|
||||
{
|
||||
video::SColor col = skin->getColor((EGUI_DEFAULT_COLOR)i);
|
||||
col.setAlpha(alpha);
|
||||
skin->setColor((EGUI_DEFAULT_COLOR)i, col);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
Update the display of the model scaling
|
||||
*/
|
||||
void UpdateScaleInfo(scene::ISceneNode* model)
|
||||
{
|
||||
IGUIElement* toolboxWnd = Device->getGUIEnvironment()->getRootGUIElement()->getElementFromId(GUI_ID_DIALOG_ROOT_WINDOW, true);
|
||||
if (!model)
|
||||
{
|
||||
toolboxWnd->getElementFromId(GUI_ID_X_SCALE, true)->setText( L"-" );
|
||||
toolboxWnd->getElementFromId(GUI_ID_Y_SCALE, true)->setText( L"-" );
|
||||
toolboxWnd->getElementFromId(GUI_ID_Z_SCALE, true)->setText( L"-" );
|
||||
}
|
||||
else
|
||||
{
|
||||
core::vector3df scale = model->getScale();
|
||||
toolboxWnd->getElementFromId(GUI_ID_X_SCALE, true)->setText( core::stringw(scale.X).c_str() );
|
||||
toolboxWnd->getElementFromId(GUI_ID_Y_SCALE, true)->setText( core::stringw(scale.Y).c_str() );
|
||||
toolboxWnd->getElementFromId(GUI_ID_Z_SCALE, true)->setText( core::stringw(scale.Z).c_str() );
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
The three following functions do several stuff used by the mesh viewer. The
|
||||
first function showAboutText() simply displays a messagebox with a caption and
|
||||
|
@ -198,13 +245,7 @@ void loadModel(const c8* fn)
|
|||
if (menu)
|
||||
for(int item = 1; item < 6; ++item)
|
||||
menu->setItemChecked(item, false);
|
||||
IGUIElement* toolboxWnd = Device->getGUIEnvironment()->getRootGUIElement()->getElementFromId(GUI_ID_DIALOG_ROOT_WINDOW, true);
|
||||
if ( toolboxWnd )
|
||||
{
|
||||
toolboxWnd->getElementFromId(GUI_ID_X_SCALE, true)->setText(L"1.0");
|
||||
toolboxWnd->getElementFromId(GUI_ID_Y_SCALE, true)->setText(L"1.0");
|
||||
toolboxWnd->getElementFromId(GUI_ID_Z_SCALE, true)->setText(L"1.0");
|
||||
}
|
||||
UpdateScaleInfo(Model);
|
||||
}
|
||||
|
||||
|
||||
|
@ -234,7 +275,7 @@ void createToolBox()
|
|||
|
||||
// add some edit boxes and a button to tab one
|
||||
env->addStaticText(L"Scale:",
|
||||
core::rect<s32>(10,20,150,45), false, false, t1);
|
||||
core::rect<s32>(10,20,60,45), false, false, t1);
|
||||
env->addStaticText(L"X:", core::rect<s32>(22,48,40,66), false, false, t1);
|
||||
env->addEditBox(L"1.0", core::rect<s32>(40,46,130,66), true, t1, GUI_ID_X_SCALE);
|
||||
env->addStaticText(L"Y:", core::rect<s32>(22,82,40,GUI_ID_OPEN_MODEL), false, false, t1);
|
||||
|
@ -242,13 +283,19 @@ void createToolBox()
|
|||
env->addStaticText(L"Z:", core::rect<s32>(22,108,40,126), false, false, t1);
|
||||
env->addEditBox(L"1.0", core::rect<s32>(40,106,130,126), true, t1, GUI_ID_Z_SCALE);
|
||||
|
||||
env->addButton(core::rect<s32>(10,134,85,165), t1, 1101, L"Set");
|
||||
env->addButton(core::rect<s32>(10,134,85,165), t1, GUI_ID_BUTTON_SET_SCALE, L"Set");
|
||||
|
||||
// quick scale buttons
|
||||
env->addButton(core::rect<s32>(65,20,95,40), t1, GUI_ID_BUTTON_SCALE_MUL10, L"* 10");
|
||||
env->addButton(core::rect<s32>(100,20,130,40), t1, GUI_ID_BUTTON_SCALE_DIV10, L"* 0.1");
|
||||
|
||||
UpdateScaleInfo(Model);
|
||||
|
||||
// add transparency control
|
||||
env->addStaticText(L"GUI Transparency Control:",
|
||||
core::rect<s32>(10,200,150,225), true, false, t1);
|
||||
IGUIScrollBar* scrollbar = env->addScrollBar(true,
|
||||
core::rect<s32>(10,225,150,240), t1, 104);
|
||||
core::rect<s32>(10,225,150,240), t1, GUI_ID_SKIN_TRANSPARENCY);
|
||||
scrollbar->setMax(255);
|
||||
scrollbar->setPos(255);
|
||||
|
||||
|
@ -256,7 +303,7 @@ void createToolBox()
|
|||
env->addStaticText(L"Framerate:",
|
||||
core::rect<s32>(10,240,150,265), true, false, t1);
|
||||
scrollbar = env->addScrollBar(true,
|
||||
core::rect<s32>(10,265,150,280), t1, 105);
|
||||
core::rect<s32>(10,265,150,280), t1, GUI_ID_SKIN_ANIMATION_FPS);
|
||||
scrollbar->setMax(MAX_FRAMERATE);
|
||||
scrollbar->setPos(DEFAULT_FRAMERATE);
|
||||
|
||||
|
@ -265,7 +312,6 @@ void createToolBox()
|
|||
root->bringToFront(root->getElementFromId(666, true));
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
To get all the events sent by the GUI Elements, we need to create an event
|
||||
receiver. This one is really simple. If an event occurs, it checks the id of
|
||||
|
@ -327,15 +373,112 @@ public:
|
|||
switch(event.GUIEvent.EventType)
|
||||
{
|
||||
case EGET_MENU_ITEM_SELECTED:
|
||||
{
|
||||
// a menu item was clicked
|
||||
OnMenuItemSelected( (IGUIContextMenu*)event.GUIEvent.Caller );
|
||||
break;
|
||||
|
||||
IGUIContextMenu* menu = (IGUIContextMenu*)event.GUIEvent.Caller;
|
||||
s32 id = menu->getItemCommandId(menu->getSelectedItem());
|
||||
case EGET_FILE_SELECTED:
|
||||
{
|
||||
// load the model file, selected in the file open dialog
|
||||
IGUIFileOpenDialog* dialog =
|
||||
(IGUIFileOpenDialog*)event.GUIEvent.Caller;
|
||||
loadModel(core::stringc(dialog->getFileName()).c_str());
|
||||
}
|
||||
break;
|
||||
|
||||
case EGET_SCROLL_BAR_CHANGED:
|
||||
|
||||
// control skin transparency
|
||||
if (id == GUI_ID_SKIN_TRANSPARENCY)
|
||||
{
|
||||
const s32 pos = ((IGUIScrollBar*)event.GUIEvent.Caller)->getPos();
|
||||
SetSkinTransparency(pos, env->getSkin());
|
||||
}
|
||||
// control animation speed
|
||||
else if (id == GUI_ID_SKIN_ANIMATION_FPS)
|
||||
{
|
||||
const s32 pos = ((IGUIScrollBar*)event.GUIEvent.Caller)->getPos();
|
||||
if (scene::ESNT_ANIMATED_MESH == Model->getType())
|
||||
((scene::IAnimatedMeshSceneNode*)Model)->setAnimationSpeed((f32)pos);
|
||||
}
|
||||
break;
|
||||
|
||||
case EGET_COMBO_BOX_CHANGED:
|
||||
|
||||
// control anti-aliasing/filtering
|
||||
if (id == GUI_ID_TEXTUREFILTER)
|
||||
{
|
||||
OnTextureFilterSelected( (IGUIComboBox*)event.GUIEvent.Caller );
|
||||
}
|
||||
break;
|
||||
|
||||
case EGET_BUTTON_CLICKED:
|
||||
|
||||
switch(id)
|
||||
{
|
||||
case GUI_ID_OPEN_MODEL: // File -> Open Model
|
||||
case GUI_ID_BUTTON_SET_SCALE:
|
||||
{
|
||||
// set scale
|
||||
gui::IGUIElement* root = env->getRootGUIElement();
|
||||
core::vector3df scale;
|
||||
core::stringc s;
|
||||
|
||||
s = root->getElementFromId(GUI_ID_X_SCALE, true)->getText();
|
||||
scale.X = (f32)atof(s.c_str());
|
||||
s = root->getElementFromId(GUI_ID_Y_SCALE, true)->getText();
|
||||
scale.Y = (f32)atof(s.c_str());
|
||||
s = root->getElementFromId(GUI_ID_Z_SCALE, true)->getText();
|
||||
scale.Z = (f32)atof(s.c_str());
|
||||
|
||||
if (Model)
|
||||
Model->setScale(scale);
|
||||
UpdateScaleInfo(Model);
|
||||
}
|
||||
break;
|
||||
case GUI_ID_BUTTON_SCALE_MUL10:
|
||||
if (Model)
|
||||
Model->setScale(Model->getScale()*10.f);
|
||||
UpdateScaleInfo(Model);
|
||||
break;
|
||||
case GUI_ID_BUTTON_SCALE_DIV10:
|
||||
if (Model)
|
||||
Model->setScale(Model->getScale()*0.1f);
|
||||
UpdateScaleInfo(Model);
|
||||
break;
|
||||
case GUI_ID_BUTTON_OPEN_MODEL:
|
||||
env->addFileOpenDialog(L"Please select a model file to open");
|
||||
break;
|
||||
case GUI_ID_BUTTON_SHOW_ABOUT:
|
||||
showAboutText();
|
||||
break;
|
||||
case GUI_ID_BUTTON_SHOW_TOOLBOX:
|
||||
createToolBox();
|
||||
break;
|
||||
case GUI_ID_BUTTON_SELECT_ARCHIVE:
|
||||
env->addFileOpenDialog(L"Please select your game archive/directory");
|
||||
break;
|
||||
}
|
||||
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
Handle "menu item clicked" events.
|
||||
*/
|
||||
void OnMenuItemSelected( IGUIContextMenu* menu )
|
||||
{
|
||||
s32 id = menu->getItemCommandId(menu->getSelectedItem());
|
||||
IGUIEnvironment* env = Device->getGUIEnvironment();
|
||||
|
||||
switch(id)
|
||||
{
|
||||
case GUI_ID_OPEN_MODEL: // FilOnButtonSetScalinge -> Open Model
|
||||
env->addFileOpenDialog(L"Please select a model file to open");
|
||||
break;
|
||||
case GUI_ID_SET_MODEL_ARCHIVE: // File -> Set Model Archive
|
||||
|
@ -424,47 +567,15 @@ public:
|
|||
case GUI_ID_CAMERA_FIRST_PERSON:
|
||||
setActiveCamera(Camera[1]);
|
||||
break;
|
||||
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case EGET_FILE_SELECTED:
|
||||
/*
|
||||
Handle the event that one of the texture-filters was selected in the corresponding combobox.
|
||||
*/
|
||||
void OnTextureFilterSelected( IGUIComboBox* combo )
|
||||
{
|
||||
// load the model file, selected in the file open dialog
|
||||
IGUIFileOpenDialog* dialog =
|
||||
(IGUIFileOpenDialog*)event.GUIEvent.Caller;
|
||||
loadModel(core::stringc(dialog->getFileName()).c_str());
|
||||
}
|
||||
break;
|
||||
|
||||
case EGET_SCROLL_BAR_CHANGED:
|
||||
|
||||
// control skin transparency
|
||||
if (id == 104)
|
||||
{
|
||||
const s32 pos = ((IGUIScrollBar*)event.GUIEvent.Caller)->getPos();
|
||||
for (s32 i=0; i<irr::gui::EGDC_COUNT ; ++i)
|
||||
{
|
||||
video::SColor col = env->getSkin()->getColor((EGUI_DEFAULT_COLOR)i);
|
||||
col.setAlpha(pos);
|
||||
env->getSkin()->setColor((EGUI_DEFAULT_COLOR)i, col);
|
||||
}
|
||||
}
|
||||
else if (id == 105)
|
||||
{
|
||||
const s32 pos = ((IGUIScrollBar*)event.GUIEvent.Caller)->getPos();
|
||||
if (scene::ESNT_ANIMATED_MESH == Model->getType())
|
||||
((scene::IAnimatedMeshSceneNode*)Model)->setAnimationSpeed((f32)pos);
|
||||
}
|
||||
break;
|
||||
|
||||
case EGET_COMBO_BOX_CHANGED:
|
||||
|
||||
// control anti-aliasing/filtering
|
||||
if (id == 108)
|
||||
{
|
||||
s32 pos = ((IGUIComboBox*)event.GUIEvent.Caller)->getSelected();
|
||||
s32 pos = combo->getSelected();
|
||||
switch (pos)
|
||||
{
|
||||
case 0:
|
||||
|
@ -503,52 +614,6 @@ public:
|
|||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case EGET_BUTTON_CLICKED:
|
||||
|
||||
switch(id)
|
||||
{
|
||||
case 1101:
|
||||
{
|
||||
// set scale
|
||||
gui::IGUIElement* root = env->getRootGUIElement();
|
||||
core::vector3df scale;
|
||||
core::stringc s;
|
||||
|
||||
s = root->getElementFromId(GUI_ID_X_SCALE, true)->getText();
|
||||
scale.X = (f32)atof(s.c_str());
|
||||
s = root->getElementFromId(GUI_ID_Y_SCALE, true)->getText();
|
||||
scale.Y = (f32)atof(s.c_str());
|
||||
s = root->getElementFromId(GUI_ID_Z_SCALE, true)->getText();
|
||||
scale.Z = (f32)atof(s.c_str());
|
||||
|
||||
if (Model)
|
||||
Model->setScale(scale);
|
||||
}
|
||||
break;
|
||||
case 1102:
|
||||
env->addFileOpenDialog(L"Please select a model file to open");
|
||||
break;
|
||||
case 1103:
|
||||
showAboutText();
|
||||
break;
|
||||
case 1104:
|
||||
createToolBox();
|
||||
break;
|
||||
case 1105:
|
||||
env->addFileOpenDialog(L"Please select your game archive/directory");
|
||||
break;
|
||||
}
|
||||
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
@ -733,20 +798,20 @@ int main(int argc, char* argv[])
|
|||
gui::IGUIToolBar* bar = env->addToolBar();
|
||||
|
||||
video::ITexture* image = driver->getTexture("open.png");
|
||||
bar->addButton(1102, 0, L"Open a model",image, 0, false, true);
|
||||
bar->addButton(GUI_ID_BUTTON_OPEN_MODEL, 0, L"Open a model",image, 0, false, true);
|
||||
|
||||
image = driver->getTexture("tools.png");
|
||||
bar->addButton(1104, 0, L"Open Toolset",image, 0, false, true);
|
||||
bar->addButton(GUI_ID_BUTTON_SHOW_TOOLBOX, 0, L"Open Toolset",image, 0, false, true);
|
||||
|
||||
image = driver->getTexture("zip.png");
|
||||
bar->addButton(1105, 0, L"Set Model Archive",image, 0, false, true);
|
||||
bar->addButton(GUI_ID_BUTTON_SELECT_ARCHIVE, 0, L"Set Model Archive",image, 0, false, true);
|
||||
|
||||
image = driver->getTexture("help.png");
|
||||
bar->addButton(1103, 0, L"Open Help", image, 0, false, true);
|
||||
bar->addButton(GUI_ID_BUTTON_SHOW_ABOUT, 0, L"Open Help", image, 0, false, true);
|
||||
|
||||
// create a combobox with some senseless texts
|
||||
|
||||
gui::IGUIComboBox* box = env->addComboBox(core::rect<s32>(250,4,350,23), bar, 108);
|
||||
gui::IGUIComboBox* box = env->addComboBox(core::rect<s32>(250,4,350,23), bar, GUI_ID_TEXTUREFILTER);
|
||||
box->addItem(L"No filtering");
|
||||
box->addItem(L"Bilinear");
|
||||
box->addItem(L"Trilinear");
|
||||
|
|
Loading…
Reference in New Issue