update the methode of calculation of the mouse event

This commit is contained in:
Edouard Dupin 2012-01-24 23:35:17 +01:00
parent d05d82ba7b
commit 43c3092fe3
2 changed files with 21 additions and 39 deletions

View File

@ -367,12 +367,11 @@ int32_t BufferText::Display(ewol::OObject2DTextColored* OOText, ewol::OObject2DC
EDN_DEBUG("Start display of text buffer [" << m_displayStartBufferPos<< ".." << mylen << "]"); EDN_DEBUG("Start display of text buffer [" << m_displayStartBufferPos<< ".." << mylen << "]");
EDN_DEBUG("cursor Pos : " << m_cursorPos << "start at pos=" << m_displayStartBufferPos); EDN_DEBUG("cursor Pos : " << m_cursorPos << "start at pos=" << m_displayStartBufferPos);
coord2D_ts drawClippingOrigin; clipping_ts drawClipping;
drawClippingOrigin.x = 0; drawClipping.x = 0;
drawClippingOrigin.y = 0; drawClipping.y = 0;
coord2D_ts drawClippingSize; drawClipping.w = sizeX;
drawClippingSize.x = sizeX; drawClipping.h = sizeY;
drawClippingSize.y = sizeY;
DrawLineNumber(OOText, OOColored, sizeX, sizeY, myPrint, currentLineID, y); DrawLineNumber(OOText, OOColored, sizeX, sizeY, myPrint, currentLineID, y);
int32_t pixelX = x_base; int32_t pixelX = x_base;
@ -403,9 +402,9 @@ int32_t BufferText::Display(ewol::OObject2DTextColored* OOText, ewol::OObject2DC
coord2D_ts textPos; coord2D_ts textPos;
textPos.x = pixelX-m_displayStartPixelX; textPos.x = pixelX-m_displayStartPixelX;
textPos.y = y; textPos.y = y;
drawSize = OOText->TextAdd(textPos, drawClippingOrigin, drawClippingSize, displayChar); drawSize = OOText->TextAdd(textPos, drawClipping, displayChar);
if (true == selectColor->HaveBg() ) { if (true == selectColor->HaveBg() ) {
//OOColored->Rectangle( pixelX, y, drawSize*strlen(tmpDisplayOfset), letterHeight); OOColored->Rectangle( pixelX, y, drawSize, letterHeight, drawClipping);
} }
} }
idX += displaywidth; idX += displaywidth;
@ -417,8 +416,6 @@ int32_t BufferText::Display(ewol::OObject2DTextColored* OOText, ewol::OObject2DC
pixelX += drawSize; pixelX += drawSize;
// move to next line ... // move to next line ...
if (currentChar=='\n') { if (currentChar=='\n') {
//drawer.EndOfLine(pixelX, y+letterHeight);
//drawer.Flush();
xx = 0; xx = 0;
idX =0; idX =0;
pixelX = x_base; pixelX = x_base;
@ -442,15 +439,13 @@ int32_t BufferText::Display(ewol::OObject2DTextColored* OOText, ewol::OObject2DC
void BufferText::GetMousePosition(int32_t width, int32_t height, int32_t &x, int32_t &y) int32_t BufferText::GetMousePosition(int32_t width, int32_t height)
{ {
int32_t fontId = ewol::GetDefaultFontId(); int32_t fontId = ewol::GetDefaultFontId();
int32_t letterWidth = ewol::GetWidth(fontId, "9"); int32_t letterWidth = ewol::GetWidth(fontId, "9");
int32_t letterHeight = ewol::GetHeight(fontId); int32_t letterHeight = ewol::GetHeight(fontId);
int32_t lineOffset = height / letterHeight; int32_t lineOffset = height / letterHeight;
y = m_displayStartLineId + lineOffset;
//******************************* get the X position : ******************************************* //******************************* get the X position : *******************************************
@ -479,12 +474,11 @@ void BufferText::GetMousePosition(int32_t width, int32_t height, int32_t &x, int
memset(displayChar, 0, sizeof(uniChar_t)*MAX_EXP_CHAR_LEN); memset(displayChar, 0, sizeof(uniChar_t)*MAX_EXP_CHAR_LEN);
int32_t pixelX = x_base; int32_t pixelX = x_base;
if (width <= pixelX) {
x = 0;
EDN_DEBUG(" Element : Befor the start of the line ... ==> END");
return;
}
int32_t startLinePosition = m_EdnBuf.CountForwardNLines(m_displayStartBufferPos, lineOffset); int32_t startLinePosition = m_EdnBuf.CountForwardNLines(m_displayStartBufferPos, lineOffset);
if (width <= pixelX) {
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("Get id element : x=" << width << "px y=" << height << "px");
EDN_DEBUG(" line offset = " << lineOffset); EDN_DEBUG(" line offset = " << lineOffset);
for (iii=startLinePosition; iii<mylen; iii = new_i) { for (iii=startLinePosition; iii<mylen; iii = new_i) {
@ -508,8 +502,8 @@ void BufferText::GetMousePosition(int32_t width, int32_t height, int32_t &x, int
} }
idX += displaywidth; idX += displaywidth;
} }
x = iii-startLinePosition; EDN_DEBUG("BufferText::GetMousePosition(" << width << "," << height << "); ==> " << iii );
EDN_DEBUG("BufferText::GetMousePosition(" << width << "," << height << "); ==> (" << x << "," << y << ")" ); return iii;
} }
@ -527,20 +521,15 @@ void BufferText::MouseEvent(int32_t width, int32_t height)
if (true == ewol::IsSetShift() ) { if (true == ewol::IsSetShift() ) {
MouseSelectFromCursorTo(width, height); MouseSelectFromCursorTo(width, height);
} else { } else {
int32_t posX, posY;
// Get the caracter mouse position // Get the caracter mouse position
GetMousePosition(width, height, posX, posY); int32_t newPos = GetMousePosition(width, height);
// find the current selected line :
int32_t newPos = m_EdnBuf.CountForwardNLines(0, posY);
// Get the display char position
newPos = m_EdnBuf.CountForwardDispChars(newPos, posX);
// move the cursor // move the cursor
SetInsertPosition(newPos); SetInsertPosition(newPos);
// if a preferred column wasn't aleady established, establish it // if a preferred column wasn't aleady established, establish it
if (m_cursorPreferredCol < 0) { /*if (m_cursorPreferredCol < 0) {
m_cursorPreferredCol = posX; m_cursorPreferredCol = posX;
} }*/
m_EdnBuf.Unselect(SELECTION_PRIMARY); m_EdnBuf.Unselect(SELECTION_PRIMARY);
ForceReDraw(true); ForceReDraw(true);
@ -561,28 +550,21 @@ void BufferText::MouseEvent(int32_t width, int32_t height)
// TODO : Simplify selection .... // TODO : Simplify selection ....
void BufferText::MouseSelectFromCursorTo(int32_t width, int32_t height) void BufferText::MouseSelectFromCursorTo(int32_t width, int32_t height)
{ {
int32_t posX, posY;
// Get the caracter mouse position // Get the caracter mouse position
GetMousePosition(width, height, posX, posY); int32_t newPos = GetMousePosition(width, height);
int32_t selStart, selEnd, selRectStart, selRectEnd; int32_t selStart, selEnd, selRectStart, selRectEnd;
bool selIsRect; bool selIsRect;
int32_t selHave = m_EdnBuf.GetSelectionPos(SELECTION_PRIMARY, selStart, selEnd, selIsRect, selRectStart, selRectEnd); int32_t selHave = m_EdnBuf.GetSelectionPos(SELECTION_PRIMARY, selStart, selEnd, selIsRect, selRectStart, selRectEnd);
//EDN_DEBUG("BufferText:: " << selHave << " = BufGetSelectionPos(SELECTION_PRIMARY," << selStart << "," << selEnd << "," << selIsRect << "," << selRectStart << "," << selRectEnd << ");" ); //EDN_DEBUG("BufferText:: " << selHave << " = BufGetSelectionPos(SELECTION_PRIMARY," << selStart << "," << selEnd << "," << selIsRect << "," << selRectStart << "," << selRectEnd << ");" );
int32_t rememberCursorPos = m_cursorPos; int32_t rememberCursorPos = m_cursorPos;
// find the current selected line :
int32_t newPos = m_EdnBuf.CountForwardNLines(0, posY);
// Get the display char position
newPos = m_EdnBuf.CountForwardDispChars(newPos, posX);
// move the cursor // move the cursor
SetInsertPosition(newPos); SetInsertPosition(newPos);
// if a preferred column wasn't aleady established, establish it // if a preferred column wasn't aleady established, establish it
if (m_cursorPreferredCol < 0) { /*if (m_cursorPreferredCol < 0) {
m_cursorPreferredCol = posX; m_cursorPreferredCol = posX;
} }*/
if (false == selHave) { if (false == selHave) {
m_EdnBuf.Select(SELECTION_PRIMARY, rememberCursorPos, m_cursorPos); m_EdnBuf.Select(SELECTION_PRIMARY, rememberCursorPos, m_cursorPos);

View File

@ -112,7 +112,7 @@ class BufferText : public Buffer {
bool TextDMoveDown(int32_t offset); bool TextDMoveDown(int32_t offset);
void SetInsertPosition(int32_t newPosition, bool insertChar = false); void SetInsertPosition(int32_t newPosition, bool insertChar = false);
void GetMousePosition(int32_t width, int32_t height, int32_t &x, int32_t &y); int32_t GetMousePosition(int32_t width, int32_t height);
void MoveUpDown(int32_t ofset); void MoveUpDown(int32_t ofset);
void DrawLineNumber(ewol::OObject2DTextColored* OOText, ewol::OObject2DColored* OOColored, int32_t sizeX, int32_t sizeY,char *myPrint, int32_t lineNumber, int32_t positionY); void DrawLineNumber(ewol::OObject2DTextColored* OOText, ewol::OObject2DColored* OOColored, int32_t sizeX, int32_t sizeY,char *myPrint, int32_t lineNumber, int32_t positionY);