Page 1 of 13

EditorFactory - Module for object management in a Canvas

Posted: Sat Jan 16, 2021 10:04 pm
by STARGÅTE
Dear all,

together with ShadowStorm I want to present our module for object management in a Canvas Gadget.
This module is related to this original thread: Project Editors Factory...
The module can be used for creating a form editor, game editor, or any kind of object-based editors,
where you want to add, remove, move, resize, attach objects.

The module is not an editor itself, its a module to create an editor in a more easy way, without thinking about the object handling itself.

Key features:
  • Create, delete and attached objects in an initialized canvas gadget.
  • Add drawing callbacks for custom object drawing.
  • Flags like: show, hide, disable, enable, select, unselect for objects.
  • Adding and customizing handles at edges and corners for moving, resizing and adding custom events.
  • Object attachment/container system with multiple frames inside of objects (like panel gadget).
  • Event management for cursor and keyboard events on objects and handles.
  • Definition of object boundaries for position and size.
  • Set and get of "all possible" general object attributes, like: X, Y, width, height, data, cursor, handles, movement/resize steps, selection style.
Download:
EditorFactory.pbi (Version 1.17.01, 2021-08-07)
EditorFactory-1-17-01.zip (Archive with include and examples)
A short documentation of each procedure is given in the module part.

The include is shared under the CC BY-NC 4.0 licence.

Feature Requests and Bugs:


    Change Log (1.17.01):
    • Added: Example #6: Example06_Gadgets.pb
    • Changed: More states returned by ObjectState() to create custom gadget easily, see example #6
    Change Log (1.16.04):
    • Added: IsObjectFrame(), AddObjectFrame(), RemoveObjectFrame(), MoveObjectFrame() to handle the frames inside of objects, but also between different objects.
    • Added: ReleaseCanvasObjects() to clean up the object manager before the canvas is freed with FreeGadget.
    • Added: #EventType_LeftMouseButtonHold, #EventType_RightMouseButtonHold, #EventType_MiddleMouseButtonHold to give continuously an event when a mouse button is held.
      These events only available in thread safe mode!
      This could be useful for the scroll bar arrows to perform a continuous scrolling.
    • Changed: CreateObject() - handling of the frame index is changed, see documentation!
    • Changed: AddObjectFrame() now handles also the frame properties like view box and inner area size.
    • Changed: SetObjectFrameClipping() --> SetObjectFrameViewBox() - changed behavior
    • Changed: SetObjectFrameOffset() --> SetObjectFrameInnerOffset() - changed behavior
    Change Log (1.15.00):
    • Added: SetObjectFrameClipping(), SetObjectFrameOffset()
    • Added: #Object_All, #Object_Default, #Object_Selected as possible constants for various functions.
    • Added: #EventType_Created, #EventType_Freed
    • Change: CanvasObjectsEvent() do not need a specific gadget
    Change Log (1.14.01):
    • Bug-fix: Multiple selection in different frames now disallowed.
    • Bug-Fix: Partially selection works now.

    Re: EditorFactory - Module for object management in a Canvas

    Posted: Sat Jan 16, 2021 10:53 pm
    by Mr.L
    Very nice, thanks for sharing!
    This module can become very handy for a future project, I have in mind...

    Re: EditorFactory - Module for object management in a Canvas

    Posted: Sat Jan 16, 2021 11:05 pm
    by ShadowStorm
    Hello, this module has been under development for some time now.

    Yes, I also think it can be very useful, there are few examples at the moment but we will add more.

    Thanks to you and if you have any questions, don't hesitate :)

    Re: EditorFactory - Module for object management in a Canvas

    Posted: Sun Jan 17, 2021 12:17 am
    by ChrisR
    Thank you for sharing this great module :)
    Now I will try to learn how to use...

    First feedback:
    On Example05_Attachment-and-containers, if I select #Object1 and #Object2 and I move #Object2,
    the moving of #Object2 is done twice, one for the attachment and one for itself.

    Re: EditorFactory - Module for object management in a Canvas

    Posted: Sun Jan 17, 2021 7:03 am
    by Amitris_de
    Thanks to ShadowStorm and STARGÅTE for this useful module. :D
    In my opinion, the most important feature of this module is "Object attachment/container system". I will ask my questions and ambiguities soon.
    Thanks again to the development team.
    With respect.

    Re: EditorFactory - Module for object management in a Canvas

    Posted: Sun Jan 17, 2021 8:51 am
    by Amitris_de
    Why can't we resize the container properly when an object is placed inside the container?

    EditorFactory
    https://i.ibb.co/8Bg8G5y/2.gif


    PB form designer
    https://i.ibb.co/PwdZczK/1.gif

    Re: EditorFactory - Module for object management in a Canvas

    Posted: Sun Jan 17, 2021 9:41 am
    by STARGÅTE
    ChrisR wrote:On Example05_Attachment-and-containers, if I select #Object1 and #Object2 and I move #Object2,
    the moving of #Object2 is done twice, one for the attachment and one for itself.
    You are right. Normally it should be disallowed to select object in different frames (here object 1 in the main frame and object 2 in the frame of object 1). I will fix it.
    Amitris_de wrote:Why can't we resize the container properly when an object is placed inside the container?
    This behavior of EditorFactory is right, because the parent object have to respect the boundary settings of all childs. If the childs should have the opportunity to overlap the frame of the parent, you have to remove the child's boundary. An additional flag has to be implemented, whether the childs should be clipped during drawing.

    Re: EditorFactory - Module for object management in a Canvas

    Posted: Sun Jan 17, 2021 10:16 am
    by ShadowStorm
    ChrisR wrote:Thank you for sharing this great module :)
    Now I will try to learn how to use...

    First feedback:
    On Example05_Attachment-and-containers, if I select #Object1 and #Object2 and I move #Object2,
    the moving of #Object2 is done twice, one for the attachment and one for itself.
    Hello,
    I couldn't figure out what you meant, but Stargate did :)
    Amitris_de wrote:Why can't we resize the container properly when an object is placed inside the container?

    EditorFactory
    Image

    PB form designer
    Image
    Hello Amitris_de,

    Thank you for your videos, they allow you to understand what you mean, good job :)
    And yes, this behavior is normal indeed :)

    It's because of the limits of the objects :)

    Re: EditorFactory - Module for object management in a Canvas

    Posted: Sun Jan 17, 2021 1:50 pm
    by ChrisR
    I started to play a little with it, amazing work :) :D

    I looked at how it could be done for the different containers
    It looks all good for Container Gadget or Canvas_Container Gadget
    Also for the Panel Gadget with the small button (layer_redraw) to represent the tab change
    But I'm wondering how it could be done for a ScrollArea Gadget with an Inner size ? hide, clipp childs when they are outside ?

    Code: Select all

    ; Example06_Containers.pb
    
    Deleted following EditorFactory update

    Re: EditorFactory - Module for object management in a Canvas

    Posted: Sun Jan 17, 2021 2:07 pm
    by STARGÅTE
    ChrisR wrote:But I'm wondering how it could be done for a ScrollArea Gadget with an Inner size ? and hide objects when they are outside ?
    This question is related to Amitris_de's question. As I remember correctly, the #PB_ScrollArea_InnerWidth und #PB_ScrollArea_InnerHeight in ScrollAreaGadget is not a real physically size, it is just to show the right scroll bar length.
    Meaning, you can position your child object wherever you want, independent from this values.
    For EditorFactory this means, you need a function like SetObjectFrameOffset() to change the drawing offset of the inner childs, like the position of scroll bars (which you have to draw by yourself, of course), together with the option to set a clipping frame of drawing of childs at the border of the frame.
    At the moment I'm not sure, if this flag have to define for the parent which contains the childs, or to all childs itself which are in the parent. What do you think?

    Edit: Probably, I make both possible, the parent can define it for all childs, but child can "exclude" itself (by a flag) to be clipped.

    Re: EditorFactory - Module for object management in a Canvas

    Posted: Sun Jan 17, 2021 2:39 pm
    by ChrisR
    Great, If you can do both :)
    I think it will be more useful (easy) to define it for the parent.
    with perhaps a flag #Boundary_ParentInnerSize for the chids.

    I would try to support Amitris as well, if my time allows, with its likely EditorFactory engine, could be a beautiful wedding :)

    Re: EditorFactory - Module for object management in a Canvas

    Posted: Mon Jan 18, 2021 9:46 am
    by Amitris_de
    In most designers, we can select objects by dragging a rectangle on a part of the them.

    https://i.ibb.co/ZgcZtfY/38.gif

    but I could not do that in EditorFactory.

    https://i.ibb.co/7RBRtV5/37.gif

    Is there a trick to doing this?

    Re: EditorFactory - Module for object management in a Canvas

    Posted: Mon Jan 18, 2021 10:17 am
    by STARGÅTE
    Amitris_de wrote:Is there a trick to doing this?
    Yes. If you use SetCursorSelectionStyle() do enable the cursor-frame selection you can use #SelectionStyle_Partially in combination with the other type-flags to enable the partially overlap.

    Code: Select all

    SetCursorSelectionStyle(#Canvas, #SelectionStyle_Solid|#SelectionStyle_Partially, $FF000000, 1.0)

    Re: EditorFactory - Module for object management in a Canvas

    Posted: Mon Jan 18, 2021 11:42 pm
    by STARGÅTE
    Sry Amitris_de, ChrisR just pointed out a bug to me, that the partially selection didn't work.
    I did a quick bug fix. See above the new link.

    Re: EditorFactory - Module for object management in a Canvas

    Posted: Tue Jan 19, 2021 8:13 pm
    by ShadowStorm
    Hi, I propose a function to know on which canvas (number) an event occurred.

    This can be very useful when creating multiple editors for the event loop.

    - On which canvas did an event occur? > CanvasNumber

    Then we will use CanvasObjectsEvent(CanvasNumber)
    to find out what kind of event (Objects or Handles) happened on it, then after knowing what it was
    use CanvasObjectsEventType(CanvasNumber) to find out what kind of event in question happened on it.

    Code: Select all

    Repeat
      
      NumeroCanvas = CanvasNumberEvent(); On which canvas did something happen?
      
      Select CanvasObjectsEvent(NumeroCanvas) ; Something happened on the NumeroCanvas.
          
        Case #Event_Object ; It is an Object Event.
          
          Select CanvasObjectsEventType(NumeroCanvas) ; What type of Events happened on the Object on the NumeroCanvas ?
              
            Case #EventType_MouseEnter
    
            ...