PtInitDrag (widget, container, flags)
This example, ex_PtInitDrag.g, is included in the product distribution.
#!/usr/cogent/bin/phgamma
/*
This example puts a small window on the screen with a text label that
can be dragged.
*/
require_lisp("PhotonWidgets");
PtInit(nil);
win = new(PtWindow);
win.SetDim(200,200);
PtRealizeWidget(win);
lab = new(PtLabel);
lab.text_string = "Drag Me";
PtRealizeWidget(lab);
DraggedWidget := nil;
method PtWidget.StartDrag ()
{
DraggedWidget = self;
PtInitDrag (self, nil, Ph_TRACK_DRAG | Ph_DRAG_TRACK);
}
function handle_drag ()
{
local event = cbinfo.event, rect;
if (event.type == Ph_EV_DRAG)
{
if (event.subtype == Ph_EV_DRAG_COMPLETE ||
event.subtype == Ph_EV_DRAG_MOVE)
{
if (DraggedWidget)
{
rect = TranslateRect (event_data.drag_event.rect,
event.translation);
DraggedWidget.SetPos (rect.ul.x, rect.ul.y);
}
if (event.subtype == Ph_EV_DRAG_COMPLETE)
DraggedWidget = nil;
}
}
}
PtAttachCallback(win,Pt_CB_RAW,#handle_drag(),Ph_EV_DRAG);
PtAttachCallback(lab,Pt_CB_RAW,#widget.StartDrag(),Ph_EV_BUT_PRESS);
PtMainLoop();
Copyright © 1995-2012 by Cogent Real-Time Systems, Inc. All rights reserved.