- adding events EGET_EDITBOX_CHANGED and EGET_EDITBOX_MARKING_CHANGED

- prevent editbox from recalculating its textbreaking each frame
- let spinbox react on each textchange without waiting for enter to prevent getting value changes without corresponding 
EGET_SPINBOX_CHANGED events.


git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@2411 dfc29bdd-3216-0410-991c-e03cc46cb475
master
cutealien 2009-06-07 01:02:42 +00:00
parent 7e3770c871
commit a7865ae234
4 changed files with 112 additions and 64 deletions

View File

@ -183,9 +183,15 @@ namespace irr
//! 'Cancel' was clicked on a messagebox //! 'Cancel' was clicked on a messagebox
EGET_MESSAGEBOX_CANCEL, EGET_MESSAGEBOX_CANCEL,
//! In an editbox was pressed 'ENTER' //! In an editbox 'ENTER' was pressed
EGET_EDITBOX_ENTER, EGET_EDITBOX_ENTER,
//! The text in an editbox was changed. This does not include automatic changes in text-breaking.
EGET_EDITBOX_CHANGED,
//! The marked area in an editbox was changed.
EGET_EDITBOX_MARKING_CHANGED,
//! The tab was changed in an tab control //! The tab was changed in an tab control
EGET_TAB_CHANGED, EGET_TAB_CHANGED,

View File

