It is currently Wed Jul 18, 2018 6:12 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 39 posts ]  Go to page 1, 2, 3  Next
Author Message
 Post subject: [Module] xButton Gadget
PostPosted: Sun Apr 01, 2018 9:06 am 
Offline
User
User

Joined: Fri Dec 10, 2010 6:31 pm
Posts: 60
Image

Hi all,
I tried to make a button with more features.The name of this button is xButton.
This button is similar to the Metro UI tiles.The project is still ongoing, but its current capabilities are as follows :

Version 1.2 :
    Added : Checked frame ability.
    Added : BorderColor Procedure.
    Added : #State_Check for State procedure.
    Changed : renamed SetImage() to SetIcon().

Version 1.1 :
    Added : toggle button ability.
    Added : #State_Toggle for State procedure.
    Added : Text_ procedure now has the argument for selection mode.
    Added : #Mode_ReturnText and #Mode_WriteText for Text_ procedure.
    Updated : Now it uses AllocateStructure instead of the linked-list for storing the xButton data.
    Changed : renamed SetReadOrder() to ReadOrder() Because now this is Set/Get Procedure.
    Fixed : Many bugs

Current Procedures :
    Create(xbtn_ID, X, Y, Width, Height, Text$ = "", ImageNumber = 0)
    Free(xbtn_ID)
    ImageAndTextRelation(xbtn_ID, State = -1, Redraw = #False) ;Set/Get Procedure
    BackgroundColor(xbtn_ID,State,Color.l=0,Redraw=#False) ;Set/Get Procedure
    ImageAlign(xbtn_ID, State = -1, Redraw = #False) ;Set/Get Procedure
    TextAlign(xbtn_ID, State = -1, Redraw = #False) ;Set/Get Procedure
    SetTextFont(xbtn_ID, fontNum, Redraw = #False)
    TextColor(xbtn_ID, Color.l = 0, Redraw = #False) ;Set/Get Procedure
    Text_(xbtn_ID, Mode = #Mode_ReturnText, Text$ = "", Redraw = #False) ;Set/Get Procedure
    SetIcon(xbtn_ID, _ImageNum, Redraw = #False)
    Redraw(xbtn_ID)
    State(xbtn_ID, State = -1, Redraw = #False) ;Set/Get Procedure
    ReadOrder(xbtn_ID, Read_Order = -1, Redraw = #False) ;Set/Get Procedure
    BorderColor(xbtn_ID, Color.l = 0, Redraw = #False);Set/Get Procedure

Attention: To correct run ImageAndTextRelation,Text and Image should be aligned like:
#Image_Top_Left with #Text_Top_Left
#Text_Middle_Center with #Image_Middle_Center

for my first job I hope you enjoy it. :wink:

The new version will be released soon


Last edited by mohsen on Mon Jul 02, 2018 6:52 am, edited 24 times in total.

Top
 Profile  
Reply with quote  
 Post subject: Re: xButtonGadget
PostPosted: Sun Apr 01, 2018 10:08 am 
Offline
Addict
Addict
User avatar

Joined: Tue Oct 09, 2007 2:15 am
Posts: 984
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:
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 5.46 LTS / 5.62 (Windows x86/x64) | Windows10 Pro x64 | Z370 Extreme4 | i7 8770k | 32GB RAM | iChill GeForce GTX 980 X4 Ultra | HAF XF Evo​​
English is not my native language... (I often use DeepL to translate my texts.)


Top
 Profile  
Reply with quote  
 Post subject: Re: xButtonGadget
PostPosted: Sun Apr 01, 2018 10:18 am 
Offline
User
User

Joined: Fri Dec 10, 2010 6:31 pm
Posts: 60
@Bisonte :
Thanks for the reply
It was a good tip. I'll fix it for the next series.


Top
 Profile  
Reply with quote  
 Post subject: Re: xButtonGadget
PostPosted: Sun Apr 01, 2018 10:23 am 
Offline
Addict
Addict
User avatar

Joined: Tue Oct 09, 2007 2:15 am
Posts: 984
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 5.46 LTS / 5.62 (Windows x86/x64) | Windows10 Pro x64 | Z370 Extreme4 | i7 8770k | 32GB RAM | iChill GeForce GTX 980 X4 Ultra | HAF XF Evo​​
English is not my native language... (I often use DeepL to translate my texts.)


Top
 Profile  
Reply with quote  
 Post subject: Re: xButtonGadget
PostPosted: Sun Apr 01, 2018 10:43 am 
Offline
User
User

Joined: Fri Dec 10, 2010 6:31 pm
Posts: 60
@Bisonte :
Thanks again
I did not know it had a negative effect. :shock:
Of course to get the Text size, I have to use it.
For the next series I will improve it.


Top
 Profile  
Reply with quote  
 Post subject: Re: xButtonGadget
PostPosted: Mon Apr 02, 2018 3:43 pm 
Offline
Addict
Addict
User avatar

Joined: Sun Nov 05, 2006 11:42 pm
Posts: 4189
Location: Lyon - France
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


Top
 Profile  
Reply with quote  
 Post subject: Re: xButtonGadget
PostPosted: Mon Apr 02, 2018 4:28 pm 
Offline
User
User

Joined: Fri Dec 10, 2010 6:31 pm
Posts: 60
@Kwai chang caine :
you're welcome :)
I'm glad you liked.


Top
 Profile  
Reply with quote  
 Post subject: Re: xButtonGadget
PostPosted: Mon Apr 02, 2018 8:43 pm 
Offline
User
User
User avatar

Joined: Thu Sep 17, 2015 3:39 pm
Posts: 98
Good work my friend :)

waiting for the next update .

_________________
interested in Cybersecurity..


Top
 Profile  
Reply with quote  
 Post subject: Re: xButtonGadget
PostPosted: Mon Apr 02, 2018 9:01 pm 
Offline
User
User

Joined: Fri Dec 10, 2010 6:31 pm
Posts: 60
@CELTIC88 :
you're welcome my friend :wink:
You helped me a lot.
The next update will be released soon.


Top
 Profile  
Reply with quote  
 Post subject: Re: [Module] xButton Gadget
PostPosted: Mon Apr 16, 2018 1:32 pm 
Offline
User
User

Joined: Fri Dec 10, 2010 6:31 pm
Posts: 60
I tried to fix the important errors and added a few features to this gadget in this update.
Your comments are very important to me. :wink:


Last edited by mohsen on Wed Apr 25, 2018 2:24 pm, edited 2 times in total.

Top
 Profile  
Reply with quote  
 Post subject: Re: [Module] xButton Gadget
PostPosted: Mon Apr 16, 2018 1:52 pm 
Offline
Addict
Addict

Joined: Sun Sep 07, 2008 12:45 pm
Posts: 3890
Location: Germany
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:
 Protected *XButtonData._XButton

 *XButtonData = AllocateMemory(SizeOf(_XButton))
 SetGadgetData(xbtn_ID, *XButtonData)


And

Code:
 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.

Top
 Profile  
Reply with quote  
 Post subject: Re: [Module] xButton Gadget
PostPosted: Mon Apr 16, 2018 2:05 pm 
Offline
User
User

Joined: Fri Dec 10, 2010 6:31 pm
Posts: 60
@ infratec:
Thank you very much for your comment.
Yes, you're right. I did not know that.
I will do this in the next update.


Top
 Profile  
Reply with quote  
 Post subject: Re: [Module] xButton Gadget
PostPosted: Mon Apr 16, 2018 5:51 pm 
Offline
Addict
Addict
User avatar

Joined: Tue Oct 09, 2007 2:15 am
Posts: 984
Since PB5.6 we should better use : AllocateStructure() and FreeStructure(). It's much easier.

Code:
 Protected *XButtonData._XButton

 *XButtonData = AllocateStructure(_XButton)
 
SetGadgetData(xbtn_ID, *XButtonData)

; To free
FreeStructure(*XButtonData)


_________________
PureBasic 5.46 LTS / 5.62 (Windows x86/x64) | Windows10 Pro x64 | Z370 Extreme4 | i7 8770k | 32GB RAM | iChill GeForce GTX 980 X4 Ultra | HAF XF Evo​​
English is not my native language... (I often use DeepL to translate my texts.)


Top
 Profile  
Reply with quote  
 Post subject: Re: [Module] xButton Gadget
PostPosted: Tue Apr 24, 2018 10:49 pm 
Offline
Addict
Addict
User avatar

Joined: Tue Mar 02, 2004 1:20 pm
Posts: 953
Location: Amphibios 9
@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

_________________
Can't decide if i need a hug, an XXL coffee, 6 shots of vodka or 2 weeks of sleep.


Top
 Profile  
Reply with quote  
 Post subject: Re: [Module] xButton Gadget
PostPosted: Wed Apr 25, 2018 6:08 am 
Offline
Addict
Addict

Joined: Fri Nov 09, 2012 11:04 pm
Posts: 1581
Location: Uttoxeter, UK
@mohsen,
Great. Thank you for sharing. :D

_________________
DE AA EB


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 39 posts ]  Go to page 1, 2, 3  Next

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 10 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye