I am drawing lines by using CDirectScreenAccess API,i want to fix starting point by tapping on screen and want to draw line at point wherever i release stylus. so how can i handle pointereventl in appview can u please tell me, im using DrawLine() for line drawing using this can i trace stylus movement??.
Hi, don't know if direct screen access changes things, but my app without it works like this:
Code:
void CXxxCanvasView::HandlePointerEventL(const TPointerEvent& aPointerEvent) { switch (aPointerEvent.iType) { case TPointerEvent::EButton1Down: { if (!iPointerIsDown) { iPointerIsDown = ETrue; ClaimPointerGrab(ETrue); SetPointerCapture(ETrue); iCurrentPointerPosition = aPointerEvent.iPosition; ActivateGc(); CleanupClosePushL(*this); // the Close will be called. CWindowGc& gc = SystemGc(); // Here do some drawing, if necessary (e.g. update "pen" position) // If no need for drawing, forget activating gc, cleanup stack etc. too. CleanupStack::Pop(); DeactivateGc(); } break; } case TPointerEvent::EDrag: { if (iPointerIsDown) { iCurrentPointerPosition = aPointerEvent.iPosition; ActivateGc(); CleanupClosePushL(*this); // the Close will be called CWindowGc& gc2 = SystemGc(); // do some drawing from the previous pen position to current // Note that you might want to draw away the previous line // before drawing the new one by changing the draw mode: //aGc.SetDrawMode(CGraphicsContext::EDrawModeNOTXOR); // and then draw the old line, and after that, the new line. CleanupStack::Pop(); DeactivateGc(); } break; } case TPointerEvent::EButton1Up: { if (iPointerIsDown) { iPointerIsDown = EFalse; SetPointerCapture(EFalse); // Now the line has been drawn, do whatever necessary next. // Then update screen DrawNow(); } break; } } }
I use the cleanup stack and Close method to make sure that if a leave happens while drawing/dragging, the craphics context and pointer grab are released. Another reason is that if, e.g. someone phones you when you are dragging, focus is switched to phone app and your app never gets to release the gc and pointer grab. When you again start drawing, the graphics context is already active. Activating an already active graphics context will crash your app.
Note that if your code in pointer down/up/dragging does not leave, you do not need to do this. My app can leave in pointer down and drag, so that's why all this complicated stuff.
Forum posts: 672
Window().PointerFilter(EPointerFilterDrag, 0);
Then in your view's HandlePointerEventL, handle the TPointerEvent::EDrag case.
Forum posts: 14
Forum posts: 12
I am drawing lines by using CDirectScreenAccess API,i want to fix starting point by tapping on screen and want to draw line at point wherever i release stylus. so how can i handle pointereventl in appview can u please tell me, im using DrawLine() for line drawing using this can i trace stylus movement??.
Forum posts: 672
{
switch (aPointerEvent.iType)
{
case TPointerEvent::EButton1Down: {
if (!iPointerIsDown) {
iPointerIsDown = ETrue;
ClaimPointerGrab(ETrue);
SetPointerCapture(ETrue);
iCurrentPointerPosition = aPointerEvent.iPosition;
ActivateGc();
CleanupClosePushL(*this); // the Close will be called.
CWindowGc& gc = SystemGc();
// Here do some drawing, if necessary (e.g. update "pen" position)
// If no need for drawing, forget activating gc, cleanup stack etc. too.
CleanupStack::Pop();
DeactivateGc();
}
break; }
case TPointerEvent::EDrag: {
if (iPointerIsDown) {
iCurrentPointerPosition = aPointerEvent.iPosition;
ActivateGc();
CleanupClosePushL(*this); // the Close will be called
CWindowGc& gc2 = SystemGc();
// do some drawing from the previous pen position to current
// Note that you might want to draw away the previous line
// before drawing the new one by changing the draw mode:
// aGc.SetDrawMode(CGraphicsContext::EDrawModeNOTXOR);
// and then draw the old line, and after that, the new line.
CleanupStack::Pop();
DeactivateGc();
}
break; }
case TPointerEvent::EButton1Up: {
if (iPointerIsDown) {
iPointerIsDown = EFalse;
SetPointerCapture(EFalse);
// Now the line has been drawn, do whatever necessary next.
// Then update screen
DrawNow();
}
break; }
}
}
void CXxxCanvasView::Close()
{
DeactivateGc();
SetPointerCapture(EFalse);
iPointerIsDown = EFalse;
}
I use the cleanup stack and Close method to make sure that if a leave happens while drawing/dragging, the craphics context and pointer grab are released. Another reason is that if, e.g. someone phones you when you are dragging, focus is switched to phone app and your app never gets to release the gc and pointer grab. When you again start drawing, the graphics context is already active. Activating an already active graphics context will crash your app.
Note that if your code in pointer down/up/dragging does not leave, you do not need to do this. My app can leave in pointer down and drag, so that's why all this complicated stuff.
Forum posts: 12
Thank you very very much, its working.