捐赠 | 广告 | 注册 | 发布 | 上传 | 关于我们    
  粤ICP备10103342号-1 DELPHI盒子 | 盒子文章 | 盒子问答悬赏 | 最新更新 | 盒子检索 | 下载中心 | 高级搜索    
  精品专区 | 繁體中文 | 奖励公告栏 | 直通车账号登陆 | 关闭GOOGLE广告 | 临时留言    
 
广告
评论:Sky_Coin 视频监控系统 1.00
laihongbo 35654 2008/10/8 12:01:04
补上HKVideoWindow.PAS

Unit HKVideoWindow;

Interface

Uses
  Windows, Classes, Graphics, Controls;

Type
  TVideoWinStyle = (Normal, FullScreen);
  TPaneStyle = (Pane1, Pane4, Pane9, Pane16, Pane25, Pane36, Pane49, Pane64);
  TPaneRect = Array[0..63] Of TRect;
  TPaintRectEvent = Procedure(Sender: TObject; ChannelNum: Integer; lpRect: TRect) Of Object;

  THKVideoWindow = Class(TCustomControl)
  Private
    FPaintRect: TPaintRectEvent;
    FPaneRect: TPaneRect;
    FRectDrawing: Boolean;
    FCanDrawRect: Boolean;
    FLockMouse: Boolean;
    FOnPaint: TNotifyEvent;
    FPaneColor, FBorderColor, FSelColor: TColor;
    FPaneStyle, FTempPaneStyle: TPaneStyle;
    FPaneFullScreen: Boolean;
    FSelected, FOldSel: Integer;
    FVideoWinStyle: TVideoWinStyle;
    FOldLeft, FOldTop, FOldWidth, FOldHeight: Integer;
    FJOPX, FJOPY, FEPX, FEPY: Integer;  //Jumping-off Point X:起始点X/Jumping-off Point Y:起始点Y/End-Point X: 终点X/End-Point Y:终点Y
    Procedure SetSelected(Value: Integer);
    Function GetPaneRect(Index: Integer): TRect;
    Procedure SetLockMouse(Value: Boolean);
    Procedure SetPaneColor(Value: TColor);
    Procedure SetPaneStyle(Value: TPaneStyle);
    Procedure SetVideoWinStyle(Value: TVideoWinStyle);
    Procedure CacPaneRect(PaneStyle: TPaneStyle);
    Procedure DrawRect(Const Rect: TRect);
    Procedure DrawGrid;
    Procedure DrawSelPane(Const CurSel, OldSel: Integer);
    Function GetSelPane(Const Pos: TPoint; Const PaneRect: TPaneRect): Integer;
  Protected
    Procedure Click; Override;
    Procedure DblClick; Override;
    Procedure MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y:
      Integer); Override;
    Procedure MouseMove(Shift: TShiftState; X, Y: Integer); Override;
    Procedure MouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
      Override;
    Procedure Paint; Override;
    Procedure Resize; Override;
  Public
    Constructor Create(AOwner: TComponent); Override;
    Destructor Destroy; Override;
    Property Canvas;
    Property PaneRect[Index: Integer]: TRect Read GetPaneRect;
    Property Selected: Integer Read FSelected Write SetSelected Default 0;
  Published
    Property Handle;
    Property Align;
    Property Height;
    Property Width;
    Property Top;
    Property Left;
    Property PopupMenu;
    Property OnClick;
    Property OnDblClick;
    Property OnMouseDown;
    Property OnMouseMove;
    Property OnMouseUp;
    Property OnMouseWheel;
    Property CanDrawRect: Boolean Read FCanDrawRect Write FCanDrawRect Default False;
    Property LockMouse: Boolean Read FLockMouse Write SetLockMouse Default False;
    Property PaneColor: TColor Read FPaneColor Write SetPaneColor;
    Property PaneStyle: TPaneStyle Read FPaneStyle Write SetPaneStyle Default Pane25;
    Property VideoWinStyle: TVideoWinStyle Read FVideoWinStyle Write SetVideoWinStyle Default Normal;
    Property BorderColor: TColor Read FBorderColor Write FBorderColor;
    Property SelColor: TColor Read FSelColor Write FSelColor;
    Property OnPaint: TNotifyEvent Read FOnPaint Write FOnPaint;
    Property OnPaintRect: TPaintRectEvent Read FPaintRect Write FPaintRect;
  End;

