Disabled topic [xButtonGadget]

Share your advanced PureBasic knowledge/code with the community.
User avatar
Bisonte
Addict
Addict
Posts: 1232
Joined: Tue Oct 09, 2007 2:15 am

Re: xButtonGadget

Post 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
...
PureBasic 6.10 LTS (Windows x86/x64) | Windows10 Pro x64 | Asus TUF X570 Gaming Plus | R9 5900X | 64GB RAM | GeForce RTX 3080 TI iChill X4 | HAF XF Evo | build by vannicom​​
English is not my native language... (I often use DeepL to translate my texts.)
User avatar
Bisonte
Addict
Addict
Posts: 1232
Joined: Tue Oct 09, 2007 2:15 am

Re: xButtonGadget

Post 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...
PureBasic 6.10 LTS (Windows x86/x64) | Windows10 Pro x64 | Asus TUF X570 Gaming Plus | R9 5900X | 64GB RAM | GeForce RTX 3080 TI iChill X4 | HAF XF Evo | build by vannicom​​
English is not my native language... (I often use DeepL to translate my texts.)
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5350
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: xButtonGadget

Post by Kwai chang caine »

Very very nice, looks like new professional GUI
For a first job, that promises :shock:
Thanks for sharing 8)
ImageThe happiness is a road...
Not a destination
User avatar
CELTIC88
Enthusiast
Enthusiast
Posts: 154
Joined: Thu Sep 17, 2015 3:39 pm

Re: xButtonGadget

Post by CELTIC88 »

Good work my friend :)

waiting for the next update .
interested in Cybersecurity..
infratec
Always Here
Always Here
Posts: 6866
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: [Module] xButton Gadget

Post 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
Last edited by infratec on Mon Apr 16, 2018 2:06 pm, edited 1 time in total.
User avatar
Bisonte
Addict
Addict
Posts: 1232
Joined: Tue Oct 09, 2007 2:15 am

Re: [Module] xButton Gadget

Post 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)

PureBasic 6.10 LTS (Windows x86/x64) | Windows10 Pro x64 | Asus TUF X570 Gaming Plus | R9 5900X | 64GB RAM | GeForce RTX 3080 TI iChill X4 | HAF XF Evo | build by vannicom​​
English is not my native language... (I often use DeepL to translate my texts.)
User avatar
Kiffi
Addict
Addict
Posts: 1357
Joined: Tue Mar 02, 2004 1:20 pm
Location: Amphibios 9

Re: [Module] xButton Gadget

Post by Kiffi »

@mohsen:

looks very interesting. Thanks for sharing! :D

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
Hygge
davido
Addict
Addict
Posts: 1890
Joined: Fri Nov 09, 2012 11:04 pm
Location: Uttoxeter, UK

Re: [Module] xButton Gadget

Post by davido »

@mohsen,
Great. Thank you for sharing. :D
DE AA EB
infratec
Always Here
Always Here
Posts: 6866
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: [Module] xButton Gadget

Post 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
walbus
Addict
Addict
Posts: 929
Joined: Sat Mar 02, 2013 9:17 am

Re: [Module] xButton Gadget

Post 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
User avatar
Bisonte
Addict
Addict
Posts: 1232
Joined: Tue Oct 09, 2007 2:15 am

Re: [Module] xButton Gadget

Post 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
PureBasic 6.10 LTS (Windows x86/x64) | Windows10 Pro x64 | Asus TUF X570 Gaming Plus | R9 5900X | 64GB RAM | GeForce RTX 3080 TI iChill X4 | HAF XF Evo | build by vannicom​​
English is not my native language... (I often use DeepL to translate my texts.)
walbus
Addict
Addict
Posts: 929
Joined: Sat Mar 02, 2013 9:17 am

Re: [Module] xButton Gadget

Post 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. :wink:

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.
Last edited by walbus on Sun Apr 29, 2018 7:30 pm, edited 1 time in total.
walbus
Addict
Addict
Posts: 929
Joined: Sat Mar 02, 2013 9:17 am

Re: [Module] xButton Gadget

Post 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
User avatar
Bisonte
Addict
Addict
Posts: 1232
Joined: Tue Oct 09, 2007 2:15 am

Re: [Module] xButton Gadget

Post 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.
PureBasic 6.10 LTS (Windows x86/x64) | Windows10 Pro x64 | Asus TUF X570 Gaming Plus | R9 5900X | 64GB RAM | GeForce RTX 3080 TI iChill X4 | HAF XF Evo | build by vannicom​​
English is not my native language... (I often use DeepL to translate my texts.)
walbus
Addict
Addict
Posts: 929
Joined: Sat Mar 02, 2013 9:17 am

Re: [Module] xButton Gadget

Post 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 :wink:
I hope you're happy now that you broke the thread ?
Post Reply