[bb] Custom Gadget Properties by skn3 [ 1+ years ago ]

Started by BlitzBot, June 29, 2017, 00:28:41

Previous topic - Next topic

BlitzBot

Title : Custom Gadget Properties
Author : skn3
Posted : 1+ years ago

Description : <a href="http://www.acsv.net/acsite/viewsoftware.php?id=103" target="_blank">http://www.acsv.net/acsite/viewsoftware.php?id=103</a>

This userlib uses the WindowProperties api, to assign named integers to any window/gadget.

This can be used to store a simple number with an existing window, or to assign a blitz object to a window. Blitz objects are stored as integers (image/bank/gadget/etc), so it is simply a matter of setting an integer to the handles value.

A Very simple userlib, but potentialy very powerfull!


Code :
Code (blitzbasic) Select
Below is the code from the example included in the file.
You will still need to download from http://www.acsv.net/acsite/viewsoftware.php?id=103
to get the library and userlib files.





;example
;this example demonstrates attatching blitz objects to a window.

;Include the library functions
Include "skn3gadgetobjects.bb"


;This function will create a blitz window, and a label which is pattatched to the window.
;It will store the handle to the label, as an integer in the window.
;This way, any functions that refer to this window, can fetch the panel.

Function CreateMyCustomWindow(name$,width,height,r,g,b,parent=0)
;this function creates a custom blitz window, with a background color
;it uses the CreateGadgetInt() to attatch a color panel, and store its
;handle in the window, for later use

;create gadgets
Local window = CreateWindow(name$,(ClientWidth(Desktop())/2)-(width/2),(ClientHeight(Desktop())/2)-(height/2),width,height,parent,1+2)
Local panel  = CreatePanel(0,0,ClientWidth(window),ClientHeight(window),window)
;setup gadgets
SetGadgetLayout(panel,1,1,1,1)
SetPanelColor(panel,r,g,b)
;link panel to window as a sub object
CreateGadgetInt(window,"MyCustomWindow_panel",panel)
;return blitz handle to window
Return window
End Function



;This function will obtain the nested panel object from the window, and modify its r,g,b color

Function SetMyCustomWindowColor(window,r,g,b)
SetPanelColor(GetGadgetInt(window,"MyCustomWindow_panel"),r,g,b)
End Function



;This function will obtain the nested panel, and free it, then free the window.

Function FreeMyCustomWindow(window)
FreeGadget(FreeGadgetInt(window,"MyCustomWindow_panel"))
FreeGadget(window)
End Function




;----------Main section of code----------------
Global window = CreateMyCustomWindow("Resize to change color",400,250, 255,0,0, 0)

;----------Main Loop---------------------------
Repeat
Select WaitEvent()
Case $802
SetMyCustomWindowColor(window,Rand(0,255),Rand(0,255),Rand(0,255))
Case $803
Exit
End Select
Forever

FreeMyCustomWindow(window)


Comments :


simonh(Posted 1+ years ago)

 No links please. The code archives is for posting code.


Floyd(Posted 1+ years ago)

 Personally, I don't mind links to code that is too big or, with multiple files, awkward to post.


simonh(Posted 1+ years ago)

 Links to external files is acceptable, as long as it is posted in addition to some code. Just posting a single dot defeats the point of the code archives somewhat.


skn3(Posted 1+ years ago)

 Well the file contains a userlib/library/example. What is easier, to download it as a zip .. or to have to make the files yourself.I'll post some code though if you really want.


simonh(Posted 1+ years ago)

 Thanks skn3.