From 26d206caaef7b9c957df8c0fd174e6eab43a58be Mon Sep 17 00:00:00 2001 From: Edouard DUPIN Date: Fri, 22 Nov 2013 21:48:05 +0100 Subject: [PATCH] [DEV] some display update --- sources/appl/Buffer.cpp | 97 ++++++++++++++++++--------------- sources/appl/Buffer.h | 52 +++++++++++------- sources/appl/Gui/TextViewer.cpp | 36 ++++++------ sources/appl/Gui/TextViewer.h | 4 +- sources/appl/Highlight.cpp | 25 ++++----- sources/appl/Highlight.h | 10 ++-- 6 files changed, 124 insertions(+), 100 deletions(-) diff --git a/sources/appl/Buffer.cpp b/sources/appl/Buffer.cpp index 2a0e99d..8da23ac 100644 --- a/sources/appl/Buffer.cpp +++ b/sources/appl/Buffer.cpp @@ -83,7 +83,7 @@ char32_t appl::Buffer::Iterator::operator* (void) { } -appl::Buffer::Iterator appl::Buffer::position(esize_t _pos) { +appl::Buffer::Iterator appl::Buffer::position(int64_t _pos) { return appl::Buffer::Iterator(this, _pos); } @@ -258,12 +258,15 @@ bool appl::Buffer::searchBack(const appl::Buffer::Iterator& _pos, const char32_t return false; } -void appl::Buffer::moveCursor(esize_t _pos) { +void appl::Buffer::moveCursor(int64_t _pos) { m_cursorPreferredCol = -1; // selecting mode ... if (m_selectMode == true) { if (m_cursorSelectPos == -1) { m_cursorSelectPos = m_cursorPos; + if (m_cursorSelectPos < 0) { + m_cursorSelectPos = 0; + } } //APPL_DEBUG("Select : " << m_cursorSelectPos << " ==> " << newPos); m_cursorPos = _pos; @@ -311,7 +314,8 @@ bool appl::Buffer::getPosAround(const appl::Buffer::Iterator& _startPos, } } return true; - } else if( false == etk::isSpecialChar(currentValue)){ + } else if( etk::isSpecialChar(currentValue) == false + || currentValue == '_') { APPL_DEBUG("select normal Char"); // Search back for (Iterator it = --position(_startPos); @@ -479,8 +483,8 @@ bool appl::Buffer::copy(std::string& _data) { void appl::Buffer::copy(std::string& _data, const appl::Buffer::Iterator& _pos, const appl::Buffer::Iterator& _posEnd) { _data.clear(); - esize_t startPos = getStartSelectionPos(); - esize_t endPos = getStopSelectionPos(); + int64_t startPos = getStartSelectionPos(); + int64_t endPos = getStopSelectionPos(); for (Iterator it = _pos; it != _posEnd && (bool)it == true; @@ -490,24 +494,32 @@ void appl::Buffer::copy(std::string& _data, const appl::Buffer::Iterator& _pos, } bool appl::Buffer::write(const std::string& _data, const appl::Buffer::Iterator& _pos) { - if ((esize_t)_pos <= 0) { - m_data.insert(0, (int8_t*)(_data.c_str()), _data.size()); - } else { - m_data.insert(_pos, (int8_t*)(_data.c_str()), _data.size()); + int64_t position = (int64_t)_pos; + if (position < 0){ + position = 0; } - regenerateHighLightAt(_pos, 0, _data.size()); + APPL_ERROR("writye at pos: " << (int64_t)_pos << " ==> " << position); + m_data.insert(position, (int8_t*)(_data.c_str()), _data.size()); + if (m_cursorPos < 0) { + m_cursorPos = 0; + } + regenerateHighLightAt(position, 0, _data.size()); m_selectMode = false; - moveCursor((esize_t)_pos+_data.size()); + moveCursor(position+_data.size()); countNumberofLine(); // TODO : use more intelligent counter setModification(true); return true; } bool appl::Buffer::replace(const std::string& _data, const appl::Buffer::Iterator& _pos, const appl::Buffer::Iterator& _posEnd) { - m_data.replace(_pos, (esize_t)_posEnd-(esize_t)_pos, (int8_t*)(_data.c_str()), _data.size()); - regenerateHighLightAt(_pos, (esize_t)_posEnd-(esize_t)_pos, _data.size()); + int64_t position = (int64_t)_pos; + if (position < 0){ + position = 0; + } + m_data.replace(position, (int64_t)_posEnd-(int64_t)_pos, (int8_t*)(_data.c_str()), _data.size()); + regenerateHighLightAt(position, (int64_t)_posEnd-(int64_t)_pos, _data.size()); m_selectMode = false; - moveCursor((esize_t)_pos+_data.size()); + moveCursor(position+_data.size()); countNumberofLine(); // TODO : use more intelligent counter setModification(true); return true; @@ -517,8 +529,8 @@ void appl::Buffer::removeSelection(void) { if (hasTextSelected() == false) { return; } - esize_t startPos = getStartSelectionPos(); - esize_t endPos = getStopSelectionPos(); + int64_t startPos = getStartSelectionPos(); + int64_t endPos = getStopSelectionPos(); m_data.remove(startPos, endPos-startPos); regenerateHighLightAt(startPos, endPos-startPos, 0); m_selectMode = false; @@ -552,7 +564,7 @@ void appl::Buffer::setHighlightType(const std::string& _type) { generateHighLightAt(0, m_data.size()); } -void appl::Buffer::regenerateHighLightAt(int32_t _pos, int32_t _nbDeleted, int32_t _nbAdded) { +void appl::Buffer::regenerateHighLightAt(int64_t _pos, int64_t _nbDeleted, int64_t _nbAdded) { // prevent ERROR... if (NULL == m_highlight) { return; @@ -564,11 +576,10 @@ void appl::Buffer::regenerateHighLightAt(int32_t _pos, int32_t _nbDeleted, int32 } // normal case //APPL_INFO("(pos="< _pos) +appl::HighlightInfo* appl::Buffer::getElementColorAtPosition(appl::DisplayHLData& _MData, int64_t _pos) { + int64_t start = etk_max(0, _MData.posHLPass2-1); + for (int64_t iii=start; iii<(int32_t)_MData.HLData.size(); iii++) { + _MData.posHLPass2 = iii; + if( _MData.HLData[iii].beginStart <= _pos + && _MData.HLData[iii].endStop > _pos) { - return &_MData.HLData[i]; + return &_MData.HLData[iii]; } - if(_MData.HLData[i].beginStart > _pos) { + if(_MData.HLData[iii].beginStart > _pos) { return getElementColorAtPosition(_pos, _MData.posHLPass1); } } diff --git a/sources/appl/Buffer.h b/sources/appl/Buffer.h index 5c2b7ca..1039566 100644 --- a/sources/appl/Buffer.h +++ b/sources/appl/Buffer.h @@ -24,8 +24,8 @@ namespace appl { class DisplayHLData { public: std::vector HLData; - int32_t posHLPass1; - int32_t posHLPass2; + int64_t posHLPass1; + int64_t posHLPass2; }; class Buffer : public ewol::EObject { public: @@ -94,7 +94,7 @@ namespace appl { * @brief basic boolean cast * @return true if the element is present in buffer */ - operator esize_t (void) const { + operator int64_t (void) const { if (m_data == NULL) { return 0; } @@ -217,7 +217,7 @@ namespace appl { * @brief Get the position in the buffer * @return The requested position. */ - esize_t getPos(void) const { + int64_t getPos(void) const { if (m_data == NULL) { return 0; } @@ -233,9 +233,16 @@ namespace appl { * @brief move the element position * @return a new iterator. */ + Iterator operator+ (const int64_t _val) const { + Iterator tmpp(*this); + for (int64_t iii=0; iii<_val; ++iii) { + ++tmpp; + } + return tmpp; + }; Iterator operator+ (const int32_t _val) const { Iterator tmpp(*this); - for (int32_t iii=0; iii<_val; ++iii) { + for (int64_t iii=0; iii<_val; ++iii) { ++tmpp; } return tmpp; @@ -244,15 +251,22 @@ namespace appl { * @brief move the element position * @return a new iterator. */ + Iterator operator- (const int64_t _val) const { + Iterator tmpp(*this); + for (int64_t iii=0; iii<_val; ++iii) { + --tmpp; + } + return tmpp; + }; Iterator operator- (const int32_t _val) const { Iterator tmpp(*this); - for (int32_t iii=0; iii<_val; ++iii) { + for (int64_t iii=0; iii<_val; ++iii) { --tmpp; } return tmpp; }; private: - Iterator(Buffer* _obj, int32_t _pos) : + Iterator(Buffer* _obj, int64_t _pos) : m_current(_pos), m_data(_obj), m_value(etk::UChar::Null) { @@ -325,9 +339,9 @@ namespace appl { protected: int64_t m_cursorPos; //!< cursor position. public: - void moveCursor(esize_t _pos); + void moveCursor(int64_t _pos); protected: - int32_t m_cursorSelectPos; //!< cursor position. + int64_t m_cursorSelectPos; //!< cursor position. public: /** * @brief Set the selection position in the buffer. @@ -490,7 +504,7 @@ namespace appl { * @param[in] _pos Requested position of the iterator. * @return The Iterator */ - Iterator position(esize_t _pos); + Iterator position(int64_t _pos); /** * @brief Get an Iterator on the start position. * @return The Iterator @@ -559,17 +573,17 @@ namespace appl { return m_highlightType; }; - void regenerateHighLightAt(int32_t _pos, int32_t _nbDeleted, int32_t _nbAdded); - void findMainHighLightPosition(int32_t _startPos, - int32_t _endPos, - int32_t& _startId, - int32_t& _stopId, + void regenerateHighLightAt(int64_t _pos, int64_t _nbDeleted, int64_t _nbAdded); + void findMainHighLightPosition(int64_t _startPos, + int64_t _endPos, + int64_t& _startId, + int64_t& _stopId, bool _backPreviousNotEnded); - void generateHighLightAt(int32_t _pos, int32_t _endPos, int32_t _addingPos=0); + void generateHighLightAt(int64_t _pos, int64_t _endPos, int64_t _addingPos=0); void cleanHighLight(void); - appl::HighlightInfo* getElementColorAtPosition(int32_t _pos, int32_t &_starPos); - void hightlightGenerateLines(appl::DisplayHLData& _MData, int32_t _HLStart, int32_t _nbLines); - appl::HighlightInfo* getElementColorAtPosition(appl::DisplayHLData& _MData, int32_t _pos); + appl::HighlightInfo* getElementColorAtPosition(int64_t _pos, int64_t &_starPos); + void hightlightGenerateLines(appl::DisplayHLData& _MData, int64_t _HLStart, int64_t _nbLines); + appl::HighlightInfo* getElementColorAtPosition(appl::DisplayHLData& _MData, int64_t _pos); }; }; diff --git a/sources/appl/Gui/TextViewer.cpp b/sources/appl/Gui/TextViewer.cpp index 4c7e4bb..32b8d2f 100644 --- a/sources/appl/Gui/TextViewer.cpp +++ b/sources/appl/Gui/TextViewer.cpp @@ -144,10 +144,10 @@ void appl::TextViewer::onRegenerateDisplay(void) { etk::Buffer& buf = m_buffer->getData(); m_displayText.setColor(etk::Color<>(0, 0, 0, 256)); float countNbLine = 1; - esize_t countColomn = 0; + int32_t countColomn = 0; // the siplay string : std::u32string stringToDisplay; - esize_t bufferElementSize = 0; + int64_t bufferElementSize = 0; bool isSelect = false; appl::Buffer::Iterator selectPosStart = m_buffer->begin(); appl::Buffer::Iterator selectPosStop = m_buffer->begin(); @@ -158,7 +158,7 @@ void appl::TextViewer::onRegenerateDisplay(void) { m_displayText.setPos(vec3(-m_originScrooled.x(), m_size.y()+m_originScrooled.y(), 0)); m_displayText.forceLineReturn(); appl::Buffer::Iterator startingIt = m_buffer->begin(); - int32_t startLineId = 0; + int64_t startLineId = 0; if (m_size.y() < m_displayText.getPos().y()) { for (startingIt = m_buffer->begin(); (bool)startingIt == true; @@ -177,7 +177,7 @@ void appl::TextViewer::onRegenerateDisplay(void) { m_lastOffsetDisplay = 0; vec3 tmpLetterSize = m_displayText.calculateSize((char32_t)'A'); { - esize_t nbLine = m_buffer->getNumberOfLines(); + int32_t nbLine = m_buffer->getNumberOfLines(); float nbLineCalc = nbLine; int32_t nbChar = 0; while (nbLineCalc >= 1.0f) { @@ -208,7 +208,7 @@ void appl::TextViewer::onRegenerateDisplay(void) { m_displayText.setClipping(vec2(m_lastOffsetDisplay, 0), m_size); } appl::DisplayHLData displayLocalSyntax; - m_buffer->hightlightGenerateLines(displayLocalSyntax, (esize_t)startingIt, m_size.y()); + m_buffer->hightlightGenerateLines(displayLocalSyntax, (int64_t)startingIt, m_size.y()); float maxSizeX = 0; appl::HighlightInfo * HLColor = NULL; for (appl::Buffer::Iterator it = startingIt; @@ -240,7 +240,7 @@ void appl::TextViewer::onRegenerateDisplay(void) { } continue; } - HLColor = m_buffer->getElementColorAtPosition(displayLocalSyntax, (esize_t)it); + HLColor = m_buffer->getElementColorAtPosition(displayLocalSyntax, (int64_t)it); bool haveBackground = false; if ( HLColor != NULL && HLColor->patern != NULL) { @@ -287,7 +287,7 @@ void appl::TextViewer::onRegenerateDisplay(void) { // set maximum size (X&Y) : { vec3 tmpLetterSize = m_displayText.calculateSize((char32_t)'A'); - esize_t nbLines = m_buffer->getNumberOfLines(); + int64_t nbLines = m_buffer->getNumberOfLines(); m_maxSize.setX(maxSizeX+m_originScrooled.x()); m_maxSize.setY((float)nbLines*tmpLetterSize.y()); } @@ -533,7 +533,7 @@ appl::Buffer::Iterator appl::TextViewer::getMousePosition(const vec2& _relativeP char32_t currentValue; vec3 positionCurentDisplay(0,0,0); vec3 tmpLetterSize = m_displayText.calculateSize((char32_t)'A'); - esize_t countColomn = 0; + int32_t countColomn = 0; std::u32string stringToDisplay; m_displayText.clear(); m_displayText.forceLineReturn(); @@ -542,7 +542,7 @@ appl::Buffer::Iterator appl::TextViewer::getMousePosition(const vec2& _relativeP ++it) { currentValue = *it; m_buffer->expand(countColomn, currentValue, stringToDisplay); - for (esize_t kkk=0; kkkmoveCursor((esize_t)_pos); + m_buffer->moveCursor((int64_t)_pos); updateScrolling(); return true; } @@ -790,7 +790,7 @@ void appl::TextViewer::moveCursorRight(appl::TextViewer::moveMode _mode) { case moveLetter: it = m_buffer->cursor(); ++it; - APPL_ERROR("Cursor position : " << (esize_t)it); + APPL_ERROR("Cursor position : " << (int64_t)it); moveCursor(it); break; case moveWord: @@ -814,7 +814,7 @@ void appl::TextViewer::moveCursorLeft(appl::TextViewer::moveMode _mode) { case moveLetter: it = m_buffer->cursor();; --it; - APPL_ERROR("Cursor position : " << (esize_t)it); + APPL_ERROR("Cursor position : " << (int64_t)it); moveCursor(it); break; case moveWord: @@ -827,7 +827,7 @@ void appl::TextViewer::moveCursorLeft(appl::TextViewer::moveMode _mode) { } } -void appl::TextViewer::moveCursorUp(esize_t _nbLine) { +void appl::TextViewer::moveCursorUp(uint32_t _nbLine) { if (m_buffer == NULL) { return; } @@ -854,7 +854,7 @@ void appl::TextViewer::moveCursorUp(esize_t _nbLine) { m_buffer->setFavoriteUpDownPos(posStore); } -void appl::TextViewer::moveCursorDown(esize_t _nbLine) { +void appl::TextViewer::moveCursorDown(uint32_t _nbLine) { if (m_buffer == NULL) { return; } @@ -884,7 +884,7 @@ void appl::TextViewer::moveCursorDown(esize_t _nbLine) { // TODO : Rename ... appl::Buffer::Iterator appl::TextViewer::getPosSize(const appl::Buffer::Iterator& _startLinePos, float _distance) { char32_t currentValue; - esize_t countColomn = 0; + int32_t countColomn = 0; std::u32string stringToDisplay; m_displayText.clear(); m_displayText.forceLineReturn(); @@ -893,7 +893,7 @@ appl::Buffer::Iterator appl::TextViewer::getPosSize(const appl::Buffer::Iterator ++it) { currentValue = *it; m_buffer->expand(countColomn, currentValue, stringToDisplay); - for (esize_t kkk=0; kkkexpand(countColomn, currentValue, stringToDisplay); - for (esize_t kkk=0; kkk &metaData, - int32_t addingPos, + int64_t addingPos, etk::Buffer &buffer) { if (0 > addingPos) { addingPos = 0; } //APPL_DEBUG("Parse element 0 => " << m_listHighlightPass1.size() << " == > position search: (" << start << "," << stop << ")" ); - int32_t elementStart = start; - int32_t elementStop = stop; + int64_t elementStart = start; + int64_t elementStop = stop; appl::HighlightInfo resultat; while (elementStart &metaData, etk::Buffer &buffer) { //APPL_DEBUG("Parse element 0 => " << m_listHighlightPass2.size() << " == > position search: (" << start << "," << stop << ")" ); - int32_t elementStart = start; - int32_t elementStop = stop; + int64_t elementStart = start; + int64_t elementStop = stop; appl::HighlightInfo resultat; while (elementStart &_metaData, - int32_t _addingPos, + int64_t _addingPos, etk::Buffer &_buffer); - void parse2(int32_t _start, - int32_t _stop, + void parse2(int64_t _start, + int64_t _stop, std::vector &_metaData, etk::Buffer &_buffer); private: