EditorFactory - Module for object management in a Canvas

Share your advanced PureBasic knowledge/code with the community.
User avatar
STARGÅTE
Addict
Addict
Posts: 1496
Joined: Thu Jan 10, 2008 1:30 pm
Location: Germany, Glienicke
Contact:

EditorFactory - Module for object management in a Canvas

Post 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.16.04, 2021-03-20)
EditorFactory-1-16-04.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.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.
    Last edited by STARGÅTE on Sat Mar 20, 2021 5:26 pm, edited 10 times in total.
    PB 5.73 ― Win 10, 20H2 ― Ryzen 9 3900X ― Radeon RX 5600 XT ITX ― Vivaldi 3.6 ― www.unionbytes.de
    Lizard - Script language for symbolic calculations and moreTypeface - Sprite-based font include/module
    Mr.L
    User
    User
    Posts: 55
    Joined: Sun Oct 09, 2011 7:39 am

    Re: EditorFactory - Module for object management in a Canvas

    Post by Mr.L »

    Very nice, thanks for sharing!
    This module can become very handy for a future project, I have in mind...
    ShadowStorm
    User
    User
    Posts: 99
    Joined: Tue Feb 14, 2017 12:07 pm

    Re: EditorFactory - Module for object management in a Canvas

    Post 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 :)
    I am French, I do not speak English.
    My apologies for the mistakes.
    User avatar
    ChrisR
    Enthusiast
    Enthusiast
    Posts: 309
    Joined: Sun Jan 08, 2017 10:27 pm
    Location: France

    Re: EditorFactory - Module for object management in a Canvas

    Post 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.
    Amitris_de
    User
    User
    Posts: 19
    Joined: Wed Jan 06, 2021 2:53 pm

    Re: EditorFactory - Module for object management in a Canvas

    Post 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.
    Amitris_de
    User
    User
    Posts: 19
    Joined: Wed Jan 06, 2021 2:53 pm

    Re: EditorFactory - Module for object management in a Canvas

    Post 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
    Last edited by Amitris_de on Tue Jan 26, 2021 12:19 pm, edited 1 time in total.
    User avatar
    STARGÅTE
    Addict
    Addict
    Posts: 1496
    Joined: Thu Jan 10, 2008 1:30 pm
    Location: Germany, Glienicke
    Contact:

    Re: EditorFactory - Module for object management in a Canvas

    Post 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.
    PB 5.73 ― Win 10, 20H2 ― Ryzen 9 3900X ― Radeon RX 5600 XT ITX ― Vivaldi 3.6 ― www.unionbytes.de
    Lizard - Script language for symbolic calculations and moreTypeface - Sprite-based font include/module
    ShadowStorm
    User
    User
    Posts: 99
    Joined: Tue Feb 14, 2017 12:07 pm

    Re: EditorFactory - Module for object management in a Canvas

    Post 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 :)
    I am French, I do not speak English.
    My apologies for the mistakes.
    User avatar
    ChrisR
    Enthusiast
    Enthusiast
    Posts: 309
    Joined: Sun Jan 08, 2017 10:27 pm
    Location: France

    Re: EditorFactory - Module for object management in a Canvas

    Post 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
    Last edited by ChrisR on Wed Jan 27, 2021 10:21 am, edited 3 times in total.
    User avatar
    STARGÅTE
    Addict
    Addict
    Posts: 1496
    Joined: Thu Jan 10, 2008 1:30 pm
    Location: Germany, Glienicke
    Contact:

    Re: EditorFactory - Module for object management in a Canvas

    Post 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.
    PB 5.73 ― Win 10, 20H2 ― Ryzen 9 3900X ― Radeon RX 5600 XT ITX ― Vivaldi 3.6 ― www.unionbytes.de
    Lizard - Script language for symbolic calculations and moreTypeface - Sprite-based font include/module
    User avatar
    ChrisR
    Enthusiast
    Enthusiast
    Posts: 309
    Joined: Sun Jan 08, 2017 10:27 pm
    Location: France

    Re: EditorFactory - Module for object management in a Canvas

    Post 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 :)
    Amitris_de
    User
    User
    Posts: 19
    Joined: Wed Jan 06, 2021 2:53 pm

    Re: EditorFactory - Module for object management in a Canvas

    Post 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?
    Last edited by Amitris_de on Tue Jan 26, 2021 12:20 pm, edited 1 time in total.
    User avatar
    STARGÅTE
    Addict
    Addict
    Posts: 1496
    Joined: Thu Jan 10, 2008 1:30 pm
    Location: Germany, Glienicke
    Contact:

    Re: EditorFactory - Module for object management in a Canvas

    Post 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)
    PB 5.73 ― Win 10, 20H2 ― Ryzen 9 3900X ― Radeon RX 5600 XT ITX ― Vivaldi 3.6 ― www.unionbytes.de
    Lizard - Script language for symbolic calculations and moreTypeface - Sprite-based font include/module
    User avatar
    STARGÅTE
    Addict
    Addict
    Posts: 1496
    Joined: Thu Jan 10, 2008 1:30 pm
    Location: Germany, Glienicke
    Contact:

    Re: EditorFactory - Module for object management in a Canvas

    Post 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.
    PB 5.73 ― Win 10, 20H2 ― Ryzen 9 3900X ― Radeon RX 5600 XT ITX ― Vivaldi 3.6 ― www.unionbytes.de
    Lizard - Script language for symbolic calculations and moreTypeface - Sprite-based font include/module
    ShadowStorm
    User
    User
    Posts: 99
    Joined: Tue Feb 14, 2017 12:07 pm

    Re: EditorFactory - Module for object management in a Canvas

    Post 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
    
            ...
    I am French, I do not speak English.
    My apologies for the mistakes.
    Post Reply