2014-10-14 13:11:37 +00:00
|
|
|
|
/*
|
|
|
|
|
* This file is part of the Colobot: Gold Edition source code
|
|
|
|
|
* Copyright (C) 2001-2014, Daniel Roux, EPSITEC SA & TerranovaTeam
|
|
|
|
|
* http://epsiteс.ch; http://colobot.info; http://github.com/colobot
|
|
|
|
|
*
|
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
|
* See the GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program. If not, see http://gnu.org/licenses
|
|
|
|
|
*/
|
2012-06-26 20:23:05 +00:00
|
|
|
|
|
|
|
|
|
|
2015-08-06 11:25:24 +00:00
|
|
|
|
#include "ui/controls/edit.h"
|
2012-06-26 20:23:05 +00:00
|
|
|
|
|
2015-08-02 11:09:48 +00:00
|
|
|
|
#include "common/config.h"
|
|
|
|
|
|
2013-02-16 21:37:43 +00:00
|
|
|
|
#include "app/app.h"
|
2014-12-11 18:01:57 +00:00
|
|
|
|
#include "app/input.h"
|
2013-02-16 21:37:43 +00:00
|
|
|
|
|
2015-07-05 11:00:48 +00:00
|
|
|
|
#include "common/logger.h"
|
2015-08-11 20:47:07 +00:00
|
|
|
|
#include "common/make_unique.h"
|
2015-08-02 11:09:48 +00:00
|
|
|
|
#include "common/misc.h"
|
|
|
|
|
|
2014-06-20 21:41:38 +00:00
|
|
|
|
#include "common/resources/inputstream.h"
|
2014-06-22 13:01:06 +00:00
|
|
|
|
#include "common/resources/outputstream.h"
|
2014-06-20 21:41:38 +00:00
|
|
|
|
|
2015-08-13 09:47:32 +00:00
|
|
|
|
#include "graphics/engine/engine.h"
|
2015-08-05 17:27:26 +00:00
|
|
|
|
|
2015-08-13 09:47:32 +00:00
|
|
|
|
#include "level/parser/parser.h"
|
2015-03-08 14:22:21 +00:00
|
|
|
|
|
2015-08-06 11:25:24 +00:00
|
|
|
|
#include "ui/controls/scroll.h"
|
2015-08-02 11:09:48 +00:00
|
|
|
|
|
|
|
|
|
#include <clipboard/clipboard.h>
|
|
|
|
|
|
2014-07-11 14:40:07 +00:00
|
|
|
|
#include <boost/algorithm/string.hpp>
|
2012-06-26 20:23:05 +00:00
|
|
|
|
|
2015-08-02 11:09:48 +00:00
|
|
|
|
#include <cstring>
|
|
|
|
|
|
2015-08-02 09:40:47 +00:00
|
|
|
|
namespace Ui
|
|
|
|
|
{
|
2012-06-26 20:23:05 +00:00
|
|
|
|
|
|
|
|
|
const float MARGX = (5.0f/640.0f);
|
|
|
|
|
const float MARGY = (5.0f/480.0f);
|
|
|
|
|
const float MARGYS = (4.0f/480.0f);
|
|
|
|
|
const float MARGY1 = (1.0f/480.0f);
|
2012-08-20 12:05:36 +00:00
|
|
|
|
//! time limit for double-click
|
|
|
|
|
const float DELAY_DBCLICK = 0.3f;
|
|
|
|
|
//! time limit for scroll
|
|
|
|
|
const float DELAY_SCROLL = 0.1f;
|
|
|
|
|
//! expansion for \b;
|
|
|
|
|
const float BIG_FONT = 1.6f;
|
2012-06-26 20:23:05 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-08-20 12:05:36 +00:00
|
|
|
|
//! Indicates whether a character is a space.
|
2012-06-26 20:23:05 +00:00
|
|
|
|
|
|
|
|
|
bool IsSpace(int character)
|
|
|
|
|
{
|
|
|
|
|
return ( character == ' ' ||
|
|
|
|
|
character == '\t' ||
|
|
|
|
|
character == '\n' );
|
|
|
|
|
}
|
|
|
|
|
|
2012-08-20 12:05:36 +00:00
|
|
|
|
//! Indicates whether a character is part of a word.
|
2012-06-26 20:23:05 +00:00
|
|
|
|
|
|
|
|
|
bool IsWord(int character)
|
|
|
|
|
{
|
|
|
|
|
char c;
|
|
|
|
|
|
2012-08-20 12:05:36 +00:00
|
|
|
|
c = tolower(GetNoAccent(character));
|
2012-06-26 20:23:05 +00:00
|
|
|
|
|
|
|
|
|
return ( (c >= 'a' && c <= 'z') ||
|
|
|
|
|
(c >= '0' && c <= '9') ||
|
|
|
|
|
c == '_' );
|
|
|
|
|
}
|
|
|
|
|
|
2012-08-20 12:05:36 +00:00
|
|
|
|
//! Indicates whether a character is a word separator.
|
2012-06-26 20:23:05 +00:00
|
|
|
|
|
|
|
|
|
bool IsSep(int character)
|
|
|
|
|
{
|
|
|
|
|
if ( IsSpace(character) ) return false;
|
|
|
|
|
return !IsWord(character);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-08-20 12:05:36 +00:00
|
|
|
|
//! Object's constructor.
|
2015-08-11 20:47:07 +00:00
|
|
|
|
CEdit::CEdit()
|
|
|
|
|
: CControl(),
|
|
|
|
|
m_lineOffset(),
|
|
|
|
|
m_lineIndent()
|
2012-06-26 20:23:05 +00:00
|
|
|
|
{
|
|
|
|
|
m_maxChar = 100;
|
2015-07-15 17:52:44 +00:00
|
|
|
|
m_text = std::vector<char>(m_maxChar+1, '\0');
|
2012-06-26 20:23:05 +00:00
|
|
|
|
m_len = 0;
|
|
|
|
|
|
2012-08-20 12:05:36 +00:00
|
|
|
|
m_fontType = Gfx::FONT_COURIER;
|
2012-06-26 20:23:05 +00:00
|
|
|
|
m_bEdit = true;
|
|
|
|
|
m_bHilite = true;
|
|
|
|
|
m_bInsideScroll = true;
|
|
|
|
|
m_bCapture = false;
|
|
|
|
|
m_bDisplaySpec = false;
|
|
|
|
|
m_bSoluce = false;
|
|
|
|
|
m_bGeneric = false;
|
|
|
|
|
m_bAutoIndent = false;
|
|
|
|
|
m_cursor1 = 0;
|
|
|
|
|
m_cursor2 = 0;
|
|
|
|
|
m_column = 0;
|
|
|
|
|
|
2015-08-11 20:47:07 +00:00
|
|
|
|
m_timeLastScroll = 0.0f;
|
|
|
|
|
m_timeBlink = 0.0f;
|
|
|
|
|
m_time = 0.0f;
|
|
|
|
|
m_historyCurrent = 0;
|
|
|
|
|
m_bMulti = false;
|
|
|
|
|
m_lineDescent = 0.0f;
|
|
|
|
|
m_timeLastClick = 0.0f;
|
|
|
|
|
m_bMultiFont = false;
|
|
|
|
|
m_lineAscent = 0.0f;
|
|
|
|
|
m_historyTotal = 0;
|
|
|
|
|
m_lineTotal = 0;
|
|
|
|
|
m_lineHeight = 0.0f;
|
|
|
|
|
m_lineVisible = 0;
|
|
|
|
|
m_lineFirst = 0;
|
|
|
|
|
|
2012-06-26 20:23:05 +00:00
|
|
|
|
HyperFlush();
|
|
|
|
|
|
|
|
|
|
m_bUndoForce = true;
|
|
|
|
|
m_undoOper = OPERUNDO_SPEC;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Object's destructor.
|
|
|
|
|
|
|
|
|
|
CEdit::~CEdit()
|
|
|
|
|
{
|
|
|
|
|
FreeImage();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Creates a new editable line.
|
|
|
|
|
|
2012-08-20 12:05:36 +00:00
|
|
|
|
bool CEdit::Create(Math::Point pos, Math::Point dim, int icon, EventType eventType)
|
2012-06-26 20:23:05 +00:00
|
|
|
|
{
|
2012-08-20 12:05:36 +00:00
|
|
|
|
if ( eventType == EVENT_NULL ) eventType = GetUniqueEventType();
|
|
|
|
|
CControl::Create(pos, dim, icon, eventType);
|
2012-06-26 20:23:05 +00:00
|
|
|
|
|
|
|
|
|
m_len = 0;
|
|
|
|
|
m_lineFirst = 0;
|
|
|
|
|
m_time = 0.0f;
|
|
|
|
|
m_timeBlink = 0.0f;
|
|
|
|
|
m_timeLastClick = 0.0f;
|
|
|
|
|
m_timeLastScroll = 0.0f;
|
|
|
|
|
|
|
|
|
|
m_bMulti = false;
|
|
|
|
|
MoveAdjust();
|
|
|
|
|
if ( m_lineVisible <= 1 )
|
|
|
|
|
{
|
|
|
|
|
m_bMulti = false;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
m_bMulti = true;
|
|
|
|
|
MoveAdjust(); // readjusts multi-line mode
|
2015-08-11 20:47:07 +00:00
|
|
|
|
m_scroll = MakeUnique<Ui::CScroll>();
|
|
|
|
|
m_scroll->Create(pos, dim, -1, EVENT_NULL);
|
2012-06-26 20:23:05 +00:00
|
|
|
|
MoveAdjust();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void CEdit::SetPos(Math::Point pos)
|
|
|
|
|
{
|
|
|
|
|
CControl::SetPos(pos);
|
|
|
|
|
MoveAdjust();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CEdit::SetDim(Math::Point dim)
|
|
|
|
|
{
|
|
|
|
|
CControl::SetDim(dim);
|
|
|
|
|
MoveAdjust();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CEdit::MoveAdjust()
|
|
|
|
|
{
|
|
|
|
|
Math::Point pos, dim;
|
|
|
|
|
float height;
|
|
|
|
|
|
2012-08-20 12:05:36 +00:00
|
|
|
|
m_lineDescent = m_engine->GetText()->GetDescent(m_fontType, m_fontSize);
|
|
|
|
|
m_lineAscent = m_engine->GetText()->GetAscent(m_fontType, m_fontSize);
|
|
|
|
|
m_lineHeight = m_engine->GetText()->GetHeight(m_fontType, m_fontSize);
|
2012-06-26 20:23:05 +00:00
|
|
|
|
|
|
|
|
|
height = m_dim.y-(m_bMulti?MARGY*2.0f:MARGY1);
|
2012-08-20 12:05:36 +00:00
|
|
|
|
m_lineVisible = static_cast<int>((height/m_lineHeight));
|
2012-06-26 20:23:05 +00:00
|
|
|
|
|
2015-08-11 20:47:07 +00:00
|
|
|
|
if (m_scroll != nullptr)
|
2012-06-26 20:23:05 +00:00
|
|
|
|
{
|
|
|
|
|
if ( m_bInsideScroll )
|
|
|
|
|
{
|
2012-08-20 12:05:36 +00:00
|
|
|
|
pos.x = m_pos.x + m_dim.x - MARGX-SCROLL_WIDTH;
|
|
|
|
|
pos.y = m_pos.y + MARGYS;
|
2012-06-26 20:23:05 +00:00
|
|
|
|
dim.x = SCROLL_WIDTH;
|
2012-08-20 12:05:36 +00:00
|
|
|
|
dim.y = m_dim.y - MARGYS*2.0f;
|
2012-06-26 20:23:05 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2012-08-20 12:05:36 +00:00
|
|
|
|
pos.x = m_pos.x + m_dim.x - SCROLL_WIDTH;
|
2012-06-26 20:23:05 +00:00
|
|
|
|
pos.y = m_pos.y;
|
|
|
|
|
dim.x = SCROLL_WIDTH;
|
|
|
|
|
dim.y = m_dim.y;
|
|
|
|
|
}
|
|
|
|
|
m_scroll->SetPos(pos);
|
|
|
|
|
m_scroll->SetDim(dim);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Justif();
|
|
|
|
|
|
|
|
|
|
if ( m_lineFirst > m_lineTotal-m_lineVisible )
|
|
|
|
|
{
|
|
|
|
|
m_lineFirst = m_lineTotal-m_lineVisible;
|
|
|
|
|
if ( m_lineFirst < 0 ) m_lineFirst = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pos.x = m_pos.x+m_dim.x-(m_bMulti?SCROLL_WIDTH:0.0f);
|
|
|
|
|
pos.y = m_pos.y;
|
|
|
|
|
GlintCreate(pos, false, false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Management of an event.
|
|
|
|
|
|
|
|
|
|
bool CEdit::EventProcess(const Event &event)
|
|
|
|
|
{
|
|
|
|
|
bool bShift, bControl;
|
|
|
|
|
|
|
|
|
|
if ( (m_state & STATE_VISIBLE) == 0 ) return true;
|
|
|
|
|
|
2012-09-19 19:45:41 +00:00
|
|
|
|
if (event.type == EVENT_MOUSE_WHEEL &&
|
2015-08-06 15:51:28 +00:00
|
|
|
|
Detect(event.mousePos))
|
2012-06-26 20:23:05 +00:00
|
|
|
|
{
|
2015-08-06 15:51:28 +00:00
|
|
|
|
auto data = event.GetData<MouseWheelEventData>();
|
|
|
|
|
if (data->dir == WHEEL_UP)
|
|
|
|
|
{
|
|
|
|
|
Scroll(m_lineFirst - 3, true);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Scroll(m_lineFirst + 3, true);
|
|
|
|
|
}
|
2012-06-26 20:23:05 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CControl::EventProcess(event);
|
|
|
|
|
|
2012-08-20 12:05:36 +00:00
|
|
|
|
if ( event.type == EVENT_FRAME )
|
2012-06-26 20:23:05 +00:00
|
|
|
|
{
|
|
|
|
|
m_time += event.rTime;
|
|
|
|
|
m_timeBlink += event.rTime;
|
|
|
|
|
}
|
|
|
|
|
|
2012-08-20 12:05:36 +00:00
|
|
|
|
if ( event.type == EVENT_MOUSE_MOVE )
|
2012-06-26 20:23:05 +00:00
|
|
|
|
{
|
2013-05-26 15:47:54 +00:00
|
|
|
|
if ( Detect(event.mousePos) &&
|
2012-09-21 22:38:17 +00:00
|
|
|
|
event.mousePos.x < m_pos.x+m_dim.x-(m_bMulti?MARGX+SCROLL_WIDTH:0.0f) )
|
2012-06-26 20:23:05 +00:00
|
|
|
|
{
|
|
|
|
|
if ( m_bEdit )
|
|
|
|
|
{
|
2012-08-20 12:05:36 +00:00
|
|
|
|
m_engine->SetMouseType(Gfx::ENG_MOUSE_EDIT);
|
2012-06-26 20:23:05 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2012-09-21 22:38:17 +00:00
|
|
|
|
if ( IsLinkPos(event.mousePos) )
|
2012-06-26 20:23:05 +00:00
|
|
|
|
{
|
2012-08-20 12:05:36 +00:00
|
|
|
|
m_engine->SetMouseType(Gfx::ENG_MOUSE_HAND);
|
2012-06-26 20:23:05 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2012-08-20 12:05:36 +00:00
|
|
|
|
m_engine->SetMouseType(Gfx::ENG_MOUSE_NORM);
|
2012-06-26 20:23:05 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-11 20:47:07 +00:00
|
|
|
|
if (m_scroll != nullptr && !m_bGeneric)
|
2012-06-26 20:23:05 +00:00
|
|
|
|
{
|
|
|
|
|
m_scroll->EventProcess(event);
|
|
|
|
|
|
2015-08-11 20:47:07 +00:00
|
|
|
|
if (event.type == m_scroll->GetEventType())
|
2012-06-26 20:23:05 +00:00
|
|
|
|
{
|
|
|
|
|
Scroll();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-04-27 17:39:22 +00:00
|
|
|
|
if (event.type == EVENT_KEY_DOWN)
|
2012-06-26 20:23:05 +00:00
|
|
|
|
{
|
2012-09-21 22:38:17 +00:00
|
|
|
|
bShift = ( (event.kmodState & KEY_MOD(SHIFT) ) != 0 );
|
2014-12-10 08:56:10 +00:00
|
|
|
|
#if PLATFORM_MACOSX
|
|
|
|
|
bControl = ( (event.kmodState & KEY_MOD(META) ) != 0);
|
|
|
|
|
#else
|
2012-09-21 22:38:17 +00:00
|
|
|
|
bControl = ( (event.kmodState & KEY_MOD(CTRL) ) != 0);
|
2014-12-10 08:56:10 +00:00
|
|
|
|
#endif
|
2015-04-27 17:39:22 +00:00
|
|
|
|
}
|
2012-06-26 20:23:05 +00:00
|
|
|
|
|
2015-04-27 17:39:22 +00:00
|
|
|
|
if ( event.type == EVENT_KEY_DOWN && m_bFocus )
|
|
|
|
|
{
|
2015-08-06 15:51:28 +00:00
|
|
|
|
auto data = event.GetData<KeyEventData>();
|
|
|
|
|
|
|
|
|
|
if ( (data->key == KEY(x) && !bShift && bControl) ||
|
|
|
|
|
(data->key == KEY(DELETE) && bShift && !bControl) )
|
2012-06-26 20:23:05 +00:00
|
|
|
|
{
|
|
|
|
|
Cut();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2015-08-06 15:51:28 +00:00
|
|
|
|
if ( (data->key == KEY(c) && !bShift && bControl) ||
|
|
|
|
|
(data->key == KEY(INSERT) && !bShift && bControl) )
|
2012-06-26 20:23:05 +00:00
|
|
|
|
{
|
|
|
|
|
Copy();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2015-08-06 15:51:28 +00:00
|
|
|
|
if ( (data->key == KEY(v) && !bShift && bControl) ||
|
|
|
|
|
(data->key == KEY(INSERT) && bShift && !bControl) )
|
2012-06-26 20:23:05 +00:00
|
|
|
|
{
|
|
|
|
|
Paste();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-06 15:51:28 +00:00
|
|
|
|
if ( data->key == KEY(a) && !bShift && bControl )
|
2012-06-26 20:23:05 +00:00
|
|
|
|
{
|
|
|
|
|
SetCursor(999999, 0);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-06 15:51:28 +00:00
|
|
|
|
if ( data->key == KEY(o) && !bShift && bControl )
|
2012-06-26 20:23:05 +00:00
|
|
|
|
{
|
2015-08-06 15:51:28 +00:00
|
|
|
|
m_event->AddEvent(Event(EVENT_STUDIO_OPEN));
|
2012-06-26 20:23:05 +00:00
|
|
|
|
}
|
2015-08-06 15:51:28 +00:00
|
|
|
|
if ( data->key == KEY(s) && !bShift && bControl )
|
2012-06-26 20:23:05 +00:00
|
|
|
|
{
|
2015-08-06 15:51:28 +00:00
|
|
|
|
m_event->AddEvent(Event(EVENT_STUDIO_SAVE));
|
2012-06-26 20:23:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-08-06 15:51:28 +00:00
|
|
|
|
if ( data->key == KEY(z) && !bShift && bControl )
|
2012-06-26 20:23:05 +00:00
|
|
|
|
{
|
|
|
|
|
Undo();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-06 15:51:28 +00:00
|
|
|
|
if ( data->key == KEY(u) && !bShift && bControl )
|
2012-06-26 20:23:05 +00:00
|
|
|
|
{
|
|
|
|
|
if ( MinMaj(false) ) return true;
|
|
|
|
|
}
|
2015-08-06 15:51:28 +00:00
|
|
|
|
if ( data->key == KEY(u) && bShift && bControl )
|
2012-06-26 20:23:05 +00:00
|
|
|
|
{
|
|
|
|
|
if ( MinMaj(true) ) return true;
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-06 15:51:28 +00:00
|
|
|
|
if ( data->key == KEY(TAB) && !bShift && !bControl && !m_bAutoIndent )
|
2012-06-26 20:23:05 +00:00
|
|
|
|
{
|
|
|
|
|
if ( Shift(false) ) return true;
|
|
|
|
|
}
|
2015-08-06 15:51:28 +00:00
|
|
|
|
if ( data->key == KEY(TAB) && bShift && !bControl && !m_bAutoIndent )
|
2012-06-26 20:23:05 +00:00
|
|
|
|
{
|
|
|
|
|
if ( Shift(true) ) return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( m_bEdit )
|
|
|
|
|
{
|
2015-08-06 15:51:28 +00:00
|
|
|
|
if ( data->key == KEY(LEFT) )
|
2012-06-26 20:23:05 +00:00
|
|
|
|
{
|
|
|
|
|
MoveChar(-1, bControl, bShift);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2015-08-06 15:51:28 +00:00
|
|
|
|
if ( data->key == KEY(RIGHT) )
|
2012-06-26 20:23:05 +00:00
|
|
|
|
{
|
|
|
|
|
MoveChar(1, bControl, bShift);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2015-08-06 15:51:28 +00:00
|
|
|
|
if ( data->key == KEY(UP) && m_bMulti )
|
2012-06-26 20:23:05 +00:00
|
|
|
|
{
|
|
|
|
|
MoveLine(-1, bControl, bShift);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2015-08-06 15:51:28 +00:00
|
|
|
|
if ( data->key == KEY(DOWN) && m_bMulti )
|
2012-06-26 20:23:05 +00:00
|
|
|
|
{
|
|
|
|
|
MoveLine(1, bControl, bShift);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-06 15:51:28 +00:00
|
|
|
|
if ( data->key == KEY(PAGEUP) && m_bMulti ) // PageUp ?
|
2012-06-26 20:23:05 +00:00
|
|
|
|
{
|
|
|
|
|
MoveLine(-(m_lineVisible-1), bControl, bShift);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2015-08-06 15:51:28 +00:00
|
|
|
|
if ( data->key == KEY(PAGEDOWN) && m_bMulti ) // PageDown ?
|
2012-06-26 20:23:05 +00:00
|
|
|
|
{
|
|
|
|
|
MoveLine(m_lineVisible-1, bControl, bShift);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2015-08-06 15:51:28 +00:00
|
|
|
|
if ( data->key == KEY(LEFT) ||
|
|
|
|
|
data->key == KEY(UP) )
|
2012-06-26 20:23:05 +00:00
|
|
|
|
{
|
|
|
|
|
Scroll(m_lineFirst-1, true);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2015-08-06 15:51:28 +00:00
|
|
|
|
if ( data->key == KEY(RIGHT) ||
|
|
|
|
|
data->key == KEY(DOWN) )
|
2012-06-26 20:23:05 +00:00
|
|
|
|
{
|
|
|
|
|
Scroll(m_lineFirst+1, true);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-06 15:51:28 +00:00
|
|
|
|
if ( data->key == KEY(PAGEUP) ) // PageUp ?
|
2012-06-26 20:23:05 +00:00
|
|
|
|
{
|
|
|
|
|
Scroll(m_lineFirst-(m_lineVisible-1), true);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2015-08-06 15:51:28 +00:00
|
|
|
|
if ( data->key == KEY(PAGEDOWN) ) // PageDown ?
|
2012-06-26 20:23:05 +00:00
|
|
|
|
{
|
|
|
|
|
Scroll(m_lineFirst+(m_lineVisible-1), true);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-06 15:51:28 +00:00
|
|
|
|
if ( data->key == KEY(HOME) )
|
2012-06-26 20:23:05 +00:00
|
|
|
|
{
|
|
|
|
|
MoveHome(bControl, bShift);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2015-08-06 15:51:28 +00:00
|
|
|
|
if ( data->key == KEY(END) )
|
2012-06-26 20:23:05 +00:00
|
|
|
|
{
|
|
|
|
|
MoveEnd(bControl, bShift);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-06 15:51:28 +00:00
|
|
|
|
if ( data->key == KEY(BACKSPACE) && !bControl ) // backspace ( <- ) ?
|
2012-06-26 20:23:05 +00:00
|
|
|
|
{
|
|
|
|
|
Delete(-1);
|
|
|
|
|
SendModifEvent();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2015-08-06 15:51:28 +00:00
|
|
|
|
if ( data->key == KEY(DELETE) && !bControl )
|
2012-06-26 20:23:05 +00:00
|
|
|
|
{
|
|
|
|
|
Delete(1);
|
|
|
|
|
SendModifEvent();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-06 15:51:28 +00:00
|
|
|
|
if ( data->key == KEY(RETURN) && !bControl )
|
2012-06-26 20:23:05 +00:00
|
|
|
|
{
|
|
|
|
|
Insert('\n');
|
|
|
|
|
SendModifEvent();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2015-08-06 15:51:28 +00:00
|
|
|
|
if ( data->key == KEY(TAB) && !bControl )
|
2012-06-26 20:23:05 +00:00
|
|
|
|
{
|
|
|
|
|
Insert('\t');
|
|
|
|
|
SendModifEvent();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-11-11 16:40:48 +00:00
|
|
|
|
if ( event.type == EVENT_KEY_DOWN && !bControl && m_bFocus )
|
2012-06-26 20:23:05 +00:00
|
|
|
|
{
|
2015-08-06 15:51:28 +00:00
|
|
|
|
auto data = event.GetData<KeyEventData>();
|
|
|
|
|
if (data->unicode >= ' ')
|
2012-06-26 20:23:05 +00:00
|
|
|
|
{
|
2015-08-06 15:51:28 +00:00
|
|
|
|
Insert(static_cast<char>(data->unicode)); // TODO: insert utf-8 char
|
2012-06-26 20:23:05 +00:00
|
|
|
|
SendModifEvent();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-09-21 22:38:17 +00:00
|
|
|
|
if ( event.type == EVENT_FOCUS )
|
2012-06-26 20:23:05 +00:00
|
|
|
|
{
|
2012-09-21 22:38:17 +00:00
|
|
|
|
if ( event.customParam == m_eventType )
|
2012-06-26 20:23:05 +00:00
|
|
|
|
{
|
|
|
|
|
m_bFocus = true;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
m_bFocus = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-06 15:51:28 +00:00
|
|
|
|
if (event.type == EVENT_MOUSE_BUTTON_DOWN &&
|
|
|
|
|
event.GetData<MouseButtonEventData>()->button == MOUSE_BUTTON_LEFT)
|
2012-06-26 20:23:05 +00:00
|
|
|
|
{
|
2012-09-21 22:38:17 +00:00
|
|
|
|
m_mouseFirstPos = event.mousePos;
|
|
|
|
|
m_mouseLastPos = event.mousePos;
|
|
|
|
|
if ( Detect(event.mousePos) )
|
2012-06-26 20:23:05 +00:00
|
|
|
|
{
|
2012-09-21 22:38:17 +00:00
|
|
|
|
if ( event.mousePos.x < m_pos.x+m_dim.x-(m_bMulti?MARGX+SCROLL_WIDTH:0.0f) )
|
2012-06-26 20:23:05 +00:00
|
|
|
|
{
|
2012-09-21 22:38:17 +00:00
|
|
|
|
MouseClick(event.mousePos);
|
2012-06-26 20:23:05 +00:00
|
|
|
|
if ( m_bEdit || m_bHilite ) m_bCapture = true;
|
|
|
|
|
}
|
|
|
|
|
m_bFocus = true;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
m_bFocus = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-08-20 12:05:36 +00:00
|
|
|
|
if ( event.type == EVENT_MOUSE_MOVE && m_bCapture )
|
2012-06-26 20:23:05 +00:00
|
|
|
|
{
|
2012-09-21 22:38:17 +00:00
|
|
|
|
m_mouseLastPos = event.mousePos;
|
|
|
|
|
MouseMove(event.mousePos);
|
2012-06-26 20:23:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-08-20 12:05:36 +00:00
|
|
|
|
if ( event.type == EVENT_FRAME && m_bCapture )
|
2012-06-26 20:23:05 +00:00
|
|
|
|
{
|
|
|
|
|
MouseMove(m_mouseLastPos);
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-06 15:51:28 +00:00
|
|
|
|
if (event.type == EVENT_MOUSE_BUTTON_UP &&
|
|
|
|
|
event.GetData<MouseButtonEventData>()->button == MOUSE_BUTTON_LEFT)
|
2012-06-26 20:23:05 +00:00
|
|
|
|
{
|
2012-09-21 22:38:17 +00:00
|
|
|
|
if ( Detect(event.mousePos) )
|
2012-06-26 20:23:05 +00:00
|
|
|
|
{
|
2012-09-21 22:38:17 +00:00
|
|
|
|
if ( event.mousePos.x < m_pos.x+m_dim.x-(m_bMulti?MARGX+SCROLL_WIDTH:0.0f) )
|
2012-06-26 20:23:05 +00:00
|
|
|
|
{
|
|
|
|
|
MouseRelease(m_mouseFirstPos);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if ( m_bCapture )
|
|
|
|
|
{
|
|
|
|
|
if ( m_timeLastClick+DELAY_DBCLICK > m_time ) // double-click ?
|
|
|
|
|
{
|
2012-09-21 22:38:17 +00:00
|
|
|
|
MouseDoubleClick(event.mousePos);
|
2012-06-26 20:23:05 +00:00
|
|
|
|
}
|
|
|
|
|
m_timeLastClick = m_time;
|
|
|
|
|
m_bCapture = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Sends an event to indicate that the text was modified.
|
|
|
|
|
|
|
|
|
|
void CEdit::SendModifEvent()
|
|
|
|
|
{
|
2015-08-06 15:51:28 +00:00
|
|
|
|
m_event->AddEvent(Event(m_eventType));
|
2012-06-26 20:23:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Detects whether the mouse is over a hyperlink character.
|
|
|
|
|
|
|
|
|
|
bool CEdit::IsLinkPos(Math::Point pos)
|
|
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
|
2012-08-31 20:28:07 +00:00
|
|
|
|
if ( m_format.size() == 0 ) return false;
|
2012-06-26 20:23:05 +00:00
|
|
|
|
|
|
|
|
|
i = MouseDetect(pos);
|
|
|
|
|
if ( i == -1 ) return false;
|
|
|
|
|
if ( i >= m_len ) return false;
|
|
|
|
|
|
2013-03-17 18:01:32 +00:00
|
|
|
|
if ( m_format.size() > static_cast<unsigned int>(i) && ((m_format[i] & Gfx::FONT_MASK_HIGHLIGHT) == Gfx::FONT_HIGHLIGHT_LINK)) return true; // TODO
|
2012-06-26 20:23:05 +00:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Positions the cursor after a double click.
|
|
|
|
|
|
|
|
|
|
void CEdit::MouseDoubleClick(Math::Point mouse)
|
|
|
|
|
{
|
|
|
|
|
int i, character;
|
|
|
|
|
|
|
|
|
|
if ( m_bMulti ) // Multi-line?
|
|
|
|
|
{
|
|
|
|
|
i = MouseDetect(mouse);
|
|
|
|
|
if ( i == -1 ) return;
|
|
|
|
|
|
|
|
|
|
while ( i > 0 )
|
|
|
|
|
{
|
2012-09-17 22:01:00 +00:00
|
|
|
|
character = static_cast<unsigned char>(m_text[i-1]);
|
2012-06-26 20:23:05 +00:00
|
|
|
|
if ( !IsWord(character) ) break;
|
|
|
|
|
i --;
|
|
|
|
|
}
|
|
|
|
|
m_cursor2 = i;
|
|
|
|
|
|
|
|
|
|
while ( i < m_len )
|
|
|
|
|
{
|
2012-09-17 22:01:00 +00:00
|
|
|
|
character = static_cast<unsigned char>(m_text[i]);
|
2012-06-26 20:23:05 +00:00
|
|
|
|
if ( !IsWord(character) ) break;
|
|
|
|
|
i ++;
|
|
|
|
|
}
|
|
|
|
|
m_cursor1 = i;
|
|
|
|
|
}
|
|
|
|
|
else // single-line?
|
|
|
|
|
{
|
|
|
|
|
m_cursor2 = 0;
|
|
|
|
|
m_cursor1 = m_len; // selects all
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
m_bUndoForce = true;
|
|
|
|
|
|
|
|
|
|
Justif();
|
|
|
|
|
ColumnFix();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Positions the cursor when clicked.
|
|
|
|
|
|
|
|
|
|
void CEdit::MouseClick(Math::Point mouse)
|
|
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
i = MouseDetect(mouse);
|
|
|
|
|
if ( i == -1 ) return;
|
|
|
|
|
|
|
|
|
|
if ( m_bEdit || m_bHilite )
|
|
|
|
|
{
|
|
|
|
|
m_cursor1 = i;
|
|
|
|
|
m_cursor2 = i;
|
|
|
|
|
m_bUndoForce = true;
|
|
|
|
|
m_timeBlink = 0.0f; // lights the cursor immediately
|
|
|
|
|
ColumnFix();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Positions the cursor when clicked released.
|
|
|
|
|
|
|
|
|
|
void CEdit::MouseRelease(Math::Point mouse)
|
|
|
|
|
{
|
2015-08-13 12:14:11 +00:00
|
|
|
|
int i = MouseDetect(mouse);
|
2012-06-26 20:23:05 +00:00
|
|
|
|
if ( i == -1 ) return;
|
|
|
|
|
|
|
|
|
|
if ( !m_bEdit )
|
|
|
|
|
{
|
2012-08-31 20:28:07 +00:00
|
|
|
|
if ( m_format.size() > 0 && i < m_len && m_cursor1 == m_cursor2 &&
|
2012-08-20 12:05:36 +00:00
|
|
|
|
(m_format[i]&Gfx::FONT_MASK_HIGHLIGHT) == Gfx::FONT_HIGHLIGHT_LINK) //TODO
|
2012-06-26 20:23:05 +00:00
|
|
|
|
{
|
2015-08-13 12:14:11 +00:00
|
|
|
|
int rank = -1;
|
|
|
|
|
for ( int j=0 ; j<=i ; j++ )
|
2012-06-26 20:23:05 +00:00
|
|
|
|
{
|
2012-08-20 12:05:36 +00:00
|
|
|
|
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
|
2012-06-26 20:23:05 +00:00
|
|
|
|
{
|
|
|
|
|
rank ++;
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-08-13 12:14:11 +00:00
|
|
|
|
assert(static_cast<unsigned int>(rank) < m_link.size());
|
2012-06-26 20:23:05 +00:00
|
|
|
|
HyperJump(m_link[rank].name, m_link[rank].marker);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Positions the cursor after movement.
|
|
|
|
|
|
|
|
|
|
void CEdit::MouseMove(Math::Point mouse)
|
|
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
if ( m_bMulti &&
|
|
|
|
|
m_timeLastScroll+DELAY_SCROLL <= m_time )
|
|
|
|
|
{
|
|
|
|
|
if ( mouse.y > m_pos.y+m_dim.y ) // above?
|
|
|
|
|
{
|
|
|
|
|
Scroll(m_lineFirst-1, false);
|
|
|
|
|
mouse.y = m_pos.y+m_dim.y-MARGY-m_lineHeight/2.0f;
|
|
|
|
|
}
|
|
|
|
|
if ( mouse.y < m_pos.y ) // lower?
|
|
|
|
|
{
|
|
|
|
|
Scroll(m_lineFirst+1, false);
|
|
|
|
|
mouse.y = m_pos.y+m_dim.y-MARGY-m_lineVisible*m_lineHeight+m_lineHeight/2.0f;
|
|
|
|
|
}
|
|
|
|
|
m_timeLastScroll = m_time;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
i = MouseDetect(mouse);
|
|
|
|
|
if ( i != -1 )
|
|
|
|
|
{
|
|
|
|
|
m_cursor1 = i;
|
|
|
|
|
m_bUndoForce = true;
|
|
|
|
|
m_timeBlink = 0.0f; // lights the cursor immediately
|
|
|
|
|
ColumnFix();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Positions the cursor when clicked.
|
|
|
|
|
|
|
|
|
|
int CEdit::MouseDetect(Math::Point mouse)
|
|
|
|
|
{
|
|
|
|
|
Math::Point pos;
|
2013-05-01 11:19:10 +00:00
|
|
|
|
float indentLength = 0.0f, offset, size;
|
2012-06-26 20:23:05 +00:00
|
|
|
|
int i, len, c;
|
|
|
|
|
bool bTitle;
|
|
|
|
|
|
|
|
|
|
if ( m_bAutoIndent )
|
|
|
|
|
{
|
2012-08-20 12:05:36 +00:00
|
|
|
|
indentLength = m_engine->GetText()->GetCharWidth(static_cast<Gfx::UTF8Char>(' '), m_fontType, m_fontSize, 0.0f)
|
|
|
|
|
* m_engine->GetEditIndentValue();
|
2012-06-26 20:23:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pos.y = m_pos.y+m_dim.y-m_lineHeight-(m_bMulti?MARGY:MARGY1);
|
|
|
|
|
for ( i=m_lineFirst ; i<m_lineTotal ; i++ )
|
|
|
|
|
{
|
2012-08-31 20:28:07 +00:00
|
|
|
|
bTitle = ( m_format.size() > 0 && (m_format[m_lineOffset[i]]&Gfx::FONT_MASK_TITLE) == Gfx::FONT_TITLE_BIG );
|
2012-06-26 20:23:05 +00:00
|
|
|
|
|
|
|
|
|
if ( i >= m_lineFirst+m_lineVisible ) break;
|
|
|
|
|
|
|
|
|
|
pos.x = m_pos.x+(10.0f/640.0f);
|
|
|
|
|
if ( m_bAutoIndent )
|
|
|
|
|
{
|
|
|
|
|
pos.x += indentLength*m_lineIndent[i];
|
|
|
|
|
}
|
|
|
|
|
offset = mouse.x-pos.x;
|
|
|
|
|
|
|
|
|
|
if ( bTitle ) pos.y -= m_lineHeight;
|
|
|
|
|
|
|
|
|
|
if ( mouse.y > pos.y )
|
|
|
|
|
{
|
|
|
|
|
len = m_lineOffset[i+1] - m_lineOffset[i];
|
|
|
|
|
|
2012-08-31 20:28:07 +00:00
|
|
|
|
if ( m_format.size() == 0 )
|
2012-06-26 20:23:05 +00:00
|
|
|
|
{
|
2015-07-15 17:52:44 +00:00
|
|
|
|
// c = m_engine->GetText()->Detect(m_text.data()+m_lineOffset[i],
|
2012-08-20 12:05:36 +00:00
|
|
|
|
// len, offset, m_fontSize,
|
|
|
|
|
// m_fontStretch, m_fontType);
|
2015-07-15 17:52:44 +00:00
|
|
|
|
c = m_engine->GetText()->Detect(std::string(m_text.data()+m_lineOffset[i]).substr(0, len), m_fontType, m_fontSize, offset); // TODO check if good
|
2012-06-26 20:23:05 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
size = m_fontSize;
|
2012-08-20 12:05:36 +00:00
|
|
|
|
if ( bTitle ) size *= Gfx::FONT_SIZE_BIG;
|
2012-06-26 20:23:05 +00:00
|
|
|
|
|
2015-07-15 17:52:44 +00:00
|
|
|
|
// c = m_engine->GetText()->Detect(m_text.data()+m_lineOffset[i],
|
2012-08-20 12:05:36 +00:00
|
|
|
|
// m_format+m_lineOffset[i],
|
|
|
|
|
// len, offset, size,
|
|
|
|
|
// m_fontStretch);
|
2015-07-15 17:52:44 +00:00
|
|
|
|
c = m_engine->GetText()->Detect(std::string(m_text.data()+m_lineOffset[i]).substr(0, len),
|
2013-02-09 22:49:38 +00:00
|
|
|
|
m_format.begin() + m_lineOffset[i],
|
2013-02-24 00:40:55 +00:00
|
|
|
|
m_format.end(),
|
2012-08-31 20:28:07 +00:00
|
|
|
|
size,
|
|
|
|
|
offset); // TODO check if good
|
2012-06-26 20:23:05 +00:00
|
|
|
|
}
|
|
|
|
|
return m_lineOffset[i]+c;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( bTitle ) i ++;
|
|
|
|
|
pos.y -= m_lineHeight;
|
|
|
|
|
}
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Clears all history.
|
|
|
|
|
|
|
|
|
|
void CEdit::HyperFlush()
|
|
|
|
|
{
|
|
|
|
|
m_historyTotal = 0;
|
|
|
|
|
m_historyCurrent = -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Indicates which is the home page.
|
|
|
|
|
|
2013-03-17 18:01:32 +00:00
|
|
|
|
void CEdit::HyperHome(std::string filename)
|
2012-06-26 20:23:05 +00:00
|
|
|
|
{
|
|
|
|
|
HyperFlush();
|
|
|
|
|
HyperAdd(filename, 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Performs a hyper jump through a link.
|
|
|
|
|
|
2013-03-17 18:01:32 +00:00
|
|
|
|
void CEdit::HyperJump(std::string name, std::string marker)
|
2012-06-26 20:23:05 +00:00
|
|
|
|
{
|
|
|
|
|
if ( m_historyCurrent >= 0 )
|
|
|
|
|
{
|
|
|
|
|
m_history[m_historyCurrent].firstLine = m_lineFirst;
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-13 12:14:11 +00:00
|
|
|
|
std::string filename = name + std::string(".txt");
|
2015-08-05 17:27:26 +00:00
|
|
|
|
filename = InjectLevelPathsForCurrentLevel(filename, "help/%lng%");
|
2014-07-11 14:40:07 +00:00
|
|
|
|
boost::replace_all(filename, "\\", "/"); //TODO: Fix this in files
|
2013-05-26 15:47:54 +00:00
|
|
|
|
|
2012-06-26 20:23:05 +00:00
|
|
|
|
if ( ReadText(filename) )
|
|
|
|
|
{
|
|
|
|
|
Justif();
|
|
|
|
|
|
2015-08-13 12:14:11 +00:00
|
|
|
|
int line = 0;
|
|
|
|
|
auto it = std::find_if(m_marker.begin(), m_marker.end(), [&marker](HyperMarker hyperMarker) { return hyperMarker.name == marker; });
|
|
|
|
|
if(it != m_marker.end())
|
2012-06-26 20:23:05 +00:00
|
|
|
|
{
|
2015-08-13 12:14:11 +00:00
|
|
|
|
int pos = it->pos;
|
|
|
|
|
for ( int i=0 ; i<m_lineTotal ; i++ )
|
2012-06-26 20:23:05 +00:00
|
|
|
|
{
|
2015-08-13 12:14:11 +00:00
|
|
|
|
if ( pos >= m_lineOffset[i] )
|
2012-06-26 20:23:05 +00:00
|
|
|
|
{
|
2015-08-13 12:14:11 +00:00
|
|
|
|
line = i;
|
2012-06-26 20:23:05 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SetFirstLine(line);
|
|
|
|
|
HyperAdd(filename, line);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Adds text to the history of visited.
|
|
|
|
|
|
2013-03-17 18:01:32 +00:00
|
|
|
|
bool CEdit::HyperAdd(std::string filename, int firstLine)
|
2012-06-26 20:23:05 +00:00
|
|
|
|
{
|
|
|
|
|
if ( m_historyCurrent >= EDITHISTORYMAX-1 ) return false;
|
|
|
|
|
|
|
|
|
|
m_historyCurrent ++;
|
2013-03-17 18:01:32 +00:00
|
|
|
|
m_history[m_historyCurrent].filename = filename;
|
2012-06-26 20:23:05 +00:00
|
|
|
|
m_history[m_historyCurrent].firstLine = firstLine;
|
|
|
|
|
|
|
|
|
|
m_historyTotal = m_historyCurrent+1;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Indicates whether a button EVENT_HYPER_ * is active or not.
|
|
|
|
|
|
2012-08-20 12:05:36 +00:00
|
|
|
|
bool CEdit::HyperTest(EventType event)
|
2012-06-26 20:23:05 +00:00
|
|
|
|
{
|
|
|
|
|
if ( event == EVENT_HYPER_HOME )
|
|
|
|
|
{
|
|
|
|
|
return ( m_historyCurrent > 0 );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( event == EVENT_HYPER_PREV )
|
|
|
|
|
{
|
|
|
|
|
return ( m_historyCurrent > 0 );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( event == EVENT_HYPER_NEXT )
|
|
|
|
|
{
|
|
|
|
|
return ( m_historyCurrent < m_historyTotal-1 );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Performs the action corresponding to a button EVENT_HYPER_ *.
|
|
|
|
|
|
2012-08-20 12:05:36 +00:00
|
|
|
|
bool CEdit::HyperGo(EventType event)
|
2012-06-26 20:23:05 +00:00
|
|
|
|
{
|
|
|
|
|
if ( !HyperTest(event) ) return false;
|
|
|
|
|
|
|
|
|
|
m_history[m_historyCurrent].firstLine = m_lineFirst;
|
|
|
|
|
|
|
|
|
|
if ( event == EVENT_HYPER_HOME )
|
|
|
|
|
{
|
|
|
|
|
m_historyCurrent = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( event == EVENT_HYPER_PREV )
|
|
|
|
|
{
|
|
|
|
|
m_historyCurrent --;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( event == EVENT_HYPER_NEXT )
|
|
|
|
|
{
|
|
|
|
|
m_historyCurrent ++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ReadText(m_history[m_historyCurrent].filename);
|
|
|
|
|
Justif();
|
|
|
|
|
SetFirstLine(m_history[m_historyCurrent].firstLine);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Draw the editable line.
|
|
|
|
|
|
|
|
|
|
void CEdit::Draw()
|
|
|
|
|
{
|
|
|
|
|
Math::Point pos, ppos, dim, start, end;
|
2013-05-01 11:19:10 +00:00
|
|
|
|
float size = 0.0f, indentLength = 0.0f;
|
2015-08-13 12:14:11 +00:00
|
|
|
|
int i, j, beg, len, c1, c2, o1, o2, eol, line;
|
2012-06-26 20:23:05 +00:00
|
|
|
|
|
|
|
|
|
if ( (m_state & STATE_VISIBLE) == 0 ) return;
|
|
|
|
|
|
|
|
|
|
if ( m_state & STATE_SHADOW )
|
|
|
|
|
{
|
|
|
|
|
DrawShadow(m_pos, m_dim);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pos.x = m_pos.x;
|
|
|
|
|
pos.y = m_pos.y;
|
|
|
|
|
dim.x = m_dim.x;
|
|
|
|
|
if ( !m_bInsideScroll ) dim.x -= m_bMulti?SCROLL_WIDTH:0.0f;
|
|
|
|
|
dim.y = m_dim.y;
|
|
|
|
|
DrawBack(pos, dim); // background
|
|
|
|
|
|
|
|
|
|
// Displays all lines.
|
|
|
|
|
c1 = m_cursor1;
|
|
|
|
|
c2 = m_cursor2;
|
|
|
|
|
if ( c1 > c2 ) Math::Swap(c1, c2); // always c1 <= c2
|
|
|
|
|
|
|
|
|
|
if ( m_bInsideScroll )
|
|
|
|
|
{
|
|
|
|
|
dim.x -= m_bMulti?SCROLL_WIDTH:0.0f + (1.0f/640.0f);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( m_bAutoIndent )
|
|
|
|
|
{
|
2012-08-20 12:05:36 +00:00
|
|
|
|
indentLength = m_engine->GetText()->GetCharWidth(static_cast<Gfx::UTF8Char>(' '), m_fontType, m_fontSize, 0.0f)
|
|
|
|
|
* m_engine->GetEditIndentValue();
|
2012-06-26 20:23:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pos.y = m_pos.y+m_dim.y-m_lineHeight-(m_bMulti?MARGY:MARGY1);
|
|
|
|
|
for ( i=m_lineFirst ; i<m_lineTotal ; i++ )
|
|
|
|
|
{
|
|
|
|
|
if ( i == m_lineFirst && i < m_lineTotal-1 &&
|
|
|
|
|
m_lineOffset[i] == m_lineOffset[i+1] )
|
|
|
|
|
{
|
|
|
|
|
pos.y -= m_lineHeight; // Double jump line \b;
|
|
|
|
|
i ++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( i >= m_lineFirst+m_lineVisible ) break;
|
|
|
|
|
|
|
|
|
|
pos.x = m_pos.x+(10.0f/640.0f);
|
|
|
|
|
if ( m_bAutoIndent )
|
|
|
|
|
{
|
2013-02-09 20:00:07 +00:00
|
|
|
|
const char *s = "\t"; // line | dotted
|
2012-06-26 20:23:05 +00:00
|
|
|
|
for ( j=0 ; j<m_lineIndent[i] ; j++ )
|
|
|
|
|
{
|
2013-02-09 20:00:07 +00:00
|
|
|
|
m_engine->GetText()->DrawText(s, m_fontType, m_fontSize, pos, 1.0f, Gfx::TEXT_ALIGN_LEFT, 0);
|
2012-06-26 20:23:05 +00:00
|
|
|
|
pos.x += indentLength;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
beg = m_lineOffset[i];
|
|
|
|
|
len = m_lineOffset[i+1] - m_lineOffset[i];
|
|
|
|
|
|
|
|
|
|
ppos = pos;
|
|
|
|
|
size = m_fontSize;
|
|
|
|
|
|
|
|
|
|
// Headline \b;?
|
2013-02-09 22:49:38 +00:00
|
|
|
|
if ( beg+len < m_len && m_format.size() > static_cast<unsigned int>(beg) &&
|
2012-08-20 12:05:36 +00:00
|
|
|
|
(m_format[beg]&Gfx::FONT_MASK_TITLE) == Gfx::FONT_TITLE_BIG )
|
2012-06-26 20:23:05 +00:00
|
|
|
|
{
|
|
|
|
|
start.x = ppos.x-MARGX;
|
|
|
|
|
end.x = dim.x-MARGX*2.0f;
|
|
|
|
|
start.y = ppos.y-(m_bMulti?0.0f:MARGY1)-m_lineHeight*(BIG_FONT-1.0f);
|
|
|
|
|
end.y = m_lineHeight*BIG_FONT;
|
|
|
|
|
DrawPart(start, end, 2); // blue gradient background ->
|
|
|
|
|
|
|
|
|
|
size *= BIG_FONT;
|
|
|
|
|
ppos.y -= m_lineHeight*(BIG_FONT-1.0f);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// As \t;?
|
2013-02-09 22:49:38 +00:00
|
|
|
|
if ( beg+len < m_len && m_format.size() > static_cast<unsigned int>(beg) &&
|
2012-08-20 12:05:36 +00:00
|
|
|
|
(m_format[beg]&Gfx::FONT_MASK_TITLE) == Gfx::FONT_TITLE_NORM )
|
2012-06-26 20:23:05 +00:00
|
|
|
|
{
|
|
|
|
|
start.x = ppos.x-MARGX;
|
|
|
|
|
end.x = dim.x-MARGX*2.0f;
|
|
|
|
|
start.y = ppos.y-(m_bMulti?0.0f:MARGY1);
|
|
|
|
|
end.y = m_lineHeight;
|
|
|
|
|
DrawPart(start, end, 2); // blue gradient background ->
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Subtitle \s;?
|
2013-02-09 22:49:38 +00:00
|
|
|
|
if ( beg+len < m_len && m_format.size() > static_cast<unsigned int>(beg) &&
|
2012-08-20 12:05:36 +00:00
|
|
|
|
(m_format[beg]&Gfx::FONT_MASK_TITLE) == Gfx::FONT_TITLE_LITTLE )
|
2012-06-26 20:23:05 +00:00
|
|
|
|
{
|
|
|
|
|
start.x = ppos.x-MARGX;
|
|
|
|
|
end.x = dim.x-MARGX*2.0f;
|
|
|
|
|
start.y = ppos.y-(m_bMulti?0.0f:MARGY1);
|
|
|
|
|
end.y = m_lineHeight;
|
|
|
|
|
DrawPart(start, end, 3); // yellow background gradient ->
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Table \tab;?
|
2013-02-09 22:49:38 +00:00
|
|
|
|
if ( beg+len < m_len && m_format.size() > static_cast<unsigned int>(beg) &&
|
2012-08-20 12:05:36 +00:00
|
|
|
|
(m_format[beg]&Gfx::FONT_MASK_HIGHLIGHT) == Gfx::FONT_HIGHLIGHT_TABLE )
|
2012-06-26 20:23:05 +00:00
|
|
|
|
{
|
|
|
|
|
start.x = ppos.x-MARGX;
|
|
|
|
|
end.x = dim.x-MARGX*2.0f;
|
|
|
|
|
start.y = ppos.y-(m_bMulti?0.0f:MARGY1);
|
|
|
|
|
end.y = m_lineHeight;
|
|
|
|
|
DrawPart(start, end, 11); // fond orange d<>grad<61> ->
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Image \image; ?
|
2013-02-09 22:49:38 +00:00
|
|
|
|
if ( beg+len < m_len && m_format.size() > static_cast<unsigned int>(beg) &&
|
2012-08-20 12:05:36 +00:00
|
|
|
|
(m_format[beg]&Gfx::FONT_MASK_IMAGE) != 0 )
|
2012-06-26 20:23:05 +00:00
|
|
|
|
{
|
|
|
|
|
line = 1;
|
|
|
|
|
while ( true ) // includes the image slices
|
|
|
|
|
{
|
|
|
|
|
if ( i+line >= m_lineTotal ||
|
|
|
|
|
i+line >= m_lineFirst+m_lineVisible ||
|
2013-02-09 22:49:38 +00:00
|
|
|
|
(m_format.size() > static_cast<unsigned int>(beg+line) && m_format[beg+line]&Gfx::FONT_MASK_IMAGE) == 0 ) break;
|
2012-06-26 20:23:05 +00:00
|
|
|
|
line ++;
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-13 12:14:11 +00:00
|
|
|
|
unsigned int iIndex = m_text[beg]; // character = index in m_image
|
|
|
|
|
assert(iIndex < m_image.size());
|
2012-06-26 20:23:05 +00:00
|
|
|
|
pos.y -= m_lineHeight*(line-1);
|
|
|
|
|
DrawImage(pos, m_image[iIndex].name,
|
2012-08-20 12:05:36 +00:00
|
|
|
|
m_image[iIndex].width*(m_fontSize/Gfx::FONT_SIZE_SMALL),
|
2012-06-26 20:23:05 +00:00
|
|
|
|
m_image[iIndex].offset, m_image[iIndex].height*line, line);
|
|
|
|
|
pos.y -= m_lineHeight;
|
|
|
|
|
i += line-1;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( ((m_bEdit && m_bFocus && m_bHilite) ||
|
|
|
|
|
(!m_bEdit && m_bHilite) ) &&
|
|
|
|
|
c1 != c2 && beg <= c2 && beg+len >= c1 ) // selected area?
|
|
|
|
|
{
|
|
|
|
|
o1 = c1; if ( o1 < beg ) o1 = beg;
|
|
|
|
|
o2 = c2; if ( o2 > beg+len ) o2 = beg+len;
|
|
|
|
|
|
2012-08-31 20:28:07 +00:00
|
|
|
|
if ( m_format.size() == 0 )
|
2012-06-26 20:23:05 +00:00
|
|
|
|
{
|
2015-07-15 17:52:44 +00:00
|
|
|
|
start.x = ppos.x+m_engine->GetText()->GetStringWidth(std::string(m_text.data()+beg).substr(0, o1-beg), m_fontType, size);
|
|
|
|
|
end.x = m_engine->GetText()->GetStringWidth(std::string(m_text.data()+o1).substr(0, o2-o1), m_fontType, size);
|
2012-06-26 20:23:05 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2015-07-15 17:52:44 +00:00
|
|
|
|
start.x = ppos.x+m_engine->GetText()->GetStringWidth(std::string(m_text.data()+beg).substr(0, o1-beg),
|
2013-02-09 22:49:38 +00:00
|
|
|
|
m_format.begin() + beg,
|
2013-02-24 00:40:55 +00:00
|
|
|
|
m_format.end(),
|
2012-08-31 20:28:07 +00:00
|
|
|
|
size);
|
2015-07-15 17:52:44 +00:00
|
|
|
|
end.x = m_engine->GetText()->GetStringWidth(std::string(m_text.data()+o1).substr(0, o2-o1),
|
2013-02-09 22:49:38 +00:00
|
|
|
|
m_format.begin() + o1,
|
2013-02-24 00:40:55 +00:00
|
|
|
|
m_format.end(),
|
2012-08-31 20:28:07 +00:00
|
|
|
|
size);
|
2012-06-26 20:23:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
start.y = ppos.y-(m_bMulti?0.0f:MARGY1);
|
|
|
|
|
end.y = m_lineHeight;
|
2013-02-09 22:49:38 +00:00
|
|
|
|
if ( m_format.size() > static_cast<unsigned int>(beg) && (m_format[beg]&Gfx::FONT_MASK_TITLE) == Gfx::FONT_TITLE_BIG) end.y *= BIG_FONT;
|
2012-06-26 20:23:05 +00:00
|
|
|
|
DrawPart(start, end, 1); // plain yellow background
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
eol = 16; // >
|
|
|
|
|
if ( len > 0 && m_text[beg+len-1] == '\n' )
|
|
|
|
|
{
|
|
|
|
|
len --; // does not display the '\ n'
|
|
|
|
|
eol = 0; // nothing
|
|
|
|
|
}
|
|
|
|
|
if ( beg+len >= m_len )
|
|
|
|
|
{
|
|
|
|
|
eol = 2; // square (eot)
|
|
|
|
|
}
|
|
|
|
|
if ( !m_bMulti || !m_bDisplaySpec ) eol = 0;
|
2012-08-31 20:28:07 +00:00
|
|
|
|
if ( m_format.size() == 0 )
|
2012-06-26 20:23:05 +00:00
|
|
|
|
{
|
2015-07-15 17:52:44 +00:00
|
|
|
|
m_engine->GetText()->DrawText(std::string(m_text.data()+beg).substr(0, len), m_fontType, size, ppos, m_dim.x, Gfx::TEXT_ALIGN_LEFT, eol);
|
2012-06-26 20:23:05 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2015-07-15 17:52:44 +00:00
|
|
|
|
m_engine->GetText()->DrawText(std::string(m_text.data()+beg).substr(0, len),
|
2013-02-09 22:49:38 +00:00
|
|
|
|
m_format.begin() + beg,
|
2013-02-24 00:40:55 +00:00
|
|
|
|
m_format.end(),
|
2012-08-31 20:28:07 +00:00
|
|
|
|
size,
|
|
|
|
|
ppos,
|
|
|
|
|
m_dim.x,
|
2012-09-18 15:52:36 +00:00
|
|
|
|
Gfx::TEXT_ALIGN_LEFT,
|
2012-08-31 20:28:07 +00:00
|
|
|
|
eol);
|
2012-06-26 20:23:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pos.y -= m_lineHeight;
|
|
|
|
|
|
|
|
|
|
if ( i < m_lineTotal-2 && m_lineOffset[i+1] == m_lineOffset[i+2] )
|
|
|
|
|
{
|
|
|
|
|
pos.y -= m_lineHeight; // double jump line \b;
|
|
|
|
|
i ++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Shows the cursor.
|
|
|
|
|
if ( (m_bEdit && m_bFocus && m_bHilite && Math::Mod(m_timeBlink, 1.0f) <= 0.5f) ) // it blinks
|
|
|
|
|
{
|
|
|
|
|
pos.y = m_pos.y+m_dim.y-m_lineHeight-(m_bMulti?MARGY:MARGY1*2.0f);
|
|
|
|
|
for ( i=m_lineFirst ; i<m_lineTotal ; i++ )
|
|
|
|
|
{
|
|
|
|
|
if ( i == m_lineTotal-1 || m_cursor1 < m_lineOffset[i+1] )
|
|
|
|
|
{
|
|
|
|
|
pos.x = m_pos.x+(10.0f/640.0f);
|
|
|
|
|
if ( m_bAutoIndent )
|
|
|
|
|
{
|
|
|
|
|
pos.x += indentLength*m_lineIndent[i];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
len = m_cursor1 - m_lineOffset[i];
|
|
|
|
|
|
2012-08-31 20:28:07 +00:00
|
|
|
|
if ( m_format.size() == 0 )
|
2012-06-26 20:23:05 +00:00
|
|
|
|
{
|
2015-07-15 17:52:44 +00:00
|
|
|
|
m_engine->GetText()->SizeText(std::string(m_text.data()+m_lineOffset[i]).substr(0, len), m_fontType,
|
2012-09-29 17:29:17 +00:00
|
|
|
|
size, pos, Gfx::TEXT_ALIGN_LEFT,
|
|
|
|
|
start, end);
|
2012-06-26 20:23:05 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2015-07-15 17:52:44 +00:00
|
|
|
|
m_engine->GetText()->SizeText(std::string(m_text.data()+m_lineOffset[i]).substr(0, len),
|
2013-02-09 22:49:38 +00:00
|
|
|
|
m_format.begin() + m_lineOffset[i],
|
2013-02-24 00:40:55 +00:00
|
|
|
|
m_format.end(),
|
2012-09-29 17:29:17 +00:00
|
|
|
|
size, pos, Gfx::TEXT_ALIGN_LEFT,
|
|
|
|
|
start, end);
|
2012-06-26 20:23:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pos.x = end.x;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
pos.y -= m_lineHeight;
|
|
|
|
|
}
|
2012-08-20 12:05:36 +00:00
|
|
|
|
pos.x -= 1.0f / 640.0f;
|
|
|
|
|
dim.x = 2.0f / 640.0f;
|
2012-06-26 20:23:05 +00:00
|
|
|
|
dim.y = m_lineHeight;
|
|
|
|
|
DrawPart(pos, dim, 0); // red
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-11 20:47:07 +00:00
|
|
|
|
if (m_scroll != nullptr && !m_bGeneric)
|
2012-06-26 20:23:05 +00:00
|
|
|
|
{
|
|
|
|
|
m_scroll->Draw();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Draw an image part.
|
|
|
|
|
|
2013-03-17 18:01:32 +00:00
|
|
|
|
void CEdit::DrawImage(Math::Point pos, std::string name, float width,
|
2012-06-26 20:23:05 +00:00
|
|
|
|
float offset, float height, int nbLine)
|
|
|
|
|
{
|
2013-03-17 18:01:32 +00:00
|
|
|
|
Math::Point uv1, uv2, dim;
|
|
|
|
|
float dp;
|
|
|
|
|
std::string filename;
|
2012-06-26 20:23:05 +00:00
|
|
|
|
|
2014-06-20 21:41:38 +00:00
|
|
|
|
filename = name + ".png";
|
2015-08-05 17:27:26 +00:00
|
|
|
|
filename = InjectLevelPathsForCurrentLevel(filename, "icons");
|
2014-07-11 14:40:07 +00:00
|
|
|
|
boost::replace_all(filename, "\\", "/"); //TODO: Fix this in files
|
2012-06-26 20:23:05 +00:00
|
|
|
|
|
|
|
|
|
m_engine->SetTexture(filename);
|
2012-08-20 12:05:36 +00:00
|
|
|
|
m_engine->SetState(Gfx::ENG_RSTATE_NORMAL);
|
2012-06-26 20:23:05 +00:00
|
|
|
|
|
|
|
|
|
uv1.x = 0.0f;
|
|
|
|
|
uv2.x = 1.0f;
|
|
|
|
|
uv1.y = offset;
|
|
|
|
|
uv2.y = offset+height;
|
|
|
|
|
|
|
|
|
|
dp = 0.5f/256.0f;
|
|
|
|
|
uv1.x += dp;
|
|
|
|
|
uv1.y += dp;
|
|
|
|
|
uv2.x -= dp;
|
|
|
|
|
uv2.y -= dp;
|
|
|
|
|
|
|
|
|
|
dim.x = width;
|
|
|
|
|
dim.y = m_lineHeight*nbLine;
|
|
|
|
|
DrawIcon(pos, dim, uv1, uv2);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Draw the background.
|
|
|
|
|
|
|
|
|
|
void CEdit::DrawBack(Math::Point pos, Math::Point dim)
|
|
|
|
|
{
|
|
|
|
|
Math::Point uv1,uv2, corner;
|
|
|
|
|
float dp;
|
|
|
|
|
|
|
|
|
|
if ( m_bGeneric ) return;
|
|
|
|
|
|
2014-07-24 20:17:49 +00:00
|
|
|
|
m_engine->SetTexture("textures/interface/button2.png");
|
2012-08-20 12:05:36 +00:00
|
|
|
|
m_engine->SetState(Gfx::ENG_RSTATE_NORMAL);
|
2012-06-26 20:23:05 +00:00
|
|
|
|
|
|
|
|
|
if ( m_bMulti )
|
|
|
|
|
{
|
|
|
|
|
uv1.x = 128.0f/256.0f; // light blue
|
|
|
|
|
uv1.y = 64.0f/256.0f;
|
|
|
|
|
uv2.x = 160.0f/256.0f;
|
|
|
|
|
uv2.y = 96.0f/256.0f;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
uv1.x = 160.0f/256.0f; // medium blue
|
|
|
|
|
uv1.y = 192.0f/256.0f;
|
|
|
|
|
uv2.x = 192.0f/256.0f;
|
|
|
|
|
uv2.y = 224.0f/256.0f;
|
|
|
|
|
}
|
|
|
|
|
if ( m_icon == 1 )
|
|
|
|
|
{
|
|
|
|
|
uv1.x = 192.0f/256.0f; // orange
|
|
|
|
|
uv1.y = 96.0f/256.0f;
|
|
|
|
|
uv2.x = 224.0f/256.0f;
|
|
|
|
|
uv2.y = 128.0f/256.0f;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
dp = 0.5f/256.0f;
|
|
|
|
|
uv1.x += dp;
|
|
|
|
|
uv1.y += dp;
|
|
|
|
|
uv2.x -= dp;
|
|
|
|
|
uv2.y -= dp;
|
|
|
|
|
|
|
|
|
|
if ( m_bMulti )
|
|
|
|
|
{
|
|
|
|
|
corner.x = 10.0f/640.0f;
|
|
|
|
|
corner.y = 10.0f/480.0f;
|
|
|
|
|
DrawIcon(pos, dim, uv1, uv2, corner, 8.0f/256.0f);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
DrawIcon(pos, dim, uv1, uv2, 8.0f/256.0f);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Draws an icon background.
|
|
|
|
|
|
|
|
|
|
void CEdit::DrawPart(Math::Point pos, Math::Point dim, int icon)
|
|
|
|
|
{
|
|
|
|
|
Math::Point uv1, uv2;
|
|
|
|
|
float dp;
|
|
|
|
|
|
2015-08-06 20:41:54 +00:00
|
|
|
|
m_engine->SetTexture("textures/effect03.png");
|
2012-08-20 12:05:36 +00:00
|
|
|
|
m_engine->SetState(Gfx::ENG_RSTATE_NORMAL);
|
2012-06-26 20:23:05 +00:00
|
|
|
|
|
|
|
|
|
uv1.x = (16.0f/256.0f)*(icon%16);
|
|
|
|
|
uv1.y = (240.0f/256.0f);
|
|
|
|
|
uv2.x = (16.0f/256.0f)+uv1.x;
|
|
|
|
|
uv2.y = (16.0f/256.0f)+uv1.y;
|
|
|
|
|
|
|
|
|
|
dp = 0.5f/256.0f;
|
|
|
|
|
uv1.x += dp;
|
|
|
|
|
uv1.y += dp;
|
|
|
|
|
uv2.x -= dp;
|
|
|
|
|
uv2.y -= dp;
|
|
|
|
|
|
|
|
|
|
DrawIcon(pos, dim, uv1, uv2);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Give the text to edit.
|
|
|
|
|
|
2012-08-31 20:28:07 +00:00
|
|
|
|
void CEdit::SetText(const char *text, bool bNew)
|
2012-06-26 20:23:05 +00:00
|
|
|
|
{
|
|
|
|
|
int i, j, font;
|
|
|
|
|
bool bBOL;
|
2013-05-26 15:47:54 +00:00
|
|
|
|
|
2012-06-26 20:23:05 +00:00
|
|
|
|
if ( !bNew ) UndoMemorize(OPERUNDO_SPEC);
|
|
|
|
|
|
|
|
|
|
m_len = strlen(text);
|
|
|
|
|
if ( m_len > m_maxChar ) m_len = m_maxChar;
|
|
|
|
|
|
2012-08-31 20:28:07 +00:00
|
|
|
|
if ( m_format.size() == 0 )
|
2012-06-26 20:23:05 +00:00
|
|
|
|
{
|
|
|
|
|
if ( m_bAutoIndent )
|
|
|
|
|
{
|
|
|
|
|
j = 0;
|
|
|
|
|
bBOL = true;
|
|
|
|
|
for ( i=0 ; i<m_len ; i++ )
|
|
|
|
|
{
|
|
|
|
|
if ( text[i] == '\t' )
|
|
|
|
|
{
|
|
|
|
|
if ( !bBOL ) m_text[j++] = ' ';
|
|
|
|
|
continue; // removes tabs
|
|
|
|
|
}
|
|
|
|
|
bBOL = ( text[i] == '\n' );
|
|
|
|
|
|
|
|
|
|
m_text[j++] = text[i];
|
|
|
|
|
}
|
|
|
|
|
m_len = j;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2015-07-15 17:52:44 +00:00
|
|
|
|
strncpy(m_text.data(), text, m_len);
|
2012-06-26 20:23:05 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
font = m_fontType;
|
|
|
|
|
j = 0;
|
|
|
|
|
bBOL = true;
|
|
|
|
|
for ( i=0 ; i<m_len ; i++ )
|
|
|
|
|
{
|
|
|
|
|
if ( m_bAutoIndent )
|
|
|
|
|
{
|
|
|
|
|
if ( text[i] == '\t' )
|
|
|
|
|
{
|
|
|
|
|
if ( !bBOL )
|
|
|
|
|
{
|
|
|
|
|
m_text[j] = ' ';
|
|
|
|
|
m_format[j] = font;
|
|
|
|
|
j ++;
|
|
|
|
|
}
|
|
|
|
|
continue; // removes tabs
|
|
|
|
|
}
|
|
|
|
|
bBOL = ( text[i] == '\n' );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( text[i] == '\\' && text[i+2] == ';' )
|
|
|
|
|
{
|
|
|
|
|
if ( text[i+1] == 'n' ) // normal ?
|
|
|
|
|
{
|
2012-08-20 12:05:36 +00:00
|
|
|
|
font &= ~Gfx::FONT_MASK_FONT;
|
|
|
|
|
font |= Gfx::FONT_COLOBOT;
|
2012-06-26 20:23:05 +00:00
|
|
|
|
i += 2;
|
|
|
|
|
}
|
|
|
|
|
else if ( text[i+1] == 'c' ) // cbot ?
|
|
|
|
|
{
|
2012-08-20 12:05:36 +00:00
|
|
|
|
font &= ~Gfx::FONT_MASK_FONT;
|
|
|
|
|
font |= Gfx::FONT_COURIER;
|
2012-06-26 20:23:05 +00:00
|
|
|
|
i += 2;
|
|
|
|
|
}
|
|
|
|
|
else if ( text[i+1] == 'b' ) // big title ?
|
|
|
|
|
{
|
2012-08-20 12:05:36 +00:00
|
|
|
|
font &= ~Gfx::FONT_MASK_TITLE;
|
|
|
|
|
font |= Gfx::FONT_TITLE_BIG;
|
2012-06-26 20:23:05 +00:00
|
|
|
|
i += 2;
|
|
|
|
|
}
|
|
|
|
|
else if ( text[i+1] == 't' ) // title ?
|
|
|
|
|
{
|
2012-08-20 12:05:36 +00:00
|
|
|
|
font &= ~Gfx::FONT_MASK_TITLE;
|
|
|
|
|
font |= Gfx::FONT_TITLE_NORM;
|
2012-06-26 20:23:05 +00:00
|
|
|
|
i += 2;
|
|
|
|
|
}
|
|
|
|
|
else if ( text[i+1] == 's' ) // subtitle ?
|
|
|
|
|
{
|
2012-08-20 12:05:36 +00:00
|
|
|
|
font &= ~Gfx::FONT_MASK_TITLE;
|
|
|
|
|
font |= Gfx::FONT_TITLE_LITTLE;
|
2012-06-26 20:23:05 +00:00
|
|
|
|
i += 2;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
m_text[j] = text[i];
|
|
|
|
|
m_format[j] = font;
|
|
|
|
|
j ++;
|
|
|
|
|
|
2012-08-20 12:05:36 +00:00
|
|
|
|
font &= ~Gfx::FONT_MASK_TITLE; // reset title
|
2012-06-26 20:23:05 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
m_len = j;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( bNew ) UndoFlush();
|
|
|
|
|
|
|
|
|
|
m_cursor1 = 0;
|
|
|
|
|
m_cursor2 = 0; // cursor to the beginning
|
|
|
|
|
Justif();
|
|
|
|
|
ColumnFix();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Returns a pointer to the edited text.
|
|
|
|
|
|
2012-08-20 12:05:36 +00:00
|
|
|
|
char* CEdit::GetText()
|
2012-06-26 20:23:05 +00:00
|
|
|
|
{
|
|
|
|
|
m_text[m_len] = 0;
|
2015-07-15 17:52:44 +00:00
|
|
|
|
return m_text.data();
|
2012-06-26 20:23:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Returns the edited text.
|
|
|
|
|
|
|
|
|
|
void CEdit::GetText(char *buffer, int max)
|
|
|
|
|
{
|
|
|
|
|
if ( m_len < max ) max = m_len;
|
|
|
|
|
if ( m_len > max ) max = max-1;
|
|
|
|
|
|
2015-07-15 17:52:44 +00:00
|
|
|
|
strncpy(buffer, m_text.data(), max);
|
2012-06-26 20:23:05 +00:00
|
|
|
|
buffer[max] = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Returns the length of the text.
|
|
|
|
|
|
2012-08-20 12:05:36 +00:00
|
|
|
|
int CEdit::GetTextLength()
|
2012-06-26 20:23:05 +00:00
|
|
|
|
{
|
|
|
|
|
return m_len;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Returns a name in a command.
|
|
|
|
|
// \x nom1 nom2 nom3;
|
|
|
|
|
|
2013-03-17 18:01:32 +00:00
|
|
|
|
std::string GetNameParam(std::string cmd, int rank)
|
2012-06-26 20:23:05 +00:00
|
|
|
|
{
|
2013-05-26 15:47:54 +00:00
|
|
|
|
std::vector<std::string> results;
|
2013-03-17 18:01:32 +00:00
|
|
|
|
boost::split(results, cmd, boost::is_any_of(" ;"));
|
2013-05-26 15:47:54 +00:00
|
|
|
|
|
|
|
|
|
if (results.size() > static_cast<unsigned int>(rank))
|
|
|
|
|
{
|
2013-03-17 18:01:32 +00:00
|
|
|
|
return results.at(rank);
|
2012-06-26 20:23:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-03-17 18:01:32 +00:00
|
|
|
|
return "";
|
2012-06-26 20:23:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Returns a number of a command.
|
|
|
|
|
// \x nom n1 n2;
|
|
|
|
|
|
2013-03-17 18:01:32 +00:00
|
|
|
|
int GetValueParam(std::string cmd, int rank)
|
2012-06-26 20:23:05 +00:00
|
|
|
|
{
|
2013-05-26 15:47:54 +00:00
|
|
|
|
std::vector<std::string> results;
|
2013-03-17 18:01:32 +00:00
|
|
|
|
boost::split(results, cmd, boost::is_any_of(" ;"));
|
|
|
|
|
int return_value = 0;
|
2013-05-26 15:47:54 +00:00
|
|
|
|
|
|
|
|
|
if (results.size() > static_cast<unsigned int>(rank))
|
|
|
|
|
{
|
2013-03-17 22:16:26 +00:00
|
|
|
|
return_value = atoi(results.at(rank).c_str());
|
2012-06-26 20:23:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-03-17 18:01:32 +00:00
|
|
|
|
return return_value;
|
2012-06-26 20:23:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Frees all images.
|
|
|
|
|
|
|
|
|
|
void CEdit::FreeImage()
|
|
|
|
|
{
|
2015-08-13 12:14:11 +00:00
|
|
|
|
for (auto& image : m_image)
|
2013-05-26 15:47:54 +00:00
|
|
|
|
{
|
2015-08-13 12:14:11 +00:00
|
|
|
|
m_engine->DeleteTexture(image.name + ".png");
|
2012-06-26 20:23:05 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Reads the texture of an image.
|
|
|
|
|
|
2013-03-17 18:01:32 +00:00
|
|
|
|
void CEdit::LoadImage(std::string name)
|
2012-06-26 20:23:05 +00:00
|
|
|
|
{
|
2013-03-17 18:01:32 +00:00
|
|
|
|
std::string filename;
|
2014-06-20 21:41:38 +00:00
|
|
|
|
filename = name + ".png";
|
2015-08-05 17:27:26 +00:00
|
|
|
|
filename = InjectLevelPathsForCurrentLevel(filename, "icons");
|
2014-07-11 14:40:07 +00:00
|
|
|
|
boost::replace_all(filename, "\\", "/"); //TODO: Fix this in files
|
2014-07-24 20:17:49 +00:00
|
|
|
|
m_engine->LoadTexture(filename);
|
2012-06-26 20:23:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Read from a text file.
|
|
|
|
|
|
2013-03-17 18:01:32 +00:00
|
|
|
|
bool CEdit::ReadText(std::string filename, int addSize)
|
2012-06-26 20:23:05 +00:00
|
|
|
|
{
|
2015-08-13 12:14:11 +00:00
|
|
|
|
int len, i, j, n, font, iLines, iCount;
|
2012-06-26 20:23:05 +00:00
|
|
|
|
char iName[50];
|
|
|
|
|
float iWidth;
|
2012-09-19 16:32:18 +00:00
|
|
|
|
InputSlot slot;
|
2012-06-26 20:23:05 +00:00
|
|
|
|
bool bInSoluce, bBOL;
|
|
|
|
|
|
2014-07-11 14:40:07 +00:00
|
|
|
|
if ( filename == "" ) return false;
|
2015-07-05 11:00:48 +00:00
|
|
|
|
|
2014-06-20 21:41:38 +00:00
|
|
|
|
CInputStream stream;
|
2014-07-11 14:40:07 +00:00
|
|
|
|
stream.open(filename);
|
2015-07-05 11:00:48 +00:00
|
|
|
|
|
2014-06-20 21:41:38 +00:00
|
|
|
|
if (!stream.is_open())
|
2013-05-26 15:47:54 +00:00
|
|
|
|
{
|
2015-07-16 19:30:55 +00:00
|
|
|
|
GetLogger()->Error("Failed to load text file %s\n", filename.c_str());
|
2013-12-27 09:50:52 +00:00
|
|
|
|
return false;
|
|
|
|
|
}
|
2012-06-26 20:23:05 +00:00
|
|
|
|
|
2014-06-20 21:41:38 +00:00
|
|
|
|
len = stream.size();
|
2012-06-26 20:23:05 +00:00
|
|
|
|
|
|
|
|
|
m_maxChar = len+addSize+100;
|
|
|
|
|
m_len = len;
|
|
|
|
|
m_cursor1 = 0;
|
|
|
|
|
m_cursor2 = 0;
|
|
|
|
|
|
|
|
|
|
FreeImage();
|
2012-09-16 18:00:25 +00:00
|
|
|
|
|
2015-07-15 17:52:44 +00:00
|
|
|
|
m_text = std::vector<char>(m_maxChar+1, '\0');
|
2012-09-16 18:00:25 +00:00
|
|
|
|
|
2015-07-15 17:52:44 +00:00
|
|
|
|
std::vector<char> buffer(m_maxChar+1, '\0');
|
2012-09-16 18:00:25 +00:00
|
|
|
|
|
2015-07-15 17:52:44 +00:00
|
|
|
|
stream.read(buffer.data(), len);
|
2012-06-26 20:23:05 +00:00
|
|
|
|
|
2013-02-09 22:49:38 +00:00
|
|
|
|
m_format.clear();
|
|
|
|
|
m_format.reserve(m_maxChar+1);
|
2013-05-26 15:47:54 +00:00
|
|
|
|
for (i = 0; i <= m_maxChar+1; i++)
|
|
|
|
|
{
|
2015-04-23 19:01:04 +00:00
|
|
|
|
m_format.push_back(m_fontType);
|
2013-02-09 22:49:38 +00:00
|
|
|
|
}
|
2013-05-26 15:47:54 +00:00
|
|
|
|
|
2014-06-20 21:41:38 +00:00
|
|
|
|
stream.close();
|
2012-06-26 20:23:05 +00:00
|
|
|
|
|
|
|
|
|
bInSoluce = false;
|
|
|
|
|
font = m_fontType;
|
2015-08-13 12:14:11 +00:00
|
|
|
|
m_image.clear();
|
|
|
|
|
m_marker.clear();
|
|
|
|
|
m_link.clear();
|
2012-06-26 20:23:05 +00:00
|
|
|
|
i = j = 0;
|
|
|
|
|
bBOL = true;
|
|
|
|
|
while ( i < m_len )
|
|
|
|
|
{
|
|
|
|
|
if ( m_bAutoIndent )
|
|
|
|
|
{
|
|
|
|
|
if ( buffer[i] == '\t' )
|
|
|
|
|
{
|
|
|
|
|
if ( !bBOL )
|
|
|
|
|
{
|
|
|
|
|
m_text[j] = buffer[i];
|
2012-09-27 21:42:52 +00:00
|
|
|
|
//if ( m_format.size() > 0 )
|
2012-09-29 20:04:39 +00:00
|
|
|
|
m_format[j] = font;
|
2012-06-26 20:23:05 +00:00
|
|
|
|
j ++;
|
|
|
|
|
}
|
|
|
|
|
i ++;
|
|
|
|
|
continue; // removes the tabs
|
|
|
|
|
}
|
|
|
|
|
bBOL = ( buffer[i] == '\n' || buffer[i] == '\r' );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( buffer[i] == '\r' ) // removes \ r
|
|
|
|
|
{
|
|
|
|
|
i ++;
|
|
|
|
|
}
|
2012-09-27 21:42:52 +00:00
|
|
|
|
else if ( buffer[i] == '\\' && buffer[i+2] == ';' )
|
2012-06-26 20:23:05 +00:00
|
|
|
|
{
|
|
|
|
|
if ( buffer[i+1] == 'n' ) // normal ?
|
|
|
|
|
{
|
|
|
|
|
if ( m_bSoluce || !bInSoluce )
|
|
|
|
|
{
|
2012-08-20 12:05:36 +00:00
|
|
|
|
font &= ~Gfx::FONT_MASK_FONT;
|
|
|
|
|
font |= Gfx::FONT_COLOBOT;
|
2012-06-26 20:23:05 +00:00
|
|
|
|
}
|
|
|
|
|
i += 3;
|
|
|
|
|
}
|
|
|
|
|
else if ( buffer[i+1] == 'c' ) // cbot ?
|
|
|
|
|
{
|
|
|
|
|
if ( m_bSoluce || !bInSoluce )
|
|
|
|
|
{
|
2012-08-20 12:05:36 +00:00
|
|
|
|
font &= ~Gfx::FONT_MASK_FONT;
|
|
|
|
|
font |= Gfx::FONT_COURIER;
|
2012-06-26 20:23:05 +00:00
|
|
|
|
}
|
|
|
|
|
i += 3;
|
|
|
|
|
}
|
|
|
|
|
else if ( buffer[i+1] == 'b' ) // big title ?
|
|
|
|
|
{
|
|
|
|
|
if ( m_bSoluce || !bInSoluce )
|
|
|
|
|
{
|
2012-08-20 12:05:36 +00:00
|
|
|
|
font &= ~Gfx::FONT_MASK_TITLE;
|
|
|
|
|
font |= Gfx::FONT_TITLE_BIG;
|
2012-06-26 20:23:05 +00:00
|
|
|
|
}
|
|
|
|
|
i += 3;
|
|
|
|
|
}
|
|
|
|
|
else if ( buffer[i+1] == 't' ) // title ?
|
|
|
|
|
{
|
|
|
|
|
if ( m_bSoluce || !bInSoluce )
|
|
|
|
|
{
|
2012-08-20 12:05:36 +00:00
|
|
|
|
font &= ~Gfx::FONT_MASK_TITLE;
|
|
|
|
|
font |= Gfx::FONT_TITLE_NORM;
|
2012-06-26 20:23:05 +00:00
|
|
|
|
}
|
|
|
|
|
i += 3;
|
|
|
|
|
}
|
|
|
|
|
else if ( buffer[i+1] == 's' ) // subtitle ?
|
|
|
|
|
{
|
|
|
|
|
if ( m_bSoluce || !bInSoluce )
|
|
|
|
|
{
|
2012-08-20 12:05:36 +00:00
|
|
|
|
font &= ~Gfx::FONT_MASK_TITLE;
|
|
|
|
|
font |= Gfx::FONT_TITLE_LITTLE;
|
2012-06-26 20:23:05 +00:00
|
|
|
|
}
|
|
|
|
|
i += 3;
|
|
|
|
|
}
|
|
|
|
|
else if ( buffer[i+1] == 'l' ) // link ?
|
|
|
|
|
{
|
|
|
|
|
if ( m_bSoluce || !bInSoluce )
|
|
|
|
|
{
|
2012-08-20 12:05:36 +00:00
|
|
|
|
font &= ~Gfx::FONT_MASK_HIGHLIGHT;
|
|
|
|
|
font |= Gfx::FONT_HIGHLIGHT_LINK;
|
2012-06-26 20:23:05 +00:00
|
|
|
|
}
|
|
|
|
|
i += 3;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
i += 3;
|
|
|
|
|
}
|
|
|
|
|
}
|
2012-09-27 21:42:52 +00:00
|
|
|
|
else if ( //m_format.size() > 0 &&
|
2012-06-26 20:23:05 +00:00
|
|
|
|
buffer[i+0] == '\\' && // \u marker name; ?
|
|
|
|
|
buffer[i+1] == 'u' &&
|
|
|
|
|
buffer[i+2] == ' ' )
|
|
|
|
|
{
|
|
|
|
|
if ( m_bSoluce || !bInSoluce )
|
|
|
|
|
{
|
2015-08-13 12:14:11 +00:00
|
|
|
|
HyperLink link;
|
|
|
|
|
link.name = GetNameParam(buffer.data()+i+3, 0);
|
|
|
|
|
link.marker = GetNameParam(buffer.data()+i+3, 1);
|
|
|
|
|
m_link.push_back(link);
|
2012-08-20 12:05:36 +00:00
|
|
|
|
font &= ~Gfx::FONT_MASK_HIGHLIGHT;
|
2012-06-26 20:23:05 +00:00
|
|
|
|
}
|
2015-07-15 17:52:44 +00:00
|
|
|
|
i += strchr(buffer.data()+i, ';')-(buffer.data()+i)+1;
|
2012-06-26 20:23:05 +00:00
|
|
|
|
}
|
2012-09-27 21:42:52 +00:00
|
|
|
|
else if (// m_format.size() > 0 &&
|
2012-06-26 20:23:05 +00:00
|
|
|
|
buffer[i+0] == '\\' && // \m marker; ?
|
|
|
|
|
buffer[i+1] == 'm' &&
|
|
|
|
|
buffer[i+2] == ' ' )
|
|
|
|
|
{
|
|
|
|
|
if ( m_bSoluce || !bInSoluce )
|
|
|
|
|
{
|
2015-08-13 12:14:11 +00:00
|
|
|
|
HyperMarker marker;
|
|
|
|
|
marker.name = GetNameParam(buffer.data()+i+3, 0);
|
|
|
|
|
marker.pos = j;
|
|
|
|
|
m_marker.push_back(marker);
|
2012-06-26 20:23:05 +00:00
|
|
|
|
}
|
2015-07-15 17:52:44 +00:00
|
|
|
|
i += strchr(buffer.data()+i, ';')-(buffer.data()+i)+1;
|
2012-06-26 20:23:05 +00:00
|
|
|
|
}
|
2012-09-27 21:42:52 +00:00
|
|
|
|
else if ( //m_format.size() > 0 &&
|
2012-06-26 20:23:05 +00:00
|
|
|
|
buffer[i+0] == '\\' && // \image name lx ly; ?
|
|
|
|
|
buffer[i+1] == 'i' &&
|
|
|
|
|
buffer[i+2] == 'm' &&
|
|
|
|
|
buffer[i+3] == 'a' &&
|
|
|
|
|
buffer[i+4] == 'g' &&
|
|
|
|
|
buffer[i+5] == 'e' &&
|
|
|
|
|
buffer[i+6] == ' ' )
|
|
|
|
|
{
|
|
|
|
|
if ( m_bSoluce || !bInSoluce )
|
|
|
|
|
{
|
2015-07-15 17:52:44 +00:00
|
|
|
|
strcpy(iName, GetNameParam(buffer.data()+i+7, 0).c_str());
|
2013-03-17 18:01:32 +00:00
|
|
|
|
|
2015-07-15 17:52:44 +00:00
|
|
|
|
//? iWidth = m_lineHeight*RetValueParam(buffer.data()+i+7, 1);
|
|
|
|
|
iWidth = static_cast<float>(GetValueParam(buffer.data()+i+7, 1));
|
2012-08-20 12:05:36 +00:00
|
|
|
|
iWidth *= m_engine->GetText()->GetHeight(Gfx::FONT_COLOBOT, Gfx::FONT_SIZE_SMALL);
|
2015-07-15 17:52:44 +00:00
|
|
|
|
iLines = GetValueParam(buffer.data()+i+7, 2);
|
2013-03-17 18:01:32 +00:00
|
|
|
|
LoadImage(std::string(iName));
|
2012-06-26 20:23:05 +00:00
|
|
|
|
|
|
|
|
|
// A part of image per line of text.
|
|
|
|
|
for ( iCount=0 ; iCount<iLines ; iCount++ )
|
|
|
|
|
{
|
2015-08-13 12:14:11 +00:00
|
|
|
|
ImageLine image;
|
|
|
|
|
image.name = iName;
|
|
|
|
|
image.offset = static_cast<float>(iCount) / static_cast<float>(iLines);
|
|
|
|
|
image.height = 1.0f/iLines;
|
|
|
|
|
image.width = iWidth*0.75f;
|
|
|
|
|
|
|
|
|
|
m_image.push_back(image);
|
|
|
|
|
m_text[j] = static_cast<char>(m_image.size()-1); // as an index into m_image
|
2013-09-28 09:13:45 +00:00
|
|
|
|
m_format[j] = Gfx::FONT_MASK_IMAGE;
|
2012-06-26 20:23:05 +00:00
|
|
|
|
j ++;
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-07-15 17:52:44 +00:00
|
|
|
|
i += strchr(buffer.data()+i, ';')-(buffer.data()+i)+1;
|
2012-06-26 20:23:05 +00:00
|
|
|
|
}
|
2012-09-27 21:42:52 +00:00
|
|
|
|
else if ( //m_format.size() > 0 &&
|
2012-06-26 20:23:05 +00:00
|
|
|
|
buffer[i+0] == '\\' && // \button; ?
|
|
|
|
|
buffer[i+1] == 'b' &&
|
|
|
|
|
buffer[i+2] == 'u' &&
|
|
|
|
|
buffer[i+3] == 't' &&
|
|
|
|
|
buffer[i+4] == 't' &&
|
|
|
|
|
buffer[i+5] == 'o' &&
|
|
|
|
|
buffer[i+6] == 'n' &&
|
|
|
|
|
buffer[i+7] == ' ' )
|
|
|
|
|
{
|
|
|
|
|
if ( m_bSoluce || !bInSoluce )
|
|
|
|
|
{
|
2015-07-15 17:52:44 +00:00
|
|
|
|
m_text[j] = GetValueParam(buffer.data()+i+8, 0);
|
2012-08-20 12:05:36 +00:00
|
|
|
|
m_format[j] = font|Gfx::FONT_BUTTON;
|
2012-06-26 20:23:05 +00:00
|
|
|
|
j ++;
|
|
|
|
|
}
|
2015-07-15 17:52:44 +00:00
|
|
|
|
i += strchr(buffer.data()+i, ';')-(buffer.data()+i)+1;
|
2012-06-26 20:23:05 +00:00
|
|
|
|
}
|
2012-09-27 21:42:52 +00:00
|
|
|
|
else if ( //m_format.size() > 0 &&
|
2012-06-26 20:23:05 +00:00
|
|
|
|
buffer[i+0] == '\\' && // \token; ?
|
|
|
|
|
buffer[i+1] == 't' &&
|
|
|
|
|
buffer[i+2] == 'o' &&
|
|
|
|
|
buffer[i+3] == 'k' &&
|
|
|
|
|
buffer[i+4] == 'e' &&
|
|
|
|
|
buffer[i+5] == 'n' &&
|
|
|
|
|
buffer[i+6] == ';' )
|
|
|
|
|
{
|
|
|
|
|
if ( m_bSoluce || !bInSoluce )
|
|
|
|
|
{
|
2012-08-20 12:05:36 +00:00
|
|
|
|
font &= ~Gfx::FONT_MASK_HIGHLIGHT;
|
|
|
|
|
font |= Gfx::FONT_HIGHLIGHT_TOKEN;
|
2012-06-26 20:23:05 +00:00
|
|
|
|
}
|
|
|
|
|
i += 7;
|
|
|
|
|
}
|
2012-09-27 21:42:52 +00:00
|
|
|
|
else if ( //m_format.size() > 0 &&
|
2012-06-26 20:23:05 +00:00
|
|
|
|
buffer[i+0] == '\\' && // \type; ?
|
|
|
|
|
buffer[i+1] == 't' &&
|
|
|
|
|
buffer[i+2] == 'y' &&
|
|
|
|
|
buffer[i+3] == 'p' &&
|
|
|
|
|
buffer[i+4] == 'e' &&
|
|
|
|
|
buffer[i+5] == ';' )
|
|
|
|
|
{
|
|
|
|
|
if ( m_bSoluce || !bInSoluce )
|
|
|
|
|
{
|
2012-08-20 12:05:36 +00:00
|
|
|
|
font &= ~Gfx::FONT_MASK_HIGHLIGHT;
|
|
|
|
|
font |= Gfx::FONT_HIGHLIGHT_TYPE;
|
2012-06-26 20:23:05 +00:00
|
|
|
|
}
|
|
|
|
|
i += 6;
|
|
|
|
|
}
|
2012-09-27 21:42:52 +00:00
|
|
|
|
else if ( //m_format.size() > 0 &&
|
2012-06-26 20:23:05 +00:00
|
|
|
|
buffer[i+0] == '\\' && // \const; ?
|
|
|
|
|
buffer[i+1] == 'c' &&
|
|
|
|
|
buffer[i+2] == 'o' &&
|
|
|
|
|
buffer[i+3] == 'n' &&
|
|
|
|
|
buffer[i+4] == 's' &&
|
|
|
|
|
buffer[i+5] == 't' &&
|
|
|
|
|
buffer[i+6] == ';' )
|
|
|
|
|
{
|
|
|
|
|
if ( m_bSoluce || !bInSoluce )
|
|
|
|
|
{
|
2012-08-20 12:05:36 +00:00
|
|
|
|
font &= ~Gfx::FONT_MASK_HIGHLIGHT;
|
|
|
|
|
font |= Gfx::FONT_HIGHLIGHT_CONST;
|
2012-06-26 20:23:05 +00:00
|
|
|
|
}
|
|
|
|
|
i += 7;
|
|
|
|
|
}
|
2012-09-27 21:42:52 +00:00
|
|
|
|
else if ( //m_format.size() > 0 &&
|
2012-06-26 20:23:05 +00:00
|
|
|
|
buffer[i+0] == '\\' && // \key; ?
|
|
|
|
|
buffer[i+1] == 'k' &&
|
|
|
|
|
buffer[i+2] == 'e' &&
|
|
|
|
|
buffer[i+3] == 'y' &&
|
|
|
|
|
buffer[i+4] == ';' )
|
|
|
|
|
{
|
|
|
|
|
if ( m_bSoluce || !bInSoluce )
|
|
|
|
|
{
|
2012-08-20 12:05:36 +00:00
|
|
|
|
font &= ~Gfx::FONT_MASK_HIGHLIGHT;
|
|
|
|
|
font |= Gfx::FONT_HIGHLIGHT_KEY;
|
2012-06-26 20:23:05 +00:00
|
|
|
|
}
|
|
|
|
|
i += 5;
|
|
|
|
|
}
|
2012-09-27 21:42:52 +00:00
|
|
|
|
else if ( //m_format.size() > 0 &&
|
2012-06-26 20:23:05 +00:00
|
|
|
|
buffer[i+0] == '\\' && // \tab; ?
|
|
|
|
|
buffer[i+1] == 't' &&
|
|
|
|
|
buffer[i+2] == 'a' &&
|
|
|
|
|
buffer[i+3] == 'b' &&
|
|
|
|
|
buffer[i+4] == ';' )
|
|
|
|
|
{
|
|
|
|
|
if ( m_bSoluce || !bInSoluce )
|
|
|
|
|
{
|
2012-08-20 12:05:36 +00:00
|
|
|
|
font |= Gfx::FONT_HIGHLIGHT_TABLE;
|
2012-06-26 20:23:05 +00:00
|
|
|
|
}
|
|
|
|
|
i += 5;
|
|
|
|
|
}
|
2012-09-27 21:42:52 +00:00
|
|
|
|
else if (// m_format.size() > 0 &&
|
2012-06-26 20:23:05 +00:00
|
|
|
|
buffer[i+0] == '\\' && // \norm; ?
|
|
|
|
|
buffer[i+1] == 'n' &&
|
|
|
|
|
buffer[i+2] == 'o' &&
|
|
|
|
|
buffer[i+3] == 'r' &&
|
|
|
|
|
buffer[i+4] == 'm' &&
|
|
|
|
|
buffer[i+5] == ';' )
|
|
|
|
|
{
|
|
|
|
|
if ( m_bSoluce || !bInSoluce )
|
|
|
|
|
{
|
2012-08-20 12:05:36 +00:00
|
|
|
|
font &= ~Gfx::FONT_MASK_HIGHLIGHT;
|
2012-06-26 20:23:05 +00:00
|
|
|
|
}
|
|
|
|
|
i += 6;
|
|
|
|
|
}
|
2012-09-27 21:42:52 +00:00
|
|
|
|
else if ( //m_format.size() > 0 &&
|
2012-06-26 20:23:05 +00:00
|
|
|
|
buffer[i+0] == '\\' && // \begin soluce; ?
|
|
|
|
|
buffer[i+1] == 'b' &&
|
|
|
|
|
buffer[i+2] == 's' &&
|
|
|
|
|
buffer[i+3] == ';' )
|
|
|
|
|
{
|
|
|
|
|
bInSoluce = true;
|
|
|
|
|
i += 4;
|
|
|
|
|
}
|
2012-09-27 21:42:52 +00:00
|
|
|
|
else if ( //m_format.size() > 0 &&
|
2012-06-26 20:23:05 +00:00
|
|
|
|
buffer[i+0] == '\\' && // \end soluce; ?
|
|
|
|
|
buffer[i+1] == 'e' &&
|
|
|
|
|
buffer[i+2] == 's' &&
|
|
|
|
|
buffer[i+3] == ';' )
|
|
|
|
|
{
|
|
|
|
|
bInSoluce = false;
|
|
|
|
|
i += 4;
|
|
|
|
|
}
|
2012-09-27 21:42:52 +00:00
|
|
|
|
else if ( //m_format.size() > 0 &&
|
2012-06-26 20:23:05 +00:00
|
|
|
|
buffer[i+0] == '\\' && // \key name; ?
|
|
|
|
|
buffer[i+1] == 'k' &&
|
|
|
|
|
buffer[i+2] == 'e' &&
|
|
|
|
|
buffer[i+3] == 'y' &&
|
|
|
|
|
buffer[i+4] == ' ' )
|
|
|
|
|
{
|
2014-12-11 18:01:57 +00:00
|
|
|
|
int count;
|
2015-07-05 11:00:48 +00:00
|
|
|
|
for (count = 0; buffer[i+5+count] != ';'; count++);
|
2014-12-11 18:01:57 +00:00
|
|
|
|
if ( m_bSoluce || !bInSoluce ) //TODO: ???
|
2012-06-26 20:23:05 +00:00
|
|
|
|
{
|
2014-12-11 18:01:57 +00:00
|
|
|
|
CInput* input = CInput::GetInstancePointer();
|
|
|
|
|
slot = input->SearchKeyById(std::string(&buffer[i+5], count));
|
|
|
|
|
if ( slot != INPUT_SLOT_MAX )
|
2012-06-26 20:23:05 +00:00
|
|
|
|
{
|
2014-12-11 18:01:57 +00:00
|
|
|
|
std::string iNameStr = input->GetKeysString(slot);
|
|
|
|
|
strcpy(iName, iNameStr.c_str());
|
|
|
|
|
m_text[j] = ' ';
|
|
|
|
|
m_format[j] = font;
|
|
|
|
|
j ++;
|
|
|
|
|
n = 0;
|
|
|
|
|
while ( iName[n] != 0 )
|
2012-06-26 20:23:05 +00:00
|
|
|
|
{
|
2014-12-11 18:01:57 +00:00
|
|
|
|
m_text[j] = iName[n++];
|
|
|
|
|
m_format[j] = font;
|
|
|
|
|
j ++;
|
2012-06-26 20:23:05 +00:00
|
|
|
|
}
|
2014-12-11 18:01:57 +00:00
|
|
|
|
m_text[j] = ' ';
|
|
|
|
|
m_format[j] = font;
|
|
|
|
|
j ++;
|
2015-07-05 11:00:48 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2014-12-11 18:01:57 +00:00
|
|
|
|
m_text[j] = '?';
|
|
|
|
|
m_format[j] = font;
|
|
|
|
|
j ++;
|
2012-06-26 20:23:05 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2014-12-11 18:01:57 +00:00
|
|
|
|
i = i+5+count+1;
|
2012-06-26 20:23:05 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if ( m_bSoluce || !bInSoluce )
|
|
|
|
|
{
|
|
|
|
|
m_text[j] = buffer[i];
|
2012-09-27 21:42:52 +00:00
|
|
|
|
//if ( m_format.size() > 0 )
|
2012-09-29 20:04:39 +00:00
|
|
|
|
m_format[j] = font;
|
2012-06-26 20:23:05 +00:00
|
|
|
|
j ++;
|
|
|
|
|
}
|
|
|
|
|
i ++;
|
|
|
|
|
|
2012-08-20 12:05:36 +00:00
|
|
|
|
font &= ~Gfx::FONT_MASK_TITLE; // reset title
|
2012-06-26 20:23:05 +00:00
|
|
|
|
|
2012-08-20 12:05:36 +00:00
|
|
|
|
if ( (font&Gfx::FONT_MASK_HIGHLIGHT) == Gfx::FONT_HIGHLIGHT_TABLE )
|
2012-06-26 20:23:05 +00:00
|
|
|
|
{
|
2012-08-20 12:05:36 +00:00
|
|
|
|
font &= ~Gfx::FONT_HIGHLIGHT_TABLE;
|
2012-06-26 20:23:05 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
m_len = j;
|
|
|
|
|
|
|
|
|
|
Justif();
|
|
|
|
|
ColumnFix();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Writes all the text in a file.
|
|
|
|
|
|
2013-03-17 18:01:32 +00:00
|
|
|
|
bool CEdit::WriteText(std::string filename)
|
2012-06-26 20:23:05 +00:00
|
|
|
|
{
|
|
|
|
|
char buffer[1000+20];
|
|
|
|
|
int i, j, k, n;
|
2013-05-01 11:19:10 +00:00
|
|
|
|
float iDim = 0.0f;
|
2012-06-26 20:23:05 +00:00
|
|
|
|
|
|
|
|
|
if ( filename[0] == 0 ) return false;
|
2015-07-05 11:00:48 +00:00
|
|
|
|
|
2014-06-22 13:01:06 +00:00
|
|
|
|
COutputStream stream;
|
|
|
|
|
stream.open(filename);
|
2015-07-05 11:00:48 +00:00
|
|
|
|
|
2014-06-22 13:01:06 +00:00
|
|
|
|
if (!stream.is_open())
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2012-06-26 20:23:05 +00:00
|
|
|
|
|
|
|
|
|
if ( m_bAutoIndent )
|
|
|
|
|
{
|
|
|
|
|
iDim = m_dim.x;
|
|
|
|
|
m_dim.x = 1000.0f; // puts an infinite width!
|
|
|
|
|
Justif();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
i = j = k = 0;
|
|
|
|
|
while ( m_text[i] != 0 && i < m_len )
|
|
|
|
|
{
|
|
|
|
|
if ( m_bAutoIndent && i == m_lineOffset[k] )
|
|
|
|
|
{
|
|
|
|
|
for ( n=0 ; n<m_lineIndent[k] ; n++ )
|
|
|
|
|
{
|
|
|
|
|
buffer[j++] = '\t';
|
|
|
|
|
}
|
|
|
|
|
k ++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
buffer[j++] = m_text[i];
|
|
|
|
|
|
|
|
|
|
if ( j >= 1000-1 )
|
|
|
|
|
{
|
2014-06-22 13:01:06 +00:00
|
|
|
|
stream.write(buffer, j);
|
2012-06-26 20:23:05 +00:00
|
|
|
|
j = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
i ++;
|
|
|
|
|
}
|
|
|
|
|
if ( j > 0 )
|
|
|
|
|
{
|
2014-06-22 13:01:06 +00:00
|
|
|
|
stream.write(buffer, j);
|
2012-06-26 20:23:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-06-22 13:01:06 +00:00
|
|
|
|
stream.close();
|
2012-06-26 20:23:05 +00:00
|
|
|
|
|
|
|
|
|
if ( m_bAutoIndent )
|
|
|
|
|
{
|
|
|
|
|
m_dim.x = iDim; // presents the initial width
|
|
|
|
|
Justif();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Manage the number of max characters editable.
|
|
|
|
|
|
|
|
|
|
void CEdit::SetMaxChar(int max)
|
|
|
|
|
{
|
|
|
|
|
FreeImage();
|
|
|
|
|
|
2012-09-16 18:00:25 +00:00
|
|
|
|
m_maxChar = max;
|
|
|
|
|
|
2015-07-15 17:52:44 +00:00
|
|
|
|
m_text = std::vector<char>(m_maxChar+1, '\0');
|
2012-09-16 18:00:25 +00:00
|
|
|
|
|
2013-02-09 22:49:38 +00:00
|
|
|
|
m_format.clear();
|
|
|
|
|
m_format.reserve(m_maxChar+1);
|
2013-05-26 15:47:54 +00:00
|
|
|
|
for (int i = 0; i <= m_maxChar+1; i++)
|
|
|
|
|
{
|
2015-04-23 19:01:04 +00:00
|
|
|
|
m_format.push_back(m_fontType);
|
2013-02-09 22:49:38 +00:00
|
|
|
|
}
|
2012-06-26 20:23:05 +00:00
|
|
|
|
|
|
|
|
|
m_len = 0;
|
|
|
|
|
m_cursor1 = 0;
|
|
|
|
|
m_cursor2 = 0;
|
|
|
|
|
Justif();
|
|
|
|
|
UndoFlush();
|
|
|
|
|
}
|
|
|
|
|
|
2012-08-20 12:05:36 +00:00
|
|
|
|
int CEdit::GetMaxChar()
|
2012-06-26 20:23:05 +00:00
|
|
|
|
{
|
|
|
|
|
return m_maxChar;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Mode management "editable".
|
|
|
|
|
|
|
|
|
|
void CEdit::SetEditCap(bool bMode)
|
|
|
|
|
{
|
|
|
|
|
m_bEdit = bMode;
|
|
|
|
|
}
|
|
|
|
|
|
2012-08-20 12:05:36 +00:00
|
|
|
|
bool CEdit::GetEditCap()
|
2012-06-26 20:23:05 +00:00
|
|
|
|
{
|
|
|
|
|
return m_bEdit;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Mode management "hilitable" (that's the franch).
|
|
|
|
|
|
2013-03-20 20:50:44 +00:00
|
|
|
|
void CEdit::SetHighlightCap(bool bEnable)
|
2012-06-26 20:23:05 +00:00
|
|
|
|
{
|
|
|
|
|
m_bHilite = bEnable;
|
|
|
|
|
}
|
|
|
|
|
|
2013-03-20 20:50:44 +00:00
|
|
|
|
bool CEdit::GetHighlightCap()
|
2012-06-26 20:23:05 +00:00
|
|
|
|
{
|
|
|
|
|
return m_bHilite;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Lift in / out connection.
|
|
|
|
|
|
|
|
|
|
void CEdit::SetInsideScroll(bool bInside)
|
|
|
|
|
{
|
|
|
|
|
m_bInsideScroll = bInside;
|
|
|
|
|
}
|
|
|
|
|
|
2012-08-20 12:05:36 +00:00
|
|
|
|
bool CEdit::GetInsideScroll()
|
2012-06-26 20:23:05 +00:00
|
|
|
|
{
|
|
|
|
|
return m_bInsideScroll;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Specifies whether to display the links showing the solution.
|
|
|
|
|
|
|
|
|
|
void CEdit::SetSoluceMode(bool bSoluce)
|
|
|
|
|
{
|
|
|
|
|
m_bSoluce = bSoluce;
|
|
|
|
|
}
|
|
|
|
|
|
2012-08-20 12:05:36 +00:00
|
|
|
|
bool CEdit::GetSoluceMode()
|
2012-06-26 20:23:05 +00:00
|
|
|
|
{
|
|
|
|
|
return m_bSoluce;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Indicates whether the text is a defile that generic.
|
|
|
|
|
|
|
|
|
|
void CEdit::SetGenericMode(bool bGeneric)
|
|
|
|
|
{
|
|
|
|
|
m_bGeneric = bGeneric;
|
|
|
|
|
}
|
|
|
|
|
|
2012-08-20 12:05:36 +00:00
|
|
|
|
bool CEdit::GetGenericMode()
|
2012-06-26 20:23:05 +00:00
|
|
|
|
{
|
|
|
|
|
return m_bGeneric;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Management of automatic indentation mode with {}.
|
|
|
|
|
|
|
|
|
|
void CEdit::SetAutoIndent(bool bMode)
|
|
|
|
|
{
|
|
|
|
|
m_bAutoIndent = bMode;
|
|
|
|
|
}
|
|
|
|
|
|
2012-08-20 12:05:36 +00:00
|
|
|
|
bool CEdit::GetAutoIndent()
|
2012-06-26 20:23:05 +00:00
|
|
|
|
{
|
|
|
|
|
return m_bAutoIndent;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Moves the cursors.
|
|
|
|
|
|
|
|
|
|
void CEdit::SetCursor(int cursor1, int cursor2)
|
|
|
|
|
{
|
|
|
|
|
if ( cursor1 > m_len ) cursor1 = m_len;
|
|
|
|
|
if ( cursor2 > m_len ) cursor2 = m_len;
|
|
|
|
|
|
|
|
|
|
m_cursor1 = cursor1;
|
|
|
|
|
m_cursor2 = cursor2;
|
|
|
|
|
m_bUndoForce = true;
|
|
|
|
|
ColumnFix();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Returns the sliders.
|
|
|
|
|
|
|
|
|
|
void CEdit::GetCursor(int &cursor1, int &cursor2)
|
|
|
|
|
{
|
|
|
|
|
cursor1 = m_cursor1;
|
|
|
|
|
cursor2 = m_cursor2;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Displayed line modifies the first.
|
|
|
|
|
|
|
|
|
|
void CEdit::SetFirstLine(int rank)
|
|
|
|
|
{
|
|
|
|
|
Scroll(rank, true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Returns the first displayed line.
|
|
|
|
|
|
2012-08-20 12:05:36 +00:00
|
|
|
|
int CEdit::GetFirstLine()
|
2012-06-26 20:23:05 +00:00
|
|
|
|
{
|
|
|
|
|
if ( m_historyTotal > 0 )
|
|
|
|
|
{
|
|
|
|
|
if ( m_historyCurrent == 0 )
|
|
|
|
|
{
|
|
|
|
|
return m_lineFirst;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return m_history[0].firstLine;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return m_lineFirst;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Shows the selected area.
|
|
|
|
|
|
|
|
|
|
void CEdit::ShowSelect()
|
|
|
|
|
{
|
|
|
|
|
int cursor1, cursor2, line;
|
|
|
|
|
|
|
|
|
|
if ( m_cursor1 < m_cursor2 )
|
|
|
|
|
{
|
|
|
|
|
cursor1 = m_cursor1;
|
|
|
|
|
cursor2 = m_cursor2;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
cursor1 = m_cursor2;
|
|
|
|
|
cursor2 = m_cursor1;
|
|
|
|
|
}
|
|
|
|
|
|
2012-08-20 12:05:36 +00:00
|
|
|
|
line = GetCursorLine(cursor2);
|
2012-06-26 20:23:05 +00:00
|
|
|
|
if ( line >= m_lineFirst+m_lineVisible )
|
|
|
|
|
{
|
|
|
|
|
line -= m_lineVisible-1;
|
|
|
|
|
if ( line < 0 ) line = 0;
|
|
|
|
|
Scroll(line, false);
|
|
|
|
|
}
|
|
|
|
|
|
2012-08-20 12:05:36 +00:00
|
|
|
|
line = GetCursorLine(cursor1);
|
2012-06-26 20:23:05 +00:00
|
|
|
|
if ( line < m_lineFirst )
|
|
|
|
|
{
|
|
|
|
|
Scroll(line, false);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Management of the display mode of special characters.
|
|
|
|
|
|
|
|
|
|
void CEdit::SetDisplaySpec(bool bDisplay)
|
|
|
|
|
{
|
|
|
|
|
m_bDisplaySpec = bDisplay;
|
|
|
|
|
}
|
|
|
|
|
|
2012-08-20 12:05:36 +00:00
|
|
|
|
bool CEdit::GetDisplaySpec()
|
2012-06-26 20:23:05 +00:00
|
|
|
|
{
|
|
|
|
|
return m_bDisplaySpec;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Multi-fonts mode management.
|
|
|
|
|
|
|
|
|
|
void CEdit::SetMultiFont(bool bMulti)
|
|
|
|
|
{
|
2012-08-31 20:28:07 +00:00
|
|
|
|
m_format.clear();
|
2013-05-26 15:47:54 +00:00
|
|
|
|
|
|
|
|
|
if (bMulti)
|
|
|
|
|
{
|
2013-02-09 22:49:38 +00:00
|
|
|
|
m_format.reserve(m_maxChar+1);
|
2013-05-26 15:47:54 +00:00
|
|
|
|
for (int i = 0; i <= m_maxChar+1; i++)
|
|
|
|
|
{
|
2015-04-23 19:01:04 +00:00
|
|
|
|
m_format.push_back(m_fontType);
|
2013-02-09 22:49:38 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2012-06-26 20:23:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-09-27 21:42:52 +00:00
|
|
|
|
// TODO check if it works correctly; was checking if variable is null
|
2012-08-20 12:05:36 +00:00
|
|
|
|
bool CEdit::GetMultiFont()
|
2012-06-26 20:23:05 +00:00
|
|
|
|
{
|
2012-08-31 20:28:07 +00:00
|
|
|
|
return ( m_format.size() > 0 );
|
2012-06-26 20:23:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Management of the character size.
|
|
|
|
|
|
|
|
|
|
void CEdit::SetFontSize(float size)
|
|
|
|
|
{
|
|
|
|
|
CControl::SetFontSize(size);
|
|
|
|
|
|
|
|
|
|
MoveAdjust();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Moves according to the visible lift.
|
|
|
|
|
|
|
|
|
|
void CEdit::Scroll()
|
|
|
|
|
{
|
2015-08-11 20:47:07 +00:00
|
|
|
|
if (m_scroll != nullptr)
|
2012-06-26 20:23:05 +00:00
|
|
|
|
{
|
2015-08-11 20:47:07 +00:00
|
|
|
|
float value = m_scroll->GetVisibleValue();
|
2012-12-29 12:32:11 +00:00
|
|
|
|
value *= m_lineTotal - m_lineVisible;
|
|
|
|
|
Scroll(static_cast<int>(value + 0.5f), true);
|
2012-06-26 20:23:05 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Moves according to the visible lift.
|
|
|
|
|
|
|
|
|
|
void CEdit::Scroll(int pos, bool bAdjustCursor)
|
|
|
|
|
{
|
|
|
|
|
int max, line;
|
|
|
|
|
|
|
|
|
|
m_lineFirst = pos;
|
|
|
|
|
|
|
|
|
|
if ( m_lineFirst < 0 ) m_lineFirst = 0;
|
|
|
|
|
|
|
|
|
|
max = m_lineTotal-m_lineVisible;
|
|
|
|
|
if ( max < 0 ) max = 0;
|
|
|
|
|
if ( m_lineFirst > max ) m_lineFirst = max;
|
|
|
|
|
|
2012-08-20 12:05:36 +00:00
|
|
|
|
line = GetCursorLine(m_cursor1);
|
2012-06-26 20:23:05 +00:00
|
|
|
|
|
|
|
|
|
if ( bAdjustCursor && m_bEdit )
|
|
|
|
|
{
|
|
|
|
|
// Cursor too high?
|
|
|
|
|
if ( line < m_lineFirst )
|
|
|
|
|
{
|
|
|
|
|
MoveLine(m_lineFirst-line, false, false);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Cursor too low?
|
|
|
|
|
if ( line >= m_lineFirst+m_lineVisible )
|
|
|
|
|
{
|
|
|
|
|
MoveLine(m_lineFirst+m_lineVisible-line-1, false, false);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
2012-06-26 21:01:17 +00:00
|
|
|
|
|
2012-06-26 20:23:05 +00:00
|
|
|
|
Justif();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Moves the cursor to the beginning of the line.
|
|
|
|
|
|
|
|
|
|
void CEdit::MoveHome(bool bWord, bool bSelect)
|
|
|
|
|
{
|
|
|
|
|
int begin, tab;
|
|
|
|
|
|
|
|
|
|
if ( bWord )
|
|
|
|
|
{
|
|
|
|
|
m_cursor1 = 0;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
begin = m_cursor1;
|
|
|
|
|
while ( begin > 0 && m_text[begin-1] != '\n' )
|
|
|
|
|
{
|
|
|
|
|
begin --;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
tab = begin;
|
|
|
|
|
while ( tab < m_len && (m_text[tab] == '\t' || m_text[tab] == ' ') )
|
|
|
|
|
{
|
|
|
|
|
tab ++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( m_cursor1 == tab )
|
|
|
|
|
{
|
|
|
|
|
m_cursor1 = begin;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
m_cursor1 = tab;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if ( !bSelect ) m_cursor2 = m_cursor1;
|
|
|
|
|
|
|
|
|
|
m_bUndoForce = true;
|
|
|
|
|
Justif();
|
|
|
|
|
ColumnFix();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Moves the cursor to the end of the line.
|
|
|
|
|
|
|
|
|
|
void CEdit::MoveEnd(bool bWord, bool bSelect)
|
|
|
|
|
{
|
|
|
|
|
if ( bWord )
|
|
|
|
|
{
|
|
|
|
|
m_cursor1 = m_len;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
while ( m_cursor1 < m_len && m_text[m_cursor1] != '\n' )
|
|
|
|
|
{
|
|
|
|
|
m_cursor1 ++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if ( !bSelect ) m_cursor2 = m_cursor1;
|
|
|
|
|
|
|
|
|
|
m_bUndoForce = true;
|
|
|
|
|
Justif();
|
|
|
|
|
ColumnFix();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Moves the cursor through characters.
|
|
|
|
|
|
|
|
|
|
void CEdit::MoveChar(int move, bool bWord, bool bSelect)
|
|
|
|
|
{
|
|
|
|
|
int character;
|
|
|
|
|
|
|
|
|
|
if ( move == -1 ) // back?
|
|
|
|
|
{
|
|
|
|
|
if ( bWord )
|
|
|
|
|
{
|
|
|
|
|
while ( m_cursor1 > 0 )
|
|
|
|
|
{
|
2012-09-17 22:01:00 +00:00
|
|
|
|
character = static_cast<unsigned char>(m_text[m_cursor1-1]);
|
2012-06-26 20:23:05 +00:00
|
|
|
|
if ( !IsSpace(character) ) break;
|
|
|
|
|
m_cursor1 --;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( m_cursor1 > 0 )
|
|
|
|
|
{
|
2012-09-17 22:01:00 +00:00
|
|
|
|
character = static_cast<unsigned char>(m_text[m_cursor1-1]);
|
2012-06-26 20:23:05 +00:00
|
|
|
|
if ( IsSpace(character) )
|
|
|
|
|
{
|
|
|
|
|
while ( m_cursor1 > 0 )
|
|
|
|
|
{
|
2012-09-17 22:01:00 +00:00
|
|
|
|
character = static_cast<unsigned char>(m_text[m_cursor1-1]);
|
2012-06-26 20:23:05 +00:00
|
|
|
|
if ( !IsSpace(character) ) break;
|
|
|
|
|
m_cursor1 --;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if ( IsWord(character) )
|
|
|
|
|
{
|
|
|
|
|
while ( m_cursor1 > 0 )
|
|
|
|
|
{
|
2012-09-17 22:01:00 +00:00
|
|
|
|
character = static_cast<unsigned char>(m_text[m_cursor1-1]);
|
2012-06-26 20:23:05 +00:00
|
|
|
|
if ( !IsWord(character) ) break;
|
|
|
|
|
m_cursor1 --;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if ( IsSep(character) )
|
|
|
|
|
{
|
|
|
|
|
while ( m_cursor1 > 0 )
|
|
|
|
|
{
|
2012-09-17 22:01:00 +00:00
|
|
|
|
character = static_cast<unsigned char>(m_text[m_cursor1-1]);
|
2012-06-26 20:23:05 +00:00
|
|
|
|
if ( !IsSep(character) ) break;
|
|
|
|
|
m_cursor1 --;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
m_cursor1 --;
|
|
|
|
|
if ( m_cursor1 < 0 ) m_cursor1 = 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( move == 1 ) // advance?
|
|
|
|
|
{
|
|
|
|
|
if ( bWord )
|
|
|
|
|
{
|
|
|
|
|
if ( m_cursor1 < m_len )
|
|
|
|
|
{
|
2012-09-17 22:01:00 +00:00
|
|
|
|
character = static_cast<unsigned char>(m_text[m_cursor1]);
|
2012-06-26 20:23:05 +00:00
|
|
|
|
if ( IsSpace(character) )
|
|
|
|
|
{
|
|
|
|
|
while ( m_cursor1 < m_len )
|
|
|
|
|
{
|
2012-09-17 22:01:00 +00:00
|
|
|
|
character = static_cast<unsigned char>(m_text[m_cursor1]);
|
2012-06-26 20:23:05 +00:00
|
|
|
|
if ( !IsSpace(character) ) break;
|
|
|
|
|
m_cursor1 ++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if ( IsWord(character) )
|
|
|
|
|
{
|
|
|
|
|
while ( m_cursor1 < m_len )
|
|
|
|
|
{
|
2012-09-17 22:01:00 +00:00
|
|
|
|
character = static_cast<unsigned char>(m_text[m_cursor1]);
|
2012-06-26 20:23:05 +00:00
|
|
|
|
if ( !IsWord(character) ) break;
|
|
|
|
|
m_cursor1 ++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if ( IsSep(character) )
|
|
|
|
|
{
|
|
|
|
|
while ( m_cursor1 < m_len )
|
|
|
|
|
{
|
2012-09-17 22:01:00 +00:00
|
|
|
|
character = static_cast<unsigned char>(m_text[m_cursor1]);
|
2012-06-26 20:23:05 +00:00
|
|
|
|
if ( !IsSep(character) ) break;
|
|
|
|
|
m_cursor1 ++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
while ( m_cursor1 < m_len )
|
|
|
|
|
{
|
2012-09-17 22:01:00 +00:00
|
|
|
|
character = static_cast<unsigned char>(m_text[m_cursor1]);
|
2012-06-26 20:23:05 +00:00
|
|
|
|
if ( !IsSpace(character) ) break;
|
|
|
|
|
m_cursor1 ++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
m_cursor1 ++;
|
|
|
|
|
if ( m_cursor1 > m_len ) m_cursor1 = m_len;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( !bSelect ) m_cursor2 = m_cursor1;
|
|
|
|
|
|
|
|
|
|
m_bUndoForce = true;
|
|
|
|
|
Justif();
|
|
|
|
|
ColumnFix();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Moves the cursor lines.
|
|
|
|
|
|
|
|
|
|
void CEdit::MoveLine(int move, bool bWord, bool bSelect)
|
|
|
|
|
{
|
2013-05-01 11:19:10 +00:00
|
|
|
|
float column, indentLength = 0.0f;
|
2012-06-26 20:23:05 +00:00
|
|
|
|
int i, line, c;
|
|
|
|
|
|
|
|
|
|
if ( move == 0 ) return;
|
|
|
|
|
|
|
|
|
|
for ( i=0 ; i>move ; i-- ) // back?
|
|
|
|
|
{
|
|
|
|
|
while ( m_cursor1 > 0 && m_text[m_cursor1-1] != '\n' )
|
|
|
|
|
{
|
|
|
|
|
m_cursor1 --;
|
|
|
|
|
}
|
|
|
|
|
if ( m_cursor1 != 0 )
|
|
|
|
|
{
|
|
|
|
|
m_cursor1 --;
|
|
|
|
|
while ( m_cursor1 > 0 )
|
|
|
|
|
{
|
|
|
|
|
if ( m_text[--m_cursor1] == '\n' )
|
|
|
|
|
{
|
|
|
|
|
m_cursor1 ++;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for ( i=0 ; i<move ; i++ ) // advance?
|
|
|
|
|
{
|
|
|
|
|
while ( m_cursor1 < m_len )
|
|
|
|
|
{
|
|
|
|
|
if ( m_text[m_cursor1++] == '\n' )
|
|
|
|
|
{
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-08-20 12:05:36 +00:00
|
|
|
|
line = GetCursorLine(m_cursor1);
|
2012-06-26 20:23:05 +00:00
|
|
|
|
|
|
|
|
|
column = m_column;
|
|
|
|
|
if ( m_bAutoIndent )
|
|
|
|
|
{
|
2012-08-20 12:05:36 +00:00
|
|
|
|
indentLength = m_engine->GetText()->GetCharWidth(static_cast<Gfx::UTF8Char>(' '), m_fontType, m_fontSize, 0.0f)
|
|
|
|
|
* m_engine->GetEditIndentValue();
|
2012-06-26 20:23:05 +00:00
|
|
|
|
column -= indentLength*m_lineIndent[line];
|
|
|
|
|
}
|
|
|
|
|
|
2012-08-31 20:28:07 +00:00
|
|
|
|
if ( m_format.size() == 0 )
|
2012-06-26 20:23:05 +00:00
|
|
|
|
{
|
2015-07-15 17:52:44 +00:00
|
|
|
|
c = m_engine->GetText()->Detect(std::string(m_text.data()+m_lineOffset[line]),
|
2012-08-20 12:05:36 +00:00
|
|
|
|
m_fontType, m_fontSize,
|
|
|
|
|
m_lineOffset[line+1]-m_lineOffset[line]);
|
2012-06-26 20:23:05 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2015-07-15 17:52:44 +00:00
|
|
|
|
c = m_engine->GetText()->Detect(std::string(m_text.data()+m_lineOffset[line]),
|
2013-02-09 22:49:38 +00:00
|
|
|
|
m_format.begin() + m_lineOffset[line],
|
2013-02-24 00:40:55 +00:00
|
|
|
|
m_format.end(),
|
2012-08-20 12:05:36 +00:00
|
|
|
|
m_fontSize,
|
|
|
|
|
m_lineOffset[line+1]-m_lineOffset[line]);
|
2012-06-26 20:23:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
m_cursor1 = m_lineOffset[line]+c;
|
|
|
|
|
if ( !bSelect ) m_cursor2 = m_cursor1;
|
|
|
|
|
|
|
|
|
|
m_bUndoForce = true;
|
|
|
|
|
Justif();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Sets the horizontal position.
|
|
|
|
|
|
|
|
|
|
void CEdit::ColumnFix()
|
|
|
|
|
{
|
|
|
|
|
float indentLength;
|
|
|
|
|
int line;
|
|
|
|
|
|
2012-08-20 12:05:36 +00:00
|
|
|
|
line = GetCursorLine(m_cursor1);
|
2012-06-26 20:23:05 +00:00
|
|
|
|
|
2012-08-31 20:28:07 +00:00
|
|
|
|
if ( m_format.size() == 0 )
|
2012-06-26 20:23:05 +00:00
|
|
|
|
{
|
2012-08-20 12:05:36 +00:00
|
|
|
|
m_column = m_engine->GetText()->GetStringWidth(
|
2015-07-15 17:52:44 +00:00
|
|
|
|
std::string(m_text.data()+m_lineOffset[line]),
|
2012-08-20 12:05:36 +00:00
|
|
|
|
m_fontType, m_fontSize);
|
2012-06-26 20:23:05 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2012-08-20 12:05:36 +00:00
|
|
|
|
m_column = m_engine->GetText()->GetStringWidth(
|
2015-07-15 17:52:44 +00:00
|
|
|
|
std::string(m_text.data()+m_lineOffset[line]),
|
2013-02-09 22:49:38 +00:00
|
|
|
|
m_format.begin() + m_lineOffset[line],
|
2013-02-24 00:40:55 +00:00
|
|
|
|
m_format.end(),
|
2012-08-20 12:05:36 +00:00
|
|
|
|
m_fontSize
|
2012-06-26 20:23:05 +00:00
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( m_bAutoIndent )
|
|
|
|
|
{
|
2012-08-20 12:05:36 +00:00
|
|
|
|
indentLength = m_engine->GetText()->GetCharWidth(static_cast<Gfx::UTF8Char>(' '), m_fontType, m_fontSize, 0.0f)
|
|
|
|
|
* m_engine->GetEditIndentValue();
|
2012-06-26 20:23:05 +00:00
|
|
|
|
m_column += indentLength*m_lineIndent[line];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Cut the selected characters or entire line.
|
|
|
|
|
|
2013-04-11 11:37:15 +00:00
|
|
|
|
bool CEdit::Cut()
|
2012-06-26 20:23:05 +00:00
|
|
|
|
{
|
|
|
|
|
UndoMemorize(OPERUNDO_SPEC);
|
2013-04-11 11:37:15 +00:00
|
|
|
|
Copy(true);
|
|
|
|
|
|
2012-06-26 20:23:05 +00:00
|
|
|
|
DeleteOne(0); // deletes the selected characters
|
|
|
|
|
Justif();
|
|
|
|
|
ColumnFix();
|
2013-04-11 11:37:15 +00:00
|
|
|
|
SendModifEvent();
|
2012-06-26 20:23:05 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Copy the selected characters or entire line.
|
|
|
|
|
|
2013-04-11 11:37:15 +00:00
|
|
|
|
bool CEdit::Copy(bool memorize_cursor)
|
2012-06-26 20:23:05 +00:00
|
|
|
|
{
|
2013-04-11 11:37:15 +00:00
|
|
|
|
int c1, c2, start, len;
|
2012-06-26 20:23:05 +00:00
|
|
|
|
|
|
|
|
|
c1 = m_cursor1;
|
|
|
|
|
c2 = m_cursor2;
|
2013-05-26 15:47:54 +00:00
|
|
|
|
if ( c1 > c2 )
|
|
|
|
|
{
|
2013-04-11 11:37:15 +00:00
|
|
|
|
Math::Swap(c1, c2); // always c1 <= c2
|
|
|
|
|
}
|
2012-06-26 20:23:05 +00:00
|
|
|
|
|
2013-05-26 15:47:54 +00:00
|
|
|
|
if ( c1 == c2 )
|
|
|
|
|
{
|
|
|
|
|
while ( c1 > 0 )
|
|
|
|
|
{
|
|
|
|
|
if ( m_text[c1 - 1] == '\n' )
|
|
|
|
|
{
|
2013-04-11 11:37:15 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
c1--;
|
2012-06-26 20:23:05 +00:00
|
|
|
|
}
|
2013-05-26 15:47:54 +00:00
|
|
|
|
while ( c2 < m_len )
|
|
|
|
|
{
|
2013-04-11 11:37:15 +00:00
|
|
|
|
c2++;
|
2013-05-26 15:47:54 +00:00
|
|
|
|
if ( m_text[c2 - 1] == '\n' )
|
|
|
|
|
{
|
2013-04-11 11:37:15 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
2012-06-26 20:23:05 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-05-26 15:47:54 +00:00
|
|
|
|
if ( c1 == c2 )
|
|
|
|
|
{
|
2012-06-26 20:23:05 +00:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2013-04-11 11:37:15 +00:00
|
|
|
|
start = c1;
|
|
|
|
|
len = c2 - c1;
|
2012-06-26 20:23:05 +00:00
|
|
|
|
|
2015-07-15 17:52:44 +00:00
|
|
|
|
std::vector<char> text(len + 1, '\0');
|
|
|
|
|
strncpy(text.data(), m_text.data() + start, len);
|
2013-04-11 11:37:15 +00:00
|
|
|
|
text[len] = 0;
|
2015-07-15 17:52:44 +00:00
|
|
|
|
widgetSetClipboardText(text.data());
|
2013-05-26 15:47:54 +00:00
|
|
|
|
|
|
|
|
|
if (memorize_cursor)
|
|
|
|
|
{
|
2013-04-11 11:37:15 +00:00
|
|
|
|
m_cursor1 = c1;
|
|
|
|
|
m_cursor2 = c2;
|
2012-06-26 20:23:05 +00:00
|
|
|
|
}
|
2013-04-11 11:37:15 +00:00
|
|
|
|
|
2012-06-26 20:23:05 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Paste the contents of the notebook.
|
|
|
|
|
|
2013-04-11 11:37:15 +00:00
|
|
|
|
bool CEdit::Paste()
|
2012-06-26 20:23:05 +00:00
|
|
|
|
{
|
|
|
|
|
char c;
|
2013-04-11 11:37:15 +00:00
|
|
|
|
char* text;
|
2012-06-26 20:23:05 +00:00
|
|
|
|
|
2013-05-26 15:47:54 +00:00
|
|
|
|
if ( !m_bEdit )
|
|
|
|
|
{
|
2012-06-26 20:23:05 +00:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2013-04-11 11:37:15 +00:00
|
|
|
|
text = widgetGetClipboardText();
|
2013-05-26 15:47:54 +00:00
|
|
|
|
|
|
|
|
|
if ( text == nullptr )
|
|
|
|
|
{
|
2012-06-26 20:23:05 +00:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
UndoMemorize(OPERUNDO_SPEC);
|
2013-05-26 15:47:54 +00:00
|
|
|
|
for ( unsigned int i = 0; i < strlen(text); i++ )
|
|
|
|
|
{
|
2013-04-11 11:37:15 +00:00
|
|
|
|
c = text[i];
|
2013-05-26 15:47:54 +00:00
|
|
|
|
if ( c == '\r' )
|
|
|
|
|
{
|
2013-04-11 11:37:15 +00:00
|
|
|
|
continue;
|
|
|
|
|
}
|
2013-05-26 15:47:54 +00:00
|
|
|
|
if ( c == '\t' && m_bAutoIndent )
|
|
|
|
|
{
|
2013-04-11 11:37:15 +00:00
|
|
|
|
continue;
|
|
|
|
|
}
|
2012-06-26 20:23:05 +00:00
|
|
|
|
InsertOne(c);
|
|
|
|
|
}
|
2013-05-26 15:47:54 +00:00
|
|
|
|
|
2013-04-11 11:37:15 +00:00
|
|
|
|
free(text);
|
2012-06-26 20:23:05 +00:00
|
|
|
|
Justif();
|
|
|
|
|
ColumnFix();
|
2013-04-11 11:37:15 +00:00
|
|
|
|
SendModifEvent();
|
2012-06-26 20:23:05 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Cancels the last action.
|
|
|
|
|
|
|
|
|
|
bool CEdit::Undo()
|
|
|
|
|
{
|
2013-05-26 15:47:54 +00:00
|
|
|
|
if ( !m_bEdit )
|
|
|
|
|
{
|
2013-04-11 11:37:15 +00:00
|
|
|
|
return false;
|
|
|
|
|
}
|
2012-06-26 20:23:05 +00:00
|
|
|
|
|
|
|
|
|
return UndoRecall();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Inserts a character.
|
|
|
|
|
|
|
|
|
|
void CEdit::Insert(char character)
|
|
|
|
|
{
|
|
|
|
|
int i, level, tab;
|
|
|
|
|
|
2013-05-26 15:47:54 +00:00
|
|
|
|
if ( !m_bEdit )
|
|
|
|
|
{
|
2013-04-11 11:37:15 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
2012-06-26 20:23:05 +00:00
|
|
|
|
|
|
|
|
|
if ( !m_bMulti ) // single-line?
|
|
|
|
|
{
|
|
|
|
|
if ( character == '\n' ||
|
|
|
|
|
character == '\t' ) return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
UndoMemorize(OPERUNDO_INSERT);
|
|
|
|
|
|
|
|
|
|
if ( m_bMulti && !m_bAutoIndent )
|
|
|
|
|
{
|
|
|
|
|
if ( character == '\n' )
|
|
|
|
|
{
|
|
|
|
|
InsertOne(character);
|
|
|
|
|
level = IndentCompute();
|
|
|
|
|
for ( i=0 ; i<level ; i++ )
|
|
|
|
|
{
|
|
|
|
|
InsertOne('\t');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if ( character == '{' )
|
|
|
|
|
{
|
|
|
|
|
tab = IndentTabCount();
|
|
|
|
|
if ( tab != -1 )
|
|
|
|
|
{
|
|
|
|
|
level = IndentCompute();
|
|
|
|
|
IndentTabAdjust(level-tab);
|
|
|
|
|
}
|
|
|
|
|
InsertOne(character);
|
|
|
|
|
}
|
|
|
|
|
else if ( character == '}' )
|
|
|
|
|
{
|
|
|
|
|
tab = IndentTabCount();
|
|
|
|
|
if ( tab != -1 )
|
|
|
|
|
{
|
|
|
|
|
level = IndentCompute()-1;
|
|
|
|
|
IndentTabAdjust(level-tab);
|
|
|
|
|
}
|
|
|
|
|
InsertOne(character);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
InsertOne(character);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if ( m_bAutoIndent )
|
|
|
|
|
{
|
|
|
|
|
if ( character == '{' )
|
|
|
|
|
{
|
|
|
|
|
InsertOne(character);
|
|
|
|
|
InsertOne('\n');
|
|
|
|
|
InsertOne('\n');
|
|
|
|
|
InsertOne('}');
|
|
|
|
|
MoveChar(-1, false, false);
|
|
|
|
|
MoveChar(-1, false, false);
|
|
|
|
|
}
|
|
|
|
|
else if ( character == '\t' )
|
|
|
|
|
{
|
2012-08-20 12:05:36 +00:00
|
|
|
|
for ( i=0 ; i<m_engine->GetEditIndentValue() ; i++ )
|
2012-06-26 20:23:05 +00:00
|
|
|
|
{
|
|
|
|
|
InsertOne(' ');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
InsertOne(character);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
InsertOne(character);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Justif();
|
|
|
|
|
ColumnFix();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Inserts a plain character.
|
|
|
|
|
|
|
|
|
|
void CEdit::InsertOne(char character)
|
|
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
if ( !m_bEdit ) return;
|
|
|
|
|
if ( !m_bMulti && character == '\n' ) return;
|
|
|
|
|
|
|
|
|
|
if ( m_cursor1 != m_cursor2 )
|
|
|
|
|
{
|
|
|
|
|
DeleteOne(0); // deletes the selected characters
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( m_len >= m_maxChar ) return;
|
|
|
|
|
|
2015-07-15 17:52:44 +00:00
|
|
|
|
for ( i=m_len ; i>m_cursor1 ; i-- )
|
2012-06-26 20:23:05 +00:00
|
|
|
|
{
|
|
|
|
|
m_text[i] = m_text[i-1]; // shoot
|
|
|
|
|
|
2013-02-11 19:17:43 +00:00
|
|
|
|
if ( m_format.size() > static_cast<unsigned int>(i) )
|
|
|
|
|
{
|
2012-06-26 20:23:05 +00:00
|
|
|
|
m_format[i] = m_format[i-1]; // shoot
|
2013-02-11 19:17:43 +00:00
|
|
|
|
}
|
2012-06-26 20:23:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
m_len ++;
|
|
|
|
|
|
|
|
|
|
m_text[m_cursor1] = character;
|
|
|
|
|
|
2015-07-15 17:52:44 +00:00
|
|
|
|
if ( static_cast<unsigned int>(m_cursor1) < m_format.size() )
|
2013-02-11 19:17:43 +00:00
|
|
|
|
{
|
2012-06-26 20:23:05 +00:00
|
|
|
|
m_format[m_cursor1] = 0;
|
2013-02-11 19:17:43 +00:00
|
|
|
|
}
|
2012-06-26 20:23:05 +00:00
|
|
|
|
|
|
|
|
|
m_cursor1++;
|
|
|
|
|
m_cursor2 = m_cursor1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Deletes the character left of cursor or all selected characters.
|
|
|
|
|
|
|
|
|
|
void CEdit::Delete(int dir)
|
|
|
|
|
{
|
|
|
|
|
if ( !m_bEdit ) return;
|
|
|
|
|
|
|
|
|
|
UndoMemorize(OPERUNDO_DELETE);
|
|
|
|
|
DeleteOne(dir);
|
|
|
|
|
|
|
|
|
|
Justif();
|
|
|
|
|
ColumnFix();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Deletes the character left of cursor or all selected plain characters.
|
|
|
|
|
|
|
|
|
|
void CEdit::DeleteOne(int dir)
|
|
|
|
|
{
|
|
|
|
|
int i, end, hole;
|
|
|
|
|
|
|
|
|
|
if ( !m_bEdit ) return;
|
|
|
|
|
|
|
|
|
|
if ( m_cursor1 == m_cursor2 )
|
|
|
|
|
{
|
|
|
|
|
if ( dir < 0 )
|
|
|
|
|
{
|
|
|
|
|
if ( m_cursor1 == 0 ) return;
|
|
|
|
|
m_cursor1 --;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if ( m_cursor2 == m_len ) return;
|
|
|
|
|
m_cursor2 ++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( m_cursor1 > m_cursor2 ) Math::Swap(m_cursor1, m_cursor2);
|
|
|
|
|
hole = m_cursor2-m_cursor1;
|
|
|
|
|
end = m_len-hole;
|
|
|
|
|
for ( i=m_cursor1 ; i<end ; i++ )
|
|
|
|
|
{
|
|
|
|
|
m_text[i] = m_text[i+hole];
|
|
|
|
|
|
2013-02-09 22:49:38 +00:00
|
|
|
|
if ( m_format.size() > static_cast<unsigned int>(i + hole) )
|
2012-06-26 20:23:05 +00:00
|
|
|
|
{
|
|
|
|
|
m_format[i] = m_format[i+hole];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
m_len -= hole;
|
|
|
|
|
m_cursor2 = m_cursor1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Calculates the indentation level of brackets {and}.
|
|
|
|
|
|
|
|
|
|
int CEdit::IndentCompute()
|
|
|
|
|
{
|
|
|
|
|
int i, level;
|
|
|
|
|
|
|
|
|
|
level = 0;
|
|
|
|
|
for ( i=0 ; i<m_cursor1 ; i++ )
|
|
|
|
|
{
|
|
|
|
|
if ( m_text[i] == '{' ) level ++;
|
|
|
|
|
if ( m_text[i] == '}' ) level --;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( level < 0 ) level = 0;
|
|
|
|
|
return level;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Counts the number of tabs before the cursor.
|
|
|
|
|
// Returns -1 if there is something else.
|
|
|
|
|
|
|
|
|
|
int CEdit::IndentTabCount()
|
|
|
|
|
{
|
|
|
|
|
int i, nb;
|
|
|
|
|
|
|
|
|
|
if ( m_cursor1 != m_cursor2 ) return -1;
|
|
|
|
|
|
|
|
|
|
i = m_cursor1;
|
|
|
|
|
nb = 0;
|
|
|
|
|
while ( i > 0 )
|
|
|
|
|
{
|
|
|
|
|
if ( m_text[i-1] == '\n' ) return nb;
|
|
|
|
|
if ( m_text[i-1] != '\t' ) return -1;
|
|
|
|
|
nb ++;
|
|
|
|
|
i --;
|
|
|
|
|
}
|
|
|
|
|
return nb;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Adds or removes qq tabs.
|
|
|
|
|
|
|
|
|
|
void CEdit::IndentTabAdjust(int number)
|
|
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
for ( i=0 ; i<number ; i++ ) // add?
|
|
|
|
|
{
|
|
|
|
|
InsertOne('\t');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for ( i=0 ; i>number ; i-- ) // delete?
|
|
|
|
|
{
|
|
|
|
|
DeleteOne(-1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Indent the left or right the entire selection.
|
|
|
|
|
|
|
|
|
|
bool CEdit::Shift(bool bLeft)
|
|
|
|
|
{
|
|
|
|
|
bool bInvert = false;
|
|
|
|
|
int c1, c2, i;
|
|
|
|
|
|
|
|
|
|
if ( m_cursor1 == m_cursor2 ) return false;
|
|
|
|
|
|
|
|
|
|
UndoMemorize(OPERUNDO_SPEC);
|
|
|
|
|
|
|
|
|
|
c1 = m_cursor1;
|
|
|
|
|
c2 = m_cursor2;
|
|
|
|
|
if ( c1 > c2 )
|
|
|
|
|
{
|
|
|
|
|
Math::Swap(c1, c2); // always c1 <= c2
|
|
|
|
|
bInvert = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( c1 > 0 )
|
|
|
|
|
{
|
|
|
|
|
if ( m_text[c1-1] != '\n' ) return false;
|
|
|
|
|
}
|
|
|
|
|
if ( c2 < m_len )
|
|
|
|
|
{
|
|
|
|
|
if ( m_text[c2-1] != '\n' ) return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( bLeft ) // shifts left?
|
|
|
|
|
{
|
|
|
|
|
i = c1;
|
|
|
|
|
while ( i < c2 )
|
|
|
|
|
{
|
|
|
|
|
if ( m_text[i] == '\t' )
|
|
|
|
|
{
|
|
|
|
|
m_cursor1 = i;
|
|
|
|
|
m_cursor2 = i+1;
|
|
|
|
|
DeleteOne(0);
|
|
|
|
|
c2 --;
|
|
|
|
|
}
|
|
|
|
|
while ( i < c2 && m_text[i++] != '\n' );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else // shifts right?
|
|
|
|
|
{
|
|
|
|
|
i = c1;
|
|
|
|
|
while ( i < c2 )
|
|
|
|
|
{
|
|
|
|
|
m_cursor1 = m_cursor2 = i;
|
|
|
|
|
InsertOne('\t');
|
|
|
|
|
c2 ++;
|
|
|
|
|
while ( i < c2 && m_text[i++] != '\n' );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( bInvert ) Math::Swap(c1, c2);
|
|
|
|
|
m_cursor1 = c1;
|
|
|
|
|
m_cursor2 = c2;
|
|
|
|
|
|
|
|
|
|
Justif();
|
|
|
|
|
ColumnFix();
|
|
|
|
|
SendModifEvent();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Math::Min conversion <-> shift the selection.
|
|
|
|
|
|
|
|
|
|
bool CEdit::MinMaj(bool bMaj)
|
|
|
|
|
{
|
|
|
|
|
int c1, c2, i, character;
|
|
|
|
|
|
|
|
|
|
if ( m_cursor1 == m_cursor2 ) return false;
|
|
|
|
|
|
|
|
|
|
UndoMemorize(OPERUNDO_SPEC);
|
|
|
|
|
|
|
|
|
|
c1 = m_cursor1;
|
|
|
|
|
c2 = m_cursor2;
|
|
|
|
|
if ( c1 > c2 ) Math::Swap(c1, c2); // alwyas c1 <= c2
|
|
|
|
|
|
|
|
|
|
for ( i=c1 ; i<c2 ; i++ )
|
|
|
|
|
{
|
2012-09-17 22:01:00 +00:00
|
|
|
|
character = static_cast<unsigned char>(m_text[i]);
|
2012-08-20 12:05:36 +00:00
|
|
|
|
if ( bMaj ) character = GetToUpper(character);
|
|
|
|
|
else character = GetToLower(character);
|
2012-06-26 20:23:05 +00:00
|
|
|
|
m_text[i] = character;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Justif();
|
|
|
|
|
ColumnFix();
|
|
|
|
|
SendModifEvent();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Cut all text lines.
|
|
|
|
|
|
|
|
|
|
void CEdit::Justif()
|
|
|
|
|
{
|
2013-05-01 11:19:10 +00:00
|
|
|
|
float width, size, indentLength = 0.0f;
|
2012-06-26 20:23:05 +00:00
|
|
|
|
int i, j, line, indent;
|
|
|
|
|
bool bDual, bString, bRem;
|
|
|
|
|
|
|
|
|
|
indent = 0;
|
|
|
|
|
m_lineTotal = 0;
|
|
|
|
|
m_lineOffset[m_lineTotal] = 0;
|
|
|
|
|
m_lineIndent[m_lineTotal] = indent;
|
|
|
|
|
m_lineTotal ++;
|
|
|
|
|
|
|
|
|
|
if ( m_bAutoIndent )
|
|
|
|
|
{
|
2012-08-20 12:05:36 +00:00
|
|
|
|
indentLength = m_engine->GetText()->GetCharWidth(static_cast<Gfx::UTF8Char>(' '), m_fontType, m_fontSize, 0.0f)
|
|
|
|
|
* m_engine->GetEditIndentValue();
|
2012-06-26 20:23:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bString = bRem = false;
|
|
|
|
|
i = 0;
|
|
|
|
|
while ( true )
|
|
|
|
|
{
|
|
|
|
|
bDual = false;
|
|
|
|
|
|
|
|
|
|
width = m_dim.x-(10.0f/640.0f)*2.0f-(m_bMulti?MARGX*2.0f+SCROLL_WIDTH:0.0f);
|
|
|
|
|
if ( m_bAutoIndent )
|
|
|
|
|
{
|
|
|
|
|
width -= indentLength*m_lineIndent[m_lineTotal-1];
|
|
|
|
|
}
|
|
|
|
|
|
2012-08-31 20:28:07 +00:00
|
|
|
|
if ( m_format.size() == 0 )
|
2012-06-26 20:23:05 +00:00
|
|
|
|
{
|
2012-08-20 12:05:36 +00:00
|
|
|
|
// TODO check if good
|
2012-10-11 21:09:29 +00:00
|
|
|
|
|
2015-07-15 17:52:44 +00:00
|
|
|
|
i += m_engine->GetText()->Justify(m_text.data()+i, m_fontType,
|
2012-09-16 18:00:25 +00:00
|
|
|
|
m_fontSize, width);
|
2012-06-26 20:23:05 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
size = m_fontSize;
|
|
|
|
|
|
2013-02-09 22:49:38 +00:00
|
|
|
|
if ( m_format.size() > static_cast<unsigned int>(i) && (m_format[i]&Gfx::FONT_MASK_TITLE) == Gfx::FONT_TITLE_BIG ) // headline?
|
2012-06-26 20:23:05 +00:00
|
|
|
|
{
|
|
|
|
|
size *= BIG_FONT;
|
|
|
|
|
bDual = true;
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-09 22:49:38 +00:00
|
|
|
|
if ( m_format.size() > static_cast<unsigned int>(i) && (m_format[i]&Gfx::FONT_MASK_IMAGE) != 0 ) // image part?
|
2012-06-26 20:23:05 +00:00
|
|
|
|
{
|
|
|
|
|
i ++; // jumps just a character (index in m_image)
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2012-08-20 12:05:36 +00:00
|
|
|
|
// TODO check if good
|
2015-07-15 17:52:44 +00:00
|
|
|
|
i += m_engine->GetText()->Justify(std::string(m_text.data()+i),
|
2013-02-09 22:49:38 +00:00
|
|
|
|
m_format.begin() + i,
|
2013-02-24 00:40:55 +00:00
|
|
|
|
m_format.end(),
|
2012-08-31 20:28:07 +00:00
|
|
|
|
size,
|
|
|
|
|
width);
|
2012-06-26 20:23:05 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( i >= m_len ) break;
|
|
|
|
|
|
|
|
|
|
if ( m_bAutoIndent )
|
|
|
|
|
{
|
|
|
|
|
for ( j=m_lineOffset[m_lineTotal-1] ; j<i ; j++ )
|
|
|
|
|
{
|
|
|
|
|
if ( !bRem && m_text[j] == '\"' ) bString = !bString;
|
|
|
|
|
if ( !bString &&
|
|
|
|
|
m_text[j] == '/' &&
|
|
|
|
|
m_text[j+1] == '/' ) bRem = true;
|
|
|
|
|
if ( m_text[j] == '\n' ) bString = bRem = false;
|
|
|
|
|
if ( m_text[j] == '{' && !bString && !bRem ) indent ++;
|
|
|
|
|
if ( m_text[j] == '}' && !bString && !bRem ) indent --;
|
|
|
|
|
}
|
|
|
|
|
if ( indent < 0 ) indent = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
m_lineOffset[m_lineTotal] = i;
|
|
|
|
|
m_lineIndent[m_lineTotal] = indent;
|
|
|
|
|
m_lineTotal ++;
|
|
|
|
|
if ( bDual )
|
|
|
|
|
{
|
|
|
|
|
m_lineOffset[m_lineTotal] = i;
|
|
|
|
|
m_lineIndent[m_lineTotal] = indent;
|
|
|
|
|
m_lineTotal ++;
|
|
|
|
|
}
|
|
|
|
|
if ( m_lineTotal >= EDITLINEMAX-2 ) break;
|
|
|
|
|
}
|
2012-10-11 21:09:29 +00:00
|
|
|
|
|
2012-06-26 20:23:05 +00:00
|
|
|
|
if ( m_len > 0 && m_text[m_len-1] == '\n' )
|
|
|
|
|
{
|
|
|
|
|
m_lineOffset[m_lineTotal] = m_len;
|
|
|
|
|
m_lineIndent[m_lineTotal] = 0;
|
|
|
|
|
m_lineTotal ++;
|
|
|
|
|
}
|
|
|
|
|
m_lineOffset[m_lineTotal] = m_len;
|
|
|
|
|
m_lineIndent[m_lineTotal] = 0;
|
|
|
|
|
|
|
|
|
|
if ( m_bAutoIndent )
|
|
|
|
|
{
|
|
|
|
|
for ( i=0 ; i<=m_lineTotal ; i++ )
|
|
|
|
|
{
|
|
|
|
|
if ( m_text[m_lineOffset[i]] == '}' )
|
|
|
|
|
{
|
|
|
|
|
if ( m_lineIndent[i] > 0 ) m_lineIndent[i] --;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( m_bMulti )
|
|
|
|
|
{
|
|
|
|
|
if ( m_bEdit )
|
|
|
|
|
{
|
2012-08-20 12:05:36 +00:00
|
|
|
|
line = GetCursorLine(m_cursor1);
|
2012-06-26 20:23:05 +00:00
|
|
|
|
if ( line < m_lineFirst )
|
|
|
|
|
{
|
|
|
|
|
m_lineFirst = line;
|
|
|
|
|
}
|
|
|
|
|
if ( line >= m_lineFirst+m_lineVisible )
|
|
|
|
|
{
|
|
|
|
|
m_lineFirst = line-m_lineVisible+1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
m_lineFirst = 0;
|
|
|
|
|
}
|
|
|
|
|
|
2012-12-29 12:32:11 +00:00
|
|
|
|
UpdateScroll();
|
2012-06-26 20:23:05 +00:00
|
|
|
|
|
|
|
|
|
m_timeBlink = 0.0f; // lights the cursor immediately
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Returns the rank of the line where the cursor is located.
|
|
|
|
|
|
2012-08-20 12:05:36 +00:00
|
|
|
|
int CEdit::GetCursorLine(int cursor)
|
2012-06-26 20:23:05 +00:00
|
|
|
|
{
|
|
|
|
|
int line, i;
|
|
|
|
|
|
|
|
|
|
line = 0;
|
|
|
|
|
for ( i=0 ; i<m_lineTotal ; i++ )
|
|
|
|
|
{
|
|
|
|
|
if ( cursor >= m_lineOffset[i] )
|
|
|
|
|
{
|
|
|
|
|
line = i;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return line;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Flush the buffer undo.
|
|
|
|
|
|
|
|
|
|
void CEdit::UndoFlush()
|
|
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
for ( i=0 ; i<EDITUNDOMAX ; i++ )
|
|
|
|
|
{
|
2015-07-15 17:52:44 +00:00
|
|
|
|
m_undo[i].text.clear();
|
2012-06-26 20:23:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
m_bUndoForce = true;
|
|
|
|
|
m_undoOper = OPERUNDO_SPEC;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Memorize the current state before a change.
|
|
|
|
|
|
|
|
|
|
void CEdit::UndoMemorize(OperUndo oper)
|
|
|
|
|
{
|
|
|
|
|
int i, len;
|
|
|
|
|
|
|
|
|
|
if ( !m_bUndoForce &&
|
|
|
|
|
oper != OPERUNDO_SPEC &&
|
|
|
|
|
m_undoOper != OPERUNDO_SPEC &&
|
|
|
|
|
oper == m_undoOper ) return;
|
|
|
|
|
|
|
|
|
|
m_bUndoForce = false;
|
|
|
|
|
m_undoOper = oper;
|
|
|
|
|
|
2015-07-15 17:52:44 +00:00
|
|
|
|
m_undo[EDITUNDOMAX-1].text.clear();
|
2012-06-26 20:23:05 +00:00
|
|
|
|
|
|
|
|
|
for ( i=EDITUNDOMAX-1 ; i>=1 ; i-- )
|
|
|
|
|
{
|
|
|
|
|
m_undo[i] = m_undo[i-1];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
len = m_len;
|
|
|
|
|
if ( len == 0 ) len ++;
|
2015-07-15 17:52:44 +00:00
|
|
|
|
m_undo[0].text = m_text;
|
2012-06-26 20:23:05 +00:00
|
|
|
|
m_undo[0].len = m_len;
|
|
|
|
|
|
|
|
|
|
m_undo[0].cursor1 = m_cursor1;
|
|
|
|
|
m_undo[0].cursor2 = m_cursor2;
|
|
|
|
|
m_undo[0].lineFirst = m_lineFirst;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Back to previous state.
|
|
|
|
|
|
|
|
|
|
bool CEdit::UndoRecall()
|
|
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
|
2015-07-15 17:52:44 +00:00
|
|
|
|
if ( m_undo[0].text.empty() ) return false;
|
2012-06-26 20:23:05 +00:00
|
|
|
|
|
|
|
|
|
m_len = m_undo[0].len;
|
2015-07-15 17:52:44 +00:00
|
|
|
|
m_text = m_undo[0].text;
|
2012-06-26 20:23:05 +00:00
|
|
|
|
|
|
|
|
|
m_cursor1 = m_undo[0].cursor1;
|
|
|
|
|
m_cursor2 = m_undo[0].cursor2;
|
|
|
|
|
m_lineFirst = m_undo[0].lineFirst;
|
|
|
|
|
|
|
|
|
|
for ( i=0 ; i<EDITUNDOMAX-1 ; i++ )
|
|
|
|
|
{
|
|
|
|
|
m_undo[i] = m_undo[i+1];
|
|
|
|
|
}
|
2015-07-15 17:52:44 +00:00
|
|
|
|
m_undo[EDITUNDOMAX-1].text.clear();
|
2012-06-26 20:23:05 +00:00
|
|
|
|
|
|
|
|
|
m_bUndoForce = true;
|
|
|
|
|
Justif();
|
|
|
|
|
ColumnFix();
|
|
|
|
|
SendModifEvent();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Clears the format of all characters.
|
|
|
|
|
|
|
|
|
|
bool CEdit::ClearFormat()
|
|
|
|
|
{
|
2012-08-31 20:28:07 +00:00
|
|
|
|
if ( m_format.size() == 0 )
|
2012-06-26 20:23:05 +00:00
|
|
|
|
{
|
|
|
|
|
SetMultiFont(true);
|
|
|
|
|
}
|
2012-08-31 20:28:07 +00:00
|
|
|
|
m_format.clear();
|
2012-06-26 20:23:05 +00:00
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Changes the format of a sequence of characters.
|
|
|
|
|
|
|
|
|
|
bool CEdit::SetFormat(int cursor1, int cursor2, int format)
|
|
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
|
2013-02-09 22:49:38 +00:00
|
|
|
|
if ( m_format.size() < static_cast<unsigned int>(cursor2) )
|
|
|
|
|
SetMultiFont(true);
|
2012-06-26 20:23:05 +00:00
|
|
|
|
|
|
|
|
|
for ( i=cursor1 ; i<cursor2 ; i++ )
|
|
|
|
|
{
|
2013-02-09 22:49:38 +00:00
|
|
|
|
m_format.at(i) |= format;
|
2012-06-26 20:23:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2012-12-29 12:32:11 +00:00
|
|
|
|
void CEdit::UpdateScroll()
|
|
|
|
|
{
|
2015-08-11 20:47:07 +00:00
|
|
|
|
if (m_scroll != nullptr)
|
2012-12-29 12:32:11 +00:00
|
|
|
|
{
|
|
|
|
|
if ( m_lineTotal <= m_lineVisible )
|
|
|
|
|
{
|
|
|
|
|
m_scroll->SetVisibleRatio(1.0f);
|
|
|
|
|
m_scroll->SetVisibleValue(0.0f);
|
|
|
|
|
m_scroll->SetArrowStep(0.0f);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2015-08-11 20:47:07 +00:00
|
|
|
|
float value = static_cast<float>(m_lineVisible) / m_lineTotal;
|
2012-12-29 12:32:11 +00:00
|
|
|
|
m_scroll->SetVisibleRatio(value);
|
|
|
|
|
|
|
|
|
|
value = static_cast<float>(m_lineFirst) / (m_lineTotal - m_lineVisible);
|
|
|
|
|
m_scroll->SetVisibleValue(value);
|
|
|
|
|
|
|
|
|
|
value = 1.0f / (m_lineTotal - m_lineVisible);
|
|
|
|
|
m_scroll->SetArrowStep(value);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2012-06-26 20:23:05 +00:00
|
|
|
|
|
2012-08-20 12:05:36 +00:00
|
|
|
|
}
|