⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 oggcontrols.cpp

📁 OggPlay for Symbian 是symbian上的一个媒体播放程序的源码。它支持ogg,wav等等多媒体格式。
💻 CPP
📖 第 1 页 / 共 4 页
字号:
    p.Debug(_L("Setting dimmed icon."));
    CGulIcon* i= p.ReadIcon(iBitmapFile);
    success= i!=0;
    if (success) SetDimmedIcon(i);
  }
  else if (p.iToken==_L("Style")) {
    p.Debug(_L("Setting style."));
    TInt s;
    success= p.ReadToken(s);
    if (success) SetStyle(s);
  }
  return success && COggControl::ReadArguments(p);
}


/***********************************************************
 *
 * COggSlider
 *
 ***********************************************************/

COggSlider::COggSlider() :
  COggControl(),
  iKnobIcon(0),
  iStyle(0),
  iValue(0),
  iMaxValue(100),
  iIsMoving(EFalse),
  iPos(0)
{
}

COggSlider::~COggSlider() {
    delete iKnobIcon;
}
void
COggSlider::SetKnobIcon(CGulIcon* anIcon)
{
  if (iKnobIcon) delete iKnobIcon;
  iKnobIcon= anIcon;
  iRedraw= ETrue;
}

void
COggSlider::SetStyle(TInt aStyle)
{
  iStyle= aStyle;
  iRedraw= ETrue; 
}

void
COggSlider::SetValue(TInt aValue)
{
  if (aValue==iValue) return;

  if (aValue<0) aValue=0;
  else if (aValue>iMaxValue) aValue= iMaxValue;

  iValue= aValue;
  iRedraw= (GetPosFromValue(iValue)!=iPos); 
}

void
COggSlider::SetMaxValue(TInt aMaxValue)
{
  iMaxValue= aMaxValue;
  iRedraw= ETrue;
}

TInt
COggSlider::CurrentValue()
{
  return iValue;
}

void 
COggSlider::Draw(CBitmapContext& aBitmapContext)
{
  if (!iKnobIcon) return;
  DrawFocus(aBitmapContext);
  TSize s(iKnobIcon->Bitmap()->SizeInPixels());
  TRect r(TPoint(0,0),s);
  TPoint p(ix,iy);

  iPos= GetPosFromValue(iValue);

  switch (iStyle) {
  case 0: r.iBr.iX= iPos; break;
  case 1: r.iTl.iY= iPos; break;
  case 2: p.iX= iPos; break;
  case 3: p.iY= iPos; break;
  }

  aBitmapContext.BitBltMasked
    (p,
     iKnobIcon->Bitmap(),
     r,
     iKnobIcon->Mask(),
     ETrue);
}

TInt COggSlider::GetPosFromValue(TInt aValue)
{
  if (!iKnobIcon) return 0;
  TSize s(iKnobIcon->Bitmap()->SizeInPixels());
  if (iMaxValue <= 0) return 0;
  switch (iStyle) {
  case 0: return (TInt)((float)iw/iMaxValue*aValue); break;
  case 1: return (TInt)((float)ih/iMaxValue*aValue); break;
  case 2: return ix+(TInt)((float)(iw-s.iWidth)/iMaxValue*aValue); break;
  case 3: return iy+(ih-s.iHeight) - TInt((float)(ih-s.iHeight)/iMaxValue*aValue); break;
  }
  return 0;
}

TInt COggSlider::GetValueFromPos(TInt aPos)
{
  if (!iKnobIcon) return 0;
  TSize s(iKnobIcon->Bitmap()->SizeInPixels());
  switch (iStyle) {
  case 0: return (TInt)((float)aPos*iMaxValue/iw); break;
  case 1: return (TInt)((float)aPos*iMaxValue/ih); break;
  case 2: return (TInt)((float)(aPos-s.iWidth/2)*iMaxValue/(iw-s.iWidth)); break;
  case 3: return (TInt)((float)((ih-s.iHeight) - (aPos-s.iHeight/2))*iMaxValue/(ih-s.iHeight)); break;
  }
  return 0;
}

void COggSlider::PointerEvent(const TPointerEvent& p)
{
  if (iDimmed) return;
  if (p.iType==TPointerEvent::EButton1Down) iIsMoving= ETrue;
  if (iIsMoving) {
    TPoint pt(p.iPosition);
    pt.iX-= ix;
    pt.iY-= iy;
    switch (iStyle) {
    case 0: SetValue(GetValueFromPos(pt.iX)); break;
    case 1: SetValue(GetValueFromPos(pt.iY)); break;
    case 2: SetValue(GetValueFromPos(pt.iX)); break;
    case 3: SetValue(GetValueFromPos(pt.iY)); break;
    }
  }
  if (p.iType==TPointerEvent::EButton1Up) {
    iIsMoving= EFalse;
    iRedraw= ETrue;
  }
  COggControl::PointerEvent(p);
}

TBool
COggSlider::ReadArguments(TOggParser& p)
{
  TBool success= ETrue;
  if (p.iToken==_L("KnobIcon")) {
    p.Debug(_L("Setting knob icon."));
    CGulIcon* i= p.ReadIcon(iBitmapFile);
    success= i!=0;
    if (success) SetKnobIcon(i);
  }
  else if (p.iToken==_L("Style")) {
    p.Debug(_L("Setting style."));
    TInt aStyle(0);
    success= p.ReadToken(aStyle);
    if (success) SetStyle(aStyle);
  }
  return success && COggControl::ReadArguments(p);
}


/***********************************************************
 *
 * COggScrollBar
 *
 ***********************************************************/

COggScrollBar::COggScrollBar() :
  COggControl(),
  iStyle(0),
  iValue(0),
  iMaxValue(100),
  iAssociated(0),
  iKnobIcon(0),
  iScrollerSize(10),
  iPos(0),
  iPage(1),
  iStep(1),
  iIsMoving(EFalse)
{
}
COggScrollBar::~COggScrollBar() {
    delete iKnobIcon;
}

void
COggScrollBar::SetStyle(TInt aStyle)
{
  iStyle= aStyle;
  iRedraw= ETrue;
}

void
COggScrollBar::SetKnobIcon(CGulIcon* anIcon)
{
  iKnobIcon= anIcon;
  iRedraw= ETrue;
}

void
COggScrollBar::SetScrollerSize(TInt aSize)
{
  iScrollerSize= aSize;
  iRedraw= ETrue;
}

void
COggScrollBar::SetPage(TInt aPage)
{
  iPage= aPage;
}

void
COggScrollBar::SetStep(TInt aStep)
{
  iStep= aStep;
}

void
COggScrollBar::SetAssociatedControl(COggControl* aControl)
{
  iAssociated= aControl;
}

void
COggScrollBar::Draw(CBitmapContext& aBitmapContext)
{
  if (!iKnobIcon) return;

  TSize s(iKnobIcon->Bitmap()->SizeInPixels());
  TRect r(TPoint(0,0),s);
  TPoint p(ix,iy);

  iPos= GetPosFromValue(iValue);

  switch (iStyle) {
  case 0: p.iX= iPos; break;
  case 1: p.iY= iPos; break;
  }

  aBitmapContext.BitBltMasked
    (p,
     iKnobIcon->Bitmap(),
     r,
     iKnobIcon->Mask(),
     ETrue);
}

