Пример #1
0
        private void button3_Click(object sender, EventArgs e)
        {
            if (!m_bImageSupport)
            {
                return;
            }
            //textBox.TextChanged -= new System.EventHandler(this.richTextBox2_TextChanged);
            string filename = FileFolderHelper.BrowserFile(new string[] { "tga", "uitex" });

            if (filename == string.Empty)
            {
                return;
            }

            ImageDialog dlg     = new ImageDialog(filename);
            int         nFrame  = 0;
            int         nWidth  = 0;
            int         nHeight = 0;

            if (dlg.ShowDialog() == DialogResult.OK)
            {
                if (dlg.strFrame != string.Empty)
                {
                    nFrame = Int32.Parse(dlg.strFrame);
                }
                if (dlg.strWidth != string.Empty)
                {
                    nWidth = Int32.Parse(dlg.strWidth);
                }
                if (dlg.strHeight != string.Empty)
                {
                    nHeight = Int32.Parse(dlg.strHeight);
                }
            }

            string retRTF = RTFHelper.GetRTFFromTgaFile(filename, textBox, nFrame);

            textBox.SelectedRtf = retRTF;

            MarkArray[textBox.SelectionStart - 1] = ImageArray.Count + ImageMark;
            filename = filename.Substring(m_Root.Length, filename.Length - m_Root.Length);

            string strW = string.Empty;
            string strH = string.Empty;

            if (nWidth != 0)
            {
                strW = widthMark + nWidth.ToString();
            }
            if (nHeight != 0)
            {
                strH = heightMark + nHeight.ToString();
            }

            string strImageMark = imageMark + filename + frameMark + nFrame.ToString() + strW + strH + frameEndMark;

            ImageArray.Add(strImageMark);
            //textBox.TextChanged += new System.EventHandler(this.richTextBox2_TextChanged);
        }
Пример #2
0
        public void refreshText()
        {
            MarkArray.Clear();
            ImageArray.Clear();
            textBox.TextChanged -= new System.EventHandler(this.richTextBox2_TextChanged);

            textBox.Text = string.Empty;
            string strCode     = Code;
            int    nIndexP     = -1;
            int    nIndexE     = -1;
            int    nIndexMarkP = -1;
            int    nIndexMarkE = -1;
            int    nStart      = 0;

            bool bEnd      = false;
            bool bImageEnd = false;

            while (true)
            {
                string strToAdd = string.Empty;
                nIndexP = strCode.IndexOf(textMark, nIndexP + 1);
                if (!bImageEnd)
                {
                    nIndexMarkP = strCode.IndexOf(imageMark, nIndexMarkP + 1);
                    if (nIndexMarkP == -1)
                    {
                        bImageEnd = true;
                    }
                }

                string strImageMark = CheckImageMark(nIndexP, nIndexMarkP);

                if (nIndexP == -1 && nIndexMarkP < 0)
                {
                    strToAdd = strToAdd + strCode.Substring(nStart, strCode.Length - nStart);
                    bEnd     = true;
                }
                else
                {
                    if (strImageMark == string.Empty)
                    {
                        strToAdd = strToAdd + strCode.Substring(nStart, nIndexP - nStart);
                    }
                    else
                    {
                        strToAdd = strToAdd + strCode.Substring(nStart, nIndexMarkP - nStart);
                    }
                }

                int nIndex = 0;
                if (strToAdd != string.Empty)
                {
                    // 默认字体
                    strToAdd = strToAdd.Replace("\\\\\\n", "\n");
                    nIndex   = textBox.Text.Length;

                    textBox.AppendText(strToAdd);

                    textBox.Select(nIndex, strToAdd.Length);
                    textBox.SelectionFont  = defFont;
                    textBox.SelectionColor = defColor;

                    for (int i = 0; i < strToAdd.Length; i++)
                    {
                        MarkArray.Insert(nIndex++, m_nDefFont as Object);
                    }
                }

                if (bEnd)
                {
                    break;
                }

                if (strImageMark != string.Empty)
                {
                    MarkArray.Add(ImageArray.Count + ImageMark);
                    ImageArray.Add(strImageMark);

                    int nCurPos = strImageMark.IndexOf(frameMark);

                    string filename = strImageMark.Substring(imageMark.Length, nCurPos - imageMark.Length);
                    filename = m_Root + filename;

                    int nWidthMarkPos = strImageMark.IndexOf(widthMark, nCurPos);
                    if (nWidthMarkPos == -1 || nWidthMarkPos - (nCurPos + frameMark.Length) > 4)
                    {
                        nWidthMarkPos = strImageMark.IndexOf(frameEndMark, nCurPos);
                    }
                    int nFrame = Int32.Parse(strImageMark.Substring(nCurPos + frameMark.Length, nWidthMarkPos - nCurPos - frameMark.Length));
                    //int nWidth = 0;
                    //int nHeight = 0;
                    //////////////////////////////////////////////////////////////////////////
                    //这个功能暂未实现,标签有,无预览效果
                    //////////////////////////////////////////////////////////////////////////

                    string retRTF = RTFHelper.GetRTFFromTgaFile(filename, textBox, nFrame);
                    textBox.Select(textBox.Text.Length, 0);
                    textBox.SelectedRtf = retRTF;

                    nIndexMarkE = strCode.IndexOf(frameEndMark, nIndexMarkP);
                    nStart      = nIndexMarkE + frameEndMark.Length;
                    nIndexP     = nStart - 1;
                    continue;
                }

                // 特定字体
                strToAdd = string.Empty;
                nIndexP  = nIndexP + textMark.Length;
                nIndexE  = strCode.IndexOf(fontMark, nIndexP);

                strToAdd = strToAdd + strCode.Substring(nIndexP, nIndexE - nIndexP);

                nIndexP = nIndexP + strToAdd.Length + fontMark.Length;
                nIndexE = strCode.IndexOf(fontEndMark, nIndexP);

                string strFontID = strCode.Substring(nIndexP, nIndexE - nIndexP);
                int    nFontID   = Int32.Parse(strFontID);
                nStart = nIndexE + fontEndMark.Length;

                Color CurColor = font.GetColorByID(nFontID);
                Font  CurFont  = font.GetFontByID(nFontID);

                strToAdd = strToAdd.Replace("\\\\\\n", "\n");

                nIndex = textBox.Text.Length;
                textBox.AppendText(strToAdd);

                textBox.Select(nIndex, strToAdd.Length);
                textBox.SelectionColor = CurColor;
                textBox.SelectionFont  = CurFont;


                for (int i = 0; i < strToAdd.Length; i++)
                {
                    MarkArray.Insert(nIndex++, nFontID as Object);
                }

                nIndexMarkP--;
            }
            textBox.TextChanged += new System.EventHandler(this.richTextBox2_TextChanged);
            m_nLastLength        = textBox.Text.Length;
        }