Namespaces

Variants
Actions

Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries over the next few weeks. Thanks for all your past and future contributions.

Interpolating points between drag events using Symbian C++

From Wiki
Jump to: navigation, search

Archived.pngArchived: This article is archived because it is not considered relevant for third-party developers creating commercial solutions today. If you think this article is still relevant, let us know by adding the template {{ReviewForRemovalFromArchive|user=~~~~|write your reason here}}.

The article is believed to be still valid for the original topic scope.

Article Metadata
Code ExampleTested with
Devices(s): Nokia 5800 XpressMusic
Compatibility
Platform(s): S60 5th Edition
Article
Keywords: Interpolation, TPointerEvent::EDrag
Created: tepaa (21 Oct 2008)
Last edited: lpvalente (23 Sep 2014)

Contents

Overview

Interpolation is a method of constructing new data points within the range of a discrete set of known data points.

When dragging an item on the screen and that item is updated after receiving a TPointerEvent::EDrag event, it moves remarkably. The reason is that the dragging points received by the application are quite far from each other. The following interpolation calculates the missing points between two TPointerEvent::EDrag events and draws the item also in them.

NOTE: The application has an Interpolation menu item which you can use to enable/disable interpolation and see the difference. Interpolation is disabled by default.

This snippet can be self-signed.


MMP file

The following capabilities and libraries are required:

CAPABILITY None       
 
LIBRARY avkon.lib


Header file

#include <coecntrl.h>
class CExampleStubAppView : public CCoeControl
{
...
public:
void EnableInterpolation(TBool aEnable);
 
private:
void StartDrawingL();
void StopDrawing();
static TInt DoDraw(TAny* aObj);
void HandlePointerEventL(const TPointerEvent&
aPointerEvent);
 
// Interpolation is calculated here
void Move(const TPoint& aPoint);
 
private:
CPeriodic* iPeriodic;
TRect iPictureRect;
TPoint iPicturePoint;
TPoint iStylusPoint;
TBool iDragging;
TBool iInterpolate;
};


Source file (consts for interpolation)

const TReal32 KSPEED = 8;           // Moving speed
const TInt DELAY = 30000; // = 33 fps (Frame/Seconds)
const TReal KFRAMETIME = 0.03030; // 1/33 fps


Source file (general)

void CExampleStubAppView::ConstructL( const TRect& aRect )
{
...
ActivateL();
 
// Start updating screen in 33 fps speed
StartDrawingL();
}
 
void CExampleStubAppView::Draw( const TRect& /*aRect*/ ) const
{
CWindowGc& gc = SystemGc();
TRect drawRect( Rect());
gc.Clear( drawRect );
 
if (iDragging)
{
gc.SetBrushColor(KRgbRed);
gc.SetBrushStyle(CGraphicsContext::ESolidBrush);
gc.DrawRect(iPictureRect);
}
}
 
void CExampleStubAppView::StartDrawingL()
{
if (!iPeriodic)
{
iPeriodic = CPeriodic::NewL(CActive::EPriorityIdle);
}
iPeriodic->Start(TTimeIntervalMicroSeconds32(0),
DELAY, TCallBack(CExampleStubAppView::DoDraw, this));
}
 
void CExampleStubAppView::StopDrawing()
{
iPeriodic->Cancel();
}
 
TInt CExampleStubAppView::DoDraw(TAny* aObj)
{
static_cast<CExampleStubAppView*>(aObj)->DrawNow();
return 1;
}
 
void CExampleStubAppView::HandlePointerEventL(const TPointerEvent&
aPointerEvent)
{
if (aPointerEvent.iType == TPointerEvent::EButton1Down)
{
iPicturePoint = aPointerEvent.iPosition;
iPictureRect.SetRect(iPicturePoint,TSize(10,10));
iDragging = ETrue;
}
else if(aPointerEvent.iType == TPointerEvent::EDrag)
{
Move(aPointerEvent.iPosition);
}
else if(aPointerEvent.iType == TPointerEvent::EButton1Up)
{
iDragging = EFalse;
}
}
 
void CExampleStubAppView::EnableInterpolation(TBool aEnable)
{
iInterpolate = aEnable;
}


Source file (actual interpolation logic)

void CExampleStubAppView::Move(const TPoint& aPoint)
{
 
// No interpolation
if (!iInterpolate)
{
TPoint offset;
offset.iX = aPoint.iX - iPictureRect.iTl.iX;
offset.iY = aPoint.iY - iPictureRect.iTl.iY;
iPictureRect.Move(offset);
return;
}
 
// Use interpolation
 
// Stylus is here
iStylusPoint = aPoint;
 
StopDrawing();
TBool move = EFalse;
 
// Calculate picture smooth drawing to stylus position (interpolate)
if (iPicturePoint.iY < iStylusPoint.iY)
{
iPicturePoint.iY += ((iStylusPoint.iY - iPicturePoint.iY) * KSPEED) * KFRAMETIME;
move = ETrue;
}
if (iPicturePoint.iY > iStylusPoint.iY)
{
iPicturePoint.iY -= ((iPicturePoint.iY - iStylusPoint.iY) * KSPEED) * KFRAMETIME;
move = ETrue;
}
if (iPicturePoint.iX < iStylusPoint.iX)
{
iPicturePoint.iX += ((iStylusPoint.iX - iPicturePoint.iX ) * KSPEED) * KFRAMETIME;
move = ETrue;
}
if (iPicturePoint.iX > iStylusPoint.iX)
{
iPicturePoint.iX -= ((iPicturePoint.iX - iStylusPoint.iX) * KSPEED) * KFRAMETIME;
move = ETrue;
}
 
if (move)
{
iPictureRect = TRect(iPicturePoint,TSize(10,10));
StartDrawingL();
}
}


Postconditions

The object is moving smoothly on the screen when dragging it with the stylus.

See also

Full example source code: File:Interpolation ExampleStub.zip

Interpolation in Wikipedia.org

This page was last modified on 23 September 2014, at 19:58.
116 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×