[DEV] first display of the cursor
This commit is contained in:
parent
40bf24a095
commit
19d3750f01
@ -10,6 +10,11 @@
|
|||||||
#include <appl/Buffer/Buffer.h>
|
#include <appl/Buffer/Buffer.h>
|
||||||
#include <appl/Debug.h>
|
#include <appl/Debug.h>
|
||||||
|
|
||||||
|
appl::Buffer::Buffer(void) :
|
||||||
|
m_cursorPos(3)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
bool appl::Buffer::LoadFile(const etk::UString& _name)
|
bool appl::Buffer::LoadFile(const etk::UString& _name)
|
||||||
{
|
{
|
||||||
@ -31,3 +36,39 @@ void appl::Buffer::SetFileName(const etk::UString& _name)
|
|||||||
// TODO : ...
|
// TODO : ...
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool appl::Buffer::OnEventEntry(const ewol::EventEntry& _event)
|
||||||
|
{
|
||||||
|
APPL_DEBUG(" event : " << _event);
|
||||||
|
if (_event.GetType() == ewol::keyEvent::keyboardChar) {
|
||||||
|
//APPL_DEBUG("KB EVENT : \"" << UTF8_data << "\" size=" << strlen(UTF8_data) << "type=" << (int32_t)typeEvent);
|
||||||
|
if (_event.GetStatus() != ewol::keyEvent::statusDown) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (_event.GetChar() == etk::UniChar::Tabulation) {
|
||||||
|
m_data.Insert(m_cursorPos, '\t');
|
||||||
|
} else if (_event.GetChar() == etk::UniChar::Return) {
|
||||||
|
m_data.Insert(m_cursorPos, '\n');
|
||||||
|
} else if (_event.GetChar() == etk::UniChar::Backspace ) {
|
||||||
|
APPL_INFO("keyEvent : <suppr> pos=" << m_cursorPos);
|
||||||
|
} else if (_event.GetChar() == etk::UniChar::Delete) {
|
||||||
|
APPL_INFO("keyEvent : <del> pos=" << m_cursorPos);
|
||||||
|
} else {
|
||||||
|
// normal adding char ...
|
||||||
|
char output[5];
|
||||||
|
int32_t nbElement = _event.GetChar().GetUtf8(output);
|
||||||
|
etk::Vector<int8_t> values;
|
||||||
|
for (int32_t iii=0; iii<nbElement; ++iii) {
|
||||||
|
values.PushBack(output[iii]);
|
||||||
|
}
|
||||||
|
m_data.Insert(m_cursorPos, values);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
// move events ...
|
||||||
|
if (_event.GetStatus() == ewol::keyEvent::statusDown) {
|
||||||
|
//m_buffer->CursorMove(_event.GetType());
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
@ -15,13 +15,14 @@
|
|||||||
#include <ewol/ewol.h>
|
#include <ewol/ewol.h>
|
||||||
#include <etk/Buffer.h>
|
#include <etk/Buffer.h>
|
||||||
#include <ewol/renderer/EObject.h>
|
#include <ewol/renderer/EObject.h>
|
||||||
|
#include <ewol/widget/Widget.h>
|
||||||
|
|
||||||
namespace appl
|
namespace appl
|
||||||
{
|
{
|
||||||
class Buffer : public ewol::EObject
|
class Buffer : public ewol::EObject
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Buffer(void) { };
|
Buffer(void);
|
||||||
~Buffer(void) { };
|
~Buffer(void) { };
|
||||||
private:
|
private:
|
||||||
etk::UString m_fileName; //!< name of the file (with his path)
|
etk::UString m_fileName; //!< name of the file (with his path)
|
||||||
@ -42,6 +43,9 @@ namespace appl
|
|||||||
ejson::Value* m_property;
|
ejson::Value* m_property;
|
||||||
appl::Selection m_selection;
|
appl::Selection m_selection;
|
||||||
*/
|
*/
|
||||||
|
public:
|
||||||
|
esize_t m_cursorPos; //!< cursor position.
|
||||||
|
bool OnEventEntry(const ewol::EventEntry& _event);
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -24,7 +24,8 @@
|
|||||||
|
|
||||||
appl::TextViewer::TextViewer(const etk::UString& _fontName, int32_t _fontSize) :
|
appl::TextViewer::TextViewer(const etk::UString& _fontName, int32_t _fontSize) :
|
||||||
m_buffer(NULL),
|
m_buffer(NULL),
|
||||||
m_displayText(_fontName, _fontSize)
|
m_displayText(_fontName, _fontSize),
|
||||||
|
m_insertMode(false)
|
||||||
{
|
{
|
||||||
SetCanHaveFocus(true);
|
SetCanHaveFocus(true);
|
||||||
RegisterMultiCast(ednMsgBufferId);
|
RegisterMultiCast(ednMsgBufferId);
|
||||||
@ -87,31 +88,83 @@ void appl::TextViewer::OnDraw(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
esize_t appl::TextViewer::Get(esize_t _pos, UniChar& _value, charset_te _charset) const
|
esize_t appl::TextViewer::Get(esize_t _pos, etk::UniChar& _value, unicode::charset_te _charset) const
|
||||||
{
|
{
|
||||||
_value = '\0';
|
_value = '\0';
|
||||||
if (_charset == unicode::EDN_CHARSET_UTF8) {
|
if (_charset == unicode::EDN_CHARSET_UTF8) {
|
||||||
char tmpVal[8];
|
char tmpVal[5];
|
||||||
tmpVal[0] = m_buffer[_pos];
|
tmpVal[0] = m_buffer->GetData()[_pos];
|
||||||
tmpVal[1] = m_buffer[_pos+1];
|
tmpVal[1] = m_buffer->GetData()[_pos+1];
|
||||||
tmpVal[2] = m_buffer[_pos+2];
|
tmpVal[2] = m_buffer->GetData()[_pos+2];
|
||||||
tmpVal[3] = m_buffer[_pos+3];
|
tmpVal[3] = m_buffer->GetData()[_pos+3];
|
||||||
tmpVal[4] = m_buffer[_pos+4];
|
tmpVal[4] = '\0';
|
||||||
tmpVal[5] = m_buffer[_pos+5];
|
|
||||||
tmpVal[6] = m_buffer[_pos+6];
|
|
||||||
tmpVal[7] = '\0';
|
|
||||||
// transform ...
|
// transform ...
|
||||||
|
int32_t nbElement = _value.SetUtf8(tmpVal);
|
||||||
|
return nbElement;
|
||||||
}
|
}
|
||||||
// TODO :: need to trancode iso ==> UNICODE ...
|
// TODO :: need to trancode iso ==> UNICODE ...
|
||||||
_value = m_buffer[_pos];
|
_value.Set(m_buffer->GetData()[_pos]);
|
||||||
return _pos+1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static const char *ControlCodeTable[32] = {
|
||||||
|
"NUL", "soh", "stx", "etx", "eot", "enq", "ack", "bel", "bs", "ht", "nl", "vt", "np", "cr", "so", "si",
|
||||||
|
"dle", "dc1", "dc2", "dc3", "dc4", "nak", "syn", "etb", "can", "em", "sub", "esc", "fs", "gs", "rs", "us"};
|
||||||
|
|
||||||
|
void appl::TextViewer::Expand(esize_t& _indent, const etk::UniChar& _value, etk::UString& _out) const
|
||||||
|
{
|
||||||
|
_out.Clear();
|
||||||
|
int32_t tabDist = 4;
|
||||||
|
if (_value == etk::UniChar::Tabulation) {
|
||||||
|
int32_t nSpaces = tabDist - (_indent % tabDist);
|
||||||
|
for (int32_t iii=0; iii<nSpaces; iii++) {
|
||||||
|
_out.Append(etk::UniChar::Space);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// Convert ASCII control codes to readable character sequences
|
||||||
|
if (_value == etk::UniChar::Null) {
|
||||||
|
_out.Append(etk::UniChar('<'));
|
||||||
|
_out.Append(etk::UniChar('n'));
|
||||||
|
_out.Append(etk::UniChar('u'));
|
||||||
|
_out.Append(etk::UniChar('l'));
|
||||||
|
_out.Append(etk::UniChar('>'));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (_value == etk::UniChar::Return) {
|
||||||
|
// nothing to display...
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (_value.Get() <= 31) {
|
||||||
|
_out.Append(etk::UniChar('<'));
|
||||||
|
const char * tmp = ControlCodeTable[_value.Get()];
|
||||||
|
while (*tmp!='\0') {
|
||||||
|
_out.Append(etk::UniChar(*tmp));
|
||||||
|
tmp++;
|
||||||
|
}
|
||||||
|
_out.Append(etk::UniChar('>'));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (_value == etk::UniChar::Delete) {
|
||||||
|
_out.Append(etk::UniChar('<'));
|
||||||
|
_out.Append(etk::UniChar('d'));
|
||||||
|
_out.Append(etk::UniChar('e'));
|
||||||
|
_out.Append(etk::UniChar('l'));
|
||||||
|
_out.Append(etk::UniChar('>'));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// nothing to do ...
|
||||||
|
_out.Append(_value);
|
||||||
|
//APPL_DEBUG("plop : " << _out);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void appl::TextViewer::OnRegenerateDisplay(void)
|
void appl::TextViewer::OnRegenerateDisplay(void)
|
||||||
{
|
{
|
||||||
if (true == NeedRedraw()) {
|
if (false == NeedRedraw()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
// For the scrooling windows
|
// For the scrooling windows
|
||||||
CalculateMaxSize();
|
CalculateMaxSize();
|
||||||
m_displayDrawing.Clear();
|
m_displayDrawing.Clear();
|
||||||
@ -141,55 +194,87 @@ void appl::TextViewer::OnRegenerateDisplay(void)
|
|||||||
m_displayText.SetPos(vec3(0.0f, m_size.y(), 0.0f) );
|
m_displayText.SetPos(vec3(0.0f, m_size.y(), 0.0f) );
|
||||||
m_displayText.ForceLineReturn();
|
m_displayText.ForceLineReturn();
|
||||||
m_displayText.PrintDecorated(tmpString);
|
m_displayText.PrintDecorated(tmpString);
|
||||||
} else {
|
// call the herited class...
|
||||||
|
WidgetScrooled::OnRegenerateDisplay();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// normal displa of the buffer :
|
||||||
|
vec3 tmpCursorPosition(0, 0, -1);
|
||||||
// real display ...
|
// real display ...
|
||||||
etk::Buffer& buf = m_buffer->GetData();
|
etk::Buffer& buf = m_buffer->GetData();
|
||||||
m_displayText.SetColor(etk::Color<>(0, 0, 0, 256));
|
m_displayText.SetColor(etk::Color<>(0, 0, 0, 256));
|
||||||
float countNbLine = 1;
|
float countNbLine = 1;
|
||||||
float countColomn = 0;
|
esize_t countColomn = 0;
|
||||||
vec3 tmpLetterSize = m_displayText.CalculateSize((uniChar_t)'A');
|
vec3 tmpLetterSize = m_displayText.CalculateSize((uniChar_t)'A');
|
||||||
|
vec3 positionCurentDisplay(0.0f, m_size.y()-tmpLetterSize.y(), 0.0f);
|
||||||
for (int32_t iii=0; iii<buf.Size(); ++iii) {
|
m_displayText.SetPos(positionCurentDisplay);
|
||||||
char c = buf.Get(iii);
|
// the siplay string :
|
||||||
etk::UniChar myChar(c);
|
etk::UString stringToDisplay;
|
||||||
if (myChar == etk::UniChar('\n')) {
|
esize_t bufferElementSize = 0;
|
||||||
|
etk::UniChar currentValue;
|
||||||
|
for (int32_t iii=0; iii<buf.Size(); iii+=bufferElementSize) {
|
||||||
|
if (iii==m_buffer->m_cursorPos) {
|
||||||
|
// need to display the cursor :
|
||||||
|
tmpCursorPosition = positionCurentDisplay;
|
||||||
|
}
|
||||||
|
bufferElementSize = Get(iii, currentValue, unicode::EDN_CHARSET_UTF8);
|
||||||
|
//APPL_DEBUG(" element size : " << iii << " : " << bufferElementSize);
|
||||||
|
if (currentValue == etk::UniChar::Return) {
|
||||||
countNbLine += 1;
|
countNbLine += 1;
|
||||||
countColomn = 0;
|
countColomn = 0;
|
||||||
|
if (bufferElementSize ==0) {
|
||||||
|
bufferElementSize = 1;
|
||||||
|
}
|
||||||
|
positionCurentDisplay.setX(0);
|
||||||
|
positionCurentDisplay.setY(positionCurentDisplay.y()-tmpLetterSize.y());
|
||||||
|
m_displayText.SetPos(positionCurentDisplay);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
countColomn += 1;
|
appl::TextViewer::Expand(countColomn, currentValue, stringToDisplay);
|
||||||
m_displayText.SetPos(vec3(countColomn*tmpLetterSize.x(),
|
//m_displayText.SetPos(positionCurentDisplay);
|
||||||
m_size.y() - countNbLine*tmpLetterSize.y(),
|
for (esize_t kkk=0; kkk<stringToDisplay.Size(); ++kkk) {
|
||||||
0.0f) );
|
m_displayText.Print(stringToDisplay[kkk]);
|
||||||
m_displayText.Print(myChar);
|
|
||||||
//tmpLetterSize.x();
|
|
||||||
}
|
}
|
||||||
|
positionCurentDisplay.setX(positionCurentDisplay.x()+tmpLetterSize.x()*(float)stringToDisplay.Size());
|
||||||
|
countColomn += stringToDisplay.Size();
|
||||||
|
|
||||||
|
if (bufferElementSize ==0) {
|
||||||
|
bufferElementSize = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (tmpCursorPosition.z()!=-1) {
|
||||||
|
// display the cursor:
|
||||||
|
APPL_DEBUG("display cursor at position : " << tmpCursorPosition);
|
||||||
|
m_displayText.SetPos(tmpCursorPosition);
|
||||||
|
m_displayText.SetColor(etk::Color<>(0xFF0000FF));
|
||||||
|
m_displayText.SetColorBg(etk::Color<>(0xFF0000FF));
|
||||||
|
m_displayText.PrintCursor(m_insertMode);
|
||||||
}
|
}
|
||||||
// call the herited class...
|
// call the herited class...
|
||||||
WidgetScrooled::OnRegenerateDisplay();
|
WidgetScrooled::OnRegenerateDisplay();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool appl::TextViewer::OnEventEntry(const ewol::EventEntry& _event)
|
bool appl::TextViewer::OnEventEntry(const ewol::EventEntry& _event)
|
||||||
{
|
{
|
||||||
if (_event.GetType() == ewol::keyEvent::keyboardChar) {
|
if (m_buffer == NULL) {
|
||||||
//APPL_DEBUG("KB EVENT : \"" << UTF8_data << "\" size=" << strlen(UTF8_data) << "type=" << (int32_t)typeEvent);
|
return false;
|
||||||
if (_event.GetStatus() == ewol::keyEvent::statusDown) {
|
|
||||||
if (m_buffer != NULL) {
|
|
||||||
//tmpBuffer->AddChar(_event.GetChar());
|
|
||||||
}
|
}
|
||||||
|
if (m_buffer->OnEventEntry(_event) == true) {
|
||||||
MarkToRedraw();
|
MarkToRedraw();
|
||||||
}
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
// move events ...
|
return false;
|
||||||
if (_event.GetStatus() == ewol::keyEvent::statusDown) {
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool appl::TextViewer::OnEventInput(const ewol::EventInput& _event)
|
||||||
|
{
|
||||||
|
vec2 relativePos = RelativePosition(_event.GetPos());
|
||||||
if (m_buffer != NULL) {
|
if (m_buffer != NULL) {
|
||||||
//tmpBuffer->cursorMove(_event.GetType());
|
|
||||||
}
|
|
||||||
MarkToRedraw();
|
|
||||||
}
|
}
|
||||||
|
GetFocus();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -201,15 +286,6 @@ void appl::TextViewer::OnEventClipboard(ewol::clipBoard::clipboardListe_te _clip
|
|||||||
MarkToRedraw();
|
MarkToRedraw();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool appl::TextViewer::OnEventInput(const ewol::EventInput& _event)
|
|
||||||
{
|
|
||||||
vec2 relativePos = RelativePosition(_event.GetPos());
|
|
||||||
if (m_buffer != NULL) {
|
|
||||||
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void appl::TextViewer::OnReceiveMessage(const ewol::EMessage& _msg)
|
void appl::TextViewer::OnReceiveMessage(const ewol::EMessage& _msg)
|
||||||
{
|
{
|
||||||
// Force redraw of the widget
|
// Force redraw of the widget
|
||||||
|
@ -26,10 +26,9 @@ namespace appl
|
|||||||
TextViewer(const etk::UString& _fontName="", int32_t _fontSize=-1);
|
TextViewer(const etk::UString& _fontName="", int32_t _fontSize=-1);
|
||||||
virtual ~TextViewer(void);
|
virtual ~TextViewer(void);
|
||||||
private:
|
private:
|
||||||
appl::Buffer* m_buffer;
|
appl::Buffer* m_buffer; //!< pointer on the current buffer to display (can be null if the buffer is remover or in state of changing buffer)
|
||||||
// drawing elements :
|
ewol::Text m_displayText; //!< Text display properties.
|
||||||
ewol::Text m_displayText;
|
ewol::Drawing m_displayDrawing; //!< Other diaplay requested.
|
||||||
ewol::Drawing m_displayDrawing;
|
|
||||||
public:
|
public:
|
||||||
void SetFontSize(int32_t _size);
|
void SetFontSize(int32_t _size);
|
||||||
void SetFontName(const etk::UString& _fontName);
|
void SetFontName(const etk::UString& _fontName);
|
||||||
@ -47,6 +46,24 @@ namespace appl
|
|||||||
virtual void OnEventClipboard(ewol::clipBoard::clipboardListe_te clipboardID);
|
virtual void OnEventClipboard(ewol::clipBoard::clipboardListe_te clipboardID);
|
||||||
virtual void OnGetFocus(void);
|
virtual void OnGetFocus(void);
|
||||||
virtual void OnLostFocus(void);
|
virtual void OnLostFocus(void);
|
||||||
|
private:
|
||||||
|
/**
|
||||||
|
* @brief Get the next element in the buffer.
|
||||||
|
* @param[in] _pos Position in the buffer
|
||||||
|
* @param[out] _value Unicode value read in the buffer
|
||||||
|
* @param[in] _charset Charset used to parse the current buffer
|
||||||
|
* @return number ofelement read in the buffer (to increment the position)
|
||||||
|
*/
|
||||||
|
esize_t Get(esize_t _pos, etk::UniChar& _value, unicode::charset_te _charset) const;
|
||||||
|
/**
|
||||||
|
* @brief Expand the specify char to have a user frendly display for special char and tabs
|
||||||
|
* @param[in] _indent Curent indentation in the line
|
||||||
|
* @param[in] _value Current value to transform
|
||||||
|
* @param[out] _out String that represent the curent value to display
|
||||||
|
*/
|
||||||
|
void Expand(esize_t& _indent, const etk::UniChar& _value, etk::UString& _out) const;
|
||||||
|
private:
|
||||||
|
bool m_insertMode; //!< the insert mode is enable
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user