private void BeginShapeCreate(DrawableBase db) { log.i("BeginShapeCreate"); RectShape rec = db as RectShape; rec.LocationChanged += LocationChg; }
private bool AreaIsOccupied(Vector2 gridPos, DrawableBase drawable) { var debugController = ApplicationController.Instance.DebugController; var isOccupied = false; for (var x = 0; x < drawable.GridSize.x; ++x) { for (var y = 0; y < drawable.GridSize.y; ++y) { var currScreenPos = GetGridCell((int)gridPos.x, (int)gridPos.y).CenterInScreenCoord; var posToCheck = new Vector2() { x = currScreenPos.x + (x * ScreenCellSize), y = currScreenPos.y - (y * ScreenCellSize) }; var gridCell = GetGridCell(posToCheck); if (drawable.Rotation != 0) { var rotatedPos = posToCheck.RotateAround(drawable.ScreenPivot, Quaternion.Euler(0, 0, drawable.Rotation)); gridCell = GetGridCell(rotatedPos); } if (!gridCell || gridCell.IsOccupied) { return(true); } } } return(isOccupied); }
public override void Update(RenderingEngine e, DrawableBase parent, DrawableBase previous) { Translation = GetTranslation(parent); var r = parent.DescriptionBounds; Size = new SizeF(r.Width, r.Height); }
public void LoadModel(DrawableBase drawable) { LightsTreeView.Nodes.Clear(); LightsTreeView.ShowRootLines = false; var dr = drawable as Drawable; var fr = drawable as FragDrawable; if (dr != null) { Drawable = dr; var lights = dr.LightAttributes; if (lights != null) { AddLightsTreeNodes(lights.data_items); } } else if (fr != null) { FragDrawable = fr; var lights = fr.OwnerFragment?.LightAttributes; if (lights != null) { AddLightsTreeNodes(lights.data_items); } } }
public Camera2D CreateCameraIntance(DrawableBase comp) { Camera2D camera = new Camera2D(); OuthersCam.Add(camera); comp.Unloaded += Comp_Unloaded; return camera; }
public bool TryGetSnapPosition(Vector2 screenPos, out Vector2 snapPos, DrawableBase drawable) { var gridPos = GetGridCellRowColumn(screenPos); if (!Single.IsNegativeInfinity(gridPos.x) && !Single.IsNegativeInfinity(gridPos.y)) { var gridCell = GetGridCell(screenPos); if (gridCell) { // Check if neighbouring cells are not occupied if (AreaIsOccupied(gridPos, drawable)) { //Debug.LogFormat("{0} | Area is occupied!", this); snapPos = screenPos; return(false); } snapPos = gridCell.CenterInScreenCoord; return(true); } } snapPos = screenPos; return(false); }
public void Draw(Graphics g, SwitchBase sw, DrawableBase parent, RenderingEngine e) { const float offset = 10; const float radius = 4; var r = sw.SelectionBounds; StringFormat format = new StringFormat(); var textBounds = g.MeasureString(this.Title, FontTitle, r.Size, format); r = new RectangleF(r.X, r.Y - offset - textBounds.Height, r.Width, textBounds.Height); ExtendedGraphics extendedGraphics = new ExtendedGraphics(g, e); var brush = GetMainBrush(r); extendedGraphics.FillRoundRectangle(brush, r.X, r.Y, r.Width, r.Height, radius); extendedGraphics.DrawRoundRectangle(Pen, r.X, r.Y, r.Width, r.Height, radius); r = new RectangleF(r.X + 4, r.Y, r.Width, r.Height); var r1 = new RectangleF(r.X + 0.5f, r.Y + 0.5f, r.Width, r.Height); var r2 = new RectangleF(r.X, r.Y, r.Width, r.Height); g.DrawString(Title, FontTitle, Brushes.Black, r1, format); g.DrawString(Title, FontTitle, Brushes.White, r2, format); }
public override void UpdateMouseMove(RenderingEngine e, DrawableBase parent, DrawableBase previous) { //Console.WriteLine("IsSelected: {0} LeftDown:{1}", IsSelected, e.MouseService.LeftMouseDown); if (e.SelectionService.Input == null && e.SelectionService.Output == null) { if (IsSelected && e.MouseService.LeftMouseDown) { Move(e, parent, previous, false); } } InputOutputBase lastIo = null; foreach (var input in Inputs) { input.UpdateMouseMove(e, this, lastIo); lastIo = input; } if (HasVariableInputs) { _addInputPin.UpdateMouseMove(e, this, lastIo); } if (HasVariableOutputs) { _addOutputPin.UpdateMouseMove(e, this, HasVariableInputs ? (DrawableBase)_addInputPin : lastIo); } }
public virtual void DrawComponents(Graphics g, RenderingEngine e, DrawableBase parent) { foreach (var uiComponent in Components) { uiComponent.Draw(g, e, this); } }
public override void UpdateMouseDown(RenderingEngine e, DrawableBase parent, DrawableBase previous) { UIComponent lastUiComponent = null; foreach (var uiComponent in Components) { uiComponent.UpdateMouseDown(e, this, lastUiComponent); lastUiComponent = uiComponent; } InputOutputBase lastIo = null; foreach (var input in Inputs) { input.UpdateMouseDown(e, this, lastIo); lastIo = input; } if (HasVariableInputs) { _addInputPin.UpdateMouseDown(e, this, lastIo); } if (HasVariableOutputs) { _addOutputPin.UpdateMouseDown(e, this, HasVariableInputs ? (DrawableBase)_addInputPin : lastIo); } base.UpdateMouseDown(e, parent, previous); }
public virtual void DrawBody(Graphics g, RenderingEngine e, DrawableBase parent) { ExtendedGraphics extendedGraphics = new ExtendedGraphics(g, e); var r = Rectangle; Brush brush; if (IsSelected) { brush = GetMainSelectionBrush(r, e); } else if (DebugMode) { brush = GetDebugBrush(r, e); } else if (DebugDataMode) { brush = GetDebugDataBrush(r, e); } else { brush = GetMainBrush(r, e); } const float radius = 3; extendedGraphics.FillRoundRectangle(brush, r.X, r.Y, r.Width, r.Height, radius); extendedGraphics.DrawRoundRectangle(Pen, r.X, r.Y, r.Width, r.Height, radius); }
public override void Draw(Graphics g, RenderingEngine e, DrawableBase parent) { var r = DescriptionBounds; float part = r.Height / 8.0f; float mid = part * 3; var rW = new RectangleF(r.X, r.Y + mid, r.Width, part * 2); var rH = new RectangleF(r.X + mid, r.Y, part * 2, r.Height); var bg = Background; if (IsMouseOver) { if (e.MouseService.LeftMouseDown) { bg = BackgroundMouseDown; } else { bg = BackgroundMouseOver; } } g.DrawRectangle(Pen, rW.X, rW.Y, rW.Width, rW.Height); g.DrawRectangle(Pen, rH.X, rH.Y, rH.Width, rH.Height); g.FillRectangle(bg, rH); g.FillRectangle(bg, rW); base.Draw(g, e, parent); }
private void SelectionController_OnObjectDeleted(DrawableBase drawable) { switch (drawable.Type) { case DrawableBase.DrawableType.Battery: var battery = (BatteryCharacter)drawable; if (battery.Battery.Voltage == 4) { ++CurrentLevel.Max4VBatteries; } else { ++CurrentLevel.Max9VBatteries; } break; case DrawableBase.DrawableType.Bulb: ++CurrentLevel.MaxBulbs; break; case DrawableBase.DrawableType.Buzzer: ++CurrentLevel.MaxBuzzers; break; case DrawableBase.DrawableType.Motor: ++CurrentLevel.MaxMotors; break; case DrawableBase.DrawableType.Switch: ++CurrentLevel.MaxSwitches; break; } }
public void AddToSelection(DrawableBase drawable) { if (_selectedObjects.Add(drawable)) { UpdateSelection(); } }
public virtual void DrawGlyph(Graphics g, RenderingEngine e, DrawableBase parent) { var r = DescriptionBounds; if (r.Height > 0) { //r.Height -= compactOffset2 ExtendedGraphics extendedGraphics = new ExtendedGraphics(g, e); float radius = 2; var brush = new SolidBrush(Color.FromArgb(40, 0, 0, 0)); extendedGraphics.FillRoundRectangle(brush, r.X, r.Y + 1, r.Width, r.Height - 1, radius); var img = GlyphImage; if (DrawGlyphImage && img != null) { float ratio = r.Height / img.Height; var imageRect = r; imageRect.Width = img.Width * ratio; imageRect.Height = img.Height * ratio; imageRect.X = r.X + r.Width * 0.5f - imageRect.Width * 0.5f; imageRect.Y = r.Y + r.Height * 0.5f - imageRect.Height * 0.5f; g.DrawImage(img, imageRect); } } }
public void ClearBridges(DrawableBase drawable) { // If distance between connection and wirepiece is bigger than 1 cell, there is a bridge between them var diff = drawable.PositionOnGrid - PositionOnGrid; if (diff.magnitude > 1) { var normalizedDiff = diff.normalized; var nextBridgeDiff = normalizedDiff; while (nextBridgeDiff != diff) { var bridgeCell = _grid.GetGridCell((int)(PositionOnGrid.x + nextBridgeDiff.x), (int)(PositionOnGrid.y + nextBridgeDiff.y)); if (bridgeCell != null) { var bridgeCellDrawable = bridgeCell.DrawableBase; if (bridgeCellDrawable != null && bridgeCellDrawable.Type == DrawableType.Wire) { var bridgedWire = bridgeCellDrawable as WirePiece; bridgedWire.IsBridge = false; } } nextBridgeDiff += normalizedDiff; } } }
// -------------------------------------------------------------------------------- public override void Draw(Graphics g, RenderingEngine e, DrawableBase parent) { DrawBody(g, e, parent); DrawInputOutputs(g, e, parent); DrawSelection(g, e, parent); DrawDescription(g, e, parent); DrawGlyph(g, e, parent); DrawText(g, e, parent); DrawComponents(g, e, parent); if (HasVariableInputs) { _addInputPin.Draw(g, e, this); } if (HasVariableOutputs) { _addOutputPin.Draw(g, e, this); } base.Draw(g, e, this); }
public override void UpdateMouseUp(RenderingEngine renderingEngine, DrawableBase parent, DrawableBase previous) { if (this.IsMouseOver) { OnClickTrigger(renderingEngine, new TriggerEventArgs(this, GetOutputData(0))); } base.UpdateMouseUp(renderingEngine, parent, previous); }
public override void UpdateMouseDown(RenderingEngine e, DrawableBase parent, DrawableBase previous) { if (IsMouseOver && IsSelected) { _active = !_active; } base.UpdateMouseDown(e, parent, previous); }
public void Draw(Graphics g, SwitchBase sw, DrawableBase parent, RenderingEngine e) { if (Enabled) { if (Items.ContainsKey(sw.UniqueName) && sw.IsMouseOver) { Items[sw.UniqueName].Draw(g, sw, parent, e); } } }
private void treeView_ItemDrag(object sender, ItemDragEventArgs e) { var treeNode = e.Item as TreeNode; DrawableBase item = treeNode?.Tag as SwitchBase; if (item != null) { DoDragDrop(e.Item, DragDropEffects.Move); } }
public override void UpdateMouseUp(RenderingEngine e, DrawableBase parent, DrawableBase previous) { HasFocus = false; if (IsMouseOver) { HasFocus = true; OnClick(); } base.UpdateMouseUp(e, parent, previous); }
public override void DrawText(Graphics g, RenderingEngine e, DrawableBase parent) { var data = GetData(1); if (data != null) { DrawDescriptionText(g, e, parent, data.Value.ToString()); } base.DrawText(g, e, parent); }
public virtual void DrawSelection(Graphics g, Engine e, DrawableBase parent) { if (IsMouseOver) { DrawSelection(g, e, parent, MouseOverPen); } if (IsSelected) { DrawSelection(g, e, parent, SelectedPen); } }
public bool IsConnectedTo(DrawableBase drawable) { foreach (var connection in Connections) { if (connection.Value == drawable) { return(true); } } return(false); }
public CircuitPart GetParentCircuitPartInGroup(DrawableBase drawable) { foreach (var part in CircuitParts) { if (part.ContainsDrawable(drawable)) { return(part); } } return(null); }
public void SetGridCells(Vector2 screenPos, DrawableBase drawable) { drawable.ClearCells(); var gridPos = GetGridCellRowColumn(screenPos); var gridCell = _cells[GetGridCellIndex((int)gridPos.x, (int)gridPos.y)]; if (gridCell && !gridCell.IsOccupied) { drawable.PositionOnGrid = gridPos; // Calculate cell positions before applying rotation var size = drawable.GridSize; var screenPositions = new List <Vector2>(); for (var x = 0; x < size.x; ++x) { for (var y = 0; y < size.y; ++y) { var posToCheck = new Vector2() { x = screenPos.x + (x * ScreenCellSize), y = screenPos.y - (y * ScreenCellSize) }; screenPositions.Add(posToCheck); } } // Apply rotation var rotation = drawable.Rotation; var cells = new List <GridCell>(); foreach (var point in screenPositions) { var newCellPos = point.RotateAround(drawable.ScreenPivot, Quaternion.Euler(0, 0, rotation)); var cellAfterRotation = GetGridCell(newCellPos); if (cellAfterRotation == null) { return; } cells.Add(cellAfterRotation); } // Link cells to drawable foreach (var cell in cells) { drawable.AddCellIndex(cell.GridPos); } drawable.UpdateCells(); ApplicationController.Instance.SelectionController.UpdateSelection(); } }
public override void DrawBody(Graphics g, RenderingEngine e, DrawableBase parent) { if (_active) { var r = new RectangleF(Position, Size); g.FillRectangle(ActiveBrush, r); DrawRectangleF(g, Pen, r); } else { base.DrawBody(g, e, parent); } }
private void EndShapeCreate(DrawableBase db) { log.i("EndShapeCreate"); //RectShape rec = db as RectShape; //if (rec.ItemType == AdItemType.Picture) //{ // tsAddPic_Click(null, null); //} //else if (rec.ItemType == AdItemType.Video && App.VIDEO) //{ // tsAddVideo_Click(null, null); //} }
public override void UpdateMouseUp(RenderingEngine e, DrawableBase parent, DrawableBase previous) { if (e.MouseService.LeftMouseDown) { HasFocus = false; if (IsMouseOver) { HasFocus = true; } } base.UpdateMouseUp(e, parent, previous); }