Canvas Callback HandlingA full description of the canvas and its resources can be found in the Reference Manual This page describes how you can develop your own canvas callback. Setting the CallbackFirst you must set the callback resource to point to your callback. If you are creating your own application then make sure the callback resource is specified when you create the Canvas: create Canvas gsharp_1.scrolledcanvas ( XuNguiCallback = "MyCanvasCB" ); If you want add your own canvas callback to Gsharp then you can use something like this: CANVAS = all("Canvas");
$(CANVAS).XuNguiCallback = "MyCanvasCB";
Writing the CallbackAs described in GUI Object Callbacks a callback has three arguments:
For our callback we know that o must be "gsharp_1.scrolledcanvas". We haven't bothered with callback data as there is only one Canvas that can generate a callback. So we only really need to examine the r argument. e.g. function MyCanvasCB(string o, string d, float r)
if (r=XuCR_POINT_SELECTED) then
echo("Point Selected");
elif (r=XuCR_DOUBLE_CLICK) then
echo("Double click");
endif
endfunction
Handling Clicks and DragsOnce we have decided which events we want to respond to, we use the values in the resources XuNguiSelection1 and XuNguiSelection2 to find the position of the interaction and then perform our response. As an example, let us say we want to implement some form of zoom. We have a simple domain that we want to zoom into: create Viewport page_1.viewport;
create Domain page_1.viewport.domain
( XuN1st2DXAxisTicklines = "behind",
XuN1st2DXAxisTickmarks = false,
XuN1st2DYAxisTicklines = "behind",
XuN1st2DYAxisTickmarks = false
);
set page_1.viewport.domain.xaxis1
( XuNaxisLabelsHeightActual = 6 %,
XuNticklinesMinor = true,
XuNticklinesMinorStyle = "lineStyle1"
);
set page_1.viewport.domain.yaxis1
( XuNaxisLabelsHeightActual = 6 %,
XuNticklinesMinor = true,
XuNticklinesMinorStyle = "lineStyle1"
);
Carry on to Pointers to GUI Objects |