std::vector<DRect> getZZCRect() { DSize size = getFrame().size; std::pair<int, int> t1 = getLineAndPos(m_curSelCharRange.first); std::pair<int, int> t2 = getLineAndPos(m_curSelCharRange.second); std::string s1 = m_szText.substr(t1.second, m_curSelCharRange.first - t1.second); if (!s1.empty() && s1[0] == '\n') s1.erase(0, 1); int l1 = getStringLength(s1); std::string s2 = m_szText.substr(t2.second, m_curSelCharRange.second - t2.second); if (!s2.empty() && s2[0] == '\n') s2.erase(0, 1); int l2 = getStringLength(s2); std::vector<DRect> vr; if (t1.first == t2.first) { vr.push_back(DRect(l1, m_iLineHeight*1.25f*t1.first, l2 - l1, m_iLineHeight)); } else { vr.push_back(DRect(l1, m_iLineHeight*1.25f*t1.first, size.width - l1, m_iLineHeight*1.25f)); int i = t1.first + 1; for (; i < t2.first; i++) { vr.push_back(DRect(0, m_iLineHeight*1.25f*i, size.width, m_iLineHeight*1.25f)); } vr.push_back(DRect(0, m_iLineHeight*1.25f*i, l2, m_iLineHeight)); } return vr; }
std::vector<CCRect> CATextView::getZZCRect() { CCSize size = getFrame().size; std::pair<int, int> t1 = getLineAndPos(m_curSelCharRange.first); std::pair<int, int> t2 = getLineAndPos(m_curSelCharRange.second); std::string s1 = m_szText.substr(t1.second, m_curSelCharRange.first - t1.second); if (!s1.empty() && s1[0] == '\n') s1.erase(0, 1); int l1 = getStringLength(s1); std::string s2 = m_szText.substr(t2.second, m_curSelCharRange.second - t2.second); if (!s2.empty() && s2[0] == '\n') s2.erase(0, 1); int l2 = getStringLength(s2); std::vector<CCRect> vr; if (t1.first == t2.first) { vr.push_back(CCRect(l1, m_iLineHeight*1.25f*t1.first, l2 - l1, m_iLineHeight)); } else { vr.push_back(CCRect(l1, m_iLineHeight*1.25f*t1.first, size.width - l1, m_iLineHeight*1.25f)); int i = t1.first + 1; for (; i < t2.first; i++) { vr.push_back(CCRect(0, m_iLineHeight*1.25f*i, size.width, m_iLineHeight*1.25f)); } vr.push_back(CCRect(0, m_iLineHeight*1.25f*i, l2, m_iLineHeight)); } for (int i = 0; i < vr.size(); i++) { vr[i].origin.y += m_pContainerView->getContentOffset().y; } return vr; }