Procedure Register;

Implementation

Procedure Register;
Begin
  RegisterComponents('Standard', [THKVideoWindow]);
End;

Constructor THKVideoWindow.Create(AOwner: TComponent);
Begin
  Inherited Create(AOwner);
  ControlStyle := [csCaptureMouse, csClickEvents, csDoubleClicks, csReflector, csFramed];
  Windows.ZeroMemory(@FPaneRect, SizeOf(TPaneRect));
  FRectDrawing := False;
  FCanDrawRect := False;
  FLockMouse := False;
  FPaneColor := Rgb(10, 10, 10);
  FBorderColor := clGreen;
  FSelColor := clAqua;
  Color := FPaneColor;
  FPaneStyle := Pane25;
  FPaneFullScreen := False;
  FSelected := 0;
  FOldSel := 0;
  FVideoWinStyle := Normal;
  Height := 120 * 2;
  Width := 160 * 2;
  FOldLeft := 0;
  FOldTop := 0;
  FOldWidth := 0;
  FOldHeight := 0;
  FJOPX := 0;
  FJOPY := 0;
  FEPX := 0;
  FEPY := 0;
  If Assigned(Parent) Then CacPaneRect(FPaneStyle);
End;

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.Click;
Var
  Pos: TPoint;
Begin
  Pos := ScreenToClient(Mouse.CursorPos);
  FOldSel := FSelected;
  FSelected := GetSelPane(Pos, FPaneRect);
  DrawSelPane(FSelected, FOldSel);
  Inherited Click;
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.SetSelected(Value: Integer);
Begin
  FOldSel := FSelected;
  FSelected := Value;
  DrawSelPane(FSelected, FOldSel);
End;

Function THKVideoWindow.GetPaneRect(Index: Integer): TRect;
Begin
  If Index <= 48 Then
  Begin
    Result.Left := FPaneRect[Index].Left + 1;
    Result.Top := FPaneRect[Index].Top + 1;
    Result.Right := FPaneRect[Index].Right - 1;
    Result.Bottom := FPaneRect[Index].Bottom - 1;
  End
  Else
    Windows.ZeroMemory(@Result, SizeOf(TRect));
End;

Procedure THKVideoWindow.MouseDown(Button: TMouseButton; Shift: TShiftState; X,
  Y: Integer);
Var
  R: TRect;
Begin
  If FCanDrawRect Then
    If Button = mbRight Then
      If Not FRectDrawing Then
        If Windows.PtInRect(FPaneRect[FSelected], Point(X, Y)) Then
        Begin
          FJOPX := X;
          FJOPY := Y;
          FEPX := X;
          FEPY := Y;
          R.Left := FPaneRect[FSelected].Left + 1;
          R.Top := FPaneRect[FSelected].Top + 1;
          R.Right := FPaneRect[FSelected].Right - 1;
          R.Bottom := FPaneRect[FSelected].Bottom - 1;
          R.TopLeft := ClientToScreen(R.TopLeft);
          R.BottomRight := ClientToScreen(R.BottomRight);
          Windows.ClipCursor(@R);
          Cursor := crCross;
          FRectDrawing := True;
        End;
  Inherited MouseDown(Button, Shift, X, Y);
End;

Procedure THKVideoWindow.MouseMove(Shift: TShiftState; X, Y: Integer);
Var
  RegLineColor: TColor;
  OldRop2: Integer;
