Ooops
November 30, 2020, 02:39:27 AM

Author Topic: [bb] Custom Gadget Properties by skn3 [ 1+ years ago ]  (Read 619 times)

Offline BlitzBot

  • Jr. Member
  • **
  • Posts: 1
[bb] Custom Gadget Properties by skn3 [ 1+ years ago ]
« on: June 29, 2017, 12:28:41 AM »
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[/url]

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
  1. Below is the code from the example included in the file.
  2. You will still need to download from http://www.acsv.net/acsite/viewsoftware.php?id=103
  3. to get the library and userlib files.
  4.  
  5.  
  6.  
  7.  
  8.  
  9. ;example
  10. ;this example demonstrates attatching blitz objects to a window.
  11.  
  12. ;Include the library functions
  13. Include "skn3gadgetobjects.bb"
  14.  
  15.  
  16. ;This function will create a blitz window, and a label which is pattatched to the window.
  17. ;It will store the handle to the label, as an integer in the window.
  18. ;This way, any functions that refer to this window, can fetch the panel.
  19.  
  20. Function CreateMyCustomWindow(name$,width,height,r,g,b,parent=0)
  21.         ;this function creates a custom blitz window, with a background color
  22.         ;it uses the CreateGadgetInt() to attatch a color panel, and store its
  23.         ;handle in the window, for later use
  24.  
  25.         ;create gadgets
  26.         Local window = CreateWindow(name$,(ClientWidth(Desktop())/2)-(width/2),(ClientHeight(Desktop())/2)-(height/2),width,height,parent,1+2)
  27.         Local panel  = CreatePanel(0,0,ClientWidth(window),ClientHeight(window),window)
  28.         ;setup gadgets
  29.         SetGadgetLayout(panel,1,1,1,1)
  30.         SetPanelColor(panel,r,g,b)
  31.         ;link panel to window as a sub object
  32.         CreateGadgetInt(window,"MyCustomWindow_panel",panel)
  33.         ;return blitz handle to window
  34.         Return window
  35. End Function
  36.  
  37.  
  38.  
  39. ;This function will obtain the nested panel object from the window, and modify its r,g,b color
  40.  
  41. Function SetMyCustomWindowColor(window,r,g,b)
  42.         SetPanelColor(GetGadgetInt(window,"MyCustomWindow_panel"),r,g,b)
  43. End Function
  44.  
  45.  
  46.  
  47. ;This function will obtain the nested panel, and free it, then free the window.
  48.  
  49. Function FreeMyCustomWindow(window)
  50.         FreeGadget(FreeGadgetInt(window,"MyCustomWindow_panel"))
  51.         FreeGadget(window)
  52. End Function
  53.  
  54.  
  55.  
  56.  
  57. ;----------Main section of code----------------
  58. Global window = CreateMyCustomWindow("Resize to change color",400,250, 255,0,0, 0)
  59.  
  60. ;----------Main Loop---------------------------
  61. Repeat
  62.         Select WaitEvent()
  63.                 Case $802
  64.                         SetMyCustomWindowColor(window,Rand(0,255),Rand(0,255),Rand(0,255))
  65.                 Case $803
  66.                         Exit
  67.         End Select
  68. Forever
  69.  
  70. 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.


 

SimplePortal 2.3.6 © 2008-2014, SimplePortal