I have just seen a HP Prime version of the NPV, IRR and cashflow applications made by Salvomic, a user in HPmuseum.org. I found it much longer than my own limited programs, which in reality were just functions to be used out of the keyboard, without any procedural or data entry instructions. But then I saw a screen shot with menu items. That was interesting! I had heard that many users wanted to be able to use the menus in the system, but there was no direct access to them with the common HP Prime functions. That got me interested and I started to search the program code for the menu functions information. It ended up being more low-level functions that I initially expected!
Let’s take a look at them. First, you need to know that something has happened, either on the screen as screen touch (or mouse in the case of the emulator), or on the keyboard.
// Detect keyboard or mouse input (keyboard has priority)
eTYP := “”;
kP := GETKEY;
IF kP <> –1 THEN
eTYP := “K”;
m := MOUSE;
m1 := m(1);
IF SIZE(m1) > 0 THEN
eTYP := “M”;
Then, he defines the procedure PUTMENU(mTXT), where mTXT is a list with 6 text elements. The real procedure that draws the menu is DRAWMENU() with all the text elements. Some of them may be “”.
// Draw the menu using the list passed in
He also defines the procedure GETMENU(mx,my,mTXT), where mx and my are the coordinates of the mouse click, using the convention of starting in the upper left corner of the screen, counting pixels. He uses a simple CASE function, after determining that the mouse click is in the lower part of the screen (line 4 of the procedure)
// Get the number of the menu item selected (1–6) by checking mouse position
// Menu items with empty/blank text will return a zero
mSEL := 0;
IF my≥220 AND my≤239 THEN
IF mx≥0 AND mx≤51 AND mTXT(1)>”” THEN mSEL := 1; END; IF mx≥53 AND mx≤104 AND mTXT(2)>”” THEN mSEL := 2; END; IF mx≥106 AND mx≤157 AND mTXT(3)>”” THEN mSEL := 3; END; IF mx≥159 AND mx≤210AND mTXT(4)>”” THEN mSEL := 4; END; IF mx≥212 AND mx≤263 AND mTXT(5)>”” THEN mSEL := 5; END; IF mx≥265 AND mx≤319 AND mTXT(6)>”” THEN mSEL := 6; END;