void __fastcall TIntMinerField::MouseUpHandler(System::TObject* Sender, Controls::TMouseButton Button, Classes::TShiftState Shift, int X, int Y)
{
  int ACol, ARow;
  SetCaptureControl(NULL);
  MouseToCell(X, Y, ACol, ARow);
  if((ACol == - 1) || (ARow == -1))
    return;
  if(((Shift == (TShiftState() << ssLeft)) && (Button == mbRight)) ||
    ((Shift == (TShiftState() << ssRight)) && (Button == mbLeft))
     || (Button == mbMiddle)) {
    FireImageChanged(imSmile);
    FSurprised = false;
    UnpressAndInvalidate();
    if(CellState[ACol][ARow].CellState == csOpened)
      FireMinerFieldEvent(ACol, ARow, meCheckSurround);
    return;
  };
  if(Button == mbLeft) {
    FireImageChanged(imSmile);
    FSurprised = false;
    if(IsExistsInArray(FPressedCells, ACol, ARow)) {
//      BeginUpdate();
      FireMinerFieldEvent(ACol, ARow, meOpenCell);
//      EndUpdate();
      UnpressAndInvalidate();
    };
    return;
  };
  if(Button == mbRight)
    UnpressAndInvalidate();
}
Esempio n. 2
0
void __fastcall DesignerHook::MouseUp(TControl* Sender,TMouseButton Button, Classes::TShiftState Shift, int X, int Y)
{
    HDC dc;
    if(Dragging_){
        MouseFree();
        SetDragging(false);
        //Dragging_ = false;
    }
    if(Selecting_){
        dc= GetDC(0);
        DrawFocusRect(dc, &OldRect_);
        ReleaseDC(0, dc);
        Selecting_= false;
        SetCaptureControl(NULL);
        if( CheckPtrType<TWinControl*>(Sender) ){
            TPoint  PtTopLeft,PtBottomRight;
            PtTopLeft.x = OldRect_.Left;
            PtTopLeft.y = OldRect_.Top;
            PtTopLeft =  Sender->ScreenToClient(PtTopLeft);
            OldRect_.Top= PtTopLeft.y;
            OldRect_.Left= PtTopLeft.x;

            PtBottomRight.x = OldRect_.right;
            PtBottomRight.y = OldRect_.bottom;
            PtBottomRight =  Sender->ScreenToClient(PtBottomRight);
            OldRect_.bottom= PtBottomRight.y;
            OldRect_.right= PtBottomRight.x;
    
            OldRect_ = PointToRect(PtTopLeft, PtBottomRight);
            AddRectControls(DownCast<TWinControl*,TControl*>(Sender), OldRect_);
            ShowGrabHandle(true);
        }
    }

}
Esempio n. 3
0
//锁定鼠标到某一个范围
void    DesignerHook::MouseLock(TControl* Sender)
{
    TRect   Rect;   
    SetCaptureControl(Sender);
    GetClipCursor(&MouseRect_);
    if(NULL == Sender->Parent){
        return;
    }
    Rect=  Sender->Parent->ClientRect;
    //Rect = Sender->Parent->ClientToScreen(Rect);
    TPoint  PtTopLeft,PtBottomRight;
    PtTopLeft.x = Rect.Left;
    PtTopLeft.y = Rect.Top;
    PtTopLeft =  Sender->Parent->ClientToScreen(PtTopLeft);
    Rect.Top= PtTopLeft.y;
    Rect.Left= PtTopLeft.x;

    PtBottomRight.x = Rect.right;
    PtBottomRight.y = Rect.bottom;
    PtBottomRight =  Sender->Parent->ClientToScreen(PtBottomRight);
    Rect.bottom= PtBottomRight.y;
    Rect.right= PtBottomRight.x;

    ClipCursor(&Rect); //把鼠标锁定在固定区?
}
Esempio n. 4
0
void __fastcall DesignerHook::MouseDown(TControl* Sender,TMouseButton Button, Classes::TShiftState Shift, int X, int Y)
{
    int  CtrlIndex=0;
    if(Dragging_) return ;
    CtrlIndex = Controls_->IndexOf(Sender);

    if(Shift.Contains(ssShift)){
        //按Shift多选
        if (Sender == Root_ || Sender == Form_ ) {
            //多选不能添加Root或者Form
            return;
        }
        if(CtrlIndex == -1){
            Add(Sender);
            SetDragging(false);
            //Dragging_=false;
        }else{
            Remove(Sender);
            ShowGrabHandle(true);
        }
    }else {
        // if (ssCtrl in Shift) or (Sender = FRoot) then
        if( Shift.Contains(ssCtrl) || Sender == Root_){
            //按住Shift或者点击的是Root就框选
            Clear();
            if(CheckPtrType<TWinControl*>(Sender)){
                TWinControl* win_ctrl=DownCast<TWinControl*,TControl*>(Sender);
                if(win_ctrl->ControlCount == 0){
                    if(CtrlIndex == -1){
                        Add(Sender);
                        ShowGrabHandle(true);
                    }
                }else{
                    PointStart_= Sender->ClientToScreen(Point(X, Y));
                    OldRect_= Rect(X, Y, X + 1, Y + 1);
                    Selecting_ = true;
                    SetCaptureControl(Sender);
                }
                return ;
            }
        }else{
            //没按Shift也没按Ctrl点击.那就添加自己到选择的控件组中 .Root和Form不能和别的控件同时在组中
            if( Sender == Root_ || Sender == Form_ ) {
                return;
            }
            if(CtrlIndex == -1){
                Clear();
                Add(Sender);
            }
            SetDragging(true);
            //Dragging_ = true;
            DraggingControl_ = Sender;
            MouseLock(Sender);
            BeforDragPos_ = Sender->ClientToScreen(Point(X, Y));
        }
    }
}
void __fastcall TIntMinerField::MouseDownHandler(System::TObject* Sender, Controls::TMouseButton Button, Classes::TShiftState Shift, int X, int Y)
{
  int ACol, ARow;

  SetCaptureControl(FGrid->Views[0]->Site);
  MouseToCell(X, Y, ACol, ARow);
  if((ACol == - 1) || (ARow == -1))
    return;

  if((Shift == (TShiftState() << ssLeft << ssRight)) || (Shift == (TShiftState() << ssLeft << ssRight))
    || (Shift == (TShiftState() << ssMiddle)) || (Shift == (TShiftState() << ssLeft << ssMiddle))
    || (Shift == (TShiftState() << ssRight << ssMiddle))) {
    FireImageChanged(imAstonisment);
    FSurprised = true;
    for(int i=-1; i <=1; i++)
      for(int j=-1; j <=1; j++)
          if(CheckFieldBounds(ACol+i, ARow+j) && (
            (CellState[ACol+i][ARow+j].CellState == csClosed)
            || (CellState[ACol+i][ARow+j].CellState == csQuestionMarked))) {
            AddPressedCell(ACol+i, ARow+j);
            InvalidateCell(ACol+i, ARow+j);
          };
    return;
  };

  if(Button == mbLeft) {
    FireImageChanged(imAstonisment);
    FSurprised = true;
    if((CellState[ACol][ARow].CellState == csClosed)
        || (CellState[ACol][ARow].CellState == csQuestionMarked)) {
        AddPressedCell(ACol, ARow);
        InvalidateCell(ACol, ARow);
      };
    return;
  };

  if(Button == mbRight) {
    if(CellState[ACol][ARow].CellState == csOpened) return;
    if(CellState[ACol][ARow].CellState == csClosed) {
      FireMinerFieldEvent(ACol, ARow, meBombMarkCell);
      FireSetMineCountEvent(mcDecMineCount);
    }
    else
    if((CellState[ACol][ARow].CellState == csBombMarked) &&
      FQuestionMarkCell) {
      FireMinerFieldEvent(ACol, ARow, meQuestionMarkCell);
      FireSetMineCountEvent(mcIncMineCount);
    }
    else {
      FireMinerFieldEvent(ACol, ARow, meCloseCell);
      if(!FQuestionMarkCell) FireSetMineCountEvent(mcIncMineCount);
    };
    InvalidateCell(ACol, ARow);
  };
}
Esempio n. 6
0
//释放对鼠标的锁定
void    DesignerHook::MouseFree()
{
    SetCaptureControl(NULL);
    ClipCursor(&MouseRect_);
}