private void PaintNodes(IList<GraphNode> nodeList, PaintState state) { int nodeCount = nodeList.Count; for(int i=0; i<nodeCount; i++) { PaintNode(nodeList[i], state); } }
// Move staple towards endpoint public void Update() { switch (paintState) { case PaintState.MoveDown: transform.position = Vector3.MoveTowards(transform.position, endPosition, extendSpeed); if (transform.position.y <= endPosition.y) { transform.position = endPosition; paintState = PaintState.MoveUp; } break; case PaintState.MoveUp: transform.position = Vector3.MoveTowards(transform.position, startPosition, retractSpeed); if (transform.position.y >= startPosition.y) { transform.position = startPosition; paintState = PaintState.Rest; } break; } }
// Push the staple down if it isn't down public void PressPaint() { if (paintState == PaintState.Rest) { paintState = PaintState.MoveDown; } }
/// <summary> /// Override that paints nodes with a fill color that represents each node's activation function. /// </summary> protected override void PaintNode(GraphNode node, PaintState state) { Point nodePos = ModelToViewport(node.Position, state); if(!IsPointWithinViewport(nodePos, state)) { // Skip node. It's outside the viewport area. return; } // Paint the node as a square. Create a Rectangle that represents the square's position and size. Point p = new Point(nodePos.X - state._nodeDiameterHalf, nodePos.Y - state._nodeDiameterHalf); Size s = new Size(state._nodeDiameter, state._nodeDiameter); Rectangle r = new Rectangle(p, s); // Paint the node. Fill first and then border, this gives a clean border. Graphics g = state._g; int activationFnId = (int)node.AuxData[0]; Brush fillBrush = _brushNodeFillArr[activationFnId % _brushNodeFillArr.Length]; g.FillRectangle(fillBrush, r); g.DrawRectangle(__penBlack, r); // Draw the node tag. nodePos.X += state._nodeDiameterHalf+1; nodePos.Y -= state._nodeDiameterHalf/2; g.DrawString(node.Tag, __fontNodeTag, __brushBlack, nodePos); }
/// <summary> /// Paint the nodes of a directed graph. /// </summary> /// <param name="model">The graph view model being painted.</param> /// <param name="state">A collection of working variables for painting a graph to a GDI+ surface.</param> protected virtual void PaintNodes(DirectedGraphViewModel model, PaintState state) { // Loop the nodes, painting each in turn. for (int i = 0; i < model.NodeIdByIdx.Count; i++) { int id = model.NodeIdByIdx.Map(i); Point pos = model.NodePosByIdx ![i];
public override void Draw(PaintEventArgs e, PaintState paintstate) { Rectangle rect; Point start = DrawStartPosition; rect = new Rectangle(start, new Size(DrawEndPosition.X - start.X, DrawEndPosition.Y - start.Y)); e.Graphics.DrawEllipse(GetForgroundPen(paintstate), rect); }
/// ------------------------------------------------------------------------------------ protected override void OnPaintBackground(PaintEventArgs e) { base.OnPaintBackground(e); if (m_mouseOver || Checked) { m_state = (m_mouseDown ? PaintState.HotDown : PaintState.Hot); } else { m_state = PaintState.Normal; } if (DrawBackground != null && DrawBackground(this, e, m_state)) { return; } var rc = ClientRectangle; using (SolidBrush br = new SolidBrush(BackColor)) e.Graphics.FillRectangle(br, rc); if (m_state != PaintState.Normal) { PaintingHelper.DrawHotBackground(e.Graphics, rc, m_state); } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Draws a background in the specified rectangle that looks like a toolbar button /// when the mouse is over it, with consideration for whether the look should be like /// the mouse is down or not. Note, when a PaintState of normal is specified, this /// method does nothing. Normal background painting is up to the caller. /// </summary> /// ------------------------------------------------------------------------------------ public static void DrawHotBackground(Graphics g, Rectangle rc, PaintState state) { // The caller has to handle painting when the state is normal. if (state == PaintState.Normal) { return; } // Determine the highlight color. Color clrHot = (Application.RenderWithVisualStyles ? VisualStyleInformation.ControlHighlightHot : SystemColors.MenuHighlight); int alpha = (Application.RenderWithVisualStyles ? 95 : 120); // Determine the angle and one of the colors for the gradient highlight. When state is // hot down, the gradiant goes from bottom (lighter) to top (darker). When the state // is just hot, the gradient is from top (lighter) to bottom (darker). float angle = (state == PaintState.HotDown ? 270 : 90); Color clr2 = ColorHelper.CalculateColor(Color.White, clrHot, alpha); // Draw the label's background. if (state == PaintState.Hot) { using (LinearGradientBrush br = new LinearGradientBrush(rc, Color.White, clr2, angle)) g.FillRectangle(br, rc); } else { using (LinearGradientBrush br = new LinearGradientBrush(rc, clr2, clrHot, angle)) g.FillRectangle(br, rc); } // Draw a black border around the label. ControlPaint.DrawBorder(g, rc, Color.Black, ButtonBorderStyle.Solid); }
/// <summary> /// Indicates if a point is within the graphics area represented by the viewport. /// That is, does an element at this position need to be painted. /// </summary> protected bool IsPointWithinViewport(Point p, PaintState state) { return (p.X >= 0) && (p.Y >= 0) && (p.X < state._viewportArea.Width) && (p.Y < state._viewportArea.Height); }
private void PaintLegend(PaintState state) { const int LineHeight = 16; const int Margin = 10; IList <ActivationFunctionInfo> fnList = _activationFnLibrary.GetFunctionList(); int count = fnList.Count; // Determine y position of first line. int yCurr = Math.Max(Margin, state._viewportArea.Height - ((count * LineHeight) + Margin)); for (int i = 0; i < count; i++, yCurr += LineHeight) { ActivationFunctionInfo fnInfo = fnList[i]; const int X = Margin; // Paint an example node as part of the legend item. Point p = new Point(X, yCurr); Size s = new Size(state._nodeDiameter, state._nodeDiameter); Rectangle r = new Rectangle(p, s); // Paint the node. Fill first and then border, this gives a clean border. Graphics g = state._g; Brush fillBrush = _brushNodeFillArr[fnInfo.Id % _brushNodeFillArr.Length]; g.FillRectangle(fillBrush, r); g.DrawRectangle(__penBlack, r); // Write the activation function string ID. g.DrawString(fnList[i].ActivationFunction.FunctionId, __fontNodeTag, __brushBlack, X + 12, yCurr - 1); } }
/// <summary> /// Indicates if a point is within the graphics area represented by the viewport. /// That is, does an element at this position need to be painted. /// </summary> protected bool IsPointWithinViewport(Point p, PaintState state) { return((p.X >= 0) && (p.Y >= 0) && (p.X < state._viewportArea.Width) && (p.Y < state._viewportArea.Height)); }
/// <summary> /// Override that paints nodes with a fill color that represents each node's activation function. /// </summary> protected override void PaintNode(GraphNode node, PaintState state) { Point nodePos = ModelToViewport(node.Position, state); if (!IsPointWithinViewport(nodePos, state)) { // Skip node. It's outside the viewport area. return; } // Paint the node as a square. Create a Rectangle that represents the square's position and size. Point p = new Point(nodePos.X - state._nodeDiameterHalf, nodePos.Y - state._nodeDiameterHalf); Size s = new Size(state._nodeDiameter, state._nodeDiameter); Rectangle r = new Rectangle(p, s); // Paint the node. Fill first and then border, this gives a clean border. Graphics g = state._g; int activationFnId = (int)node.AuxData[0]; Brush fillBrush = _brushNodeFillArr[activationFnId % _brushNodeFillArr.Length]; g.FillRectangle(fillBrush, r); g.DrawRectangle(__penBlack, r); // Draw the node tag. nodePos.X += state._nodeDiameterHalf + 1; nodePos.Y -= state._nodeDiameterHalf / 2; g.DrawString(node.Tag, __fontNodeTag, __brushBlack, nodePos); }
/// <summary> /// Paint a directed graph. /// </summary> /// <param name="model">The graph view model to paint.</param> /// <param name="state">A collection of working variables for painting a graph to a GDI+ surface.</param> protected virtual void PaintGraph(DirectedGraphViewModel model, PaintState state) { // Paint all connections, followed by all nodes. // This way the slightly 'rough' positioning of the connection endpoints is overpainted by the nodes // to produce an overall good visual result. PaintConnections(model, state); PaintNodes(model, state); }
/// <summary> /// Paints the provided IOGraph onto the provided GDI+ Graphics drawing surface. /// </summary> protected override void PaintNetwork(IOGraph graph, PaintState state) { // Invoke the base painting routine. base.PaintNetwork(graph, state); // Paint a legend for the activation functions. PaintLegend(state); }
/// <summary> /// Paints the provided IOGraph onto the provided GDI+ Graphics drawing surface. /// </summary> public void PaintNetwork(IOGraph graph, Graphics g, Rectangle viewportArea, float zoomFactor) { // Create a PaintState object. This holds all temporary state info for the painting routines. // Pass the call on to the virtual PaintNetwork. This allows us to override a version of PaintNetwork // that has access to a PaintState object. PaintState state = new PaintState(g, viewportArea, zoomFactor, graph.ConnectionWeightRange); PaintNetwork(graph, state); }
public override void Draw(PaintEventArgs e, PaintState paintstate) { Point[] pts = new Point[3]; pts[0] = DrawStart; pts[1] = new Point(DrawStart.X, DrawEnd.Y); pts[2] = new Point(DrawEnd.X, DrawStart.Y); e.Graphics.DrawPolygon(GetForgroundPen(paintstate), pts); }
private void PaintNodes(IList <GraphNode> nodeList, PaintState state) { int nodeCount = nodeList.Count; for (int i = 0; i < nodeCount; i++) { PaintNode(nodeList[i], state); } }
public IDisposable ApplyTo(SKPaint paint) { var state = new PaintState(paint, paint.Color, paint.Shader); paint.Color = Paint.Color; paint.Shader = Paint.Shader; return(state); }
private void OnPaintCellState(DataGridViewProgressCellPaintStateEventArgs arg) { if (arg == null) { throw new ArgumentNullException("arg"); } PaintState?.Invoke(this, arg); }
public override void Draw(PaintEventArgs e, PaintState paintstate) { Point old = DrawStart; Pen pen = GetForgroundPen(paintstate); foreach (LinePoint pt in _points) { MyDrawLine(e, pen, old, pt.DrawPos); old = pt.DrawPos; } }
public void EraserTouched() { paintState = PaintState.Eraser; brush_hi.SetActive(false); eraser_hi.SetActive(true); selectedColor = Color.white; foreach (ColorPalette cp in colorPalettes) { cp.Deselect(); } }
public void Start() { paintBox.GetComponent <ToolType>().SetType(PlantType.Paint); machineType = PlantType.Paint; paintState = PaintState.Rest; extendSpeed = 0.1f; retractSpeed = 0.2f; startPosition = transform.position; endPosition = new Vector3(startPosition.x, startPosition.y - 1.5f, startPosition.z); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Draws a background in the specified rectangle that looks like a toolbar button /// when the mouse is over it, with consideration for whether the look should be like /// the mouse is down or not. Note, when a PaintState of normal is specified, this /// method does nothing. Normal background painting is up to the caller. /// </summary> /// ------------------------------------------------------------------------------------ public static void DrawHotBackground(Graphics g, Rectangle rc, PaintState state) { // The caller has to handle painting when the state is normal. if (state == PaintState.Normal) { return; } var hotDown = (state == PaintState.HotDown); var clr1 = (hotDown ? ProfessionalColors.ButtonPressedGradientBegin : ProfessionalColors.ButtonSelectedGradientBegin); var clr2 = (hotDown ? ProfessionalColors.ButtonPressedGradientEnd : ProfessionalColors.ButtonSelectedGradientEnd); using (var br = new LinearGradientBrush(rc, clr1, clr2, 90)) g.FillRectangle(br, rc); var clrBrdr = (hotDown ? ProfessionalColors.ButtonPressedHighlightBorder : ProfessionalColors.ButtonSelectedHighlightBorder); ControlPaint.DrawBorder(g, rc, clrBrdr, ButtonBorderStyle.Solid); //// Determine the highlight color. //Color clrHot = (CanPaintVisualStyle() ? // VisualStyleInformation.ControlHighlightHot : SystemColors.MenuHighlight); //int alpha = (CanPaintVisualStyle() ? 95 : 120); //// Determine the angle and one of the colors for the gradient highlight. When state is //// hot down, the gradiant goes from bottom (lighter) to top (darker). When the state //// is just hot, the gradient is from top (lighter) to bottom (darker). //float angle = (state == PaintState.HotDown ? 270 : 90); //Color clr2 = ColorHelper.CalculateColor(Color.White, clrHot, alpha); //// Draw the label's background. //if (state == PaintState.Hot) //{ // using (LinearGradientBrush br = new LinearGradientBrush(rc, Color.White, clr2, angle)) // g.FillRectangle(br, rc); //} //else //{ // using (LinearGradientBrush br = new LinearGradientBrush(rc, clr2, clrHot, angle)) // g.FillRectangle(br, rc); //} //// Draw a black border around the label. //ControlPaint.DrawBorder(g, rc, Color.Black, ButtonBorderStyle.Solid); }
private void PaintConnections(IList <GraphNode> nodeList, PaintState state) { int nodeCount = nodeList.Count; for (int i = 0; i < nodeCount; i++) { List <GraphConnection> conList = nodeList[i].OutConnectionList; int conCount = conList.Count; for (int j = 0; j < conCount; j++) { PaintConnection(conList[j], state); } } }
/// ------------------------------------------------------------------------------------ /// <summary> /// /// </summary> /// <param name="state"></param> /// <param name="normalBack"></param> /// <returns></returns> /// ------------------------------------------------------------------------------------ protected Color GetBackColorShade(PaintState state, Color normalBack) { if (this.Enabled) { switch (state) { case PaintState.MouseOver: return Color.FromArgb(50, SystemColors.ActiveCaption); case PaintState.MouseDown: return Color.FromArgb(65, SystemColors.ActiveCaption); case PaintState.Pushed: return Color.FromArgb(40, SystemColors.ActiveCaption); } } return normalBack; }
/// ------------------------------------------------------------------------------------ /// <summary> /// /// </summary> /// <returns></returns> /// ------------------------------------------------------------------------------------ private void DeterminePaintState() { if ((m_mouseIsDown && m_mouseIsOver && ButtonIsOn) || (m_mouseIsDown && m_mouseIsOver) || (m_mouseIsDown && ButtonIsOn) || (m_mouseIsOver && ButtonIsOn)) { m_paintState = PaintState.MouseDown; } else if (m_mouseIsDown || m_mouseIsOver && ShadeWhenMouseOver) m_paintState = PaintState.MouseOver; else if (ButtonIsOn) m_paintState = PaintState.Pushed; else m_paintState = PaintState.Normal; }
/// ------------------------------------------------------------------------------------ /// <summary> /// Track when the mouse leaves the control when a mouse button is pressed. /// </summary> /// ------------------------------------------------------------------------------------ protected override void OnMouseMove(MouseEventArgs e) { base.OnMouseMove(e); m_mouseOver = ClientRectangle.Contains(e.Location); var newState = (m_mouseOver ? PaintState.Hot : PaintState.Normal); if (m_mouseOver && m_mouseDown) { newState = PaintState.HotDown; } if (newState != m_state) { m_state = newState; Invalidate(); } }
/// <summary> /// Paints the provided IOGraph onto the current GDI+ Graphics drawing surface. /// </summary> protected virtual void PaintNetwork(IOGraph graph, PaintState state) { // Create per-node state info. int hiddenNodeCount = graph.HiddenNodeList.Count; int inputNodeCount = graph.InputNodeList.Count; int outputNodeCount = graph.OutputNodeList.Count; state._nodeStateDict = new Dictionary<GraphNode,ConnectionPointInfo>(hiddenNodeCount + inputNodeCount + outputNodeCount); // Paint all connections. We do this first and paint nodes on top of the connections. This allows the // slightly messy ends of the connections to be painted over by the nodes. PaintConnections(graph.InputNodeList, state); PaintConnections(graph.HiddenNodeList, state); PaintConnections(graph.OutputNodeList, state); // Paint all nodes. Painted over the top of connection endpoints. PaintNodes(graph.InputNodeList, state); PaintNodes(graph.HiddenNodeList, state); PaintNodes(graph.OutputNodeList, state); }
/// <summary> /// Paints the provided IOGraph onto the current GDI+ Graphics drawing surface. /// </summary> protected virtual void PaintNetwork(IOGraph graph, PaintState state) { // Create per-node state info. int hiddenNodeCount = graph.HiddenNodeList.Count; int inputNodeCount = graph.InputNodeList.Count; int outputNodeCount = graph.OutputNodeList.Count; state._nodeStateDict = new Dictionary <GraphNode, ConnectionPointInfo>(hiddenNodeCount + inputNodeCount + outputNodeCount); // Paint all connections. We do this first and paint nodes on top of the connections. This allows the // slightly messy ends of the connections to be painted over by the nodes. PaintConnections(graph.InputNodeList, state); PaintConnections(graph.HiddenNodeList, state); PaintConnections(graph.OutputNodeList, state); // Paint all nodes. Painted over the top of connection endpoints. PaintNodes(graph.InputNodeList, state); PaintNodes(graph.HiddenNodeList, state); PaintNodes(graph.OutputNodeList, state); }
private void PaintConnection(GraphConnection con, PaintState state) { Point srcPos = ModelToViewport(con.SourceNode.Position, state); Point tgtPos = ModelToViewport(con.TargetNode.Position, state); // Connections leave from the base of the source node and enter the top of the target node. // Adjust end points to make them neatly terminate just underneath the edge of the endpoint nodes. srcPos.Y += (int)(state._nodeDiameterHalf * 0.9f); tgtPos.Y -= (int)(state._nodeDiameterHalf * 0.9f); // Is any part of the connection within the viewport area? if (!IsPointWithinViewport(srcPos, state) && !IsPointWithinViewport(tgtPos, state)) { // Skip connection. It's outside the viewport area. return; } // Create a pen for painting the connection. // Width is related to connection strength/magnitude. float width = (float)(con.Weight < 0.0 ? -Math.Log10(1.0 - con.Weight) : Math.Log10(1.0 + con.Weight)); width = width * state._connectionWeightToWidth * state._zoomFactor; width = Math.Max(1f, Math.Abs(width)); Pen pen = new Pen(con.Weight < 0f ? _connectionNegative : _connectionPositive, width); // Draw the connection line. if (tgtPos.Y > srcPos.Y) { // Target is below the source. Draw a straight line. state._g.DrawLine(pen, srcPos, tgtPos); } else { // Target is above source. Draw a back-connection. PaintBackConnection(pen, srcPos, tgtPos, state.GetNodeStateInfo(con.SourceNode), state.GetNodeStateInfo(con.TargetNode), state); } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Paints the background of the OK and Reset buttons. /// </summary> /// ------------------------------------------------------------------------------------ private bool HandleButtonDrawBackground(XButton btn, PaintEventArgs e, PaintState state) { if (state == PaintState.Hot || state == PaintState.HotDown) { return(false); } var rc = btn.ClientRectangle; Color clr = ColorHelper.CalculateColor(Color.White, BackColor, 100); using (SolidBrush br = new SolidBrush(clr)) e.Graphics.FillRectangle(br, rc); rc.Width--; rc.Height--; clr = ColorHelper.CalculateColor(Color.Black, BackColor, 70); using (Pen pen = new Pen(clr)) e.Graphics.DrawRectangle(pen, rc); //btn.DrawText(e); return(true); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Draws a background in the specified rectangle that looks like a toolbar button /// when the mouse is over it, with consideration for whether the look should be like /// the mouse is down or not. Note, when a PaintState of normal is specified, this /// method does nothing. Normal background painting is up to the caller. /// </summary> /// ------------------------------------------------------------------------------------ public static void DrawHotBackground(Graphics g, Rectangle rc, PaintState state) { // The caller has to handle painting when the state is normal. if (state == PaintState.Normal) return; var hotDown = (state == PaintState.HotDown); var clr1 = (hotDown ? ProfessionalColors.ButtonPressedGradientBegin : ProfessionalColors.ButtonSelectedGradientBegin); var clr2 = (hotDown ? ProfessionalColors.ButtonPressedGradientEnd : ProfessionalColors.ButtonSelectedGradientEnd); using (var br = new LinearGradientBrush(rc, clr1, clr2, 90)) g.FillRectangle(br, rc); var clrBrdr = (hotDown ? ProfessionalColors.ButtonPressedHighlightBorder : ProfessionalColors.ButtonSelectedHighlightBorder); ControlPaint.DrawBorder(g, rc, clrBrdr, ButtonBorderStyle.Solid); //// Determine the highlight color. //Color clrHot = (CanPaintVisualStyle() ? // VisualStyleInformation.ControlHighlightHot : SystemColors.MenuHighlight); //int alpha = (CanPaintVisualStyle() ? 95 : 120); //// Determine the angle and one of the colors for the gradient highlight. When state is //// hot down, the gradiant goes from bottom (lighter) to top (darker). When the state //// is just hot, the gradient is from top (lighter) to bottom (darker). //float angle = (state == PaintState.HotDown ? 270 : 90); //Color clr2 = ColorHelper.CalculateColor(Color.White, clrHot, alpha); //// Draw the label's background. //if (state == PaintState.Hot) //{ // using (LinearGradientBrush br = new LinearGradientBrush(rc, Color.White, clr2, angle)) // g.FillRectangle(br, rc); //} //else //{ // using (LinearGradientBrush br = new LinearGradientBrush(rc, clr2, clrHot, angle)) // g.FillRectangle(br, rc); //} //// Draw a black border around the label. //ControlPaint.DrawBorder(g, rc, Color.Black, ButtonBorderStyle.Solid); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Draws a background in the specified rectangle that looks like a toolbar button /// when the mouse is over it, with consideration for whether the look should be like /// the mouse is down or not. Note, when a PaintState of normal is specified, this /// method does nothing. Normal background painting is up to the caller. /// </summary> /// ------------------------------------------------------------------------------------ public static void DrawHotBackground(Graphics g, Rectangle rc, PaintState state) { // The caller has to handle painting when the state is normal. if (state == PaintState.Normal) return; // Determine the highlight color. // TODO-Linux: VisualStyleInformation.ControlHighlightHot has a MonoTODO. Color clrHot = (Application.RenderWithVisualStyles ? VisualStyleInformation.ControlHighlightHot : SystemColors.MenuHighlight); int alpha = (Application.RenderWithVisualStyles ? 95 : 120); // Determine the angle and one of the colors for the gradient highlight. When state is // hot down, the gradiant goes from bottom (lighter) to top (darker). When the state // is just hot, the gradient is from top (lighter) to bottom (darker). float angle = (state == PaintState.HotDown ? 270 : 90); Color clr2 = ColorHelper.CalculateColor(Color.White, clrHot, alpha); // Draw the label's background. if (state == PaintState.Hot) { using (LinearGradientBrush br = new LinearGradientBrush(rc, Color.White, clr2, angle)) g.FillRectangle(br, rc); } else { using (LinearGradientBrush br = new LinearGradientBrush(rc, clr2, clrHot, angle)) g.FillRectangle(br, rc); } // Draw a black border around the label. ControlPaint.DrawBorder(g, rc, Color.Black, ButtonBorderStyle.Solid); }
/// ------------------------------------------------------------------------------------ /// <summary> /// /// </summary> /// <param name="state"></param> /// <returns></returns> /// ------------------------------------------------------------------------------------ protected Color GetBackColorShade(PaintState state) { return(GetBackColorShade(state, SystemColors.Control)); }
public override void Draw(PaintEventArgs e, PaintState paintstate) { MyDrawLine(e, GetForgroundPen(paintstate), DrawStart, DrawEnd); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Track when the mouse leaves the control when a mouse button is pressed. /// </summary> /// ------------------------------------------------------------------------------------ protected override void OnMouseMove(MouseEventArgs e) { base.OnMouseMove(e); m_mouseOver = ClientRectangle.Contains(e.Location); PaintState newState = (m_mouseOver ? PaintState.Hot : PaintState.Normal); if (m_mouseOver && m_mouseDown) newState = PaintState.HotDown; if (newState != m_state) { m_state = newState; Invalidate(); } }
public Pen GetForgroundPen(PaintState paintstate) { if (paintstate.SelectedIdx == paintstate.ShapeIdx) return new Pen(Color.Red,5); return new Pen(ForgroundColor, paintstate.SelectedIdx > paintstate.ShapeIdx ? 2 : 1); }
private void paintWallsToolStripMenuItem_Click(object sender, EventArgs e) { if (paintWallsToolStripMenuItem.Checked) { paintWallsToolStripMenuItem.Checked = false; paintFloorsToolStripMenuItem.Checked = false; painting = PaintState.None; } else { paintWallsToolStripMenuItem.Checked = true; paintFloorsToolStripMenuItem.Checked = false; painting = PaintState.Wall; } }
public void BrushTouched() { paintState = PaintState.Brush; brush_hi.SetActive(true); eraser_hi.SetActive(false); }
private void PaintConnections(IList<GraphNode> nodeList, PaintState state) { int nodeCount = nodeList.Count; for(int i=0; i<nodeCount; i++) { List<GraphConnection> conList = nodeList[i].OutConnectionList; int conCount = conList.Count; for(int j=0; j<conCount; j++) { PaintConnection(conList[j], state); } } }
public abstract void Draw(PaintEventArgs e, PaintState paintstate);
private void PaintLegend(PaintState state) { const int LineHeight = 16; const int Margin = 10; IList<ActivationFunctionInfo> fnList = _activationFnLibrary.GetFunctionList(); int count = fnList.Count; // Determine y position of first line. int yCurr = Math.Max(Margin, state._viewportArea.Height - ((count * LineHeight) + Margin)); for(int i=0; i<count; i++, yCurr += LineHeight) { ActivationFunctionInfo fnInfo = fnList[i]; const int X = Margin; // Paint an example node as part of the legend item. Point p = new Point(X, yCurr); Size s = new Size(state._nodeDiameter, state._nodeDiameter); Rectangle r = new Rectangle(p, s); // Paint the node. Fill first and then border, this gives a clean border. Graphics g = state._g; Brush fillBrush = _brushNodeFillArr[fnInfo.Id % _brushNodeFillArr.Length]; g.FillRectangle(fillBrush, r); g.DrawRectangle(__penBlack, r); // Write the activation function string ID. g.DrawString(fnList[i].ActivationFunction.FunctionId, __fontNodeTag, __brushBlack, X+12, yCurr-1); } }
/// <summary> /// Converts from a model coordinate to a viewport coordinate. /// </summary> protected Point ModelToViewport(Point p, PaintState state) { p.X = (int)((float)p.X * state._zoomFactor) - state._viewportArea.X; p.Y = (int)((float)p.Y * state._zoomFactor) - state._viewportArea.Y; return p; }
/// ------------------------------------------------------------------------------------ /// <summary> /// /// </summary> /// ------------------------------------------------------------------------------------ protected override void OnPaintBackground(PaintEventArgs e) { base.OnPaintBackground(e); if (m_mouseOver || Checked) m_state = (m_mouseDown ? PaintState.HotDown : PaintState.Hot); else m_state = PaintState.Normal; Rectangle rc = ClientRectangle; using (SolidBrush br = new SolidBrush(BackColor)) e.Graphics.FillRectangle(br, rc); if (m_state != PaintState.Normal) PaintingHelper.DrawHotBackground(e.Graphics, rc, m_state); }
public IDisposable ApplyTo(SKPaint paint) { var state = new PaintState(paint, paint.Color, paint.Shader); paint.Color = Paint.Color; paint.Shader = Paint.Shader; return state; }
private void PaintBackConnection(Pen pen, Point srcPos, Point tgtPos, ConnectionPointInfo srcInfo, ConnectionPointInfo tgtInfo, PaintState state) { const float SlopeInit = 0.25f; const float SlopeIncr = 0.23f; // This is the maximum slope value we get before exceeding the slope threshold of 1. float slopeMax = SlopeInit + (SlopeIncr * (float)Math.Floor((1f-SlopeInit) / SlopeIncr)); // Back connection is described by the line ABCDEF. A = srcPos and F = tgtPos. int srcConIdx, tgtConIdx; int srcSide, tgtSide; // If the source and target nodes are close on the X-axis then connect to the same side on both // nodes. Otherwise connect nodes on their facing sides. if(Math.Abs(tgtPos.X - srcPos.X) <= NodeDiameterModel) { srcConIdx = srcInfo._lowerLeft++; tgtConIdx = tgtInfo._upperLeft++; srcSide = -1; tgtSide = -1; } else if(tgtPos.X > srcPos.X) { srcConIdx = srcInfo._lowerRight++; tgtConIdx = tgtInfo._upperLeft++; srcSide = 1; tgtSide = -1; } else { srcConIdx = srcInfo._lowerLeft++; tgtConIdx = tgtInfo._upperRight++; srcSide = -1; tgtSide = 1; } //--- Point B. // The line AB is a connection leg emerging from the base of a node. To visually seperate multiple legs // the first leg has a gentle gradient (almost horizontal) and each successive leg has a steeper gradient. // Once a vertical gradient has been reached each sucessive leg is made longer. // Calculate leg slope: 0=horizontal, 1=vertical. Hence this is value is not a gradient. // Slope pre-trimming back to maximum of 1.0. float slopePre = SlopeInit + (SlopeIncr * srcConIdx); // Leg length. float lenAB = state._backConnectionLegLength; float slope = slopePre; if(slope > slopeMax) { // Increase length in fractions of _backConnectionLegLength. lenAB += (slopePre-slopeMax) * state._backConnectionLegLength; slope = 1f; } // Calculate position of B as relative to A. // Note. Length is taken to be L1 length (Manhatten distance). This means that the successive B positions // describe a straight line (rather than the circle you get with L2/Euclidean distance) which in turn // ensures that the BC segments of successive connections are evenly spaced out. int xDelta = (int)(lenAB * (1f - slope)) * srcSide; int yDelta = (int)(lenAB * slope); Point b = new Point(srcPos.X + xDelta, srcPos.Y + yDelta); //--- Point C. // Line BC is a horizontal line from the end of the leg AB. int lenBC = (int)(2f * slopePre * state._backConnectionLegLength); xDelta = lenBC * srcSide; Point c = new Point(b.X + xDelta, b.Y); //--- Point E. Equivalent to point B but emerging from the target node. slopePre = SlopeInit + (SlopeIncr * tgtConIdx); // Leg length. float lenEF = state._backConnectionLegLength; slope = slopePre; if(slope > slopeMax) { // Increase length in fractions of _backConnectionLegLength. lenEF += (slopePre-slopeMax) * state._backConnectionLegLength; slope = 1f; } xDelta = (int)(lenEF * (1f - slope)) * tgtSide; yDelta = -(int)(lenEF * slope); Point e = new Point(tgtPos.X + xDelta, tgtPos.Y + yDelta); //--- Point D. Equivalent to point C but on the target end of the connection. int lenDE = (int)(2f * slopePre * state._backConnectionLegLength); xDelta = lenDE * tgtSide; Point d = new Point(e.X + xDelta, e.Y); state._g.DrawLines(pen, new Point[]{srcPos,b,c,d,e,tgtPos}); }
/// ------------------------------------------------------------------------------------ /// <summary> /// /// </summary> /// <param name="state"></param> /// <returns></returns> /// ------------------------------------------------------------------------------------ protected Color GetBackColorShade(PaintState state) { return GetBackColorShade(state, SystemColors.Control); }
private void PaintConnection(GraphConnection con, PaintState state) { Point srcPos = ModelToViewport(con.SourceNode.Position, state); Point tgtPos = ModelToViewport(con.TargetNode.Position, state); // Connections leave from the base of the source node and enter the top of the target node. // Adjust end points to make them neatly terminate just underneath the edge of the endpoint nodes. srcPos.Y += (int)(state._nodeDiameterHalf * 0.9f); tgtPos.Y -= (int)(state._nodeDiameterHalf * 0.9f); // Is any part of the connection within the viewport area? if(!IsPointWithinViewport(srcPos, state) && !IsPointWithinViewport(tgtPos, state)) { // Skip connection. It's outside the viewport area. return; } // Create a pen for painting the connection. // Width is related to connection strength/magnitude. float width = (float)(con.Weight < 0.0 ? -Math.Log10(1.0 - con.Weight) : Math.Log10(1.0 + con.Weight)); width = width * state._connectionWeightToWidth * state._zoomFactor; width = Math.Max(1f, Math.Abs(width)); Pen pen = new Pen(con.Weight < 0f ? _connectionNegative : _connectionPositive, width); // Draw the connection line. if(tgtPos.Y > srcPos.Y) { // Target is below the source. Draw a straight line. state._g.DrawLine(pen, srcPos, tgtPos); } else { // Target is above source. Draw a back-connection. PaintBackConnection(pen, srcPos, tgtPos, state.GetNodeStateInfo(con.SourceNode), state.GetNodeStateInfo(con.TargetNode), state); } }
public override void Draw(PaintEventArgs e, PaintState paintstate) { e.Graphics.DrawRectangle(GetForgroundPen(paintstate), NormalizedRect); }
/// <summary> /// Paint method /// </summary> protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); if (Jumps == null) { return; } uint indexFrom = uint.MaxValue; uint indexTo = uint.MaxValue; indexFrom = (uint)_Grid.FirstDisplayedCell.RowIndex; indexTo = indexFrom + (uint)_Grid.DisplayedRowCount(true); List <PaintState> ls = new List <PaintState>(); foreach (Instruction i in Jumps) { if (i.Jump.To == null || i.Jump.To.Index == i.Location.Index) { continue; } if (!i.Jump.To.IndexBetween(indexFrom, indexTo) && !i.Location.IndexBetween(indexFrom, indexTo)) { continue; } PaintState p = new PaintState() { IndexFrom = i.Location.Index, IndexTo = i.Jump.To.Index, Style = i.Jump.Style, RectFrom = _Grid.GetRowDisplayRectangle((int)i.Location.Index, false), RectTo = _Grid.GetRowDisplayRectangle((int)i.Jump.To.Index, false) }; if (p.RectFrom.IsEmpty && p.RectTo.IsEmpty) { continue; } ls.Add(p); if (ls.Count == MaxDrawJump) { break; } } if (ls.Count <= 0) { return; } int x = 5; int step = Math.Max((Width - x - ArrowWidth) / ls.Count, 1); foreach (PaintState p in ls.OrderBy(u => u.Distance)) { PainJump(e.Graphics, p, x); x += step; } }
public Home(int doors, int windows) { this.doors = doors; this.windows = windows; state = PaintState.Unpainted; }
public void PaintHome() { state = PaintState.Painted; }
/// <summary> /// Paint jump /// </summary> /// <param name="gp">Graphics</param> /// <param name="pt">Paint</param> /// <param name="s">Separation</param> void PainJump(Graphics gp, PaintState pt, int x) { Rectangle rFrom = pt.RectFrom; Rectangle rTo = pt.RectTo; if (rTo.IsEmpty && rFrom.IsEmpty) { return; } bool current = CurrentInstructionIndex == pt.IndexFrom; using (Pen p = new Pen(current ? Color.Green : Color.Black, current ? 2F : 1F)) { p.DashStyle = pt.Style; if (!rTo.IsEmpty) { gp.DrawLine(p, x, rTo.Y + (rTo.Height / 2), Width, rTo.Y + (rTo.Height / 2)); DrawArrow(gp, current ? Brushes.Green : Brushes.Black, Width, rTo.Y + (rTo.Height / 2), false); if (rFrom.IsEmpty) { // Not To if (pt.IndexFrom < pt.IndexTo) { // To up gp.DrawLine(p, x, rTo.Y + (rTo.Height / 2), x, 0); } else { // To down gp.DrawLine(p, x, rTo.Y + (rTo.Height / 2), x, Height); } } } if (!rFrom.IsEmpty) { gp.DrawLine(p, x, rFrom.Y + (rFrom.Height / 2), Width, rFrom.Y + (rFrom.Height / 2)); DrawArrow(gp, current ? Brushes.Green : Brushes.Black, Width, rFrom.Y + (rFrom.Height / 2), true); if (rTo.IsEmpty) { // Not To if (pt.IndexFrom > pt.IndexTo) { // To up gp.DrawLine(p, x, rFrom.Y + (rFrom.Height / 2), x, 0); } else { // To down gp.DrawLine(p, x, rFrom.Y + (rFrom.Height / 2), x, Height); } } else { // From and to gp.DrawLine(p, x, rFrom.Y + (rFrom.Height / 2), x, rTo.Y + (rTo.Height / 2)); } } } }