void BSlider::SetBarThickness(float thickness) { if (thickness < 1.0) thickness = 1.0; else thickness = roundf(thickness); if (thickness != fBarThickness) { // calculate invalid barframe and extend by hashmark size float hInset = 0.0; float vInset = 0.0; if (fOrientation == B_HORIZONTAL) vInset = -6.0; else hInset = -6.0; BRect invalid = BarFrame().InsetByCopy(hInset, vInset) | ThumbFrame(); fBarThickness = thickness; invalid = invalid | BarFrame().InsetByCopy(hInset, vInset) | ThumbFrame(); Invalidate(invalid); InvalidateLayout(); } }
void APPosSlider::DrawThumb(void) { BRect rect; BView *view; // Get the frame rectangle of the thumb // and the offscreen view rect = ThumbFrame(); view = OffscreenView(); // Draw the black shadow view->SetDrawingMode(B_OP_ALPHA); rgb_color c = BeDarkShadow; c.alpha = 128; view->SetHighColor(c); rect.top++; rect.left++; view->FillEllipse(rect); // Fill the inside of the thumb view->SetDrawingMode(B_OP_COPY); view->SetHighColor(BeButtonGrey); rect.OffsetBy(-1, -1); view->FillEllipse(rect); // Draw the dark grey edge view->SetHighColor(86, 86, 86, 255); // TODO : use an Haiku define to get that ? view->SetPenSize(1.2); view->StrokeEllipse(rect); }
void BSlider::DrawFocusMark() { if (!IsFocus()) return; OffscreenView()->SetHighColor(ui_color(B_KEYBOARD_NAVIGATION_COLOR)); BRect frame = ThumbFrame(); if (fStyle == B_BLOCK_THUMB) { frame.left += 2.0f; frame.top += 2.0f; frame.right -= 3.0f; frame.bottom -= 3.0f; OffscreenView()->StrokeRect(frame); } else { if (fOrientation == B_HORIZONTAL) { OffscreenView()->StrokeLine(BPoint(frame.left, frame.bottom + 2.0f), BPoint(frame.right, frame.bottom + 2.0f)); } else { OffscreenView()->StrokeLine(BPoint(frame.left - 2.0f, frame.top), BPoint(frame.left - 2.0f, frame.bottom)); } } }
void BSlider::SetValue(int32 value) { if (value < fMinValue) value = fMinValue; if (value > fMaxValue) value = fMaxValue; if (value == Value()) return; _SetLocationForValue(value); BRect oldThumbFrame = ThumbFrame(); // While it would be enough to do this dependent on fUseFillColor, // that doesn't work out if DrawBar() has been overridden by a sub class if (fOrientation == B_HORIZONTAL) oldThumbFrame.top = BarFrame().top; else oldThumbFrame.left = BarFrame().left; BControl::SetValueNoUpdate(value); BRect invalid = oldThumbFrame | ThumbFrame(); if (Style() == B_TRIANGLE_THUMB) { // 1) We need to take care of pixels touched because of anti-aliasing. // 2) We need to update the region with the focus mark as well. (A // method BSlider::FocusMarkFrame() would be nice as well.) if (fOrientation == B_HORIZONTAL) { if (IsFocus()) invalid.bottom += 2; invalid.InsetBy(-1, 0); } else { if (IsFocus()) invalid.left -= 2; invalid.InsetBy(0, -1); } } Invalidate(invalid); UpdateTextChanged(); }
void SeekSlider::DrawThumb() { if (!IsEnabled()) return; BRect frame = ThumbFrame(); be_control_look->DrawSliderTriangle(this, frame, frame, kThumbRed, 0, B_HORIZONTAL); }
BSize SeekSlider::MaxSize() { BSize size = BSlider::MaxSize(); BRect unscaledThumbFrame = BSlider::ThumbFrame(); BRect scaledThumbFrame = ThumbFrame(); size.height += scaledThumbFrame.Height() - unscaledThumbFrame.Height(); return size; }
void SeekSlider::GetPreferredSize(float* _width, float* _height) { BSlider::GetPreferredSize(_width, _height); if (_width != NULL) { float minWidth = 15.0 + StringWidth(fDisabledString.String()) + 15.0; *_width = max_c(*_width, minWidth); } if (_height != NULL) { BRect unscaledThumbFrame = BSlider::ThumbFrame(); BRect scaledThumbFrame = ThumbFrame(); *_height += scaledThumbFrame.Height() - unscaledThumbFrame.Height(); } }
void BSlider::Draw(BRect updateRect) { // clear out background BRegion background(updateRect); background.Exclude(BarFrame()); bool drawBackground = true; if (Parent() && (Parent()->Flags() & B_DRAW_ON_CHILDREN) != 0) { // This view is embedded somewhere, most likely the Tracker Desktop // shelf. drawBackground = false; } // ToDo: the triangle thumb doesn't delete its background, so we still have // to do it Note, this also creates a different behaviour for subclasses, // depending on the thumb style - if possible this should be avoided. if (Style() == B_BLOCK_THUMB) { BRect thumbFrame = ThumbFrame(); if (be_control_look != NULL) { // fill background where shadow will be... // TODO: Such drawint dependent behavior should be moved into // BControlLook of course. thumbFrame.right--; thumbFrame.bottom--; } background.Exclude(thumbFrame); } #if USE_OFF_SCREEN_VIEW if (!fOffScreenBits) return; if (fOffScreenBits->Lock()) { fOffScreenView->SetViewColor(ViewColor()); fOffScreenView->SetLowColor(LowColor()); #endif if (drawBackground && background.Frame().IsValid()) OffscreenView()->FillRegion(&background, B_SOLID_LOW); #if USE_OFF_SCREEN_VIEW fOffScreenView->Sync(); fOffScreenBits->Unlock(); } #endif DrawSlider(); }
void BSlider::MouseDown(BPoint point) { if (!IsEnabled()) return; if (BarFrame().Contains(point) || ThumbFrame().Contains(point)) fInitialLocation = _Location(); uint32 buttons; GetMouse(&point, &buttons, true); _ConstrainPoint(point, fInitialLocation); SetValue(ValueForPoint(point)); if (_Location() != fInitialLocation) InvokeNotify(ModificationMessage(), B_CONTROL_MODIFIED); if (Window()->Flags() & B_ASYNCHRONOUS_CONTROLS) { SetTracking(true); SetMouseEventMask(B_POINTER_EVENTS, B_LOCK_WINDOW_FOCUS | B_NO_POINTER_HISTORY); } else { // synchronous mouse tracking BPoint prevPoint; while (buttons) { prevPoint = point; snooze(SnoozeAmount()); GetMouse(&point, &buttons, true); if (_ConstrainPoint(point, prevPoint)) { int32 value = ValueForPoint(point); if (value != Value()) { SetValue(value); InvokeNotify(ModificationMessage(), B_CONTROL_MODIFIED); } } } if (_Location() != fInitialLocation) Invoke(); } }
void APPosSlider::DrawFocusMark(void) { BRect rect; BView *view; rgb_color color; if (IsFocus()) { // Get the frame rectangle of the thumb // and the offscreen view rect = ThumbFrame(); view = OffscreenView(); // Get the color to use color = keyboard_navigation_color(); view->SetHighColor(color); // Draw a circle inside the thumb rect.InsetBy(2.0f, 2.0f); view->StrokeEllipse(rect); } }
void BSlider::DrawBar() { BRect frame = BarFrame(); BView *view = OffscreenView(); if (be_control_look != NULL) { uint32 flags = be_control_look->Flags(this); rgb_color base = ui_color(B_PANEL_BACKGROUND_COLOR); rgb_color rightFillColor = fBarColor; rgb_color leftFillColor = fUseFillColor ? fFillColor : fBarColor; be_control_look->DrawSliderBar(view, frame, frame, base, leftFillColor, rightFillColor, Position(), flags, fOrientation); return; } rgb_color no_tint = ui_color(B_PANEL_BACKGROUND_COLOR); rgb_color lightenmax; rgb_color darken1; rgb_color darken2; rgb_color darkenmax; rgb_color barColor; rgb_color fillColor; if (IsEnabled()) { lightenmax = tint_color(no_tint, B_LIGHTEN_MAX_TINT); darken1 = tint_color(no_tint, B_DARKEN_1_TINT); darken2 = tint_color(no_tint, B_DARKEN_2_TINT); darkenmax = tint_color(no_tint, B_DARKEN_MAX_TINT); barColor = fBarColor; fillColor = fFillColor; } else { lightenmax = tint_color(no_tint, B_LIGHTEN_MAX_TINT); darken1 = no_tint; darken2 = tint_color(no_tint, B_DARKEN_1_TINT); darkenmax = tint_color(no_tint, B_DARKEN_3_TINT); barColor.red = (fBarColor.red + no_tint.red) / 2; barColor.green = (fBarColor.green + no_tint.green) / 2; barColor.blue = (fBarColor.blue + no_tint.blue) / 2; barColor.alpha = 255; fillColor.red = (fFillColor.red + no_tint.red) / 2; fillColor.green = (fFillColor.green + no_tint.green) / 2; fillColor.blue = (fFillColor.blue + no_tint.blue) / 2; fillColor.alpha = 255; } // exclude the block thumb from the bar filling BRect lowerFrame = frame.InsetByCopy(1, 1); lowerFrame.top++; lowerFrame.left++; BRect upperFrame = lowerFrame; BRect thumbFrame; if (Style() == B_BLOCK_THUMB) { thumbFrame = ThumbFrame(); if (fOrientation == B_HORIZONTAL) { lowerFrame.right = thumbFrame.left; upperFrame.left = thumbFrame.right; } else { lowerFrame.top = thumbFrame.bottom; upperFrame.bottom = thumbFrame.top; } } else if (fUseFillColor) { if (fOrientation == B_HORIZONTAL) { lowerFrame.right = floor(lowerFrame.left - 1 + Position() * (lowerFrame.Width() + 1)); upperFrame.left = lowerFrame.right; } else { lowerFrame.top = floor(lowerFrame.bottom + 1 - Position() * (lowerFrame.Height() + 1)); upperFrame.bottom = lowerFrame.top; } } view->SetHighColor(barColor); view->FillRect(upperFrame); if (Style() == B_BLOCK_THUMB || fUseFillColor) { if (fUseFillColor) view->SetHighColor(fillColor); view->FillRect(lowerFrame); } if (Style() == B_BLOCK_THUMB) { // We don't want to stroke the lines over the thumb PushState(); BRegion region; GetClippingRegion(®ion); region.Exclude(thumbFrame); ConstrainClippingRegion(®ion); } view->SetHighColor(darken1); view->StrokeLine(BPoint(frame.left, frame.top), BPoint(frame.left + 1.0f, frame.top)); view->StrokeLine(BPoint(frame.left, frame.bottom), BPoint(frame.left + 1.0f, frame.bottom)); view->StrokeLine(BPoint(frame.right - 1.0f, frame.top), BPoint(frame.right, frame.top)); view->SetHighColor(darken2); view->StrokeLine(BPoint(frame.left + 1.0f, frame.top), BPoint(frame.right - 1.0f, frame.top)); view->StrokeLine(BPoint(frame.left, frame.bottom - 1.0f), BPoint(frame.left, frame.top + 1.0f)); view->SetHighColor(lightenmax); view->StrokeLine(BPoint(frame.left + 1.0f, frame.bottom), BPoint(frame.right, frame.bottom)); view->StrokeLine(BPoint(frame.right, frame.bottom - 1.0f), BPoint(frame.right, frame.top + 1.0f)); frame.InsetBy(1.0f, 1.0f); view->SetHighColor(darkenmax); view->StrokeLine(BPoint(frame.left, frame.bottom), BPoint(frame.left, frame.top)); view->StrokeLine(BPoint(frame.left + 1.0f, frame.top), BPoint(frame.right, frame.top)); if (Style() == B_BLOCK_THUMB) PopState(); }
void BSlider::_DrawTriangleThumb() { BRect frame = ThumbFrame(); BView *view = OffscreenView(); if (be_control_look != NULL) { rgb_color base = ui_color(B_PANEL_BACKGROUND_COLOR); uint32 flags = be_control_look->Flags(this); be_control_look->DrawSliderTriangle(view, frame, frame, base, flags, fOrientation); return; } rgb_color no_tint = ui_color(B_PANEL_BACKGROUND_COLOR); rgb_color lightenmax; rgb_color lighten1; rgb_color darken2; rgb_color darken3; rgb_color darkenmax; if (IsEnabled()) { lightenmax = tint_color(no_tint, B_LIGHTEN_MAX_TINT); lighten1 = no_tint; darken2 = tint_color(no_tint, B_DARKEN_2_TINT); darken3 = tint_color(no_tint, B_DARKEN_3_TINT); darkenmax = tint_color(no_tint, B_DARKEN_MAX_TINT); } else { lightenmax = tint_color(no_tint, B_LIGHTEN_2_TINT); lighten1 = tint_color(no_tint, B_LIGHTEN_1_TINT); darken2 = tint_color(no_tint, (B_NO_TINT + B_DARKEN_1_TINT) / 2); darken3 = tint_color(no_tint, B_DARKEN_1_TINT); darkenmax = tint_color(no_tint, B_DARKEN_3_TINT); } if (Orientation() == B_HORIZONTAL) { view->SetHighColor(lighten1); view->FillTriangle( BPoint(frame.left + 1, frame.bottom - 3), BPoint((frame.left + frame.right) / 2, frame.top + 1), BPoint(frame.right - 1, frame.bottom - 3)); view->SetHighColor(no_tint); view->StrokeLine(BPoint(frame.right - 2, frame.bottom - 3), BPoint(frame.left + 3, frame.bottom - 3)); view->SetHighColor(darkenmax); view->StrokeLine(BPoint(frame.left, frame.bottom - 1), BPoint(frame.right, frame.bottom - 1)); view->StrokeLine(BPoint(frame.right, frame.bottom - 2), BPoint((frame.left + frame.right) / 2, frame.top)); view->SetHighColor(darken2); view->StrokeLine(BPoint(frame.right - 1, frame.bottom - 2), BPoint(frame.left + 1, frame.bottom - 2)); view->SetHighColor(darken3); view->StrokeLine(BPoint(frame.left, frame.bottom - 2), BPoint((frame.left + frame.right) / 2 - 1, frame.top + 1)); view->SetHighColor(lightenmax); view->StrokeLine(BPoint(frame.left + 2, frame.bottom - 3), BPoint((frame.left + frame.right) / 2, frame.top + 1)); // Shadow view->SetHighColor(0, 0, 0, IsEnabled() ? 80 : 40); view->SetDrawingMode(B_OP_ALPHA); view->StrokeLine(BPoint(frame.left + 1, frame.bottom), BPoint(frame.right, frame.bottom)); } else { view->SetHighColor(lighten1); view->FillTriangle( BPoint(frame.left, (frame.top + frame.bottom) / 2), BPoint(frame.right - 1, frame.top + 1), BPoint(frame.right - 1, frame.bottom - 1)); view->SetHighColor(darkenmax); view->StrokeLine(BPoint(frame.right - 1, frame.top), BPoint(frame.right - 1, frame.bottom)); view->StrokeLine(BPoint(frame.right - 1, frame.bottom), BPoint(frame.right - 2, frame.bottom)); view->SetHighColor(darken2); view->StrokeLine(BPoint(frame.right - 2, frame.top + 2), BPoint(frame.right - 2, frame.bottom - 1)); view->StrokeLine( BPoint(frame.left, (frame.top + frame.bottom) / 2), BPoint(frame.right - 2, frame.top)); view->SetHighColor(darken3); view->StrokeLine( BPoint(frame.left + 1, (frame.top + frame.bottom) / 2 + 1), BPoint(frame.right - 3, frame.bottom - 1)); view->SetHighColor(lightenmax); view->StrokeLine( BPoint(frame.left + 1, (frame.top + frame.bottom) / 2), BPoint(frame.right - 2, frame.top + 1)); // Shadow view->SetHighColor(0, 0, 0, IsEnabled() ? 80 : 40); view->SetDrawingMode(B_OP_ALPHA); view->StrokeLine(BPoint(frame.right, frame.top + 1), BPoint(frame.right, frame.bottom)); } view->SetDrawingMode(B_OP_COPY); }
void BSlider::_DrawBlockThumb() { BRect frame = ThumbFrame(); BView *view = OffscreenView(); if (be_control_look != NULL) { rgb_color base = ui_color(B_PANEL_BACKGROUND_COLOR); uint32 flags = be_control_look->Flags(this); be_control_look->DrawSliderThumb(view, frame, frame, base, flags, fOrientation); return; } rgb_color no_tint = ui_color(B_PANEL_BACKGROUND_COLOR); rgb_color lighten2; rgb_color lighten1; rgb_color darken2; rgb_color darken3; rgb_color darkenmax; if (IsEnabled()) { lighten2 = tint_color(no_tint, B_LIGHTEN_2_TINT); lighten1 = no_tint; darken2 = tint_color(no_tint, B_DARKEN_2_TINT); darken3 = tint_color(no_tint, B_DARKEN_3_TINT); darkenmax = tint_color(no_tint, B_DARKEN_MAX_TINT); } else { lighten2 = tint_color(no_tint, B_LIGHTEN_2_TINT); lighten1 = tint_color(no_tint, B_LIGHTEN_1_TINT); darken2 = tint_color(no_tint, (B_NO_TINT + B_DARKEN_1_TINT) / 2.0); darken3 = tint_color(no_tint, B_DARKEN_1_TINT); darkenmax = tint_color(no_tint, B_DARKEN_3_TINT); } // blank background for shadow // ToDo: this also draws over the hash marks (though it's not *that* noticeable) view->SetHighColor(no_tint); view->StrokeLine(BPoint(frame.left, frame.top), BPoint(frame.left, frame.top)); BRect barFrame = BarFrame(); if (barFrame.right >= frame.right) { // leave out barFrame from shadow background clearing view->StrokeLine(BPoint(frame.right, frame.top), BPoint(frame.right, barFrame.top - 1.0f)); view->StrokeLine(BPoint(frame.right, barFrame.bottom + 1.0f), BPoint(frame.right, frame.bottom)); } else { view->StrokeLine(BPoint(frame.right, frame.top), BPoint(frame.right, frame.bottom)); } view->StrokeLine(BPoint(frame.left, frame.bottom), BPoint(frame.right - 1.0f, frame.bottom)); view->StrokeLine(BPoint(frame.left, frame.bottom - 1.0f), BPoint(frame.left, frame.bottom - 1.0f)); view->StrokeLine(BPoint(frame.right - 1.0f, frame.top), BPoint(frame.right - 1.0f, frame.top)); // Outline (top, left) view->SetHighColor(darken3); view->StrokeLine(BPoint(frame.left, frame.bottom - 2.0f), BPoint(frame.left, frame.top + 1.0f)); view->StrokeLine(BPoint(frame.left + 1.0f, frame.top), BPoint(frame.right - 2.0f, frame.top)); // Shadow view->SetHighColor(0, 0, 0, IsEnabled() ? 100 : 50); view->SetDrawingMode(B_OP_ALPHA); view->StrokeLine(BPoint(frame.right, frame.top + 2.0f), BPoint(frame.right, frame.bottom - 1.0f)); view->StrokeLine(BPoint(frame.left + 2.0f, frame.bottom), BPoint(frame.right - 1.0f, frame.bottom)); view->SetDrawingMode(B_OP_COPY); view->SetHighColor(darken3); view->StrokeLine(BPoint(frame.right - 1.0f, frame.bottom - 1.0f), BPoint(frame.right - 1.0f, frame.bottom - 1.0f)); // First bevel frame.InsetBy(1.0f, 1.0f); view->SetHighColor(darkenmax); view->StrokeLine(BPoint(frame.left, frame.bottom), BPoint(frame.right - 1.0f, frame.bottom)); view->StrokeLine(BPoint(frame.right, frame.bottom - 1.0f), BPoint(frame.right, frame.top)); view->SetHighColor(lighten2); view->StrokeLine(BPoint(frame.left, frame.top), BPoint(frame.left, frame.bottom - 1.0f)); view->StrokeLine(BPoint(frame.left + 1.0f, frame.top), BPoint(frame.right - 1.0f, frame.top)); frame.InsetBy(1.0f, 1.0f); view->FillRect(BRect(frame.left, frame.top, frame.right - 1.0f, frame.bottom - 1.0f)); // Second bevel and center dots view->SetHighColor(darken2); view->StrokeLine(BPoint(frame.left, frame.bottom), BPoint(frame.right, frame.bottom)); view->StrokeLine(BPoint(frame.right, frame.bottom - 1.0f), BPoint(frame.right, frame.top)); if (Orientation() == B_HORIZONTAL) { view->StrokeLine(BPoint(frame.left + 6.0f, frame.top + 2.0f), BPoint(frame.left + 6.0f, frame.top + 2.0f)); view->StrokeLine(BPoint(frame.left + 6.0f, frame.top + 4.0f), BPoint(frame.left + 6.0f, frame.top + 4.0f)); view->StrokeLine(BPoint(frame.left + 6.0f, frame.top + 6.0f), BPoint(frame.left + 6.0f, frame.top + 6.0f)); } else { view->StrokeLine(BPoint(frame.left + 2.0f, frame.top + 6.0f), BPoint(frame.left + 2.0f, frame.top + 6.0f)); view->StrokeLine(BPoint(frame.left + 4.0f, frame.top + 6.0f), BPoint(frame.left + 4.0f, frame.top + 6.0f)); view->StrokeLine(BPoint(frame.left + 6.0f, frame.top + 6.0f), BPoint(frame.left + 6.0f, frame.top + 6.0f)); } frame.InsetBy(1.0f, 1.0f); // Third bevel view->SetHighColor(lighten1); view->StrokeLine(BPoint(frame.left, frame.bottom), BPoint(frame.right, frame.bottom)); view->StrokeLine(BPoint(frame.right, frame.bottom - 1.0f), BPoint(frame.right, frame.top)); }
void VolumeSlider::DrawThumb() { #if ROUND_KNOB // Draw a round thumb BRect rect(ThumbFrame()); rgb_color base = ui_color(B_PANEL_BACKGROUND_COLOR); rgb_color frameLightColor; rgb_color frameShadowColor; rgb_color shadowColor = (rgb_color){ 0, 0, 0, 60 }; float topTint = 0.49; float middleTint1 = 0.62; float middleTint2 = 0.76; float bottomTint = 0.90; if (!IsEnabled()) { topTint = (topTint + B_NO_TINT) / 2; middleTint1 = (middleTint1 + B_NO_TINT) / 2; middleTint2 = (middleTint2 + B_NO_TINT) / 2; bottomTint = (bottomTint + B_NO_TINT) / 2; shadowColor = (rgb_color){ 0, 0, 0, 30 }; } // Draw shadow #if !KNOB_EMBEDDED rect.left++; rect.top++; SetDrawingMode(B_OP_ALPHA); SetHighColor(shadowColor); FillEllipse(rect); // Draw thumb shape rect.OffsetBy(-1, -1); #endif if (IsFocus()) { // focused frameLightColor = ui_color(B_KEYBOARD_NAVIGATION_COLOR); frameShadowColor = frameLightColor; } else { // figure out the tints to be used float frameLightTint; float frameShadowTint; if (!IsEnabled()) { frameLightTint = 1.30; frameShadowTint = 1.35; shadowColor.alpha = 30; } else { frameLightTint = 1.6; frameShadowTint = 1.65; } frameLightColor = tint_color(base, frameLightTint); frameShadowColor = tint_color(base, frameShadowTint); } BGradientLinear frameGradient; frameGradient.AddColor(frameShadowColor, 0); frameGradient.AddColor(frameLightColor, 255); frameGradient.SetStart(rect.LeftTop()); frameGradient.SetEnd(rect.RightBottom()); FillEllipse(rect, frameGradient); rect.InsetBy(1, 1); // frameGradient.MakeEmpty(); // frameGradient.AddColor(borderColor, 0); // frameGradient.AddColor(tint_color(borderColor, 0.8), 255); // view->FillEllipse(rect, frameGradient); // rect.InsetBy(1, 1); BGradientLinear gradient; if (!IsEnabled()) { gradient.AddColor(tint_color(base, topTint), 0); gradient.AddColor(tint_color(base, bottomTint), 255); } else { gradient.AddColor(tint_color(base, topTint), 0); gradient.AddColor(tint_color(base, middleTint1), 132); gradient.AddColor(tint_color(base, middleTint2), 136); gradient.AddColor(tint_color(base, bottomTint), 255); } gradient.SetStart(rect.LeftTop()); gradient.SetEnd(rect.LeftBottom()); FillEllipse(rect, gradient); #else BSlider::DrawThumb(); #endif }