Beispiel #1
0
        protected void OnScroll(ScrollEventArgs se)
        {
            bool hasViewChanged = false;

            if (se.ScrollOrientation == ScrollOrientation.HorizontalScroll)
            {
                GDI.SCROLLINFO si = new GDI.SCROLLINFO();
                si.cbSize = System.Runtime.InteropServices.Marshal.SizeOf(typeof(GDI.SCROLLINFO));
                si.fMask  = (int)(GDI.ScrollInfoMask.SIF_TRACKPOS | GDI.ScrollInfoMask.SIF_PAGE | GDI.ScrollInfoMask.SIF_POS);
                GDI.GetScrollInfo(Handle, (int)GDI.ScrollBarDirection.SB_HORZ, ref si);

                switch (se.Type)
                {
                case ScrollEventType.LargeDecrement:
                    m_view = new RectD(m_view.Left - m_view.Width, m_view.Top, m_view.Right - m_view.Width, m_view.Bottom);
                    break;

                case ScrollEventType.LargeIncrement:
                    m_view = new RectD(m_view.Left + m_view.Width, m_view.Top, m_view.Right + m_view.Width, m_view.Bottom);
                    break;

                case ScrollEventType.SmallDecrement:
                    m_view = new RectD(m_view.Left - m_view.Width * 0.1f, m_view.Top, m_view.Right - m_view.Width * 0.1f, m_view.Bottom);
                    break;

                case ScrollEventType.SmallIncrement:
                    m_view = new RectD(m_view.Left + m_view.Width * 0.1f, m_view.Top, m_view.Right + m_view.Width * 0.1f, m_view.Bottom);
                    break;

                case ScrollEventType.ThumbTrack:
                {
                    double tp = si.nTrackPos / ScrollScale * m_physExtents.Width + m_physExtents.Left;
                    m_view = new RectD(tp, m_view.Top, tp + m_view.Width, m_view.Bottom);
                }
                break;
                }

                ClampView();
                UpdateScroll();
                Invalidate();

                hasViewChanged = true;
            }
            else if (se.ScrollOrientation == ScrollOrientation.VerticalScroll)
            {
                GDI.SCROLLINFO si = new GDI.SCROLLINFO();
                si.cbSize = System.Runtime.InteropServices.Marshal.SizeOf(typeof(GDI.SCROLLINFO));
                si.fMask  = (int)(GDI.ScrollInfoMask.SIF_TRACKPOS | GDI.ScrollInfoMask.SIF_PAGE | GDI.ScrollInfoMask.SIF_POS);
                GDI.GetScrollInfo(Handle, (int)GDI.ScrollBarDirection.SB_VERT, ref si);

                switch (se.Type)
                {
                case ScrollEventType.LargeDecrement:
                    m_view = new RectD(m_view.Left, m_view.Top - m_view.Height, m_view.Right, m_view.Bottom - m_view.Height);
                    break;

                case ScrollEventType.LargeIncrement:
                    m_view = new RectD(m_view.Left, m_view.Top + m_view.Height, m_view.Right, m_view.Bottom + m_view.Height);
                    break;

                case ScrollEventType.SmallDecrement:
                    m_view = new RectD(m_view.Left, m_view.Top - m_view.Height * 0.1f, m_view.Right, m_view.Bottom - m_view.Height * 0.1f);
                    break;

                case ScrollEventType.SmallIncrement:
                    m_view = new RectD(m_view.Left, m_view.Top + m_view.Height * 0.1f, m_view.Right, m_view.Bottom + m_view.Height * 0.1f);
                    break;

                case ScrollEventType.ThumbTrack:
                {
                    double tp = si.nTrackPos / ScrollScale * m_physExtents.Height + m_physExtents.Top;
                    m_view = new RectD(m_view.Left, tp, m_view.Right, tp + m_view.Height);
                }
                break;
                }

                ClampView();
                UpdateScroll();
                Invalidate();

                hasViewChanged = true;
            }

            if (hasViewChanged)
            {
                OnViewChanged();
            }
        }
Beispiel #2
0
        protected override void OnMouseMove(MouseEventArgs e)
        {
            bool hasViewChanged = false;

            if ((e.Button & MouseButtons.Left) != 0)
            {
                Point displacement = new Point(e.Location.X - m_panDragStart.X, e.Location.Y - m_panDragStart.Y);

                if (m_isPanPriming)
                {
                    if (displacement.X * displacement.X + displacement.Y * displacement.Y >= 25)
                    {
                        m_isPanning    = true;
                        m_isPanPriming = false;
                    }
                }

                if (m_isPanning)
                {
                    double samplesXPerPixel = m_view.Width / ClientRectangle.Width;
                    double samplesYPerPixel = m_view.Height / ClientRectangle.Height;

                    m_view = new RectD(
                        m_view.Left - samplesXPerPixel * displacement.X,
                        m_view.Top - samplesYPerPixel * displacement.Y,
                        m_view.Right - samplesXPerPixel * displacement.X,
                        m_view.Bottom - samplesYPerPixel * displacement.Y);

                    m_panDragStart = e.Location;

                    ClampView();
                    UpdateScroll();
                    Invalidate();

                    hasViewChanged = true;
                }
            }

            if ((e.Button & MouseButtons.Right) != 0)
            {
                if (m_isScaling)
                {
                    double sxCurrent = SampleXFromClientX(m_scaleDragOrigin.X);
                    double syCurrent = SampleYFromClientY(m_scaleDragOrigin.Y);

                    Point ptDisplacement = new Point(e.Location.X - m_scaleDragStart.X, e.Location.Y - m_scaleDragStart.Y);
                    m_scaleDragStart = e.Location;

                    double samplesPerPixelX = GetSamplesPerPixelX();
                    double samplesPerPixelY = GetSamplesPerPixelY();
                    double sx = ptDisplacement.X * samplesPerPixelX;
                    double sy = -ptDisplacement.Y * samplesPerPixelY;

                    const double ZoomDragScaleX = 2.5;
                    const double ZoomDragScaleY = 2.5;

                    m_view = new RectD(
                        m_view.Left + sx * ZoomDragScaleX, m_view.Top + sy * ZoomDragScaleY,
                        m_view.Right - sx * ZoomDragScaleX, m_view.Bottom - sy * ZoomDragScaleY);

                    ClampView();

                    double sxNew = SampleXFromClientX(m_scaleDragOrigin.X);
                    double syNew = SampleYFromClientY(m_scaleDragOrigin.Y);

                    m_view = new RectD(
                        m_view.Left - (sxNew - sxCurrent), m_view.Top - (syNew - syCurrent),
                        m_view.Right - (sxNew - sxCurrent), m_view.Bottom - (syNew - syCurrent));

                    ClampView();
                    UpdateScroll();
                    Invalidate();

                    hasViewChanged = true;
                }
            }

            if (hasViewChanged)
            {
                OnViewChanged();
            }

            base.OnMouseMove(e);
        }
        protected override void OnMouseMove(MouseEventArgs e)
        {
            bool hasViewChanged = false;

            if ((e.Button & MouseButtons.Left) != 0)
            {
                Point displacement = new Point(e.Location.X - m_panDragStart.X, e.Location.Y - m_panDragStart.Y);

                if (m_isPanPriming)
                {
                    if (displacement.X * displacement.X + displacement.Y * displacement.Y >= 25)
                    {
                        m_isPanning    = true;
                        m_isPanPriming = false;
                    }
                }

                if (m_isPanning)
                {
                    double samplesXPerPixel = m_view.Width / ClientRectangle.Width;
                    double samplesYPerPixel = m_view.Height / ClientRectangle.Height;

                    m_view = new RectD(
                        m_view.Left - samplesXPerPixel * displacement.X,
                        m_view.Top - samplesYPerPixel * displacement.Y,
                        m_view.Right - samplesXPerPixel * displacement.X,
                        m_view.Bottom - samplesYPerPixel * displacement.Y);

                    m_panDragStart = e.Location;

                    ClampView();
                    UpdateScroll();
                    Invalidate();

                    hasViewChanged = true;
                }
            }

            if ((e.Button & MouseButtons.Right) != 0)
            {
                if (m_isScaling)
                {
                    double sxCurrent = SampleXFromClientX(m_scaleDragOrigin.X);
                    double syCurrent = SampleYFromClientY(m_scaleDragOrigin.Y);

                    Point ptDisplacement = new Point(e.Location.X - m_scaleDragStart.X, e.Location.Y - m_scaleDragStart.Y);
                    m_scaleDragStart = e.Location;

                    double samplesPerPixelX = GetSamplesPerPixelX();
                    double samplesPerPixelY = GetSamplesPerPixelY();
                    double sx = ptDisplacement.X * samplesPerPixelX;
                    double sy = -ptDisplacement.Y * samplesPerPixelY;

                    const double ZoomDragScaleX = 2.5;
                    const double ZoomDragScaleY = 2.5;

                    m_view = new RectD(
                        m_view.Left + sx * ZoomDragScaleX, m_view.Top + sy * ZoomDragScaleY,
                        m_view.Right - sx * ZoomDragScaleX, m_view.Bottom - sy * ZoomDragScaleY);

                    ClampView();

                    double sxNew = SampleXFromClientX(m_scaleDragOrigin.X);
                    double syNew = SampleYFromClientY(m_scaleDragOrigin.Y);

                    m_view = new RectD(
                        m_view.Left - (sxNew - sxCurrent), m_view.Top - (syNew - syCurrent),
                        m_view.Right - (sxNew - sxCurrent), m_view.Bottom - (syNew - syCurrent));

                    ClampView();
                    UpdateScroll();
                    Invalidate();

                    hasViewChanged = true;
                }
            }

            if ((e.Button & MouseButtons.Middle) != 0)
            {
                if (m_isSelecting)
                {
                    m_selectionEnd = SampleXFromClientX(e.X);
                    Invalidate();
                }
            }

            if (e.Button == 0)
            {
                if (e.X != m_lastPoint.X || e.Y != m_lastPoint.Y)
                {
                    var      hitResult        = HitTest(e.Location);
                    Interval selectedInterval = hitResult.Value;

                    if (selectedInterval != m_hoverInterval)
                    {
                        m_hoverInterval = selectedInterval;
                        if (selectedInterval != null)
                        {
                            string path;
                            lock (m_tree)
                            {
                                path = m_tree.GetRailName(hitResult.Key);
                            }
                            int sep = path.LastIndexOfAny(new char[] { '/', '\\' });
                            if (sep >= 0)
                            {
                                path = path.Substring(sep + 1);
                            }

                            double selectedStart = selectedInterval.Start;
                            double selectedEnd   = selectedInterval.End;
                            double duration      = selectedEnd - selectedStart;
                            string durationText  = duration > 1.0 ? string.Format("{0}s", duration) : string.Format("{0}ms", duration * 1000.0);
                            m_tooltip.SetToolTip(this, string.Format("{0}\n{1}\n{2}s-{3}s ({4})", path, GetTextForIntervalProps(selectedInterval), selectedStart, selectedEnd, durationText));
                        }
                        else
                        {
                            m_tooltip.SetToolTip(this, string.Empty);
                        }
                    }
                }
                m_lastPoint = new Point(e.X, e.Y);
            }

            if (hasViewChanged)
            {
                OnViewChanged();
            }

            base.OnMouseMove(e);
        }
        private void FillNode(TreemapNode n, RectD nBounds, RectD vBounds, double pxX, double pxY, int depth)
        {
            if (Overlaps(nBounds, vBounds))
            {
                GLTexture tex = n.Texture;
                if (tex != null && tex.Valid)
                {
                    OpenGL.glEnd();
                    OpenGL.glEnable(OpenGL.GL_TEXTURE_2D);
                    OpenGL.glDisable(OpenGL.GL_BLEND);
                    tex.Bind();

                    OpenGL.glColor3f(1.0f, 1.0f, 1.0f);
                    OpenGL.glBegin(OpenGL.GL_QUADS);
                }
                else
                {
                    RGB col = new RGB(new HSV(depth * (1.0f / 6.0f), 0.5f - depth / 256.0f, 1));
                    OpenGL.glColor3f(col.r, col.g, col.b);
                }

                {
                    OpenGL.glTexCoord2f(0.0f, 0.0f);
                    OpenGL.glVertex2f((float)nBounds.Left, (float)nBounds.Top);

                    OpenGL.glTexCoord2f(0.0f, 1.0f);
                    OpenGL.glVertex2f((float)nBounds.Left, (float)nBounds.Bottom);

                    OpenGL.glTexCoord2f(1.0f, 1.0f);
                    OpenGL.glVertex2f((float)nBounds.Right, (float)nBounds.Bottom);

                    OpenGL.glTexCoord2f(1.0f, 0.0f);
                    OpenGL.glVertex2f((float)nBounds.Right, (float)nBounds.Top);
                }

                if (tex != null && tex.Valid)
                {
                    OpenGL.glEnd();
                    tex.Unbind();
                    OpenGL.glDisable(OpenGL.GL_TEXTURE_2D);
                    OpenGL.glEnable(OpenGL.GL_BLEND);
                    OpenGL.glBegin(OpenGL.GL_QUADS);
                }

                RectD conBounds = new RectD(
                    nBounds.Left + nBounds.Width * 0.01f,
                    nBounds.Top + nBounds.Height * 0.03f,
                    nBounds.Right - nBounds.Width * 0.01f,
                    nBounds.Bottom - nBounds.Height * 0.01f);

                for (int i = 0, c = n.Children.Count; i != c; ++i)
                {
                    TreemapNode cn = n.Children[i];

                    RectD cBounds = new RectD(
                        cn.Bounds.Left * conBounds.Width + conBounds.Left,
                        cn.Bounds.Top * conBounds.Height + conBounds.Top,
                        cn.Bounds.Right * conBounds.Width + conBounds.Left,
                        cn.Bounds.Bottom * conBounds.Height + conBounds.Top);

                    if (cBounds.Width > pxX * 5)
                    {
                        cBounds.Left  += pxX * m_pxNodeMargin;
                        cBounds.Right -= pxX * m_pxNodeMargin;
                    }

                    if (cBounds.Height > pxY * 5)
                    {
                        cBounds.Top    += pxY * m_pxNodeMargin;
                        cBounds.Bottom -= pxY * m_pxNodeMargin;
                    }

                    FillNode(cn, cBounds, vBounds, pxX, pxY, depth + 1);
                }
            }
        }
