fixes
This commit is contained in:
@@ -39,7 +39,7 @@
|
|||||||
{
|
{
|
||||||
"Name": "Console",
|
"Name": "Console",
|
||||||
"Mode": 1,
|
"Mode": 1,
|
||||||
"Key": 192,
|
"Key": 220,
|
||||||
"MouseButton": 0,
|
"MouseButton": 0,
|
||||||
"GamepadButton": 0,
|
"GamepadButton": 0,
|
||||||
"Gamepad": 0
|
"Gamepad": 0
|
||||||
@@ -47,7 +47,15 @@
|
|||||||
{
|
{
|
||||||
"Name": "Console",
|
"Name": "Console",
|
||||||
"Mode": 1,
|
"Mode": 1,
|
||||||
"Key": 220,
|
"Key": 223,
|
||||||
|
"MouseButton": 0,
|
||||||
|
"GamepadButton": 0,
|
||||||
|
"Gamepad": 0
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Name": "Console",
|
||||||
|
"Mode": 1,
|
||||||
|
"Key": 192,
|
||||||
"MouseButton": 0,
|
"MouseButton": 0,
|
||||||
"GamepadButton": 0,
|
"GamepadButton": 0,
|
||||||
"Gamepad": 0
|
"Gamepad": 0
|
||||||
|
|||||||
@@ -75,6 +75,7 @@ namespace Cabrito
|
|||||||
{
|
{
|
||||||
public int lineIndex;
|
public int lineIndex;
|
||||||
public int lineOffset;
|
public int lineOffset;
|
||||||
|
public int lineLength;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void CalculateVisibleLines(IReadOnlyCollection<string> lines, out int firstVisibleLine, out int lastVisibleLine, out LineInfo[] wrappedLines)
|
private void CalculateVisibleLines(IReadOnlyCollection<string> lines, out int firstVisibleLine, out int lastVisibleLine, out LineInfo[] wrappedLines)
|
||||||
@@ -92,19 +93,23 @@ namespace Cabrito
|
|||||||
int lineMaxLines = (int)(Height / (font.Height / Platform.DpiScale)); // number of fully visible lines
|
int lineMaxLines = (int)(Height / (font.Height / Platform.DpiScale)); // number of fully visible lines
|
||||||
int numLines = 0;
|
int numLines = 0;
|
||||||
int lineIndex = lines.Count - 1;
|
int lineIndex = lines.Count - 1;
|
||||||
List<LineInfo> lineInfos = new List<LineInfo>(lineMaxLines);
|
List<LineInfo> lineInfos = new List<LineInfo>(lineMaxLines+1);
|
||||||
foreach (string line in lines.Reverse())
|
foreach (string line in lines.Reverse())
|
||||||
{
|
{
|
||||||
int numChars = 0;
|
int numChars = 0;
|
||||||
|
int startIndex = lineInfos.Count;
|
||||||
while (numChars < line.Length)
|
while (numChars < line.Length)
|
||||||
{
|
{
|
||||||
LineInfo li = new LineInfo();
|
LineInfo li = new LineInfo();
|
||||||
li.lineIndex = lineIndex;
|
li.lineIndex = lineIndex;
|
||||||
li.lineOffset = numChars;
|
li.lineOffset = numChars;
|
||||||
|
li.lineLength = Math.Min(line.Length - numChars, lineMaxChars);
|
||||||
lineInfos.Add(li);
|
lineInfos.Add(li);
|
||||||
|
|
||||||
numChars += lineMaxChars;
|
numChars += lineMaxChars;
|
||||||
}
|
}
|
||||||
|
if (lineInfos.Count - startIndex > 1)
|
||||||
|
lineInfos.Reverse(startIndex, lineInfos.Count - startIndex);
|
||||||
numLines++;
|
numLines++;
|
||||||
lineIndex--;
|
lineIndex--;
|
||||||
|
|
||||||
@@ -200,6 +205,7 @@ namespace Cabrito
|
|||||||
float lineHeight = font.Height / Platform.DpiScale;
|
float lineHeight = font.Height / Platform.DpiScale;
|
||||||
float accumHeight = wrappedLines.Length * lineHeight;
|
float accumHeight = wrappedLines.Length * lineHeight;
|
||||||
|
|
||||||
|
// selection in line-space, wrapping ignored
|
||||||
int selectionLeftLine = selectionStartLine;
|
int selectionLeftLine = selectionStartLine;
|
||||||
int selectionLeftChar = selectionStartChar;
|
int selectionLeftChar = selectionStartChar;
|
||||||
int selectionRightLine = selectionEndLine;
|
int selectionRightLine = selectionEndLine;
|
||||||
@@ -223,29 +229,35 @@ namespace Cabrito
|
|||||||
|
|
||||||
TextLayoutOptions layout = _layout;
|
TextLayoutOptions layout = _layout;
|
||||||
layout.Bounds.Y -= accumHeight - Height;
|
layout.Bounds.Y -= accumHeight - Height;
|
||||||
for (int i = startLine; i < lastLine; i++)
|
//for (int i = startLine; i < lastLine; i++)
|
||||||
|
foreach (LineInfo li in wrappedLines)
|
||||||
{
|
{
|
||||||
string line = lines.ElementAt(i);
|
var lineIndex = li.lineIndex;
|
||||||
|
string fullLine = lines.ElementAt(lineIndex);
|
||||||
|
string line = fullLine.Substring(li.lineOffset, li.lineLength);
|
||||||
|
|
||||||
|
int leftChar = selectionLeftChar;
|
||||||
|
int rightChar = selectionRightChar;
|
||||||
|
|
||||||
Rectangle selectionRect = new Rectangle(layout.Bounds.X, layout.Bounds.Y, 0f, 0f);
|
Rectangle selectionRect = new Rectangle(layout.Bounds.X, layout.Bounds.Y, 0f, 0f);
|
||||||
|
|
||||||
// apply selection
|
// apply selection
|
||||||
if (i >= selectionLeftLine && i <= selectionRightLine)
|
if (lineIndex >= selectionLeftLine && lineIndex <= selectionRightLine)
|
||||||
{
|
{
|
||||||
if (i > selectionLeftLine && i < selectionRightLine)
|
if (lineIndex > selectionLeftLine && lineIndex < selectionRightLine)
|
||||||
{
|
{
|
||||||
// whole line is selected
|
// whole line is selected
|
||||||
Vector2 lineSize = font.MeasureText(line);
|
Vector2 lineSize = font.MeasureText(line);
|
||||||
selectionRect.Width = lineSize.X;
|
selectionRect.Width = lineSize.X;
|
||||||
selectionRect.Height = lineSize.Y;
|
selectionRect.Height = lineSize.Y;
|
||||||
}
|
}
|
||||||
else if (i == selectionLeftLine)
|
else if (lineIndex == selectionLeftLine)
|
||||||
{
|
{
|
||||||
if (i < selectionRightLine)
|
if (lineIndex < selectionRightLine)
|
||||||
{
|
{
|
||||||
// right side of the line is selected
|
// right side of the line is selected
|
||||||
Vector2 leftSize = font.MeasureText(line.Substring(0, selectionLeftChar));
|
Vector2 leftSize = font.MeasureText(fullLine.Substring(0, leftChar));
|
||||||
Vector2 rightSize = font.MeasureText(line.Substring(selectionLeftChar));
|
Vector2 rightSize = font.MeasureText(fullLine.Substring(leftChar));
|
||||||
selectionRect.X += leftSize.X;
|
selectionRect.X += leftSize.X;
|
||||||
selectionRect.Width = rightSize.X;
|
selectionRect.Width = rightSize.X;
|
||||||
selectionRect.Height = rightSize.Y;
|
selectionRect.Height = rightSize.Y;
|
||||||
@@ -253,25 +265,25 @@ namespace Cabrito
|
|||||||
//int diff = line.Length - selectionLeftChar;
|
//int diff = line.Length - selectionLeftChar;
|
||||||
//line = line.Substring(0, selectionLeftChar) + (diff > 0 ? new string('X', diff) : "");
|
//line = line.Substring(0, selectionLeftChar) + (diff > 0 ? new string('X', diff) : "");
|
||||||
}
|
}
|
||||||
else if (i == selectionRightLine)
|
else if (lineIndex == selectionRightLine && leftChar != rightChar)
|
||||||
{
|
{
|
||||||
// selecting middle of the one line
|
// selecting middle of the one line
|
||||||
Vector2 lineSize = font.MeasureText(line);
|
Vector2 lineSize = font.MeasureText(fullLine);
|
||||||
Vector2 leftSize = font.MeasureText(line.Substring(0, selectionLeftChar));
|
Vector2 leftSize = font.MeasureText(fullLine.Substring(0, leftChar));
|
||||||
Vector2 rightSize = font.MeasureText(line.Substring(selectionRightChar));
|
Vector2 midSize = font.MeasureText(fullLine.Substring(leftChar, rightChar-leftChar));
|
||||||
|
|
||||||
selectionRect.X += leftSize.X;
|
selectionRect.X += leftSize.X;
|
||||||
selectionRect.Width = lineSize.X - (leftSize.X + rightSize.Y);
|
selectionRect.Width = midSize.X;
|
||||||
selectionRect.Height = lineSize.Y;
|
selectionRect.Height = lineSize.Y;
|
||||||
|
|
||||||
//int diff = selectionRightChar - selectionLeftChar;
|
//int diff = selectionRightChar - selectionLeftChar;
|
||||||
//line = line.Substring(0, selectionLeftChar) + (diff > 0 ? new string('X', diff) : "") + line.Substring(selectionRightChar);
|
//line = line.Substring(0, selectionLeftChar) + (diff > 0 ? new string('X', diff) : "") + line.Substring(selectionRightChar);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (i == selectionRightLine)
|
else if (lineIndex == selectionRightLine)
|
||||||
{
|
{
|
||||||
// left side of the line is selected
|
// left side of the line is selected
|
||||||
Vector2 leftSize = font.MeasureText(line.Substring(0, selectionRightChar));
|
Vector2 leftSize = font.MeasureText(fullLine.Substring(0, rightChar));
|
||||||
selectionRect.Width = leftSize.X;
|
selectionRect.Width = leftSize.X;
|
||||||
selectionRect.Height = leftSize.Y;
|
selectionRect.Height = leftSize.Y;
|
||||||
|
|
||||||
@@ -290,9 +302,10 @@ namespace Cabrito
|
|||||||
{
|
{
|
||||||
TextLayoutOptions layout = _layout;
|
TextLayoutOptions layout = _layout;
|
||||||
layout.Bounds.Y -= accumHeight - Height;
|
layout.Bounds.Y -= accumHeight - Height;
|
||||||
for (int i = startLine; i < lastLine; i++)
|
foreach (LineInfo li in wrappedLines)
|
||||||
{
|
{
|
||||||
string line = lines.ElementAt(i);
|
var lineIndex = li.lineIndex;
|
||||||
|
string line = lines.ElementAt(lineIndex).Substring(li.lineOffset, li.lineLength);
|
||||||
Render2D.DrawText(font, line, TextColor, ref layout);
|
Render2D.DrawText(font, line, TextColor, ref layout);
|
||||||
layout.Bounds.Y += lineHeight;
|
layout.Bounds.Y += lineHeight;
|
||||||
}
|
}
|
||||||
@@ -369,7 +382,7 @@ namespace Cabrito
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
hitLine = wrappedLines[hitWrappedLine].lineIndex;
|
hitLine = wrappedLines[hitWrappedLine].lineIndex;
|
||||||
string line = lines.ElementAt(hitLine);
|
string line = lines.ElementAt(hitLine).Substring(wrappedLines[hitWrappedLine].lineOffset, wrappedLines[hitWrappedLine].lineLength);
|
||||||
|
|
||||||
layout.Bounds.Y = top + ((hitWrappedLine) * lineHeight);
|
layout.Bounds.Y = top + ((hitWrappedLine) * lineHeight);
|
||||||
layout.Bounds.Height = top + 9999;//(visibleHeight / Platform.DpiScale);
|
layout.Bounds.Height = top + 9999;//(visibleHeight / Platform.DpiScale);
|
||||||
@@ -379,8 +392,9 @@ namespace Cabrito
|
|||||||
}*/
|
}*/
|
||||||
|
|
||||||
hitChar = font.HitTestText(line, location, ref layout);
|
hitChar = font.HitTestText(line, location, ref layout);
|
||||||
|
hitChar += wrappedLines[hitWrappedLine].lineOffset;
|
||||||
|
|
||||||
FlaxEngine.Debug.Log(string.Format("hit line {0}/{1}, max lines {2}", hitWrappedLine, wrappedLines.Length, lineMaxLines));
|
//FlaxEngine.Debug.Log(string.Format("hit line {0}/{1}, char {2}", hitWrappedLine, wrappedLines.Length, hitChar));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -389,6 +403,20 @@ namespace Cabrito
|
|||||||
return HitTestText(location + _viewOffset);
|
return HitTestText(location + _viewOffset);
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
|
public override bool OnKeyDown(KeyboardKeys key)
|
||||||
|
{
|
||||||
|
bool shiftDown = Root.GetKey(KeyboardKeys.Shift);
|
||||||
|
bool ctrlDown = Root.GetKey(KeyboardKeys.Control);
|
||||||
|
|
||||||
|
if ((shiftDown && key == KeyboardKeys.Delete) || (ctrlDown && key == KeyboardKeys.Insert) || (ctrlDown && key == KeyboardKeys.C) || (ctrlDown && key == KeyboardKeys.X))
|
||||||
|
{
|
||||||
|
Copy();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
//else if (ctrlDown && key == KeyboardKeys.A)
|
||||||
|
// SelectAll();
|
||||||
|
return base.OnKeyDown(key);
|
||||||
|
}
|
||||||
|
|
||||||
public override bool OnMouseDown(Vector2 location, MouseButton button)
|
public override bool OnMouseDown(Vector2 location, MouseButton button)
|
||||||
{
|
{
|
||||||
@@ -414,6 +442,7 @@ namespace Cabrito
|
|||||||
selectionStartChar = hitChar;
|
selectionStartChar = hitChar;
|
||||||
selectionEndLine = hitLine;
|
selectionEndLine = hitLine;
|
||||||
selectionEndChar = hitChar;
|
selectionEndChar = hitChar;
|
||||||
|
FlaxEngine.Debug.Log(string.Format("start line {0} char {1}", hitLine, hitChar));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
throw new Exception("no???");
|
throw new Exception("no???");
|
||||||
@@ -446,126 +475,96 @@ namespace Cabrito
|
|||||||
{
|
{
|
||||||
selectionEndLine = hitLine;
|
selectionEndLine = hitLine;
|
||||||
selectionEndChar = hitChar;
|
selectionEndChar = hitChar;
|
||||||
|
FlaxEngine.Debug.Log(string.Format("end line {0} char {1}", hitLine, hitChar));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public override bool OnMouseUp(Vector2 location, MouseButton button)
|
public override bool OnMouseUp(Vector2 location, MouseButton button)
|
||||||
{
|
{
|
||||||
if (button == MouseButton.Left)
|
if (button == MouseButton.Left)
|
||||||
{
|
{
|
||||||
OnSelectingEnd();
|
OnSelectingEnd();
|
||||||
|
Focus(inputBox);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
#if false
|
protected void Copy()
|
||||||
public class ConsoleContentTextBox_Old : ConsoleTextBoxBase
|
|
||||||
{
|
|
||||||
[HideInEditor]
|
|
||||||
public ConsoleInputTextBox inputBox;
|
|
||||||
|
|
||||||
private string _textCache;
|
|
||||||
private long _textCacheLines;
|
|
||||||
public override string Text
|
|
||||||
{
|
{
|
||||||
get
|
if (!selectionActive)
|
||||||
|
return;
|
||||||
|
|
||||||
|
// selection in line-space, wrapping ignored
|
||||||
|
int selectionLeftLine = selectionStartLine;
|
||||||
|
int selectionLeftChar = selectionStartChar;
|
||||||
|
int selectionRightLine = selectionEndLine;
|
||||||
|
int selectionRightChar = selectionEndChar;
|
||||||
|
|
||||||
|
if (selectionLeftLine > selectionRightLine || (selectionLeftLine == selectionRightLine && selectionLeftChar > selectionRightChar))
|
||||||
{
|
{
|
||||||
var lines = Console.GetLines();
|
selectionLeftLine = selectionEndLine;
|
||||||
if (_textCache == null || _textCacheLines != lines.Count)
|
selectionLeftChar = selectionEndChar;
|
||||||
|
selectionRightLine = selectionStartLine;
|
||||||
|
selectionRightChar = selectionStartChar;
|
||||||
|
}
|
||||||
|
|
||||||
|
var lines = Console.GetLines();
|
||||||
|
CalculateVisibleLines(lines, out int startLine, out int lastLine, out LineInfo[] wrappedLines);
|
||||||
|
|
||||||
|
StringBuilder selectedText = new StringBuilder();
|
||||||
|
int lastLineIndex = -1;
|
||||||
|
|
||||||
|
foreach (LineInfo li in wrappedLines)
|
||||||
|
{
|
||||||
|
var lineIndex = li.lineIndex;
|
||||||
|
if (lineIndex < selectionLeftLine || lineIndex > selectionRightLine)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (lastLineIndex != lineIndex && lastLineIndex != -1)
|
||||||
|
selectedText.AppendLine();
|
||||||
|
lastLineIndex = lineIndex;
|
||||||
|
|
||||||
|
string fullLine = lines.ElementAt(lineIndex);
|
||||||
|
string line = fullLine.Substring(li.lineOffset, li.lineLength);
|
||||||
|
|
||||||
|
int leftChar = selectionLeftChar;
|
||||||
|
int rightChar = selectionRightChar;
|
||||||
|
|
||||||
|
if (lineIndex >= selectionLeftLine && lineIndex <= selectionRightLine)
|
||||||
{
|
{
|
||||||
//Deselect();
|
if (lineIndex > selectionLeftLine && lineIndex < selectionRightLine)
|
||||||
//ResetViewOffset();
|
{
|
||||||
|
// whole line is selected
|
||||||
_textCache = string.Join("\n", lines);
|
selectedText.Append(line);
|
||||||
_textCacheLines = lines.Count;
|
}
|
||||||
|
else if (lineIndex == selectionLeftLine)
|
||||||
OnTextChanged();
|
{
|
||||||
|
if (lineIndex < selectionRightLine)
|
||||||
|
{
|
||||||
|
// right side of the line is selected
|
||||||
|
selectedText.Append(fullLine.Substring(leftChar));
|
||||||
|
}
|
||||||
|
else if (lineIndex == selectionRightLine && leftChar != rightChar)
|
||||||
|
{
|
||||||
|
// selecting middle of the one line
|
||||||
|
selectedText.Append(fullLine.Substring(leftChar, rightChar - leftChar));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (lineIndex == selectionRightLine)
|
||||||
|
{
|
||||||
|
// left side of the line is selected
|
||||||
|
selectedText.Append(fullLine.Substring(0, rightChar));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return _textCache;
|
|
||||||
}
|
}
|
||||||
set => _textCache = value;
|
|
||||||
|
if (selectedText.Length > 0)
|
||||||
|
Clipboard.Text = selectedText.ToString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public ConsoleContentTextBox_Old(ConsoleInputTextBox inputBox, float x, float y, float width, float height) : base(x, y, width, height)
|
|
||||||
{
|
|
||||||
this.inputBox = inputBox;
|
|
||||||
Height = height;
|
|
||||||
|
|
||||||
IsMultiline = true;
|
|
||||||
IsReadOnly = true;
|
|
||||||
CaretColor = new Color(0f, 0f, 0f, 0f);
|
|
||||||
AutoFocus = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void OnGotFocus()
|
|
||||||
{
|
|
||||||
base.OnGotFocus();
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void OnLostFocus()
|
|
||||||
{
|
|
||||||
ClearSelection();
|
|
||||||
base.OnLostFocus();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override void OnTextChanged()
|
|
||||||
{
|
|
||||||
base.OnTextChanged();
|
|
||||||
ScrollToEnd();
|
|
||||||
}
|
|
||||||
|
|
||||||
public override bool OnKeyDown(KeyboardKeys key)
|
|
||||||
{
|
|
||||||
bool ret;
|
|
||||||
switch (key)
|
|
||||||
{
|
|
||||||
case KeyboardKeys.Escape:
|
|
||||||
ret = true; // disable text restoration
|
|
||||||
break;
|
|
||||||
case KeyboardKeys.Home:
|
|
||||||
case KeyboardKeys.End:
|
|
||||||
// TODO: scroll top and scroll bottom
|
|
||||||
ret = true;
|
|
||||||
break;
|
|
||||||
case KeyboardKeys.ArrowUp:
|
|
||||||
case KeyboardKeys.ArrowDown:
|
|
||||||
case KeyboardKeys.ArrowLeft:
|
|
||||||
case KeyboardKeys.ArrowRight:
|
|
||||||
ret = true; // input box has priority
|
|
||||||
break;
|
|
||||||
case KeyboardKeys.PageUp:
|
|
||||||
case KeyboardKeys.PageDown:
|
|
||||||
return true;
|
|
||||||
default:
|
|
||||||
ret = base.OnKeyDown(key);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (inputBox == null)
|
|
||||||
return ret;
|
|
||||||
return inputBox.OnKeyDown(key);
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void OnKeyUp(KeyboardKeys key)
|
|
||||||
{
|
|
||||||
base.OnKeyUp(key);
|
|
||||||
if (inputBox != null)
|
|
||||||
inputBox.OnKeyUp(key);
|
|
||||||
}
|
|
||||||
|
|
||||||
public override bool OnCharInput(char c)
|
|
||||||
{
|
|
||||||
if (inputBox == null)
|
|
||||||
return base.OnCharInput(c);
|
|
||||||
|
|
||||||
Focus(inputBox);
|
|
||||||
return inputBox.OnCharInput(c);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,26 +24,52 @@ namespace Cabrito
|
|||||||
IsMultiline = true; // Not really but behaves better than single-line box
|
IsMultiline = true; // Not really but behaves better than single-line box
|
||||||
}
|
}
|
||||||
|
|
||||||
public override bool OnCharInput(char c)
|
private bool IsConsoleKeyPressed(KeyboardKeys key = KeyboardKeys.None)
|
||||||
{
|
{
|
||||||
// Ignore any characters generated by the key which opens the console
|
// Ignore any characters generated by the key which opens the console
|
||||||
var consoleKeyMappings = Input.ActionMappings.Where(x => x.Name == "Console" && x.Key != KeyboardKeys.None);
|
IEnumerable<ActionConfig> consoleKeyMappings;
|
||||||
|
if (key == KeyboardKeys.None)
|
||||||
|
consoleKeyMappings = Input.ActionMappings.Where(x => x.Name == "Console" && x.Key != KeyboardKeys.None);
|
||||||
|
else
|
||||||
|
consoleKeyMappings = Input.ActionMappings.Where(x => x.Name == "Console" && x.Key == key);
|
||||||
foreach (var mapping in consoleKeyMappings)
|
foreach (var mapping in consoleKeyMappings)
|
||||||
{
|
{
|
||||||
|
if (Input.InputText.Length > 0)
|
||||||
|
{
|
||||||
|
if ((mapping.Key == KeyboardKeys.Backslash || mapping.Key == KeyboardKeys.BackQuote) &&
|
||||||
|
(Input.InputText.ToLowerInvariant().Contains('ö') ||
|
||||||
|
Input.InputText.ToLowerInvariant().Contains('æ') ||
|
||||||
|
Input.InputText.ToLowerInvariant().Contains('ø')))
|
||||||
|
{
|
||||||
|
continue; // Scandinavian keyboards layouts
|
||||||
|
}
|
||||||
|
else if (mapping.Key == KeyboardKeys.BackQuote && Input.InputText.ToLowerInvariant().Contains('\''))
|
||||||
|
continue;
|
||||||
|
else if (mapping.Key == KeyboardKeys.Backslash && (Input.InputText.ToLowerInvariant().Contains('\\') || Input.InputText.ToLowerInvariant().Contains('|')))
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if (Input.GetKey(mapping.Key))
|
if (Input.GetKey(mapping.Key))
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override bool OnCharInput(char c)
|
||||||
|
{
|
||||||
|
if (IsConsoleKeyPressed())
|
||||||
|
return true;
|
||||||
|
|
||||||
return base.OnCharInput(c);
|
return base.OnCharInput(c);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override bool OnKeyDown(KeyboardKeys key)
|
public override bool OnKeyDown(KeyboardKeys key)
|
||||||
{
|
{
|
||||||
var consoleKeyMappings = Input.ActionMappings.Where(x => x.Name == "Console" && x.Key != KeyboardKeys.None);
|
|
||||||
bool shiftDown = Root.GetKey(KeyboardKeys.Shift);
|
bool shiftDown = Root.GetKey(KeyboardKeys.Shift);
|
||||||
bool ctrlDown = Root.GetKey(KeyboardKeys.Control);
|
bool ctrlDown = Root.GetKey(KeyboardKeys.Control);
|
||||||
|
|
||||||
if (consoleKeyMappings.Any(x => x.Key == key))
|
if (IsConsoleKeyPressed(key))
|
||||||
{
|
{
|
||||||
Clear();
|
Clear();
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -58,6 +58,8 @@ namespace Cabrito
|
|||||||
{
|
{
|
||||||
Console.Init();
|
Console.Init();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
consoleInputEvent = new InputEvent("Console");
|
consoleInputEvent = new InputEvent("Console");
|
||||||
consoleInputEvent.Triggered += OnConsoleInputEvent;
|
consoleInputEvent.Triggered += OnConsoleInputEvent;
|
||||||
|
|
||||||
@@ -160,7 +162,7 @@ namespace Cabrito
|
|||||||
Console.RegisterConsoleScript(this);
|
Console.RegisterConsoleScript(this);
|
||||||
RefreshLayout();
|
RefreshLayout();
|
||||||
|
|
||||||
#if false
|
#if true
|
||||||
//for (int i = 0; i < 10; i++)
|
//for (int i = 0; i < 10; i++)
|
||||||
{
|
{
|
||||||
string[] teststr = {
|
string[] teststr = {
|
||||||
@@ -225,6 +227,15 @@ namespace Cabrito
|
|||||||
{
|
{
|
||||||
|
|
||||||
};*/
|
};*/
|
||||||
|
|
||||||
|
/*Console.Print("normal line");
|
||||||
|
Console.Print(
|
||||||
|
"a very very very long long long line in repeat a very very very long long long line in repeat 1 a very very ver"
|
||||||
|
+ "y long long long line in repeat a very very very 2 long long long line in repeat a very very very 3 long long"
|
||||||
|
+ " long line in repeat a very very very long long long 4 line in repeat");
|
||||||
|
Console.Print("another normal line");*/
|
||||||
|
|
||||||
|
|
||||||
Debug.Logger.LogHandler.SendLog += OnSendLog;
|
Debug.Logger.LogHandler.SendLog += OnSendLog;
|
||||||
Debug.Logger.LogHandler.SendExceptionLog += OnSendExceptionLog;
|
Debug.Logger.LogHandler.SendExceptionLog += OnSendExceptionLog;
|
||||||
}
|
}
|
||||||
@@ -270,6 +281,29 @@ namespace Cabrito
|
|||||||
|
|
||||||
private void OnConsoleInputEvent()
|
private void OnConsoleInputEvent()
|
||||||
{
|
{
|
||||||
|
string currentInput = Input.InputText;
|
||||||
|
|
||||||
|
if (Input.InputText.Length > 0)
|
||||||
|
{
|
||||||
|
// Really need rawinput support with separate ActionConfig.RawKey values, bound to physical keys/scancode instead of virtual ones
|
||||||
|
var consoleKeys = Input.ActionMappings.Where(x => x.Name == "Console" && x.Key != KeyboardKeys.None);
|
||||||
|
bool backslash = consoleKeys.Any(x => x.Key == KeyboardKeys.Backslash);
|
||||||
|
bool backquote = consoleKeys.Any(x => x.Key == KeyboardKeys.BackQuote);
|
||||||
|
|
||||||
|
// Workaround to only trigger Console key from key bound to left side of 1 (tilde/backquote/backslash key)
|
||||||
|
if ((backslash || backquote) &&
|
||||||
|
(Input.InputText.ToLowerInvariant().Contains('ö') ||
|
||||||
|
Input.InputText.ToLowerInvariant().Contains('æ') ||
|
||||||
|
Input.InputText.ToLowerInvariant().Contains('ø'))) // Scandinavian keyboard layouts
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else if (backquote && Input.InputText.ToLowerInvariant().Contains('\'')) // UK keyboard layouts
|
||||||
|
return;
|
||||||
|
else if (backslash && (Input.InputText.ToLowerInvariant().Contains('\\') || Input.InputText.ToLowerInvariant().Contains('|'))) // US/International keyboard layouts
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (!consoleInputBox.IsFocused)
|
if (!consoleInputBox.IsFocused)
|
||||||
Console.Open();
|
Console.Open();
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -82,7 +82,7 @@ namespace Cabrito
|
|||||||
_layout = TextLayoutOptions.Default;
|
_layout = TextLayoutOptions.Default;
|
||||||
_layout.VerticalAlignment = IsMultiline ? TextAlignment.Near : TextAlignment.Center;
|
_layout.VerticalAlignment = IsMultiline ? TextAlignment.Near : TextAlignment.Center;
|
||||||
_layout.TextWrapping = TextWrapping.NoWrap;
|
_layout.TextWrapping = TextWrapping.NoWrap;
|
||||||
_layout.Bounds = new Rectangle(DefaultMargin, 1, Width - 2 * DefaultMargin, Height - 2);
|
_layout.Bounds = new Rectangle(0, 0, Width, Height);//new Rectangle(DefaultMargin, 1, Width - 2 * DefaultMargin, Height - 2);
|
||||||
|
|
||||||
var style = Style.Current;
|
var style = Style.Current;
|
||||||
Font = new FontReference(style.FontMedium);
|
Font = new FontReference(style.FontMedium);
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
|
using FlaxEditor.Content.Settings;
|
||||||
using FlaxEngine;
|
using FlaxEngine;
|
||||||
using FlaxEngine.GUI;
|
using FlaxEngine.GUI;
|
||||||
|
|
||||||
@@ -26,6 +27,8 @@ namespace Cabrito
|
|||||||
|
|
||||||
RenderTask t;
|
RenderTask t;
|
||||||
|
|
||||||
|
TimeSettings timeSettings;
|
||||||
|
|
||||||
public override void OnAwake()
|
public override void OnAwake()
|
||||||
{
|
{
|
||||||
label = (Label)control.Control;
|
label = (Label)control.Control;
|
||||||
@@ -41,6 +44,9 @@ namespace Cabrito
|
|||||||
t = new RenderTask();
|
t = new RenderTask();
|
||||||
t.Render += OnDraw;
|
t.Render += OnDraw;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var settings = FlaxEditor.Content.Settings.GameSettings.Load();
|
||||||
|
timeSettings = settings.Time.CreateInstance<FlaxEditor.Content.Settings.TimeSettings>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void OnDestroy()
|
public override void OnDestroy()
|
||||||
@@ -70,6 +76,28 @@ namespace Cabrito
|
|||||||
label.Text += "\nCon: " + conTime.ToString() + "ms";
|
label.Text += "\nCon: " + conTime.ToString() + "ms";
|
||||||
label.Text += "\n" + currentRenderer;
|
label.Text += "\n" + currentRenderer;
|
||||||
label.Text += "\nGC memory: " + (GC.GetTotalMemory(false)/1000000.0f).ToString() + "MB";
|
label.Text += "\nGC memory: " + (GC.GetTotalMemory(false)/1000000.0f).ToString() + "MB";
|
||||||
|
|
||||||
|
/*if (!Platform.HasFocus)
|
||||||
|
{
|
||||||
|
Time.UpdateFPS = 15;
|
||||||
|
Time.DrawFPS = 15;
|
||||||
|
Time.PhysicsFPS = 15;
|
||||||
|
}
|
||||||
|
#if FLAX_EDITOR
|
||||||
|
else if (!FlaxEditor.Editor.IsPlayMode)
|
||||||
|
{
|
||||||
|
var editorFPS = FlaxEditor.Editor.Instance.Options.Options.General.EditorFPS;
|
||||||
|
Time.UpdateFPS = editorFPS;
|
||||||
|
Time.DrawFPS = editorFPS;
|
||||||
|
Time.PhysicsFPS = timeSettings.PhysicsFPS;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Time.UpdateFPS = timeSettings.UpdateFPS;
|
||||||
|
Time.DrawFPS = timeSettings.DrawFPS;
|
||||||
|
Time.PhysicsFPS = timeSettings.PhysicsFPS;
|
||||||
|
}*/
|
||||||
}
|
}
|
||||||
|
|
||||||
void OnDraw(RenderTask tt, GPUContext context)
|
void OnDraw(RenderTask tt, GPUContext context)
|
||||||
|
|||||||
Reference in New Issue
Block a user