📄 wikilauncherappview.cpp
字号:
//
// Draw axis
//
// -------------------------------------------------
void CWikiLauncherAppView::DrawAxis( CWindowGc& aGc ) const
{
aGc.SetPenColor( KRgbBlack );
aGc.SetPenStyle( CWindowGc::ESolidPen );
aGc.DrawLine( TPoint( Rect().Width() / 2, 0 ), TPoint( Rect().Width() / 2, Rect().Height() ) );
aGc.DrawLine( TPoint( 0, Rect().Height() / 2 ), TPoint( Rect().Width(), Rect().Height() / 2 ) );
}
// -------------------------------------------------
//
// Draw actual coordinate
//
// -------------------------------------------------
void CWikiLauncherAppView::DrawActualCoord( CWindowGc& aGc ) const
{
if ( iPoints.Count() > 0 )
{
_LIT( KFormatter, "[%i:%i]" );
TBuf<16> text;
TPoint p = TransformCoordBack( iPoints[iPoints.Count()-1] );
aGc.UseFont( CEikonEnv::Static()->AnnotationFont() );
aGc.SetPenColor( KRgbBlack );
aGc.SetPenStyle( CWindowGc::ESolidPen );
text.Format( KFormatter, p.iX, p.iY );
aGc.DrawText( text, TPoint( 10, 50 ) );
text.Format( KFormatter, iPoints[iPoints.Count()-1].iX, iPoints[iPoints.Count()-1].iY );
aGc.DrawText( text, TPoint( 10, 65 ) );
aGc.DiscardFont();
}
}
// -------------------------------------------------
//
// Draw hand stroke
//
// -------------------------------------------------
void CWikiLauncherAppView::DrawHandStroke( CWindowGc& aGc ) const
{
if ( EMovement == iState )
{
aGc.SetPenColor( KRgbRed );
aGc.SetPenStyle( CWindowGc::ESolidPen );
for (TInt i = 0; i < iPoints.Count() - 1;i++)
aGc.DrawLine( iPoints[i], iPoints[i+1] );
}
}
// -------------------------------------------------
//
// Draw hand stroke
//
// -------------------------------------------------
void CWikiLauncherAppView::DrawLine( CWindowGc& aGc ) const
{
if ( EMovement == iState )
{
aGc.SetPenColor( KRgbGreen );
aGc.SetPenStyle( CWindowGc::ESolidPen );
// Get first and loast point
TPoint first = TransformCoord( iPoints[0] );
TPoint last = TransformCoord( iPoints[iPoints.Count()-1] );
// Compute its Y coordinates
first.iY = (TReal)(iB*first.iX) + iA;
last.iY = (TReal)(iB*last.iX) + iA;
// Transform them back to the pixel coordinates
first = TransformCoordBack( first );
last = TransformCoordBack( last );
aGc.DrawLine( first, last );
}
}
// -------------------------------------------------
//
// Draw direction
//
// -------------------------------------------------
void CWikiLauncherAppView::DrawDirection( CWindowGc& aGc ) const
{
if ( EMovement == iState )
{
TReal angleDeg;
if ( Angle( angleDeg ) > KErrNotFound )
{
_LIT( KFormatter, "[Ang:%f]" );
TBuf<64> text;
text.Format( KFormatter, angleDeg );
aGc.UseFont( CEikonEnv::Static()->AnnotationFont() );
aGc.SetPenColor( KRgbBlack );
aGc.SetPenStyle( CWindowGc::ESolidPen );
aGc.DrawText( text, TPoint( 10, 80 ) );
aGc.DiscardFont();
}
}
}
// -------------------------------------------------
//
// Transfrom coordinates from pixel-based
// coordinate to 0,0 system
//
// -------------------------------------------------
TPoint CWikiLauncherAppView::TransformCoord( TPoint aPoint ) const
{
return TPoint( aPoint.iX - Rect().Width() / 2, -(aPoint.iY - Rect().Height() / 2) );
}
// -------------------------------------------------
//
// Transfrom coordinates back
//
// -------------------------------------------------
TPoint CWikiLauncherAppView::TransformCoordBack( TPoint aPoint ) const
{
return TPoint( aPoint.iX + Rect().Width() / 2, Rect().Height() - (aPoint.iY + Rect().Height() / 2) );
}
// -------------------------------------------------
//
// Calculate linear regression (least square)
// coeficients
//
// -------------------------------------------------
void CWikiLauncherAppView::CalculateLinearRegressionCoef()
{
// LR variables
TReal n, sumX, sumY, sumXsqr, sumXY;
n = sumX = sumY = sumXsqr = sumXY = 0;
// Transform from pixel coordinates
RArray<TPoint> points;
for (TInt i = 0; i < iPoints.Count() - 1;i++)
points.Append( TransformCoord(iPoints[i]) );
// Compute LR variables
for (TInt i = 0; i < points.Count() - 1;i++)
{
n++;
sumX += points[i].iX;
sumY += points[i].iY;
sumXsqr += points[i].iX * points[i].iX;
sumXY += points[i].iX * points[i].iY;
}
// y = iA + iB * x
iB = ( n * sumXY - sumY * sumX) / ( n * sumXsqr - sumX * sumX);
iA = (sumY - iB * sumX) / n;
points.Close();
}
// -------------------------------------------------
//
// Get angle in degrees (not radians!)
//
// -------------------------------------------------
TInt CWikiLauncherAppView::Angle( TReal& aAngleDeg ) const
{
if ( EMovement == iState )
{
TReal angle = 0;
Math::ATan( angle, iB );
angle *= 180/KPi;
TInt y1 = iB*1 + iA;
TInt y2 = iB*2 + iA;
if ( y1 < y2 )
{
if ( iPoints[0].iX > iPoints[iPoints.Count() - 1].iX )
aAngleDeg = angle + 180;
else
aAngleDeg = angle;
}
else
{
if ( iPoints[0].iX > iPoints[iPoints.Count() - 1].iX )
aAngleDeg = angle + 180;
else
aAngleDeg = angle + 360;
}
return KErrNone;
}
else
return KErrNotFound;
}
// ---------------------------------------------
//
// Check if at least at one direction the
// values are increasing...
//
// ---------------------------------------------
TBool CWikiLauncherAppView::CheckHandStroke()
{
TBool directX = ETrue;
TBool directY = ETrue;
for ( TInt i = 0; i < iPoints.Count() -1 ; i++ )
{
if ( iPoints[0].iX > iPoints[iPoints.Count() - 1].iX )
directX = iPoints[i].iX > iPoints[i+1].iX;
else
directX = iPoints[i].iX < iPoints[i+1].iX;
if ( iPoints[0].iY > iPoints[iPoints.Count() - 1].iY )
directY = iPoints[i].iY > iPoints[i+1].iY;
else
directY = iPoints[i].iY < iPoints[i+1].iY;
}
return ( directX | directY );
}
// ---------------------------------------------------------
//
// Get the direction
//
// ---------------------------------------------------------
TInt CWikiLauncherAppView::Direction( TRotationDirection& aDirection) const
{
TReal angle;
if ( Angle( angle ) == KErrNone )
{
if ( angle >= 45 & angle < 45 + 90 )
aDirection = ERotationUp;
else
if ( angle >= 45 + 90 & angle < 45 + 180 )
aDirection = ERotationLeft;
else
if ( angle >= 45 + 180 & angle < 45 + 270 )
aDirection = ERotationDown;
else
aDirection = ERotationRight;
return KErrNone;
}
else
return KErrNotFound;
}
// ---------------------------------------------------------
//
// Draw the rotated cube
//
// ---------------------------------------------------------
TInt CWikiLauncherAppView::DrawCallBack( TAny* aInstance )
{
#if defined( __TEXTURE_CUBE__ )
#define iCube iTextureCube
#else
#define iCube iSimpleCube
#endif
CWikiLauncherAppView* self = (CWikiLauncherAppView*) aInstance;
#if defined( __TEXTURE_CUBE__ )
if ( self->iCube->GetState() != self->iTextureCubeState &&
self->iTextureCubeState == CTexture::ELoadingTextures )
{
eglSwapBuffers( self->iEglDisplay, self->iEglSurface );
self->iPeriodic->Cancel();
self->iAnimation = EFalse;
self->iTextureCubeState = CTexture::ERunning;
return KErrNone;
}
if ( self->iCube->GetState() == CTexture::ERunning )
{
#endif
/* Check if the textures are loaded before doing any rendering. */
TRotationDirection d;
if ( self->Direction( d ) == KErrNone )
{
switch (d)
{
case ERotationRight: self->iAngle = self->iAngle + 5;break;
case ERotationLeft: self->iAngle = self->iAngle - 5;break;
default:
{
self->iPeriodic->Cancel();
self->iAnimation = EFalse;
return KErrNone;
}
}
/* Call the main OpenGL ES Symbian rendering 'loop' */
self->iCube->AppCycle( self->iAngle, d);
// Call eglSwapBuffers, which blit the graphics to the window
eglSwapBuffers( self->iEglDisplay, self->iEglSurface );
// Suspend the current thread for a short while. Give some time
// to other threads and AOs, avoids the ViewSrv error in ARMI and
// THUMB release builds. One may try to decrease the callback
// function instead of this.
if ( !( self->iAngle % 50 ) )
{
User::After(0);
}
// Cancel after 90 degree is rotated
if ( (self->iAngle % 90 == 0) )
{
self->iPeriodic->Cancel();
self->iAnimation = EFalse;
}
}
else
{
self->iPeriodic->Cancel();
self->iAnimation = EFalse;
}
#if defined( __TEXTURE_CUBE__ )
}
#endif
return KErrNone;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -