cursorlistener.m

来自「国际象棋程序,解压到当前目录,在matlab窗口输入chess即可应用」· M 代码 · 共 50 行

M
50
字号
function cursorListener(hObject, eventdata, handles)
% cursorListener   Activate the cursor.
% Each figure calls this function, via the Buttond down Callback.
%
% Inputs:
% * hObject ... currently not used
% * eventdata ... currently not used
% * handles ... currently not used
% * global board ... chess board and related information
% * global game ... status of the game
%
% Outputs:
% * WindowButtonUpFcn ... sets the Callback for the mouse button up function
% * WindowButtonMotionFcn ... sets the Callback for the mouse motion function
%
% Example
% Set the callback function of the current object to the cursorListener
% |set(gco,'ButtonDownFcn','cursorListener');|
%
% See also: setCursor, stopCursor, reset_cursor
%
%% Signature
% Author: W.Garn
% E-Mail: wgarn@yahoo.com
% Date: 2006/03/23 12:00:00 
% 
% Copyright 2006 W.Garn
%
global board
global game

if  game.status
    position = get(gca,'currentPoint');
    xy = [position(1) position(3)];
    xy = xy+.5;
    xy = round(xy);

    cp = xy2matrix(xy);

    %if board.figures(cp(1),cp(2)) ~= ' ' %it is a figure (shouldn't be necessary)
    if board.active_color == getColor(cp) % not that an opponents figure is chosen.
        setCursor(cp);
        set(gcf,'WindowButtonUpFcn',@stopCursor);
        set(gcf,'WindowButtonMotionFcn',@displayCursor);
    end
end
  


⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?