Commit c4988bda authored by cutealien's avatar cutealien

EditBox works now with numpad on X11 (thx @Hendu for bureport).


git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@4926 dfc29bdd-3216-0410-991c-e03cc46cb475
parent f591a5ac
-------------------------- --------------------------
Changes in 1.9 (not yet released) Changes in 1.9 (not yet released)
- EditBox works now with numpad on X11
- Added helper functions for converting between wchar and utf-8. Patch provided by Hendu. - Added helper functions for converting between wchar and utf-8. Patch provided by Hendu.
- Added sphere frustum culling support. Patch provided by Hendu. - Added sphere frustum culling support. Patch provided by Hendu.
- Fixed issues with setViewPort method under OpenGL. (reported by anontypist) - Fixed issues with setViewPort method under OpenGL. (reported by anontypist)
......
...@@ -423,295 +423,306 @@ bool CGUIEditBox::processKey(const SEvent& event) ...@@ -423,295 +423,306 @@ bool CGUIEditBox::processKey(const SEvent& event)
return false; return false;
} }
} }
// default keyboard handling // Some special keys - but only handle them if KeyInput.Char is null as on some systems (X11) they might have same key-code as ansi-keys otherwise
else else if (event.KeyInput.Char == 0)
switch(event.KeyInput.Key)
{ {
case KEY_END: switch(event.KeyInput.Key)
{ {
s32 p = Text.size(); case KEY_END:
if (WordWrap || MultiLine)
{ {
p = getLineFromPos(CursorPos); s32 p = Text.size();
p = BrokenTextPositions[p] + (s32)BrokenText[p].size(); if (WordWrap || MultiLine)
if (p > 0 && (Text[p-1] == L'\r' || Text[p-1] == L'\n' )) {
p-=1; p = getLineFromPos(CursorPos);
p = BrokenTextPositions[p] + (s32)BrokenText[p].size();
if (p > 0 && (Text[p-1] == L'\r' || Text[p-1] == L'\n' ))
p-=1;
}
if (event.KeyInput.Shift)
{
if (MarkBegin == MarkEnd)
newMarkBegin = CursorPos;
newMarkEnd = p;
}
else
{
newMarkBegin = 0;
newMarkEnd = 0;
}
CursorPos = p;
BlinkStartTime = os::Timer::getTime();
} }
break;
case KEY_HOME:
{
s32 p = 0;
if (WordWrap || MultiLine)
{
p = getLineFromPos(CursorPos);
p = BrokenTextPositions[p];
}
if (event.KeyInput.Shift)
{
if (MarkBegin == MarkEnd)
newMarkBegin = CursorPos;
newMarkEnd = p;
}
else
{
newMarkBegin = 0;
newMarkEnd = 0;
}
CursorPos = p;
BlinkStartTime = os::Timer::getTime();
}
break;
case KEY_LEFT:
if (event.KeyInput.Shift) if (event.KeyInput.Shift)
{ {
if (MarkBegin == MarkEnd) if (CursorPos > 0)
newMarkBegin = CursorPos; {
if (MarkBegin == MarkEnd)
newMarkBegin = CursorPos;
newMarkEnd = p; newMarkEnd = CursorPos-1;
}
} }
else else
{ {
newMarkBegin = 0; newMarkBegin = 0;
newMarkEnd = 0; newMarkEnd = 0;
} }
CursorPos = p;
BlinkStartTime = os::Timer::getTime();
}
break;
case KEY_HOME:
{
s32 p = 0; if (CursorPos > 0) CursorPos--;
if (WordWrap || MultiLine) BlinkStartTime = os::Timer::getTime();
{ break;
p = getLineFromPos(CursorPos);
p = BrokenTextPositions[p];
}
case KEY_RIGHT:
if (event.KeyInput.Shift) if (event.KeyInput.Shift)
{ {
if (MarkBegin == MarkEnd) if (Text.size() > (u32)CursorPos)
newMarkBegin = CursorPos; {
newMarkEnd = p; if (MarkBegin == MarkEnd)
newMarkBegin = CursorPos;
newMarkEnd = CursorPos+1;
}
} }
else else
{ {
newMarkBegin = 0; newMarkBegin = 0;
newMarkEnd = 0; newMarkEnd = 0;
} }
CursorPos = p;
BlinkStartTime = os::Timer::getTime();
}
break;
case KEY_RETURN:
if (MultiLine)
{
inputChar(L'\n');
}
else
{
calculateScrollPos();
sendGuiEvent( EGET_EDITBOX_ENTER );
}
return true;
case KEY_LEFT:
if (event.KeyInput.Shift) if (Text.size() > (u32)CursorPos) CursorPos++;
{ BlinkStartTime = os::Timer::getTime();
if (CursorPos > 0) break;
case KEY_UP:
if (MultiLine || (WordWrap && BrokenText.size() > 1) )
{ {
if (MarkBegin == MarkEnd) s32 lineNo = getLineFromPos(CursorPos);
newMarkBegin = CursorPos; s32 mb = (MarkBegin == MarkEnd) ? CursorPos : (MarkBegin > MarkEnd ? MarkBegin : MarkEnd);
if (lineNo > 0)
newMarkEnd = CursorPos-1; {
} s32 cp = CursorPos - BrokenTextPositions[lineNo];
} if ((s32)BrokenText[lineNo-1].size() < cp)
else CursorPos = BrokenTextPositions[lineNo-1] + core::max_((u32)1, BrokenText[lineNo-1].size())-1;
{ else
newMarkBegin = 0; CursorPos = BrokenTextPositions[lineNo-1] + cp;
newMarkEnd = 0; }
}
if (CursorPos > 0) CursorPos--; if (event.KeyInput.Shift)
BlinkStartTime = os::Timer::getTime(); {
break; newMarkBegin = mb;
newMarkEnd = CursorPos;
}
else
{
newMarkBegin = 0;
newMarkEnd = 0;
}
case KEY_RIGHT: }
if (event.KeyInput.Shift) else
{
if (Text.size() > (u32)CursorPos)
{ {
if (MarkBegin == MarkEnd) return false;
newMarkBegin = CursorPos;
newMarkEnd = CursorPos+1;
} }
} break;
else case KEY_DOWN:
{ if (MultiLine || (WordWrap && BrokenText.size() > 1) )
newMarkBegin = 0;
newMarkEnd = 0;
}
if (Text.size() > (u32)CursorPos) CursorPos++;
BlinkStartTime = os::Timer::getTime();
break;
case KEY_UP:
if (MultiLine || (WordWrap && BrokenText.size() > 1) )
{
s32 lineNo = getLineFromPos(CursorPos);
s32 mb = (MarkBegin == MarkEnd) ? CursorPos : (MarkBegin > MarkEnd ? MarkBegin : MarkEnd);
if (lineNo > 0)
{ {
s32 cp = CursorPos - BrokenTextPositions[lineNo]; s32 lineNo = getLineFromPos(CursorPos);
if ((s32)BrokenText[lineNo-1].size() < cp) s32 mb = (MarkBegin == MarkEnd) ? CursorPos : (MarkBegin < MarkEnd ? MarkBegin : MarkEnd);
CursorPos = BrokenTextPositions[lineNo-1] + core::max_((u32)1, BrokenText[lineNo-1].size())-1; if (lineNo < (s32)BrokenText.size()-1)
{
s32 cp = CursorPos - BrokenTextPositions[lineNo];
if ((s32)BrokenText[lineNo+1].size() < cp)
CursorPos = BrokenTextPositions[lineNo+1] + core::max_((u32)1, BrokenText[lineNo+1].size())-1;
else
CursorPos = BrokenTextPositions[lineNo+1] + cp;
}
if (event.KeyInput.Shift)
{
newMarkBegin = mb;
newMarkEnd = CursorPos;
}
else else
CursorPos = BrokenTextPositions[lineNo-1] + cp; {
} newMarkBegin = 0;
newMarkEnd = 0;
}
if (event.KeyInput.Shift)
{
newMarkBegin = mb;
newMarkEnd = CursorPos;
} }
else else
{ {
newMarkBegin = 0; return false;
newMarkEnd = 0;
} }
break;
case KEY_INSERT:
if ( !isEnabled() )
break;
} OverwriteMode = !OverwriteMode;
else break;
{ case KEY_DELETE:
return false; if ( !isEnabled() )
} break;
break;
case KEY_DOWN: if (Text.size() != 0)
if (MultiLine || (WordWrap && BrokenText.size() > 1) )
{
s32 lineNo = getLineFromPos(CursorPos);
s32 mb = (MarkBegin == MarkEnd) ? CursorPos : (MarkBegin < MarkEnd ? MarkBegin : MarkEnd);
if (lineNo < (s32)BrokenText.size()-1)
{ {
s32 cp = CursorPos - BrokenTextPositions[lineNo]; core::stringw s;
if ((s32)BrokenText[lineNo+1].size() < cp)
CursorPos = BrokenTextPositions[lineNo+1] + core::max_((u32)1, BrokenText[lineNo+1].size())-1; if (MarkBegin != MarkEnd)
{
// delete marked text
const s32 realmbgn = MarkBegin < MarkEnd ? MarkBegin : MarkEnd;
const s32 realmend = MarkBegin < MarkEnd ? MarkEnd : MarkBegin;
s = Text.subString(0, realmbgn);
s.append( Text.subString(realmend, Text.size()-realmend) );
Text = s;
CursorPos = realmbgn;
}
else else
CursorPos = BrokenTextPositions[lineNo+1] + cp; {
} // delete text before cursor
s = Text.subString(0, CursorPos);
s.append( Text.subString(CursorPos+1, Text.size()-CursorPos-1) );
Text = s;
}
if (event.KeyInput.Shift) if (CursorPos > (s32)Text.size())
{ CursorPos = (s32)Text.size();
newMarkBegin = mb;
newMarkEnd = CursorPos; BlinkStartTime = os::Timer::getTime();
}
else
{
newMarkBegin = 0; newMarkBegin = 0;
newMarkEnd = 0; newMarkEnd = 0;
textChanged = true;
} }
break;
} default:
else
{
return false; return false;
} }
break; }
else
case KEY_BACK: {
if ( !isEnabled() ) // default keyboard handling
break; switch(event.KeyInput.Key)
if (Text.size())
{ {
core::stringw s; case KEY_RETURN:
if (MultiLine)
if (MarkBegin != MarkEnd)
{ {
// delete marked text inputChar(L'\n');
const s32 realmbgn = MarkBegin < MarkEnd ? MarkBegin : MarkEnd;
const s32 realmend = MarkBegin < MarkEnd ? MarkEnd : MarkBegin;
s = Text.subString(0, realmbgn);
s.append( Text.subString(realmend, Text.size()-realmend) );
Text = s;
CursorPos = realmbgn;
} }
else else
{ {
// delete text behind cursor calculateScrollPos();
if (CursorPos>0) sendGuiEvent( EGET_EDITBOX_ENTER );
s = Text.subString(0, CursorPos-1);
else
s = L"";
s.append( Text.subString(CursorPos, Text.size()-CursorPos) );
Text = s;
--CursorPos;
} }
return true;
if (CursorPos < 0) case KEY_BACK:
CursorPos = 0; if ( !isEnabled() )
BlinkStartTime = os::Timer::getTime(); break;
newMarkBegin = 0;
newMarkEnd = 0;
textChanged = true;
}
break;
case KEY_INSERT:
if ( !isEnabled() )
break;
OverwriteMode = !OverwriteMode; if (Text.size())
break; {
case KEY_DELETE: core::stringw s;
if ( !isEnabled() )
break;
if (Text.size() != 0) if (MarkBegin != MarkEnd)
{ {
core::stringw s; // delete marked text
const s32 realmbgn = MarkBegin < MarkEnd ? MarkBegin : MarkEnd;
const s32 realmend = MarkBegin < MarkEnd ? MarkEnd : MarkBegin;
if (MarkBegin != MarkEnd) s = Text.subString(0, realmbgn);
{ s.append( Text.subString(realmend, Text.size()-realmend) );
// delete marked text Text = s;
const s32 realmbgn = MarkBegin < MarkEnd ? MarkBegin : MarkEnd;
const s32 realmend = MarkBegin < MarkEnd ? MarkEnd : MarkBegin;
s = Text.subString(0, realmbgn); CursorPos = realmbgn;
s.append( Text.subString(realmend, Text.size()-realmend) ); }
Text = s; else
{
// delete text behind cursor
if (CursorPos>0)
s = Text.subString(0, CursorPos-1);
else
s = L"";
s.append( Text.subString(CursorPos, Text.size()-CursorPos) );
Text = s;
--CursorPos;
}
CursorPos = realmbgn; if (CursorPos < 0)
} CursorPos = 0;
else BlinkStartTime = os::Timer::getTime();
{ newMarkBegin = 0;
// delete text before cursor newMarkEnd = 0;
s = Text.subString(0, CursorPos); textChanged = true;
s.append( Text.subString(CursorPos+1, Text.size()-CursorPos-1) );
Text = s;
} }
break;
if (CursorPos > (s32)Text.size()) case KEY_ESCAPE:
CursorPos = (s32)Text.size(); case KEY_TAB:
case KEY_SHIFT:
case KEY_F1:
case KEY_F2:
case KEY_F3:
case KEY_F4:
case KEY_F5:
case KEY_F6:
case KEY_F7:
case KEY_F8:
case KEY_F9:
case KEY_F10:
case KEY_F11:
case KEY_F12:
case KEY_F13:
case KEY_F14:
case KEY_F15:
case KEY_F16:
case KEY_F17:
case KEY_F18:
case KEY_F19:
case KEY_F20:
case KEY_F21:
case KEY_F22:
case KEY_F23:
case KEY_F24:
// ignore these keys
return false;
BlinkStartTime = os::Timer::getTime(); default:
newMarkBegin = 0; inputChar(event.KeyInput.Char);
newMarkEnd = 0; return true;
textChanged = true;
} }
break;
case KEY_ESCAPE:
case KEY_TAB:
case KEY_SHIFT:
case KEY_F1:
case KEY_F2:
case KEY_F3:
case KEY_F4:
case KEY_F5:
case KEY_F6:
case KEY_F7:
case KEY_F8:
case KEY_F9:
case KEY_F10:
case KEY_F11:
case KEY_F12:
case KEY_F13:
case KEY_F14:
case KEY_F15:
case KEY_F16:
case KEY_F17:
case KEY_F18:
case KEY_F19:
case KEY_F20:
case KEY_F21:
case KEY_F22:
case KEY_F23:
case KEY_F24:
// ignore these keys
return false;
default:
inputChar(event.KeyInput.Char);
return true;
} }
// Set new text markers // Set new text markers
......
...@@ -698,7 +698,7 @@ bool CIrrDeviceLinux::createWindow() ...@@ -698,7 +698,7 @@ bool CIrrDeviceLinux::createWindow()
// create new Window // create new Window
// Remove window manager decoration in fullscreen // Remove window manager decoration in fullscreen
WndAttributes.override_redirect = !netWM && CreationParams.Fullscreen; WndAttributes.override_redirect = !netWM && CreationParams.Fullscreen;
XWindow = XCreateWindow(XDisplay, XWindow = XCreateWindow(XDisplay,
RootWindow(XDisplay, VisualInfo->screen), RootWindow(XDisplay, VisualInfo->screen),
x, y, Width, Height, 0, VisualInfo->depth, x, y, Width, Height, 0, VisualInfo->depth,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment