예제 #1
0
 protected override void OnMouseMove(MouseEventArgs e)
 {
     if (CanBeControlled)
     {
         if (MouseButtons.HasFlag(MouseButtons.Left))
         {
             int           x      = lastLocalMousePosition.X - LocalMousePosition.X;
             int           y      = lastLocalMousePosition.Y - LocalMousePosition.Y;
             Model.Vector2 offset = FieldRenderer.ScreenToOffset(new Point(x, y), Size);
             FieldRenderer.MoveCamera(offset);
         }
         lastLocalMousePosition = LocalMousePosition;
     }
 }
예제 #2
0
        public void DrawTexture(Texture2D texture, Model.Vector2 a, Model.Vector2 b, Model.Vector2 c, Model.Vector2 d, Color color)
        {
            GL.Color3(color);
            GL.BindTexture(TextureTarget.Texture2D, texture.ID);
            GL.Enable(EnableCap.Texture2D);
            GL.Enable(EnableCap.Blend);
            GL.Begin(PrimitiveType.Quads);

            GL.TexCoord2(0, 0);
            GL.Vertex2(ToGL(a));
            GL.TexCoord2(1, 0);
            GL.Vertex2(ToGL(b));
            GL.TexCoord2(1, 1);
            GL.Vertex2(ToGL(c));
            GL.TexCoord2(0, 1);
            GL.Vertex2(ToGL(d));

            GL.End();
            GL.Disable(EnableCap.Texture2D);
        }
예제 #3
0
        public void updateGraph()
        {
            double maxSeconds = 0;
            double aggregateTimeSeriesMin = double.MaxValue;
            double aggregateTimeSeriesMax = double.MinValue;
            minTimeInterval = 1.0;

            if (listOfTimeSeries.SelectedItems.Count > 0)
            {
                // calculate the maxima for all the visible time series, so the graph will be drawn
                // at the size of the largest one.
                foreach (TimeSeries timeSeries in listOfTimeSeries.SelectedItems)
                {
                    if ((timeSeries.Series.Count - 1) * timeSeries.Parameters.TimeInterval > maxSeconds)
                        maxSeconds = (timeSeries.Series.Count - 1) * timeSeries.Parameters.TimeInterval;

                    if (timeSeries.MaxValue > aggregateTimeSeriesMax)
                        aggregateTimeSeriesMax = timeSeries.MaxValue;

                    if (timeSeries.MinValue < aggregateTimeSeriesMin)
                        aggregateTimeSeriesMin = timeSeries.MinValue;

                    if (timeSeries.Parameters.TimeInterval < minTimeInterval)
                        minTimeInterval = timeSeries.Parameters.TimeInterval;
                }
                // stop divide by zero errors by having some height if all values are the same
                if (aggregateTimeSeriesMax == aggregateTimeSeriesMin)
                {
                    aggregateTimeSeriesMin -= 0.005;
                    aggregateTimeSeriesMax += 0.005;
                }

                // this is the visible drawing area, based on the size of the picture box
                graphAxes = new System.Drawing.Rectangle(70, 10, picGraphBox.Width - 80, picGraphBox.Height - 30);

                if (maxSeconds > 0)
                {
                    // constrain scroll to be less than (maxSeconds - (maxSeconds / zoom))
                    // because maxSeconds / zoom is the width of the view on screen
                    // and you can't scroll further to the right than this.
                    double maxScroll = maxSeconds - (maxSeconds / zoom);

                    // scroll bar changes by one per scroll, so scroll should change by minTimeInterval
                    // and maximum should be maxScroll / minTimeInterval

                    graphScrollBar.Maximum = (int)Math.Floor(maxScroll / minTimeInterval) + graphScrollBar.LargeChange;
                    if (scroll > maxScroll)
                    {
                        //scroll = (float)Math.Floor((maxSeconds - (maxSeconds / zoom)) / minTimeInterval) * (float)minTimeInterval;
                        scroll = (float)maxScroll;
                        graphScrollBar.Value = (int)(scroll / minTimeInterval);
                    }

                    graphLocalArea = new MuCell.Model.Rectangle(
                        scroll, aggregateTimeSeriesMin,
                        (maxSeconds / zoom), aggregateTimeSeriesMax - aggregateTimeSeriesMin);
                    pixelScale = new MuCell.Model.Vector2((float)(graphAxes.Width / graphLocalArea.Width), (float)(graphAxes.Height / graphLocalArea.Height));

                    // change the gridline interval so there aren't too many or too few on the graph
                    gridInterval = new MuCell.Model.Vector2(1.0f, 1.0f);

                    gridInterval.x = (float)Math.Pow(10, Math.Floor(Math.Log10(graphLocalArea.Width)));
                    if (graphLocalArea.Width < gridInterval.x * 5)
                    {
                        if (graphLocalArea.Width < gridInterval.x * 1.5)
                        {
                            gridInterval.x /= 4f;
                        }
                        else
                        {
                            gridInterval.x /= 2f;
                        }
                    }

                    gridInterval.y = (float)Math.Pow(10, Math.Floor(Math.Log10(graphLocalArea.Height)));
                    if (graphLocalArea.Height < gridInterval.y * 5)
                    {
                        if (graphLocalArea.Height < gridInterval.y * 1.5)
                        {
                            gridInterval.y /= 4f;
                        }
                        else
                        {
                            gridInterval.y /= 2f;
                        }
                    }

                    labelInterval = new MuCell.Model.Vector2(gridInterval.x, gridInterval.y);
                }
                else
                {
                    graphLocalArea = new MuCell.Model.Rectangle(0, 0, 0, 0);
                }
            }
            picGraphBox.Refresh();
        }