Post Reply 
Example: creating icon menus
01-08-2014, 05:07 AM (This post was last modified: 01-08-2014 05:13 AM by Han.)
Post: #9
RE: Example: creating icon menus
(01-08-2014 03:58 AM)The Shadow Wrote:  Hi, new to the forums here.

This program is really awesome - it's much easier to do than I was expecting!

Question: Is it possible to differentiate between regular and long clicks? I ask because from messing around with it, it seems that every long click first reports as a regular click.

To be clear, I'd like to have a menu in which a regular click on an item does one thing, and a long click on it does another.

If using WAIT(-1) to detect the mouse, then it is possible to detect the mouse clicks (long vs short). When a mouse event occurs, the WAIT(-1) command returns a list whose first entry determines the mouse event type. A 3 means a click occurred and a 7 means a long-click occurred. Please note, however, that clicks cause several events. A single click will actually trigger three events: mouse down, mouse up, followed by the actual "click". A long click triggers: mouse down, mouse up, long click, and finally regular click. Thus, your mouse event handler code MUST handle the long click FIRST, and enable some sort of local flag so that it does not also trigger the extraneous click event. Below is the code to test click events and what the WAIT(-1) returns.

For some strange reason (likely a bug), a long click is never generated if your first mouse event is in fact a long click!

Code:

EXPORT TEST()
BEGIN
  local getmouse=1, key;

  while getmouse do
    key:=WAIT(-1);
    if TYPE(key)==6 then
      if key(1)==3 then
        rect(); textout_p(key,0,120); wait(.5);
      else
        rect(); textout_p(key,0,0); wait(.5);
      end;
    end; 
  end;
END;

Here's how I would create the mouse handler:
Code:

local lclick=0, getmouse=1, key;

while getmouse do
  key:=WAIT(-1);

  // YOU MUST HANDLE MOUSE CLICKS BEFORE KEY PRESSES
  if TYPE(key)==6 then

    case
      if key(1)==7 then
        lclick:=1; // tell future events we just had long click
        // insert long click code here
      end;

      if key(1)==3 then
        if lclick then
          lclick:=0;
          // fake mouse click; add code here if you still want to handle it
        else
          // insert code here for true single-clicks
        end;
      end;

      // any other mouse events handled here must also set lclick to 0

    end;

  else

  // here is where you place the key-press handlers

  end;

end;

Graph 3D | QPI | SolveSys
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
Example: creating icon menus - Han - 01-03-2014, 10:31 PM
RE: Example: creating icon menus - Han - 01-04-2014, 04:45 AM
RE: Example: creating icon menus - Han - 01-04-2014, 03:55 PM
RE: Example: creating icon menus - Mic - 01-04-2014, 02:57 PM
RE: Example: creating icon menus - Han - 01-08-2014 05:07 AM
RE: Example: creating icon menus - Han - 01-08-2014, 06:20 PM



User(s) browsing this thread: 3 Guest(s)