Author Topic: GUI / MEM libraries (Alpha versions)  (Read 703 times)

DSMan195276

  • Hero Member
  • *****
  • Posts: 1996
  • Yes
    • Email
GUI / MEM libraries (Alpha versions)
« on: February 03, 2013, 01:16:39 AM »
I've been working on these libraries as they're being used in my FTP program that I'm also working on. The GUI library is text only but currently supports the following elements:

Boxes (Such as borders for dialog boxes)
Input boxes
Text boxes
List boxes
Drop-Downs
Check-boxes
Menus
Buttons
Radio Buttons
Labels

That's what I've implemented so far, though I'm happy to implement other elements that you think would be helpful. I think right now though it's a good set of gui elements without having to much bloat. Moving on though, I'm saying it's in 'Alpha' version right now because I'm not 100% on if I'll keep it like it is or change it a bit, and once I have a full release I don't want to break any compatibility. Also, now that there is a working version of this library I'll be working on some optimization to reduce it's CPU usage and speed it up a bit, though that's not to say it's slow right now.

To use the library, just download the zip file and extract it into your qb64 folder. If it's done right, you should have two new folders 'gui_library' and 'mem_library'. After that you're fine to use the library be including the files in those folders. I would compile the example program I have which uses all the GUI elements to test it out. I would also take a look at the code of the example to learn how it works and how to use it, though again the libraries syntax is currently subject to change, though at this point seems unlikely it'll have many big changes besides bug fixes.

In the zip is also my documentation on the library, which is currently 8 pages long. Admittedly the documentation isn't amazing but it does explain everything (And I'm happy to answer any questions if you have them). Looking at the example code using the library will probably be more helpful though as it shows a practical usage of all the current elements. If you want to take a look at what it looks like, I attached a screen-shot of the GUI system with several elements used and a menu open.

The memory library part is an updated version of the other array/string in TYPE's library that I wrote. It's more focused on just handling strings and arrays of strings in TYPE's though. The reason it's separate is that I'm also writing a FTP library which uses the same MEM commands, and having them as a separate library just makes things easier.

Please download it, mess with it, and let me know what you'd like to see changed or what blew up. Thanks,

Github for this project: https://github.com/DSMan195276/qb64_ftp_client/tree/working_branch
See 'gui_library' folder -- I do my development in the branch 'working_branch' and there is no guarantee that it will compile at any given time. Currently in the 'master' branch is the last version of my FTP client before I started splitting up the GUI code and focusing on that.

Matt

Update (4/21/2013):
Another Alpha update. The event system is implemented and all of the internal workings now work off of that event system (Making a lot of transparency between how it works outside of the system and how it works inside). Because of some discrepancies between how click events were handled on the old system vs. the new system, not everything acts perfectly and I will be updating the behavior of the elements, however that's a somewhat lower priority then just getting everything working. Currently, All mouse based events and key based events work as needed. Take a look at gui_example.bas to see the changes (Namely, there is now a look for events in the general structure for the GUI loop). This is just an alpha so there isn't any concrete documentation yet.
« Last Edit: April 21, 2013, 07:14:44 AM by DSMan195276 »
"Cast your cares on the Lord and he will sustain you; he will never let the righteous be shaken" -- Psalm 55:22
QB64 Linux Installer

LINUXQB64gltester

  • Full Member
  • ***
  • Posts: 241
    • Anyone that likes Art
Re: GUI / MEM libraries (Alpha versions)
« Reply #1 on: March 17, 2013, 10:42:32 AM »
Hi, Matt,
 I am trying to create a menu, for a project I am working on, so I had done a "search", here on qb64 SMF search,  this is the first thing that comes up,
 For years now, I have tried to avoid using librarys, of any kind, but maybe it is time for me to try to start learning more on that.  I did download the zip files, and compiled,  "GUI_example.bas "
 I did make some change in the paths it uses, to find these:
Code: [Select]
'$include:'mem_lib.bi'
'$include:'gui_lib.bi'   
I have it all in one folder, now, so anyway, it seems to compile fine, and appears like it would work,
but I am not sure as to what to do, next, or how to use it ?  Can I create a menu with it ? then save the file. ?   
   I also looked at your https://github.com/DSMan195276/qb64_ftp_client/tree/working_branch  That is nice, interesting, it is very similar to the qb64 repository, ( I think) anyway appears that way),... What I am looking for, would be a very basic menu, about 4 choices, 1 of which is the "quit" option, but I would like it to be easy to edit, so as the program I am working on developes, I can add more options, as needed , easily,..if using a library and doing that way is better, then I guess I need to learn more about this,.. so that is why I am here,
ok well for now that is all from Garry
oh here is a screen shot,
For off topic discussions :
Non-QB64 Related Discussion Forum
Also
My Experimenting Forum
"QB64 has a great future!"

DSMan195276

  • Hero Member
  • *****
  • Posts: 1996
  • Yes
    • Email
Re: GUI / MEM libraries (Alpha versions)
« Reply #2 on: March 17, 2013, 01:59:33 PM »
Hi Garry,

Glad to see someone's taking a bit of interest in this besides me :). Yes the repo I'm using is very similar to QB64's, it's the same kind of thing, I just summit all my changes and updates to it so that it's easier to manage.

The menu system is fairly flexible, though it is a bit more complex then other menu system since it supports a bit more options then some others. The documentation is slightly lacking right now since it's all still being worked on (Specifically I just got multi-sub menus implemented in menus a few days ago -- Only the mouse works with them currently though). While the code is still be developed and subject to a bit of change, I don't intend on changing the structure much (I do intend to change the event handling, but that will come later and shouldn't cause any big changes for the menus). The Menu is text only (Which may be good or bad depending on your program). This should still work with a graphical screen, but may not be as convenient to use. If you want graphical menus Ritchie has a nice library for them. But on with a quick example of making a simple menu with my gui system:

Code: [Select]
'$include:'mem_lib.bi'
'$include:'gui_lib.bi'

gui_init

'Even though you have one element, the menu, you need an array to send to the gui commands
'This does make it easy to expand if you ever add more elements later.
DIM gui(1) as GUI_element_type
DIM base_menu(10) as GUI_menu_item_type 'This array is for the base horizontal menu
DIM File_menu(10) as GUI_menu_item_type 'This array is for the options in the 'File' menu

gui(1).type = GUI_MENU
GUI_init_element gui(1), "Menu"
gui(1).row1 = 1 'Row the menu will be displayed on
gui(1).col1 = 1 'Column the menu will start on
gui(1).col2 = 80 'Column the menu will end on
gui(1).menu_padding = 2 'Put the spaces of padding before the first option -- Looks a bit nicer
'Note these flags only apply to the most recent version of the GUI library
gui(1).flags = gui(1).flags OR GUI_FLAG_SKIP OR GUI_FLAG_SHADOW

' --- Below are the flags for the old version -- You can try these if you want to just do a quick test.
'I'll hopefully have a copy of the new version ready for download sometime this week.
'gui(1).skip = -1
'gui(1).shadow = -1

'The MEM_put_str command is used to put a string into one of my 'MEM_string_type' variables
'You can think of a MEM_string_type as just a regular string, the only difference being to set its value, you use MEM_put_str
'Each menu option's name is a MEM_string_type
'The character after the '#', if it is there, will be the one used for 'Alt' if you want that functionality in the menu.
MEM_put_str base_menu(1).nam, "#File"

'Now we attach our base menu to our GUI_MENU GUI_element_type variable
''gui(1)' is our GUI_MENU element that we already made
' 1 is the number of elements in our base menu (In this case, it's just one, 'File')
'_OFFSET(base_menu(1)) just means to send the _OFFSET of our first element in our array
'Don't worry about the _OFFSET stuff does really, just remember to send the _OFFSET of the first element of the array
GUI_attach_base_menu gui(1), 1, _OFFSET(base_menu(1))

'Now we create all the options for the 'File' menu. -- This is the array 'file_menu()'
'We set the 'nam' strings to what we want displayed, and then we set the 'ident' strings to a 5 character long string that we will use internally to recognize this option.
'The reason for using the 'ident' strings is so you don't have to refer to a menu option by it's place in the menu, just by it's identifier
MEM_put_str file_menu(1).nam, "Option 1": file_menu(1).ident = "OPTN1"
MEM_put_str file_menu(2).nam, "Option 2": file_menu(2).ident = "OPTN2"
MEM_put_Str file_menu(3).nam, "Option 3": file_menu(3).ident = "OPTN3"
MEM_put_str file_menu(4).nam, "Exit": file_menu(4).ident = "EXIT "

'Same syntax as before
'base_menu(1), is the menu we want to attach to
'4 is the number of options we have
'_OFFSET(file_menu(1)) is just the offset to the first element in our array of options.
GUI_attach_menu base_menu(1), 4, _OFFSET(file_menu(1))

'Now we're done creating the menu, all that's left to do is display this menu and handle options from it

