Crainiate Community

Support and discussion for users of Crainiate component software products
Welcome to Crainiate Community Sign in | Join | Help
in Search

Diagram scrolling like in Google Maps

Last post 03-03-2008 8:31 AM by James Westgate. 3 replies.
Page 1 of 1 (4 items)
Sort Posts: Previous Next
  • 02-26-2008 3:50 PM

    Diagram scrolling like in Google Maps

    Hello,

    I'm trying to make a scroll feature that will allow a user to drag & drop the diagram to scroll it (just like in Google Maps and many more...). I've overridden OnDiagramMouseDown, OnDiagramMouseUp and OnMouseMove in the Model class to capture proper mouse events (middle button in my case) and update AutoScrollPosition when mouse is moving, but it's very inefficient. It's not smooth, it looks very ugly, I don't know how to describe it well...
    I think it may be caused by the fact that every time I change AutoScrollPosition the diagram is being drawn from scratch and the performance is not good enough for the OnMouseMove event, but I'm not sure... Do you know how can I make it look good ?

    Best regards,
    Ireneusz Patalas

    • 87.105.212.19
  • 02-27-2008 5:02 PM In reply to

    Re: Diagram scrolling like in Google Maps

    Hi,

    Can you post the code you use to scroll googlemaps style?

    The component is optimised for smooth scrolling. When you scroll using scroll bars do you get the same effect?
    You may want to attach an event hander to the Model.Render class to see if the diagram is beign re-rendered, this will cause the allocation of a new bitmap and this is an expensive operation.

    Normally a diagram is only rendered if somehting has changed, or is scrolled outside of it's RenderRectangle. A RenderRectangle is normally 4 times the size of the viewable area.

    • 86.130.71.215
  • 02-28-2008 11:25 AM In reply to

    Re: Diagram scrolling like in Google Maps

    It's more or less like this:

    Protected Overrides Sub OnDiagramMouseDown(ByVal e As System.Windows.Forms.MouseEventArgs)
        If e.Button = Windows.Forms.MouseButtons.Middle Then
            ' remember the necessary values
            m_CanDragDiagram = True
            m_MouseDownPosition = e.Location
            m_MouseDownAutoScroll = AutoScrollPosition
            Me.Cursor = Cursors.SizeAll
        End If
        MyBase.OnDiagramMouseDown(e)
    End Sub

    Protected Overrides Sub OnDiagramMouseUp(ByVal e As System.Windows.Forms.MouseEventArgs)
        If e.Button = Windows.Forms.MouseButtons.Middle Then
            m_CanDragDiagram = False
            Cursor = Cursors.Default
        End If
        MyBase.OnDiagramMouseUp(e)
    End Sub

    Protected Overrides Sub OnMouseMove(ByVal e As System.Windows.Forms.MouseEventArgs)
        If m_CanDragDiagram Then
            ' difference between current mouse position and the position where the mouse was down
            Dim diff As Point = Point.Subtract(m_MouseDownPosition, New Size(e.Location))
            AutoScrollPosition = New Point(-m_MouseDownAutoScroll.X + diff.X, -m_MouseDownAutoScroll.Y + diff.Y)
        End If
        MyBase.OnMouseMove(e)
    End Sub

    When I scroll using scrollbars I do not get the same effect, so it's probably something wrong in my code. I've also attached a debug information to Render class and it seems to be called only a few times when I'm scrolling (sometimes only once).

    • 87.105.212.19
  • 03-03-2008 8:31 AM In reply to

    Re: Diagram scrolling like in Google Maps

    I tried a quick sample by modifying the Editor Example to include the following subclass

    public class MyModel: Model
    {
      
    protected override void OnMouseMove(System.Windows.Forms.MouseEventArgs e)
       {
         
    base.OnMouseMove(e);
         
    if (e.Button == System.Windows.Forms.MouseButtons.Middle)
          {
            
    if (CurrentMouseElements.MouseStartElement == null)
             {
                AutoScrollPosition =
    new System.Drawing.Point(e.X, e.Y);
             }
          }
       }
    }

    This seems to work fine for me from the scrolling point of view.
    • 212.183.134.65
Page 1 of 1 (4 items)