void Start() { startBlock = gameObject.GetComponent <StartBlock>(); GP = GameObject.Find("Script").GetComponent <GPCtrlr>(); if (gameObject.GetComponent <StartBlock>() != null) { startBlock = gameObject.GetComponent <StartBlock>(); x = startBlock.x; y = startBlock.y; } else { loadBlock = gameObject.GetComponent <LoadBlock>(); x = loadBlock.x; y = loadBlock.y; } }
public void _Finish() { // Sort widths Pillars.SortWidths(); Platforms.SortWidths(); Ceilings.SortWidths(); StartBlock.SortWidths(); EndBlock.SortWidths(); if (MyTileSetInfo.Pendulums.Group.Dict.Count == 0) { MyTileSetInfo.Pendulums.Group = PieceQuad.ElevatorGroup; } if (MyTileSetInfo.Elevators.Group.Dict.Count == 0) { MyTileSetInfo.Elevators.Group = PieceQuad.ElevatorGroup; } if (MyTileSetInfo.FallingBlocks.Group.Dict.Count == 0) { MyTileSetInfo.FallingBlocks.Group = PieceQuad.FallGroup; } if (MyTileSetInfo.BouncyBlocks.Group.Dict.Count == 0) { MyTileSetInfo.BouncyBlocks.Group = PieceQuad.BouncyGroup; } if (MyTileSetInfo.MovingBlocks.Group.Dict.Count == 0) { MyTileSetInfo.MovingBlocks.Group = PieceQuad.MovingGroup; } MyTileSetInfo.Pendulums.Group.SortWidths(); MyTileSetInfo.Elevators.Group.SortWidths(); MyTileSetInfo.FallingBlocks.Group.SortWidths(); MyTileSetInfo.MovingBlocks.Group.SortWidths(); MyTileSetInfo.BouncyBlocks.Group.SortWidths(); }
public void SearchBlock() { blockgroup = GameObject.FindWithTag("Block").GetComponent <StartBlock>(); }
string Rewrite(int fnum, WasmFunction func) { var code = ""; var depth = 2; var stack = new Stack <string>(); var labelStack = new Stack <(bool Added, int Num)?>(); var labelNum = 0; void StartBlock(string head, (bool Added, int Num)?label = null) { code += new string('\t', depth++) + head + " {\n"; labelStack.Push(label); } void EndBlock() { code += new string('\t', --depth) + "}\n"; var label = labelStack.Pop(); if (label != null && !label.Value.Added) { Add($"Label{label.Value.Num}:"); } } void Add(string stmt) => code += new string('\t', depth) + stmt + (/*stmt.EndsWith(":") ? "\n" :*/ ";\n"); void Push(string expr) => stack.Push(expr); string Pop() => stack.Pop(); string LastLine() => code.TrimEnd().Split("\n").Last(); void CutLastLine() => code = code.Substring(0, code.Length - LastLine().Length - 1); var fname = GetFunction((uint)fnum).Item1; StartBlock($"public unsafe static {Rewrite(func.Signature.ReturnType)} {fname}({string.Join(", ", func.Signature.ParamTypes.Select((x, i) => $"{Rewrite(x)} p{i}"))})"); StartBlock("unchecked"); string LocalName(uint num) => num < func.Signature.ParamTypes.Length ? $"p{num}" : $"l{num - func.Signature.ParamTypes.Length}"; for (var i = 0; i < func.Locals.Length; ++i) { Add($"{Rewrite(func.Locals[i])} l{i} = 0"); } void Binary(string op) { var(b, a) = (Pop(), Pop()); Push($"({a}) {op} ({b})"); } void UnsignedBinary(string op, string type) { var(b, a) = (Pop(), Pop()); Push($"({type}) ((u{type}) ({a}) {op} (u{type}) ({b}))"); } void ToBool() => Push($"({Pop()}) ? 1 : 0"); void Swap() { var(b, a) = (Pop(), Pop()); Push(b); Push(a); } foreach (var _inst in func.Instructions) { switch (_inst) { case Instruction <uint> inst when inst == Opcode.get_global: Push(GlobalName(inst.Operand)); break; case Instruction <uint> inst when inst == Opcode.set_global: Add($"{GlobalName(inst.Operand)} = {Pop()}"); break; case Instruction <uint> inst when inst == Opcode.get_local: Push(LocalName(inst.Operand)); break; case Instruction <uint> inst when inst == Opcode.set_local: Add($"{LocalName(inst.Operand)} = {Pop()}"); break; case Instruction <uint> inst when inst == Opcode.tee_local: Push($"({LocalName(inst.Operand)} = {Pop()})"); break; case Instruction <int> inst when inst == Opcode.i32_const: Push(inst.Operand.ToString()); break; case Instruction <long> inst when inst == Opcode.i64_const: Push(inst.Operand + "L"); break; case Instruction <float> inst when inst == Opcode.f32_const: Push($"Reinterpret_f32(0x{BitConverter.ToUInt32(BitConverter.GetBytes(inst.Operand)):X}U)"); break; case Instruction <double> inst when inst == Opcode.f64_const: Push($"Reinterpret_f64(0x{BitConverter.ToUInt64(BitConverter.GetBytes(inst.Operand)):X}UL)"); break; case Instruction <WasmType> inst when inst == Opcode.loop: Add($"Label{++labelNum}:"); StartBlock("", (true, labelNum)); break; case Instruction <WasmType> inst when inst == Opcode.block: StartBlock("", (false, ++labelNum)); break; case Instruction <WasmType> inst when inst == Opcode.@if: StartBlock($"if(({Pop()}) != 0)"); Push("~IF~"); break; case Instruction <uint> inst when inst == Opcode.call: { var(fn, ft) = GetFunction(inst.Operand); var p = ft.ParamTypes.Select(_ => Pop()).Reverse().ToList(); var c = $"{fn}({string.Join(", ", p)})"; if (ft.ReturnType == null) { Add(c); } else { Push(c); } break; } case Instruction <uint> inst when inst == Opcode.call_indirect: { var ft = Module.FuncTypes[inst.Operand]; var p = ft.ParamTypes.Select(_ => Pop()).Reverse().ToList(); //var c = $"{fn}({string.Join(", ", p)})"; Add("throw new System.NotImplementedException(\"Indirect\")"); if (ft.ReturnType != null) { Push("0"); } break; } case Instruction <(uint Alignment, uint Offset)> inst: switch (inst.Op) { case Opcode.i32_store: Swap(); Add($"__Storei32({Pop()}, {Pop()})"); break; case Opcode.i32_load: Push($"__Loadi32({Pop()})"); break; case Opcode.i32_store8: Swap(); Add($"__Storei32_8({Pop()}, {Pop()})"); break; case Opcode.i32_load8_s: Push($"__Loadi32_8s({Pop()})"); break; case Opcode.i32_load8_u: Push($"__Loadi32_8u({Pop()})"); break; case Opcode.i32_store16: Swap(); Add($"__Storei32_16({Pop()}, {Pop()})"); break; case Opcode.i32_load16_s: Push($"__Loadi32_16s({Pop()})"); break; case Opcode.i32_load16_u: Push($"__Loadi32_16u({Pop()})"); break; case Opcode.i64_store: Swap(); Add($"__Storei64({Pop()}, {Pop()})"); break; case Opcode.i64_load: Push($"__Loadi64({Pop()})"); break; case Opcode.i64_store8: Swap(); Add($"__Storei64_8({Pop()}, {Pop()})"); break; case Opcode.i64_load8_s: Push($"__Loadi64_8s({Pop()})"); break; case Opcode.i64_load8_u: Push($"__Loadi64_8u({Pop()})"); break; case Opcode.i64_store16: Swap(); Add($"__Storei64_16({Pop()}, {Pop()})"); break; case Opcode.i64_load16_s: Push($"__Loadi64_16s({Pop()})"); break; case Opcode.i64_load16_u: Push($"__Loadi64_16u({Pop()})"); break; case Opcode.i64_store32: Swap(); Add($"__Storei64_32({Pop()}, {Pop()})"); break; case Opcode.i64_load32_s: Push($"__Loadi64_32s({Pop()})"); break; case Opcode.i64_load32_u: Push($"__Loadi64_32u({Pop()})"); break; case Opcode.f32_store: Swap(); Add($"__Storef32({Pop()}, {Pop()})"); break; case Opcode.f32_load: Push($"__Loadf32({Pop()})"); break; case Opcode.f64_store: Swap(); Add($"__Storef64({Pop()}, {Pop()})"); break; case Opcode.f64_load: Push($"__Loadf64({Pop()})"); break; default: throw new NotImplementedException($"Unhandled instruction: {_inst.ToPrettyString()}"); } break; case Instruction <uint> inst when inst == Opcode.br_if: { var labels = labelStack.ToList(); Add($"if(({Pop()}) != 0) goto Label{labels[(int) inst.Operand].Value.Num}"); break; } case Instruction <uint> inst when inst == Opcode.br: { var labels = labelStack.ToList(); Add($"goto Label{labels[(int) inst.Operand].Value.Num}"); break; } case Instruction <(uint[] Table, uint Default)> inst when inst == Opcode.br_table: { Add("throw new System.Exception(\"br_table\")"); break; } default: switch (_inst.Op) { case Opcode.i32_add: case Opcode.i64_add: case Opcode.f32_add: case Opcode.f64_add: Binary("+"); break; case Opcode.i32_sub: case Opcode.i64_sub: case Opcode.f32_sub: case Opcode.f64_sub: Binary("-"); break; case Opcode.i32_mul: case Opcode.i64_mul: case Opcode.f32_mul: case Opcode.f64_mul: Binary("*"); break; case Opcode.i32_div_s: case Opcode.i64_div_s: case Opcode.f32_div: case Opcode.f64_div: Binary("/"); break; case Opcode.i32_div_u: UnsignedBinary("/", "int"); break; case Opcode.i64_div_u: UnsignedBinary("/", "long"); break; case Opcode.i32_rem_s: case Opcode.i64_rem_s: Binary("%"); break; case Opcode.i32_rem_u: UnsignedBinary("%", "int"); break; case Opcode.i64_rem_u: UnsignedBinary("%", "long"); break; case Opcode.f32_neg: case Opcode.f64_neg: Push($"-({Pop()})"); break; case Opcode.f32_abs: Push($"System.MathF.Abs({Pop()})"); break; case Opcode.f64_abs: Push($"System.Math.Abs({Pop()})"); break; case Opcode.f32_sqrt: Push($"System.MathF.Sqrt({Pop()})"); break; case Opcode.f64_sqrt: Push($"System.Math.Sqrt({Pop()})"); break; case Opcode.f32_floor: Push($"System.MathF.Floor({Pop()})"); break; case Opcode.f64_floor: Push($"System.Math.Floor({Pop()})"); break; case Opcode.f32_ceil: Push($"System.MathF.Ceiling({Pop()})"); break; case Opcode.f64_ceil: Push($"System.Math.Ceiling({Pop()})"); break; case Opcode.i32_and: case Opcode.i64_and: Binary("&"); break; case Opcode.i32_or: case Opcode.i64_or: Binary("|"); break; case Opcode.i32_xor: case Opcode.i64_xor: Binary("^"); break; case Opcode.i32_shl: case Opcode.i64_shl: Push($"(int) ({Pop()})"); Binary("<<"); break; case Opcode.i32_shr_s: case Opcode.i64_shr_s: Push($"(int) ({Pop()})"); Binary(">>"); break; case Opcode.i32_shr_u: Swap(); Push($"(uint) ({Pop()})"); Swap(); Binary(">>"); Push($"(int) ({Pop()})"); break; case Opcode.i64_shr_u: Push($"(int) ({Pop()})"); Swap(); Push($"(ulong) ({Pop()})"); Swap(); Binary(">>"); Push($"(long) ({Pop()})"); break; case Opcode.i32_ge_s: case Opcode.i64_ge_s: case Opcode.f32_ge: case Opcode.f64_ge: Binary(">="); ToBool(); break; case Opcode.i32_gt_s: case Opcode.i64_gt_s: case Opcode.f32_gt: case Opcode.f64_gt: Binary(">"); ToBool(); break; case Opcode.i32_le_s: case Opcode.i64_le_s: case Opcode.f32_le: case Opcode.f64_le: Binary("<="); ToBool(); break; case Opcode.i32_lt_s: case Opcode.i64_lt_s: case Opcode.f32_lt: case Opcode.f64_lt: Binary("<"); ToBool(); break; case Opcode.i32_lt_u: { var(b, a) = (Pop(), Pop()); Push($"(uint) ({a}) < (uint) ({b})"); ToBool(); break; } case Opcode.i32_le_u: { var(b, a) = (Pop(), Pop()); Push($"(uint) ({a}) <= (uint) ({b})"); ToBool(); break; } case Opcode.i32_gt_u: { var(b, a) = (Pop(), Pop()); Push($"(uint) ({a}) > (uint) ({b})"); ToBool(); break; } case Opcode.i32_ge_u: { var(b, a) = (Pop(), Pop()); Push($"(uint) ({a}) >= (uint) ({b})"); ToBool(); break; } case Opcode.i64_lt_u: { var(b, a) = (Pop(), Pop()); Push($"(ulong) ({a}) < (ulong) ({b})"); ToBool(); break; } case Opcode.i64_le_u: { var(b, a) = (Pop(), Pop()); Push($"(ulong) ({a}) <= (ulong) ({b})"); ToBool(); break; } case Opcode.i64_gt_u: { var(b, a) = (Pop(), Pop()); Push($"(ulong) ({a}) > (ulong) ({b})"); ToBool(); break; } case Opcode.i64_ge_u: { var(b, a) = (Pop(), Pop()); Push($"(ulong) ({a}) >= (ulong) ({b})"); ToBool(); break; } case Opcode.i32_eq: case Opcode.i64_eq: case Opcode.f32_eq: case Opcode.f64_eq: Binary("=="); ToBool(); break; case Opcode.i32_ne: case Opcode.i64_ne: case Opcode.f32_ne: case Opcode.f64_ne: Binary("!="); ToBool(); break; case Opcode.i32_eqz: case Opcode.i64_eqz: Push("0"); Binary("=="); ToBool(); break; case Opcode.f32_convert_s_i32: case Opcode.f32_convert_s_i64: case Opcode.f32_convert_u_i32: case Opcode.f32_convert_u_i64: case Opcode.f32_demote_f64: Push($"(float) ({Pop()})"); break; case Opcode.f64_convert_s_i32: case Opcode.f64_convert_s_i64: case Opcode.f64_convert_u_i32: case Opcode.f64_convert_u_i64: case Opcode.f64_promote_f32: Push($"(double) ({Pop()})"); break; case Opcode.i32_reinterpret_f32: Push($"Reinterpret_i32({Pop()})"); break; case Opcode.f32_reinterpret_i32: Push($"Reinterpret_f32({Pop()})"); break; case Opcode.i64_reinterpret_f64: Push($"Reinterpret_i64({Pop()})"); break; case Opcode.f64_reinterpret_i64: Push($"Reinterpret_f64({Pop()})"); break; case Opcode.i32_wrap_i64: Push($"(int) ({Pop()})"); break; case Opcode.i64_extend_s_i32: Push($"(long) ({Pop()})"); break; case Opcode.i64_extend_u_i32: Push($"(long) (ulong) (uint) ({Pop()})"); break; case Opcode.i32_trunc_s_f32: Push($"(int) System.MathF.Truncate({Pop()})"); break; case Opcode.i32_trunc_s_f64: Push($"(int) System.Math.Truncate({Pop()})"); break; case Opcode.i32_trunc_u_f32: Push($"(int) (uint) System.MathF.Truncate({Pop()})"); break; case Opcode.i32_trunc_u_f64: Push($"(int) (uint) System.Math.Truncate({Pop()})"); break; case Opcode.i64_trunc_s_f32: Push($"(long) System.MathF.Truncate({Pop()})"); break; case Opcode.i64_trunc_s_f64: Push($"(long) System.Math.Truncate({Pop()})"); break; case Opcode.i64_trunc_u_f32: Push($"(long) (ulong) System.MathF.Truncate({Pop()})"); break; case Opcode.i64_trunc_u_f64: Push($"(long) (ulong) System.Math.Truncate({Pop()})"); break; case Opcode.@else: if (stack.Peek() != "~IF~" && LastLine().Contains("if(")) { Swap(); if (stack.Pop() != "~IF~") { throw new Exception("Expected only one value from ternary if"); } var last = LastLine().Split("if(")[1]; Push(last.Substring(0, last.Length - 3)); CutLastLine(); Push("~TERNARY~"); } else { if (stack.Pop() != "~IF~") { throw new Exception("Expected no new values from non-ternary if"); } EndBlock(); StartBlock("else"); } break; case Opcode.end: if (stack.Count >= 3) { var slist = stack.ToList(); if (slist[1] != "~TERNARY~") { EndBlock(); break; } Add($"/* {slist.ToPrettyString()} */"); labelStack.Pop(); depth--; var _else = Pop(); if (Pop() != "~TERNARY~") { throw new Exception("Expected ternary"); } var cond = Pop(); var _if = Pop(); Push($"({cond}) ? ({_if}) : ({_else})"); } else { EndBlock(); } break; case Opcode.@return: Add(func.Signature.ReturnType == null ? "return" : $"return {Pop()}"); break; case Opcode.drop: stack.Pop(); break; case Opcode.unreachable: Add("throw new System.Exception(\"Trapping for unreachable code\")"); break; case Opcode.grow_memory: Push($"growMemory({Pop()})"); break; case Opcode.nop: break; default: func.Print(); throw new NotImplementedException($"Unhandled instruction: {_inst.ToPrettyString()}"); } break; } } if (func.Signature.ReturnType != null && stack.Count != 0) { Add($"return {Pop()}"); } EndBlock(); EndBlock(); return(code); }
// Start is called before the first frame update void Start() { MeshPrint = this.gameObject.GetComponent <MeshRenderer>(); blockgroup = GameObject.FindWithTag("Block").GetComponent <StartBlock>(); }
/// <inheritdoc /> public FrmDesigner(FrmWelcome ParentFrmWelcome = null) { InitializeComponent(); //Connections = new Dictionary<BaseBlock, BaseBlock>(); PnlCommandPalette.Hide(); SContainer_Workspace.Panel2.Paint += DrawLinks; SContainer_Workspace.Panel2.Refresh(); MovementTicker = new Timer { Interval = 10, Enabled = false }; MovementTicker.Tick += DoMove; _ParentFrmWelcome = ParentFrmWelcome; BlockTree.NodeMouseDoubleClick += AddBlock; BlockTree.KeyPress += BlockTree_KeyPress; TxtCommandPaletteSearch.TextChanged += (S, E) => { DoSearch(); }; BtnHideCommandPalette.Click += (S, E) => { TxtCommandPaletteSearch.Text = ""; PnlCommandPalette.Hide(); }; KeyUp += OnKeyRelease; LViewSearchResults.ItemActivate += LViewSearchResults_Activated; SContainer_Workspace.Panel2.SuspendLayout(); /*{ * var VarBlock = new DeclareVarBlock { * Location = new Point(300, 10), * Id = (int) BasicBlockIds.Starter, * Size = new Size(200, 100), * TabIndex = (int) BasicBlockIds.Starter * }; * * VarBlock.MouseDown += Block_OnMouseDown; * VarBlock.MouseUp += Block_OnMouseUp; * * SContainer_Workspace.Panel2.Controls.Add(VarBlock); * }*/ { var StartBlock = new StartBlock { Location = new Point(10, 10), Id = (int)BasicBlockIds.Starter, Size = new Size(100, 100), TabIndex = (int)BasicBlockIds.Starter }; StartBlock.Name = StartBlock.GetType().Name + StartBlock.Id; StartBlock.MouseDown += Block_OnMouseDown; StartBlock.MouseUp += Block_OnMouseUp; SContainer_Workspace.Panel2.Controls.Add(StartBlock); } { var DeclarationBlock = new VarDeclareBlock { Location = new Point(SContainer_Workspace.Panel2.Width - 210, 10), Id = (int)BasicBlockIds.Variable, Size = new Size(100, 100), TabIndex = (int)BasicBlockIds.Variable }; DeclarationBlock.Name = DeclarationBlock.GetType().Name + DeclarationBlock.Id; DeclarationBlock.MouseDown += Block_OnMouseDown; DeclarationBlock.MouseUp += Block_OnMouseUp; SContainer_Workspace.Panel2.Controls.Add(DeclarationBlock); } SContainer_Workspace.Panel2.ResumeLayout(true); }
private static BaseBlock RebuildBlock(DeserializedProps Props) { var TypeName = Props.Name.Trim(Digits); BaseBlock BlockToReturn = null; switch (TypeName) { case "StartBlock": { BlockToReturn = new StartBlock(); break; } case "VarDeclareBlock": { BlockToReturn = new VarDeclareBlock(); break; } case "BeepBlock": { BlockToReturn = new BeepBlock(); break; } case "EmptyNormalBlock": { BlockToReturn = new EmptyNormalBlock(); break; } case "DecimalCreateBlock": { BlockToReturn = new DecimalCreateBlock { Value = (decimal)Props.Value, VarName = Props.VarName, }; break; } case "VarRefBlock": { BlockToReturn = new VarRefBlock { VarName = Props.VarName, }; break; } default: { MessageBox.Show("Unable to build the following Block Type - Definition Missing:" + $"{Environment.NewLine}{TypeName}", "B#", MessageBoxButtons.OK, MessageBoxIcon.Error); return(null); } } BlockToReturn.Location = Props.Location; BlockToReturn.Code = Props.Code; BlockToReturn.Name = Props.Name; BlockToReturn.ConnectorSelected = Props.ConnectorSelected; BlockToReturn.TopConnectorZone = Props.TopConnectorZone; BlockToReturn.BottomConnectorZone = Props.BottomConnectorZone; BlockToReturn.OutlineRectangle = Props.OutlineRectangle; BlockToReturn.Size = Props.Size; BlockToReturn.Id = Props.Id; BlockToReturn.NextBlockId = Props.NextBlockId; return(BlockToReturn); }
public string PrettyPrint(string funcName = "") { var str = new StringBuilder(); // Only add the function header if it isn't the lua file's main function if (Parent != null) { str.Append($"function"); #if DEBUG str.Append($" --[[{Id}]]"); #endif str.Append($" {funcName}("); if (Parameters.Count > 0 || IsVarArgs) { str.Append(" "); } // Add all the parameters for (int i = 0; i < Parameters.Count; i++) { if (i != 0) { str.Append(", "); } str.Append(Parameters[i]); } // Add the vararg if the function has it if (IsVarArgs) { if (Parameters.Any()) { str.Append(", "); } str.Append("..."); } if (Parameters.Count > 0 || IsVarArgs) { str.Append(" "); } str.Append(")\n"); } #if DEBUG if (FunctionDebugInfo != null) { str.Append($"--[[ Func length: {FunctionDebugInfo.FunctionStart} - {FunctionDebugInfo.FunctionEnd}]]"); var debugStr = "--[[vars: "; foreach (var variableData in FunctionDebugInfo.VariableNames) { debugStr += $"{variableData.Name}: {variableData.Start} - {variableData.End}"; } debugStr += "]]"; str.Append(debugStr); var debugUpvalStr = "--[[upvals: "; foreach (var variableData in FunctionDebugInfo.UpvalueNames) { debugUpvalStr += $"{variableData}"; } debugUpvalStr += "]]"; str.Append(debugUpvalStr); } #endif if (IsAST) { var block = StartBlock.PrintBlock(IndentLevel); if (Parent != null) { block = block.AddIndent(); } str.Append(block + "\n"); } else if (IsControlFlowGraph) { foreach (var b in Blocks.OrderBy(a => a.Id)) { if (b == EndBlock) { continue; } str.Append(b.ToStringWithLoop() + "\n"); foreach (var inst in b.PhiFunctions.Values) { str.Append(inst + "\n"); } foreach (var inst in b.Instructions) { str.Append(inst + "\n"); } // Insert an implicit goto for fallthrough blocks if the destination isn't actually the next block var lastinst = (b.Instructions.Count > 0) ? b.Instructions.Last() : null; if (lastinst != null && ((lastinst is Jump j && j.Conditional && b.Successors[0].Id != (b.Id + 1)) || (!(lastinst is Jump) && !(lastinst is Return) && b.Successors[0].Id != (b.Id + 1)))) { str.Append("(goto " + b.Successors[0] + ")" + "\n"); } } } else { for (int n = 0; n < Instructions.Count; n++) { var inst = Instructions[n]; str.Append($@"{n}-{inst.OpLocation:D3}-{inst.LineLocation:D4} "); str.Append(inst + "\n"); } } if (Parent != null) { str.Append("end"); if (!IsInline) { str.Append("\n"); } } return(str.ToString()); }
// picture box mouse down event private void pictureBox_MouseDown(object sender, MouseEventArgs e) { // disable buttons during block moving if (scrollDown) { return; } // if block has to start moving if (e.Button == MouseButtons.Middle && selected != null && !linking) { scrollDown = true; pictureBoxImage = CreateImageWithoutSelectedBlock(selected); xDis = selected.X - e.X; yDis = selected.Y - e.Y; } // (un)select block if (e.Button == MouseButtons.Right) { SelectBlock(e.X, e.Y); RefreshScheme(); pictureBoxImage = (Image)pictureBox.Image.Clone(); } // left click mouse interaction if (e.Button == MouseButtons.Left) { // create operation block if (button == OperationBoxButton) { canvas = Graphics.FromImage(pictureBox.Image); OperatingBlock bloc = new OperatingBlock(e.X, e.Y, resourceManager.GetString("OperationBlock")); bloc.Draw(canvas); blockList.Add(bloc); } // create decide block else if (button == DecidingBoxButton) { canvas = Graphics.FromImage(pictureBox.Image); DecidingBlock bloc = new DecidingBlock(e.X, e.Y, resourceManager.GetString("DecideBlock")); bloc.Draw(canvas); blockList.Add(bloc); } // create start block else if (button == startBoxButton) { if (FindNearestBlock((Block b) => { if (b.GetType().Name == "StartBlock") { return(true); } else { return(false); } }, blockList, e.X, e.Y) == null) { // create canvas = Graphics.FromImage(pictureBox.Image); StartBlock bloc = new StartBlock(e.X, e.Y, resourceManager.GetString("StartBlock")); bloc.Draw(canvas); blockList.Add(bloc); } else { // if already exist then show message MessageBox.Show(resourceManager.GetString("DoubleStartBlockWarning")); } } //create end block else if (button == endBoxButton) { canvas = Graphics.FromImage(pictureBox.Image); EndBlock bloc = new EndBlock(e.X, e.Y, resourceManager.GetString("StopBlock")); bloc.Draw(canvas); blockList.Add(bloc); } // start link creating else if (button == linkButton) { LinkPoint x = null; foreach (Block block in blockList) { if ((x = block.CheckPoint(e.X, e.Y, false)) != null) { selectedLinkPoint = x; } } if (selectedLinkPoint != null) { linking = true; pictureBox.Refresh(); pictureBoxImage = (Image)pictureBox.Image.Clone(); } } // delete block else if (button == deleteButton) { Block removed = FindNearestBlock((Block block) => block.Click(e.X, e.Y), blockList, e.X, e.Y); if (removed != null) { textSelectedBlock.Enabled = false; textSelectedBlock.Text = ""; if (selected == removed) { selected = null; } removed.Remove(); blockList.Remove(removed); } RefreshScheme(); } } pictureBox.Refresh(); }
public override int GetHashCode() { return(StartBlock.GetHashCode() ^ Transaction.GetHashCode() ^ Address.GetHashCode()); }
/// <summary> /// The pipeline observes a stream of DateTimeOffsets. Each DateTimeOffset /// received will cause a report to be produced. /// </summary> /// <returns></returns> public IObserver <DateTimeOffset> AsObserver() { return(StartBlock.AsObserver()); }