22 #include "precompiled.h"
47 : m_iBufferPos(-1), m_iBufferPos_Tail(-1), m_SelectingText(false), m_HorizontalScroll(0.f),
48 m_PrevTime(0.0), m_CursorVisState(true), m_CursorBlinkRate(0.5)
58 AddSetting(GUIST_CGUISpriteInstance,
"sprite");
59 AddSetting(GUIST_CGUISpriteInstance,
"sprite_selectarea");
61 AddSetting(GUIST_CColor,
"textcolor_selected");
91 CStrW *pCaption = (CStrW*)
m_Settings[
"caption"].m_pSetting;
92 bool shiftKeyPressed =
g_keys[SDLK_RSHIFT] ||
g_keys[SDLK_LSHIFT];
120 *pCaption = pCaption->Left( (
long) pCaption->length()-1);
123 pCaption->Right( (
long) pCaption->length()-
m_iBufferPos );
143 if (pCaption->empty() ||
m_iBufferPos == (int)pCaption->length())
150 pCaption->Right( (
long) pCaption->length()-(
m_iBufferPos+1) );
161 if (!shiftKeyPressed)
180 if (!shiftKeyPressed)
224 if (!shiftKeyPressed)
252 if (!shiftKeyPressed)
297 if (!shiftKeyPressed)
310 m_iBufferPos <= current->m_ListStart+(
int)current->m_ListOfX.size())
321 pos_x = current->m_ListOfX[
m_iBufferPos-current->m_ListStart-1];
342 if (!shiftKeyPressed)
355 m_iBufferPos <= current->m_ListStart+(
int)current->m_ListOfX.size())
366 pos_x = current->m_ListOfX[
m_iBufferPos-current->m_ListStart-1];
417 if (max_length != 0 && (
int)pCaption->length() >= max_length)
430 pCaption->Right((
long) pCaption->length()-
m_iBufferPos);
450 CStrW *pCaption = (CStrW*)
m_Settings[
"caption"].m_pSetting;
451 bool shiftKeyPressed =
g_keys[SDLK_RSHIFT] ||
g_keys[SDLK_LSHIFT];
453 std::string hotkey =
static_cast<const char*
>(ev->
ev.
user.
data1);
454 if (hotkey ==
"paste")
470 pCaption->Right((
long) pCaption->length()-
m_iBufferPos);
481 else if (hotkey ==
"copy" || hotkey ==
"cut")
501 CStrW text = (pCaption->Left(virtualTo)).Right(virtualTo - virtualFrom);
513 else if (hotkey ==
"text.delete.left")
554 else if (hotkey ==
"text.delete.right")
562 if (!pCaption->empty() &&
m_iBufferPos < (int)pCaption->length())
570 if (iswspace((*pCaption)[
m_iBufferPos]) || iswpunct((*pCaption)[m_iBufferPos]))
586 else if (hotkey ==
"text.move.left")
592 if (!shiftKeyPressed)
642 else if (hotkey ==
"text.move.right")
648 if (!shiftKeyPressed)
657 if (!pCaption->empty() &&
m_iBufferPos < (int)pCaption->length())
659 CStrW searchString = *pCaption;
664 if (iswspace((*pCaption)[
m_iBufferPos]) || iswpunct((*pCaption)[m_iBufferPos]))
702 switch (Message.
type)
712 (Message.
value == CStr(
"size") ||
713 Message.
value == CStr(
"z") ||
714 Message.
value == CStr(
"absolute")))
723 if (Message.
value == CStr(
"scrollbar_style"))
725 CStr scrollbar_style;
731 if (Message.
value == CStr(
"size") ||
732 Message.
value == CStr(
"z") ||
733 Message.
value == CStr(
"font") ||
734 Message.
value == CStr(
"absolute") ||
735 Message.
value == CStr(
"caption") ||
736 Message.
value == CStr(
"scrollbar") ||
737 Message.
value == CStr(
"scrollbar_style"))
742 if (Message.
value == CStr(
"multiline"))
747 if (multiline ==
false)
764 bool scrollbar, multiline;
799 CStrW *pCaption = (CStrW*)
m_Settings[
"caption"].m_pSetting;
801 if (pCaption->length() == 0)
813 if ((m_iBufferPos + 1 < (
int) pCaption->length() && iswspace((*pCaption)[m_iBufferPos + 1])) ||
814 (m_iBufferPos - 1 > 0 && iswspace((*pCaption)[m_iBufferPos - 1])))
822 while (m_iBufferPos > 0)
824 if (!iswspace((*pCaption)[m_iBufferPos - 1]))
830 while (m_iBufferPos > 0)
832 if (iswspace((*pCaption)[m_iBufferPos - 1]))
855 if (iswspace((*pCaption)[
m_iBufferPos_Tail]) || iswpunct((*pCaption)[m_iBufferPos_Tail]))
877 if (iswspace((*pCaption)[
m_iBufferPos_Tail]) || iswpunct((*pCaption)[m_iBufferPos_Tail]))
886 while (m_iBufferPos > 0)
888 if (iswspace((*pCaption)[m_iBufferPos - 1]))
893 if (iswpunct((*pCaption)[m_iBufferPos]))
899 if (iswspace((*pCaption)[
m_iBufferPos_Tail]) || iswpunct((*pCaption)[m_iBufferPos_Tail]))
954 CStr scrollbar_style;
1025 if (scrollbar && multiline)
1034 CColor color, color_selected;
1042 CStrW *pCaption = (CStrW*)
m_Settings[
"caption"].m_pSetting;
1055 if (scrollbar && multiline)
1060 CFont font(font_name);
1081 if (cliparea !=
CRect())
1083 glEnable(GL_SCISSOR_TEST);
1088 int VirtualFrom, VirtualTo;
1108 textRenderer.
Font(font_name);
1112 textRenderer.Translate(
1120 float buffered_y = -scroll+buffer_zone;
1126 bool drawing_box =
false;
1129 float x_pointer=0.f;
1149 int VirtualFrom, VirtualTo;
1166 ++it, buffered_y += ls, x_pointer = 0.f)
1176 for (
int i=0; i < (int)it->m_ListOfX.size()+2; ++i)
1178 if (it->m_ListStart + i == VirtualFrom)
1192 const bool at_end = (i == (int)it->m_ListOfX.size()+1);
1194 if (drawing_box ==
true &&
1195 (it->m_ListStart + i == VirtualTo || at_end))
1201 if (it->m_ListStart + i != VirtualFrom)
1209 drawing_box =
false;
1245 if (sprite_selectarea)
1249 if (i < (
int)it->m_ListOfX.size())
1267 buffered_y = -scroll;
1270 textRenderer.Color(color);
1274 bool using_selected_color =
false;
1278 ++it, buffered_y += ls)
1280 if (buffered_y + buffer_zone >= -ls || !multiline)
1288 CMatrix3D savedTransform = textRenderer.GetTransform();
1292 textRenderer.
Translate(0.f, -(
float)(
int)scroll, 0.f);
1298 for (
int i=0; i < (int)it->m_ListOfX.size()+1; ++i)
1300 if (!multiline && i < (
int)it->m_ListOfX.size())
1302 if (it->m_ListOfX[i] - m_HorizontalScroll < -buffer_zone)
1306 textRenderer.Translate(it->m_ListOfX[i], 0.f, 0.f);
1308 textRenderer.Translate(it->m_ListOfX[i] - it->m_ListOfX[i-1], 0.f, 0.f);
1316 it->m_ListStart + i == VirtualTo)
1318 using_selected_color =
false;
1319 textRenderer.Color(color);
1322 if (i != (
int)it->m_ListOfX.size() &&
1327 textRenderer.Put(0.0f, 0.0f, L
"_");
1332 it->m_ListStart + i >= VirtualFrom &&
1333 it->m_ListStart + i < VirtualTo &&
1334 using_selected_color ==
false)
1336 using_selected_color =
true;
1337 textRenderer.Color(color_selected);
1340 if (i != (
int)it->m_ListOfX.size())
1341 textRenderer.PrintfAdvance(L
"%lc", (*pCaption)[it->m_ListStart + i]);
1344 if (!multiline && i < (
int)it->m_ListOfX.size())
1351 if (it->m_ListStart + (
int)it->m_ListOfX.size() ==
m_iBufferPos)
1353 textRenderer.Color(color);
1355 textRenderer.PutAdvance(L
"_");
1357 if (using_selected_color)
1359 textRenderer.Color(color_selected);
1363 textRenderer.SetTransform(savedTransform);
1366 textRenderer.Translate(0.f, ls, 0.f);
1369 textRenderer.Render();
1371 if (cliparea !=
CRect())
1372 glDisable(GL_SCISSOR_TEST);
1393 if (font_name.empty())
1406 if (to_before == -1)
1407 to = (int)caption.length();
1409 CFont font(font_name);
1411 std::list<SRow>::iterator current_line;
1414 int check_point_row_start = -1;
1415 int check_point_row_end = -1;
1418 if (from == 0 && to_before == -1)
1427 std::list<SRow>::iterator destroy_row_from, destroy_row_to;
1432 bool destroy_row_from_used=
false, destroy_row_to_used=
false;
1442 if (destroy_row_from_used ==
false &&
1443 it->m_ListStart > from)
1446 destroy_row_from = it;
1449 destroy_row_from_used =
true;
1459 if (destroy_row_to_used ==
false &&
1460 it->m_ListStart > to_before)
1462 destroy_row_to = it;
1464 destroy_row_to_used =
true;
1474 check_point_row_start = destroy_row_to->m_ListStart;
1475 check_point_row_end = check_point_row_start + (int)destroy_row_to->m_ListOfX.size();
1476 if (destroy_row_to->m_ListOfX.empty())
1477 ++check_point_row_end;
1485 if (destroy_row_from_used ==
false)
1494 destroy_row_from_used =
true;
1496 current_line = destroy_row_from;
1499 if (destroy_row_to_used ==
false)
1502 check_point_row_start = -1;
1504 destroy_row_from_used =
true;
1509 from = destroy_row_from->m_ListStart;
1512 to = destroy_row_to->m_ListStart;
1514 to = (
int)caption.length();
1520 std::list<SRow>::iterator temp_it = destroy_row_to;
1529 int delta = to_after - to_before;
1532 for (std::list<SRow>::iterator it = current_line;
1536 it->m_ListStart += delta;
1540 check_point_row_start += delta;
1541 check_point_row_end += delta;
1543 if (to != (
int)caption.length())
1548 int last_word_started=from;
1555 for (
int i=from; i<to; ++i)
1557 if (caption[i] == L
'\n' && multiline)
1559 if (i==to-1 && to != (
int)caption.length())
1574 if (caption[i] == L
' '
1576 last_word_started = i+1;
1587 last_word_started = i;
1611 i=last_word_started-1;
1628 std::list<SRow>::iterator destroy_row_from, destroy_row_to;
1633 bool destroy_row_from_used=
false, destroy_row_to_used=
false;
1643 if (destroy_row_from_used ==
false &&
1644 it->m_ListStart > check_point_row_start)
1651 destroy_row_from = it;
1652 destroy_row_from_used =
true;
1656 if (destroy_row_to_used ==
false &&
1657 it->m_ListStart > check_point_row_end)
1659 destroy_row_to = it;
1660 destroy_row_to_used =
true;
1671 check_point_row_start = destroy_row_to->m_ListStart;
1672 check_point_row_end = check_point_row_start + (int)destroy_row_to->m_ListOfX.size();
1673 if (destroy_row_to->m_ListOfX.empty())
1674 ++check_point_row_end;
1677 check_point_row_start = check_point_row_end = -1;
1684 if (destroy_row_from_used ==
false)
1689 destroy_row_from_used =
true;
1691 current_line = destroy_row_from;
1694 if (destroy_row_to_used ==
false)
1697 check_point_row_start = check_point_row_end = -1;
1699 destroy_row_to_used =
true;
1704 from = destroy_row_from->m_ListStart;
1707 to = destroy_row_to->m_ListStart;
1709 to = (
int)caption.length();
1715 current_line = destroy_row_to;
1717 std::list<SRow>::iterator temp = destroy_row_to;
1780 CStrW *pCaption = (CStrW*)
m_Settings[
"caption"].m_pSetting;
1785 CFont font(font_name);
1791 mouse.
x -= buffer_zone;
1792 mouse.
y += scroll - buffer_zone;
1796 int row = (int)((mouse.
y) / spacing);
1807 for (
int i=0; i<row; ++i)
1820 retPosition = current->m_ListStart;
1836 for (std::vector<float>::iterator it=current->m_ListOfX.begin();
1837 it!=current->m_ListOfX.end();
1842 if (x - previous >= *it - x)
1853 if (i == (
int)current->m_ListOfX.size())
1865 CStrW *pCaption = (CStrW*)
m_Settings[
"caption"].m_pSetting;
1881 *pCaption = pCaption->Left( virtualFrom ) +
1882 pCaption->Right( (
long) pCaption->length() - (virtualTo) );
1884 UpdateText(virtualFrom, virtualTo, virtualFrom);
1933 CFont font(font_name);
1945 m_iBufferPos <= current->m_ListStart+(
int)current->m_ListOfX.size())
1960 if (-scroll + (
float)row * spacing < 0.f)
1972 float x_position = 0.f;
1973 float x_total = 0.f;
void Translate(float x, float y, float z)
void DrawSprite(const CGUISpriteInstance &Sprite, int CellID, const float &Z, const CRect &Rect, const CRect &Clipping=CRect())
Draw GUI Sprite.
Status sys_clipboard_set(const wchar_t *text)
int GetCharacterWidth(wchar_t c)
float left
Returning CPos representing each corner.
static PSRETURN GetSetting(const IGUIObject *pObject, const CStr &Setting, T &Value)
Retrieves a setting by name from object pointer.
#define CFG_GET_VAL(name, type, destination)
shared_ptr< CShaderTechnique > CShaderTechniquePtr
Status sys_clipboard_free(wchar_t *copy)
virtual float GetBufferedZ() const
Returns not the Z value, but the actual buffered Z value, i.e.
virtual void UpdateCachedSize()
All sizes are relative to resolution, and the calculation is not wanted in real time, therefore it is cached, update the cached size with this function.
#define ENSURE(expr)
ensure the expression <expr> evaluates to non-zero.
#define UNUSED2(param)
mark a function local variable or parameter as unused and avoid the corresponding compiler warning...
std::map< CStr, SGUISetting > m_Settings
Settings pool, all an object's settings are located here If a derived object has got more settings th...
bool g_mouse_buttons[6]
g_mouse_buttons: Mouse buttons states, indexed by SDL_BUTTON_* constants.
void AddSetting(const EGUISettingType &Type, const CStr &Name)
Add a setting to m_Settings.
CRect m_CachedActualSize
Cached size, real size m_Size is actually dependent on resolution and can have different real outcome...
Made to represent screen positions and delta values.
InReaction SendEvent(EGUIMessageType type, const CStr &EventName)
Send event to this GUI object (HandleMessage and ScriptEvent)
wchar_t * sys_clipboard_get()
CPos GetMousePos() const
Get Mouse from CGUI.
void Font(const CStrW &font)
Set the font for subsequent print calls.
Message send to IGUIObject::HandleMessage() in order to give life to Objects manually with a derived ...
EGUIMessageType type
Describes what the message regards.
CPos TopLeft() const
Get Position equivalent to top/left corner.
std::map< int32_t, bool > g_keys
g_keys: Key states, indexed by SDLK* constants.
static PSRETURN GetSettingPointer(const IGUIObject *pObject, const CStr &Setting, T *&Value)
Rectangle class used for screen rectangles.