private void PaintStates(object sender, PaintEventArgs e)
        {
            AutomataUI fw = sender as AutomataUI; // connect to encapsulating class GUIAutomataUINode aka main.cs

            if (fw.stateList.Count != 0)
            {
                foreach (State state in fw.stateList) // Loop through List with foreach.
                {
                    string stateName = state.Name;
                    if (state.Frames > 0)
                    {
                        stateName += " [" + Convert.ToString(state.Frames) + "]";
                    }


                    if (state.ID == "Init")
                    {
                        e.Graphics.FillEllipse(InitBrush, state.Bounds);                                //circle
                        e.Graphics.DrawString(stateName, myfont, transBackColor, state.Bounds, format); //text
                    }
                    else
                    {
                        e.Graphics.FillEllipse(StateBrush, state.Bounds);                           //circle
                        e.Graphics.DrawString(stateName, myfont, whiteBrush, state.Bounds, format); //text
                    }
                }
            }
        }
        private void PaintSpreadButtons(object sender, PaintEventArgs e)
        {
            AutomataUI   fw           = sender as AutomataUI;
            StringFormat stringFormat = new StringFormat();

            stringFormat.Alignment     = StringAlignment.Center;
            stringFormat.LineAlignment = StringAlignment.Center;
            int size = Convert.ToInt16(20 * dpi);
            int posx = Convert.ToInt16(23 * dpi);
            int posy = Convert.ToInt16(30 * dpi);

            if (fw.ActiveStateIndex.SliceCount > 1)
            {
                Spreadbuttons.Clear();
                for (int i = 0; i < fw.ActiveStateIndex.SliceCount; i++)
                {
                    Spreadbuttons.Add(new Rectangle(new Point(i * posx + 10, posy), new Size(size, size)));
                    if (i == fw.ShowSlice[0])
                    {
                        e.Graphics.FillRectangle(OrangeBrush, Spreadbuttons.Last());
                    }
                    else
                    {
                        e.Graphics.FillRectangle(InitBrush, Spreadbuttons.Last());
                    }
                    e.Graphics.DrawString(Convert.ToString(i), myfont, StateBrush, Spreadbuttons.Last(), stringFormat); //text
                }
            }
        }
        private void PaintBezierHandles(object sender, PaintEventArgs e, Transition transition)
        {
            AutomataUI fw    = sender as AutomataUI; // connect to encapsulating class GUIAutomataUINode aka main.cs
            double     angle = 0.0;

            foreach (Transition subtransition in fw.transitionList) // check if there is a return transition to draw double connections correctly
            {
                if (subtransition.startState.ID == transition.endState.ID && subtransition.endState.ID == transition.startState.ID)
                {
                    angle = 0.4;
                    break;
                }
                else
                {
                    angle = 0.0;
                }
            }


            Lines.EdgePoints myEdgePoints = Lines.GetEdgePoints(State.Center(transition.startState.Bounds), State.Center(transition.endState.Bounds), 40, 40, angle); //draw line from state to state

            bezierEdit.bezierStart = new Rectangle(new Point(myEdgePoints.A.X - 5 + transition.startBezierPoint.X, myEdgePoints.A.Y - 5 + transition.startBezierPoint.Y), new Size(10, 10));
            bezierEdit.bezierEnd   = new Rectangle(new Point(myEdgePoints.B.X - 5 + transition.endBezierPoint.X, myEdgePoints.B.Y - 5 + transition.endBezierPoint.Y), new Size(10, 10));


            e.Graphics.DrawLine(GrayPen, myEdgePoints.A, AddTwoPoints(bezierEdit.bezierStart.Location, new Point(5, 5)));
            e.Graphics.DrawLine(GrayPen, myEdgePoints.B, AddTwoPoints(bezierEdit.bezierEnd.Location, new Point(5, 5)));

            e.Graphics.FillEllipse(OrangeBrush, bezierEdit.bezierStart);
            e.Graphics.FillEllipse(OrangeBrush, bezierEdit.bezierEnd);
        }
