diff --git a/Sources/Buffer/Buffer.cpp b/Sources/Buffer/Buffer.cpp index e7002b7..cf09c5d 100644 --- a/Sources/Buffer/Buffer.cpp +++ b/Sources/Buffer/Buffer.cpp @@ -185,6 +185,25 @@ void Buffer::DrawLine(DrawerManager &drawer, bufferAnchor_ts &anchor) } +/** + * @brief + * + * @param[in,out] --- + * + * @return --- + * + */ +void Buffer::DrawLineEmpty(DrawerManager &drawer, int32_t lineScreenID) +{ + ColorizeManager * myColorManager = ColorizeManager::getInstance(); + int32_t positionY = m_lineHeight * (lineScreenID); +# ifdef NDEBUG + drawer.Rectangle(myColorManager->Get(COLOR_CODE_BASIC_BG), 0, positionY, drawer.GetWidth(), m_lineHeight ); +# else + drawer.Rectangle(myColorManager->Get(COLOR_CODE_CURSOR), 0, positionY, drawer.GetWidth(), m_lineHeight ); +# endif +} + /** * @brief * @@ -457,8 +476,15 @@ void Buffer::AnchorSetSize(int32_t anchorID, int32_t sizePixelX, int32_t sizePix { int32_t localID = AnchorRealId(anchorID); if (localID >=0) { - m_AnchorList[localID].m_displaySize.x = sizePixelX / m_lineWidth; - m_AnchorList[localID].m_displaySize.y = sizePixelY / m_lineHeight; + position_ts mySize; + mySize.x = sizePixelX / m_lineWidth; + mySize.y = sizePixelY / m_lineHeight; + if( m_AnchorList[localID].m_displaySize.x != mySize.x + || m_AnchorList[localID].m_displaySize.y != mySize.y ) + { + AnchorForceRedrawAll(localID); + } + m_AnchorList[localID].m_displaySize = mySize; } } @@ -475,6 +501,7 @@ void Buffer::AnchorSetStartOffset(int32_t anchorID, int32_t offsetX, int32_t off if (0=0) { - m_AnchorList[localID].m_BufferNumberLineOffset = 0; + if (-5000 == realAnchorId) { + int32_t localID = AnchorCurrentId(); + if (localID >=0) { + m_AnchorList[localID].m_BufferNumberLineOffset = 0; + for(int32_t iii=0; iii < MAX_LINE_DISPLAYABLE_BY_BUFFER; iii++) { + m_AnchorList[localID].m_redrawLine[iii] = true; + } + } + } else { + m_AnchorList[realAnchorId].m_BufferNumberLineOffset = 0; for(int32_t iii=0; iii < MAX_LINE_DISPLAYABLE_BY_BUFFER; iii++) { - m_AnchorList[localID].m_redrawLine[iii] = true; + m_AnchorList[realAnchorId].m_redrawLine[iii] = true; } } } @@ -528,18 +562,25 @@ void Buffer::AnchorForceRedrawLine(int32_t lineID) void Buffer::AnchorForceRedrawOffsef(int32_t offset) { - //offset *= -1; - //EDN_DEBUG("** => set ofset : " << offset); + EDN_DEBUG("** => set ofset : " << offset); + if (0 == offset) { + EDN_DEBUG("No apply offset ..."); + return; + } int32_t localID = AnchorCurrentId(); if (localID >=0) { + EDN_DEBUG("offset ID=" << localID); m_AnchorList[localID].m_BufferNumberLineOffset += offset; if (offset < 0) { if (-1 * offset < MAX_LINE_DISPLAYABLE_BY_BUFFER) { + EDN_DEBUG("move redraw request : [" << -1*offset << "," << MAX_LINE_DISPLAYABLE_BY_BUFFER << "[=[" << -1*offset + offset << "," << MAX_LINE_DISPLAYABLE_BY_BUFFER+offset << "["); + //for(int32_t iii=MAX_LINE_DISPLAYABLE_BY_BUFFER; iii >= -1*offset; iii--) { for(int32_t iii=-1*offset; iii < MAX_LINE_DISPLAYABLE_BY_BUFFER; iii++) { //EDN_DEBUG("move redraw request : " << iii << " <== " << iii+offset << " val=" << m_AnchorList[localID].m_redrawLine[iii+offset]); m_AnchorList[localID].m_redrawLine[iii] = m_AnchorList[localID].m_redrawLine[iii+offset]; } + EDN_DEBUG("move redraw request : [" << 0 << "," << -1*offset << "[=true"); for(int32_t iii=0; iii < -1*offset; iii++) { //EDN_DEBUG("move redraw request : " << iii << " <== true"); m_AnchorList[localID].m_redrawLine[iii] = true; @@ -553,10 +594,12 @@ void Buffer::AnchorForceRedrawOffsef(int32_t offset) } } else { if (offset < MAX_LINE_DISPLAYABLE_BY_BUFFER) { + EDN_DEBUG("move redraw request : [" << 0 << "," << MAX_LINE_DISPLAYABLE_BY_BUFFER-offset << "[=[" << offset << "," << MAX_LINE_DISPLAYABLE_BY_BUFFER << "["); for(int32_t iii=0; iii < MAX_LINE_DISPLAYABLE_BY_BUFFER-offset ; iii++) { //EDN_DEBUG("move redraw request : " << iii << " <== " << iii+offset << " val=" << m_AnchorList[localID].m_redrawLine[iii+offset]); m_AnchorList[localID].m_redrawLine[iii] = m_AnchorList[localID].m_redrawLine[iii+offset]; } + EDN_DEBUG("move redraw request : [" << MAX_LINE_DISPLAYABLE_BY_BUFFER-offset+1 << "," << MAX_LINE_DISPLAYABLE_BY_BUFFER << "[=true"); for(int32_t iii=MAX_LINE_DISPLAYABLE_BY_BUFFER-offset+1; iii < MAX_LINE_DISPLAYABLE_BY_BUFFER; iii++) { //EDN_DEBUG("move redraw request : " << iii << " <== true"); m_AnchorList[localID].m_redrawLine[iii] = true; @@ -569,9 +612,12 @@ void Buffer::AnchorForceRedrawOffsef(int32_t offset) } } } + EDN_DEBUG("move redraw request : [" << m_AnchorList[localID].m_displaySize.y << "," << MAX_LINE_DISPLAYABLE_BY_BUFFER << "[=true"); for(int32_t iii=m_AnchorList[localID].m_displaySize.y; iii < MAX_LINE_DISPLAYABLE_BY_BUFFER; iii++) { //EDN_DEBUG("move redraw request : " << iii << " <== true"); m_AnchorList[localID].m_redrawLine[iii] = true; } + } else { + EDN_ERROR("can not find the real ID in linste.Size()=" << m_AnchorList.Size()); } } diff --git a/Sources/Buffer/Buffer.h b/Sources/Buffer/Buffer.h index 91f77fe..c645e25 100644 --- a/Sources/Buffer/Buffer.h +++ b/Sources/Buffer/Buffer.h @@ -110,6 +110,7 @@ class Buffer { virtual void SetLineDisplay(uint32_t lineNumber); virtual void DrawLine(DrawerManager &drawer, bufferAnchor_ts &anchor); + virtual void DrawLineEmpty(DrawerManager &drawer, int32_t lineScreenID); // return the new cursor position ... virtual void AddChar(char * UTF8data); virtual void cursorMove(int32_t gtkKey); @@ -158,7 +159,7 @@ class Buffer { int32_t m_lineHeight; int32_t AnchorRealId(int32_t anchorID); int32_t AnchorCurrentId(void); - void AnchorForceRedrawAll(void); + void AnchorForceRedrawAll(int32_t realAnchorId = -5000); void AnchorForceRedrawLine(int32_t lineID); void AnchorForceRedrawOffsef(int32_t offset); Edn::VectorType m_AnchorList; //!< list of all line anchor in the current buffer diff --git a/Sources/Buffer/BufferEmpty.cpp b/Sources/Buffer/BufferEmpty.cpp index e599ae7..e5fdd5a 100644 --- a/Sources/Buffer/BufferEmpty.cpp +++ b/Sources/Buffer/BufferEmpty.cpp @@ -43,7 +43,7 @@ BufferEmpty::BufferEmpty() { m_lineWidth = Display::GetFontWidth(); - m_lineHeight = Display::GetFontHeight(); + m_lineHeight = Display::GetFontHeight()*4; } /** diff --git a/Sources/Buffer/BufferText.cpp b/Sources/Buffer/BufferText.cpp index 9b89d25..1227614 100644 --- a/Sources/Buffer/BufferText.cpp +++ b/Sources/Buffer/BufferText.cpp @@ -59,6 +59,7 @@ void BufferText::BasicInit(void) //EDN_INFO("Init"); // new mode : m_cursorPos = 0; + m_cursorPosPrevious = m_cursorPos; m_cursorPreferredCol = -1; m_cursorOn = true; // set at the sustem buffer internal @@ -475,6 +476,7 @@ void BufferText::MouseEventDouble(void) int32_t beginPos, endPos; if (true == m_EdnBuf.SelectAround(m_cursorPos, beginPos, endPos)) { m_EdnBuf.Select(SELECTION_PRIMARY, beginPos, endPos); + m_cursorPosPrevious = m_cursorPos; m_cursorPos = endPos; } // no else @@ -491,6 +493,7 @@ void BufferText::MouseEventDouble(void) void BufferText::MouseEventTriple(void) { m_EdnBuf.Select(SELECTION_PRIMARY, m_EdnBuf.StartOfLine(m_cursorPos), m_EdnBuf.EndOfLine(m_cursorPos)); + m_cursorPosPrevious = m_cursorPos; m_cursorPos = m_EdnBuf.EndOfLine(m_cursorPos); } @@ -500,18 +503,21 @@ void BufferText::RemoveLine(void) int32_t stop = m_EdnBuf.EndOfLine(m_cursorPos); m_EdnBuf.Remove(start, stop+1); SetInsertPosition(start); - SetModify(true); + SetModify(true); } void BufferText::SelectAll(void) { m_EdnBuf.Select(SELECTION_PRIMARY, 0, m_EdnBuf.Size()); + m_cursorPosPrevious = m_cursorPos; m_cursorPos = m_EdnBuf.Size(); + AnchorForceRedrawAll(); } void BufferText::SelectNone(void) { m_EdnBuf.Unselect(SELECTION_PRIMARY); + AnchorForceRedrawAll(); } #define SCROLL_NB_LINE (3) @@ -526,7 +532,6 @@ void BufferText::SelectNone(void) */ void BufferText::ScrollDown(void) { - MoveUpDown(SCROLL_NB_LINE); } @@ -592,7 +597,6 @@ void BufferText::SetInsertPosition(int32_t newPos, bool insertChar) int32_t rememberCursorPos = m_cursorPos; //EDN_DEBUG("newPos=" << newPos); - // unselect buffer: m_EdnBuf.Unselect(SELECTION_PRIMARY); /* make sure new position is ok, do nothing if it hasn't changed */ @@ -603,6 +607,7 @@ void BufferText::SetInsertPosition(int32_t newPos, bool insertChar) if (newPos > m_EdnBuf.Size()) { newPos = m_EdnBuf.Size(); } + m_cursorPosPrevious = m_cursorPos; m_cursorPos = newPos; } m_cursorPreferredCol = -1; @@ -721,8 +726,6 @@ void BufferText::cursorMove(int32_t gtkKey) if (m_cursorPos > 0) { SetInsertPosition(m_cursorPos - 1); } - tmplineID = m_EdnBuf.CountLines(0, m_cursorPos); - AnchorForceRedrawLine(tmplineID); break; # ifdef USE_GTK_VERSION_3_0 case GDK_KEY_Right: @@ -733,8 +736,6 @@ void BufferText::cursorMove(int32_t gtkKey) if (m_cursorPos < m_EdnBuf.Size() ) { SetInsertPosition(m_cursorPos + 1); } - tmplineID = m_EdnBuf.CountLines(0, m_cursorPos); - AnchorForceRedrawLine(tmplineID); break; # ifdef USE_GTK_VERSION_3_0 case GDK_KEY_Up: @@ -742,10 +743,7 @@ void BufferText::cursorMove(int32_t gtkKey) case GDK_Up: # endif //EDN_INFO("keyEvent : "); - tmplineID = m_EdnBuf.CountLines(0, m_cursorPos); - AnchorForceRedrawLine(tmplineID); TextDMoveUp(1); - AnchorForceRedrawLine(tmplineID-1); break; # ifdef USE_GTK_VERSION_3_0 case GDK_KEY_Down: @@ -754,10 +752,7 @@ void BufferText::cursorMove(int32_t gtkKey) # endif //EDN_INFO("keyEvent : "); // check if we have enought line ... - tmplineID = m_EdnBuf.CountLines(0, m_cursorPos); - AnchorForceRedrawLine(tmplineID); TextDMoveDown(1); - AnchorForceRedrawLine(tmplineID+1); break; # ifdef USE_GTK_VERSION_3_0 case GDK_KEY_Page_Up: @@ -812,16 +807,26 @@ void BufferText::cursorMove(int32_t gtkKey) */ void BufferText::UpdateWindowsPosition(bool centerPage) { - for (int32_t iii=0; iii < m_AnchorList.Size() ; iii++) { - if (centerPage == false) { - // Display position (Y mode): - //EDN_INFO(" m_displayStart(" << m_displayStart.x << "," << m_displayStart.y << ") m_displaySize(" << m_displaySize.x << "," <=0) { + position_ts displayPreviousStart = m_AnchorList[iii].m_displayStart; + //EDN_INFO(" m_displayStart(" << m_AnchorList[iii].m_displayStart.x << "," << m_AnchorList[iii].m_displayStart.y << ") m_displaySize(" << m_AnchorList[iii].m_displaySize.x << "," << m_AnchorList[iii].m_displaySize.y << ")"); if (m_AnchorList[iii].m_displayStart.y > (int32_t)cursorPosition.y - globals::getNbLineBorder() ) { m_AnchorList[iii].m_displayStart.y = cursorPosition.y - globals::getNbLineBorder(); if (m_AnchorList[iii].m_displayStart.y < 0) { @@ -844,14 +849,39 @@ void BufferText::UpdateWindowsPosition(bool centerPage) //update the buffer position ID : m_AnchorList[iii].m_bufferPos = m_EdnBuf.CountForwardNLines(0, m_AnchorList[iii].m_displayStart.y); m_AnchorList[iii].m_lineId = m_AnchorList[iii].m_displayStart.y; - } else { - // center the line at the middle of the screen : - position_ts cursorPosition; - //EDN_DEBUG(" -------------------------------------------------"); - cursorPosition.y = m_EdnBuf.CountLines(0, m_cursorPos); - //EDN_DEBUG(" cursor position : " << m_cursorPos << " ==> ligne=" << cursorPosition.y); - cursorPosition.x = 0; - + if (m_AnchorList[iii].m_displayStart.x != displayPreviousStart.x) { + AnchorForceRedrawAll(iii); + } else { + if (m_AnchorList[iii].m_displayStart.y != displayPreviousStart.y) { + EDN_WARNING("SELECT an ofset : displayPreviousStart.y=" << displayPreviousStart.y << " m_AnchorList[iii].m_displayStart.y=" << m_AnchorList[iii].m_displayStart.y << " ==>" << m_AnchorList[iii].m_displayStart.y - displayPreviousStart.y); + EDN_WARNING("SELECT ... offset = " << m_AnchorList[iii].m_BufferNumberLineOffset); + AnchorForceRedrawOffsef(m_AnchorList[iii].m_displayStart.y - displayPreviousStart.y); + EDN_WARNING("SELECT ... offset = " << m_AnchorList[iii].m_BufferNumberLineOffset); + } + int32_t SelectionStart, SelectionEnd, SelectionRectStart, SelectionRectEnd; + bool SelectionIsRect; + bool haveSelectionActive = m_EdnBuf.GetSelectionPos(SELECTION_PRIMARY, SelectionStart, SelectionEnd, SelectionIsRect, SelectionRectStart, SelectionRectEnd); + if (true == haveSelectionActive) { + int32_t start = edn_min(linePreviousID, cursorPosition.y); + int32_t stop = edn_max(linePreviousID, cursorPosition.y); + EDN_WARNING("SELECT force redraw range of lines : (" << start << "," << stop << ")"); + for (int32_t jjj=start; jjj <= stop; jjj++) { + AnchorForceRedrawLine(jjj); + } + } + } + } + } else { + // center the line at the middle of the screen : + position_ts cursorPosition; + //EDN_DEBUG(" -------------------------------------------------"); + cursorPosition.y = m_EdnBuf.CountLines(0, m_cursorPos); + //EDN_DEBUG(" cursor position : " << m_cursorPos << " ==> ligne=" << cursorPosition.y); + cursorPosition.x = 0; + // Done for all Anchor elements ... + //for (int32_t iii=0; iii < m_AnchorList.Size() ; iii++) { + int32_t iii = AnchorCurrentId(); + if (iii >=0) { m_AnchorList[iii].m_displayStart.x = 0; //EDN_DEBUG(" display size : " << m_displaySize.y); m_AnchorList[iii].m_displayStart.y = cursorPosition.y - m_AnchorList[iii].m_displaySize.y/2; @@ -860,6 +890,7 @@ void BufferText::UpdateWindowsPosition(bool centerPage) m_AnchorList[iii].m_lineId = m_AnchorList[iii].m_displayStart.y; //EDN_DEBUG(" display start : " << m_displayStart.x << "x" << m_displayStart.y); //EDN_DEBUG(" -------------------------------------------------"); + AnchorForceRedrawAll(iii); } } } @@ -898,11 +929,13 @@ void BufferText::AddChar(char * UTF8data) m_EdnBuf.ReplaceSelected(SELECTION_PRIMARY, tmpVect); SetInsertPosition(SelectionStart+tmpVect.Size(), true); } else { + int32_t tmpPos = m_cursorPos; if (true == globals::IsSetShift() ) { - m_cursorPos = m_EdnBuf.UnIndent(SELECTION_PRIMARY); + tmpPos = m_EdnBuf.UnIndent(SELECTION_PRIMARY); } else { - m_cursorPos = m_EdnBuf.Indent(SELECTION_PRIMARY); + tmpPos = m_EdnBuf.Indent(SELECTION_PRIMARY); } + SetInsertPosition(tmpPos, true); } } actionDone = true; @@ -992,8 +1025,6 @@ void BufferText::AddChar(char * UTF8data) } } } - int32_t tmplineID = m_EdnBuf.CountLines(0, m_cursorPos); - AnchorForceRedrawLine(tmplineID); SetModify(true); UpdateWindowsPosition(); } @@ -1186,7 +1217,7 @@ void BufferText::Cut(int8_t clipboardID) if (true == haveSelectionActive ) { EDN_INFO("REMOVE SELECTION"); m_EdnBuf.RemoveSelected(SELECTION_PRIMARY); - m_cursorPos = SelectionStart; + SetInsertPosition(SelectionStart, true); } UpdateWindowsPosition(); SetModify(true); @@ -1214,11 +1245,11 @@ void BufferText::Paste(int8_t clipboardID) if (true == haveSelectionActive ) { // replace data m_EdnBuf.ReplaceSelected(SELECTION_PRIMARY, mVect ); - m_cursorPos = SelectionStart + mVect.Size(); + SetInsertPosition(SelectionStart + mVect.Size(), true); } else { // insert data m_EdnBuf.Insert(m_cursorPos, mVect); - m_cursorPos += mVect.Size(); + SetInsertPosition(mVect.Size(), true); } UpdateWindowsPosition(); diff --git a/Sources/Buffer/BufferText.h b/Sources/Buffer/BufferText.h index c2108e4..44516fa 100644 --- a/Sources/Buffer/BufferText.h +++ b/Sources/Buffer/BufferText.h @@ -88,6 +88,7 @@ class BufferText : public Buffer { EdnBuf m_EdnBuf; //!< buffer associated on this displayer // Cursor : + int32_t m_cursorPosPrevious; //!< Previous position in the buffer of the cursor int32_t m_cursorPos; //!< position in the buffer of the cursor int32_t m_cursorPreferredCol; //!< colomn of the last up and down ... bool m_cursorOn; //!< the blink of the cursor ... diff --git a/Sources/CustumWidget/CodeView/CodeView.cpp b/Sources/CustumWidget/CodeView/CodeView.cpp index 2f78c02..a839b52 100644 --- a/Sources/CustumWidget/CodeView/CodeView.cpp +++ b/Sources/CustumWidget/CodeView/CodeView.cpp @@ -197,8 +197,6 @@ void CodeView::OnMessage(int32_t id, int32_t dataID) } -#define COUNT_TIME plop - gboolean CodeView::CB_displayDraw( GtkWidget *widget, GdkEventExpose *event, gpointer data) { CodeView * self = reinterpret_cast(data); @@ -237,7 +235,7 @@ gboolean CodeView::CB_displayDraw( GtkWidget *widget, GdkEventExpose *event, gpo Buffer * tmpBuf = self->m_bufferManager->Get(self->m_bufferID); - #ifdef COUNT_TIME + #ifndef NDEBUG GTimeVal timeStart; g_get_current_time(&timeStart); #endif @@ -250,7 +248,9 @@ gboolean CodeView::CB_displayDraw( GtkWidget *widget, GdkEventExpose *event, gpo int32_t currentLineID = 0; while (true == enableToWrite) { if (true == anchor.m_redrawLine[currentLineID]) { - EDN_DEBUG("draw line : " << currentLineID); + #ifndef NDEBUG + EDN_DEBUG("draw line=" << currentLineID << " realID=" << anchor.m_lineNumber ); + #endif tmpBuf->DrawLine(monDrawer, anchor); } enableToWrite = tmpBuf->AnchorNext(anchor); @@ -260,13 +260,11 @@ gboolean CodeView::CB_displayDraw( GtkWidget *widget, GdkEventExpose *event, gpo // Need to clean the end of windows (sometimes)... if(currentLineIDGet(COLOR_CODE_BASIC_BG), 0, positionY, monDrawer.GetWidth(), positionZ ); - monDrawer.Rectangle(myColorManager->Get(COLOR_CODE_CURSOR), 0, positionY, monDrawer.GetWidth(), positionZ ); - currentLineID ++; + for (int32_t iii=currentLineID; iii < anchor.m_displaySize.y; iii++) { + tmpBuf->DrawLineEmpty(monDrawer, iii); + } } - #ifdef COUNT_TIME + #ifndef NDEBUG GTimeVal timeStop; g_get_current_time(&timeStop); EDN_DEBUG("Display Generation = " << timeStop.tv_usec - timeStart.tv_usec << " micro-s ==> " << (timeStop.tv_usec - timeStart.tv_usec)/1000. << "ms"); diff --git a/Sources/tools/Display/Display.cpp b/Sources/tools/Display/Display.cpp index b4fe61e..c715d58 100644 --- a/Sources/tools/Display/Display.cpp +++ b/Sources/tools/Display/Display.cpp @@ -171,12 +171,13 @@ DrawerManager::DrawerManager(GtkWidget * widget, int32_t x, int32_t y, int32_t s } cairo_scale(m_cairo, 1.0, 1.0); - - // for Test only : this remove slowly the old line that is not rewritten - cairo_set_source_rgb(m_cairo, 0, 0, 0); - cairo_set_source_rgba(m_cairo, 1, 1, 1, 0.05); - cairo_paint(m_cairo); +# ifndef NDEBUG + // for Test only : this remove slowly the old line that is not rewritten + cairo_set_source_rgb(m_cairo, 0, 0, 0); + cairo_set_source_rgba(m_cairo, 1, 1, 1, 0.05); + cairo_paint(m_cairo); +# endif cairo_set_font_size(m_cairo, POLICE_SIZE); m_dataToDisplay[0] = '\0';