-
Inside a custom component, I can differentiate the left and mouse buttons by doing: event.mods:isLeftButtonDown() and event.mods:isRightButtonDown() respectively in the mouseDown method. In the "drag" method, I can use event:getDistanceFromDragStartX(). But it seems to fire at both mouse buttons. Even when I use an if/ else statement to get the left or right mouse button, it still seems to pass on the distance to another method regardless of which button is pressed. So, the question is, is there a way to differentiate the drag distance of the left mouse button from the right mouse button? |
Beta Was this translation helpful? Give feedback.
Replies: 8 comments 22 replies
-
Hi @DnaldeT! |
Beta Was this translation helpful? Give feedback.
-
This is how I did it. I use lua to detect whether right or left button clicked and then plot the x,y separately. Maybe there's a better way? In this panel x,y coordinates are limited to the comp:getHeight() and comp:getWidth() with my new friend jlimit()! Tedjuh distance travelled_1_1_1_2021-02-28_21-38.zip constructor = function() myMeta={ leftDragDistance = 0, rightDragDistance = 0, leftDragDistance = 0, rightDragDistance = 0, left={enterX = 0,enterY = 0,leaveX = 0,leaveY = 0}, right={enterX = 0,enterY = 0,leaveX = 0,leaveY = 0}, --engagedButton="left" } coords = setmetatable({},{__index=myMeta}) end mouseDown = function(--[[ CtrlrComponent --]] comp --[[ MouseEvent --]], event) if event.mods:isLeftButtonDown() then coords.left.enterX = jlimit(0, comp:getWidth(), event.x) coords.left.enterY = jlimit(0, comp:getHeight(), event.y) end if event.mods:isRightButtonDown() then coords.right.enterX = jlimit(0, comp:getWidth(), event.x) coords.right.enterY = jlimit(0, comp:getHeight(), event.y) end end mouseUp = function(--[[ CtrlrComponent --]] comp --[[ MouseEvent --]], event) if event.mods:isLeftButtonDown() then coords.left.leaveX = jlimit(0, comp:getWidth(), event.x) coords.left.leaveY = jlimit(0, comp:getHeight(), event.y) end if event.mods:isRightButtonDown() then coords.right.leaveX = jlimit(0, comp:getWidth(), event.x) coords.right.leaveY = jlimit(0, comp:getHeight(), event.y) end panel:getComponent("myComp"):repaint() end mouseDrag = function(--[[ CtrlrComponent --]] comp --[[ MouseEvent --]], event) if event.mods:isLeftButtonDown() then coords.leftDragDistance = event:getDistanceFromDragStartX() panel:getLabel("d"):setText("Left drag distance = " .. event:getDistanceFromDragStartX()) end if event.mods:isRightButtonDown() then coords.rightDragDistance = event:getDistanceFromDragStartX() panel:getLabel("d"):setText("Right drag distance = " .. event:getDistanceFromDragStartX()) end end myPaint = function(--[[ CtrlrComponent --]] comp --[[ CtrlrComponent --]], g) if blockFunction then return end g:fillAll(Colour(0xff99ccff)) local leftColour = 0xff0000ff local rightColour = 0xffff0000 g:setColour(Colour(leftColour)) myLineL = Line(coords.left.enterX, coords.left.enterY, coords.left.leaveX, coords.left.leaveY) g:drawLine(myLineL, 2) g:setColour(Colour(rightColour)) myLineR = Line(coords.right.enterX, coords.right.enterY, coords.right.leaveX, coords.right.leaveY) g:drawLine(myLineR, 2) end |
Beta Was this translation helpful? Give feedback.
-
Just for my info, what do you want to achieve? |
Beta Was this translation helpful? Give feedback.
-
Lots to go through, thank you all for the valuable input. But first to answer some questions: What am I trying to achieve? A slider consisting of 2 arcs (or pie segments?). The inner arc is the value to control the modulator. The outer arc is to set a minimum or maximum for the inner arc. I got a "sort of" working example but it takes the arcs themselves as mouse focus. To calculate which arc I'm on I do: (cX and cY are centre of X/Y of the component) That results in: F.y.i. totalBlueDragX = (blueMouseDown +(custBlueDragX - blueMouseDown)) - blueMouseDown) / 482 -- to get a value of 0 to whatever. But the way of handling the start/ end angle of the blue arc gets harder when the slider is quite small. So I figured, why not throw the right-mouse button in the mix to control the blue arc?. Easily said, not so easily done. Because in some way, the drag script sends a value on either mouse button no matter how many true or false statements I throw at it from the MouseDown script to prevent the left-mouse from sending a value when dragging the right-mouse button. I even already wrote a mouseDrag method almost exactly the same as yours, Dnaldoog. But the red arc still changes value when dragging the arc. And that is weird because all properties of the red or blue arc are defined in redSomething/ blueSomething. So I really don't get where the red arc gets the value from when dragging the blue arc. And to my knowledge, MouseUp comes "after" the drag. So shouldn't matter, right? "confused look". See example panel. |
Beta Was this translation helpful? Give feedback.
-
I'm following this with great interest. I'll need to do this very soon, and I've been running over in my head how to do it. I've never used a custom component before. Has anyone got any info on how to get into them? |
Beta Was this translation helpful? Give feedback.
-
@DnaldeT I had some fun with your challenge and I built it "my way" but re-using some stuff from you. Please look at the methods under the group "goodweather" Please have a look at my code and re-use! @Godlike-Productions : study my code and the uiCustomComponent I attached the 4 methods to.
As @dnaldoog mentioned, look at the Graphics class in Juce to learn about drawing line, pies (this example), using the path object... |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
Probably not the right way to do it, too much code and the code could be easier but for now the mouse-handling of the component and how the component deals with the drawing part is "almost" spot-on. Left Mouse Button controls the Red Angle. Right Mouse Button controls the Blue Angle, Click and Drag on the Left Half controls StartAngle, Click and Drag on the Right Half controls EndAngle. Now on to setting the "min-max" angles of the red Angle to the Blue Angle at mouseUp. |
Beta Was this translation helpful? Give feedback.
This is how I did it. I use lua to detect whether right or left button clicked and then plot the x,y separately. Maybe there's a better way?
In this panel x,y coordinates are limited to the comp:getHeight() and comp:getWidth() with my new friend jlimit()!
Tedjuh distance travelled_1_1_1_2021-02-28_21-38.zip