October 28, 2020, 05:57:26 AM

Author Topic: [bb] DropDown Menus! by Yahfree [ 1+ years ago ]  (Read 1072 times)

Offline BlitzBot

  • Jr. Member
  • **
  • Posts: 1
[bb] DropDown Menus! by Yahfree [ 1+ years ago ]
« on: June 29, 2017, 12:28:42 AM »
Title : DropDown Menus!
Author : Yahfree
Posted : 1+ years ago

Description : Hey, first of all i'd like to thank b32, for helping me with many problems i encountered making this..

UPDATE: Better ID system, DeleteDropDown function, Visual Arrow, width support.
Ok, this dropdown system works with types, so you will need the functions, and the types above the main program (see code)

you will also need this before everything:

"Global CursorX, CursorY, CursorHit"

and this in your main loop:

"CursorX=MouseX()
CursorY=MouseY()
CursorHit=MouseHit(1)"

to create a dropdown simply use the following

DDname.DropDown=CreateDropDown(X,Y,Width,AcceptsID)

DDname.DropDown = DDname is the handle of your dropdown basicly.. later you can use this to access stuff like the current selected item (DDnamewords)

X=X of dropdown
Y= y of dropdown
Width = width of dropdown *MUST be 25 or higher
AcceptsID = ID that the dropdown accepts more later

To add stuff to your dropdown you must have the following after your graphics setup..

"Type list
   Field name$
   Field ID
End Type"

