void BrushSelector::OnPixmapListSelected(wxTreeEvent& event) { try { // 以下是改成定义文件后的修改 // mPaintInOneGrid = false; // 保存当前选中的纹理的大小 int selectedTexXSize = 0; int selectedTexZSize = 0; // 当画刷被选中时,要进行判断 wxTreeItemId itemId = event.GetItem(); wxTreeItemId rootId = mBrushesTree->GetRootItem(); // 如果选中根,就返回 if ( itemId == rootId ) { // 选中根目录名时,所有选项都变灰 mFlipHorizontal->Enable(false); mFlipVertical->Enable(false); mRotateRightAngle->Enable(false); mMirrorDiagonal->Enable(false); mRandom->Enable(false); mEnablePreview->Enable(false); // 缩略图用黑白图 mBrushesPreview->SetBitmap(mBlackWhitePreviewImage); return; } if (itemId.IsOk()) { mCurrentOrientationType = 0; // 如果选项的父是root,说明该画刷是放在根目录下的,也有可能是根目录下的子目录 if ( mBrushesTree->GetItemParent(itemId) == rootId ) { mCurrentFileName = mBrushesTree->GetItemText(itemId); } else { // 以下处理不是放在根目录下的画刷 wxTreeItemId parentId = mBrushesTree->GetItemParent(itemId); mCurrentFileName = mBrushesTree->GetItemText(itemId); // 以此取出父目录的目录名,组合成相对路径名,并加上文件名 while ( parentId != rootId ) { wxString parentText = mBrushesTree->GetItemText(parentId); parentText += '/'; mCurrentFileName.Prepend( parentText ); parentId = mBrushesTree->GetItemParent(parentId); } } // 如果名字中有.,说明是文件名,不是目录名 if ( mCurrentFileName.find_first_of('|') != wxString::npos ) { mFlipHorizontal->Enable(true); mFlipVertical->Enable(true); mRotateRightAngle->Enable(true); mMirrorDiagonal->Enable(true); mRandom->Enable(true); mEnablePreview->Enable(true); Ogre::String currentFileName(mCurrentFileName.c_str()); size_t pos = currentFileName.find_last_of('/'); // 取出brush名称 Ogre::String brushName = currentFileName.substr(0,pos); Ogre::String textureName = currentFileName.substr(pos+1); const Fairy::TextureInfos ¤tPaintInfos = GetSceneManipulator()->getTextureInfos(brushName); const Fairy::TextureInfo ¤tPaintInfo = GetSceneManipulator()->getTextureInfo(brushName, textureName); Ogre::Image *previewImage = GetSceneManipulator()->getPreviewImage(currentPaintInfo.ownerTextureName); // 组成纹理信息字符串 Ogre::String texInfoString; texInfoString += currentPaintInfo.ownerTextureName; texInfoString += "|"; texInfoString += Ogre::StringConverter::toString(currentPaintInfo.height); texInfoString += "|"; texInfoString += Ogre::StringConverter::toString(currentPaintInfo.width); texInfoString += "|"; texInfoString += Ogre::StringConverter::toString(currentPaintInfo.leftCorner); texInfoString += "|"; texInfoString += Ogre::StringConverter::toString(currentPaintInfo.topCorner); texInfoString += "|"; texInfoString += Ogre::StringConverter::toString(previewImage->getHeight()); texInfoString += "|"; texInfoString += Ogre::StringConverter::toString(previewImage->getWidth()); texInfoString += "|"; texInfoString += Ogre::StringConverter::toString(currentPaintInfo.rotateType); Fairy::Action* action = GetSceneManipulator()->_getAction("SimplePaintAction"); action->setParameter( "%TextureName", "InputBegin" ); action->setParameter( "%TextureName", AS_STRING(texInfoString) ); action->setParameter( "%OrientationType", Ogre::StringConverter::toString(mCurrentOrientationType) ); if ( (currentPaintInfo.width > 1 || currentPaintInfo.height > 1) && !mPaintInOneGrid ) { action->setParameter( "%TexNormalSize", "false" ); mFlipHorizontal->Enable(false); mFlipVertical->Enable(false); mRotateRightAngle->Enable(false); mMirrorDiagonal->Enable(false); mRandom->Enable(false); } else { action->setParameter("%TexNormalSize","true"); } GetSceneManipulator()->setActiveAction(action); buildPreviewBitmap(currentPaintInfo); if ( mEnablePreview->IsChecked() == false ) { // 如果不显示缩略图,就显示默认的黑白图 mBrushesPreview->SetBitmap(mBlackWhitePreviewImage); } } // 如果名字中有.,说明不是文件名,是目录名 else { mFlipHorizontal->Enable(false); mFlipVertical->Enable(false); mRotateRightAngle->Enable(false); mMirrorDiagonal->Enable(false); mRandom->Enable(false); mEnablePreview->Enable(true); // 把整个目录的纹理进行判断,并加入到透明纹理列表 const Fairy::Action* action = OnStartAutoTexAction(itemId, mCurrentFileName); if ( action != 0 ) { // 从该组纹理的实心纹理中随机用一个来做为缩略图 // 读取这张纹理,并缩放到mPreviewImageWidth*mPreviewImageHeight,用于缩略图 // Ogre::String tempTexName = action->getParameter( "%TextureName" ); const Fairy::TextureInfos ¤tPaintInfos = GetSceneManipulator()->getTextureInfos(mCurrentFileName.c_str()); // const Fairy::TextureInfo ¤tPaintInfo = currentPaintInfos[0]; // 构建preview image buildPreviewBitmap(currentPaintInfos[0]); } else { mEnablePreview->Enable(false); mBrushesPreview->SetBitmap(mBlackWhitePreviewImage); } if ( mEnablePreview->IsChecked() == false ) { // 如果不显示缩略图,就显示默认的黑白图 mBrushesPreview->SetBitmap(mBlackWhitePreviewImage); } } } // 让所有的checkbox回复未选择的状态 mFlipHorizontal->SetValue(false); mFlipVertical->SetValue(false); mRotateRightAngle->SetValue(false); mMirrorDiagonal->SetValue(false); mRandom->SetValue(false); } catch (Ogre::Exception &e) { wxMessageBox( e.getDescription().c_str(), /* _("Texture Wrong")*/wxT("纹理定义出错或找不到纹理图片"), wxOK|wxCENTRE|wxICON_ERROR, this); } }
void MaterialPreviewDialog::InitPreviewGrids(void) { wxFlexGridSizer *item0 = new wxFlexGridSizer( 6, 0, 0 ); typedef std::list<Ogre::String> MaterialFileNameList; MaterialFileNameList materialFileNameList; Ogre::FileInfoListPtr fileInfoList = Ogre::ResourceGroupManager::getSingleton().findResourceFileInfo( Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, "*.material"); for (Ogre::FileInfoList::const_iterator it = fileInfoList->begin(); it != fileInfoList->end(); ++it) { if ( it->archive->getName() == EFFECT_PATH) { materialFileNameList.push_back(it->filename); } } wxComboBox *matCombo = mParentDialog->mMaterialComboBox; assert (matCombo); for ( int i=0; i<matCombo->GetCount(); ++i ) { Ogre::String matName = matCombo->GetString(i); Ogre::MaterialPtr mat = Ogre::MaterialManager::getSingleton().getByName(matName); if (mat.isNull()) { } else { size_t numOfTex = mat->getTechnique(0)->getPass(0)->getNumTextureUnitStates(); if (numOfTex > 0) { Ogre::String texName = mat->getTechnique(0)->getPass(0)->getTextureUnitState(0)->getTextureName(); if (texName.empty() == false) { wxBoxSizer *item1 = new wxBoxSizer( wxVERTICAL ); wxStaticBitmap *item2 = new wxStaticBitmap( this, ID_STATICBITMAP, TexturePreview( 0 ), wxDefaultPosition, wxSize(64,64) ); item1->Add( item2, 0, wxALIGN_CENTER|wxALL, 5 ); wxStaticText *item3 = new wxStaticText( this, ID_TEXT_MATERIAL_NAME, _("text"), wxDefaultPosition, wxDefaultSize, 0 ); item1->Add( item3, 0, wxALIGN_CENTER|wxALL, 5 ); wxButton *item4 = new wxButton( this, ID_BUTTON_USE, _("Use"), wxDefaultPosition, wxDefaultSize, 0 ); item1->Add( item4, 0, wxALIGN_CENTER|wxALL, 5 ); item0->Add( item1, 0, wxALIGN_CENTER|wxALL, 5 ); buildPreviewBitmap( texName ); item2->SetBitmap(mCurrentPreviewImage); item3->SetLabel(texName.c_str()); item4->SetLabel(matName.c_str()); } } } } this->SetSizer( item0 ); item0->SetSizeHints( this ); }