Change the redraw methode of the code viewer ==> reparse every time needed the line in the buffer for the second pass of highlight

This commit is contained in:
Edouard Dupin 2012-02-07 18:04:15 +01:00
parent 7734a8ce36
commit 8ba3e2e3d4
11 changed files with 138 additions and 102 deletions

View File

@ -113,6 +113,8 @@ class Buffer {
virtual void JumpAtLine(int32_t newLine);
virtual int32_t GetCurrentLine(void);
virtual int32_t GetNumberOfLine(void) { return 1; };
protected:
bool m_fileModify; //!<
// naming

View File

@ -79,7 +79,6 @@ void BufferText::BasicInit(void)
m_displayStartLineId = 0;
m_displaySize.x = 200;
m_displaySize.y = 20;
m_displayLocalSyntax.idSequence = -1;
}
@ -294,6 +293,12 @@ void BufferText::UpdatePointerNumber(void)
}
*/
int32_t BufferText::GetNumberOfLine(void)
{
return m_EdnBuf.CountLines();
}
// TODO : Remove this ... it is really bad...
static int32_t g_basicfontId = 0;
@ -314,6 +319,10 @@ int32_t BufferText::Display(ewol::OObject2DTextColored* OOTextNormal,
int32_t offsetX, int32_t offsetY,
int32_t sizeX, int32_t sizeY)
{
offsetX -= 40;
if (offsetX<0) {
offsetX = 0;
}
int32_t selStart, selEnd, selRectStart, selRectEnd;
bool selIsRect;
int32_t selHave;
@ -373,6 +382,7 @@ int32_t BufferText::Display(ewol::OObject2DTextColored* OOTextNormal,
int displayLines = 0;
// Regenerate the colorizing if necessary ...
displayHLData_ts m_displayLocalSyntax;
m_EdnBuf.HightlightGenerateLines(m_displayLocalSyntax, m_displayStartBufferPos, m_displaySize.y);
//GTimeVal timeStart;
//g_get_current_time(&timeStart);
@ -385,14 +395,22 @@ int32_t BufferText::Display(ewol::OObject2DTextColored* OOTextNormal,
EDN_DEBUG("Start display of text buffer [" << m_displayStartBufferPos<< ".." << mylen << "]");
EDN_DEBUG("cursor Pos : " << m_cursorPos << "start at pos=" << m_displayStartBufferPos);
DrawLineNumber(OOTextNormal, OOColored, x_base, sizeY, myPrint, currentLineID, y);
int32_t pixelX = x_base + SEPARATION_SIZE_LINE_NUMBER;
clipping_ts drawClipping;
drawClipping.x = 0;
drawClipping.y = 0;
drawClipping.w = sizeX;
drawClipping.h = sizeY;
DrawLineNumber(OOTextNormal, OOColored, x_base, sizeY, myPrint, currentLineID, y);
int32_t pixelX = x_base + SEPARATION_SIZE_LINE_NUMBER;
clipping_ts drawClippingTextArea;
drawClippingTextArea.x = pixelX;
drawClippingTextArea.y = 0;
drawClippingTextArea.w = sizeX - drawClipping.x;
drawClippingTextArea.h = sizeY;
for (iii=m_displayStartBufferPos; iii<mylen && displayLines < m_displaySize.y ; iii = new_i) {
//EDN_DEBUG("diplay element=" << iii);
int displaywidth;
@ -434,7 +452,7 @@ int32_t BufferText::Display(ewol::OObject2DTextColored* OOTextNormal,
}
}
coord2D_ts textPos;
textPos.x = pixelX-m_displayStartPixelX;
textPos.x = pixelX-offsetX;
textPos.y = y;
if (true == selectColor->GetItalic() ) {
if (true == selectColor->GetBold() ) {
@ -450,9 +468,9 @@ int32_t BufferText::Display(ewol::OObject2DTextColored* OOTextNormal,
}
}
OOTextSelected->SetColor(selectColor->GetFG());
drawSize = OOTextSelected->TextAdd(textPos, drawClipping, displayChar);
drawSize = OOTextSelected->TextAdd(textPos, drawClippingTextArea, displayChar);
if (true == haveBg ) {
OOColored->Rectangle( pixelX, y, drawSize, letterHeight, drawClipping);
OOColored->Rectangle(textPos.x, y, drawSize, letterHeight, drawClippingTextArea);
}
}
idX += displaywidth;
@ -525,8 +543,8 @@ int32_t BufferText::GetMousePosition(int32_t width, int32_t height)
EDN_DEBUG(" Element : Befor the start of the line ... ==> END");
return startLinePosition;
}
EDN_DEBUG("Get id element : x=" << width << "px y=" << height << "px");
EDN_DEBUG(" line offset = " << lineOffset);
EDN_VERBOSE("Get id element : x=" << width << "px y=" << height << "px");
EDN_VERBOSE(" line offset = " << lineOffset);
for (iii=startLinePosition; iii<mylen; iii = new_i) {
int displaywidth;
uint32_t currentChar = '\0';
@ -534,21 +552,21 @@ int32_t BufferText::GetMousePosition(int32_t width, int32_t height)
displaywidth = m_EdnBuf.GetExpandedChar(new_i, idX, displayChar, currentChar);
if (currentChar!='\n') {
int32_t drawSize = ewol::GetWidth(g_basicfontId, displayChar);
EDN_DEBUG(" Element : " << currentChar << "=\"" << (char)currentChar << "\" display offset=" << pixelX << "px width=" << drawSize << "px");
EDN_VERBOSE(" Element : " << currentChar << "=\"" << (char)currentChar << "\" display offset=" << pixelX << "px width=" << drawSize << "px");
pixelX += drawSize;
if (width <= pixelX) {
EDN_DEBUG(" Find IT ==> END");
EDN_VERBOSE(" Find IT ==> END");
// find position ...
break;
}
} else {
EDN_DEBUG(" Element : \"\\n\" display width=---px ==> end of line ==> END");
EDN_VERBOSE(" Element : \"\\n\" display width=---px ==> end of line ==> END");
// end of line ... exit cycle
break;
}
idX += displaywidth;
}
EDN_DEBUG("BufferText::GetMousePosition(" << width << "," << height << "); ==> " << iii );
EDN_VERBOSE("BufferText::GetMousePosition(" << width << "," << height << "); ==> " << iii );
return iii;
}
@ -721,7 +739,6 @@ void BufferText::ScrollUp(void)
*/
void BufferText::MoveUpDown(int32_t ofset)
{
m_displayLocalSyntax.idSequence = -1;
if (ofset >= 0) {
int32_t nbLine = m_EdnBuf.NumberOfLines();
if (m_displayStartLineId+ofset+3 > nbLine) {
@ -756,7 +773,6 @@ void BufferText::MoveUpDown(int32_t ofset)
void BufferText::ForceReDraw(bool allElement)
{
NeedToCleanEndPage = true;
//m_displayLocalSyntax.idSequence = -1;
}
void BufferText::SetInsertPosition(int32_t newPos, bool insertChar)

View File

@ -79,6 +79,7 @@ class BufferText : public Buffer {
void Undo(void);
void Redo(void);
void SetCharset(unicode::charset_te newCharset);
int32_t GetNumberOfLine(void);
protected:
void NameChange(void);
@ -100,8 +101,6 @@ class BufferText : public Buffer {
int32_t m_cursorPreferredCol; //!< colomn of the last up and down ...
cursorDisplayMode_te m_cursorMode; //!< type of cursor Selected
displayHLData_ts m_displayLocalSyntax; //!< for the display of the local elements (display HL mode)
// internal function
void BasicInit(void);
void UpdateWindowsPosition(bool centerPage = false);

View File

@ -115,11 +115,12 @@ void ColorizeManager::LoadFile(const char * xmlFilename)
return;
}
// allocate data
char * fileBuffer = new char[fileSize];
char * fileBuffer = new char[fileSize+5];
if (NULL == fileBuffer) {
EWOL_ERROR("Error Memory allocation size=" << fileSize);
return;
}
memset(fileBuffer, 0, (fileSize+5)*sizeof(char));
// load data from the file :
fileName.fRead(fileBuffer, 1, fileSize);
// close the file:

View File

@ -73,6 +73,7 @@ CodeView::CodeView(void)
//old
/*
ewol::widgetMessageMultiCast::Add(GetWidgetId(), ednMsgCodeViewCurrentChangeBufferId);
ewol::widgetMessageMultiCast::Add(GetWidgetId(), ednMsgCodeViewCurrentSave);
ewol::widgetMessageMultiCast::Add(GetWidgetId(), ednMsgCodeViewCurrentSaveAs);
@ -92,6 +93,7 @@ CodeView::CodeView(void)
ewol::widgetMessageMultiCast::Add(GetWidgetId(), ednMsgCodeViewCurrentRedo);
ewol::widgetMessageMultiCast::Add(GetWidgetId(), ednMsgCodeViewCurrentGotoLine);
ewol::widgetMessageMultiCast::Add(GetWidgetId(), ednMsgCodeViewCurrentSetCharset);
*/
}
CodeView::~CodeView(void)
@ -106,30 +108,45 @@ bool CodeView::CalculateMinSize(void)
return true;
}
void CodeView::CalculateMaxSize(void)
{
m_maxSize.x = 4096;
int32_t letterHeight = ewol::GetHeight(m_fontNormal);
m_maxSize.y = m_bufferManager->Get(m_bufferID)->GetNumberOfLine() * letterHeight;
}
void CodeView::OnRegenerateDisplay(void)
{
// create tmp object :
ewol::OObject2DTextColored* myOObjectTextNormal = new ewol::OObject2DTextColored(m_fontNormal);
ewol::OObject2DTextColored* myOObjectTextBold = new ewol::OObject2DTextColored(m_fontBold);
ewol::OObject2DTextColored* myOObjectTextItalic = new ewol::OObject2DTextColored(m_fontItalic);
ewol::OObject2DTextColored* myOObjectTextBoldItalic = new ewol::OObject2DTextColored(m_fontBoldItalic);
ewol::OObject2DColored* myOObjectsColored = new ewol::OObject2DColored();
// generate the objects :
//m_bufferID = 0;
m_bufferManager->Get(m_bufferID)->Display(myOObjectTextNormal, myOObjectTextBold, myOObjectTextItalic, myOObjectTextBoldItalic, myOObjectsColored,
m_originScrooledX, m_originScrooledY, m_size.x, m_size.y);
// clean the object list ...
ClearOObjectList();
// add generated element
AddOObject(myOObjectsColored, "CodeViewBackground");
AddOObject(myOObjectTextNormal, "CodeViewTextNormal");
AddOObject(myOObjectTextBold, "CodeViewTextBold");
AddOObject(myOObjectTextItalic, "CodeViewTextItalic");
AddOObject(myOObjectTextBoldItalic, "CodeViewTextBoldItalic");
if (true == NeedRedraw()) {
// For the scrooling windows
CalculateMaxSize();
// create tmp object :
ewol::OObject2DTextColored* myOObjectTextNormal = new ewol::OObject2DTextColored(m_fontNormal);
ewol::OObject2DTextColored* myOObjectTextBold = new ewol::OObject2DTextColored(m_fontBold);
ewol::OObject2DTextColored* myOObjectTextItalic = new ewol::OObject2DTextColored(m_fontItalic);
ewol::OObject2DTextColored* myOObjectTextBoldItalic = new ewol::OObject2DTextColored(m_fontBoldItalic);
ewol::OObject2DColored* myOObjectsColored = new ewol::OObject2DColored();
// generate the objects :
//m_bufferID = 0;
m_bufferManager->Get(m_bufferID)->Display(myOObjectTextNormal, myOObjectTextBold, myOObjectTextItalic, myOObjectTextBoldItalic, myOObjectsColored,
m_originScrooled.x, m_originScrooled.y, m_size.x, m_size.y);
// clean the object list ...
ClearOObjectList();
// add generated element
AddOObject(myOObjectsColored, "CodeViewBackground");
AddOObject(myOObjectTextNormal, "CodeViewTextNormal");
AddOObject(myOObjectTextBold, "CodeViewTextBold");
AddOObject(myOObjectTextItalic, "CodeViewTextItalic");
AddOObject(myOObjectTextBoldItalic, "CodeViewTextBoldItalic");
// call the herited class...
WidgetScrooled::OnRegenerateDisplay();
}
}
@ -202,14 +219,15 @@ bool CodeView::OnEventInput(int32_t IdInput, ewol::eventInputType_te typeEvent,
if (ewol::EVENT_INPUT_TYPE_DOWN == typeEvent) {
m_buttunOneSelected = true;
ewol::widgetManager::FocusKeep(this);
//EDN_INFO("mouse-event BT1 ==> One Clicked %d, %d", (uint32_t)event->x, (uint32_t)event->y);
m_bufferManager->Get(m_bufferID)->MouseEvent(x, y);
MarkToReedraw();
} else if (ewol::EVENT_INPUT_TYPE_UP == typeEvent) {
m_buttunOneSelected = false;
m_bufferManager->Get(m_bufferID)->Copy(COPY_MIDDLE_BUTTON);
MarkToReedraw();
} else if (ewol::EVENT_INPUT_TYPE_SINGLE == typeEvent) {
//EDN_INFO("mouse-event BT1 ==> One Clicked %d, %d", (uint32_t)event->x, (uint32_t)event->y);
m_bufferManager->Get(m_bufferID)->MouseEvent(x, y);
MarkToReedraw();
// nothing to do ...
} else if (ewol::EVENT_INPUT_TYPE_DOUBLE == typeEvent) {
//EDN_INFO("mouse-event BT1 ==> Double Clicked %d, %d", (uint32_t)event->x, (uint32_t)event->y);
m_bufferManager->Get(m_bufferID)->MouseEventDouble();

View File

@ -71,6 +71,8 @@ class CodeView :public ewol::WidgetScrooled
void SetFontNameBold(etk::String fontName);
void SetFontNameItalic(etk::String fontName);
void SetFontNameBoldItalic(etk::String fontName);
private:
void CalculateMaxSize(void);
};
#endif

View File

@ -122,13 +122,20 @@ MainWindows::MainWindows(void)
myCodeView->SetExpendY(true);
myCodeView->SetFillX(true);
myCodeView->SetFillY(true);
myCodeView->SetFontSize(11);
myCodeView->SetFontNameNormal( "freefont/FreeMono.ttf");
myCodeView->SetFontNameBold( "freefont/FreeMonoBold.ttf");
myCodeView->SetFontNameItalic( "freefont/FreeMonoOblique.ttf");
myCodeView->SetFontNameBoldItalic("freefont/FreeMonoBoldOblique.ttf");
/*
myCodeView->SetFontSize(11);
myCodeView->SetFontNameNormal( "ubuntu/UbuntuMono-R.ttf");
myCodeView->SetFontNameBold( "ubuntu/UbuntuMono-B.ttf");
myCodeView->SetFontNameItalic( "ubuntu/UbuntuMono-RI.ttf");
myCodeView->SetFontNameBoldItalic("ubuntu/UbuntuMono-BI.ttf");
*/
mySizerHori->SubWidgetAdd(myCodeView);
}

View File

@ -64,11 +64,12 @@ Highlight::Highlight(etk::String &xmlFilename)
return;
}
// allocate data
char * fileBuffer = new char[fileSize];
char * fileBuffer = new char[fileSize+5];
if (NULL == fileBuffer) {
EWOL_ERROR("Error Memory allocation size=" << fileSize);
return;
}
memset(fileBuffer, 0, (fileSize+5)*sizeof(char));
// load data from the file :
fileName.fRead(fileBuffer, 1, fileSize);
// close the file:

View File

@ -78,7 +78,6 @@ EdnBuf::EdnBuf(void)
// basicly no HL system ...
m_Highlight = NULL;
m_nbLine = 1;
m_HLDataSequence = 0;
}
/**

View File

@ -68,7 +68,6 @@ typedef enum{
typedef struct {
etk::VectorType<colorInformation_ts> HLData;
int32_t idSequence;
int32_t posHLPass1;
int32_t posHLPass2;
}displayHLData_ts;
@ -159,7 +158,6 @@ class EdnBuf {
private:
Highlight * m_Highlight; //!< internal link with the Highlight system
etk::VectorType<colorInformation_ts> m_HLDataPass1; //!< colorisation position in the current buffer pass 1
int32_t m_HLDataSequence; //!< position of the start of line requested by the screen viewer
void RegenerateHighLightAt(int32_t pos, int32_t nbDeleted, int32_t nbAdded);
void GenerateHighLightAt(int32_t pos, int32_t endPos, int32_t addinPos=0);
void CleanHighLight(void);

View File

@ -46,9 +46,6 @@ void EdnBuf::RegenerateHighLightAt(int32_t pos, int32_t nbDeleted, int32_t nbAdd
//GTimeVal timeStart;
//g_get_current_time(&timeStart);
// remove display HL...
m_HLDataSequence++;
// prevent ERROR...
if (NULL == m_Highlight) {
return;
@ -287,7 +284,6 @@ colorInformation_ts *EdnBuf::GetElementColorAtPosition(int32_t pos, int32_t &sta
}
void EdnBuf::HightlightGenerateLines(displayHLData_ts & MData, int32_t HLStart, int32_t nbLines)
{
MData.posHLPass1 = 0;
@ -295,65 +291,62 @@ void EdnBuf::HightlightGenerateLines(displayHLData_ts & MData, int32_t HLStart,
if (NULL == m_Highlight) {
return;
}
if (MData.idSequence != m_HLDataSequence) {
//GTimeVal timeStart;
//g_get_current_time(&timeStart);
MData.idSequence = m_HLDataSequence;
HLStart = StartOfLine(HLStart);
MData.HLData.Clear();
int32_t HLStop = CountForwardNLines(HLStart, nbLines);
int32_t startId, stopId;
// find element previous
FindMainHighLightPosition(HLStart, HLStop, startId, stopId, true);
//GTimeVal timeStart;
//g_get_current_time(&timeStart);
HLStart = StartOfLine(HLStart);
MData.HLData.Clear();
int32_t HLStop = CountForwardNLines(HLStart, nbLines);
int32_t startId, stopId;
// find element previous
FindMainHighLightPosition(HLStart, HLStop, startId, stopId, true);
int32_t k;
//EDN_DEBUG("List of section between : "<< startId << " & " << stopId);
int32_t endSearch = stopId+1;
if (-1 == stopId) {
endSearch = m_HLDataPass1.Size();
}
for (k=edn_max(startId, 0); k<endSearch; k++) {
// empty section :
if (0==k) {
if (HLStart < m_HLDataPass1[k].beginStart) {
//EDN_DEBUG(" ==> (empty section 1 ) k="<<k<<" start="<<HLStart<<" stop="<<m_HLDataPass1[k].beginStart );
m_Highlight->Parse2(HLStart,
m_HLDataPass1[k].beginStart,
MData.HLData,
m_data);
} // else : nothing to do ...
} else {
//EDN_DEBUG(" ==> (empty section 2 ) k="<<k<<" start="<<m_HLDataPass1[k-1].endStop<<" stop="<<m_HLDataPass1[k].beginStart );
m_Highlight->Parse2(m_HLDataPass1[k-1].endStop,
int32_t k;
//EDN_DEBUG("List of section between : "<< startId << " & " << stopId);
int32_t endSearch = stopId+1;
if (-1 == stopId) {
endSearch = m_HLDataPass1.Size();
}
for (k=edn_max(startId, 0); k<endSearch; k++) {
// empty section :
if (0==k) {
if (HLStart < m_HLDataPass1[k].beginStart) {
//EDN_DEBUG(" ==> (empty section 1 ) k="<<k<<" start="<<HLStart<<" stop="<<m_HLDataPass1[k].beginStart );
m_Highlight->Parse2(HLStart,
m_HLDataPass1[k].beginStart,
MData.HLData,
m_data);
}
// under section :
//EDN_DEBUG(" ==> (under section ) k="<<k<<" start="<<m_HLDataPass1[k].beginStart<<" stop="<<m_HLDataPass1[k].endStop << " subSectionOfID=" << 99999999);
// TODO : ...
} // else : nothing to do ...
} else {
//EDN_DEBUG(" ==> (empty section 2 ) k="<<k<<" start="<<m_HLDataPass1[k-1].endStop<<" stop="<<m_HLDataPass1[k].beginStart );
m_Highlight->Parse2(m_HLDataPass1[k-1].endStop,
m_HLDataPass1[k].beginStart,
MData.HLData,
m_data);
}
if (endSearch == (int32_t)m_HLDataPass1.Size() ){
//if( k < (int32_t)m_HLDataPass1.Size()) {
if (m_HLDataPass1.Size() != 0) {
//EDN_DEBUG(" ==> (empty section 3 ) k="<<k<<" start="<<m_HLDataPass1[k-1].endStop<<" stop="<<HLStop );
m_Highlight->Parse2(m_HLDataPass1[k-1].endStop,
HLStop,
MData.HLData,
m_data);
} else {
//EDN_DEBUG(" ==> (empty section 4 ) k="<<k<<" start=0 stop="<<HLStop );
m_Highlight->Parse2(0,
HLStop,
MData.HLData,
m_data);
}
}
//GTimeVal timeStop;
//g_get_current_time(&timeStop);
//EDN_DEBUG("Display reAnnalyse = " << timeStop.tv_usec - timeStart.tv_usec << " micro-s");
// under section :
//EDN_DEBUG(" ==> (under section ) k="<<k<<" start="<<m_HLDataPass1[k].beginStart<<" stop="<<m_HLDataPass1[k].endStop << " subSectionOfID=" << 99999999);
// TODO : ...
}
if (endSearch == (int32_t)m_HLDataPass1.Size() ){
//if( k < (int32_t)m_HLDataPass1.Size()) {
if (m_HLDataPass1.Size() != 0) {
//EDN_DEBUG(" ==> (empty section 3 ) k="<<k<<" start="<<m_HLDataPass1[k-1].endStop<<" stop="<<HLStop );
m_Highlight->Parse2(m_HLDataPass1[k-1].endStop,
HLStop,
MData.HLData,
m_data);
} else {
//EDN_DEBUG(" ==> (empty section 4 ) k="<<k<<" start=0 stop="<<HLStop );
m_Highlight->Parse2(0,
HLStop,
MData.HLData,
m_data);
}
}
//GTimeVal timeStop;
//g_get_current_time(&timeStop);
//EDN_DEBUG("Display reAnnalyse = " << timeStop.tv_usec - timeStart.tv_usec << " micro-s");
}