Revision: 2389 http://rigsofrods.svn.sourceforge.net/rigsofrods/?rev=2389&view=rev Author: rorthomas Date: 2012-01-30 10:36:01 +0000 (Mon, 30 Jan 2012) Log Message: ----------- added texture tool window: allows the user to view and save textures
Modified Paths: -------------- trunk/bin/resources/mygui.zip trunk/source/main/gui/gui_menu.cpp Added Paths: ----------- trunk/source/main/gui/TextureToolWindow.cpp trunk/source/main/gui/TextureToolWindow.h Modified: trunk/bin/resources/mygui.zip =================================================================== (Binary files differ) Added: trunk/source/main/gui/TextureToolWindow.cpp =================================================================== --- trunk/source/main/gui/TextureToolWindow.cpp (rev 0) +++ trunk/source/main/gui/TextureToolWindow.cpp 2012-01-30 10:36:01 UTC (rev 2389) @@ -0,0 +1,225 @@ +/* +This source file is part of Rigs of Rods +Copyright 2005-2012 Pierre-Michel Ricordel +Copyright 2007-2012 Thomas Fischer + +For more information, see http://www.rigsofrods.com/ + +Rigs of Rods is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License version 3, as +published by the Free Software Foundation. + +Rigs of Rods is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with Rigs of Rods. If not, see <http://www.gnu.org/licenses/>. +*/ +#ifdef USE_MYGUI + +#include "TextureToolWindow.h" +#include "gui_manager.h" +#include "language.h" +#include "utils.h" +#include "Settings.h" +#include "Console.h" + +using namespace Ogre; + +TextureToolWindow::TextureToolWindow() +{ + initialiseByAttributes(this); + + ((MyGUI::Window*)mMainWidget)->setCaption(_L("Texture Tool")); + ((MyGUI::Window*)mMainWidget)->eventWindowButtonPressed += MyGUI::newDelegate(this, &TextureToolWindow::notifyWindowPressed); + + mBtnSavePNG->setCaption(_L("Save as PNG")); + mBtnSavePNG->eventMouseButtonClick += MyGUI::newDelegate(this, &TextureToolWindow::eventClickSavePNGButton); + + mBtnSaveRAW->setCaption(_L("Save Raw")); + mBtnSaveRAW->eventMouseButtonClick += MyGUI::newDelegate(this, &TextureToolWindow::eventClickSaveRAWButton); + + mCBo->eventComboAccept += MyGUI::newDelegate(this, &TextureToolWindow::eventSelectTexture); + mCBo->eventComboChangePosition += MyGUI::newDelegate(this, &TextureToolWindow::eventSelectTexture2); + + mChkDynamic->eventMouseButtonClick += MyGUI::newDelegate(this, &TextureToolWindow::eventClickDynamicButton); +} + +TextureToolWindow::~TextureToolWindow() +{ +} + +void TextureToolWindow::show() +{ + ((MyGUI::Window*)mMainWidget)->setVisibleSmooth(true); + //((MyGUI::Window*)mMainWidget)->setAlpha(0.9); + fillCombo(); +} + +void TextureToolWindow::fillCombo() +{ + bool dynamicOnly = mChkDynamic->getStateSelected(); + mCBo->deleteAllItems(); + + Ogre::ResourceManager::ResourceMapIterator it = Ogre::TextureManager::getSingleton().getResourceIterator(); + + while (it.hasMoreElements()) + { + Ogre::TexturePtr txt = (Ogre::TexturePtr)it.getNext(); + + if(dynamicOnly && ((txt->getUsage() & TU_STATIC) != 0)) continue; + + mCBo->addItem(txt->getName()); + } + + if(mCBo->getItemCount() > 0) + { + mCBo->setIndexSelected(0); + mCBo->beginToItemSelected(); + updateControls(mCBo->getItemNameAt(0)); + } +} + + +void TextureToolWindow::hide() +{ + ((MyGUI::Window*)mMainWidget)->setVisibleSmooth(false); +} + +void TextureToolWindow::notifyWindowPressed(MyGUI::Window* _widget, const std::string& _name) +{ + MyGUI::WindowPtr window = _widget->castType<MyGUI::Window>(); + if (_name == "close") + hide(); +} + +void TextureToolWindow::eventClickSavePNGButton( MyGUI::WidgetPtr _sender ) +{ + saveTexture(mCBo->getItemNameAt(mCBo->getItemIndexSelected()), true); +} + +void TextureToolWindow::eventClickSaveRAWButton( MyGUI::WidgetPtr _sender ) +{ + saveTexture(mCBo->getItemNameAt(mCBo->getItemIndexSelected()), false); +} + +void TextureToolWindow::eventSelectTexture( MyGUI::WidgetPtr _sender ) +{ + updateControls(mCBo->getItemNameAt(mCBo->getItemIndexSelected())); +} + +void TextureToolWindow::saveTexture( Ogre::String texName, bool usePNG ) +{ + try + { + TexturePtr tex = Ogre::TextureManager::getSingleton().getByName(texName); + if(tex.isNull()) return; + + Image img; + tex->convertToImage(img); + + // Save to disk! + String outname = SSETTING("User Path") + texName; + if(usePNG) outname += ".png"; + + img.save(outname); +#ifdef USE_MYGUI + UTFString msg = _L("saved texture as ") + outname; + Console::getInstance().putMessage(Console::CONSOLE_MSGTYPE_INFO, Console::CONSOLE_MSGTYPE_INFO, msg, "information.png"); +#endif //USE_MYGUI + } + catch(Exception &e) + { +#ifdef USE_MYGUI + UTFString str = "Exception while saving image:" + e.getFullDescription(); + Console::getInstance().putMessage(Console::CONSOLE_MSGTYPE_INFO, Console::CONSOLE_MSGTYPE_INFO, str, "error.png"); +#endif //USE_MYGUI + } +} + +void TextureToolWindow::updateControls( Ogre::String texName ) +{ + try + { + TexturePtr tex = Ogre::TextureManager::getSingleton().getByName(texName); + if(tex.isNull()) + { + mTxt->setCaption(convertToMyGUIString("Texture not found:\n"+texName)); + mBtnSavePNG->setEnabled(false); + return; + } + + Ogre::String str = "#aa0000" + texName + "#000000\n"; + str += "#00aa00res: #000000" + TOSTRING(tex->getWidth()) + " x " + TOSTRING(tex->getHeight()) + " pixels\n"; + str += "#00aa00size: #000000" + formatBytes(tex->getSize()) + "\n"; + str += "#00aa00format: #000000" + PixelUtil::getFormatName(tex->getFormat()) + "\n"; + if(tex->getNumFaces() > 1) + str += "#00aa00faces: #000000" + TOSTRING(tex->getNumFaces()) + "\n"; + if(tex->getFSAA() > 0) + str += "#00aa00FSAA: #000000" + TOSTRING(tex->getFSAA()) + "\n"; + if(tex->getNumMipmaps() > 0) + str += "#00aa00mipmaps: #000000" + TOSTRING(tex->getNumMipmaps()) + "\n"; + + String typeStr=""; + switch(tex->getTextureType()) + { + case TEX_TYPE_1D: typeStr = "1D"; break; + case TEX_TYPE_2D: typeStr = "2D"; break; + case TEX_TYPE_3D: typeStr = "3D"; break; + case TEX_TYPE_CUBE_MAP: typeStr = "Cube Map"; break; + } + str += "#00aa00type: #000000" + typeStr + "\n"; + + String usageStr=""; + if(tex->getUsage() & TU_STATIC) + usageStr += "static,\n"; + if(tex->getUsage() & TU_DYNAMIC) + usageStr += "dynamic,\n"; + if(tex->getUsage() & TU_WRITE_ONLY) + usageStr += "write only,\n"; + if(tex->getUsage() & TU_STATIC_WRITE_ONLY) + usageStr += "static write only,\n"; + if(tex->getUsage() & TU_DYNAMIC_WRITE_ONLY) + usageStr += "dynamic write only,\n"; + if(tex->getUsage() & TU_DYNAMIC_WRITE_ONLY_DISCARDABLE) + usageStr += "dynamic write only discardable,\n"; + if(tex->getUsage() & TU_AUTOMIPMAP) + usageStr += "automipmap,\n"; + if(tex->getUsage() & TU_RENDERTARGET) + usageStr += "rendertarget,\n"; + if(tex->getUsage() & TU_DEFAULT) + usageStr += "default\n"; + + str += "#00aa00usage: #000000" + usageStr + "\n"; + if(tex->getDepth() > 1) + str += "#00aa00depth: #000000" + TOSTRING(tex->getDepth()) + "\n"; + + + mTxt->setCaption(convertToMyGUIString(str)); + mImage->setImageTexture(texName); + mBtnSavePNG->setEnabled(true); + } + catch(Exception &e) + { +#ifdef USE_MYGUI + UTFString str = "Exception while opening texture:" + e.getFullDescription(); + Console::getInstance().putMessage(Console::CONSOLE_MSGTYPE_INFO, Console::CONSOLE_MSGTYPE_INFO, str, "error.png"); +#endif //USE_MYGUI + } +} + +void TextureToolWindow::eventSelectTexture2( MyGUI::ComboBoxPtr _sender, size_t _index ) +{ + updateControls(mCBo->getItemNameAt(_index)); +} + +void TextureToolWindow::eventClickDynamicButton( MyGUI::WidgetPtr _sender ) +{ + mChkDynamic->setStateSelected(!mChkDynamic->getStateSelected()); + fillCombo(); +} + +#endif //MYGUI + Added: trunk/source/main/gui/TextureToolWindow.h =================================================================== --- trunk/source/main/gui/TextureToolWindow.h (rev 0) +++ trunk/source/main/gui/TextureToolWindow.h 2012-01-30 10:36:01 UTC (rev 2389) @@ -0,0 +1,78 @@ +/* +This source file is part of Rigs of Rods +Copyright 2005-2012 Pierre-Michel Ricordel +Copyright 2007-2012 Thomas Fischer + +For more information, see http://www.rigsofrods.com/ + +Rigs of Rods is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License version 3, as +published by the Free Software Foundation. + +Rigs of Rods is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with Rigs of Rods. If not, see <http://www.gnu.org/licenses/>. +*/ +#ifdef USE_MYGUI + +#ifndef __HIGHSCORE_WINDOW_H__ +#define __HIGHSCORE_WINDOW_H__ + +#include "RoRPrerequisites.h" +#include "Singleton.h" +#include "mygui/BaseLayout.h" +#include <Ogre.h> +#include "skin.h" + + +ATTRIBUTE_CLASS_LAYOUT(TextureToolWindow, "TextureTool.layout"); + +class TextureToolWindow : + public wraps::BaseLayout, + public Singleton2<TextureToolWindow> +{ + friend class Singleton2<TextureToolWindow>; + TextureToolWindow(); + ~TextureToolWindow(); +public: + void show(); + void hide(); + +private: + ATTRIBUTE_FIELD_WIDGET_NAME(TextureToolWindow, mTxt, "txtInfo"); + MyGUI::TextBox* mTxt; + + ATTRIBUTE_FIELD_WIDGET_NAME(TextureToolWindow, mCBo, "cboTextures"); + MyGUI::ComboBox* mCBo; + + ATTRIBUTE_FIELD_WIDGET_NAME(TextureToolWindow, mBtnSavePNG, "btnSavePNG"); + MyGUI::Button* mBtnSavePNG; + + ATTRIBUTE_FIELD_WIDGET_NAME(TextureToolWindow, mBtnSaveRAW, "btnSaveRAW"); + MyGUI::Button* mBtnSaveRAW; + + ATTRIBUTE_FIELD_WIDGET_NAME(TextureToolWindow, mImage, "imgTexture"); + MyGUI::ImageBox* mImage; + + ATTRIBUTE_FIELD_WIDGET_NAME(TextureToolWindow, mChkDynamic, "chkDynamic"); + MyGUI::Button* mChkDynamic; + + void notifyWindowPressed(MyGUI::Window* _widget, const std::string& _name); + void eventClickSavePNGButton(MyGUI::WidgetPtr _sender); + void eventClickSaveRAWButton(MyGUI::WidgetPtr _sender); + void eventClickDynamicButton(MyGUI::WidgetPtr _sender); + void eventSelectTexture(MyGUI::WidgetPtr _sender); + void eventSelectTexture2(MyGUI::ComboBoxPtr _sender, size_t _index); + + void updateControls(Ogre::String texName); + void saveTexture( Ogre::String texName, bool png ); + void fillCombo(); +}; + +#endif // __HIGHSCORE_WINDOW_H__ + +#endif //MYGUI Modified: trunk/source/main/gui/gui_menu.cpp =================================================================== --- trunk/source/main/gui/gui_menu.cpp 2012-01-30 05:15:30 UTC (rev 2388) +++ trunk/source/main/gui/gui_menu.cpp 2012-01-30 10:36:01 UTC (rev 2389) @@ -32,6 +32,7 @@ #include "Savegame.h" #include "network.h" #include "utils.h" +#include "TextureToolWindow.h" #include "language.h" @@ -146,8 +147,12 @@ p->addItem(_L("show Beam strength"), MyGUI::MenuItemType::Normal, "debug-beam-strength"); p->addItem(_L("show Beam hydros"), MyGUI::MenuItemType::Normal, "debug-beam-hydros"); p->addItem(_L("show Beam commands"), MyGUI::MenuItemType::Normal, "debug-beam-commands"); + p->addItem("-", MyGUI::MenuItemType::Separator); + p->addItem(_L("Texture Tool"), MyGUI::MenuItemType::Normal, "texturetool"); pop.push_back(p); + + // event callbacks mainmenu->eventMenuCtrlAccept += MyGUI::newDelegate(this, &GUI_MainMenu::onMenuBtn); @@ -421,8 +426,12 @@ { Beam *b = BeamFactory::getSingleton().getCurrentTruck(); if(b) b->setDebugOverlayState(11); + } else if(miname == _L("Texture Tool")) + { + TextureToolWindow::getInstance().show(); } + //LOG(" menu button pressed: " + _item->getCaption()); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. ------------------------------------------------------------------------------ Try before you buy = See our experts in action! The most comprehensive online learning library for Microsoft developers is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3, Metro Style Apps, more. Free future releases when you subscribe now! http://p.sf.net/sfu/learndevnow-dev2 _______________________________________________ Rigsofrods-devel mailing list Rigsofrods-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/rigsofrods-devel