void 
COggScrollBar::PointerEvent(const TPointerEvent& p)
{
  COggControl::PointerEvent(p);
  //if (!iKnobIcon) return;

  TSize s(0,0);
  if (iKnobIcon) s= iKnobIcon->Bitmap()->SizeInPixels();
  TInt k,s1,s2;
  if (iStyle==0) {
    k= s.iWidth;
    s1= p.iPosition.iX-ix;
    s2= p.iPosition.iX;
  } else {
    k= s.iHeight;
    s1= p.iPosition.iY-iy;
    s2= p.iPosition.iY;
  }

  if (p.iType==TPointerEvent::EButton1Up) iIsMoving= EFalse;

  if (p.iType==TPointerEvent::EButton1Down) {
    if (s1<iScrollerSize) {
      SetValue(iValue-iStep);
    } else if (s1>ih-iScrollerSize) {
      SetValue(iValue+iStep);
    } else if (s2>=iPos && s2<=iPos+k) {
      iIsMoving= ETrue;
    } else if (s2<iPos) {
      SetValue(iValue-iPage+1);
    } else if (s2>iPos+k) {
      SetValue(iValue+iPage-1);
    }
  }

  if (iIsMoving) SetValue(GetValueFromPos(s2));
}

void 
COggScrollBar::SetMaxValue(TInt aMaxValue)
{
  if (iMaxValue!=aMaxValue) {
    iMaxValue= aMaxValue;
    iRedraw= ETrue;
  }
}

void 
COggScrollBar::SetValue(TInt aValue)
{
  if (aValue<0) aValue=0;
  else if (aValue>iMaxValue) aValue= iMaxValue;
  if (iValue!=aValue) {
    iValue= aValue;
    iRedraw= (GetPosFromValue(aValue)!=iPos);
    if (iAssociated) iAssociated->ControlEvent(0, aValue);
  }
}

TInt 
COggScrollBar::GetPosFromValue(TInt aValue)
{
  if (!iKnobIcon || iMaxValue==0) return 0;
  TSize s(iKnobIcon->Bitmap()->SizeInPixels());
  switch (iStyle) {
  case 0: return ix+iScrollerSize+(TInt)((float)(iw-s.iWidth-2*iScrollerSize)/iMaxValue*aValue); break;
  case 1: return iy+iScrollerSize+(TInt)((float)(ih-s.iHeight-2*iScrollerSize)/iMaxValue*aValue); break;
  }
  return 0;
}

TInt 
COggScrollBar::GetValueFromPos(TInt aPos)
{
  if (!iKnobIcon) return 0;
  TSize s(iKnobIcon->Bitmap()->SizeInPixels());
  switch (iStyle) {
  case 0: return (TInt)((float)(aPos-ix-s.iWidth/2-iScrollerSize)*iMaxValue/(iw-s.iWidth-2*iScrollerSize)); break;
  case 1: return (TInt)((float)(aPos-iy-iScrollerSize-s.iHeight/2)*iMaxValue/(ih-s.iHeight-2*iScrollerSize)); break;
  }
  return 0;
}

TBool
COggScrollBar::ReadArguments(TOggParser& p)
{
  TBool success= COggControl::ReadArguments(p);
  if (success && p.iToken==_L("ScrollerSize")) {
    p.Debug(_L("Setting scroller size."));
    TInt i;
    success= p.ReadToken(i);
    if (success) SetScrollerSize(i);
  }
  if (success && p.iToken==_L("Style")) {
    p.Debug(_L("Setting style."));
    TInt i;
    success= p.ReadToken(i);
    if (success) SetStyle(i);
  }
  if (success && p.iToken==_L("Page")) {
    p.Debug(_L("Setting page."));
    TInt i;
    success= p.ReadToken(i);
    if (success) SetPage(i);
  }
  if (success && p.iToken==_L("KnobIcon")) {
    p.Debug(_L("Setting knob icon."));
    CGulIcon* c= p.ReadIcon(iBitmapFile);
    success= c!=0;
    if (success) SetKnobIcon(c);
  }
  if (success && p.iToken==_L("Step")) {
    p.Debug(_L("Setting step."));
    TInt i;
    success= p.ReadToken(i);
    if (success) SetStep(i);
  }
  return success;
}


/***********************************************************
 *
 * COggAnalyzer
 *
 ***********************************************************/
COggAnalyzer::COggAnalyzer()
: COggControl(ETrue), iNumValues(16), iStyle(1)
{
  iValues= new TInt[iNumValues];
  iPeaks= new TInt[iNumValues];
  iDx= (TInt)((float)iw/iNumValues);
  Clear();
}

