changing pointer to colorful picture

8 views (last 30 days)
nathan blanc
nathan blanc on 2 Sep 2021
Answered: Pratyush ongeveer 21 uur ago
I am working on an app with a drag and drop functionality. this means that buttons can be dragged by the user.
at the moment, the functionality is based on the code attached at the bottom, which is set as the WindowButtonMotionFcn of the app under certain conditions. however, this runs relatively slowly, especially when there are many components.
i was thinking of changing the method completly, and instead change the pointer itself into a picture of the button that the user can drag around. however as far as I saw the pointer can only be set to a black and white 16*16 or 32*32 picture. this is despite the fact that pointers in general can be colorful and large in many applications. (even the "watch" pointer in matlab itself is colorful) is there a way around this?
alternatively, is there a way to accelerate the attached function? I think one of the problems is that the app renders all the graphical components even when you drag one tiny button. is there a way to overcome this?
many thanks in advance
function Drag_Component(fig_handle,~,Button,dx,dy)
pos = get(fig_handle, 'currentpoint'); % get mouse location on figure
x = pos(1);
y = pos(2); % assign locations to x and y
% get button width and height
target_pos = get(Button,'position');
tw = target_pos(3); th = target_pos(4);
% update button position based on the computed x,y locations
target_pos = [x-dx, y-dy, tw, th];
set(Button,'position', target_pos);
end

Answers (1)

Pratyush
Pratyush ongeveer 21 uur ago
Hi Nathan,
To enhance the performance of drag-and-drop in your app and potentially customize the cursor beyond MATLAB's basic black-and-white icon limitations, consider the following strategies:
Optimize Drag-and-Drop Functionality:
  • Update component positions less frequently or only after significant mouse movements.
  • Temporarily replace complex components with simpler outlines during drag operations.
  • Attempt to minimize the number of redraws and graphical updates during dragging.
Custom Cursor Alternatives:
  • MATLAB's built-in support for custom cursors is limited to simple, small black-and-white images. For more advanced cursor customization (like colorful or larger cursors), MATLAB does not offer direct support.
  • You might explore deeper Java integration within MATLAB for more advanced cursor customization, though this can be complex and not guaranteed to work across all platforms.
  • Create a movable figure that mimics a custom cursor by following the mouse pointer. This figure can be transparent and display a colorful image, acting as a pseudo-cursor.
Given MATLAB's limitations, optimizing your current drag-and-drop function and using creative workarounds like an overlay figure may offer the best path forward for both performance improvements and enhanced cursor customization.

Products


Release

R2020b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!