Page 1 of 2
Re: xButtonGadget
Posted: Sun Apr 01, 2018 10:08 am
by Bisonte
Nice.
A little hint : Don't use datatype LONG for handles! They may work on machines with more than 2 GB or not...
And with this little change, the Gadget can handle also #PB_Any
Code: Select all
Procedure xButtonGadget(xbtn_ID, X.d, Y.d, Width.l, Height.l, Text$ = "", ImageNumber = 0)
Protected ID = CanvasGadget(xbtn_ID, X, Y, Width, Height) ; Change
If Gadget = #PB_Any : Gadget = ID : EndIf ; Added
If ID ; Change
If AddElement(xButtonList())
xButtonList()\ID = Gadget ; Change
xButtonList()\Width = Width
xButtonList()\Height = Height
...
Re: xButtonGadget
Posted: Sun Apr 01, 2018 10:23 am
by Bisonte
Another hint : Try to open a StartDrawing() or StartVectorDrawing() only once per event. These calls greatly reduce performance.
If I read it right, you use it four times...
Re: xButtonGadget
Posted: Mon Apr 02, 2018 3:43 pm
by Kwai chang caine
Very very nice, looks like new professional GUI
For a first job, that promises
Thanks for sharing
Re: xButtonGadget
Posted: Mon Apr 02, 2018 8:43 pm
by CELTIC88
Good work my friend
waiting for the next update .
Re: [Module] xButton Gadget
Posted: Mon Apr 16, 2018 1:52 pm
by infratec
Why you use a list for storing the data?
So you have always to search inside the list.
In such a case of a custom gadget I always allocate memory of the size of the strucure and set te data of the gadget to the address of this memory.
So you know always the values without searching in a list.
Like:
Code: Select all
Protected *XButtonData._XButton
*XButtonData = AllocateMemory(SizeOf(_XButton))
SetGadgetData(xbtn_ID, *XButtonData)
And
Code: Select all
Protected *XButtonData._XButton
*XButtonData = GetGadgetData(xbtn_ID)
Debug *XButtonData\Width
Bernd
Re: [Module] xButton Gadget
Posted: Mon Apr 16, 2018 5:51 pm
by Bisonte
Since PB5.6 we should better use : AllocateStructure() and FreeStructure(). It's much easier.
Code: Select all
Protected *XButtonData._XButton
*XButtonData = AllocateStructure(_XButton)
SetGadgetData(xbtn_ID, *XButtonData)
; To free
FreeStructure(*XButtonData)
Re: [Module] xButton Gadget
Posted: Tue Apr 24, 2018 10:49 pm
by Kiffi
@mohsen:
looks very interesting. Thanks for sharing!
But what I miss a little bit is an example code (kitchen sink), which demonstrates how to use the individual functions. It would be nice if you (or maybe someone else) could provide something like that.
Thanks in advance & Greetings ... Peter
Re: [Module] xButton Gadget
Posted: Wed Apr 25, 2018 6:08 am
by davido
@
mohsen,
Great. Thank you for sharing.
Re: [Module] xButton Gadget
Posted: Wed Apr 25, 2018 8:55 pm
by infratec
Hi,
Procedure xButton_GetData(xbtn_ID)
If IsGadget(xbtn_ID) And GadgetType(xbtn_ID) = #PB_GadgetType_Canvas
Protected *XButtonData._xButton = GetGadgetData(xbtn_ID)
ProcedureReturn *XButtonData
EndIf
EndProcedure
What's returned if it is not a gadget?
Btw. you don't need to call this procedure, since every place you need the data it is a valid gadget
so a simple GetGadgetData() would be enough instead of calling an additional procedure.
Bernd
Re: [Module] xButton Gadget
Posted: Sun Apr 29, 2018 11:07 am
by walbus
@mohsen
Its a good idea
I think, its better you change complete to #pb_any
Integer division /2 you can write >>1, it's faster , /4 is >>2
But, if the code is fast enough, you don't have to optimize it further according to speed, that doesn't have a meaningful effect
For the images, you should change this so that they are automatically resized so that any image can be used easily.
You can search for "FitSize" in the BF code and also use the code for it, that is OK.
However, pictures behind informal text are usually annoying, as they do not serve any meaningful purpose.
Text with "GradientColor" is more meaningful
Regards Werner
Re: [Module] xButton Gadget
Posted: Sun Apr 29, 2018 11:20 am
by Bisonte
The compiler will crash, if the gadget is not valid, so the "DebuggerWarning" is worthless
mohsen wrote:
Code: Select all
Procedure xButton_GetData(xbtn_ID)
If IsGadget(xbtn_ID) And GadgetType(xbtn_ID) = #PB_GadgetType_Canvas
Protected *XButtonData._xButton = GetGadgetData(xbtn_ID)
ProcedureReturn *XButtonData
Else
DebuggerWarning("Please set a valid gadget number.")
EndIf
EndProcedure
This one don't crash on a nonvalid gadget number...
Code: Select all
Procedure xButton_GetData(xbtn_ID)
Protected *XButtonData._xButton = #Null
If IsGadget(xbtn_ID)
If GadgetType(xbtn_ID) = #PB_GadgetType_Canvas
*XButtonData = GetGadgetData(xbtn_ID)
EndIf
Else
DebuggerWarning("Please set a valid gadget number.")
EndIf
ProcedureReturn *XButtonData
EndProcedure
Re: [Module] xButton Gadget
Posted: Sun Apr 29, 2018 2:15 pm
by walbus
Hi mohsen
Well, #PB_any has only advantages, in principle PB should use this as default, so that you don't have to write #PB_any separately anymore.
You'll never get into a collision with it.
Threads should only be used if it is absolutely necessary.
It usually does not lead to anything simple in itself to make things complicated.
You must then also primarily activate Thread save.
So, your tools are then only usable if this is activated.
If thread save is activated, this is also a brake for an application, everything becomes slower.
Using threads you have to think about exactly what you are using them for.
You often see programmers wanting to show what they can do in their codes.
But this is the wrong way.
It is important to try to make a code as simple and efficient as possible.
If you don't, you'll have trouble debugging your own code, especially if it's a little older.
If you want to output an image that the user can modify,
it is important that this image is always fit exactly,
a photo is not distorted, not to small and not to large,
because the space provided for the image in the GUI has different dimensions than your image.
Re: [Module] xButton Gadget
Posted: Sun Apr 29, 2018 6:15 pm
by walbus
Well, I don't do much with gadgets myself.
Opinions on this can vary greatly.
It is always the result that counts.
First of all, I always try to avoid threads, so users are not forced to activate threads to use my software.
I do not use external tools with threads whenever possible.
You can download the GFX_Wizzard_BF if you want.
It works with about 160 demo files completely without threads.
Not even BindEvent is used.
A few structures and a few lists, that's all.
Nevertheless, everything is animated, fast and extremely powerful.
http://nachtoptik.de/ablage/GFX_Wizzard_BF.zip
But always look for the things yourself
Check what is good and what is not so good
Think simple
Re: [Module] xButton Gadget
Posted: Sun Apr 29, 2018 7:03 pm
by Bisonte
mohsen wrote:@Bisonte:
Thanks.
The result of the implementation of two functions is the same. Which crash you are talking about?
If you do IsGadget() AND GadgetType() at the same line... the compiler will break compiling : #Gadget not initialised
So the "IsGadget()" question is unnecessary.
To check if a gadget is not valid, you don't want to break the compiler...
So your "GadgetType()" question has to be in the next line, so the compiler don't see it if this gadget is not initialised.
@walbus:
Please don't advertise your work all the time. Even if it's great. A note that this or that works well and a link is sufficient. When I look at the threads like this, I always have the feeling that a commercial block is coming up. In the thread you introduce it, it's enough. Thank you.
Re: [Module] xButton Gadget
Posted: Sun Apr 29, 2018 7:28 pm
by walbus
@Bisonte
I haven't commented your postings in this thread either and leave it up to you to reply, without my any comment.
mohsen has also asked me for more info and it's his thread, not your.
You're not happy if you can't stir ?
But thank you for your valuable advice, I love it when others think for me
I hope you're happy now that you broke the thread ?