} //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.. }
}//CreateTextureAtlasInfo() /// <summary> /// load .odm.a file /// jintaeks on 2013-11-12, 17:19 /// </summary> /// <param name="textureAtlasInfo_"></param> /// <param name="strOdmaFilePath_"></param> /// <returns></returns> public static bool LoadExistingAtlasInfo(ref KTextureAtlasInfo textureAtlasInfo_, string strOdmaFilePath_) { if (textureAtlasInfo_ == null) { return(false); // invalid atlas info. }//if if (System.IO.File.Exists(strOdmaFilePath_) == false) { MessageBox.Show("파일이 존재하지 않습니다. \nPath : " + strOdmaFilePath_); return(false); }//if int iParseMode = 0; string strLine = ""; // you must set 'Encoding.Default' to read Korean Hangul text from file. jintaeks on 2013-11-04, 14:48 StreamReader file = new StreamReader(strOdmaFilePath_, Encoding.Default); while ((strLine = file.ReadLine()) != null) { strLine.Trim(); if (strLine.Length <= 0) { continue; }//if if (iParseMode == 0) { int iStrLength = strLine.Length; int iEqualSignIndex = strLine.IndexOf("="); string strName = strLine.Substring(0, iEqualSignIndex); strName = strName.Trim(); strName = strName.ToLower(); int iRemainedTextLenght = iStrLength - iEqualSignIndex - 1; string strData = strLine.Substring(iEqualSignIndex + 1, iRemainedTextLenght); if (strName == "width") { textureAtlasInfo_.m_iAtlasWidth = Convert.ToInt32(strData); } else if (strName == "height") { textureAtlasInfo_.m_iAtlasHeight = Convert.ToInt32(strData); } else if (strName == "material") { string[] astrMtrlInfo = strData.Split(new char[] { ',' }); if (astrMtrlInfo.Length == 6) { for (int iDataIndex = 0; iDataIndex < 6; iDataIndex += 1) { astrMtrlInfo[iDataIndex] = astrMtrlInfo[iDataIndex].Trim(); }//for int iTextrInfoIndex = 0; bool bIsFindTextrInfo = textureAtlasInfo_.FindTextureInfo(ref iTextrInfoIndex, astrMtrlInfo[0]); Debug.Assert(bIsFindTextrInfo == true); if (bIsFindTextrInfo == true) { KTextureInfo textrInfo = new KTextureInfo(); bool bIsGetTextureInfo = textureAtlasInfo_.GetTextureInfo(ref textrInfo, iTextrInfoIndex); if (bIsGetTextureInfo == true) { textrInfo.m_iLeft = Convert.ToInt32(astrMtrlInfo[1]); textrInfo.m_iTop = Convert.ToInt32(astrMtrlInfo[2]); textrInfo.m_iWidth = Convert.ToInt32(astrMtrlInfo[3]); textrInfo.m_iHeight = Convert.ToInt32(astrMtrlInfo[4]); astrMtrlInfo[5] = astrMtrlInfo[5].ToLower(); textrInfo.m_bIsRotateCcw = String.Compare(astrMtrlInfo[5], "true") == 0; if (textrInfo.m_bIsRotateCcw == true) { textrInfo.RotateImage(90); }//if textureAtlasInfo_.SetTextureInfo(iTextrInfoIndex, textrInfo); } //if } //if } } //if.. else if.. } //if } //while file.Close(); return(true); }//LoadExistingAtlasInfo()