1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108:
| procedure TForm4.synmemo1PaintTransient(Sender: TObject; Canvas: TCanvas; TransientType: TTransientType); var Pix: TPoint; Match: TSynTokenMatches; I: Integer; Pos1, Pos2: TBufferCoord; P1, P2: TPoint; Token: string; Bracket1, Bracket2: Char; Attri: TSynHighlighterAttributes; Rect1, Rect2: TRect; editor:tsynedit;
function CharToPixels(P: TBufferCoord): TPoint; begin Result:=Editor.RowColumnToPixels(Editor.BufferToDisplayPos(P)); end;
begin editor:=tsynedit(sender);
if (not needHighlightBrackets) or (editor.Highlighter = nil) then Exit; Pos1 := editor.CaretXY; editor.GetHighlighterAttriAtRowCol(Pos1, Token, Attri); Pos2 := editor.GetMatchingBracketEx(Pos1); if (Pos1.char > 1) and (Pos2.char = 0) then begin Dec(Pos1.char); editor.GetHighlighterAttriAtRowCol(Pos1, Token, Attri); Pos2 := editor.GetMatchingBracketEx(Pos1); end;
if (PrevPos1.char <> Pos1.char) or (PrevPos1.line <> Pos1.line) or (PrevPos2.char <> Pos2.char) or (PrevPos2.line <> Pos2.line) then begin editor.InvalidateLine(PrevPos1.line); PrevPos1 := Pos1; editor.InvalidateLine(PrevPos2.line); PrevPos2 := Pos2; end;
if ((Pos2.char = 0) and (Pos2.line = 0)) or editor.SelAvail or (Length(Token) <> 1) then begin Pos1 := editor.CaretXY; editor.GetHighlighterAttriAtRowCol(Pos1, Token, Attri); if (acedit.lines.count<=0) or (length(acedit.LineText)<6) or (acedit.CaretY<2) then exit; I := SynEditGetMatchingTokenEx(Editor, Editor.CaretXY, PasTokens, Match); if I = 0 then Exit; Canvas.Brush.Style := bsSolid; if Abs(I) = 2 then Canvas.Brush.Color := clAqua else Canvas.Brush.Color := clYellow; if I <> -1 then begin Pix := CharToPixels(Match.OpenTokenPos); Canvas.Font.Color := Editor.Font.Color; Canvas.Font.Style := Match.TokenAttri.Style; Canvas.TextOut(Pix.X, Pix.Y, Match.OpenToken); end; if I <> 1 then begin Pix := CharToPixels(Match.CloseTokenPos); Canvas.Font.Color := Editor.Font.Color; Canvas.Font.Style := Match.TokenAttri.Style; Canvas.TextOut(Pix.X, Pix.Y, Match.CloseToken); end; exit; end;
Bracket1 := Token[1]; if Bracket1 in BracketSet then begin Bracket2 := GetOppositeBracket(Bracket1); P1 := editor.RowColumnToPixels(editor.BufferToDisplayPos(Pos1)); P2 := editor.RowColumnToPixels(editor.BufferToDisplayPos(Pos2)); with Canvas do begin Font.Assign(editor.Font); Font.Style := Attri.Style; Font.Color := FgColorHighlight; Brush.Color := BgColorHighlight; end; Rect1.Top := P1.Y; Rect1.Left := P1.X; Rect1.Bottom := Rect1.Top + Canvas.TextHeight(Bracket1); Rect1.Right := Rect1.Left + Canvas.TextWidth(Bracket1); Canvas.FillRect(Rect1); Canvas.TextOut(P1.X, P1.Y, Bracket1); Rect2.Top := P2.Y; Rect2.Left := P2.X; Rect2.Bottom := Rect2.Top + Canvas.TextHeight(Bracket2); Rect2.Right := Rect2.Left + Canvas.TextWidth(Bracket2); Canvas.FillRect(Rect2); Canvas.TextOut(P2.X, P2.Y, Bracket2); end; end; |