Jump to content

UniCanvas - What is the best way to detect a canvas mouse RightClick ?


andyhill

Recommended Posts

1 hour ago, andyhill said:

Looking for advice on how to detect a uni canvas mouse RightClick ?

Hello,

One possible solution for now:

function afterrender(sender, eOpts)
{
    sender.getEl().dom.addEventListener('contextmenu', function(){
        ajaxRequest(sender, ...)
    })
}

 

Link to comment
Share on other sites

Thank You Sherzod.

Issue, this brings up the Browser context popup "Save Image" etc, I want this for my use only - not the browser.

Also, There is no x/y or any other previous mouse down event preceding the RightClick, how do I know where the RightClick was clicked ? Please advise ?

Minimal testing on several mouse events shows eOpts is blank "console.log(eOpts);"

 

On another matter dealing with the canvas object, I need a completed event after:-

image loaded
lines drawn
flood fill completed
clear

beginupdate
endupdate

etc.

The OnReadyEvent only fires once after initialization, can it not be made to fire after any drawing begin-end event (have I missed something) ?

 

Link to comment
Share on other sites

8 hours ago, andyhill said:

Issue, this brings up the Browser context popup "Save Image" etc, I want this for my use only - not the browser.

function afterrender(sender, eOpts)
{
    sender.getEl().dom.addEventListener('contextmenu', function(e){
        //ajaxRequest(sender, ...)
        e.preventDefault()
    })
}

 

Link to comment
Share on other sites

9 hours ago, andyhill said:

Issue, this brings up the Browser context popup "Save Image" etc, I want this for my use only - not the browser.

Also, There is no x/y or any other previous mouse down event preceding the RightClick, how do I know where the RightClick was clicked ? Please advise ?

1. UniCanvas1 -> ClientEvents -> ExtEvents ->

function afterrender(sender, eOpts)
{
    sender.getEl().dom.addEventListener('contextmenu', function(e){
        ajaxRequest(sender, '_contextmenu', ['x=' + e.layerX, 'y=' + e.layerY]);                             
        e.preventDefault();
    })
}

2. 

procedure TMainForm.UniCanvas1AjaxEvent(Sender: TComponent; EventName: string;
  Params: TUniStrings);
begin
  if EventName = '_contextmenu' then
  begin
    UniPopupMenu1.Popup(Params.Values['x'].ToInteger + 10, Params.Values['y'].ToInteger + 10)
  end;

end;

 

Link to comment
Share on other sites

9 hours ago, andyhill said:

Can you please ADD to the canvas object an event that "fires after any drawing endupdate" please.

 

4 hours ago, Sherzod said:

Are you using "UniCanvas1.PaintMode := pmFreeHand;" ?

Some approaches can be analyzed from here:

https://stackoverflow.com/questions/4648465/does-canvas-element-have-change-event/

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...