📄 mediacontrolview.cpp
字号:
return fSeekSlider->Value();}// GetVolumeuint32MediaControlView::GetVolume() const{ return fVolumeSlider->Value();}// SetSkippablevoidMediaControlView::SetSkippable(bool backward, bool forward){ fSkipBack->SetEnabled(backward); fSkipForward->SetEnabled(forward);}// SetMutedvoidMediaControlView::SetMuted(bool mute){ fVolumeSlider->SetMuted(mute);}// _LayoutControlsvoidMediaControlView::_LayoutControls(BRect frame) const{ // seek slider BRect r(frame); // calculate absolutly minimal width float minWidth = fSkipBack->Bounds().Width();// minWidth += fRewind->Bounds().Width(); minWidth += fStop->Bounds().Width(); minWidth += fPlayPause->Bounds().Width();// minWidth += fForward->Bounds().Width(); minWidth += fSkipForward->Bounds().Width(); minWidth += fMute->Bounds().Width(); minWidth += VOLUME_MIN_WIDTH; // layout time slider and info view float width, height; fPositionInfo->GetBigPreferredSize( &width, &height ); float ratio = width / height; width = r.Height() * ratio; if (frame.Width() - minWidth - MIN_SPACE >= width && frame.Height() >= height) { r.right = r.left + width; fPositionInfo->SetMode(PositionInfoView::MODE_BIG); _LayoutControl(fPositionInfo, r, true, true); frame.left = r.right + MIN_SPACE; r.left = frame.left; r.right = frame.right; // r.bottom = r.top + r.Height() / 2.0 - MIN_SPACE / 2.0; r.bottom = r.top + fSeekSlider->Bounds().Height(); _LayoutControl(fSeekSlider, r, true); } else { fPositionInfo->GetPreferredSize( &width, &height ); fPositionInfo->SetMode(PositionInfoView::MODE_SMALL); fPositionInfo->ResizeTo(width, height); r.bottom = r.top + r.Height() / 2.0 - MIN_SPACE / 2.0; r.right = r.left + fPositionInfo->Bounds().Width(); _LayoutControl(fPositionInfo, r, true ); r.left = r.right + MIN_SPACE; r.right = frame.right; _LayoutControl(fSeekSlider, r, true); } float currentWidth = frame.Width(); float space = (currentWidth - minWidth) / 6.0;//8.0; // apply weighting space = MIN_SPACE + (space - MIN_SPACE) / VOLUME_SLIDER_LAYOUT_WEIGHT; // layout controls with "space" inbetween r.left = frame.left; r.top = r.bottom + MIN_SPACE + 1.0; r.bottom = frame.bottom; // skip back r.right = r.left + fSkipBack->Bounds().Width(); _LayoutControl(fSkipBack, r); // rewind// r.left = r.right + space;// r.right = r.left + fRewind->Bounds().Width();// _LayoutControl(fRewind, r); // stop r.left = r.right + space; r.right = r.left + fStop->Bounds().Width(); _LayoutControl(fStop, r); // play/pause r.left = r.right + space; r.right = r.left + fPlayPause->Bounds().Width(); _LayoutControl(fPlayPause, r); // forward// r.left = r.right + space;// r.right = r.left + fForward->Bounds().Width();// _LayoutControl(fForward, r); // skip forward r.left = r.right + space; r.right = r.left + fSkipForward->Bounds().Width(); _LayoutControl(fSkipForward, r); // speaker icon r.left = r.right + space + space; r.right = r.left + fMute->Bounds().Width(); _LayoutControl(fMute, r); // volume slider r.left = r.right + SPEAKER_SLIDER_DIST; // keep speaker icon and volume slider attached r.right = frame.right; _LayoutControl(fVolumeSlider, r, true);}// _MinFrameBRect MediaControlView::_MinFrame() const{ // add up width of controls along bottom (seek slider will likely adopt) float minWidth = 2 * BORDER_INSET; minWidth += fSkipBack->Bounds().Width() + MIN_SPACE;// minWidth += fRewind->Bounds().Width() + MIN_SPACE; minWidth += fStop->Bounds().Width() + MIN_SPACE; minWidth += fPlayPause->Bounds().Width() + MIN_SPACE;// minWidth += fForward->Bounds().Width() + MIN_SPACE; minWidth += fSkipForward->Bounds().Width() + MIN_SPACE + MIN_SPACE; minWidth += fMute->Bounds().Width() + SPEAKER_SLIDER_DIST; minWidth += VOLUME_MIN_WIDTH; // add up height of seek slider and heighest control on bottom float minHeight = 2 * BORDER_INSET; minHeight += fSeekSlider->Bounds().Height() + MIN_SPACE + MIN_SPACE / 2.0; minHeight += fBottomControlHeight; return BRect(0.0, 0.0, minWidth - 1.0, minHeight - 1.0);}// _LayoutControlvoidMediaControlView::_LayoutControl(BView* view, BRect frame, bool resizeWidth, bool resizeHeight) const{ if (!resizeHeight) // center vertically frame.top = (frame.top + frame.bottom) / 2.0 - view->Bounds().Height() / 2.0; if (!resizeWidth) //center horizontally frame.left = (frame.left + frame.right) / 2.0 - view->Bounds().Width() / 2.0; view->MoveTo(frame.LeftTop()); float width = resizeWidth ? frame.Width() : view->Bounds().Width(); float height = resizeHeight ? frame.Height() : view->Bounds().Height(); if (resizeWidth || resizeHeight) view->ResizeTo(width, height);}/***************************************************************************** * SeekSlider *****************************************************************************/SeekSlider::SeekSlider(BRect frame, const char* name, MediaControlView *owner, int32 minValue, int32 maxValue) : BControl(frame, name, NULL, NULL, B_FOLLOW_NONE, B_WILL_DRAW | B_FULL_UPDATE_ON_RESIZE), fOwner(owner), fTracking(false), fMinValue(minValue), fMaxValue(maxValue){ BFont font(be_plain_font); font.SetSize(9.0); SetFont(&font);}SeekSlider::~SeekSlider(){ _EndSeek();}/***************************************************************************** * VolumeSlider::AttachedToWindow *****************************************************************************/voidSeekSlider::AttachedToWindow(){ BControl::AttachedToWindow(); SetViewColor(B_TRANSPARENT_32_BIT);}/***************************************************************************** * VolumeSlider::Draw *****************************************************************************/voidSeekSlider::Draw(BRect updateRect){ BRect r(Bounds()); float knobWidth2 = SEEK_SLIDER_KNOB_WIDTH / 2.0; float sliderStart = (r.left + knobWidth2); float sliderEnd = (r.right - knobWidth2); float knobPos = sliderStart + floorf((sliderEnd - sliderStart - 1.0) * (Value() - fMinValue) / (fMaxValue - fMinValue) + 0.5); // draw both sides (the original from Be doesn't seem // to make a difference for enabled/disabled state)// DrawBitmapAsync(fLeftSideBits, r.LeftTop());// DrawBitmapAsync(fRightSideBits, BPoint(sliderEnd + 1.0, r.top)); // colors for the slider area between the two bitmaps rgb_color background = kBackground;//ui_color(B_PANEL_BACKGROUND_COLOR); rgb_color shadow = tint_color(background, B_DARKEN_2_TINT); rgb_color softShadow = tint_color(background, B_DARKEN_1_TINT); rgb_color darkShadow = tint_color(background, B_DARKEN_4_TINT); rgb_color midShadow = tint_color(background, B_DARKEN_3_TINT); rgb_color light = tint_color(background, B_LIGHTEN_MAX_TINT); rgb_color softLight = tint_color(background, B_LIGHTEN_1_TINT); rgb_color green = kSeekGreen; rgb_color greenShadow = kSeekGreenShadow; rgb_color black = kBlack; rgb_color dotGrey = midShadow; rgb_color dotGreen = greenShadow; // draw frame _StrokeFrame(r, softShadow, softShadow, softLight, softLight); r.InsetBy(1.0, 1.0); _StrokeFrame(r, black, black, light, light); if (IsEnabled()) { r.InsetBy(1.0, 1.0); // inner shadow _StrokeFrame(r, greenShadow, greenShadow, green, green); r.top++; r.left++; _StrokeFrame(r, greenShadow, greenShadow, green, green); // inside area r.InsetBy(1.0, 1.0); SetHighColor(green); FillRect(r); // dots int32 dotCount = (int32)(r.Width() / 6.0); BPoint dotPos; dotPos.y = r.top + 2.0; SetHighColor(dotGreen); for (int32 i = 0; i < dotCount; i++) { dotPos.x = sliderStart + i * 6.0 + 5.0; StrokeLine(dotPos, BPoint(dotPos.x, dotPos.y + 6.0)); } // slider handle r.top -= 4.0; r.bottom += 3.0; r.left = knobPos - knobWidth2; r.right = knobPos + knobWidth2; // black outline float handleBottomSize = 2.0; float handleArrowSize = 6.0; BeginLineArray(10); // upper handle AddLine(BPoint(r.left, r.top + handleBottomSize), BPoint(r.left, r.top), black); AddLine(BPoint(r.left + 1.0, r.top), BPoint(r.right, r.top), black); AddLine(BPoint(r.right, r.top + 1.0), BPoint(r.right, r.top + handleBottomSize), black); AddLine(BPoint(r.right - 1.0, r.top + handleBottomSize + 1.0), BPoint(knobPos, r.top + handleArrowSize), black); AddLine(BPoint(knobPos - 1.0, r.top + handleArrowSize - 1.0), BPoint(r.left + 1.0, r.top + handleBottomSize + 1.0), black); // lower handle AddLine(BPoint(r.left, r.bottom), BPoint(r.left, r.bottom - handleBottomSize), black); AddLine(BPoint(r.left + 1.0, r.bottom - handleBottomSize - 1.0), BPoint(knobPos, r.bottom - handleArrowSize), black); AddLine(BPoint(knobPos + 1.0, r.bottom - handleArrowSize + 1.0), BPoint(r.right, r.bottom - handleBottomSize), black); AddLine(BPoint(r.right, r.bottom - handleBottomSize + 1.0), BPoint(r.right, r.bottom), black); AddLine(BPoint(r.right - 1.0, r.bottom), BPoint(r.left + 1.0, r.bottom), black); EndLineArray(); // inner red light and shadow lines r.InsetBy(1.0, 1.0); handleBottomSize--; handleArrowSize -= 2.0; BeginLineArray(10); // upper handle AddLine(BPoint(r.left, r.top + handleBottomSize), BPoint(r.left, r.top), kSeekRedLight); AddLine(BPoint(r.left + 1.0, r.top), BPoint(r.right, r.top), kSeekRedLight); AddLine(BPoint(r.right, r.top + 1.0), BPoint(r.right, r.top + handleBottomSize), kSeekRedShadow); AddLine(BPoint(r.right - 1.0, r.top + handleBottomSize + 1.0), BPoint(knobPos, r.top + handleArrowSize), kSeekRedShadow); AddLine(BPoint(knobPos - 1.0, r.top + handleArrowSize - 1.0), BPoint(r.left + 1.0, r.top + handleBottomSize + 1.0), kSeekRedLight); // lower handle AddLine(BPoint(r.left, r.bottom), BPoint(r.left, r.bottom - handleBottomSize), kSeekRedLight); AddLine(BPoint(r.left + 1.0, r.bottom - handleBottomSize - 1.0), BPoint(knobPos, r.bottom - handleArrowSize), kSeekRedLight); AddLine(BPoint(knobPos + 1.0, r.bottom - handleArrowSize + 1.0), BPoint(r.right, r.bottom - handleBottomSize), kSeekRedShadow); AddLine(BPoint(r.right, r.bottom - handleBottomSize + 1.0), BPoint(r.right, r.bottom), kSeekRedShadow); AddLine(BPoint(r.right - 1.0, r.bottom), BPoint(r.left + 1.0, r.bottom), kSeekRedShadow); EndLineArray(); // fill rest of handles with red SetHighColor(kSeekRed); r.InsetBy(1.0, 1.0); handleArrowSize -= 2.0; BPoint arrow[3]; // upper handle arrow arrow[0].x = r.left; arrow[0].y = r.top; arrow[1].x = r.right; arrow[1].y = r.top; arrow[2].x = knobPos; arrow[2].y = r.top + handleArrowSize; FillPolygon(arrow, 3); // lower handle arrow arrow[0].x = r.left; arrow[0].y = r.bottom; arrow[1].x = r.right; arrow[1].y = r.bottom; arrow[2].x = knobPos; arrow[2].y = r.bottom - handleArrowSize; FillPolygon(arrow, 3); } else { r.InsetBy(1.0, 1.0); _StrokeFrame(r, darkShadow, darkShadow, darkShadow, darkShadow); r.InsetBy(1.0, 1.0); _StrokeFrame(r, darkShadow, darkShadow, darkShadow, darkShadow); r.InsetBy(1.0, 1.0); SetHighColor(darkShadow); SetLowColor(shadow); // stripes float width = floorf(StringWidth(DISABLED_SEEK_MESSAGE)); float textPos = r.left + r.Width() / 2.0 - width / 2.0; pattern stripes = {{ 0xc7, 0x8f, 0x1f, 0x3e, 0x7c, 0xf8, 0xf1, 0xe3 }}; BRect stripesRect(r); stripesRect.right = textPos - 5.0; FillRect(stripesRect, stripes); stripesRect.left = textPos + width + 3.0; stripesRect.right = r.right; FillRect(stripesRect, stripes); // info text r.left = textPos - 4.0; r.right = textPos + width + 2.0; FillRect(r); SetHighColor(shadow); SetLowColor(darkShadow); font_height fh; GetFontHeight(&fh); DrawString(DISABLED_SEEK_MESSAGE, BPoint(textPos, r.top + ceilf(fh.ascent) - 1.0)); }}/***************************************************************************** * SeekSlider::MouseDown *****************************************************************************/voidSeekSlider::MouseDown(BPoint where){ if (IsEnabled() && Bounds().Contains(where)) { SetValue(_ValueFor(where.x)); fTracking = true; SetMouseEventMask(B_POINTER_EVENTS, B_LOCK_WINDOW_FOCUS); _BeginSeek(); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -