Painting a rectangle

I want to add decorating rectangles to my net (derived from GoDocument). So i started to create a class like ‘LinearGradientRoundedRectangle’ in your demo1 sample. When i add an instance to my net i want the point i pressed the mouse button to be the upper left corner and the point i released the mouse button to be the bottom right corner. So it should behave almost like a painting application.

What is the best way to do this?

(The net nodes i add to my document should further on be added in default size by single click on my view.)

That’s easy–use a GoToolCreating tool.
And for doing the same when clicking in the view, implement GoView.BackgroundSingleClicked and/or ObjectSingleClicked event handler(s).

So far i failed getting a GoToolCreating to work.

My main window has a GoView and a Toobar. There are two radiogroups of Toolbuttons. One group for selecting a link type. And another group for selecting a node type which will be created when user clicks in GoView (including one toolbutton to create no node). Before thinking of using customized GoTools, i used GoView.BackgroundSingleClicked to create a node (depending on the toolbutton which is down) and add it to my document. And clicking on a link type toolbutton set GoView.NewLinkClass to different link classes.
But this does not match my needs regarding rectangles mentioned in my last post.

So I think it is the most flexible realization to create different GoTools each time user clicks on a toolbutton. But it will be activated immediatly and the node shows when mouse pointer is moved over GoView.

Does the GoToolManager switch to GoToolCreating under any condition? So i could replace default GoToolCreating with own one? Or do i have to switch manually to this tool?

If your application is designed to have a mode in which such drags will create an object, then you want to have your command such as toolbar button click set GoView.Tool to be an instance of GoToolCreating. GoToolCreating.Modal should be set to true.
You could keep reusing the same instance of GoToolCreating, since that might be more convenient in maintaining the state of that tool, particularly what kind of object it should create.
You can override GoToolCreating.Start and .Stop to set the GoView.Cursor (or GoView.CursorName) if you don’t want the default “Cross” cursor.
You seem to want to actually have a visible object that follows the mouse pointer during mouse-overs. You can do that by adding the GoToolCreating.Prototype to the GoView.Layers.Default layer. [Or maybe you want to add a copy of the prototype to the view.] Remove it in the Stop method, and I suppose in an override of CopyPrototype so that it doesn’t interfere visually with the actual NewObject while the user is dragging the mouse.

Ok, step by step its going foreward :-)

But there is one thing i dont understand in default behaviour of GoToolCreating. I use a node as prototype which contains of a label and a rectangle which is the SelectionObject. If i activate my tool MouseMove does not work properly. The node is not reshaped correctly. After releasing mouse button everything is ok and MouseDownPoint and MouseUpPoint are vertexes of my rectangle.

If i override DoMouseMove and set NewObject.SelectionObject.Bounds everything works fine. Maybe bug in GoToolCreating or in my node class?

It’s interesting you mention that, because we just added a GoToolCreating.ResizesSelectionObject property, to control whether the result of ComputeBox controls the size of the whole NewObject, or just the NewObject’s SelectionObject. I think you are right, that the old behavior was inconsistent on this issue.
Alas, this new feature didn’t make it into 2.4.1. It will be in the next release. But it sounds like you have already implemented this, by overriding DoMouseMove.

Another one regarding GoToolCreating: If i see it right, GoToolCreating is not working with a GoView.Grid. But GoToolResizing is. It would be very nice if you going to extend GoToolCreating :-)

How would you want that to work?
Do you mind if the object isn’t sized or positioned where the user drew it, because either or both of the starting point and the end point are snapped to some grid point?
Or should the object just be moved (and resized?) after creation?

I am working with a grid with a small cell size – width and height
each 4. And i was expecting that FirstInput.DocPoint and
LastInput.DocPoint snap to the grid immediately (if it is visible). In
this case the shape always is drawn correcty before user releases mouse
button. So the user can easily create two rectangles with same values
for top and height (by click and drag).

If the points do not snap to the grid the user rarely would be able to
click on points for same top and height. And if he then starts to move
and resize rectangles, he has to do it for both rectangles because in
this case the points snap to the grid.

I thought it would be a good idea and I started implementation of this.
To my feeling the tools move/resize and creating should behave similar
and i just wanted to share my thoughts :-)

OK, done for the next release, which looks like 2.4.2.

Fine! Thx for the good news.