Home › Forums › General › Programming › Drag&Drop
- This topic has 12 replies, 2 voices, and was last updated 8 years, 11 months ago by zeoka.
-
AuthorPosts
-
April 29, 2015 at 2:36 am #45024
Hi I try some things
takeSrc = function(component, mouseEvent) SrcTrgX = mouseEvent:getMouseDownX () SrcTrgY = mouseEvent:getMouseDownY () --SrcTrgI = Image(RGB,64,16,true) --console(""..SrcTrgI:getFormat () ) if SrcTrgX >= 0 and SrcTrgX <= 64 then for u = 0,13 do if SrcTrgY >= u*16 and SrcTrgY <= (u*16) + 16 then -- SrcTrgG = Graphics(SrcTrgI) -- SrcTrgG:setColour(BLACK) -- SrcTrgG:drawText(MdSrc1TABLEu+1TABLE,0,0,64,16,CENTRE,false) end end end --SrcTrgI not valid details = DragAndDropSourceDetails("DragSrc&Trgt",component ,SrcTrgX,SrcTrgY ) return (details) end
I encounter issue with probably image pixel format , another thing : DragAndDropSourceDetails wants x and y not Point() but it will returns a point ?
I see in the demo example you don’t use these values but put them in the description var().
how the target recognize the good source ?
RecSrc = function( component, dragSourceDetails) if dragSourceDetails:getDescription() == "DragSrc&Trgt" then return (1) else return (0) end end
The description is ok but If i put statement in it then not
I can’t get localPosition I tried various things
and tried to do a function to get the datatest3 = function(component,dragSourceDetails) function getPoint (name,component,x,y) if x and y ~= nil then return x,y end end --nameok = dragSourceDetails:getDescription() getPoint(dragSourceDetails) console(nameok) console(""..x) console(""..y) if nameok == "DragSrc&Trgt" then end end
But maybe dragSourceDetails return a point() or else ?
At least I get Image() oouffApril 29, 2015 at 2:10 pm #45050Ok I gave up LocalPosition and done like the example using only description
but can’t find anything when item is dropped to indicate the position of dropping…
I would drop in specific zones
I notice that for me shouldDrawDragImageWhenOver ( ) is false when the target isInterested and not on the example panel , I’m doing as the example panel thought
Surely because I don’t use (description,image,x,y) but (description,component,x,y)?
It’ temporary but I don’t know if Image() is registered in Ctrlr and if it needs
because I don’t get itApril 29, 2015 at 4:29 pm #45057but can’t find anything when item is dropped to indicate the position of dropping…
Do you mean the position where you release the mouse button? If that’s the case, I think it’s not possible, you only know the position when you start dragging. I gave up with drag & drop only for this reason.
Also this words from Jules:
The drag-and-drop classes are for picking something up, and dropping it onto a target, assuming that nothing of interest is going to happen in-between. I’d say that if you need to do anything even slightly complicated inside your itemDragMove, then you should probably do it some other way.
April 29, 2015 at 6:28 pm #45059Thx
yes I would have drop positionThis is what I do to have drop values but this is failing
Description() is 100(the source type value because several lists obtained by loop&mouseEvent) + my value (here 0 to 13 ) so I do :-- -- Called when the mouse moves over a component -- FilterPos = function( comp,event) FltX = event.x FltY = event.y end
-- -- Called when a DragAndDrop event occurs over this component -- test = function(component,dragSourceDetails) nameok = dragSourceDetails:getDescription() --console(nameok) if FltX ~= nil and FltY ~= nil then --if nameok:byte(1) == 49 if FltX >= 64 and FltX <= 128 and FltY >= 80 and FltY <= 120 then FiltTrg = 0 -- elseif -- then -- elseif -- then -- elseif -- then else FiltTrg = nil end component:repaint() --end end end
in my customcomponent paint scrip I added
g:setColour(BLACK:withAlpha(0.3 )) if FiltTrg ~= nil then if FiltTrg == 0 then g:fillRoundedRectangle(64,80 ,64,40,2.0) end end
this add rectangle where the item can be dragged
-- -- Called when something is dropped on this component -- test3 = function(component,dragSourceDetails) console(string.format("Dropx:%d",FltX)) console(string.format("Dropy:%d",FltY)) console("DropXbrut:".. FltX) console("DropYbrut:".. FltY) console(dragSourceDetails:getDescription()) end
my X and Y values are not realistics !!?? signed or not why ?
ex I drop near 128,40 and get :
Dropx:92
Dropy:11
DropXbrut:92
DropYbrut:11
103
or near 128,80 :
Dropx:234
Dropy:3
DropXbrut:234
DropYbrut:3
102I have another issue with MyDescriprtionString:byte(1) method that returns nil
At least I get Image() it was (PixelFormat) an index- This reply was modified 8 years, 12 months ago by zeoka.
April 30, 2015 at 12:53 am #45083Hi Dasfaker
I quasi get it but with mouseDownCallback of the target custom comp :
mouseDown : select the target zone and give a variable and repaint
dragStart : take the info
IsInterested : it choses if return(1) or (0) with variable
Dropped : take the description string and get its value , set the buffer byte with value,
set the variable to nil and repaintthis is the last step that fails : tonumber(dragSourceDetails:getDescription())
returns nil I’ve read LUA and this is possible to put variable in it
the description is not a string , string.format doesn t change itconsole(dragSourceDetails:getDescription()) it’s ok
I do tonumber(“110”) it’s ok
tonumber(dragSourceDetails:getDescription()) it’s nilApril 30, 2015 at 3:41 pm #45127console(dragSourceDetails:getDescription()) it’s ok
I do tonumber(“110″) it’s ok
tonumber(dragSourceDetails:getDescription()) it’s nilMy description is string number only
No idea ? Need to set a string parameter before convert to number ?
I want drag&drop to evitate to program many comboboxes in my customcomps
EDIT : just a thought , if we can create childs to the custom comp and there are on top we can finally drop in several zones ?
Dasfaker what do you think about that ?Attachments:
You must be logged in to view attached files.April 30, 2015 at 9:27 pm #45156I have to look at the code I tried about drag&drop, I think I solved where the mouse was dropped without childs, but it was impossible to redraw the target component until the mouse was released, a feature I needed.
In fact, contrary to what I said before about not been able to know the drop point, it’s easy, just checking the mouse position on mouse up you get the drop point.
April 30, 2015 at 11:09 pm #45161I tried with mouse up too
we have to define target Point before dropping
Yes drag&drop override any target component mouse eventbut I simply not get the description as value
how did you make ?
April 30, 2015 at 11:15 pm #45165I didn’t used the description at all. In my case, I just had two custom components displaying a bank of patches, something like an excel table (with cells). I just clicked on a cell (a patch) and dragged to another cell in the same or the other custom component. I just needed two variables, one the cell clicked, the other the cell where I dropped. I mean, I used variables independent of the description stuff.
April 30, 2015 at 11:22 pm #45166thank you for your help
I will rethink my methodsMay 3, 2015 at 9:05 pm #45606Hi
I try to do dragAndDrop with componentchild targets and IsInterested , Events independent of parent
and if see if that worksI’ve created valid components with some prop in beforeLoadingCallback and I get issue with addAndMakeVisible :
-- -- Called when the panel has finished loading -- Loaded = function() Mytext = "" for u = 1,6 do Mytext = Mytext.."ID".. CFlt?u?:getComponentID().."\n" -- panel:getComponent("Filter"):addAndMakeVisible (CFlt?u?,-1) -- Ambiguous -- GFlt?u?:drawText("coucou",0,10,64,20,CENTRE,false) -- CFlt?u?:paint(GFlt?u?) end panel:getLabelComponent("TEXT"):setText(Mytext) -- working end
*table separator are represented with “?”
I haven’t set componentName not sure it is neededNot sure if must type a stringComponentName or identifier (here a table name) in
addAndMakeVisible but this fails“And for it to serve any useful purpose, you’ll need to write a subclass of Component or use one of the other types of component from the library. ”
What does it means ?May 4, 2015 at 4:13 pm #45670Hi
I need some help !
I can’t get painting of my childs created, it lacks something , it is just a first test-- -- Called when the panel has finished loading -- Loaded = function() Gsrc = Graphics(Image(2,64,40,true)) Gsrc:setColour(Colour(0xffffffff)) Gsrc:fillRect(0,0,64,40) Gsrc:setColour(CL3[panel:getGlobalVariable(5)+1]) for i = 1,6 do l = {89,91,94,109,111,114} MyFilter:addChildAndSetID(Component("Flt"..i),""..l{i}) --MyFilter:findChildWithID(""..l{I}):setAlwaysOnTop(true) MyFilter:findChildWithID(""..l{i}):setBounds (Sidx{l{i}}.x,Sidx{l{i}}.y,64,40) Gsrc:drawText(Sidx{l{i}}.n,0,10,64,20,CENTRE,false) MyFilter:findChildWithID(""..l{I}):paintEntireComponent(Gsrc,true) --MyFilter:findChildWithID(""..l{I}): setBufferedToImage (true ) end end
I see also in the lua editor “addMethod” there is Callbacks like componentLUAmouseup . are they callback I could use for my childs
and try to drop on them ?May 21, 2015 at 1:48 am #47758Hi
I get the Description userdata !
if u <= 15 then MyDetails = string.format("0%x",u) else MyDetails = string.format("%x",u) end details = DragAndDropSourceDetails(MyDetails ,SrcTrgI,0,0) the description here is a number ,generally useful for later , I pass it to hexstring and in isInterested callback : if SOURCE == 1 then local a = component:getOwner():getPropertyInt("modulatorCustomIndex") local b = dragSourceDetails:getDescription() local c = MemoryBlock(b) if c:getByte(0) <= Sidx[a].mx then panel:getComponent("drtext"):setText(""..c:getByte(0)) return (1) else return (0) end else return (0) end end I pass the description into a local memoryblock and get the byte as value I pass that to text to check the value
-
AuthorPosts
- The forum ‘Programming’ is closed to new topics and replies.