@ -67,6 +67,10 @@ CGUIEditBox::CGUIEditBox(const wchar_t* text, bool border,
} }
breakText(); breakText();
if ( Text.size() )
sendGuiEvent(EGET_EDITBOX_CHANGED);
calculateScrollPos(); calculateScrollPos();
} }
@ -132,8 +136,12 @@ void CGUIEditBox::setWordWrap(bool enable)
void CGUIEditBox::updateAbsolutePosition() void CGUIEditBox::updateAbsolutePosition()
{ {
core::rect<s32> oldAbsoluteRect(AbsoluteRect);
IGUIElement::updateAbsolutePosition(); IGUIElement::updateAbsolutePosition();
breakText(); if ( oldAbsoluteRect != AbsoluteRect )
{
breakText();
}
} }
@ -202,8 +210,7 @@ bool CGUIEditBox::OnEvent(const SEvent& event)
if (event.GUIEvent.Caller == this) if (event.GUIEvent.Caller == this)
{ {
MouseMarking = false; MouseMarking = false;
MarkBegin = 0; setTextMarkers(0,0);
MarkEnd = 0;
} }
} }
break; break;
@ -230,6 +237,8 @@ bool CGUIEditBox::processKey(const SEvent& event)
return false; return false;
bool textChanged = false; bool textChanged = false;
s32 newMarkBegin = MarkBegin;
s32 newMarkEnd = MarkEnd;
// control shortcut handling // control shortcut handling
@ -245,8 +254,8 @@ bool CGUIEditBox::processKey(const SEvent& event)
{ {
case KEY_KEY_A: case KEY_KEY_A:
// select all // select all
MarkBegin = 0; newMarkBegin = 0;
MarkEnd = Text.size(); newMarkEnd = Text.size();
break; break;
case KEY_KEY_C: case KEY_KEY_C:
// copy to clipboard // copy to clipboard
@ -281,8 +290,8 @@ bool CGUIEditBox::processKey(const SEvent& event)
Text = s; Text = s;
CursorPos = realmbgn; CursorPos = realmbgn;
MarkBegin = 0; newMarkBegin = 0;
MarkEnd = 0; newMarkEnd = 0;
textChanged = true; textChanged = true;
} }
} }
@ -332,8 +341,8 @@ bool CGUIEditBox::processKey(const SEvent& event)
} }
} }
MarkBegin = 0; newMarkBegin = 0;
MarkEnd = 0; newMarkEnd = 0;
textChanged = true; textChanged = true;
} }
break; break;
@ -341,30 +350,30 @@ bool CGUIEditBox::processKey(const SEvent& event)
// move/highlight to start of text // move/highlight to start of text
if (event.KeyInput.Shift) if (event.KeyInput.Shift)
{ {
MarkEnd = CursorPos; newMarkEnd = CursorPos;
MarkBegin = 0; newMarkBegin = 0;
CursorPos = 0; CursorPos = 0;
} }
else else
{ {
CursorPos = 0; CursorPos = 0;
MarkBegin = 0; newMarkBegin = 0;
MarkEnd = 0; newMarkEnd = 0;
} }
break; break;
case KEY_END: case KEY_END:
// move/highlight to end of text // move/highlight to end of text
if (event.KeyInput.Shift) if (event.KeyInput.Shift)
{ {
MarkBegin = CursorPos; newMarkBegin = CursorPos;
MarkEnd = Text.size(); newMarkEnd = Text.size();
CursorPos = 0; CursorPos = 0;
} }
else else
{ {
CursorPos = Text.size(); CursorPos = Text.size();
MarkBegin = 0; newMarkBegin = 0;
MarkEnd = 0; newMarkEnd = 0;
} }
break; break;
default: default:
@ -389,14 +398,14 @@ bool CGUIEditBox::processKey(const SEvent& event)
if (event.KeyInput.Shift) if (event.KeyInput.Shift)
{ {
if (MarkBegin == MarkEnd) if (MarkBegin == MarkEnd)
MarkBegin = CursorPos; newMarkBegin = CursorPos;
MarkEnd = p; newMarkEnd = p;
} }
else else
{ {
MarkBegin = 0; newMarkBegin = 0;
MarkEnd = 0; newMarkEnd = 0;
} }
CursorPos = p; CursorPos = p;
BlinkStartTime = os::Timer::getTime(); BlinkStartTime = os::Timer::getTime();
@ -415,13 +424,13 @@ bool CGUIEditBox::processKey(const SEvent& event)
if (event.KeyInput.Shift) if (event.KeyInput.Shift)
{ {
if (MarkBegin == MarkEnd) if (MarkBegin == MarkEnd)
MarkBegin = CursorPos; newMarkBegin = CursorPos;
MarkEnd = p; newMarkEnd = p;
} }
else else
{ {
MarkBegin = 0; newMarkBegin = 0;
MarkEnd = 0; newMarkEnd = 0;
} }
CursorPos = p; CursorPos = p;
BlinkStartTime = os::Timer::getTime(); BlinkStartTime = os::Timer::getTime();
@ -434,13 +443,7 @@ bool CGUIEditBox::processKey(const SEvent& event)
} }
else else
{ {
SEvent e; sendGuiEvent( EGET_EDITBOX_ENTER );
e.EventType = EET_GUI_EVENT;
e.GUIEvent.Caller = this;
e.GUIEvent.Element = 0;
e.GUIEvent.EventType = EGET_EDITBOX_ENTER;
if (Parent)
Parent->OnEvent(e);
} }
break; break;
case KEY_LEFT: case KEY_LEFT:
@ -450,15 +453,15 @@ bool CGUIEditBox::processKey(const SEvent& event)
if (CursorPos > 0) if (CursorPos > 0)
{ {
if (MarkBegin == MarkEnd) if (MarkBegin == MarkEnd)
MarkBegin = CursorPos; newMarkBegin = CursorPos;
MarkEnd = CursorPos-1; newMarkEnd = CursorPos-1;
} }
} }
else else
{ {
MarkBegin = 0; newMarkBegin = 0;
MarkEnd = 0; newMarkEnd = 0;
} }
if (CursorPos > 0) CursorPos--; if (CursorPos > 0) CursorPos--;
@ -471,15 +474,15 @@ bool CGUIEditBox::processKey(const SEvent& event)
if (Text.size() > (u32)CursorPos) if (Text.size() > (u32)CursorPos)
{ {
if (MarkBegin == MarkEnd) if (MarkBegin == MarkEnd)
MarkBegin = CursorPos; newMarkBegin = CursorPos;
MarkEnd = CursorPos+1; newMarkEnd = CursorPos+1;
} }
} }
else else
{ {
MarkBegin = 0; newMarkBegin = 0;
MarkEnd = 0; newMarkEnd = 0;
} }
if (Text.size() > (u32)CursorPos) CursorPos++; if (Text.size() > (u32)CursorPos) CursorPos++;
@ -501,13 +504,13 @@ bool CGUIEditBox::processKey(const SEvent& event)
if (event.KeyInput.Shift) if (event.KeyInput.Shift)
{ {
MarkBegin = mb; newMarkBegin = mb;
MarkEnd = CursorPos; newMarkEnd = CursorPos;
} }
else else
{ {
MarkBegin = 0; newMarkBegin = 0;
MarkEnd = 0; newMarkEnd = 0;
} }
} }
@ -532,13 +535,13 @@ bool CGUIEditBox::processKey(const SEvent& event)
if (event.KeyInput.Shift) if (event.KeyInput.Shift)
{ {
MarkBegin = mb; newMarkBegin = mb;
MarkEnd = CursorPos; newMarkEnd = CursorPos;
} }
else else
{ {
MarkBegin = 0; newMarkBegin = 0;
MarkEnd = 0; newMarkEnd = 0;
} }
} }
@ -583,8 +586,8 @@ bool CGUIEditBox::processKey(const SEvent& event)
if (CursorPos < 0) if (CursorPos < 0)
CursorPos = 0; CursorPos = 0;
BlinkStartTime = os::Timer::getTime(); BlinkStartTime = os::Timer::getTime();
MarkBegin = 0; newMarkBegin = 0;
MarkEnd = 0; newMarkEnd = 0;
textChanged = true; textChanged = true;
} }
break; break;
@ -620,8 +623,8 @@ bool CGUIEditBox::processKey(const SEvent& event)
CursorPos = (s32)Text.size(); CursorPos = (s32)Text.size();
BlinkStartTime = os::Timer::getTime(); BlinkStartTime = os::Timer::getTime();
MarkBegin = 0; newMarkBegin = 0;
MarkEnd = 0; newMarkEnd = 0;
textChanged = true; textChanged = true;
} }
break; break;
@ -661,9 +664,15 @@ bool CGUIEditBox::processKey(const SEvent& event)
break; break;
} }
// Set new text markers
setTextMarkers( newMarkBegin, newMarkEnd );
// break the text if it has changed // break the text if it has changed
if (textChanged) if (textChanged)
{
breakText(); breakText();
sendGuiEvent(EGET_EDITBOX_CHANGED);
}
calculateScrollPos(); calculateScrollPos();
@ -712,7 +721,9 @@ void CGUIEditBox::draw()
if (font) if (font)
{ {
if (LastBreakFont != font) if (LastBreakFont != font)
{
breakText(); breakText();
}
// calculate cursor pos // calculate cursor pos
@ -862,9 +873,9 @@ void CGUIEditBox::setText(const wchar_t* text)
Text = text; Text = text;
CursorPos = 0; CursorPos = 0;
HScrollPos = 0; HScrollPos = 0;
MarkBegin = 0; setTextMarkers(0, 0);
MarkEnd = 0;
breakText(); breakText();
sendGuiEvent(EGET_EDITBOX_CHANGED);
} }
@ -933,7 +944,9 @@ bool CGUIEditBox::processMouse(const SEvent& event)
{ {
CursorPos = getCursorPos(event.MouseInput.X, event.MouseInput.Y); CursorPos = getCursorPos(event.MouseInput.X, event.MouseInput.Y);
if (MouseMarking) if (MouseMarking)
MarkEnd = CursorPos; {
setTextMarkers( MarkBegin, CursorPos );
}
MouseMarking = false; MouseMarking = false;
calculateScrollPos(); calculateScrollPos();
return true; return true;
@ -944,7 +957,7 @@ bool CGUIEditBox::processMouse(const SEvent& event)
if (MouseMarking) if (MouseMarking)
{ {
CursorPos = getCursorPos(event.MouseInput.X, event.MouseInput.Y); CursorPos = getCursorPos(event.MouseInput.X, event.MouseInput.Y);
MarkEnd = CursorPos; setTextMarkers( MarkBegin, CursorPos );
calculateScrollPos(); calculateScrollPos();
return true; return true;
} }
@ -956,8 +969,7 @@ bool CGUIEditBox::processMouse(const SEvent& event)
BlinkStartTime = os::Timer::getTime(); BlinkStartTime = os::Timer::getTime();
MouseMarking = true; MouseMarking = true;
CursorPos = getCursorPos(event.MouseInput.X, event.MouseInput.Y); CursorPos = getCursorPos(event.MouseInput.X, event.MouseInput.Y);
MarkBegin = CursorPos; setTextMarkers(CursorPos, CursorPos );
MarkEnd = CursorPos;
calculateScrollPos(); calculateScrollPos();
return true; return true;
} }
@ -973,11 +985,12 @@ bool CGUIEditBox::processMouse(const SEvent& event)
// move cursor // move cursor
CursorPos = getCursorPos(event.MouseInput.X, event.MouseInput.Y); CursorPos = getCursorPos(event.MouseInput.X, event.MouseInput.Y);
s32 newMarkBegin = MarkBegin;
if (!MouseMarking) if (!MouseMarking)
MarkBegin = CursorPos; newMarkBegin = CursorPos;
MouseMarking = true; MouseMarking = true;
MarkEnd = CursorPos; setTextMarkers( newMarkBegin, CursorPos);
calculateScrollPos(); calculateScrollPos();
return true; return true;
} }
@ -1273,11 +1286,11 @@ void CGUIEditBox::inputChar(wchar_t c)
} }
BlinkStartTime = os::Timer::getTime(); BlinkStartTime = os::Timer::getTime();
MarkBegin = 0; setTextMarkers(0, 0);
MarkEnd = 0;
} }
} }
breakText(); breakText();
sendGuiEvent(EGET_EDITBOX_CHANGED);
} }
@ -1331,6 +1344,31 @@ void CGUIEditBox::calculateScrollPos()
// todo: adjust scrollbar // todo: adjust scrollbar
} }
//! set text markers
void CGUIEditBox::setTextMarkers(s32 begin, s32 end)
{
if ( begin != MarkBegin || end != MarkEnd )
{
MarkBegin = begin;
MarkEnd = end;
sendGuiEvent(EGET_EDITBOX_MARKING_CHANGED);
}
}
//! send some gui event to parent
void CGUIEditBox::sendGuiEvent(EGUI_EVENT_TYPE type)
{
if ( Parent )
{
SEvent e;
e.EventType = EET_GUI_EVENT;
e.GUIEvent.Caller = this;
e.GUIEvent.Element = 0;
e.GUIEvent.EventType = type;
Parent->OnEvent(e);
}
}
//! Writes attributes of the element. //! Writes attributes of the element.
void CGUIEditBox::serializeAttributes(io::IAttributes* out, io::SAttributeReadWriteOptions* options=0) const void CGUIEditBox::serializeAttributes(io::IAttributes* out, io::SAttributeReadWriteOptions* options=0) const

View File

@ -117,6 +117,10 @@ namespace gui
void inputChar(wchar_t c); void inputChar(wchar_t c);
//! calculates the current scroll position //! calculates the current scroll position
void calculateScrollPos(); void calculateScrollPos();
//! send some gui event to parent
void sendGuiEvent(EGUI_EVENT_TYPE type);
//! set text markers
void setTextMarkers(s32 begin, s32 end);
bool processKey(const SEvent& event); bool processKey(const SEvent& event);
bool processMouse(const SEvent& event); bool processMouse(const SEvent& event);

View File

@ -199,7 +199,7 @@ bool CGUISpinBox::OnEvent(const SEvent& event)
changeEvent = true; changeEvent = true;
} }
} }
if ( event.GUIEvent.EventType == EGET_EDITBOX_ENTER ) if ( event.GUIEvent.EventType == EGET_EDITBOX_CHANGED )
{ {
if (event.GUIEvent.Caller == EditBox) if (event.GUIEvent.Caller == EditBox)
{ {