HP Prime DRAWMENU



#6

Hello,

Somebody knows how to detect a click on a menu drawn with DRAWMENU command on HP Prime ?


#7

Quote:
Somebody knows how to detect a click on a menu drawn with DRAWMENU command on HP Prime ?

Here's what I used:

  m := MOUSE;
m1 := m(1);
mx := m1(1);
my := m1(2);
menu := softmenu(mx,my,n);

where softmenu() is defined to be


////////////////////////////////////////////////////////////
// converts pixel x,y into a menu choice
// returns menu number (1 through n)
// returns 0 if an invalid menu option was selected (>n) or tap was exactly between two menu options
// returns -1 if y was not in softmenu region of the screen
softmenu(x,y,n)
BEGIN
LOCAL m;

m:=-1;
IF y >= 220 THEN
CASE
IF 0 <= x <= 51 THEN m := 1; END;
IF 53 <= x <= 104 THEN m := 2; END;
IF 106 <= x <= 157 THEN m := 3; END;
IF 159 <= x <= 210 THEN m := 4; END;
IF 212 <= x <= 263 THEN m := 5; END;
IF 265 <= x <= 319 THEN m := 6; END;
DEFAULT m:=0; // if it's right in between menu options
END;
// check to see if valid menu option was selected
IF m > n THEN
m := 0;
END;
END;
RETURN m;
END;

-wes


#8

Thank you, I used this way with coordonates detection. I thought there was a specific command for the drawn menus.

#9

The list returned from a MOUSE call contains the x and y values
in the following format #nnn:16d
For example if I touch the menu key 6, I get #273:16d as the x pixel
coordinate. How can I extract the value 273 - the x value from this
expression? I can't use the list format of the x,y coordinates
in a conditional statement.


#10

Quote:
The list returned from a MOUSE call contains the x and y values
in the following format #nnn:16d
For example if I touch the menu key 6, I get #273:16d as the x pixel
coordinate. How can I extract the value 273 - the x value from this
expression? I can't use the list format of the x,y coordinates
in a conditional statement.

The B->R function converts these 16-bit integers to reals, but you don't have to; you can use comparisons without converting them. You can also use the SUB command (or subscript notation) to extract individual items from that list, of course. Hope that helps!

Forum Jump: