public IBlockView ChildHasPoint(Point p, Point origin) { for (int i = 0; i < Contents.Count; ++i) { IBlockView v = Contents[i]; Point rp = new Point(0, layoutOffsets[i * 2]); // notice that contentOffsets also holds the offset if (v.HasPoint(p, origin.Offseted(rp.X, rp.Y))) // of the "side" graphics, not just the content views { IBlockView chp = v.ChildHasPoint(p, origin.Offseted(rp.X, rp.Y)); if (chp == v) { return(this); } else { return(chp); } } } for (int i = 0; i < Scripts.Count; ++i) { IBlockView v = Scripts[i]; Point rp = scriptOffsets[i]; if (v.HasPoint(p, origin.Offseted(rp.X, rp.Y))) { return(v.ChildHasPoint(p, origin.Offseted(rp.X, rp.Y))); } } return(this); }
public Bitmap MakeSpeechBalloon(Sprite s, string text, out Point drawFrom) { Rectangle r1 = AreaRight(Bounds, s.Bounds); int margin = 2; Rectangle r2 = r1; r1.Inflate(-margin * 2, -margin * 2); Size textSize = graphics.MeasureString(text, textFont, r1.Size.ToSizeF()).ToSize(); textSize = new Size(textSize.Width + 1, textSize.Height + 1); Bitmap ret = new Bitmap(textSize.Width + margin * 2, textSize.Height + margin * 2, System.Drawing.Imaging.PixelFormat.Format32bppPArgb); Point head = new Point(ret.Width / 2, ret.Height - 1); using (Graphics g = Graphics.FromImage(ret)) { g.Clear(Color.Transparent); Point[] points = { head, head.Offseted(3, -2), head.Offseted(6, -2) }; Rectangle r3 = new Rectangle(1, 1, ret.Width - 2, ret.Height - 4); g.FillRectangle(Brushes.White, r3); g.DrawRectangle(Pens.Black, r3); g.FillPolygon(Brushes.White, points); g.DrawPolygon(Pens.Black, points); g.DrawLine(Pens.White, points[1], points[2].Offseted(0, -1)); g.DrawString(text, textFont, Brushes.Black, new Rectangle(new Point(margin, margin), textSize)); } drawFrom = s.Bounds.TopRight().Offseted(2, -10); return(ret); }
public IBlockView ChildHasPoint(Point p, Point origin) { int y = 0; for (int i = 0; i < elements.Count; ++i) { IBlockView v = elements[i]; Point rp = new Point(0, y); if (v.HasPoint(p, origin.Offseted(rp.X, rp.Y))) { IBlockView c = v.ChildHasPoint(p, origin.Offseted(rp.X, rp.Y)); if (i == 0 && c == v) { // selecting the first block-> select whole stack // but selecting a proper child of the first block should // go normally return(this); } else { return(c); } } y += elementBitmaps[i].Height - BlockStackView.NotchHeight; } return(this); }
public void TestRender(Graphics g, Point p, Font f) { Head.TestRender(g, p, f); Side.TestRender(g, p.Offseted(0, 100), f); Waist.TestRender(g, p.Offseted(0, 150), f); FootCap.TestRender(g, p.Offseted(0, 200), f); FootStack.TestRender(g, p.Offseted(0, 250), f); }
internal void MouseMove(Point point) { if (state == CanvasState.Dragging) { Point d = point.Minus(draggingOrigin); Point p1 = allViews[dragged]; Point p2 = p1.Offseted(d); Size sz = dragged.Assemble().Size; Rectangle inva = Rectangle.Union(new Rectangle(p1, sz), new Rectangle(p2, sz)); inva.Inflate(5, 5); draggedModel.Location = p2; draggingOrigin = point; DropRegion active; if (FindActiveDropRegion(ViewBounds(dragged), out active)) { Rectangle topLevelDest = ViewBounds(active.Destination.AbsoluteAncestor()); inva = Rectangle.Union(inva, topLevelDest); } Update(inva); } if (state == CanvasState.Ready) { /* * IBlockView hit = HitTest(point); * if (hit != null) * canvasView.status = hit.ToString(); * else * canvasView.status = "<None>"; * //*/ } }
public IBlockView ChildHasPoint(Point p, Point origin) { for (int i = 0; i < argViews.Count; ++i) { IBlockView v = argViews[i]; Point rp = v.RelativePos; if (!trueArgs[i] && !(v is ITextualView)) { continue; } if (v.HasPoint(p, origin.Offseted(rp.X, rp.Y))) { return(v.ChildHasPoint(p, origin.Offseted(rp.X, rp.Y))); } } return(this); }
public IEnumerable <DropRegion> DropRegions(Point origin) { if (elements.Count == 0) { yield break; } else { bool connectAbove = false, connectBelow = false; IStackableBlockView first = (IStackableBlockView)elements[0]; IStackableBlockView last = (IStackableBlockView)elements.Last(); connectAbove = first.EffectiveAttribute() != BlockAttributes.Hat; connectBelow = last.EffectiveAttribute() != BlockAttributes.Cap; if (connectAbove) { yield return(new DropRegion(DropType.Above, new Rectangle(origin.Offseted(0, -2), new Size(_cached.Width, 5)), this)); } int y = origin.Y + elementBitmaps[0].Height - BlockStackView.NotchHeight; for (int i = 1; i < elements.Count; ++i) { yield return(new DropRegion(DropType.Between, new Rectangle(origin.X, y - 2, elementBitmaps[i].Width, 5), this, i)); y += elementBitmaps[i].Height - BlockStackView.NotchHeight; } if (connectBelow) { yield return(new DropRegion(DropType.Below, new Rectangle(origin.Offseted(0, _cached.Height - 2), new Size(_cached.Width, 5)), this)); } foreach (DropRegion r in ChildDropRegions(origin)) { yield return(r); } } }
public static Point AbsolutePos(this IBlockView v) { Point p = v.RelativePos; while (v.Parent != null) { p = p.Offseted(v.Parent.RelativePos); v = v.Parent; } return(p); }
public static IEnumerable<DropRegion> EdgeDropRegions( this IInvokationBlockView view, Point origin, Size size) { BlockAttributes Attribute = view.Attribute; int Width = size.Width; int Height = size.Height; if (Attribute == BlockAttributes.Stack) { yield return new DropRegion(DropType.Above, new Rectangle(origin.Offseted(0, -2), new Size(Width, 5)), view); yield return new DropRegion(DropType.Below, new Rectangle(origin.Offseted(0, Height - 2), new Size(Width, 5)), view); } else if (Attribute == BlockAttributes.Hat) { yield return new DropRegion(DropType.Below, new Rectangle(origin.Offseted(0, Height - 2), new Size(Width, 5)), view); } else if (Attribute == BlockAttributes.Cap) { yield return new DropRegion(DropType.Above, new Rectangle(origin.Offseted(0, -2), new Size(Width, 5)), view); } }
public IEnumerable<DropRegion> ChildDropRegions(Point origin) { int y = 0; for (int i = 0; i < elements.Count; ++i) { foreach (DropRegion dr in elements[i].ChildDropRegions(origin.Offseted(0, y))) { yield return dr; } y += elementBitmaps[i].Height - BlockStackView.NotchHeight; } }
public IEnumerable <DropRegion> ChildDropRegions(Point origin) { int y = 0; for (int i = 0; i < elements.Count; ++i) { foreach (DropRegion dr in elements[i].ChildDropRegions(origin.Offseted(0, y))) { yield return(dr); } y += elementBitmaps[i].Height - BlockStackView.NotchHeight; } }
public static IEnumerable <DropRegion> EdgeDropRegions( this IInvokationBlockView view, Point origin, Size size) { BlockAttributes Attribute = view.Attribute; int Width = size.Width; int Height = size.Height; if (Attribute == BlockAttributes.Stack) { yield return(new DropRegion(DropType.Above, new Rectangle(origin.Offseted(0, -2), new Size(Width, 5)), view)); yield return(new DropRegion(DropType.Below, new Rectangle(origin.Offseted(0, Height - 2), new Size(Width, 5)), view)); } else if (Attribute == BlockAttributes.Hat) { yield return(new DropRegion(DropType.Below, new Rectangle(origin.Offseted(0, Height - 2), new Size(Width, 5)), view)); } else if (Attribute == BlockAttributes.Cap) { yield return(new DropRegion(DropType.Above, new Rectangle(origin.Offseted(0, -2), new Size(Width, 5)), view)); } }
public IEnumerable <DropRegion> ChildDropRegions(Point origin) { int i = 0; foreach (IBlockView c in Contents) { foreach (DropRegion dr in c.DropRegions(origin.Offseted(0, layoutOffsets[i * 2]))) { yield return(dr); } i++; } i = 0; foreach (IBlockView s in Scripts) { Point p = scriptOffsets[i]; if ((s.Model is BlockStack) && ((BlockStack)s.Model).Empty) { // It's just a placeholder, no 'real' BlockStackView here // We assume here that each script is preceded by a content and that they strictly // alternate, and thus we can set the width of the placeholder to be that of // the previous content (Contents[i].Width) yield return(new DropRegion(DropType.AsArgument, new Rectangle(origin.Offseted(p), new Size(Contents[i].Width, 5)), this, scriptIndexes[i], DataType.Script)); } else { foreach (DropRegion dr in s.DropRegions(origin.Offseted(p.X, p.Y))) { yield return(dr); } } i++; } }
public void TestRender(Graphics g, Point p, Font f) { int x = 0, y = 0; for (int i = 0; i < asArray.Length; ++i) { x = 0; for (int j = 0; j < asArray[i].Length; ++j) { g.DrawImageUnscaled(asArray[i][j], p.Offseted(x, y)); //g.DrawString(string.Format("[{0}][{1}]", i, j), f, Brushes.Black, p.Offseted(x, y)); x += asArray[i][j].Width + 5; } y += asArray[i][0].Height + 5; } }
internal void MouseDown(Point p) { if (state == CanvasState.TextEditing) { // Since the mousedown registered, we've clicked outside the textbox ResetTextEditState(); } else if (state == CanvasState.Ready) { if (canvasView.PaletteRect.Contains(p)) { int x = canvasView.PaletteRect.Left; int y = canvasView.PaletteRect.Top; IBlock[] defaultArgs; string funcName = palette.HitTest(p.Offseted(-x, -y), out defaultArgs); if (funcName != "") { IBlock b = blockSpace.makeNewBlock(funcName, defaultArgs); TopLevelScript s = AddTopLevel(b, p.Offseted(-5, -5)); dragged = blockViews[b]; draggingOrigin = p; draggedModel = s; state = CanvasState.Dragging; PrepareDropRegions(b); Update(ViewBounds(dragged)); return; } } IBlockView hit = HitTest(p); if (hit == null) { return; } if (!allViews.ContainsKey(hit)) { if (hit.Model.ParentRelationship.Type == ParentRelationshipType.Stack) { int i = hit.Model.ParentRelationship.Index; Point np = hit.AbsolutePos(); Rectangle bounds = ViewBounds(hit.AbsoluteAncestor()); BlockStack parent = (BlockStack)hit.Model.ParentRelationship.Parent; TopLevelScript splitted = SplitBlockStack(parent, i, np); Update(bounds); draggedModel = splitted; hit = blockViews[splitted.Block]; } else if (hit.Model.ParentRelationship.Type == ParentRelationshipType.Arg) { if (hit is ITextualView) { // We shouldn't detach e.g a number argument from its block // but we should enable the user to edit it SetEditState((ITextualView)hit); return; } int i = hit.Model.ParentRelationship.Index; Point np = hit.AbsolutePos(); Rectangle bounds = ViewBounds(hit.AbsoluteAncestor()); InvokationBlock parent = (InvokationBlock)hit.Model.ParentRelationship.Parent; TopLevelScript splitted = TakeoutBlockArgument(parent, i, np); Update(bounds); draggedModel = splitted; hit = blockViews[splitted.Block]; } else if (hit.Model.ParentRelationship.Type == ParentRelationshipType.FormalParameter) { ProcDefBlock pd = (ProcDefBlock )hit.Model.ParentRelationship.Parent; VarAccessBlock va = new VarAccessBlock((VarDefBlock)pd.Bits[hit.Model.ParentRelationship.Index]); TopLevelScript tls = AddTopLevel(va, p); hit = ViewFromBlock(va); draggedModel = tls; } else if (hit.Model.ParentRelationship.Type == ParentRelationshipType.None) { hit = null; draggedModel = null; } } else { draggedModel = blockSpace.FindScript(hit.Model); } if (hit != null) { dragged = hit; draggingOrigin = p; state = CanvasState.Dragging; PrepareDropRegions(hit.Model); } Update(); } }
public void TestRender(Graphics g, Point p, Font f) { g.DrawImageUnscaled(A, p); g.DrawImageUnscaled(B, p.Offseted(A.Width+5, 0)); g.DrawImageUnscaled(C, p.Offseted(A.Width + B.Width + 10, 0)); }
public void TestRender(Graphics g, Point p, Font f) { g.DrawImageUnscaled(A1, p); g.DrawImageUnscaled(A2, p.Offseted(0, A1.Height + 5)); g.DrawImageUnscaled(A3, p.Offseted(0, A1.Height + A2.Height+ 10)); }
public void TestRender(Graphics g, Point p, Font f) { int x=0, y=0; for (int i = 0; i < asArray.Length; ++i) { x = 0; for (int j = 0; j < asArray[i].Length; ++j) { g.DrawImageUnscaled(asArray[i][j], p.Offseted(x,y)); //g.DrawString(string.Format("[{0}][{1}]", i, j), f, Brushes.Black, p.Offseted(x, y)); x += asArray[i][j].Width + 5; } y += asArray[i][0].Height + 5; } }
public void TestRender(Graphics g, Point p, Font f) { Head.TestRender(g, p, f); Side.TestRender(g, p.Offseted(0,100), f); Waist.TestRender(g, p.Offseted(0, 150), f); FootCap.TestRender(g, p.Offseted(0, 200), f); FootStack.TestRender(g, p.Offseted(0, 250), f); }
public IEnumerable<DropRegion> ChildDropRegions(Point origin) { int i = 0; foreach (IBlockView c in Contents) { foreach (DropRegion dr in c.DropRegions(origin.Offseted(0, layoutOffsets[i*2]))) yield return dr; i++; } i = 0; foreach (IBlockView s in Scripts) { Point p = scriptOffsets[i]; if ((s.Model is BlockStack) && ((BlockStack)s.Model).Empty) { // It's just a placeholder, no 'real' BlockStackView here // We assume here that each script is preceded by a content and that they strictly // alternate, and thus we can set the width of the placeholder to be that of // the previous content (Contents[i].Width) yield return new DropRegion(DropType.AsArgument, new Rectangle(origin.Offseted(p), new Size(Contents[i].Width, 5)), this, scriptIndexes[i], DataType.Script); } else { foreach (DropRegion dr in s.DropRegions(origin.Offseted(p.X, p.Y))) yield return dr; } i++; } }
public void TestRender(Graphics g, Point p, Font f) { g.DrawImageUnscaled(A1, p); g.DrawImageUnscaled(A2, p.Offseted(0, A1.Height + 5)); g.DrawImageUnscaled(A3, p.Offseted(0, A1.Height + A2.Height + 10)); }
public void TestRender(Graphics g, Point p, Font f) { g.DrawImageUnscaled(A, p); g.DrawImageUnscaled(B, p.Offseted(A.Width + 5, 0)); g.DrawImageUnscaled(C, p.Offseted(A.Width + B.Width + 10, 0)); }
public IBlockView ChildHasPoint(Point p, Point origin) { int y = 0; for (int i = 0; i < elements.Count; ++i) { IBlockView v = elements[i]; Point rp = new Point(0, y); if (v.HasPoint(p, origin.Offseted(rp.X, rp.Y))) { IBlockView c = v.ChildHasPoint(p, origin.Offseted(rp.X, rp.Y)); if (i == 0 && c == v) { // selecting the first block-> select whole stack // but selecting a proper child of the first block should // go normally return this; } else { return c; } } y += elementBitmaps[i].Height - BlockStackView.NotchHeight; } return this; }
public IEnumerable<DropRegion> DropRegions(Point origin) { if (elements.Count == 0) { yield break; } else { bool connectAbove = false, connectBelow = false; IStackableBlockView first = (IStackableBlockView)elements[0]; IStackableBlockView last = (IStackableBlockView)elements.Last(); connectAbove = first.EffectiveAttribute()!= BlockAttributes.Hat; connectBelow = last.EffectiveAttribute()!= BlockAttributes.Cap; if(connectAbove) yield return new DropRegion(DropType.Above, new Rectangle(origin.Offseted(0, -2), new Size(_cached.Width, 5)), this); int y = origin.Y + elementBitmaps[0].Height - BlockStackView.NotchHeight; for (int i = 1; i < elements.Count; ++i) { yield return new DropRegion(DropType.Between, new Rectangle(origin.X, y - 2, elementBitmaps[i].Width, 5), this, i); y += elementBitmaps[i].Height - BlockStackView.NotchHeight; } if(connectBelow) yield return new DropRegion(DropType.Below, new Rectangle(origin.Offseted(0, _cached.Height - 2), new Size(_cached.Width, 5)), this); foreach (DropRegion r in ChildDropRegions(origin)) yield return r; } }
public IBlockView ChildHasPoint(Point p, Point origin) { for (int i = 0; i < Contents.Count; ++i) { IBlockView v = Contents[i]; Point rp = new Point(0, layoutOffsets[i*2]); // notice that contentOffsets also holds the offset if (v.HasPoint(p, origin.Offseted(rp.X, rp.Y))) // of the "side" graphics, not just the content views { IBlockView chp = v.ChildHasPoint(p, origin.Offseted(rp.X, rp.Y)); if (chp == v) return this; else return chp; } } for (int i = 0; i < Scripts.Count; ++i) { IBlockView v = Scripts[i]; Point rp = scriptOffsets[i]; if (v.HasPoint(p, origin.Offseted(rp.X, rp.Y))) return v.ChildHasPoint(p, origin.Offseted(rp.X, rp.Y)); } return this; }
public static Point Offseted(this Point p, Point p2) { return(p.Offseted(p2.X, p2.Y)); }
internal void MouseDown(Point p) { if (state == CanvasState.TextEditing) { // Since the mousedown registered, we've clicked outside the textbox ResetTextEditState(); } else if (state == CanvasState.Ready) { if (canvasView.PaletteRect.Contains(p)) { int x = canvasView.PaletteRect.Left; int y = canvasView.PaletteRect.Top; IBlock[] defaultArgs; string funcName = palette.HitTest(p.Offseted(-x, -y), out defaultArgs); if (funcName != "") { IBlock b = blockSpace.makeNewBlock(funcName,defaultArgs); TopLevelScript s = AddTopLevel(b, p.Offseted(-5, -5)); dragged = blockViews[b]; draggingOrigin = p; draggedModel = s; state = CanvasState.Dragging; PrepareDropRegions(b); Update(ViewBounds(dragged)); return; } } IBlockView hit = HitTest(p); if (hit == null) return; if (!allViews.ContainsKey(hit)) { if (hit.Model.ParentRelationship.Type == ParentRelationshipType.Stack) { int i = hit.Model.ParentRelationship.Index; Point np = hit.AbsolutePos(); Rectangle bounds = ViewBounds(hit.AbsoluteAncestor()); BlockStack parent = (BlockStack)hit.Model.ParentRelationship.Parent; TopLevelScript splitted = SplitBlockStack(parent, i, np); Update(bounds); draggedModel = splitted; hit = blockViews[splitted.Block]; } else if (hit.Model.ParentRelationship.Type == ParentRelationshipType.Arg) { if (hit is ITextualView) { // We shouldn't detach e.g a number argument from its block // but we should enable the user to edit it SetEditState((ITextualView) hit); return; } int i = hit.Model.ParentRelationship.Index; Point np = hit.AbsolutePos(); Rectangle bounds = ViewBounds(hit.AbsoluteAncestor()); InvokationBlock parent = (InvokationBlock)hit.Model.ParentRelationship.Parent; TopLevelScript splitted = TakeoutBlockArgument(parent, i, np); Update(bounds); draggedModel = splitted; hit = blockViews[splitted.Block]; } else if (hit.Model.ParentRelationship.Type == ParentRelationshipType.FormalParameter) { ProcDefBlock pd = (ProcDefBlock ) hit.Model.ParentRelationship.Parent; VarAccessBlock va = new VarAccessBlock((VarDefBlock)pd.Bits[hit.Model.ParentRelationship.Index]); TopLevelScript tls = AddTopLevel(va, p); hit = ViewFromBlock(va); draggedModel = tls; } else if (hit.Model.ParentRelationship.Type == ParentRelationshipType.None) { hit = null; draggedModel = null; } } else { draggedModel = blockSpace.FindScript(hit.Model); } if (hit != null) { dragged = hit; draggingOrigin = p; state = CanvasState.Dragging; PrepareDropRegions(hit.Model); } Update(); } }
public void Reassemble() { // Recompute the parts array in case one of the parts' views was reassembled for (int i = 0; i < parts.Count; ++i) { parts[i] = argViews[i].Assemble(); } int firstTextWidth = parts.Count == 0? 1: Math.Max(parts[0].Width, abc.MinTextWidth); int bmpWidth = abc.TextStart.X + firstTextWidth + abc.TextArgDist + parts.After(1).Sum(b => b.Width) + 3; bmpWidth = Math.Max(bmpWidth, abc.MinWidth); int height = parts.Count == 0? 1: parts.Max(b => b.Height); height = Math.Max(height, abc.WMid.Height); int width = bmpWidth - (abc.NW.Width + abc.NE.Width); int bmpHeight = height + abc.NW.Height + abc.SW.Height; Bitmap ret = new Bitmap(bmpWidth, bmpHeight, System.Drawing.Imaging.PixelFormat.Format32bppPArgb); if (_cached != null) { _cached.Dispose(); } _cached = ret; using (Graphics g = Graphics.FromImage(ret)) { g.FastSettings(); g.Clear(Color.Transparent); abc.RenderToFit(g, width, height); if (parts.Count != 0) { Point p = abc.TextStart; int yC = (height - this.parts[0].Height) / 2; Point relativePos = p.Offseted(0, yC); g.DrawImageUnscaled(parts[0], relativePos); argViews[0].RelativePos = relativePos; p.Offset(firstTextWidth + abc.TextArgDist, 0); for (int i = 1; i < parts.Count; ++i) { yC = (height - this.parts[i].Height) / 2; relativePos = p.Offseted(0, yC); g.DrawImageUnscaled(this.parts[i], relativePos); argViews[i].RelativePos = relativePos; p.Offset(this.parts[i].Width, 0); } } } _width = bmpWidth; _height = bmpHeight; fresh = true; }