//////////////////////////////////////////////////////////////////////////////////////////////////// // function members // public FormAtlasMain() { InitializeComponent(); m_alistMaterials = null;// new ArrayList(); m_strOdmFileName = ""; m_eCurrentTextureType = ETextureType.DIFFUSE; m_iSelectedMaterialIndex = -1; m_iSelectedAtlasTextureIndex = -1; m_textureAtlasInfo = null; m_eIsTextureLocatingMode = ETextureLocatingMode.NONE; //m_pntPickMouseOffset; m_fAtlasZoomRatio = 1.0f; m_pntAtlasLeftTop.X = 0; m_pntAtlasLeftTop.Y = 0; }//FormAtlasMain
}//_PickTextureOnCanvas() private void panelTextureCanvas_MouseDown(object sender, MouseEventArgs e) { radioButtonDiffuseTexture.Focus(); // move texture in atlas if (e.Button == MouseButtons.Left) { int iPickedTextr = -1; bool bIsPickTexture = _PickTextureOnCanvas(ref iPickedTextr , ( int )((e.X - m_pntAtlasLeftTop.X) / m_fAtlasZoomRatio) , ( int )((e.Y - m_pntAtlasLeftTop.Y) / m_fAtlasZoomRatio)); if (bIsPickTexture == true) { KTextureInfo textrInfo = new KTextureInfo(); bool bIsGetTextureInfo = m_textureAtlasInfo.GetTextureInfo(ref textrInfo, iPickedTextr); Debug.Assert(bIsGetTextureInfo == true); if (bIsGetTextureInfo == true) { m_pntPickMouseOffset.X = ( int )(e.X - textrInfo.m_iLeft * m_fAtlasZoomRatio) - 1; m_pntPickMouseOffset.Y = ( int )(e.Y - textrInfo.m_iTop * m_fAtlasZoomRatio) - 1; m_iSelectedAtlasTextureIndex = iPickedTextr; m_eIsTextureLocatingMode = ETextureLocatingMode.TEXTURE; }//if // sync to material index if (m_iSelectedAtlasTextureIndex != m_iSelectedMaterialIndex) { m_iSelectedMaterialIndex = m_iSelectedAtlasTextureIndex; listBoxMaterials.SetSelected(m_iSelectedMaterialIndex, true); _UpdateMaterialTextureInfo(); } //if } //if } // move atlas itself. else if (e.Button == MouseButtons.Right) { m_pntPickMouseOffset.X = ( int )(e.X - m_pntAtlasLeftTop.X); m_pntPickMouseOffset.Y = ( int )(e.Y - m_pntAtlasLeftTop.Y); m_eIsTextureLocatingMode = ETextureLocatingMode.ATLAS; } //if.. else if.. } //panelTextureCanvas_MouseDown()
} //panelTextureCanvas_MouseDown() private void panelTextureCanvas_MouseUp(object sender, MouseEventArgs e) { double fMouseX = e.X; // + cfSnapSize / 2.0; double fMouseY = e.Y; // +cfSnapSize / 2.0; bool bIsValidMtrlIndex = IsValidAtlasTextureIndex(m_iSelectedAtlasTextureIndex); if (bIsValidMtrlIndex == true && m_eIsTextureLocatingMode == ETextureLocatingMode.TEXTURE) { double cfSnapSize = 32; // apply 32*32 virtual snap to grid. jintaeks on 2013-11-06, 10:40 KTextureInfo textrInfo = ( KTextureInfo )m_textureAtlasInfo.m_alistTextureInfo[m_iSelectedAtlasTextureIndex]; int iSnapXIndex = ( int )((fMouseX - m_pntPickMouseOffset.X) / m_fAtlasZoomRatio / cfSnapSize); int iSnapYIndex = ( int )((fMouseY - m_pntPickMouseOffset.Y) / m_fAtlasZoomRatio / cfSnapSize); textrInfo.m_iLeft = ( int )(iSnapXIndex * cfSnapSize); textrInfo.m_iTop = ( int )(iSnapYIndex * cfSnapSize); m_textureAtlasInfo.SetTextureInfo(m_iSelectedAtlasTextureIndex, textrInfo); m_textureAtlasInfo.AutoAdjustAtlasSize(); _InvalidateTextureCanvas(); m_eIsTextureLocatingMode = ETextureLocatingMode.NONE; m_iSelectedAtlasTextureIndex = -1; } else if (m_eIsTextureLocatingMode == ETextureLocatingMode.ATLAS) { double cfSnapSize = 32; int iSnapXIndex = ( int )((fMouseX - m_pntPickMouseOffset.X) / cfSnapSize); int iSnapYIndex = ( int )((fMouseY - m_pntPickMouseOffset.Y) / cfSnapSize); m_pntAtlasLeftTop.X = ( int )(iSnapXIndex * cfSnapSize); m_pntAtlasLeftTop.Y = ( int )(iSnapYIndex * cfSnapSize); _InvalidateTextureCanvas(); m_eIsTextureLocatingMode = ETextureLocatingMode.NONE; }//if.. else if.. }