Beispiel #4
0
        private void PaintRegions(object sender, PaintEventArgs e)
        {
            AutomataUI fw = sender as AutomataUI;

            if (fw.regionList.Count != 0)
            {
                foreach (AutomataRegion region in fw.regionList) // Loop through List with foreach.
                {
                    string regionName = region.Name;
                    e.Graphics.FillRectangle(selectbrush, region.Bounds);

                    Point[] points =
                    {
                        new Point(region.SizeHandle.X,                           region.SizeHandle.Y + region.SizeHandle.Height),
                        new Point(region.SizeHandle.X + region.SizeHandle.Width, region.SizeHandle.Y),
                        new Point(region.SizeHandle.X + region.SizeHandle.Width, region.SizeHandle.Y + region.SizeHandle.Height)
                    };
                    e.Graphics.FillPolygon(whiteBrush, points);

                    SizeF stringSize = new SizeF();
                    stringSize = e.Graphics.MeasureString(regionName, largefont, 1000);
                    Rectangle textbounds = new Rectangle(region.Bounds.Location, new Size((int)stringSize.Width + 10, (int)stringSize.Height + 10));

                    e.Graphics.DrawString(regionName, largefont, whiteBrush, textbounds, format); //text
                }
            }
        }
Beispiel #5
0
        public void PaintAutomata(object sender, PaintEventArgs e)
        {
            AutomataUI fw = sender as AutomataUI; // connect to encapsulating class GUIAutomataUINode aka main.cs

            dpi = e.Graphics.DpiX / 96;           // get scaling of windows
            int fontsize = Convert.ToInt16(8 / dpi);

            myfont = new Font("Serif", fontsize, FontStyle.Regular);

            try
            {
                if (fw.stateList.Count > 0)
                {
                    e.Graphics.TranslateTransform(StagePos.X, StagePos.Y);            //Move stage
                    e.Graphics.ScaleTransform(dpi, dpi);                              //dpi scaling
                    e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;               // shapeman
                    e.Graphics.Clear(MyBackgroundColor);
                    e.Graphics.FillEllipse(StateBrush, fw.x - 10, fw.y - 10, 20, 20); // draw mouse

                    PaintRegions(sender, e);

                    PaintTransitions(sender, e);    //draw transitions

                    PaintEditTransition(sender, e); //draw add connection

                    if (fw.stateList.Count > 1)
                    {
                        PaintStateHighlight(sender, e, fw.TargetStateIndex[fw.ShowSlice[0]], new Pen(MyDarkCyan, 10.0f));        //draw target state highlight
                        PaintStateHighlight(sender, e, fw.ActiveStateIndex[fw.ShowSlice[0]], new Pen(MyColorDarkOrange, 10.0f)); //draw active state highlight
                    }

                    PaintSelectionRect(e);

                    PaintStates(sender, e); //draw states

                    if (bezierEdit.HighlightTransitionIndex != null)
                    {
                        PaintBezierHandles(sender, e, bezierEdit.highlightTransition);                                                //draw bezierhandles
                    }
                    e.Graphics.ScaleTransform(1 / dpi, 1 / dpi);                                                                      //invert dpi scaling
                    e.Graphics.TranslateTransform(0 - StagePos.X, 0 - StagePos.Y);                                                    //invert move stage
                    myfont = new Font("Serif", 8, FontStyle.Regular);
                    e.Graphics.DrawString(fw.licenseOwner, myfont, whiteBrush, new Rectangle(new Point(10, 10), new Size(400, 100))); //text

                    PaintSpreadButtons(sender, e);                                                                                    //Paint Buttons to select which spread of Automata u want
                }
            }
            catch (NullReferenceException exc)
            {
                var st    = new StackTrace(exc, true);
                var frame = st.GetFrame(0);
                var line  = frame.GetFileLineNumber();
                debug = "F**K: " + exc.TargetSite + " caused an exception on line: " + line;
            }
        }
        private void PaintStateHighlight(object sender, PaintEventArgs e, int index, Pen penColor)
        {
            AutomataUI fw = sender as AutomataUI; // connect to encapsulating class GUIAutomataUINode aka main.cs

            if (fw.stateList.Count > 1)
            {
                var item = fw.stateList.ElementAt(index);
                e.Graphics.DrawEllipse(
                    penColor,
                    item.Bounds.X,
                    item.Bounds.Y,
                    StateSize, StateSize); // active state ring
            }
        }
        public void JoregMode(object sender, bool JMode)
        {
            AutomataUI fw = sender as AutomataUI; // connect to encapsulating class GUIAutomataUINode aka main.cs

            if (JMode)
            {
                MyBackgroundColor = Color.FromArgb(230, 230, 230);
                transBackColor    = new SolidBrush(MyBackgroundColor);
                whiteBrush        = new SolidBrush(Color.FromArgb(0, 0, 0));
                StateBrush        = new SolidBrush(Color.FromArgb(205, 205, 205));
                MyColorDarkOrange = Color.FromArgb(154, 154, 154);
                InitBrush         = new SolidBrush(Color.FromArgb(102, 102, 102));

                RedPen    = new Pen(Color.FromArgb(102, 102, 102), 1.5f);
                AzurePen  = new Pen(Color.FromArgb(154, 154, 154), 1.5f);
                OrangePen = new Pen(Color.FromArgb(102, 102, 102), 2.0f);

                RedPen.CustomEndCap    = bigArrow;
                AzurePen.CustomEndCap  = bigArrow;
                OrangePen.CustomEndCap = bigArrow;

                MyDarkCyan = Color.FromArgb(50, 50, 50);
                fw.Invalidate(); //redraw
            }
            else
            {
                MyBackgroundColor = Color.FromArgb(20, 20, 20);
                transBackColor    = new SolidBrush(MyBackgroundColor);
                whiteBrush        = new SolidBrush(Color.FromArgb(190, 190, 190));
                StateBrush        = new SolidBrush(Color.FromArgb(50, 50, 50));
                MyColorDarkOrange = Color.DarkOrange;
                InitBrush         = new SolidBrush(Color.FromArgb(0, 255, 234));

                RedPen    = new Pen(Color.Red, 1.5f);
                AzurePen  = new Pen(Color.Aqua, 1.5f);
                OrangePen = new Pen(Color.DarkOrange, 2.0f);


                RedPen.CustomEndCap    = bigArrow;
                AzurePen.CustomEndCap  = bigArrow;
                OrangePen.CustomEndCap = bigArrow;

                MyDarkCyan = Color.DarkCyan;
                fw.Invalidate();
            }
        }
        private void PaintEditTransition(object sender, PaintEventArgs e)
        {
            AutomataUI fw = sender as AutomataUI; // connect to encapsulating class GUIAutomataUINode aka main.cs

            if (fw.startConnectionState != null)
            {
                Lines.EdgePoints myEdgePoints = new Lines.EdgePoints();

                if (fw.targetConnectionState != null)                                                                                                             // is transition between state and state
                {
                    myEdgePoints = Lines.GetEdgePoints(State.Center(fw.startConnectionState.Bounds), State.Center(fw.targetConnectionState.Bounds), 40, 40, 0.0); //draw line from state to state
                }
                else // is transition between state and mouse
                {
                    myEdgePoints = Lines.GetEdgePoints(State.Center(fw.startConnectionState.Bounds), new Point(fw.x, fw.y), 40, 10, 0.0); // get edge points for mouse
                }
                e.Graphics.DrawLine(RedPen, myEdgePoints.A, myEdgePoints.B);                                                              //drawline
            }
        }
        // Methoden //
        private void PaintTransitions(object sender, PaintEventArgs e)
        {
            AutomataUI fw = sender as AutomataUI; // connect to encapsulating class GUIAutomataUINode aka main.cs

            double winkel = 0.0;

            greenPen.Alignment = PenAlignment.Center;

            transitionPaths.Clear();

            int i = 0;

            #region lines

            foreach (Transition transition in fw.transitionList) // draw lines
            {
                if (transition.IsPingPong)
                {
                    AzurePen.CustomStartCap  = bigArrow;
                    OrangePen.CustomStartCap = bigArrow;
                    AzurePen.DashStyle       = DashStyle.Dot;
                }
                else
                {
                    AzurePen.CustomStartCap  = noArrow;
                    OrangePen.CustomStartCap = noArrow;
                    AzurePen.DashStyle       = DashStyle.Solid;
                }

                foreach (Transition subtransition in fw.transitionList) // check if there is a return transition to draw double connections correctly
                {
                    if (subtransition.startState.ID == transition.endState.ID && subtransition.endState.ID == transition.startState.ID)
                    {
                        winkel = 0.4;
                        break;
                    }
                    else
                    {
                        winkel = 0.0;
                    }
                }

                // getting start and endpoint for transition lines
                Lines.EdgePoints myEdgePoints = Lines.GetEdgePoints(State.Center(transition.startState.Bounds), State.Center(transition.endState.Bounds), 40, 40, winkel);

                #region bezierstuff
                //empty path object
                bezierEdit.path = new GraphicsPath();

                //create path with edge positions
                bezierEdit.path.AddBezier(myEdgePoints.A, AddTwoPoints(myEdgePoints.A, transition.startBezierPoint), AddTwoPoints(myEdgePoints.B, transition.endBezierPoint), myEdgePoints.B);

                if (transition == bezierEdit.highlightTransition)
                {
                    e.Graphics.DrawPath(RedPen, bezierEdit.path);                                               // draw red editable bezier
                }
                else if (i == fw.TransitionIndex[fw.ShowSlice[0]] && fw.TransitionFramesOut[fw.ShowSlice[0]] > 0)
                {
                    e.Graphics.DrawPath(OrangePen, bezierEdit.path);                                                                                               // active transition
                }
                else
                {
                    e.Graphics.DrawPath(AzurePen, bezierEdit.path); //draw standard bezier
                }
                transitionPaths.Add(bezierEdit.path);               // create list of bezier paths for hitdetection
                i++;
                #endregion
            }
            #endregion

            #region text
            foreach (Transition transition in fw.transitionList)        // draw text
            {
                foreach (Transition subtransition in fw.transitionList) // check if there is a return transition to draw double connections correctly
                {
                    if (subtransition.startState.ID == transition.endState.ID && subtransition.endState.ID == transition.startState.ID)
                    {
                        winkel = 0.4;
                        break;
                    }
                    else
                    {
                        winkel = 0.0;
                    }
                }

                string text       = transition.Name + " [" + Convert.ToString(transition.Frames) + "]"; // create text
                SizeF  stringSize = new SizeF();
                stringSize = e.Graphics.MeasureString(text, myfont, 100);

                Lines.EdgePoints myEdgePoints = Lines.GetEdgePoints(State.Center(transition.startState.Bounds), State.Center(transition.endState.Bounds), 40, 40, winkel);

                //could be optimized and only done once
                Point center = CalculateBezierCenter(0.5, myEdgePoints.A, AddTwoPoints(myEdgePoints.A, transition.startBezierPoint), AddTwoPoints(myEdgePoints.B, transition.endBezierPoint), myEdgePoints.B);


                Rectangle Bounds = new Rectangle(
                    center,
                    new Size(Convert.ToInt32(stringSize.Width + 1),
                             Convert.ToInt32(stringSize.Height + 1)));
                Bounds.X = Bounds.X - (Bounds.Size.Width / 2);
                Bounds.Y = Bounds.Y - (Bounds.Size.Height / 2);

                e.Graphics.FillRectangle(transBackColor, Bounds);
                e.Graphics.DrawString(text, myfont, whiteBrush, Bounds, format); //text

                transition.Bounds = Bounds;                                      //set textbounds to transition
            }
            #endregion
        }