{"id":3139,"date":"2012-01-13T08:24:00","date_gmt":"2012-01-13T13:24:00","guid":{"rendered":"https:\/\/blogs.mathworks.com\/pick\/?p=3139"},"modified":"2012-01-13T08:24:00","modified_gmt":"2012-01-13T13:24:00","slug":"drag-objects-conveniently-2","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/pick\/2012\/01\/13\/drag-objects-conveniently-2\/","title":{"rendered":"Drag Objects Conveniently"},"content":{"rendered":"<div xmlns:mwsh=\"https:\/\/www.mathworks.com\/namespace\/mcode\/v1\/syntaxhighlight.dtd\" class=\"content\">\r\n   <introduction><\/introduction>\r\n   <p><a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/authors\/911\">Brett<\/a>'s Pick this week is <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/4179-draggable\">Draggable,<\/a> by <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/authors\/10751\">Francois Bouffard<\/a>.\r\n   <\/p>\r\n   <p>For a pet project of mine, I needed to implement (in MATLAB code, of course!) a repositionable, resizable rectangle. I wanted\r\n      to be able to drag the rectangle itself, but I also wanted to expose \"handles\" that would allow me to drag from the sides\r\n      or from the corners, and to control, or constrain, the motion.\r\n   <\/p>\r\n   <p>As a first step, I needed a general function that facilitated \"draggability\" of MATLAB objects. That's where \"Draggable\" comes\r\n      in. Starting, as I usually do, with the File Exchange, I quickly found my way to Francois's file. I downloaded it, encouraged\r\n      by several 5-star reviews (now including my own!), and was very pleased by how tractable the problem became.\r\n   <\/p>\r\n   <p><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/pick\/files\/draggable2.gif\"> <\/p>\r\n   <p>\"Draggable\" is exceptionally well implemented, and despite having taken it for a significant test drive, I have been unable\r\n      to find fault with it.\r\n   <\/p>\r\n   <p>Francois mentioned in his comments that he plans to revisit his code at some point in the future to  enable one to apply the\r\n      functionality simultaneously to multiple handles. I agree that that would make a nice enhancement, though activating objects\r\n      one-at-a-time wasn't extremely onerous. It would also be nice if there were a \"diagonal\" constraint--at least for my purposes.\r\n      But in its current state, I'm very happy to select \"Draggable\" as this week's Pick of the Week--very nice work, Francois!\r\n   <\/p>\r\n   <p>Incidentally, my \"draggableRect\" isn't on the File Exchange <i>yet<\/i>, but I hope to have it up soon!\r\n   <\/p>\r\n   <p>As always, <a href=\"https:\/\/blogs.mathworks.com\/pick\/?p=3139#respond\">comments to this blog post<\/a> are welcome. Or leave a comment for Francois <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/4179-draggable#comments\">here<\/a>.\r\n   <\/p><script language=\"JavaScript\">\r\n<!--\r\n\r\n    function grabCode_5988cd6d582d4b7eb91c1a745c892e53() {\r\n        \/\/ Remember the title so we can use it in the new page\r\n        title = document.title;\r\n\r\n        \/\/ Break up these strings so that their presence\r\n        \/\/ in the Javascript doesn't mess up the search for\r\n        \/\/ the MATLAB code.\r\n        t1='5988cd6d582d4b7eb91c1a745c892e53 ' + '##### ' + 'SOURCE BEGIN' + ' #####';\r\n        t2='##### ' + 'SOURCE END' + ' #####' + ' 5988cd6d582d4b7eb91c1a745c892e53';\r\n    \r\n        b=document.getElementsByTagName('body')[0];\r\n        i1=b.innerHTML.indexOf(t1)+t1.length;\r\n        i2=b.innerHTML.indexOf(t2);\r\n \r\n        code_string = b.innerHTML.substring(i1, i2);\r\n        code_string = code_string.replace(\/REPLACE_WITH_DASH_DASH\/g,'--');\r\n\r\n        \/\/ Use \/x3C\/g instead of the less-than character to avoid errors \r\n        \/\/ in the XML parser.\r\n        \/\/ Use '\\x26#60;' instead of '<' so that the XML parser\r\n        \/\/ doesn't go ahead and substitute the less-than character. \r\n        code_string = code_string.replace(\/\\x3C\/g, '\\x26#60;');\r\n\r\n        author = 'Brett Shoelson';\r\n        copyright = 'Copyright 2012 The MathWorks, Inc.';\r\n\r\n        w = window.open();\r\n        d = w.document;\r\n        d.write('<pre>\\n');\r\n        d.write(code_string);\r\n\r\n        \/\/ Add author and copyright lines at the bottom if specified.\r\n        if ((author.length > 0) || (copyright.length > 0)) {\r\n            d.writeln('');\r\n            d.writeln('%%');\r\n            if (author.length > 0) {\r\n                d.writeln('% _' + author + '_');\r\n            }\r\n            if (copyright.length > 0) {\r\n                d.writeln('% _' + copyright + '_');\r\n            }\r\n        }\r\n\r\n        d.write('<\/pre>\\n');\r\n      \r\n      d.title = title + ' (MATLAB code)';\r\n      d.close();\r\n      }   \r\n      \r\n-->\r\n<\/script><p style=\"text-align: right; font-size: xx-small; font-weight:lighter;   font-style: italic; color: gray\"><br><a href=\"javascript:grabCode_5988cd6d582d4b7eb91c1a745c892e53()\"><span style=\"font-size: x-small;        font-style: italic;\">Get \r\n            the MATLAB code \r\n            <noscript>(requires JavaScript)<\/noscript><\/span><\/a><br><br>\r\n      Published with MATLAB&reg; 7.14<br><\/p>\r\n<\/div>\r\n<!--\r\n5988cd6d582d4b7eb91c1a745c892e53 ##### SOURCE BEGIN #####\r\n%% Drag Objects Conveniently\r\n%% \r\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/authors\/911 Brett>'s Pick this week is\r\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/4179-draggable Draggable,> by \r\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/authors\/10751 Francois Bouffard>.\r\n\r\n%%\r\n% For a pet project of mine, I needed to implement (in\r\n% MATLAB code, of course!) a repositionable, resizable\r\n% rectangle. I wanted to be able to drag the rectangle\r\n% itself, but I also wanted to expose \"handles\" that would\r\n% allow me to drag from the sides or from the corners, and\r\n% to control, or constrain, the motion.\r\n\r\n%%\r\n% As a first step, I needed a general function that\r\n% facilitated \"draggability\" of MATLAB objects. That's where\r\n% \"Draggable\" comes in. Starting, as I usually do, with the\r\n% File Exchange, I quickly found my way to Francois's file.\r\n% I downloaded it, encouraged by several 5-star reviews (now\r\n% including my own!), and was very pleased by how tractable\r\n% the problem became.\r\n\r\n%%\r\n% \r\n% <<https:\/\/blogs.mathworks.com\/pick\/files\/draggable2.gif>>\r\n% \r\n\r\n%%\r\n% \"Draggable\" is exceptionally well implemented, and despite\r\n% having taken it for a significant test drive, I have been\r\n% unable to find fault with it. \r\n%\r\n\r\n%%\r\n% Francois mentioned in his comments that he plans to\r\n% revisit his code at some point in the future to  enable\r\n% one to apply the functionality simultaneously to multiple\r\n% handles. I agree that that would make a nice enhancement,\r\n% though activating objects one-at-a-time wasn't extremely\r\n% onerous. It would also be nice if there were a \"diagonal\"\r\n% constraintREPLACE_WITH_DASH_DASHat least for my purposes. But in its current\r\n% state, I'm very happy to select \"Draggable\" as this week's\r\n% Pick of the WeekREPLACE_WITH_DASH_DASHvery nice work, Francois!\r\n\r\n%%\r\n% Incidentally, my \"draggableRect\" isn't on the File Exchange\r\n% _yet_, but I hope to have it up soon!\r\n\r\n%% \r\n% As always, <https:\/\/blogs.mathworks.com\/pick\/?p=3139#respond comments to this blog post> are welcome. Or leave a\r\n% comment for Francois\r\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/4179-draggable#comments here>.\r\n\r\n##### SOURCE END ##### 5988cd6d582d4b7eb91c1a745c892e53\r\n-->","protected":false},"excerpt":{"rendered":"<p>\r\n   \r\n   Brett's Pick this week is Draggable, by Francois Bouffard.\r\n   \r\n   For a pet project of mine, I needed to implement (in MATLAB code, of course!) a repositionable, resizable rectangle. I... <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/pick\/2012\/01\/13\/drag-objects-conveniently-2\/\">read more >><\/a><\/p>","protected":false},"author":34,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[16],"tags":[],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/3139"}],"collection":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/users\/34"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/comments?post=3139"}],"version-history":[{"count":11,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/3139\/revisions"}],"predecessor-version":[{"id":3153,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/3139\/revisions\/3153"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/media?parent=3139"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/categories?post=3139"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/tags?post=3139"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}