Is CGE suitable for a Visio clone?

#1

Would CGE be suitable to develop a light-weight Visio clone, i.e. a flowchart editor? Simple block shapes, maybe with images, joined by connectors. Select objects, move objects with the mouse, that sort of thing.

The reason I ask is that I’m thinking of developing a simulation program that will require all the 3D capabilities of CGE, but also some 2D connectivity/flowsheet definitions. Would be nice to use one external graphics library only.

So, if possible, what would be the best base class for a shape - a TSprite or TDrawableImage? What about picking and dragging?

#2

Short answer: Yes.

At the moment you can experiment with this using Castle Editor (in tools directory) - check the latest version 6.5 - it has a lot of improvements and is very stable. While it’s still under development it has already a lot of powerful features, and you can easily see the capabilities.
That said, creating a Visio from a scratch would be a relatively complex task to provide for an ergonomic and WYSIWYG workflow. I’d recommend developing it with Castle User Interface (see https://castle-engine.io/manual_user_interface_and_2d_drawing.php) instead of TDrawableImage. This approach is harder to start, but will provide for a much higher degree of flexibility, you will need for that task.
The only thing I’m worried about are “connectors”. However, one way or another this issue is fixable. I’d try first of all to create a custom child of TCastleUserInterface, that would create a connector based on two “dock points”, or maybe more control points. My first guess would be to make lines by making three TCastleRectangleControl that would be “colored lines”.

1 Like
#3

As for line drawing, one can create TCastleUserInterface descendant that calls in overridden Render method DrawPrimitive2D ( https://castle-engine.io/apidoc/html/CastleGLUtils.html#DrawPrimitive2D ), it allows to draw lines. See https://castle-engine.io/manual_2d_ui_custom_drawn.php .

1 Like
#4

Many thanks for the replies; I’ve started with the UIControls and so far so good, I can draw and select nicely.

Next question. What would be the most sensible approach to drag a selected object across the screen; I plan on using OnPress, OnMotion, OnRelease or should I be looking at TTouchSensor?

#5

I’ve answered my own question; the former works very nicely! I just can’t find a method to bring the selected UIControl to the front so that when dragged it always goes over/on top of the other controls.

1 Like
#6

Yes, this is a valid way to implement dragging. However, pay attention, that it’s best to adjust TCastleUserInterface.VerticalAnchorDelta and TCastleUserInterface.HorizonatalAnchorDelta (see https://castle-engine.io/apidoc-unstable/html/CastleUIControls.TCastleUserInterface.html ), this way they are correctly moved relative to parent TCastleUserInterface in all situations, e.g. including if the parent interface is larger than the screen area, e.g. if it is is located within a TCastleScrollView instance see https://castle-engine.io/apidoc-unstable/html/CastleControls.TCastleScrollView.html .

I think the best way is to "RemoveControl and InsertFront" it. You can also use InsertControl to insert the UI element at a specific index.
Another approach I would have tried is to have a separate UI layer for dragged elements (i.e. remove it from “main one” and “insert into a new one, which is always atop”) - this would provide more flexibility and will be less prone to possible bugs, I guess.