public void DropEverything(CMouseCaptureState this_state, CMouseCaptureState next_state) { HostForm.listBox1.Items.Add("DropEverything : " + this_state); MasterArrow = null; SlaveArrows.Clear(); }
void btnEditorOK_Click(object sender, SdlDotNet.Widgets.MouseButtonEventArgs e) { Arrows.Arrow arrowToSend = new Arrows.Arrow(); arrowToSend.Name = txtName.Text; arrowToSend.Pic = hsbPic.Value; arrowToSend.Range = hsbRange.Value; arrowToSend.Amount = hsbAmount.Value; Messenger.SendSaveArrow(itemNum, arrowToSend); pnlArrowEditor.Visible = false; pnlArrowList.Visible = true; this.Size = new System.Drawing.Size(pnlArrowList.Width, pnlArrowList.Height); }
public void DisplayArrowData() { // First, get the arrow instance based on the stored arrow index Arrows.Arrow arrow = Arrows.ArrowHelper.Arrows[itemNum]; // Update the widgets with the arrow data txtName.Text = arrow.Name; //pic.Image = Tools.CropImage(Logic.Graphics.GraphicsManager.Arrows, new Rectangle(0, arrow.Pic * 32, 32, 32)); hsbAmount.Value = arrow.Amount; hsbRange.Value = arrow.Range; pnlArrowEditor.Visible = true; this.Size = new System.Drawing.Size(pnlArrowEditor.Width, pnlArrowEditor.Height); }
public void DropSlave(CMouseCaptureState this_state, CMouseCaptureState next_state) { // Переходы машины состояний [B1] и [B2] if ((next_state == CapturedSecond) || (next_state == CapturedMaster)) { HostForm.listBox1.Items.Add("DropSlave : " + this_state); Arrows.Arrow arrow = ButtonToArrow(this_state.CapturedButton); SlaveArrows.Remove(arrow); this_state.CapturedButton = MouseButtons.None; } }
// Ответные события для машины состояний //--------------------------------------------------------------------------- public void CaptureMaster(CMouseCaptureState this_state, CMouseCaptureState prev_state) { // Захватываем основную "ведущую" стрелку. // Нужно только в ситуации если вход в это состояние произошел // из ситуации, когда ни одна кнопка мыши не была захвачена. if (prev_state == Released) { HostForm.listBox1.Items.Add("CaptureMaster : " + this_state); Arrows.Arrow arrow = ButtonToArrow(this_state.CapturedButton); MasterArrow = arrow; SlaveArrows.Clear(); } }
public void CaptureSlave(CMouseCaptureState this_state, CMouseCaptureState prev_state) { if ( // Переход машины состояний [C1] ((this_state == CapturedSecond) && (prev_state == CapturedMaster)) || // Или переход машины состояний [C2] ((this_state == CapturedThird) && (prev_state == CapturedSecond)) ) { HostForm.listBox1.Items.Add("CaptureSlave : " + this_state); Arrows.Arrow arrow = ButtonToArrow(this_state.CapturedButton); SlaveArrows.Add(arrow); } }
public CManipulator(ClockForm host) { HostForm = host; MasterArrow = null; SlaveArrows = new HashSet <Arrows.Arrow> (); ButtonToArrowMap = new Dictionary <MouseButtons, Arrows.Arrow> { [MouseButtons.Left] = HostForm.AllArrows.User1, [MouseButtons.Right] = HostForm.AllArrows.User2, [MouseButtons.Middle] = HostForm.AllArrows.User3, }; Released = new CMouseCaptureState("Released"); CapturedMaster = new CMouseCaptureState("Captured Master : First button"); CapturedSecond = new CMouseCaptureState("Captured Slave : Second button"); CapturedThird = new CMouseCaptureState("Captured Slave : Third button"); Released.OnEnter += DropEverything; CapturedMaster.OnEnter += CaptureMaster; CapturedSecond.OnEnter += CaptureSlave; CapturedSecond.OnLeave += DropSlave; CapturedThird.OnEnter += CaptureSlave; CapturedThird.OnLeave += DropSlave; // Простая машина состояний для управления тремя векторами одновременно // с использованием трех кнопок мыши. Используется для примера кода, // а не потому, что это самое короткое или лучшее решение. // // Три уровня «захвата» кнопок мыши. // // .-------------------. // .------------------------→ | Зажата первая | // | .---[R1]----| "мастер" кнопка | // | | '-------------------' // [C1] | | ↑ // | | [C2] [B1] // | | ↓ | // .--------------------. | .---------------------. // | Мышь в свободном | ←--O---[R2]----| Две кнопки зажаты | // | состоянии | | '---------------------' // '--------------------' | | ↑ // | [C3] [B2] // | ↓ | // | .-------------------------. // '---[R3]----| Все три кнопки зажаты | // '-------------------------' // // Сокращения: C -- захват, B -- возврат, R -- сброс // // Анализ состояния [CapturedMaster] // // Точки входа: // [C1] -> CapturedMaster.Enter -> делегат CaptureMaster из [C1] // [B1] -> CapturedMaster.Enter -> делегат CaptureMaster из [B1] // // Machine = new СMouseStateMachine ( new СMouseStateMachine.CStates ( Released, CapturedMaster, CapturedSecond, CapturedThird ) ); Machine.AttachTransition(CapturedMaster, CapturedSecond, TransDir.Any); Machine.AttachTransition(CapturedSecond, CapturedThird, TransDir.Any); Machine.AttachTransition(Released, CapturedMaster, TransDir.Forward); Machine.AttachTransition(Machine.Any, Released, TransDir.Forward); }