DO: _LIMIT 100 'Main code loop -- Limit to lower CPU usage

  IF GUI_update_screen(gui(), 1, selected_gui) then
    GUI_draw_element_array gui(), 1, selected_gui
  end if

  g_clicked = GUI_mouse_range(gui(), 1, selected_gui)

  key$ = GUI_inkey$(gui(), 1, selected_gui)

  'From here, you can continue with your code as normal, using 'key$' as the return from INKEY$
  'Also GUI_MX, GUI_MY, and GUI_BUT tell you the state of the mouse (Location and whether a click is happening)
 
  'Flags are used in the most recent version
  if gui(1).flags AND GUI_FLAG_MENU_CHOSEN then
    'Reset the flag
    gui(1).flags = gui(1).flags AND NOT GUI_FLAG_MENU_CHOSEN

    i$ = gui(1).menu_choice 'This is the 'ident' string of the selected menu choice

    'Set the menu to be updated and redraw it so the menu doesn't display like it's still open
    gui(1).flags = gui(1).flags OR GUI_FLAG_UPDATED

    'Redraw screen so menu doesn't show before opening menu choice
    GUI_draw_element_array gui(), 1, selected_gui

   'From here, you process the i$ string, by checking if it is equal to any of the options above:
    IF i$ = "OPTN1" THEN
      locate 2, 1
      print "Option 1"
    elseif i$ = "OPTN2" then
      locate 2, 1
      print "Option 2"
    elseif i$ = "OPTN3" then
      locate 3, 1
      print "Option 3"
    elseif i$ = "EXIT " then
      END
    end if
  end if

loop until key$ = chr$(27) 'Loop until ESC key

END

'$include:'mem_lib.bm'
'$include:'gui_lib.bm'

I can't test that code just yet, so It may not compile and have a few typos (And if you don't have the repo version of the library, which I'm willing to guess you don't, then it also won't compile). That code should give you at least the very basic idea of the menu system, if you want to get more of an idea then I would suggest modifying the menu in the GUI_example.bas code and go from there.

Once I have the newest version of the GUI library done I'll make sure to create a proper menu example so you can easily see how the menu works. The system isn't to complicated (And offers what I think is very nice flexibility) but it may take just a little bit to wrap your head around it.

Depending on how simple you need the menu, you may want to consider just writing it yourself as that will be much easier to integrate into your program. However libraries like mine and Ritchie's can make it much easier and make debugging take less time if what it offers is really all you need.

Matt
"Cast your cares on the Lord and he will sustain you; he will never let the righteous be shaken" -- Psalm 55:22
QB64 Linux Installer

LINUXQB64gltester

  • Full Member
  • ***
  • Posts: 241
    • Anyone that likes Art
Re: GUI / MEM libraries (Alpha versions)
« Reply #3 on: March 17, 2013, 02:52:53 PM »
Quote
  Depending on how simple you need the menu, you may want to consider just writing it yourself as that will be much easier to integrate into your program.

  Ok, yes that is the easiest, but at the same time, also, especially,
Quote
If you want graphical menus Ritchie has a nice library for them
I do have that in mind,
a menu that uses thumbnail images,and text,  so thanks on this,
 Yours is still interesting to me though too, and it will be a while before I am really ready for the menu, so we will see how that goes,
Quote
And if you don't have the repo version of the library, which I'm willing to guess you don't, then it also won't compile
I have part, but I all ready saw that, it was your more recent example
 But I did not have any of the new includes ,IE:
Code: [Select]
'$include:'dialogs/prompt.bi' There were a lot more,  I did not notice, but from what I saw with the HQtortise, "plugin" or software,,..I can create a clone, on my computer, just like I did with the qb64 one,..? That seems like that would be best, so I have everything,..thanks
Edited: Boy that was easy, I saw, where it (https://github.com/DSMan195276/qb64_ftp_client/tree/working_branch ) has the .zip, option, and downloaded all of it, no need for HQ tortise, ...ok well now I can set up a folder, and work with this.
thanks again
« Last Edit: March 17, 2013, 03:19:09 PM by LINUXQB64gltester »
For off topic discussions :
Non-QB64 Related Discussion Forum
Also
My Experimenting Forum
"QB64 has a great future!"

DSMan195276

  • Hero Member
  • *****
  • Posts: 1996
  • Yes
    • Email
Re: GUI / MEM libraries (Alpha versions)
« Reply #4 on: March 17, 2013, 03:44:13 PM »
One of the nice things about github is that you can download the entire repo as a zip. Just download this. Just unzip that to a directory and you can use the most current repo version (GUI_example.bas *should* compile, text_editor.bas won't, and ftp-main.bas may or may-not compile).

If you're hoping to use thumbnail images then this probably isn't what you want sadly, I'd take a look at Ritchie's work since that's already graphical and probably wouldn't take a *ton* of time to modify to have thumbnail images and such. I have considered converting this into a graphical GUI, but I have to say I like the text look, and it simplifies the entire thing greatly. Converting this setup from text into graphical wouldn't take a *ton* of work, however it would take some work to keep it working with both text and graphics and since I currently don't have a ton of use for graphical GUI's it's not a huge focus on mine.

As for the other files that I'm including, those are mostly for testing purposes. Since my dialogs (Like prompt.bm, ftp_connect.bm, etc.) are singular files, I can easily test their GUI by simply commenting out parts of the file except for the GUI portion and the compiling it in with GUI_example.bas. If you find GUI_example.bas isn't compiling, then you should comment out all of the includes except for gui_lib and mem_lib, and the comment out all of the lines the IDE tells you it can't figure out (They'll be function calls to routines contained in those files, mostly at the end of the code in the section where I process the menu choice.). After that it should compile fine. I would only use the menu's with the mouse as I've noted, using the arrow keys currently doesn't work yet.

Matt
"Cast your cares on the Lord and he will sustain you; he will never let the righteous be shaken" -- Psalm 55:22
QB64 Linux Installer

small no more

  • Sr. Member
  • ****
  • Posts: 256
  • Ask and you will receive, Seek and you will find
    • not launched
Re: GUI / MEM libraries (Alpha versions)
« Reply #5 on: March 22, 2013, 02:18:34 AM »
I am getting an error when I load the includes files.


Undefined type in line 10 of C:/gui/gui_lib.bi included on line 1


this is the error line in gui_lib.bi file on line 10

nam as MEM_string_type 'Displayed string for MENU choice
A good teacher must be able to put himself in the place of those who find learning hard.


                                           Eliphas Levi

DSMan195276

  • Hero Member
  • *****
  • Posts: 1996
  • Yes
    • Email
Re: GUI / MEM libraries (Alpha versions)
« Reply #6 on: March 22, 2013, 08:55:06 AM »
Did you make sure to include the mem/mem_lib.bi file before the gui_lib.bi file? You should have two lines at the code of your code in this order:

Code: [Select]
'$include:'mem_lib/mem_lib.bi'
'$include:'gui_lib/gui_lib.bi'

Of course the paths can be different, they have to be in that order though because the GUI stuff uses some of the MEM stuff (mainly the strings from the MEM library.).

Matt

Edit: I should have noted, you will also need to include 'mem_lib.bm' at the end of your program. If you don't you'll get errors about functions with names starting with "MEM_". QB64's IDE should flag them automatically so it should be easy to catch and fix if this is the case.
« Last Edit: March 23, 2013, 12:10:24 AM by DSMan195276 »
"Cast your cares on the Lord and he will sustain you; he will never let the righteous be shaken" -- Psalm 55:22
QB64 Linux Installer

small no more

  • Sr. Member
  • ****
  • Posts: 256
  • Ask and you will receive, Seek and you will find
    • not launched
Re: GUI / MEM libraries (Alpha versions)
« Reply #7 on: March 24, 2013, 12:06:36 AM »
I have the latest repo of qb64 and copied your program and still get an error.

this program code from above

Code: [Select]
'$include:'mem_lib.bi'
'$include:'gui_lib.bi'

gui_init

'Even though you have one element, the menu, you need an array to send to the gui commands
'This does make it easy to expand if you ever add more elements later.
DIM gui(1) as GUI_element_type
DIM base_menu(10) as GUI_menu_item_type 'This array is for the base horizontal menu
DIM File_menu(10) as GUI_menu_item_type 'This array is for the options in the 'File' menu

gui(1).type = GUI_MENU
GUI_init_element gui(1), "Menu"
gui(1).row1 = 1 'Row the menu will be displayed on
gui(1).col1 = 1 'Column the menu will start on
gui(1).col2 = 80 'Column the menu will end on
gui(1).menu_padding = 2 'Put the spaces of padding before the first option -- Looks a bit nicer
'Note these flags only apply to the most recent version of the GUI library
gui(1).flags = gui(1).flags OR GUI_FLAG_SKIP OR GUI_FLAG_SHADOW

' --- Below are the flags for the old version -- You can try these if you want to just do a quick test.
'I'll hopefully have a copy of the new version ready for download sometime this week.
'gui(1).skip = -1
'gui(1).shadow = -1

'The MEM_put_str command is used to put a string into one of my 'MEM_string_type' variables
'You can think of a MEM_string_type as just a regular string, the only difference being to set its value, you use MEM_put_str
'Each menu option's name is a MEM_string_type
'The character after the '#', if it is there, will be the one used for 'Alt' if you want that functionality in the menu.
MEM_put_str base_menu(1).nam, "#File"

'Now we attach our base menu to our GUI_MENU GUI_element_type variable
''gui(1)' is our GUI_MENU element that we already made
' 1 is the number of elements in our base menu (In this case, it's just one, 'File')
'_OFFSET(base_menu(1)) just means to send the _OFFSET of our first element in our array
'Don't worry about the _OFFSET stuff does really, just remember to send the _OFFSET of the first element of the array
GUI_attach_base_menu gui(1), 1, _OFFSET(base_menu(1))

'Now we create all the options for the 'File' menu. -- This is the array 'file_menu()'
'We set the 'nam' strings to what we want displayed, and then we set the 'ident' strings to a 5 character long string that we will use internally to recognize this option.
'The reason for using the 'ident' strings is so you don't have to refer to a menu option by it's place in the menu, just by it's identifier
MEM_put_str file_menu(1).nam, "Option 1": file_menu(1).ident = "OPTN1"
MEM_put_str file_menu(2).nam, "Option 2": file_menu(2).ident = "OPTN2"
MEM_put_Str file_menu(3).nam, "Option 3": file_menu(3).ident = "OPTN3"
MEM_put_str file_menu(4).nam, "Exit": file_menu(4).ident = "EXIT "

'Same syntax as before
'base_menu(1), is the menu we want to attach to
'4 is the number of options we have
'_OFFSET(file_menu(1)) is just the offset to the first element in our array of options.
GUI_attach_menu base_menu(1), 4, _OFFSET(file_menu(1))

'Now we're done creating the menu, all that's left to do is display this menu and handle options from it

DO: _LIMIT 100 'Main code loop -- Limit to lower CPU usage

  IF GUI_update_screen(gui(), 1, selected_gui) then
    GUI_draw_element_array gui(), 1, selected_gui
  end if

  g_clicked = GUI_mouse_range(gui(), 1, selected_gui)

  key$ = GUI_inkey$(gui(), 1, selected_gui)

  'From here, you can continue with your code as normal, using 'key$' as the return from INKEY$
  'Also GUI_MX, GUI_MY, and GUI_BUT tell you the state of the mouse (Location and whether a click is happening)

  'Flags are used in the most recent version
  if gui(1).flags AND GUI_FLAG_MENU_CHOSEN then
    'Reset the flag
    gui(1).flags = gui(1).flags AND NOT GUI_FLAG_MENU_CHOSEN

    i$ = gui(1).menu_choice 'This is the 'ident' string of the selected menu choice

    'Set the menu to be updated and redraw it so the menu doesn't display like it's still open
    gui(1).flags = gui(1).flags OR GUI_FLAG_UPDATED

    'Redraw screen so menu doesn't show before opening menu choice
    GUI_draw_element_array gui(), 1, selected_gui

   'From here, you process the i$ string, by checking if it is equal to any of the options above:
    IF i$ = "OPTN1" THEN
      locate 2, 1
      print "Option 1"
    elseif i$ = "OPTN2" then
      locate 2, 1
      print "Option 2"
    elseif i$ = "OPTN3" then
      locate 3, 1
      print "Option 3"
    elseif i$ = "EXIT " then
      END
    end if
  end if

loop until key$ = chr$(27) 'Loop until ESC key

END

'$include:'mem_lib.bm'
'$include:'gui_lib.bm'


gives me this error

Element not defined on line 12

line 12 reads

gui(1).type = GUI_MENU
A good teacher must be able to put himself in the place of those who find learning hard.


                                           Eliphas Levi

DSMan195276

  • Hero Member
  • *****
  • Posts: 1996
  • Yes
    • Email
Re: GUI / MEM libraries (Alpha versions)
« Reply #8 on: March 24, 2013, 07:14:11 AM »
Sorry, that's my fault, I should have tested the program before putting it up. 'type' needs to become 'element_type' and then it should work. You should note when you try this program, since nothing is draw under where the menu's are going to pop-up, they menu will not be erased from the program's screen when the menus closes. The reason this happens is because I didn't add another GUI element that covers the rest of the screen. It's simple enough to do and I could modify this example a bit to show that if wanted. I would recommend taking a look at the gui_example.bas code too as that is probably a better example then this code:

Code: [Select]
'$include:'mem_lib.bi'
'$include:'gui_lib.bi'

gui_init

'Even though you have one element, the menu, you need an array to send to the gui commands
'This does make it easy to expand if you ever add more elements later.
DIM gui(1) as GUI_element_type
DIM base_menu(10) as GUI_menu_item_type 'This array is for the base horizontal menu
DIM File_menu(10) as GUI_menu_item_type 'This array is for the options in the 'File' menu

gui(1).element_type = GUI_MENU
GUI_init_element gui(1), "Menu"
gui(1).row1 = 1 'Row the menu will be displayed on
gui(1).col1 = 1 'Column the menu will start on
gui(1).col2 = 80 'Column the menu will end on
gui(1).menu_padding = 2 'Put the spaces of padding before the first option -- Looks a bit nicer
'Note these flags only apply to the most recent version of the GUI library
gui(1).flags = gui(1).flags OR GUI_FLAG_SKIP OR GUI_FLAG_SHADOW

' --- Below are the flags for the old version -- You can try these if you want to just do a quick test.
'I'll hopefully have a copy of the new version ready for download sometime this week.
'gui(1).skip = -1
'gui(1).shadow = -1

'The MEM_put_str command is used to put a string into one of my 'MEM_string_type' variables
'You can think of a MEM_string_type as just a regular string, the only difference being to set its value, you use MEM_put_str
'Each menu option's name is a MEM_string_type
'The character after the '#', if it is there, will be the one used for 'Alt' if you want that functionality in the menu.
MEM_put_str base_menu(1).nam, "#File"

'Now we attach our base menu to our GUI_MENU GUI_element_type variable
''gui(1)' is our GUI_MENU element that we already made
' 1 is the number of elements in our base menu (In this case, it's just one, 'File')
'_OFFSET(base_menu(1)) just means to send the _OFFSET of our first element in our array
'Don't worry about the _OFFSET stuff does really, just remember to send the _OFFSET of the first element of the array
GUI_attach_base_menu gui(1), 1, _OFFSET(base_menu(1))

'Now we create all the options for the 'File' menu. -- This is the array 'file_menu()'
'We set the 'nam' strings to what we want displayed, and then we set the 'ident' strings to a 5 character long string that we will use internally to recognize this option.
'The reason for using the 'ident' strings is so you don't have to refer to a menu option by it's place in the menu, just by it's identifier
MEM_put_str file_menu(1).nam, "Option 1": file_menu(1).ident = "OPTN1"
MEM_put_str file_menu(2).nam, "Option 2": file_menu(2).ident = "OPTN2"
MEM_put_Str file_menu(3).nam, "Option 3": file_menu(3).ident = "OPTN3"
MEM_put_str file_menu(4).nam, "Exit": file_menu(4).ident = "EXIT "

'Same syntax as before
'base_menu(1), is the menu we want to attach to
'4 is the number of options we have
'_OFFSET(file_menu(1)) is just the offset to the first element in our array of options.
GUI_attach_menu base_menu(1), 4, _OFFSET(file_menu(1))

'Now we're done creating the menu, all that's left to do is display this menu and handle options from it

DO: _LIMIT 100 'Main code loop -- Limit to lower CPU usage

  IF GUI_update_screen(gui(), 1, selected_gui) then
    GUI_draw_element_array gui(), 1, selected_gui
  end if

  g_clicked = GUI_mouse_range(gui(), 1, selected_gui)

  key$ = GUI_inkey$(gui(), 1, selected_gui)

  'From here, you can continue with your code as normal, using 'key$' as the return from INKEY$
  'Also GUI_MX, GUI_MY, and GUI_BUT tell you the state of the mouse (Location and whether a click is happening)

  'Flags are used in the most recent version
  if gui(1).flags AND GUI_FLAG_MENU_CHOSEN then
    'Reset the flag
    gui(1).flags = gui(1).flags AND NOT GUI_FLAG_MENU_CHOSEN

    i$ = gui(1).menu_choice 'This is the 'ident' string of the selected menu choice

    'Set the menu to be updated and redraw it so the menu doesn't display like it's still open
    gui(1).flags = gui(1).flags OR GUI_FLAG_UPDATED

    'Redraw screen so menu doesn't show before opening menu choice
    GUI_draw_element_array gui(), 1, selected_gui

   'From here, you process the i$ string, by checking if it is equal to any of the options above:
    IF i$ = "OPTN1" THEN
      locate 8, 1
      print "Option 1"
    elseif i$ = "OPTN2" then
      locate 8, 1
      print "Option 2"
    elseif i$ = "OPTN3" then
      locate 8, 1
      print "Option 3"
    elseif i$ = "EXIT " then
      END
    end if
  end if

loop until key$ = chr$(27) 'Loop until ESC key

END

'$include:'mem_lib.bm'
'$include:'gui_lib.bm'

Matt
"Cast your cares on the Lord and he will sustain you; he will never let the righteous be shaken" -- Psalm 55:22
QB64 Linux Installer

EricR

  • Jr. Member
  • **
  • Posts: 68
  • Loading Humor.sys on boot should be mandatory
    • Email
Re: GUI / MEM libraries (Alpha versions)
« Reply #9 on: March 27, 2013, 03:12:33 PM »

I have 2 questions on this GUI library you are coding.
01) Do you have even a rough guess when the next alpha will be uploaded?  I do want to try this GUI form building you are donating to the group.  I just want it to be a good bit more finished lest you change things around and I get lost. 
02) Can I safely assume that in due time it will run on QB64GL?  I am taking a serious liking to the new QB64 and I do not want to go back to SDL version if I can help it. 


DSMan195276

  • Hero Member
  • *****
  • Posts: 1996
  • Yes
    • Email
Re: GUI / MEM libraries (Alpha versions)
« Reply #10 on: March 27, 2013, 04:03:31 PM »
I have 2 questions on this GUI library you are coding.
01) Do you have even a rough guess when the next alpha will be uploaded?  I do want to try this GUI form building you are donating to the group.  I just want it to be a good bit more finished lest you change things around and I get lost. 
02) Can I safely assume that in due time it will run on QB64GL?  I am taking a serious liking to the new QB64 and I do not want to go back to SDL version if I can help it. 

1. Fairly soon I'm expecting.  The current plan is to finish up all the sub-menu stuff (It works with the mouse, and is almost done for using keys). After that I'll test it to make sure it's stable, fix up any bugs I find and then put out the next Alpha. It really just depends when I get enough time to finish up the menu stuff (I'm working on it right now actually, I may finish it up soon with that in mind). After the menu stuff is sufficiently done, all that's left is to work out a few more systems for the GUI before putting out a beta. I plan to get a much better event system working (What I have in mind really shouldn't be to bad to implement, it's not meant to be complex). The current system for detecting GUI events is very lacking in what it can and can't catch, so the new system will remedy that and also provide a good base for adding in new events for the future if needed. Unless I see a need for something else, that will probably be the last addition before the release.

2. I've been making sure that the code currently runs on both the latest GL as well as the SDL version. Until GL has an official release as QB64, I intend to make sure both options are supported. Once GL becomes the official version and a sufficient transfer period goes by, then I'll start considering breaking SDL compatibility, though I won't do it unless there are some GL specific things that the GUI needs to be able to tend to.

Matt
"Cast your cares on the Lord and he will sustain you; he will never let the righteous be shaken" -- Psalm 55:22
QB64 Linux Installer

EricR

  • Jr. Member
  • **
  • Posts: 68
  • Loading Humor.sys on boot should be mandatory
    • Email
Re: GUI / MEM libraries (Alpha versions)
« Reply #11 on: March 28, 2013, 12:22:41 PM »
Thanks

When you have a working beta even a early one, I do have 2 active development apps as well as 3 apps on dev standby that can benefit from your gui work. It sounds like your next release will be a beta even if it is labeled an alpha. 


DSMan195276

  • Hero Member
  • *****
  • Posts: 1996
  • Yes
    • Email
Re: GUI / MEM libraries (Alpha versions)
« Reply #12 on: March 30, 2013, 01:17:43 AM »
I just updated the .zip and gui_example.bas code on here to the latest version. It's not without it's problems. If you run into bugs please let me know what you were doing at the time and what all happened. Besides some basic bug fixes and possibly a bit of changes in the mouse system the code is largely what the beta will look like (Of course, I'll be updating the internals a bit and adding the event system). While it may be worth looking over this code and testing it out, I would recommend holding off on implementing it just yet, as when I implement the event system it will end-up breaking your code, and internal changes to the setup are still open at this point (Though unlikely seeing as the current setup is working just fine).

Matt
"Cast your cares on the Lord and he will sustain you; he will never let the righteous be shaken" -- Psalm 55:22
QB64 Linux Installer

EricR

  • Jr. Member
  • **
  • Posts: 68
  • Loading Humor.sys on boot should be mandatory
    • Email
Re: GUI / MEM libraries (Alpha versions)
« Reply #13 on: April 01, 2013, 03:15:32 PM »
I am going to take a look at the updated GUI later.  I do have one problem right now.  You say you have included docs in the download.  I do not see any such docs in either zip file.  Am I missing something?

DSMan195276

  • Hero Member
  • *****
  • Posts: 1996
  • Yes
    • Email
Re: GUI / MEM libraries (Alpha versions)
« Reply #14 on: April 01, 2013, 03:33:49 PM »
I am going to take a look at the updated GUI later.  I do have one problem right now.  You say you have included docs in the download.  I do not see any such docs in either zip file.  Am I missing something?

If you're asking about documentation, then sorry to say i don't have any current documentation for the latest release of the GUI library. This being because it will take a bit of time to get everything written out, and I'd rather not spend time documenting features that may or may not end up in the latest release (Or forget to update part of the documentation and cause lots of confusion). That said, GUI_example.bas uses all of the GUI elements and various features of each (And has lots of comments detailing things). If you want to learn about the GUI system, I would mess around with that program and with the parameters in the program and see what happens when you do what. Also look at GUI_lib.bi as it has the declarations for all of the flags, the flag names themselves are fairly self-explanatory. There are some which are internal to the GUI system which will probably have no real effect if you mess with them. I may split those off from the normal flags to avoid confusion, we'll have to see on that account.

When I have a full release of the code I also plan to have a simple text editing program like NotePad as an example program. I'll also be including some common dialogs I've written that have useful features, such as a file-open dialog, file-save dialog, etc... It'll give much more example code to mess around with.

Matt

Update: I got some time to work on it this morning (And possibly will continue to do so later today). I'm in the process of overhauling the mouse system a bit to accommodate some changes so the mouse events can be detected. I decided to try going with an event system setup like this:

Code: [Select]
'Byte 1
CONST GUI_EVENT_MOUSE             = 1
CONST GUI_EVENT_KEY               = 2

'Event_key_type flags
CONST GUI_EVENT_KEY_PRESSED       = &H00000001
CONST GUI_EVENT_KEY_RELEASE       = &H00000002

'Event_mouse_type flags
CONST GUI_EVENT_MOUSE_DRAG                = &H00000001

CONST GUI_EVENT_MOUSE_LEFT_DOWN           = &H00000004
CONST GUI_EVENT_MOUSE_LEFT_UP             = &H00000010
CONST GUI_EVENT_MOUSE_LEFT_SINGLE_CLICK   = &H00000080
CONST GUI_EVENT_MOUSE_LEFT_DOUBLE_CLICK   = &H00000100

CONST GUI_EVENT_MOUSE_RIGHT_DOWN          = &H00000002
CONST GUI_EVENT_MOUSE_RIGHT_UP            = &H00000020
CONST GUI_EVENT_MOUSE_RIGHT_SINGLE_CLICK  = &H00000200
CONST GUI_EVENT_MOUSE_RIGHT_DOUBLE_CLICK  = &H00000400

CONST GUI_EVENT_MOUSE_MIDDLE_DOWN         = &H00000008
CONST GUI_EVENT_MOUSE_MIDDLE_UP           = &H00000040
CONST GUI_EVENT_MOUSE_MIDDLE_SINGLE_CLICK = &H00000800
CONST GUI_EVENT_MOUSE_MIDDLE_DOUBLE_CLICK = &H00001000

CONST GUI_EVENT_MOUSE_SCROLL_UP           = &H00002000
CONST GUI_EVENT_MOUSE_SCROLL_DOWN         = &H00004000
CONST GUI_EVENT_MOUSE_MOVEMENT            = &H00008000

TYPE GUI_event_generic_type
  event_type as _UNSIGNED LONG
  gui_element AS _UNSIGNED LONG
  mem as _MEM
  allocated as _UNSIGNED _BYTE
END TYPE

TYPE GUI_event_key_type
  key_code AS _UNSIGNED LONG 
  flags AS _BYTE
END TYPE

TYPE GUI_event_mouse_type
  row AS _UNSIGNED LONG
  col AS _UNSIGNED LONG
  row2 AS _UNSIGNED LONG 'Used if a drag occured
  col2 AS _UNSIGNED LONG
  scroll AS LONG
  flags as INTEGER
END TYPE

SUB GUI_init_event (e as GUI_event_generic_type)
e.mem = _MEMNEW(18) 'Size of the biggest event
e.allocated = 18
END SUB

SUB GUI_free_event (e as GUI_event_generic_type)
_MEMFREE e.mem
e.allocated = 0
END SUB

SUB GUI_get_key_event (e as GUI_event_generic_type, e2 as GUI_event_key_type)
e2 = _MEMGET(e.mem, e.mem.OFFSET, GUI_event_key_type)
END SUB

SUB GUI_get_mouse_event (e as GUI_event_generic_type, e2 as GUI_event_mouse_type)
e2 = _MEMGET(e.mem, e.mem.OFFSET, GUI_event_mouse_type)
END SUB

The basic idea is that the type 'GUI_event_generic_type' is used as a generic event structure that can then hold any other type of event via it's _MEM. Because of this, the generics will have to be allocated and freed at the beginning and the end of your program. The good news is that you really only need one generic per piece of your program so it's pretty simple and just one basic call. The generic is important because it's what the GUI system will pass back to your program when any type of event happens. It also means that I can add new events as much as I want, and all it requires is making sure the generic can hold it (And thus, adding new events does not increase the size of the normal events). The disadvantage is that you have to use _MEMGET() to get the actual event out of the generic (the GUI provides wrapper functions to do this, as you can see at the end of the above code).

If you need to say, only handle mouse events, then you create a GUI_event_generic_type and then GUI_event_mouse_type. Then it just takes a small bit of code to read the generic event's 'event_type' properties and get the GUI_event_mouse_type via the GUI_get_mouse_event function. And from there, the GUI_event_mouse_type holds all the information you need and you can use that virtually excessively from there. Detecting key presses is practically the same except you use GUI_get_key_event and a GUI_event_key_type instead. As you can imagine, it's easy to extend this system by just adding more event types (And you never actually have to deal with new events or have any extra bloat because of them).
« Last Edit: April 09, 2013, 07:54:39 AM by DSMan195276 »
"Cast your cares on the Lord and he will sustain you; he will never let the righteous be shaken" -- Psalm 55:22
QB64 Linux Installer