MyCanvas_2D class
This is a sub-class of the Canvas_2D class, to deal especifically with axes that present only 2D behavior, on the CanvasMouseEvents educational app.
Contents
Authors
- Pedro Cortez F Lopes (pedrocortez@id.uff.br)
- Rafael Lopez Rangel (rafaelrangel@tecgraf.puc-rio.br)
- Luiz Fernando Martha (lfm@tecgraf.puc-rio.br)
History
@version 1.00
Initial version: August 2021
Adapted from the code initially prepared for the course CIV 2801 - Fundamentos de Computação Gráfica, 2021, second term, Department of Civil Engineering, PUC-Rio.
Class definition
classdef MyCanvas_2D < Canvas_2D
Private properties - mouse events
properties (SetAccess = private, GetAccess = private)
firstPosition = []; % x and y coordinates of the first pointer position.
firstPositionGiven = false; % flag indicating that first point was selected.
lineDisplayed = false; % flag indicating that a line was displayed.
clr = [0 0 1]; % color to be used for plots (blue)
markSize = 0.01; % radius of circle mark.
xLim_mSz = 150; % Proportionality constant (xLim/markSize)
% handles to plots (for quick access)
h_mark_1 = [];
h_mark_2 = [];
h_line = [];
draw = []; % handle to object that draws on canvas
end
Constructor method
methods
function this = MyCanvas_2D(ax,fig,fcn)
if (nargin == 0)
ax = [];
fig = [];
fcn = [];
elseif (nargin <= 2)
fcn = [];
end
this = this@Canvas_2D(ax,fig,fcn);
% Creates an object to draw on canvas:
% <drawoncanvas.html *DrawOnCanvas*> class.
this.draw = DrawOnCanvas(this);
end
end
Public methods
Implementation of the methods that act as mouse event callbacks.
methods
%------------------------------------------------------------------
% Mouse button down callback - generic callback, called from an
% Emouse object.
% Input:
% * this = handle to this canvas object
% * pt = current cursor coordinates
% * whichMouseButton = 'left', 'right', 'center', 'double click'
function onButtonDown(this,pt,whichMouseButton)
% Compute mark size, based on canvas x limits
this.markSize = diff(this.ax.XLim) / this.xLim_mSz;
%%%%%%% COMPLETE HERE - MOUSEVENTS: 01 %%%%%%%
%%%%%%% COMPLETE HERE - MOUSEVENTS: 01 %%%%%%%
end
%------------------------------------------------------------------
% Mouse button up callback - generic callback, called from an
% Emouse object.
% Input:
% * this = handle to this canvas object
% * pt = current cursor coordinates
% * whichMouseButton = 'left', 'right', 'center', 'double click'
function onButtonUp(this,~,~)
%%%%%%% COMPLETE HERE - MOUSEVENTS: 03 %%%%%%%
%%%%%%% COMPLETE HERE - MOUSEVENTS: 03 %%%%%%%
end
%------------------------------------------------------------------
% Mouse move callback - generic callback, called from an
% Emouse object.
% Input:
% * this = handle to this canvas object
% * pt = current cursor coordinates
function onMouseMove(this,pt)
%%%%%%% COMPLETE HERE - MOUSEVENTS: 02 %%%%%%%
%%%%%%% COMPLETE HERE - MOUSEVENTS: 02 %%%%%%%
end
end
end