EditorFactory - Module for object management in a Canvas

Share your advanced PureBasic knowledge/code with the community.
User avatar
STARGÅTE
Addict
Addict
Posts: 2086
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 »

This is a good point, when handling with multiple gadgets. But due to the event handling in the module, it has to look like this (similar to NetworkServerEvent() from Pure Basic):

For a specific gadget:

Code: Select all

Repeat
	Select CanvasObjectsEvent(#CanvasGadget)
		Case #Event_Handle
			Select CanvasObjectsEventType(#CanvasGadget)
				Case #EventType_LeftMouseClick
For an unspecific gadget:

Code: Select all

Repeat
	Select CanvasObjectsEvent()
		Case #Event_Handle
			CanvasGadget = CanvasObjectsEventGadget()
			Select CanvasObjectsEventType(CanvasGadget)
				Case #EventType_LeftMouseClick
I'm adding it to the to-do list.
PB 6.01 ― Win 10, 21H2 ― Ryzen 9 3900X, 32 GB ― NVIDIA GeForce RTX 3080 ― Vivaldi 6.0 ― www.unionbytes.de
Lizard - Script language for symbolic calculations and moreTypeface - Sprite-based font include/module
jamirokwai
Enthusiast
Enthusiast
Posts: 772
Joined: Tue May 20, 2008 2:12 am
Location: Cologne, Germany
Contact:

Re: EditorFactory - Module for object management in a Canvas

Post by jamirokwai »

Hi there,

nice and great functionality. Thanks for sharing!

On macOS, there is an error thrown in line 2261 of EditorFactory.pbi: CocoaMessage(0, CustomCursor, "initWithImage:", ImageID(iImage), "hotSpot:@", @Hotspot)

Line 2261: With 'EnableExplicit', variables have to be declared: CustomCursor.

If you remove EnableExplicit, it works nonetheless.
Regards,
JamiroKwai
User avatar
ChrisR
Addict
Addict
Posts: 1150
Joined: Sun Jan 08, 2017 10:27 pm
Location: France

Re: EditorFactory - Module for object management in a Canvas

Post by ChrisR »

Is it possible to extend the use of #PB_All, to change all objects, as it is made for:

Code: Select all

ObjectHandleDisplayMode(#PB_All, #Handle_ShowIfSelected)
For these procedures:

Code: Select all

AddObjectHandle(#PB_All, #Handle_Size | #Handle_Position)
SetObjectCursor(#PB_All, #PB_Cursor_Cross)
SetObjectSelectionStyle(#PB_All, #SelectionStyle_Solid, RGBA(192, 128, 64, 255), 3)
There are probably others where it would be good to have, to avoid having to do it for each object.
it would be a bonus if it could be done at initialization, as default property, before creating the objects.
User avatar
STARGÅTE
Addict
Addict
Posts: 2086
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 »

@jamirokwai: Thanks for the report.

@ChrisR:
Good point. Probably I will improve this method even more. #PB_All is a very strong constant, because it would influence really all objects, which could generate unexpected behaviors. I will add it, but additionally I would add somethink like #PB_Selected that influences only the selected objects.

Regarding to your second comment: For the function SetObjectSelectionStyle it is already possible to use #PB_Default as object number, to define the default style for the module. This style is then used when new objects are created. I think I can extend this feature to more functions.
PB 6.01 ― Win 10, 21H2 ― Ryzen 9 3900X, 32 GB ― NVIDIA GeForce RTX 3080 ― Vivaldi 6.0 ― www.unionbytes.de
Lizard - Script language for symbolic calculations and moreTypeface - Sprite-based font include/module
ShadowStorm
Enthusiast
Enthusiast
Posts: 237
Joined: Tue Feb 14, 2017 12:07 pm

Re: EditorFactory - Module for object management in a Canvas

Post by ShadowStorm »

I would like to add something important to me.
To be able to display a tooltip under the mouse when it passes over an object (configurable).

Simple to start with like this:

SetObjectToolTip(HotSpotX, HotSpotY, width, height, Text$, BackGroundColor, TextFontColor, TextBackColor, TextStyle, Image)

GetObjectToolTip()...

Otherwise, we could also imagine something even more powerful, a kind of SetObjectToolTipDrawingCallback(), because here we could do what we want, so it's even more powerful.

To think about it !
I am French, I do not speak English.
My apologies for the mistakes.

I have sometimes problems of expression
I am sometimes quite clumsy, please excuse me and let me know.
Amitris_de
User
User
Posts: 31
Joined: Wed Jan 06, 2021 2:53 pm

Re: EditorFactory - Module for object management in a Canvas

Post by Amitris_de »

Hi STARGÅTE,

Is there a way to be notified of an event in SetObjectDrawingCallback function?
Similar to this :

Code: Select all

Procedure MyDrawing(Object.i, Width.i, Height.i, iData.i, Event.i)
  If Event = #EventType_Resized
    ....	
  EndIf
EndProcedure
ShadowStorm
Enthusiast
Enthusiast
Posts: 237
Joined: Tue Feb 14, 2017 12:07 pm

Re: EditorFactory - Module for object management in a Canvas

Post by ShadowStorm »

Hi Amitris_de,

Not that way no!
But you have an event that happens when you resize an object, look at the example: Example02_Cursors-selections-and-events
I am French, I do not speak English.
My apologies for the mistakes.

I have sometimes problems of expression
I am sometimes quite clumsy, please excuse me and let me know.
Amitris_de
User
User
Posts: 31
Joined: Wed Jan 06, 2021 2:53 pm

Re: EditorFactory - Module for object management in a Canvas

Post by Amitris_de »

@ShadowStorm : Thanks for your reply .
With each passing moment, I realize more and more the power of this module. :shock:
User avatar
STARGÅTE
Addict
Addict
Posts: 2086
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 »

The short answer is: no.
The drawing (and the drawing callback) is not performed on each individual event, but only for a collection of events happened at the same time, otherwise the performance would be worse.
For example, if you release the mouse button the events are: #EventType_LeftMouseBottonUp, #EventType_LeftMouseClick and #EventType_Resized, but only one drawing is performed.
In this case the #EventType_Resized event is the last event, but this is not always the case.

The module strictly differentiate between the drawing calls and the event calls to gain performance.
In general it is not possible to respond events in the drawing call or to perform a drawing in the event loop.

Could you explain what you want to do, maybe I can then suggest a better solution: e.g. implementing a BindObjectEvent() procedure (like in PB)

@ShadowStorm:
You can use GadgetToolTip() after an object event happend.
PB 6.01 ― Win 10, 21H2 ― Ryzen 9 3900X, 32 GB ― NVIDIA GeForce RTX 3080 ― Vivaldi 6.0 ― www.unionbytes.de
Lizard - Script language for symbolic calculations and moreTypeface - Sprite-based font include/module
Amitris_de
User
User
Posts: 31
Joined: Wed Jan 06, 2021 2:53 pm

Re: EditorFactory - Module for object management in a Canvas

Post by Amitris_de »

STARGÅTE wrote: Could you explain what you want to do, maybe I can then suggest a better solution: e.g. implementing a BindObjectEvent() procedure (like in PB)

I capture of PB gadgets and draw them in the DrawingCallback function. therefore, there is no need to re-capture until a control property is changed or the control is resized. but now the capture operation is done almost frequently.
I wanted to prevent unnecessary repetition of this.
Last edited by Amitris_de on Fri Jan 22, 2021 1:32 pm, edited 1 time in total.
User avatar
STARGÅTE
Addict
Addict
Posts: 2086
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 »

Then I would say, you have to do the capture of PB gadget in the object event loop to decide for which event you want a new capute. After a #EventType_Resized you perform the capture and you can save the image as SetObjectData().
Then, in the drawing callback you can receive this image with GetObjectData().
Probably you need then two additional events like: #EventType_Created and #EventType_Freed, but this is easy for me to implement. What do you think on?
PB 6.01 ― Win 10, 21H2 ― Ryzen 9 3900X, 32 GB ― NVIDIA GeForce RTX 3080 ― Vivaldi 6.0 ― www.unionbytes.de
Lizard - Script language for symbolic calculations and moreTypeface - Sprite-based font include/module
Amitris_de
User
User
Posts: 31
Joined: Wed Jan 06, 2021 2:53 pm

Re: EditorFactory - Module for object management in a Canvas

Post by Amitris_de »

this method is easy. I was a little confused, thanks for your guidance. :)
ShadowStorm
Enthusiast
Enthusiast
Posts: 237
Joined: Tue Feb 14, 2017 12:07 pm

Re: EditorFactory - Module for object management in a Canvas

Post by ShadowStorm »

#EventType_Created et #EventType_Freed, good idea ;)
With each passing moment, I realize more and more the power of this module.
Thank you, we worked hard for this, but it's not over yet.
I am French, I do not speak English.
My apologies for the mistakes.

I have sometimes problems of expression
I am sometimes quite clumsy, please excuse me and let me know.
User avatar
ChrisR
Addict
Addict
Posts: 1150
Joined: Sun Jan 08, 2017 10:27 pm
Location: France

Re: EditorFactory - Module for object management in a Canvas

Post by ChrisR »

Amitris_de wrote:With each passing moment, I realize more and more the power of this module. :shock:
I'm very impressed as well :shock:

For fun, I created an example with Captured Gadgets,
With Grid on Canvas, Capture Gadget only on Resize, Create Alternatively a Button or a Text Gadget if the Selection is Empty...

On the containers, the selection is only available on the border or with SelectionStyle
Is there a way to select from the inner empty space?

In case the Parent is a Panel
I defined the Boundary iMinY with GetGadgetAttribute(GetObjectData(ParentObject), #PB_Panel_TabHeight),
looks good but I noted that the Y position is wrong. It ignores the Panel Tab Height (SetObjectY, SetObjectY, Object\iY)
Do you have an idea on how it could be done ?

Also, No idea how to do for the ScrollArea with it's Inner size.

Code: Select all

; Example_Captured_Gadget.pb

Deleted following EditorFactory update
Last edited by ChrisR on Tue Jan 26, 2021 12:02 pm, edited 1 time in total.
User avatar
STARGÅTE
Addict
Addict
Posts: 2086
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 the containers, the selection is only available on the border or with SelectionStyle
Is there a way to select from the inner empty space?
It is possible, but then you can not select the child object with the selection frame or in your case, create new object with the selection frame, because whenever you click into the empty space the parent object is selected.
Therefore I decided to allow only the border. Should it be changed?
ChrisR wrote:In case the Parent is a Panel
I defined the Boundary iMinY with GetGadgetAttribute(GetObjectData(ParentObject), #PB_Panel_TabHeight),
looks good but I noted that the Y position is wrong. It ignores the Panel Tab Height (SetObjectY, SetObjectY, Object\iY)
Do you have an idea on how it could be done ?
Please wait for the next version, if the offset of drawing is included. Then you define in case of the panel gadget an y-offset of ... and the boundary can still be defined as y = 0 (but it is displayed shifted) and the return y-inner-position is 0 when the child gadget is on the top of the head.
But anyway, I have to check how we/you can handle that a child object is drawing over the parent empty space, but not over the scroll bars or the tabs in a panel gadget.
Probably I will include a function like SetObjectChildChipping(Object, Left, Top, Right, Bottom), where you can define the clip frame/padding for the drawing of inner objects.
In case of the PanelGadget: SetObjectChildChipping(Object, 0, 20, 0, 0)
In case of the ScrollAreaGadget: SetObjectChildChipping(Object, 0, 0, 20, 20)
PB 6.01 ― Win 10, 21H2 ― Ryzen 9 3900X, 32 GB ― NVIDIA GeForce RTX 3080 ― Vivaldi 6.0 ― www.unionbytes.de
Lizard - Script language for symbolic calculations and moreTypeface - Sprite-based font include/module
Post Reply