COggAnalyzer::~COggAnalyzer()
{
  if (iValues) { delete[] iValues; iValues= 0; }
  if (iPeaks) { delete[] iPeaks; iPeaks= 0; }
  if (iBarIcon) { delete iBarIcon; iBarIcon= 0; }
}

void
COggAnalyzer::SetPosition(TInt ax, TInt ay, TInt aw, TInt ah)
{
  COggControl::SetPosition(ax,ay,aw,ah);
  iDx= (TInt)((float)iw/iNumValues);
}

void
COggAnalyzer::SetBarIcon(CGulIcon* aBarIcon)
{
  if (iBarIcon) delete iBarIcon;
  iBarIcon= aBarIcon;
  iRedraw= ETrue;
}

void
COggAnalyzer::SetValue(TInt i, TInt theValue)
{
  if (iValues[i]!=theValue) {
    iValues[i]= theValue;
    if (theValue>iPeaks[i]) iPeaks[i]= iValues[i];
    iRedraw= ETrue;
  }
}

void
COggAnalyzer::SetStyle(TInt aStyle)
{
  iStyle= aStyle;
  iRedraw= ETrue;
}

TInt
COggAnalyzer::Style()
{
  return iStyle;
}

void
COggAnalyzer::Cycle()
{
  if( iStyle == EPeak ) {
      iCycle++;
      if (iCycle%10==0) {
        iCycle= 0;
        for (int i=0; i<iNumValues; i++) {
          if (iPeaks[i]>0 || iPeaks[i]!=iValues[i]) {
            if (iPeaks[i]!=iValues[i]) { 
            iPeaks[i]= iValues[i];
            iRedraw= ETrue;
            }
          }
        }
      }
      else {
        for (int i=0; i<iNumValues; i++) {
          if (iValues[i]>iPeaks[i]) { 
            iPeaks[i]= iValues[i];
            iRedraw= ETrue;
          } 
        }
      }
    }
  else if( iStyle == EDecay ) {
    for (int i=0; i<iNumValues; i++) {
      if (iValues[i] && iValues[i] + KDecaySteplength > iPeaks[i]) { 
        iPeaks[i]= iValues[i];
        iRedraw= ETrue;
      }
      else {
        if( iPeaks[i] && (iPeaks[i] -= KDecaySteplength) < 0 ) {
          iPeaks[i] = 0;
          iRedraw= ETrue;
          }
      }
    }    
  }
}

void
COggAnalyzer::Draw(CBitmapContext& aBitmapContext)
{
  // Series 60 special mode
  if (iStyle==EDecay) {
    if (iBarIcon) {
      TInt x= ix;
      TSize s(iBarIcon->Bitmap()->SizeInPixels());
      for (int i=0; i<iNumValues; i++) {
        TInt val = iPeaks[i];
        TRect rc(TPoint(0,ih-val), s);
        aBitmapContext.BitBltMasked(TPoint(x,iy+ih-val),iBarIcon->Bitmap(), rc, iBarIcon->Mask(), ETrue);
        x+= iDx;
      }
    }
    return;
  }

  // UIQ rendering
  if (iBarIcon) {
    TInt x= ix;
    TSize s(iBarIcon->Bitmap()->SizeInPixels());
    for (int i=0; i<iNumValues; i++) {
      TRect rc(TPoint(0,ih-iValues[i]), s);
      aBitmapContext.BitBltMasked(TPoint(x,iy+ih-iValues[i]),iBarIcon->Bitmap(), rc, iBarIcon->Mask(), ETrue);
      x+= iDx;
    }
  }
  else {
    TRect r(TPoint(ix,iy),TSize(iDx-1,ih));
    aBitmapContext.SetBrushColor(KRgbBlue);
    for (int i=0; i<iNumValues; i++) {
      r.iTl.iY= iy+ih-iValues[i];
      aBitmapContext.Clear(r);
      r.Move(iDx,0);
    }
  }

  if (iStyle==EPeak) {
    aBitmapContext.SetBrushColor(KRgbDarkBlue);
    TRect p(TPoint(ix,iy),TSize(iDx-1,ih));
    for (int i=0; i<iNumValues; i++) {
      p.iTl.iY= iy+ih-iPeaks[i]-1;
      p.iBr.iY= p.iTl.iY+2;
      aBitmapContext.Clear(p);
      p.Move(iDx, 0);
    }
  }
}

