15.08.2015, 19:12
Okay, I've had a look through my code, and using the built-in commands works fine for the cycle gadget, provided it doesn't have too many entries. It appears that there is a fixed amount of space allocated by the MUICycle command, and adding too many options causes trashed memory and usually a crash. I don't know what that number is or if it changes based on length of entries or what, but for up to 10 entries it should be safe and this code works fine for me:
For more entries, you need to call the muicycle custom class directly, and that's a little bit more complicated. I use this code instead of MUICycle for longer lists of options:
*cycleoptionaddrs(0) is a primitive array containing the addresses of each entry in an array containing the text of each of the entries required. It's messy, but this code can be used to define the entries, where the constant #maxoptions is the number of options, and option$ is an array containing the options required:
Setting up a notify is no problem, similar to any other gadget but using the cycle gadget specific constant #MUIA_Cycle_Active which you set up to trigger every time the active entry changes. MUINotifyApp works fine here.
Finally, reading the active entry seems to work fine for me with MUIGetCycle, but it can also be read by using:
This is the generic way of reading the attribute of any MUI object. Setting the active entry in the cycle gadget however caused me problems in the past using MUISetCycle, so I always just use:
where entry is the item to be selected. This will also trigger an event that says your cycle gadget was changed, so if this might cause a problem for your code, disable the notification for the update by adding the NoNotify tag:
The MUI Autodocs contain descriptions of al lthe constants that apply for each object type. They're quite well laid out and while the code will look a little different to the C examples, the basics are the same, and the constants are the same too except they have a # in front of the name in Blitz but not in C. General rule for the MUI constants, those starting with #MUIA_ are attributes, #MUIM_ are methods, #MUIV_ are special values specific to the objects in question, and #MUII_ are MUI images.
Hope that helps!
Code:
WBStartup
WbToScreen 0
optimize 5
Syntax 2
; *** MUI Object Constants
#main_window=0
#main_app=1
#main_group=2
#main_cycle=3
#main_vspace=4
#main_quit=5
; *** MUI Event Constants
#ev_main_close=-1
#ev_main_cycle=1
#ev_main_quit=2
; *** End of MUI Constants
MUIApplicationTitle "MUI Cycle Test"
MUIApplicationVersion "$VER: MUICycleTest 1.0 (15.08.2015)"
MUIApplicationCopyright "(c)2015, Rob Cranley"
MUIApplicationAuthor "Rob Cranley"
MUIApplicationDescription "MUI Cycle Gadget Test"
MUIApplicationBase "MUICYCLETEST"
; *** Create MUI gadgets for main window
NPrint "Creating main window gadgets..."
MUICycle #main_cycle,"Test 1","Cycle Option 2","Option 3","Something something","5th Option"
MUIVSpace #main_vspace,0
MUIKeyButton #main_quit,"Quit","q"
NPrint "Creating overall group..."
MUIAddObjsVGroup #main_group,#main_cycle,#main_vspace,#main_quit
MUICreateVGroup #main_group
NPrint "Creating main window..."
MUIAddTags #main_window,#MUIA_Window_AppWindow,1
MUICreateWindow #main_window,"MUI Cycle Test","MAIN",#main_group
MUIAddSubWindow #main_window
If MUICreateApplication=False Then NPrint "Unable to create MUI application!!":End
MUIApplicationObj #main_app
; *** MUI Notifies
NPrint "Setting up notifies"
MUINotifyApp #main_window,#MUIA_Window_CloseRequest,1,#ev_main_close
MUINotifyApp #main_cycle,#MUIA_Cycle_Active,#MUIV_EveryTime,#ev_main_cycle
MUINotifyApp #main_quit,#MUIA_Pressed,0,#ev_main_close
NPrint "Opening main window..."
If MUIOpenWindow(#main_window)=False Then NPrint "Error opening window":End
; *** Main Loop
Repeat
ev.l=MUIWaitEvent
If ev
NPrint "MUI Event: ",ev
Select ev
Case #ev_main_cycle
Print "Cycle option changed to "
NPrint MUIGetCycle(#main_cycle)
Case #ev_main_close
quit.b=True
End Select
End If
Until quit
MUICloseWindow #main_window
End
For more entries, you need to call the muicycle custom class directly, and that's a little bit more complicated. I use this code instead of MUICycle for longer lists of options:
Code:
MUINewObject #main_cycle,"Cycle.mui",#MUIA_Cycle_Entries,&*cycleoptionaddrs(0)
Code:
For i=0 To #maxoptions-1
Read x$
option$(i)=x$
*cycleoptionaddrs(i)=&option$(i)
Next i
option$(#maxoptions)="Null!" ; Not necessary but good to catch bugs in case the option count is too big
*steptypeaddrs(#maxoptions)=Null ; Marks the end of the list for MUI
Data$ "Entry 1","Option 2","Cycle list 3" ; Add #maxoptions of strings here.
Setting up a notify is no problem, similar to any other gadget but using the cycle gadget specific constant #MUIA_Cycle_Active which you set up to trigger every time the active entry changes. MUINotifyApp works fine here.
Finally, reading the active entry seems to work fine for me with MUIGetCycle, but it can also be read by using:
Code:
result=MUIGet(#main_cycle,#MUIA_Cycle_Active)
Code:
MUISet #main_cycle,#MUIA_Cycle_Active,entry
Code:
MUISet #main_cycle,#MUIA_NoNotify,1,#MUIA_Cycle_Active,entry
The MUI Autodocs contain descriptions of al lthe constants that apply for each object type. They're quite well laid out and while the code will look a little different to the C examples, the basics are the same, and the constants are the same too except they have a # in front of the name in Blitz but not in C. General rule for the MUI constants, those starting with #MUIA_ are attributes, #MUIM_ are methods, #MUIV_ are special values specific to the objects in question, and #MUII_ are MUI images.
Hope that helps!