Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions Game.Client/GarrysMod/LuaPanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1674,9 +1674,7 @@ static int Panel__SetTextHidden(ILuaInterface lua) {

[LuaMethod]
static int Panel__SetPopupStayAtBack(ILuaInterface lua) {
Panel? panel = GetPanelOrError(lua);
if (panel != null && lua.GetBool(2))
Surface.MovePopupToBack(panel);
GetPanelOrError(lua)?.SetPopupStayAtBack(lua.GetBool(2));
return 0;
}

Expand Down
2 changes: 2 additions & 0 deletions Source.Common/GUI/IPanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ public interface IPanel : IExtDisposable
// Used by the drag/drop manager to always draw on top
bool IsTopmostPopup();
void SetTopmostPopup(bool state);
bool IsPopupStayAtBack();
void SetPopupStayAtBack(bool state);
void InvalidateLayout(bool layoutNow = false, bool reloadScheme = false);

int GetAlpha();
Expand Down
2 changes: 1 addition & 1 deletion Source.GUI.Controls/Menu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -853,7 +853,7 @@ public override void OnMouseWheeled(int delta) {
}

public override void OnKillFocus(Panel? newPanel) {
if (newPanel == null || !HasParent(newPanel)) {
if (newPanel == null || !newPanel.HasParent(this)) {
if (!IsKeyboardInputEnabled() && newPanel == null)
return;

Expand Down
3 changes: 3 additions & 0 deletions Source.GUI.Controls/Panel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,7 @@ public void SetScheme(IScheme scheme) {
bool MouseInput;
bool KbInput;
bool TopmostPopup;
bool PopupStayAtBack;
[PanelAnimationVar("alpha", "255")] float Alpha;
IBorder? Border;
IScheme? Scheme;
Expand Down Expand Up @@ -1228,6 +1229,8 @@ public bool IsProportional() {
}

public bool IsTopmostPopup() => TopmostPopup;
public bool IsPopupStayAtBack() => PopupStayAtBack;
public void SetPopupStayAtBack(bool state) => PopupStayAtBack = state;

public bool IsVisible() {
return Visible;
Expand Down
92 changes: 89 additions & 3 deletions Source.GUI.Controls/RichText.cs
Original file line number Diff line number Diff line change
Expand Up @@ -713,9 +713,94 @@ public int PixelToCursorSpace(int cx, int cy) {
return i;
}

//public override void OnKeyCodeTyped(ButtonCode code) // todo
//{
//}
public override void OnKeyCodeTyped(ButtonCode code) {
bool shift = Input.IsKeyDown(ButtonCode.KeyLShift) || Input.IsKeyDown(ButtonCode.KeyRShift);
bool ctrl = Input.IsKeyDown(ButtonCode.KeyLControl) || Input.IsKeyDown(ButtonCode.KeyRControl);
bool alt = Input.IsKeyDown(ButtonCode.KeyLAlt) || Input.IsKeyDown(ButtonCode.KeyRAlt);
bool winkey = Input.IsKeyDown(ButtonCode.KeyLWin) || Input.IsKeyDown(ButtonCode.KeyRWin);
bool fallThrough = false;

if (ctrl || (winkey && IsOSX)) {
switch (code) {
case ButtonCode.KeyA:
CursorPos = 0;
Select[0] = 0;
Select[1] = TextStream.Count;
return;

case ButtonCode.KeyInsert:
case ButtonCode.KeyC:
case ButtonCode.KeyX:
CopySelected();
return;

case ButtonCode.KeyPageUp:
case ButtonCode.KeyHome:
GotoTextStart();
break;

case ButtonCode.KeyPageDown:
case ButtonCode.KeyEnd:
GotoTextEnd();
break;

default:
fallThrough = true;
break;
}
}
else if (alt)
fallThrough = true;
else {
switch (code) {
case ButtonCode.KeyTab:
case ButtonCode.KeyLShift:
case ButtonCode.KeyRShift:
case ButtonCode.KeyEscape:
case ButtonCode.KeyEnter:
fallThrough = true;
break;

case ButtonCode.KeyDelete:
if (shift)
CopySelected();
break;

case ButtonCode.KeyHome:
GotoTextStart();
break;

case ButtonCode.KeyEnd:
GotoTextEnd();
break;

case ButtonCode.KeyPageUp:
if (VertScrollBar.IsVisible()) {
int window = VertScrollBar.GetRangeWindow();
int newval = VertScrollBar.GetValue();
VertScrollBar.SetValue(newval - window - 1);
}
break;

case ButtonCode.KeyPageDown:
if (VertScrollBar.IsVisible()) {
int window = VertScrollBar.GetRangeWindow();
int newval = VertScrollBar.GetValue();
VertScrollBar.SetValue(newval + window + 1);
}
break;

default:
return;
}
}

if (code != ButtonCode.KeyLControl && code != ButtonCode.KeyRControl)
Select[1] = CursorPos;

if (fallThrough)
base.OnKeyCodeTyped(code);
}

public bool GetSelectedRange(out int start, out int end) {
if (Select[0] == -1) {
Expand Down Expand Up @@ -966,6 +1051,7 @@ public virtual void CutSelected() {
RequestFocus();
}

[UiMessage("DoCopySelected")]
public virtual void CopySelected() {
if (GetSelectedRange(out int x0, out int x1)) {
List<char> buf = [];
Expand Down
77 changes: 57 additions & 20 deletions Source.GUI.Controls/TextEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -772,6 +772,13 @@ public override void OnKeyCodeTyped(ButtonCode code) {
GotoWordLeft();
break;

case ButtonCode.KeyBackspace:
if (GetSelectedRange(out _, out _))
DeleteSelected();
else
DeleteWordLeft();
break;

case ButtonCode.KeyEnter:
if (Multiline) {
DeleteSelected();
Expand Down Expand Up @@ -969,16 +976,7 @@ private void GotoWordLeft() {
if (CursorPos < 1)
return;

while (--CursorPos >= 0)
if (!char.IsWhiteSpace(TextStream[CursorPos]))
break;


while (--CursorPos >= 0)
if (char.IsWhiteSpace(TextStream[CursorPos]))
break;

CursorPos++;
CursorPos = FindWordLeft(CursorPos);

ScrollLeft();

Expand All @@ -987,6 +985,54 @@ private void GotoWordLeft() {
Repaint();
}

enum CharClass { Whitespace, Word, Punctuation }

static CharClass GetCharClass(char ch) {
if (char.IsWhiteSpace(ch))
return CharClass.Whitespace;
if (char.IsLetterOrDigit(ch) || ch == '_')
return CharClass.Word;
return CharClass.Punctuation;
}

private int FindWordLeft(int pos) {
while (pos > 0 && GetCharClass(TextStream[pos - 1]) == CharClass.Whitespace)
pos--;

if (pos > 0) {
CharClass charClass = GetCharClass(TextStream[pos - 1]);
while (pos > 0 && GetCharClass(TextStream[pos - 1]) == charClass)
pos--;
}

return pos;
}

private int FindWordRight(int pos) {
int count = TextStream.Count;
if (pos < count) {
CharClass charClass = GetCharClass(TextStream[pos]);
if (charClass != CharClass.Whitespace)
while (pos < count && GetCharClass(TextStream[pos]) == charClass)
pos++;
}

while (pos < count && GetCharClass(TextStream[pos]) == CharClass.Whitespace)
pos++;

return pos;
}

private void DeleteWordLeft() {
int start = FindWordLeft(CursorPos);
if (start == CursorPos)
return;

Select[0] = start;
Select[1] = CursorPos;
DeleteSelected();
}

private void ScrollLeft() {
if (Multiline)
return;
Expand All @@ -1007,16 +1053,7 @@ private void ScrollLeft() {
private void GotoWordRight() {
SelectCheck();

while (++CursorPos < TextStream.Count)
if (char.IsWhiteSpace(TextStream[CursorPos]))
break;

while (++CursorPos < TextStream.Count)
if (!char.IsWhiteSpace(TextStream[CursorPos]))
break;

if (CursorPos > TextStream.Count)
CursorPos = TextStream.Count;
CursorPos = FindWordRight(CursorPos);

ScrollRight();

Expand Down
3 changes: 3 additions & 0 deletions Source.MaterialSystem/Surface/MatSystemSurface.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1071,6 +1071,9 @@ public void MovePopupToBack(IPanel panel) {
}

public void MovePopupToFront(IPanel panel) {
if (panel.IsPopupStayAtBack())
return;

int index = PopupList.IndexOf(panel);
if (index == -1)
return;
Expand Down
Loading