Begin
  If FCanDrawRect Then
    If ssRight In Shift Then
      If FRectDrawing Then
        With Canvas Do
        Begin
          Lock;
          RegLineColor := Windows.GetBkColor(Handle) Xor Rgb(127, 127, 127);
          OldRop2 := Windows.GetROP2(Handle);
          Windows.SetROP2(Handle, R2_XORPEN);
          Pen.Width := 1;
          Pen.Color := RegLineColor;
          Pen.Style := psDash;
          MoveTo(FJOPX, FJOPY);
          LineTo(FEPX, FJOPY);
          LineTo(FEPX, FEPY);
          LineTo(FJOPX, FEPY);
          LineTo(FJOPX, FJOPY);
          FEPX := X;
          FEPY := Y;
          MoveTo(FJOPX, FJOPY);
          LineTo(FEPX, FJOPY);
          LineTo(FEPX, FEPY);
          LineTo(FJOPX, FEPY);
          LineTo(FJOPX, FJOPY);
          Windows.SetROP2(Handle, OldRop2);
          Unlock;
        End;
  Inherited MouseMove(Shift, X, Y);
End;

Procedure THKVideoWindow.MouseUp(Button: TMouseButton; Shift: TShiftState; X,
  Y: Integer);
Var
  FilledRect: TRect;
Begin
  If FCanDrawRect Then
    If Button = mbRight Then
      If FRectDrawing Then
      Begin
        Canvas.Lock;
        Canvas.Pen.Style := psSolid;
        Cursor := crDefault;
        If Not FLockMouse Then Windows.ClipCursor(Nil);
        FJOPX := -1;
        FJOPY := -1;
        FEPX := -1;
        FEPY := -1;
        Canvas.Brush.Style := bsSolid;
        Canvas.Brush.Color := FPaneColor;
        FilledRect.Left := FPaneRect[FSelected].Left + 1;
        FilledRect.Top := FPaneRect[FSelected].Top + 1;
        FilledRect.Right := FPaneRect[FSelected].Right - 1;
        FilledRect.Bottom := FPaneRect[FSelected].Bottom - 1;
        Canvas.FillRect(FilledRect);
        Canvas.Unlock;
        FRectDrawing := False;
      End;
  Inherited MouseUp(Button, Shift, X, Y);
End;

Procedure THKVideoWindow.Paint;
Begin
  DrawGrid;
  DrawSelPane(FSelected, FOldSel);
  Inherited Paint;
  If Assigned(FOnPaint) Then FOnPaint(Self);
End;

Procedure THKVideoWindow.Resize;
Begin
  CacPaneRect(FPaneStyle);
  DrawGrid;
  DrawSelPane(FSelected, FOldSel);
  Parent.Update;
  Inherited Resize;
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.
jemsn 35653 2008/10/8 11:54:32
顶,好人一个,就是少了一个HKVideoWindow.PAS文件,按isyou6 说的到http://www.2ccc.com/article.asp?articleid=3735下载了,但打开Sky_Coin.dpr后还是提示缺少控件.
laihongbo 35652 2008/10/8 11:46:24
怎么说HKVideoWindow不全呢,HKVideoWindow控件就一个PAS文件(仅users了Windows, Classes, Graphics, Controls,如何不全),这个版本我改进过的。。

如果说你是用HKVideoWindow里的DEMO是编译不了的。我只是改进控件合适自已用了,DEMO我可没空改。
aq031 35649 2008/10/8 10:49:23
好人!!!!
weiwei123 35639 2008/10/7 17:05:22
非常好,顶了。
控件方面的问题可以自己解决啊!
isyou6 35630 2008/10/7 11:49:23
烦!组件版本不一致,有些属性没有!提供的不全。
isyou6 35629 2008/10/7 11:43:12
THKVideoWindow组件大家到http://www.2ccc.com/article.asp?articleid=3735下载!
isyou6 35628 2008/10/7 11:39:10
提供的THKVideoWindow组件缺少PAS文件哦!
第一页 上一页 下一页 最后页 有 28 条纪录 共2页 21 - 28
 用户名:
 密 码:
自动登陆(30天有效)
 
  DELPHI盒子版权所有 技术支持:深圳市麟瑞科技有限公司 1999-2024 V4.01 粤ICP备10103342号-1 更新RSS列表