ID is the dropdown this goes into (see createdropdown's AcceptsID)

the so if you have a dropdown that accepts ID 5 and you want this item to go into that dropdown, you delclare that items ID=5.

name$ is what the user sees in the dropdown,

to create an item do the following:

"myitem.list = New list
myitem
ame="Pick ME"
myitemID=1"

you can add more fields to the List type if you want to know more about what the user picked, for example:

"Type list
   Field name$
   Field ID
   Field number
End Type"

you access these attributes like so:

"For checklist.list = Each list
If checklist
ame=DDnamewords
print checklist
umber
end if
next"
as shown above i accessed the current "words" that the dropdown is displaying uptop.

you can access all the attributes of a dropdown by a simple: DDnameattrubute

replace ddname with your dropdown handle and atributes with the attribute you want to access.

here is the dropdown type this goes above all the functions. and below that global call of Cursor stats(see above)

"Type DropDown
Field drawdrop
Field scrolly
Field shown
Field x,y
Field words$
Field Accepts
Field DropDown_ID
End Type"

other stuff:

DrawDropDowns(handle)

you could draw all dropdowns with a for-next loop like in the code example below, or you could draw them indivisualy by feeding a dropdowns handle into it.

DeleteDropDown(handle)

This deletes a dropdown specified by the handle.

Here is an example of all of the above put into one:


Code :
Code: BlitzBasic
  1. Global CursorX, CursorY, CursorHit
  2.  
  3. Type DropDown
  4. Field width
  5. Field drawdrop
  6. Field scrolly
  7. Field shown
  8. Field x,y
  9. Field words$
  10. Field Accepts
  11. End Type
  12.  
  13. ;-----------------------------------------------------------------
  14. ;                       CreateDropDown()
  15. ;-----------------------------------------------------------------
  16.  
  17.  
  18.  
  19.  
  20. Function CreateDropDown.DropDown(x,y,dd_width,Accepted)
  21.  
  22.  
  23.  
  24. NewDD.DropDown = New DropDown
  25. NewDDx=x
  26. NewDDy=y
  27. NewDDdrawdrop=False
  28. NewDDscrolly=y+20
  29. NewDDshown=y
  30. NewDDAccepts=Accepted
  31. NewDDwidth=dd_width
  32.  
  33.  
  34. Return NewDD
  35. End Function
  36.  
  37. ;----------------------------------------------------------------
  38. ;              DrawDropDowns()
  39. ;----------------------------------------------------------------
  40.  
  41. Function DrawDropDowns(Creation_Info.DropDown)
  42.  
  43.  
  44.  
  45. drawdrop = Creation_Infodrawdrop
  46. scrolly = Creation_Infoscrolly
  47. shown = Creation_Infoshown
  48. x = Creation_Infox
  49. y = Creation_Infoy
  50. words$ = Creation_Infowords$
  51. number = Creation_InfoAccepts
  52. width = Creation_Infowidth
  53.  
  54. ;If you click on the button, dropdown=True
  55. If RectsOverlap(x+width-25,y,25,20,CursorX,CursorY,5,5) And CursorHit
  56.   If drawdrop=False
  57.      drawdrop=True
  58. Else
  59.    drawdrop=False
  60.   End If
  61. End If
  62.  
  63.  
  64.  
  65. If drawdrop=True
  66. Rect x,y,width,200,0
  67. Line x+width,y+20,x+width-12.5,y+10
  68. Line x+width-25,y+20,x+width-12.5,y+10
  69.  
  70.  
  71. ;For...Each ... should get the name of all the objects.
  72. i=0
  73. For checklist.list = Each list
  74.  
  75. If checklistID=number
  76. i=i+1
  77.  
  78. ;Made this For i...2 loop so the Text can loop itself...
  79. Viewport x,y+20,125,180
  80.    Text x,shown+(i*20),checklist
  81. ame
  82. Viewport 0,0,GraphicsWidth(),GraphicsHeight()
  83.  
  84. ;If you click on one of the names it will put it up top.
  85.     If RectsOverlap(x,shown+(i*20),width-25,20,CursorX,CursorY,5,5) And CursorX > x And CursorX< x+125 And CursorY > y+20 And CursorY < y+200 And MouseDown(1)
  86.         words$=checklist
  87. ame
  88.         drawdrop=False
  89.         shown=y
  90.         scrolly=y+20
  91.      End If
  92.  
  93.  
  94. End If
  95. Next
  96. Rect x+width-25,y+20,25,180,False
  97. If i>9
  98.  
  99.  
  100.  
  101.  
  102.    Rect x+width-25,scrolly,25,20,True
  103.   If RectsOverlap(x+width-25,y+20,25,180,CursorX,CursorY,5,5) And MouseDown(1)
  104.      scrolly=MouseY()
  105. End If
  106.  
  107.  
  108.  
  109.  
  110. If scrolly<y+20 scrolly=y+20
  111. If scrolly>y+180 scrolly=y+180
  112.  
  113. ;The more things in the Text the faster it scrolls To compensate..
  114. ScrollbarPos = ScrollY - y-20
  115. ScrollbarMax = y+180- y-20
  116. ListSize = (i - 9) * 20
  117. shown = y - (scrollbarpos * listsize / scrollbarmax)
  118.  
  119.  
  120. End If
  121.  
  122. Else
  123.  
  124. Line x+width-25,y,x+width-12.5,y+10
  125. Line x+width,y,x+width-12.5,y+10
  126.  
  127. End If
  128.  
  129.  
  130.  
  131. ;Draws the 3 main parts of the dropdown, with all the math from above: Main box, DD button,
  132. Rect x,y,width,20,0
  133. Rect x+width-25,y,25,20,0
  134. Text x,y,words
  135.  
  136.  
  137. ;Takes the Creation info and Equals it to the messed with dropdown info.
  138. Creation_Infoscrolly = scrolly
  139. Creation_Infodrawdrop = drawdrop
  140. Creation_Infoshown = shown
  141. Creation_Infowords$ = words$
  142.  
  143. End Function
  144.  
  145. ;-------------------------------------------------------------------------
  146. ;                          DeleteDropDown(DropDown_ID)
  147. ;-------------------------------------------------------------------------
  148.  
  149. Function DeleteDropDown(ID.Dropdown)
  150. Delete ID
  151. End Function
  152.  
  153. ;----------------------------------------------------------------------
  154. ;             Example program
  155. ;----------------------------------------------------------------------
  156.  
  157.  
  158.  
  159. Graphics 300,500,16,2
  160.  
  161. SetBuffer BackBuffer()
  162.  
  163. ;---------------------
  164.  
  165. Type list
  166.    Field name$
  167.    Field ID
  168. End Type
  169.  
  170. For i=1 To 200
  171.  
  172. list1.list = New list
  173. list1
  174. ame="bah"+i
  175. list1ID=1
  176.  
  177. Next
  178.  
  179. For i=1 To 400
  180.  
  181. list1.list = New list
  182. list1ID=2
  183. list1
  184. ame="test"+i
  185.  
  186. Next
  187.  
  188. ;---------------------------
  189.  
  190. dd1.DropDown=CreateDropDown(50,0,100,1) ; ID=1
  191. dd2.DropDown=CreateDropDown(180,0,100,1) ; ID=2
  192. dd3.DropDown=CreateDropDown(50,250,100,2) ; ID=3
  193. dd4.DropDown=CreateDropDown(180,250,100,2) ; ID=4
  194.  
  195. ;--------------------------------------
  196. While Not KeyHit(1)
  197. Cls
  198.  
  199. CursorX = MouseX()
  200. CursorY = MouseY()
  201. CursorHit = MouseHit(1)
  202.  
  203.  
  204. For CheckDD.DropDown = Each DropDown
  205. DrawDropDowns(CheckDD.DropDown)
  206. Next
  207.  
  208. Text 0,460,"Press 2-5 to delete Dropdowns"
  209. If KeyHit(3) DeleteDropDown(dd1)
  210. If KeyHit(4) DeleteDropDown(dd2)
  211. If KeyHit(5) DeleteDropDown(dd3)
  212. If KeyHit(6) DeleteDropDown(dd4)
  213.  
  214.  
  215.  
  216.  
  217. Delay 5
  218. Flip
  219. Wend


Comments :


Yo! Wazzup?(Posted 1+ years ago)

 b23? I think you mean b32.Nice Dropdowns!


Yahfree(Posted 1+ years ago)

 Haha, your right, Sorry >>b32<< :D


 

SimplePortal 2.3.6 © 2008-2014, SimplePortal