#if!defined(SERIES60)
void COggAnalyzer::RenderWaveform(short int data[2][512])
#else
void COggAnalyzer::RenderWaveform(short int *data)
#endif
{
#if defined (SERIES60)
  if (!data)
	  return;
#endif

  if (iStyle==0) return;
  for (int i=0; i<512; i++) {
#if!defined(SERIES60)
    iFFTRe[i]= data[0][i];
#else
    iFFTRe[i]= *data++;
#endif
    iFFTIm[i]= 0;
  }
  window(iFFTRe, 512);
  fix_fft( iFFTRe, iFFTIm, 9, 0 );
  fix_loud( iFFTAbs, iFFTRe, iFFTIm, 256, 0);

  RenderFrequencies(iFFTAbs);
}

void COggAnalyzer::RenderWaveformFromMDCT(const TInt32* aFreqBins)
{
    // This function takes as input the maximal MDCT coefficients of 
    // each frequency bins 
    
    // Convert to log
    TInt i, j;
    for (j=0; j<16; j++)
    {
        TInt v = aFreqBins[j];
        for(i=0; i<KDCTAnalyzerDynamic; ++i)
        {
            if( loud2[i+12] <= v)
                break;
        }
        /* i is [0 43] */
        i = - i + KDCTAnalyzerDynamic ; /* [43 .. 0 ] */
        iValues[j]= (i*ih)/KDCTAnalyzerDynamic;
    }

  iRedraw= ETrue;
}

void COggAnalyzer::RenderFrequencies(short int data[256])
{
  if (iStyle==0) return;

  int i,c;
  int y;

  static const int xscale[17] = { 0, 1, 2, 3, 5, 7, 10, 14, 20, 28, 40, 54, 74, 101, 137, 187, 250 };

  for(i = 0; i < iNumValues; i++) {

    for(c = xscale[i], y = 10; c < xscale[i + 1]; c++)
      if (data[c] < y) y= data[c];

    iValues[i]= (TInt)((float)(y+100.)/110.*ih);
  }
  
  iRedraw= ETrue;
}

void COggAnalyzer::Clear()
{
  for (int i=0; i<iNumValues; i++) {
    if ( iValues[i] || iPeaks[i] ) {
      iValues[i]= 0;
      iPeaks[i]= 0;
      iRedraw= ETrue;
    }
  }
}

void COggAnalyzer::PointerEvent(const TPointerEvent& p)
{
  COggControl::PointerEvent(p);
  if (p.iType==TPointerEvent::EButton1Down) {
    iStyle= (iStyle+1)%3;
    iRedraw= ETrue;
    if (iStyle==0) Clear();
  }
}

TBool
COggAnalyzer::ReadArguments(TOggParser& p)
{
  TBool success= COggControl::ReadArguments(p);
  if (success && p.iToken==_L("Style")) {
    p.Debug(_L("Setting style."));
    success= p.ReadToken(iStyle);
  }
  if (success && p.iToken==_L("BarIcon")) {
    p.Debug(_L("Setting bar icon."));
    SetBarIcon(p.ReadIcon(iBitmapFile));
    success= iBarIcon!=0;
  }
  return success;
}


/***********************************************************
 *
 * COggListBox
 *
 ***********************************************************/
COggListBox::COggListBox() :
  COggControl(),
  iFontColor(0,0,0),
  iFontColorSelected(255,0,0),
  iSelected(-1)
{
  iData= CColumnListBoxData::NewL();
  iLineHeight= 16;
  iLinesVisible= 1;
}

COggListBox::~COggListBox()

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -