Unfinished Input box.
This was SVN commit r1394.
This commit is contained in:
parent
30ad195c0b
commit
0adc8f6ca2
@ -15,6 +15,9 @@ gee@pyro.nu
|
||||
#include "OverlayText.h"
|
||||
#include "lib/res/unifont.h"
|
||||
|
||||
#include "ps/CLogger.h"
|
||||
#define LOG_CATEGORY "gui"
|
||||
|
||||
using namespace std;
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
@ -41,6 +44,8 @@ CInput::CInput() : m_iBufferPos(0)
|
||||
bar->SetRightAligned(true);
|
||||
bar->SetUseEdgeButtons(true);
|
||||
AddScrollBar(bar);
|
||||
|
||||
UpdateText(); // will create an empty row, just so we have somewhere to position the insertion marker
|
||||
}
|
||||
|
||||
CInput::~CInput()
|
||||
@ -61,12 +66,18 @@ int CInput::ManuallyHandleEvent(const SDL_Event* ev)
|
||||
|
||||
switch (szChar){
|
||||
//TODOcase '\r':
|
||||
case '\n':
|
||||
/* case '\n':
|
||||
// TODO Gee: (2004-09-07) New line? I should just add '\n'
|
||||
*pCaption += wchar_t('\n');
|
||||
++m_iBufferPos;
|
||||
break;
|
||||
|
||||
*/
|
||||
/* case '\r':
|
||||
// TODO Gee: (2004-09-07) New line? I should just add '\n'
|
||||
*pCaption += wchar_t('\n');
|
||||
++m_iBufferPos;
|
||||
break;
|
||||
*/
|
||||
case '\t':
|
||||
/* Auto Complete */
|
||||
// TODO Gee: (2004-09-07) What to do with tab?
|
||||
@ -84,6 +95,8 @@ int CInput::ManuallyHandleEvent(const SDL_Event* ev)
|
||||
*pCaption = pCaption->Left( m_iBufferPos-1 ) +
|
||||
pCaption->Right( (long) pCaption->Length()-m_iBufferPos );
|
||||
|
||||
UpdateText(m_iBufferPos-1, m_iBufferPos, m_iBufferPos-1);
|
||||
|
||||
--m_iBufferPos;
|
||||
break;
|
||||
|
||||
@ -95,6 +108,7 @@ int CInput::ManuallyHandleEvent(const SDL_Event* ev)
|
||||
*pCaption = pCaption->Left( m_iBufferPos ) +
|
||||
pCaption->Right( (long) pCaption->Length()-(m_iBufferPos+1) );
|
||||
|
||||
UpdateText(m_iBufferPos, m_iBufferPos+1, m_iBufferPos);
|
||||
break;
|
||||
|
||||
case SDLK_HOME:
|
||||
@ -115,7 +129,6 @@ int CInput::ManuallyHandleEvent(const SDL_Event* ev)
|
||||
++m_iBufferPos;
|
||||
break;
|
||||
|
||||
/* BEGIN: Buffer History Lookup */
|
||||
case SDLK_UP:
|
||||
/*if (m_deqBufHistory.size() && iHistoryPos != (int)m_deqBufHistory.size() - 1)
|
||||
{
|
||||
@ -131,9 +144,7 @@ int CInput::ManuallyHandleEvent(const SDL_Event* ev)
|
||||
SetBuffer(m_deqBufHistory.at(iHistoryPos).data());
|
||||
else FlushBuffer();*/
|
||||
break;
|
||||
/* END: Buffer History Lookup */
|
||||
|
||||
/* BEGIN: Message History Lookup */
|
||||
case SDLK_PAGEUP:
|
||||
//if (m_iMsgHistPos != (int)m_deqMsgHistory.size()) m_iMsgHistPos++;
|
||||
break;
|
||||
@ -143,6 +154,10 @@ int CInput::ManuallyHandleEvent(const SDL_Event* ev)
|
||||
break;
|
||||
/* END: Message History Lookup */
|
||||
|
||||
case '\r':
|
||||
cooked = '\n'; // Change to '\n' and do default:
|
||||
// NOTE: Fall-through
|
||||
|
||||
default: //Insert a character
|
||||
if (cooked == 0)
|
||||
return EV_PASS; // Important, because we didn't use any key
|
||||
@ -153,10 +168,20 @@ int CInput::ManuallyHandleEvent(const SDL_Event* ev)
|
||||
*pCaption = pCaption->Left(m_iBufferPos) + CStrW(cooked) +
|
||||
pCaption->Right((long) pCaption->Length()-m_iBufferPos);
|
||||
|
||||
UpdateText(m_iBufferPos, m_iBufferPos, m_iBufferPos+1);
|
||||
|
||||
++m_iBufferPos;
|
||||
|
||||
// TODO
|
||||
//UpdateText(m_iBufferPos, m_iBufferPos, m_iBufferPos+4);
|
||||
|
||||
//m_iBufferPos+=4;
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
//UpdateText();
|
||||
|
||||
return EV_HANDLED;
|
||||
}
|
||||
|
||||
@ -193,12 +218,86 @@ void CInput::HandleMessage(const SGUIMessage &Message)
|
||||
GetScrollBar(0).SetScrollBarStyle( scrollbar_style );
|
||||
}
|
||||
|
||||
if (Message.value == CStr("caption"))
|
||||
{
|
||||
UpdateText();
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case GUIM_MOUSE_PRESS_LEFT:
|
||||
// SetFocus();
|
||||
//m_iBufferPos = 0;
|
||||
// Okay, this section is about pressing the mouse and
|
||||
// choosing where the point should be placed. For
|
||||
// instance, if we press between a and b, the point
|
||||
// should of course be placed accordingly. Other
|
||||
// special cases are handled like the input box norms.
|
||||
{
|
||||
|
||||
CPos mouse = GetMousePos();
|
||||
|
||||
// Pointer to caption, will come in handy
|
||||
CStrW *pCaption = (CStrW*)m_Settings["caption"].m_pSetting;
|
||||
|
||||
// Now get the height of the font.
|
||||
CFont *font=NULL;
|
||||
font = new CFont("Console");
|
||||
float spacing = font->GetLineSpacing();
|
||||
float height = font->GetHeight();
|
||||
|
||||
// Change mouse position relative to text.
|
||||
// Include scrolling.
|
||||
mouse -= m_CachedActualSize.TopLeft();
|
||||
|
||||
//if ((m_CharacterPositions.size()-1) * spacing + height < mouse.y)
|
||||
// m_iBufferPos = pCaption->Length();
|
||||
int row = (int)(mouse.y / spacing);//m_CharachterPositions.size()
|
||||
|
||||
if (row > m_CharacterPositions.size()-1)
|
||||
row = m_CharacterPositions.size()-1;
|
||||
|
||||
// TODO Gee (2004-11-21): Okay, I need a 'list' for some reasons, but I would really
|
||||
// be able to get the specific element here. This is hopefully a temporary hack.
|
||||
|
||||
list<SRow>::iterator current = m_CharacterPositions.begin();
|
||||
for (int i=0; i<row; ++i)
|
||||
++current;
|
||||
|
||||
//m_iBufferPos = m_CharacterPositions.get.m_ListStart;
|
||||
m_iBufferPos = current->m_ListStart;
|
||||
|
||||
// Okay, no loop through the glyphs to find the appropriate X position
|
||||
float previous=0.f;
|
||||
int i=0;
|
||||
for (vector<float>::iterator it=current->m_ListOfX.begin();
|
||||
it!=current->m_ListOfX.end();
|
||||
++it, ++i)
|
||||
{
|
||||
if (*it >= mouse.x)
|
||||
{
|
||||
if (i != 0)
|
||||
{
|
||||
if (mouse.x - previous > *it - mouse.x)
|
||||
m_iBufferPos += i+1;
|
||||
else
|
||||
m_iBufferPos += i;
|
||||
}
|
||||
// else let the value be current->m_ListStart which it already is.
|
||||
|
||||
// check if the previous or the current is closest.
|
||||
break;
|
||||
}
|
||||
previous = *it;
|
||||
}
|
||||
// If a position wasn't found, we will assume the last
|
||||
// character of that line.
|
||||
if (i == current->m_ListOfX.size())
|
||||
m_iBufferPos += i;
|
||||
|
||||
// clean up
|
||||
delete font;
|
||||
|
||||
break;
|
||||
}
|
||||
case GUIM_MOUSE_WHEEL_DOWN:
|
||||
GetScrollBar(0).ScrollMinus();
|
||||
// Since the scroll was changed, let's simulate a mouse movement
|
||||
@ -280,6 +379,7 @@ void CInput::Draw()
|
||||
|
||||
// Get the height of this font.
|
||||
float h = (float)font->GetHeight();
|
||||
float ls = (float)font->GetLineSpacing();
|
||||
|
||||
glTranslatef((GLfloat)int(m_CachedActualSize.left), (GLfloat)int(m_CachedActualSize.top+h), bz);
|
||||
glColor4f(1.f, 1.f, 1.f, 1.f);
|
||||
@ -287,20 +387,40 @@ void CInput::Draw()
|
||||
// U+FE33: PRESENTATION FORM FOR VERTICAL LOW LINE
|
||||
// (sort of like a | which is aligned to the left of most characters)
|
||||
|
||||
for (size_t i=0; i<caption.Length(); ++i)
|
||||
float buffered_y=0.f;
|
||||
|
||||
for (list<SRow>::const_iterator it = m_CharacterPositions.begin();
|
||||
it != m_CharacterPositions.end();
|
||||
++it)
|
||||
{
|
||||
if (m_iBufferPos == i)
|
||||
if (buffered_y > m_CachedActualSize.GetHeight())
|
||||
break;
|
||||
|
||||
glPushMatrix();
|
||||
// We might as well use 'i' here, because we need it
|
||||
for (int i=0; i < it->m_ListOfX.size(); ++i)
|
||||
{
|
||||
glPushMatrix();
|
||||
glwprintf(L"%lc", 0xFE33);
|
||||
glPopMatrix();
|
||||
if (it->m_ListStart + i == m_iBufferPos)
|
||||
{
|
||||
glPushMatrix();
|
||||
glwprintf(L"%lc", 0xFE33);
|
||||
glPopMatrix();
|
||||
}
|
||||
|
||||
glwprintf(L"%lc", caption[it->m_ListStart + i]);
|
||||
}
|
||||
|
||||
glwprintf(L"%lc", caption[(int)i]);
|
||||
}
|
||||
if (it->m_ListStart + it->m_ListOfX.size() == m_iBufferPos)
|
||||
{
|
||||
glwprintf(L"%lc", 0xFE33);
|
||||
}
|
||||
|
||||
if (m_iBufferPos == caption.Length())
|
||||
glwprintf(L"%lc", 0xFE33);
|
||||
glPopMatrix();
|
||||
glTranslatef(0.f, ls, 0.f);
|
||||
|
||||
buffered_y += ls;
|
||||
|
||||
}
|
||||
|
||||
glPopMatrix();
|
||||
|
||||
@ -309,3 +429,413 @@ void CInput::Draw()
|
||||
delete font;
|
||||
}
|
||||
}
|
||||
|
||||
void CInput::UpdateText(int from, int to_before, int to_after)
|
||||
{
|
||||
CStrW caption;
|
||||
GUI<CStrW>::GetSetting(this, "caption", caption);
|
||||
|
||||
SRow row;
|
||||
row.m_ListStart = 0;
|
||||
|
||||
int to;
|
||||
|
||||
if (to_before == -1)
|
||||
to = caption.Length();
|
||||
|
||||
CFont *font=NULL;
|
||||
font = new CFont("Console");
|
||||
|
||||
|
||||
//LOG(ERROR, LOG_CATEGORY, "Point 1 %d %d", to_before, to_after);
|
||||
|
||||
list<SRow>::iterator current_line;
|
||||
|
||||
// Used to ... TODO
|
||||
int check_point_row_start = -1;
|
||||
int check_point_row_end = -1;
|
||||
|
||||
// Reset
|
||||
if (from == 0 && to_before == -1)
|
||||
{
|
||||
m_CharacterPositions.clear();
|
||||
current_line = m_CharacterPositions.begin();
|
||||
}
|
||||
else
|
||||
{
|
||||
assert(to_before != -1);
|
||||
|
||||
//LOG(ERROR, LOG_CATEGORY, "Point 2 - %d %d", from, to_before);
|
||||
|
||||
list<SRow>::iterator destroy_row_from, destroy_row_to;
|
||||
|
||||
// Iterate, and remove everything between 'from' and 'to_before'
|
||||
// actually remove the entire lines they are on, it'll all have
|
||||
// to be redone. And when going along, we'll delete a row at a time
|
||||
// when continuing to see how much more after 'to' we need to remake.
|
||||
int i=0;
|
||||
for (list<SRow>::iterator it=m_CharacterPositions.begin();
|
||||
it!=m_CharacterPositions.end(); ++it, ++i)
|
||||
{
|
||||
if (destroy_row_from == list<SRow>::iterator() &&
|
||||
it->m_ListStart > from)
|
||||
{
|
||||
// Destroy the previous line, and all to 'to_before'
|
||||
//if (i >= 2)
|
||||
// destroy_row_from = it-2;
|
||||
//else
|
||||
// destroy_row_from = it-1;
|
||||
destroy_row_from = it;
|
||||
--destroy_row_from;
|
||||
|
||||
// For the rare case that we might remove characters to a word
|
||||
// so that it should go on the previous line, we need to
|
||||
// by standards re-do the whole previous line too (if one
|
||||
// exists)
|
||||
if (destroy_row_from != m_CharacterPositions.begin())
|
||||
--destroy_row_from;
|
||||
}
|
||||
|
||||
if (destroy_row_to == list<SRow>::iterator() &&
|
||||
it->m_ListStart > to_before)
|
||||
{
|
||||
destroy_row_to = it;
|
||||
|
||||
// If it isn't the last row, we'll add another row to delete,
|
||||
// just so we can see if the last restorted line is
|
||||
// identical to what it was before. If it isn't, then we'll
|
||||
// have to continue.
|
||||
// 'check_point_row_start' is where we store how the that
|
||||
// line looked.
|
||||
if (destroy_row_to != m_CharacterPositions.end())
|
||||
{
|
||||
check_point_row_start = destroy_row_to->m_ListStart;
|
||||
check_point_row_end = check_point_row_start + destroy_row_to->m_ListOfX.size();
|
||||
if (destroy_row_to->m_ListOfX.empty())
|
||||
++check_point_row_end;
|
||||
}
|
||||
|
||||
++destroy_row_to;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (destroy_row_from == list<SRow>::iterator())
|
||||
{
|
||||
destroy_row_from = m_CharacterPositions.end();
|
||||
--destroy_row_from;
|
||||
|
||||
current_line = destroy_row_from;
|
||||
}
|
||||
|
||||
if (destroy_row_to == list<SRow>::iterator())
|
||||
{
|
||||
destroy_row_to = m_CharacterPositions.end();
|
||||
check_point_row_start = -1;
|
||||
}
|
||||
|
||||
// set 'from' to the row we'll destroy from
|
||||
// and 'to' to the row we'll destroy to
|
||||
from = destroy_row_from->m_ListStart;
|
||||
|
||||
if (destroy_row_to != m_CharacterPositions.end())
|
||||
to = destroy_row_to->m_ListStart; // notice it will iterate [from, to), so it will never reach to.
|
||||
else
|
||||
to = caption.Length();
|
||||
|
||||
|
||||
// Setup the first row
|
||||
row.m_ListStart = destroy_row_from->m_ListStart;
|
||||
|
||||
//LOG(ERROR, LOG_CATEGORY, "Point 3 %d", to);
|
||||
|
||||
// Set current line, new rows will be added before current_line, so
|
||||
// we'll choose the destroy_row_to, because it won't be deleted
|
||||
// in the coming erase.
|
||||
current_line = destroy_row_to;
|
||||
|
||||
list<SRow>::iterator temp_it = destroy_row_to;
|
||||
--temp_it;
|
||||
|
||||
CStr c_caption1(caption.GetSubstring(destroy_row_from->m_ListStart, (temp_it->m_ListStart + temp_it->m_ListOfX.size()) -destroy_row_from->m_ListStart));
|
||||
//LOG(ERROR, LOG_CATEGORY, "Now destroying: \"%s\"", c_caption1.c_str());
|
||||
|
||||
m_CharacterPositions.erase(destroy_row_from, destroy_row_to);
|
||||
|
||||
//LOG(ERROR, LOG_CATEGORY, "--> %d %d", from, to);
|
||||
////CStr c_caption(caption.GetSubstring(from, to-from));
|
||||
//LOG(ERROR, LOG_CATEGORY, "Re-doing string: \"%s\"", c_caption.c_str());
|
||||
|
||||
// If there has been a change in number of characters
|
||||
// we need to change all m_ListStart that comes after
|
||||
// the interval we just destroyed. We'll change all
|
||||
// values with the delta change of the string length.
|
||||
int delta = to_after - to_before;
|
||||
if (delta != 0)
|
||||
{
|
||||
for (list<SRow>::iterator it=current_line;
|
||||
it!=m_CharacterPositions.end();
|
||||
++it)
|
||||
{
|
||||
it->m_ListStart += delta;
|
||||
}
|
||||
|
||||
// Update our check point too!
|
||||
check_point_row_start += delta;
|
||||
check_point_row_end += delta;
|
||||
|
||||
if (to != caption.Length())
|
||||
to += delta;
|
||||
}
|
||||
}
|
||||
|
||||
int last_word_started=from;
|
||||
int last_list_start=-1;
|
||||
float x_pos = 0.f;
|
||||
|
||||
//if (to_before != -1)
|
||||
// return;
|
||||
|
||||
//LOG(ERROR, LOG_CATEGORY, "%d %d", from, to);
|
||||
|
||||
for (int i=from; i<to; ++i)
|
||||
{
|
||||
if (caption[i] == wchar_t('\n'))
|
||||
{
|
||||
// Input row, and clear it.
|
||||
//m_CharacterPositions.push_back(row);
|
||||
/*if (m_CharacterPositions.empty())
|
||||
m_CharacterPositions.push_back( row );
|
||||
else
|
||||
{
|
||||
vector<SRow>::iterator pos( &m_CharacterPositions[current_line] );
|
||||
m_CharacterPositions.insert( pos, row );
|
||||
++current_line;
|
||||
}*/
|
||||
if (i==to-1)
|
||||
break; // it will be added outside
|
||||
|
||||
CStr c_caption1(caption.GetSubstring(row.m_ListStart, row.m_ListOfX.size()));
|
||||
//LOG(ERROR, LOG_CATEGORY, "Adding1: \"%s\" (%d,%d,%d)", c_caption1.c_str(), from, to, i);
|
||||
|
||||
current_line = m_CharacterPositions.insert( current_line, row );
|
||||
++current_line;
|
||||
|
||||
|
||||
// Setup the next row:
|
||||
row.m_ListOfX.clear();
|
||||
row.m_ListStart = i+1;
|
||||
x_pos = 0.f;
|
||||
|
||||
// If it's done now, no more word-wrapping
|
||||
// needs to be done.
|
||||
//if (i==to-1)
|
||||
// break;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (caption[i] == wchar_t(' ')/* || TODO Gee (2004-10-13): the '-' disappears, fix.
|
||||
caption[i] == wchar_t('-')*/)
|
||||
last_word_started = i+1;
|
||||
|
||||
x_pos += (float)font->GetCharacterWidth(caption[i]);
|
||||
|
||||
//LOG(ERROR, LOG_CATEGORY, "%c %f", (char)caption[i], (float)font->GetCharacterWidth(caption[i]));
|
||||
|
||||
if (x_pos >= m_CachedActualSize.GetWidth())
|
||||
{
|
||||
// The following decides whether it will word-wrap a word,
|
||||
// or if it's only one word on the line, where it has to
|
||||
// break the word apart.
|
||||
if (last_word_started == row.m_ListStart)
|
||||
{
|
||||
last_word_started = i;
|
||||
row.m_ListOfX.resize(row.m_ListOfX.size() - (i-last_word_started));
|
||||
//row.m_ListOfX.push_back( x_pos );
|
||||
//continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
// regular word-wrap
|
||||
row.m_ListOfX.resize(row.m_ListOfX.size() - (i-last_word_started+1));
|
||||
}
|
||||
|
||||
// Now, create a new line:
|
||||
// notice: when we enter a newline, you can stand with the cursor
|
||||
// both before and after that character, being on different
|
||||
// rows. With automatic word-wrapping, that is not possible. Which
|
||||
// is intuitively correct.
|
||||
CStr c_caption1(caption.GetSubstring(row.m_ListStart, row.m_ListOfX.size()));
|
||||
//LOG(ERROR, LOG_CATEGORY, "Adding2: \"%s\" - %d [%d, %d[", c_caption1.c_str(), last_word_started, from, to);
|
||||
|
||||
current_line = m_CharacterPositions.insert( current_line, row );
|
||||
++current_line;
|
||||
|
||||
// Setup the next row:
|
||||
row.m_ListOfX.clear();
|
||||
row.m_ListStart = last_word_started;
|
||||
|
||||
i=last_word_started-1;
|
||||
|
||||
x_pos = 0.f;
|
||||
}
|
||||
else
|
||||
// Get width of this character:
|
||||
row.m_ListOfX.push_back( x_pos );
|
||||
}
|
||||
|
||||
// Check if it's the last iteration, and we're not revising the whole string
|
||||
// because in that case, more word-wrapping might be needed.
|
||||
// also check if the current line isn't the end
|
||||
if (to_before != -1 && i == to-1 && current_line != m_CharacterPositions.end())
|
||||
{
|
||||
//LOG(ERROR, LOG_CATEGORY, "row.m_ListStart = %d", row.m_ListStart);
|
||||
//LOG(ERROR, LOG_CATEGORY, "check_point_row_start = %d", check_point_row_start);
|
||||
//LOG(ERROR, LOG_CATEGORY, "last_list_start = %d", last_list_start);
|
||||
|
||||
/* if (last_list_start != -1 &&
|
||||
last_list_start == row.m_ListStart)
|
||||
{
|
||||
to = current_line->m_ListStart;
|
||||
LOG(ERROR, LOG_CATEGORY, "*** %d %d", i, to);
|
||||
}
|
||||
else
|
||||
{
|
||||
*/
|
||||
// check all rows and see if any existing
|
||||
|
||||
//LOG(ERROR, LOG_CATEGORY, "(%d %d) (%d %d)", i, to, row.m_ListStart, check_point_row_start);
|
||||
|
||||
if (row.m_ListStart != check_point_row_start)
|
||||
{
|
||||
|
||||
list<SRow>::iterator destroy_row_from, destroy_row_to;
|
||||
|
||||
// Iterate, and remove everything between 'from' and 'to_before'
|
||||
// actually remove the entire lines they are on, it'll all have
|
||||
// to be redone. And when going along, we'll delete a row at a time
|
||||
// when continuing to see how much more after 'to' we need to remake.
|
||||
int i=0;
|
||||
for (list<SRow>::iterator it=m_CharacterPositions.begin();
|
||||
it!=m_CharacterPositions.end(); ++it, ++i)
|
||||
{
|
||||
if (destroy_row_from == list<SRow>::iterator() &&
|
||||
it->m_ListStart > check_point_row_start)
|
||||
{
|
||||
// Destroy the previous line, and all to 'to_before'
|
||||
//if (i >= 2)
|
||||
// destroy_row_from = it-2;
|
||||
//else
|
||||
// destroy_row_from = it-1;
|
||||
destroy_row_from = it;
|
||||
//--destroy_row_from;
|
||||
|
||||
//LOG(ERROR, LOG_CATEGORY, "[ %d %d %d", i, it->m_ListStart, check_point_row_start);
|
||||
}
|
||||
|
||||
if (destroy_row_to == list<SRow>::iterator() &&
|
||||
it->m_ListStart > check_point_row_end)
|
||||
{
|
||||
destroy_row_to = it;
|
||||
|
||||
// If it isn't the last row, we'll add another row to delete,
|
||||
// just so we can see if the last restorted line is
|
||||
// identical to what it was before. If it isn't, then we'll
|
||||
// have to continue.
|
||||
// 'check_point_row_start' is where we store how the that
|
||||
// line looked.
|
||||
// if (destroy_row_to !=
|
||||
if (destroy_row_to != m_CharacterPositions.end())
|
||||
{
|
||||
check_point_row_start = destroy_row_to->m_ListStart;
|
||||
check_point_row_end = check_point_row_start + destroy_row_to->m_ListOfX.size();
|
||||
if (destroy_row_to->m_ListOfX.empty())
|
||||
++check_point_row_end;
|
||||
|
||||
//LOG(ERROR, LOG_CATEGORY, "] %d %d %d", i, destroy_row_to->m_ListStart, check_point_row_end);
|
||||
}
|
||||
else
|
||||
check_point_row_start = check_point_row_end = -1;
|
||||
|
||||
++destroy_row_to;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (destroy_row_from == list<SRow>::iterator())
|
||||
{
|
||||
destroy_row_from = m_CharacterPositions.end();
|
||||
--destroy_row_from;
|
||||
|
||||
current_line = destroy_row_from;
|
||||
}
|
||||
|
||||
if (destroy_row_to == list<SRow>::iterator())
|
||||
{
|
||||
destroy_row_to = m_CharacterPositions.end();
|
||||
check_point_row_start = check_point_row_end = -1;
|
||||
}
|
||||
|
||||
// set 'from' to the from row we'll destroy
|
||||
// and 'to' to 'to_after'
|
||||
from = destroy_row_from->m_ListStart;
|
||||
|
||||
if (destroy_row_to != m_CharacterPositions.end())
|
||||
to = destroy_row_to->m_ListStart; // notice it will iterate [from, to[, so it will never reach to.
|
||||
else
|
||||
to = caption.Length();
|
||||
|
||||
|
||||
//LOG(ERROR, LOG_CATEGORY, "Point 3 %d", to);
|
||||
|
||||
// Set current line, new rows will be added before current_line, so
|
||||
// we'll choose the destroy_row_to, because it won't be deleted
|
||||
// in the coming erase.
|
||||
current_line = destroy_row_to;
|
||||
|
||||
m_CharacterPositions.erase(destroy_row_from, destroy_row_to);
|
||||
|
||||
//LOG(ERROR, LOG_CATEGORY, "--> %d %d", from, to);
|
||||
CStr c_caption(caption.GetSubstring(from, to-from));
|
||||
//LOG(ERROR, LOG_CATEGORY, "Re-doing string: \"%s\"", c_caption.c_str());
|
||||
|
||||
/*if (current_line != m_CharacterPositions.end())
|
||||
{
|
||||
current_line = m_CharacterPositions.erase(current_line);
|
||||
|
||||
if (current_line != m_CharacterPositions.end())
|
||||
{
|
||||
check_point_row_start = current_line->m_ListStart;
|
||||
to = check_point_row_start;
|
||||
}
|
||||
else
|
||||
{
|
||||
to = caption.Length();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
check_point_row_start = -1; // just one more row, which is the last, we don't need this anymore
|
||||
to = caption.Length();
|
||||
}*/
|
||||
|
||||
/*if (destroy_row_to != m_CharacterPositions.end())
|
||||
to = destroy_row_to->m_ListStart-1;
|
||||
else
|
||||
to = caption.Length();*/
|
||||
}
|
||||
// else, the for loop will end naturally.
|
||||
//}
|
||||
|
||||
//last_list_start = row.m_ListStart;
|
||||
}
|
||||
}
|
||||
// add the final row (even if empty)
|
||||
CStr c_caption1(caption.GetSubstring(row.m_ListStart, row.m_ListOfX.size()));
|
||||
//LOG(ERROR, LOG_CATEGORY, "Adding3: \"%s\"", c_caption1.c_str());
|
||||
|
||||
m_CharacterPositions.insert( current_line, row );
|
||||
//++current_line;
|
||||
|
||||
delete font;
|
||||
}
|
||||
|
@ -43,8 +43,8 @@ class IGUIScrollBar;
|
||||
*
|
||||
* It doesn't use IGUITextOwner, because we don't need
|
||||
* any other features than word-wrapping, and we need to be
|
||||
* able to rapidly
|
||||
*
|
||||
* able to rapidly change the string.
|
||||
*
|
||||
* @see IGUIObject
|
||||
*/
|
||||
class CInput : public IGUIScrollBarOwner
|
||||
@ -78,9 +78,34 @@ protected:
|
||||
*/
|
||||
virtual void Draw();
|
||||
|
||||
// Calculate m_CharacterPosition
|
||||
// the main task for this function is to perfom word-wrapping
|
||||
// You input from which character it has been changed, because
|
||||
// if we add a character to the very last end, we don't want
|
||||
// process everything all over again! Also notice you can
|
||||
// specify a 'to' also, it will only be used though if a '\n'
|
||||
// appears, because then the word-wrapping won't change after
|
||||
// that.
|
||||
void UpdateText(int from=0, int to_before=-1, int to_after=-1);
|
||||
|
||||
protected:
|
||||
// Cursor position
|
||||
int m_iBufferPos;
|
||||
|
||||
// the outer vector is lines, and the inner is X positions
|
||||
// in a row. So that we can determine where characters are
|
||||
// placed. It's important because we need to know where the
|
||||
// pointer should be placed when the input control is pressed.
|
||||
struct SRow
|
||||
{
|
||||
int m_ListStart; // Where does the Row starts
|
||||
std::vector<float> m_ListOfX; // List of X values for each character.
|
||||
};
|
||||
|
||||
// List of rows, list because I use a lot of iterators, and change
|
||||
// its size continuously, it's easier and safer if I know the
|
||||
// iterators never gets invalidated.
|
||||
std::list< SRow > m_CharacterPositions;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user