Destructor THKVideoWindow.Destroy; Begin Inherited Destroy; End;
Procedure THKVideoWindow.DrawSelPane(Const CurSel, OldSel: Integer); Begin With Canvas Do Begin Lock; Pen.Width := 1; Pen.Color := FBorderColor; DrawRect(FPaneRect[OldSel]); Pen.Color := FSelColor; DrawRect(FPaneRect[CurSel]); Unlock; End; End;
Function THKVideoWindow.GetSelPane(Const Pos: TPoint; Const PaneRect: TPaneRect): Integer; Var I: Integer; Begin Result := -1; For I := 0 To 48 Do If Windows.PtInRect(PaneRect[I], Pos) Then Begin Result := I; Exit; End; End;
Procedure THKVideoWindow.DblClick; Var R: TRect; Begin If Not FPaneFullScreen Then Begin CacPaneRect(Pane1); FTempPaneStyle := FPaneStyle; FPaneStyle := Pane1; End Else Begin FPaneStyle := FTempPaneStyle; CacPaneRect(FPaneStyle); End; If FLockMouse Then Begin R.TopLeft := Self.ClientToScreen(FPaneRect[FSelected].TopLeft); R.BottomRight := Self.ClientToScreen(FPaneRect[FSelected].BottomRight); Windows.ClipCursor(@R); End; FPaneFullScreen := Not FPaneFullScreen; DrawGrid; DrawSelPane(FSelected, FOldSel); Inherited DblClick; End;
Procedure THKVideoWindow.SetLockMouse(Value: Boolean); Var R: TRect; Begin If Value <> FLockMouse Then Begin If Value Then Begin R.TopLeft := ClientToScreen(FPaneRect[FSelected].TopLeft); R.BottomRight := ClientToScreen(FPaneRect[FSelected].BottomRight); Windows.ClipCursor(@R); End Else If Not Value Then Windows.ClipCursor(Nil); FLockMouse := Value; End; End;
Procedure THKVideoWindow.SetPaneColor(Value: TColor); Begin If Value <> FPaneColor Then Begin Color := Value; FPaneColor := Value; End; End;
Procedure THKVideoWindow.SetPaneStyle(Value: TPaneStyle); Begin If FPaneStyle <> Value Then Begin FPaneStyle := Value; CacPaneRect(FPaneStyle); DrawGrid; DrawSelPane(FSelected, FOldSel); End; End;
Procedure THKVideoWindow.SetVideoWinStyle(Value: TVideoWinStyle); Begin If Value <> FVideoWinStyle Then Begin If Value = Normal Then Begin Left := FOldLeft; Top := FOldTop; Width := FOldWidth; Height := FOldHeight; End Else If Value = FullScreen Then Begin FOldLeft := Left; FOldTop := Top; FOldWidth := Width; FOldHeight := Height; Left := 0; Top := 0; Width := 1024; Height := 768; End; CacPaneRect(FPaneStyle); DrawGrid; DrawSelPane(FSelected, FOldSel); FVideoWinStyle := Value; Parent.Update; End; End;
Procedure THKVideoWindow.CacPaneRect(PaneStyle: TPaneStyle); Procedure SplitRects(Const Width, Height, Cols, Rows: Integer; Var PaneRect: TPaneRect); Var // Row col _PaneRect: Array[0..6, 0..6] Of TRect; //临时PaneRect PaneW, PaneH: Integer; //“平均宽、高” ModW, ModH: Integer; //“剩余像素数W、H” iCol, iRow: Integer; //行列标识 Begin //求得“平均宽、高” PaneW := Width Div Cols; PaneH := Height Div Rows; //求得“剩余像素数W、H” ModW := Width Mod Cols; ModH := Height Mod Rows; //清空_PaneRect Windows.ZeroMemory(@PaneRect, SizeOf(TPaneRect)); Windows.ZeroMemory(@_PaneRect, SizeOf(_PaneRect)); //计算 For iRow := 0 To Rows - 1 Do For iCol := 0 To Cols - 1 Do Begin //如果为第一列,则Left=0,否则为前一列的Rect.Right If iCol = 0 Then _PaneRect[iRow, iCol].Left := 0 Else _PaneRect[iRow, iCol].Left := _PaneRect[iRow, iCol - 1].Right; //如果为第一行,则Top=0,否则为前一列的Rect.Bottom If iRow = 0 Then _PaneRect[iRow, iCol].Top := 0 Else _PaneRect[iRow, iCol].Top := _PaneRect[iRow - 1, iCol].Bottom; //如果当前Row在“剩余像素数Row”内,则分配“剩余像素数Row” If iRow < ModH Then _PaneRect[iRow, iCol].Bottom := _PaneRect[iRow, iCol].Top + PaneH + 1 Else _PaneRect[iRow, iCol].Bottom := _PaneRect[iRow, iCol].Top + PaneH; //如果当前Col在“剩余像素数Col”内,则分配“剩余像素数Col” If iCol < ModW Then _PaneRect[iRow, iCol].Right := _PaneRect[iRow, iCol].Left + PaneW + 1 Else _PaneRect[iRow, iCol].Right := _PaneRect[iRow, iCol].Left + PaneW;
PaneRect[iRow * Cols + iCol] := _PaneRect[iRow, iCol]; End; End; Begin If PaneStyle = Pane1 Then Begin Windows.ZeroMemory(@FPaneRect, SizeOf(TPaneRect)); FPaneRect[FSelected] := Rect(0, 0, ClientWidth - 1, ClientHeight - 1); End Else If PaneStyle = Pane4 Then SplitRects(Self.ClientWidth - 1, Self.ClientHeight - 1, 2, 2, FPaneRect) Else If PaneStyle = Pane9 Then SplitRects(Self.ClientWidth - 1, Self.ClientHeight - 1, 3, 3, FPaneRect) Else If PaneStyle = Pane16 Then SplitRects(Self.ClientWidth - 1, Self.ClientHeight - 1, 4, 4, FPaneRect) Else If PaneStyle = Pane25 Then SplitRects(Self.ClientWidth - 1, Self.ClientHeight - 1, 5, 5, FPaneRect) Else If PaneStyle = Pane36 Then SplitRects(Self.ClientWidth - 1, Self.ClientHeight - 1, 6, 6, FPaneRect) Else If PaneStyle = Pane49 Then SplitRects(Self.ClientWidth - 1, Self.ClientHeight - 1, 7, 7, FPaneRect); End;
Procedure THKVideoWindow.DrawRect(Const Rect: TRect); Begin With Canvas, Rect Do Begin MoveTo(Left, Top); LineTo(Right, Top); LineTo(Right, Bottom); LineTo(Left, Bottom); LineTo(Left, Top); End; End;
Procedure THKVideoWindow.DrawGrid; Var I: Integer; Begin With Canvas Do Begin Lock; //清除背景 Brush.Style := bsSolid; Brush.Color := FPaneColor; FillRect(Self.ClientRect); //画线 Pen.Width := 1; Pen.Color := FBorderColor; For I := 0 To 48 Do Begin DrawRect(FPaneRect[I]); If Assigned(FPaintRect) Then FPaintRect(Self, I, FPaneRect[I]); End; Unlock; End; End; End.