📄 aslider.cpp
字号:
dc->DrawText(_("R"), mRightX-7, 1); } else { // draw the '-' and the '+' dc->SetPen(*wxBLACK_PEN); dc->DrawLine(mLeftX, mCenterY-10, mLeftX+5, mCenterY-10); dc->DrawLine(mRightX-7, mCenterY-10, mRightX-2, mCenterY-10); dc->DrawLine(mRightX-5, mCenterY-12, mRightX-5, mCenterY-7); } delete dc; if (i==0) mBitmap = bitmap; else mSelBitmap = bitmap; } delete backgroundImage; int x=mWidth/2, y=mHeight, wx, wy; wxWindow *top = mParent; while(top && !top->IsTopLevel()) { top->GetPosition(&wx, &wy); x += wx; y += wy; top = top->GetParent(); } mPopWin = NULL; Move(pos); CreatePopWin();}LWSlider::~LWSlider(){ delete mBitmap; delete mSelBitmap; delete mThumbBitmap; delete mSelThumbBitmap; delete mPopWin;}void LWSlider::SetId(wxWindowID id){ mID = id;}void LWSlider::CreatePopWin(){ if (mPopWin) return; wxString maxStr = mName + wxT(": 000000"); if (mStyle == PAN_SLIDER || mStyle == DB_SLIDER || mStyle == SPEED_SLIDER) maxStr += wxT("000"); wxWindow *top = mParent; while(top && !top->IsTopLevel()) { top = top->GetParent(); } mPopWin = new TipPanel(top, -1, maxStr, wxDefaultPosition); mPopWin->Hide();}void LWSlider::SetPopWinPosition(){ int x, y, wx, wy; x=mWidth/2 + mLeft; y=mHeight + mTop + 1; wxWindow *top = mParent; while(top && !top->IsTopLevel()) { top->GetPosition(&wx, &wy); x += wx; y += wy; top = top->GetParent(); } if (mPopWin) ((TipPanel *)mPopWin)->SetPos(wxPoint(x, y));}void LWSlider::Move(const wxPoint &newpos){ mLeft = newpos.x; mTop = newpos.y;}void LWSlider::RecreateTipWin(){ delete mPopWin; mPopWin = NULL; CreatePopWin();}void LWSlider::OnPaint(wxDC &dc, bool selected){ //thumbPos should be in pixels int thumbPos = ValueToPosition(mCurrentValue); int thumbY = mCenterY - (mThumbHeight/2); wxBitmap *bitmap; wxBitmap *thumbBitmap; if (selected) { bitmap = mSelBitmap; thumbBitmap = mSelThumbBitmap; } else { bitmap = mBitmap; thumbBitmap = mThumbBitmap; }#if defined(__WXMAC__) || defined(__WXMSW__) dc.DrawBitmap(*bitmap, mLeft, mTop); dc.DrawBitmap(*thumbBitmap, mLeft+thumbPos, mTop+thumbY);#else wxMemoryDC memDC; memDC.SelectObject(*bitmap); dc.Blit(mLeft, mTop, mWidth, mHeight, &memDC, 0, 0, wxCOPY, FALSE); memDC.SelectObject(*thumbBitmap); dc.Blit(mLeft+thumbPos, mTop+thumbY, mThumbWidth, mThumbHeight, &memDC, 0, 0, wxCOPY, FALSE);#endif if (mPopWin) mPopWin->Refresh();}void LWSlider::FormatPopWin(){ wxString label; wxString valstr; switch(mStyle) { case FRAC_SLIDER: label.Printf(wxT("%s: %.1f"), mName.c_str(), mCurrentValue); break; case DB_SLIDER: valstr.Printf(wxT("%.1f"), mCurrentValue); if (valstr.Right(1) == wxT("0")) valstr = valstr.Left(valstr.Length() - 2); if (mCurrentValue > 0) valstr = wxT("+") + valstr; label.Printf(wxT("%s: %s dB"), mName.c_str(), valstr.c_str()); break; case PAN_SLIDER: if (mCurrentValue == 0.0) label.Printf(wxT("%s: %s"), mName.c_str(), _("Center")); else { if (mCurrentValue < 0.0) label.Printf(wxT("%s: %.0f%% %s"), mName.c_str(), -mCurrentValue * 100.0f, _("Left")); else /* if (val > 0.0) */ label.Printf(wxT("%s: %.0f%% %s"), mName.c_str(), mCurrentValue * 100.0f, _("Right")); } break; case SPEED_SLIDER: label.Printf(wxT("%s: %.2fx"), mName.c_str(), mCurrentValue); break; } ((TipPanel *)mPopWin)->label = label;}void LWSlider::OnMouseEvent(wxMouseEvent & event){ if (event.Entering()) { #if wxUSE_TOOLTIPS // Not available in wxX11 // Display the tooltip in the status bar if (mParent->GetToolTip()) { wxString tip = mParent->GetToolTip()->GetTip(); GetActiveProject()->TP_DisplayStatusMessage(tip); Refresh(); } #endif } else if (event.Leaving()) { GetActiveProject()->TP_DisplayStatusMessage(wxT("")); Refresh(); } float prevValue = mCurrentValue; if (event.ButtonDClick()) { //On a double-click, we should pop up a dialog. SliderDialog * dialog = new SliderDialog(mParent, -1, mName, mParent->ClientToScreen(wxPoint(event.m_x,event.m_y)), wxSize(mWidth,mHeight), mStyle, Get()); if(dialog->ShowModal() == wxID_OK) Set(dialog->Get()); dialog->Destroy(); Refresh(); } else if (event.ButtonDown()) { //This jumps the thumb to clicked position if (!mIsDragging) { mCurrentValue = PositionToValue(event.m_x, event.ShiftDown()); mIsDragging = true; mParent->CaptureMouse(); FormatPopWin(); SetPopWinPosition(); mPopWin->Show(); } // Don't generate notification yet return; } else if (event.ButtonUp() && mIsDragging) { mIsDragging = false; mParent->ReleaseMouse(); mPopWin->Hide(); ((TipPanel *)mPopWin)->SetPos(wxPoint(-1000, -1000)); } else if (event.Dragging() && mIsDragging) { mCurrentValue = PositionToValue(event.m_x, event.ShiftDown()); } else if (event.m_wheelRotation != 0) { //Calculate the number of steps in a given direction this event //represents (allows for two or more clicks on a single event.) int steps = event.m_wheelRotation / (event.m_wheelDelta > 0 ? event.m_wheelDelta : 120); float stepSize = mStepValue; if(stepSize == 0) { stepSize = (mMaxValue - mMinValue)/10; } Set(Get()+ steps * stepSize); Refresh(); } if (prevValue != mCurrentValue) { FormatPopWin(); mPopWin->Refresh(); Refresh(); wxCommandEvent *e = new wxCommandEvent(wxEVT_COMMAND_SLIDER_UPDATED, mID); int intValue = (int)((mCurrentValue - mMinValue) * 1000.0f / (mMaxValue - mMinValue)); e->SetInt( intValue ); mParent->ProcessEvent(*e); delete e; }}int LWSlider::ValueToPosition(float val){ return (int)rint((val - mMinValue) * mWidthX / (mMaxValue - mMinValue));}float LWSlider::PositionToValue(int xPos, bool shiftDown){ int pos = (xPos - mLeft) - mLeftX; // MM: Special cases: If position is at the very left or the // very right, set minimum/maximum value without other checks if (pos <= 0) return mMinValue; if (pos >= mWidthX) return mMaxValue; float val = ((float)pos/(float)mWidthX) * (mMaxValue - mMinValue) + mMinValue; if (!(mCanUseShift && shiftDown) && mStepValue != STEP_CONTINUOUS) { // MM: If shift is not down, or we don't allow usage // of shift key at all, trim value to steps of // provided size. val = (int)(val / mStepValue + 0.5 * (val>0?1.0f:-1.0f)) * mStepValue; } return val;}float LWSlider::Get(){ if (mStyle == DB_SLIDER) return pow(10.0f, mCurrentValue / 20.0f); else return mCurrentValue;}void LWSlider::Set(float value){ if(mIsDragging) return; if (mStyle == DB_SLIDER) mCurrentValue = 20.0f*log10(value); else mCurrentValue = value; if (mCurrentValue < mMinValue) mCurrentValue = mMinValue; if (mCurrentValue > mMaxValue) mCurrentValue = mMaxValue; Refresh();}void LWSlider::Increase(int steps){ if(mIsDragging) return; mCurrentValue += (steps * mStepValue); if (mCurrentValue < mMinValue) mCurrentValue = mMinValue; if (mCurrentValue > mMaxValue) mCurrentValue = mMaxValue; Refresh();}void LWSlider::Decrease(int steps){ if(mIsDragging) return; mCurrentValue -= (steps * mStepValue); if (mCurrentValue < mMinValue) mCurrentValue = mMinValue; if (mCurrentValue > mMaxValue) mCurrentValue = mMaxValue; Refresh();}void LWSlider::Refresh(){ if (mHW) mParent->Refresh(false);}//// ASlider//BEGIN_EVENT_TABLE(ASlider, wxWindow) EVT_MOUSE_EVENTS(ASlider::OnMouseEvent) EVT_PAINT(ASlider::OnPaint)END_EVENT_TABLE()ASlider::ASlider(wxWindow * parent, wxWindowID id, wxString name, const wxPoint & pos, const wxSize & size): wxWindow(parent, id, pos, size){ mLWSlider = new LWSlider(this, name, wxPoint(0, 0), size, FRAC_SLIDER, true); mLWSlider->SetId(id);}ASlider::ASlider(wxWindow * parent, wxWindowID id, wxString name, const wxPoint & pos, const wxSize & size, int style): wxWindow(parent,id,pos,size){ mLWSlider = new LWSlider(this, name, wxPoint(0,0),size, style, true); mLWSlider->SetId(id);}ASlider::~ASlider(){ delete mLWSlider;}void ASlider::OnPaint(wxPaintEvent &event){ wxPaintDC dc(this); mLWSlider->OnPaint(dc, false);}void ASlider::OnMouseEvent(wxMouseEvent &event){ mLWSlider->OnMouseEvent(event);}void ASlider::RecreateTipWin(){ mLWSlider->RecreateTipWin();}float ASlider::Get(){ return mLWSlider->Get();}void ASlider::Set(float value){ mLWSlider->Set(value);}void ASlider::Increase(int steps){ mLWSlider->Increase(steps);}void ASlider::Decrease(int steps){ mLWSlider->Decrease(steps);}// Indentation settings for Vim and Emacs and unique identifier for Arch, a// version control system. Please do not modify past this point.//// Local Variables:// c-basic-offset: 3// indent-tabs-mode: nil// End://// vim: et sts=3 sw=3// arch-tag: 0030c06f-7a62-40eb-b833-0a9fb96d1f55
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -