Checking menus & buttons in GEM (hisoft basic)

Moderators: exxos, simonsunnyboy, Mug UK, Zorro 2, Moderator Team

User avatar
exxos
Hardware Guru
Hardware Guru
Posts: 4933
Joined: Fri Mar 28, 2003 8:36 pm
Location: England
Contact:

Checking menus & buttons in GEM (hisoft basic)

Postby exxos » Sat Dec 26, 2015 11:00 am

I can check menus using this line..

Code: Select all

e=evnt_multi(mu_mesag+mu_button,258,3,0,0,0,0,0,0,0,0,0,0,0,_
                       VARPTR(mess(0)),100,xa,ya,buttona,kstate,k,br)

and I can check buttons using this line.

Code: Select all

but=form_do(tree&,0) AND &h7f

Problem is, both lines seem to halt the code until something happens, so I can't check buttons and menu at the same time.

I thought I would ask about that first line as it seems to offer options to check for lots of things, but there is a timer in there where I can't find any info, I assume it would only check that line for a few milliseconds so it could run other parts of my code, but even so, the check for button line would pause the checking of the menu code. So I am clueless on how to check menu and buttons at the same time :(

How the code works is without the evnt_multi line, the menus can't even be accessed, like they are disabled totally. With the line the menus work, but I then have to press a button twice to get it to work. so presumably the evnt_multi is stuck until a button is pressed, but then it runs the but=form_do line, so then I have to click the button again.

If evnt_multi can report the button number which is clicked on without using the but=form_do line, then that would probably solve my problem. Though the info on the function is a bit confusing to say the least. http://toshyp.atari.org/en/008007.html#evnt_multi From what I can tell, it can detect a mouse click, but not the button. So that would mean I could need some other function to check work out what button was pressed. Can only assume by checking where on the screen the click happend (IE XY position of the mouse) but that seems more like a work-around way of doing it :roll: :shrug: :shrug:
4MB STFM 1.44 FD- VELOCE+ 020 STE - Falcon 030 CT60 - Atari 2600 - Atari 7800 - Gigafile - SD Floppy Emulator - PeST - various clutter

http://www.exxoshost.co.uk/atari/ All my hardware guides - mods - games - STOS
http://www.exxoshost.co.uk/atari/last/storenew/ - All my hardware mods for sale - Please help support by making a purchase.
http://ataristeven.exxoshost.co.uk/Steem.htm Latest Steem Emulator

User avatar
Mikefulton
Captain Atari
Captain Atari
Posts: 169
Joined: Sun Nov 29, 2015 10:27 am

Re: Checking menus & buttons in GEM (hisoft basic)

Postby Mikefulton » Sun Dec 27, 2015 1:30 am

You're specifying that you're waiting for 258 mouse clicks from both buttons to get a button event. The second parameter is more typically set to 1.

Perhaps you've confused the ev_bclicks and ev_bmask parameters?

User avatar
Mikefulton
Captain Atari
Captain Atari
Posts: 169
Joined: Sun Nov 29, 2015 10:27 am

Re: Checking menus & buttons in GEM (hisoft basic)

Postby Mikefulton » Sun Dec 27, 2015 1:39 am

By the way, the form _do() function is used exclusively for handling modal interaction with an object tree. If you want to draw an object tree as part of a non-modal window, you have to manage the events and UI interaction yourself instead of using form_do(). Look around online and you'll find source for form_do() that will show you how to do that.

User avatar
Mikefulton
Captain Atari
Captain Atari
Posts: 169
Joined: Sun Nov 29, 2015 10:27 am

Re: Checking menus & buttons in GEM (hisoft basic)

Postby Mikefulton » Sun Dec 27, 2015 1:49 am

Also... You're passing 100 for a timer value but not specifying that you want a timer event. The ev_flags parameter has to have the MU_TIMER bit set if you want a timeout to satisfy the conditions for the evnt_multi() call returning.

User avatar
Mikefulton
Captain Atari
Captain Atari
Posts: 169
Joined: Sun Nov 29, 2015 10:27 am

Re: Checking menus & buttons in GEM (hisoft basic)

Postby Mikefulton » Sun Dec 27, 2015 2:12 am

I think what you want is this:

Code: Select all


int evFlags = evnt_multi( MU_MESAG|MU_BUTTON, 1, 0x103, 3, ....... );

if( evFlags & MU_BUTTON ) // button event occurred
{
  If( ev_bbutton & 0x01 )
  {
  // button 0 pressed
  }
  if( ev_bbutton & 0x02 )
  {
  // button 1 pressed
  }
}


Setting bit 8 of ev_bmask makes AES check for the buttons individually instead of collectively. Then you set bit 0 of ev_bstate to indicate you're looking for button 0 pressed and bit 1 to indicate you're looking for button 1 pressed.

User avatar
exxos
Hardware Guru
Hardware Guru
Posts: 4933
Joined: Fri Mar 28, 2003 8:36 pm
Location: England
Contact:

Re: Checking menus & buttons in GEM (hisoft basic)

Postby exxos » Sun Dec 27, 2015 10:30 am

Mikefulton wrote:I think what you want is this:

Setting bit 8 of ev_bmask makes AES check for the buttons individually instead of collectively. Then you set bit 0 of ev_bstate to indicate you're looking for button 0 pressed and bit 1 to indicate you're looking for button 1 pressed.


Thanks for reply Mike, It's confusing the heck out of me thats for sure.

Thanks for the code suggestion, though how does that fit in with actual button clicks, I don't mean the mouse button, I mean a actual button box on the screen. I've not got as far as checking/working out mouse button clicks in the menu yet..

The form_do thing waits for a "button box" to be clicked and returns the button number in the tree, though the code waits on that line so it freezes the menus up.

I want to check if any button boxes have been clicked on the main program screen, but also I need to check the menus aswell. Its that I can't work out :(

Of course evnt_multi will return a mouse button press, but how do I get from that to workout out what menu item was click on, and also what "button box" number was clicked. There are 15 "button boxes" on the screen currently, starting from tree number 52ish. so if evnt_multi could simply report what tree numbers were clicked on (box buttons and menu items ) then that would probably solve my problems.
4MB STFM 1.44 FD- VELOCE+ 020 STE - Falcon 030 CT60 - Atari 2600 - Atari 7800 - Gigafile - SD Floppy Emulator - PeST - various clutter

http://www.exxoshost.co.uk/atari/ All my hardware guides - mods - games - STOS
http://www.exxoshost.co.uk/atari/last/storenew/ - All my hardware mods for sale - Please help support by making a purchase.
http://ataristeven.exxoshost.co.uk/Steem.htm Latest Steem Emulator

User avatar
Mikefulton
Captain Atari
Captain Atari
Posts: 169
Joined: Sun Nov 29, 2015 10:27 am

Re: Checking menus & buttons in GEM (hisoft basic)

Postby Mikefulton » Sun Dec 27, 2015 11:44 am

The event library does not directly operate with object trees at all. There is no event for a UI button being clicked. "Button" always refers to mouse buttons when talking about events.

The way the AES library function form_do() itself works is that it calls evnt_multi() to get mouse events, button events, and keyboard events, then it processes them as appropriate, and ultimately returns when something happens that indicates the application should be notified.

When an mouse click event occurs, for example, it calls the objc_find function of the object library, which walks the specified object tree to determine which specific object was clicked, or if the click happened outside the object tree.

If objc_find returns that it found an object, then form_do looks at the object type, state, and flags to determine what action makes sense. For example, if the object was a checkbox, and the SELECTED flag was clear, then it would set the SELECTED flag and redraw the object with a checkbox in place.

Ultimately, form_do will return when something with either the EXIT or TOUCHEXIT flag is clicked.

If you're using an object tree as part of your window, like a toolbar, or then your event handling must include a chunk of code that includes most of the functionality of the form_do() function. A lot of this will be calls to the object library functions like objc_find.

The difference will be that before (or after) that chunk of code runs, then you'll *also* process any other events like window redraws, etc., which may have occurred. Also, if you determine that the mouse click occurred outside the object tree, then you'll have to either process it or ignore it, depending on where it was. The form_do() function would do a system bell sound as a warning that the user clicked outside the object tree (dialog box).

About '87 or '88, Atari sent developers the source code for a form_do() function that was intended to be used as the basis for object trees shown in windows. I don't have a link, but I would imagine that this code is out there somewhere. Note that you don't want the actual source for the form_do() that's in event library.

If you can't find that, then maybe just try coding it from scratch. You know basically what has to happen when things are clicked on, so make it happen!

User avatar
exxos
Hardware Guru
Hardware Guru
Posts: 4933
Joined: Fri Mar 28, 2003 8:36 pm
Location: England
Contact:

Re: Checking menus & buttons in GEM (hisoft basic)

Postby exxos » Sun Dec 27, 2015 10:02 pm

Mikefulton wrote:
If you're using an object tree as part of your window, like a toolbar, or then your event handling must include a chunk of code that includes most of the functionality of the form_do() function. A lot of this will be calls to the object library functions like objc_find.

The difference will be that before (or after) that chunk of code runs, then you'll *also* process any other events like window redraws, etc., which may have occurred. Also, if you determine that the mouse click occurred outside the object tree, then you'll have to either process it or ignore it, depending on where it was. The form_do() function would do a system bell sound as a warning that the user clicked outside the object tree (dialog box).

If you can't find that, then maybe just try coding it from scratch. You know basically what has to happen when things are clicked on, so make it happen!



Thanks, I feared something like "objc_find" was how it was going to work out. It looks straight forwards so will give it a try out tomorrow.

I do get the system bell warning when clicking outside of my form. To be expected I guess. So the only "info" I have to work with is the XY location of the mouse and the button click, pretty much as your example earlier. So just need a couple of calls (hopefully) to work out whats at those XY locations and then work out the button number in the tree.. sounds simple.. so probably will take 2 months :)
4MB STFM 1.44 FD- VELOCE+ 020 STE - Falcon 030 CT60 - Atari 2600 - Atari 7800 - Gigafile - SD Floppy Emulator - PeST - various clutter

http://www.exxoshost.co.uk/atari/ All my hardware guides - mods - games - STOS
http://www.exxoshost.co.uk/atari/last/storenew/ - All my hardware mods for sale - Please help support by making a purchase.
http://ataristeven.exxoshost.co.uk/Steem.htm Latest Steem Emulator

User avatar
exxos
Hardware Guru
Hardware Guru
Posts: 4933
Joined: Fri Mar 28, 2003 8:36 pm
Location: England
Contact:

Re: Checking menus & buttons in GEM (hisoft basic)

Postby exxos » Mon Dec 28, 2015 12:54 pm

I've made some small progress, though the keyboard "scancode" does not seem to report any sensible number :shrug:

KEY A
7777

KEY B
12386

KEY C
11875

There seems to be a function called nkc_n2gem though I cant work out if its some sub routine or a built in function in hisoft.. the full line is
ProcessKeys CHR$(nkc_n2gem(kr) AND 255),kr,kstate

I could probably just check for 7777 for the A key anyway, just slightly confused where/how those numbers are generated.


Second problem, This code worked to de-select a button (it highlights when clicked, so need to un-highlight it)

Code: Select all

SUB Exclob_state(ob,flag_mask)
shared tree&
STATIC t&
't&=ObjectAddr&(object)+ob_state
t& = tree&+ (ob*24)+ob_state
POKEW   t&,PEEKW(t&) AND (NOT flag_mask)
END SUB

exclob_state but,mask_selected



But since changing the code I need a new way to now highlight the button. The code I have is..


Code: Select all

[quote]SUB DeselectObject(BYVAL obj)
STATIC state
shared tree&
state=getob_state(obj)
junk=objc_change(tree&,obj,0,0,0,0,state AND (NOT mask_selected),1)
END SUB

SUB SelectObject(BYVAL obj)
STATIC state
shared tree&
state=getob_state(obj)
junk=objc_change(tree&,obj,0,0,0,0,state OR mask_selected,1)
END SUB[/quote]


But I just get 2 bombs when I call that :roll:

I did try changing my original code to

Code: Select all

SUB Exclob_state(ob,flag_mask)
shared tree&
STATIC t&
't&=ObjectAddr&(object)+ob_state
t& = tree&+ (ob*24)+ob_state
POKEW   t&,PEEKW(t&) [b]OR flag_mask[/b]
END SUB

exclob_state but,mask_selected



Thinking it would match the code which worked before, but it doesn't do anything. Possible it needs a re-draw, but no clue. I did look to see if there was just a "BSET" function in hisoft but seems not, it would be easier to set and clear bits using that function, so cant try that either.

I also have a similar problem with the menus, once a menu item is clicked, the menu "title" remains highlighted. Everytime I try to "un-highlight" it, I am back to 2 bombs again :(


EDIT1:

ROTFLMAO!!


Steem__00025.png
Steem__00026.png


Gembench "Black Edition" anyone ? :twisted: :twisted:

EDIT2:
Steem__00027.png
:D :D :D :D :D

So using objc_find and the mouse XY form the evnt_multi function I've translated and highlighted the correct button A W E S O M E

Now if I could just figure out how to solve the menu highlight problem :roll: :lol: :lol:
You do not have the required permissions to view the files attached to this post.
4MB STFM 1.44 FD- VELOCE+ 020 STE - Falcon 030 CT60 - Atari 2600 - Atari 7800 - Gigafile - SD Floppy Emulator - PeST - various clutter

http://www.exxoshost.co.uk/atari/ All my hardware guides - mods - games - STOS
http://www.exxoshost.co.uk/atari/last/storenew/ - All my hardware mods for sale - Please help support by making a purchase.
http://ataristeven.exxoshost.co.uk/Steem.htm Latest Steem Emulator

User avatar
Mikefulton
Captain Atari
Captain Atari
Posts: 169
Joined: Sun Nov 29, 2015 10:27 am

Re: Checking menus & buttons in GEM (hisoft basic)

Postby Mikefulton » Wed Jan 13, 2016 1:03 am

exxos wrote:I've made some small progress, though the keyboard "scancode" does not seem to report any sensible number :shrug:

KEY A
7777

KEY B
12386

KEY C
11875



The 16-bit keycode returned by evnt_keybd or evnt_multi has the keyboard scan code in the high byte and the resulting ASCII code in the low byte. If you just want to go by scancode, mask off the low byte.

I know you're working in BASIC but if you check out the "keyboard.h" file from most ST C compilers, there will be a list of definitions for the keyboard scan codes.

Off the top of my head, i couldn't tell you for sure if those codes you've listed make any sense. I'm used to seeing them shown in hexadecimal.

User avatar
Mikefulton
Captain Atari
Captain Atari
Posts: 169
Joined: Sun Nov 29, 2015 10:27 am

Re: Checking menus & buttons in GEM (hisoft basic)

Postby Mikefulton » Wed Jan 13, 2016 1:15 am

exxos wrote:Second problem, This code worked to de-select a button (it highlights when clicked, so need to un-highlight it)

...

But since changing the code I need a new way to now highlight the button. The code I have is..


Code: Select all

SUB DeselectObject(BYVAL obj)
STATIC state
shared tree&
state=getob_state(obj)
junk=objc_change(tree&,obj,0,0,0,0,state AND (NOT mask_selected),1)
END SUB

SUB SelectObject(BYVAL obj)
STATIC state
shared tree&
state=getob_state(obj)
junk=objc_change(tree&,obj,0,0,0,0,state OR mask_selected,1)
END SUB


But I just get 2 bombs when I call that :roll:

The version with objc_change would be the way to go, but it looks like the parameters are wrong. A value is missing.

After 'obj' there should be a ZERO for a reserved value, followed by the clipping rectangle, then the new ob_state value. It looks like you're missing the reserved value.

Also, why is the clip rectangle all zeroes? Set that to the same XYWH as the root object of the tree and you should be fine.


Social Media

     

Return to “Other BASIC”

Who is online

Users browsing this forum: No registered users and 2 guests