Beispiel #5
0
        protected override void glDraw()
        {
            while (true)
            {
                KeyValuePair <Image, GLTexture> req;

                lock (m_thumbnailComplete)
                {
                    if (m_thumbnailComplete.Count == 0)
                    {
                        break;
                    }
                    req = m_thumbnailComplete[0];
                    m_thumbnailComplete.RemoveAt(0);
                }

                if (req.Key != null)
                {
                    req.Value.Update((Bitmap)req.Key);
                    req.Key.Dispose();
                }
            }

            if (m_logViews.Count > 0)
            {
                LogView lv = m_logViews[0];
                LogData ld = lv.m_logData;

                if (m_remakeTree)
                {
                    VirtualBounds = new RectD(0, 0, 1, 1);
                    View          = new RectD(0, 0, 1, 1);

                    TreemapNode rootNode = CreateTree();

                    FrameRecord fr = m_frameRecord;

                    if (fr != null)
                    {
                        lock (ld)
                        {
                            List <RDIElementValue <ProfilerRDI> > children = new List <RDIElementValue <ProfilerRDI> >();

                            float totalSize = 0;

                            foreach (RDIElementValue <ProfilerRDI> prdiEv in m_logControl.m_prdiTree.GetValueEnumerator(fr))
                            {
                                float size = prdiEv.m_value;

                                if (size == 0.0f)
                                {
                                    continue;
                                }

                                children.Add(prdiEv);
                                totalSize += size;
                            }

                            rootNode.Name = String.Format("{0} MB", totalSize);

                            children.Sort((a, b) => - a.m_value.CompareTo(b.m_value));

                            foreach (RDIElementValue <ProfilerRDI> ev in children)
                            {
                                float  size = ev.m_value;
                                string path = ev.m_rdi.Path;
                                int    sep  = path.LastIndexOf('/');

                                GLTexture tex = null;

                                if (path.StartsWith("/TexStrm/"))
                                {
                                    string texturepath = path.Substring("/TexStrm/".Length).Replace(".dds", ".tif");
                                    tex = RequestThumbnail(texturepath, -size);
                                }

                                TreemapNode child = CreateChild(rootNode);
                                child.Size    = size / totalSize;
                                child.Name    = (sep >= 0) ? path.Substring(sep + 1) : path;
                                child.Tag     = ev;
                                child.Texture = tex;
                            }
                        }
                    }

                    VirtualBounds = new RectD(0, 0, 1, 1);
                    View          = new RectD(0, 0, 1, 1);

                    m_remakeTree = false;
                }
            }
            base.glDraw();
        }