Removed image, link and marker limits in SatCom, closes #554

master
krzys-h 2015-08-13 14:14:11 +02:00
parent e5e1d4973f
commit bc05cda0e7
2 changed files with 39 additions and 70 deletions

View File

@ -115,13 +115,11 @@ CEdit::CEdit()
m_cursor1 = 0; m_cursor1 = 0;
m_cursor2 = 0; m_cursor2 = 0;
m_column = 0; m_column = 0;
m_imageTotal = 0;
m_timeLastScroll = 0.0f; m_timeLastScroll = 0.0f;
m_timeBlink = 0.0f; m_timeBlink = 0.0f;
m_time = 0.0f; m_time = 0.0f;
m_historyCurrent = 0; m_historyCurrent = 0;
m_markerTotal = 0;
m_bMulti = false; m_bMulti = false;
m_lineDescent = 0.0f; m_lineDescent = 0.0f;
m_timeLastClick = 0.0f; m_timeLastClick = 0.0f;
@ -640,9 +638,7 @@ void CEdit::MouseClick(Math::Point mouse)
void CEdit::MouseRelease(Math::Point mouse) void CEdit::MouseRelease(Math::Point mouse)
{ {
int i, j, rank; int i = MouseDetect(mouse);
i = MouseDetect(mouse);
if ( i == -1 ) return; if ( i == -1 ) return;
if ( !m_bEdit ) if ( !m_bEdit )
@ -650,8 +646,8 @@ void CEdit::MouseRelease(Math::Point mouse)
if ( m_format.size() > 0 && i < m_len && m_cursor1 == m_cursor2 && if ( m_format.size() > 0 && i < m_len && m_cursor1 == m_cursor2 &&
(m_format[i]&Gfx::FONT_MASK_HIGHLIGHT) == Gfx::FONT_HIGHLIGHT_LINK) //TODO (m_format[i]&Gfx::FONT_MASK_HIGHLIGHT) == Gfx::FONT_HIGHLIGHT_LINK) //TODO
{ {
rank = -1; int rank = -1;
for ( j=0 ; j<=i ; j++ ) for ( int j=0 ; j<=i ; j++ )
{ {
if ( (j == 0 || (m_format[j-1]&Gfx::FONT_MASK_HIGHLIGHT) != Gfx::FONT_HIGHLIGHT_LINK) && // TODO check if good if ( (j == 0 || (m_format[j-1]&Gfx::FONT_MASK_HIGHLIGHT) != Gfx::FONT_HIGHLIGHT_LINK) && // TODO check if good
(m_format[j+0]&Gfx::FONT_MASK_HIGHLIGHT) == Gfx::FONT_HIGHLIGHT_LINK) // TODO (m_format[j+0]&Gfx::FONT_MASK_HIGHLIGHT) == Gfx::FONT_HIGHLIGHT_LINK) // TODO
@ -659,6 +655,7 @@ void CEdit::MouseRelease(Math::Point mouse)
rank ++; rank ++;
} }
} }
assert(static_cast<unsigned int>(rank) < m_link.size());
HyperJump(m_link[rank].name, m_link[rank].marker); HyperJump(m_link[rank].name, m_link[rank].marker);
} }
} }
@ -783,18 +780,12 @@ void CEdit::HyperHome(std::string filename)
void CEdit::HyperJump(std::string name, std::string marker) void CEdit::HyperJump(std::string name, std::string marker)
{ {
std::string filename;
std:: string sMarker;
int i, line, pos;
if ( m_historyCurrent >= 0 ) if ( m_historyCurrent >= 0 )
{ {
m_history[m_historyCurrent].firstLine = m_lineFirst; m_history[m_historyCurrent].firstLine = m_lineFirst;
} }
sMarker = marker; std::string filename = name + std::string(".txt");
filename = name + std::string(".txt");
filename = InjectLevelPathsForCurrentLevel(filename, "help/%lng%"); filename = InjectLevelPathsForCurrentLevel(filename, "help/%lng%");
boost::replace_all(filename, "\\", "/"); //TODO: Fix this in files boost::replace_all(filename, "\\", "/"); //TODO: Fix this in files
@ -802,20 +793,17 @@ void CEdit::HyperJump(std::string name, std::string marker)
{ {
Justif(); Justif();
line = 0; int line = 0;
for ( i=0 ; i<m_markerTotal ; i++ ) auto it = std::find_if(m_marker.begin(), m_marker.end(), [&marker](HyperMarker hyperMarker) { return hyperMarker.name == marker; });
if(it != m_marker.end())
{ {
if (sMarker == m_marker[i].name) int pos = it->pos;
for ( int i=0 ; i<m_lineTotal ; i++ )
{ {
pos = m_marker[i].pos; if ( pos >= m_lineOffset[i] )
for ( i=0 ; i<m_lineTotal ; i++ )
{ {
if ( pos >= m_lineOffset[i] ) line = i;
{
line = i;
}
} }
break;
} }
} }
@ -896,7 +884,7 @@ void CEdit::Draw()
{ {
Math::Point pos, ppos, dim, start, end; Math::Point pos, ppos, dim, start, end;
float size = 0.0f, indentLength = 0.0f; float size = 0.0f, indentLength = 0.0f;
int i, j, beg, len, c1, c2, o1, o2, eol, iIndex, line; int i, j, beg, len, c1, c2, o1, o2, eol, line;
if ( (m_state & STATE_VISIBLE) == 0 ) return; if ( (m_state & STATE_VISIBLE) == 0 ) return;
@ -1017,7 +1005,8 @@ void CEdit::Draw()
line ++; line ++;
} }
iIndex = m_text[beg]; // character = index in m_image unsigned int iIndex = m_text[beg]; // character = index in m_image
assert(iIndex < m_image.size());
pos.y -= m_lineHeight*(line-1); pos.y -= m_lineHeight*(line-1);
DrawImage(pos, m_image[iIndex].name, DrawImage(pos, m_image[iIndex].name,
m_image[iIndex].width*(m_fontSize/Gfx::FONT_SIZE_SMALL), m_image[iIndex].width*(m_fontSize/Gfx::FONT_SIZE_SMALL),
@ -1426,12 +1415,9 @@ int GetValueParam(std::string cmd, int rank)
void CEdit::FreeImage() void CEdit::FreeImage()
{ {
std::string filename; for (auto& image : m_image)
for (int i = 0 ; i < m_imageTotal; i++ )
{ {
filename = m_image[i].name + ".png"; m_engine->DeleteTexture(image.name + ".png");
m_engine->DeleteTexture(filename);
} }
} }
@ -1450,7 +1436,7 @@ void CEdit::LoadImage(std::string name)
bool CEdit::ReadText(std::string filename, int addSize) bool CEdit::ReadText(std::string filename, int addSize)
{ {
int len, i, j, n, font, iIndex, iLines, iCount, iLink; int len, i, j, n, font, iLines, iCount;
char iName[50]; char iName[50];
float iWidth; float iWidth;
InputSlot slot; InputSlot slot;
@ -1493,10 +1479,9 @@ bool CEdit::ReadText(std::string filename, int addSize)
bInSoluce = false; bInSoluce = false;
font = m_fontType; font = m_fontType;
iIndex = 0; m_image.clear();
iLink = 0; m_marker.clear();
m_imageTotal = 0; m_link.clear();
m_markerTotal = 0;
i = j = 0; i = j = 0;
bBOL = true; bBOL = true;
while ( i < m_len ) while ( i < m_len )
@ -1590,12 +1575,10 @@ bool CEdit::ReadText(std::string filename, int addSize)
{ {
if ( m_bSoluce || !bInSoluce ) if ( m_bSoluce || !bInSoluce )
{ {
if ( iLink < EDITLINKMAX ) HyperLink link;
{ link.name = GetNameParam(buffer.data()+i+3, 0);
m_link[iLink].name = GetNameParam(buffer.data()+i+3, 0); link.marker = GetNameParam(buffer.data()+i+3, 1);
m_link[iLink].marker = GetNameParam(buffer.data()+i+3, 1); m_link.push_back(link);
iLink ++;
}
font &= ~Gfx::FONT_MASK_HIGHLIGHT; font &= ~Gfx::FONT_MASK_HIGHLIGHT;
} }
i += strchr(buffer.data()+i, ';')-(buffer.data()+i)+1; i += strchr(buffer.data()+i, ';')-(buffer.data()+i)+1;
@ -1607,12 +1590,10 @@ bool CEdit::ReadText(std::string filename, int addSize)
{ {
if ( m_bSoluce || !bInSoluce ) if ( m_bSoluce || !bInSoluce )
{ {
if ( m_markerTotal < EDITLINKMAX ) HyperMarker marker;
{ marker.name = GetNameParam(buffer.data()+i+3, 0);
m_marker[m_markerTotal].name = GetNameParam(buffer.data()+i+3, 0); marker.pos = j;
m_marker[m_markerTotal].pos = j; m_marker.push_back(marker);
m_markerTotal ++;
}
} }
i += strchr(buffer.data()+i, ';')-(buffer.data()+i)+1; i += strchr(buffer.data()+i, ';')-(buffer.data()+i)+1;
} }
@ -1627,7 +1608,6 @@ bool CEdit::ReadText(std::string filename, int addSize)
{ {
if ( m_bSoluce || !bInSoluce ) if ( m_bSoluce || !bInSoluce )
{ {
strcpy(iName, GetNameParam(buffer.data()+i+7, 0).c_str()); strcpy(iName, GetNameParam(buffer.data()+i+7, 0).c_str());
//? iWidth = m_lineHeight*RetValueParam(buffer.data()+i+7, 1); //? iWidth = m_lineHeight*RetValueParam(buffer.data()+i+7, 1);
@ -1639,17 +1619,14 @@ bool CEdit::ReadText(std::string filename, int addSize)
// A part of image per line of text. // A part of image per line of text.
for ( iCount=0 ; iCount<iLines ; iCount++ ) for ( iCount=0 ; iCount<iLines ; iCount++ )
{ {
if (iIndex >= EDITIMAGEMAX) ImageLine image;
{ image.name = iName;
GetLogger()->Warn("Too many images, current limit is %d image lines. This limit will be removed in the future.\n", EDITIMAGEMAX); image.offset = static_cast<float>(iCount) / static_cast<float>(iLines);
break; image.height = 1.0f/iLines;
} image.width = iWidth*0.75f;
m_image[iIndex].name = iName;
m_image[iIndex].offset = static_cast<float>(iCount) / static_cast<float>(iLines);
m_image[iIndex].height = 1.0f/iLines;
m_image[iIndex].width = iWidth*0.75f;
m_text[j] = static_cast<char>(iIndex++); // as an index into m_image m_image.push_back(image);
m_text[j] = static_cast<char>(m_image.size()-1); // as an index into m_image
m_format[j] = Gfx::FONT_MASK_IMAGE; m_format[j] = Gfx::FONT_MASK_IMAGE;
j ++; j ++;
} }
@ -1840,7 +1817,6 @@ bool CEdit::ReadText(std::string filename, int addSize)
} }
} }
m_len = j; m_len = j;
m_imageTotal = iIndex;
Justif(); Justif();
ColumnFix(); ColumnFix();

View File

@ -39,10 +39,6 @@ class CScroll;
const int EDITSTUDIOMAX = 20000; const int EDITSTUDIOMAX = 20000;
//! maximum total number of lines //! maximum total number of lines
const int EDITLINEMAX = 1000; const int EDITLINEMAX = 1000;
//! maximum total number of lines with images
const int EDITIMAGEMAX = 100;
//! maximum number of links
const int EDITLINKMAX = 100;
//! max number of levels preserves //! max number of levels preserves
const int EDITHISTORYMAX = 50; const int EDITHISTORYMAX = 50;
@ -256,11 +252,9 @@ protected:
int m_lineTotal; // number lines used (in m_lineOffset) int m_lineTotal; // number lines used (in m_lineOffset)
int m_lineOffset[EDITLINEMAX]; int m_lineOffset[EDITLINEMAX];
char m_lineIndent[EDITLINEMAX]; char m_lineIndent[EDITLINEMAX];
int m_imageTotal; std::vector<ImageLine> m_image;
ImageLine m_image[EDITIMAGEMAX]; std::vector<HyperLink> m_link;
HyperLink m_link[EDITLINKMAX]; std::vector<HyperMarker> m_marker;
int m_markerTotal;
HyperMarker m_marker[EDITLINKMAX];
int m_historyTotal; int m_historyTotal;
int m_historyCurrent; int m_historyCurrent;
HyperHistory m_history[EDITHISTORYMAX]; HyperHistory m_history[EDITHISTORYMAX];
@ -281,4 +275,3 @@ protected:
} }