void BRadioButton::Draw(BRect updateRect) { // its size depends on the text height font_height fontHeight; GetFontHeight(&fontHeight); rgb_color base = ui_color(B_PANEL_BACKGROUND_COLOR); uint32 flags = be_control_look->Flags(this); if (fOutlined) flags |= BControlLook::B_CLICKED; BRect knobRect(_KnobFrame(fontHeight)); BRect rect(knobRect); be_control_look->DrawRadioButton(this, rect, updateRect, base, flags); BRect labelRect(Bounds()); labelRect.left = knobRect.right + 1 + be_control_look->DefaultLabelSpacing(); const BBitmap* icon = IconBitmap( B_INACTIVE_ICON_BITMAP | (IsEnabled() ? 0 : B_DISABLED_ICON_BITMAP)); be_control_look->DrawLabel(this, Label(), icon, labelRect, updateRect, base, flags); }
BRect BRadioButton::_KnobFrame() const { font_height fontHeight; GetFontHeight(&fontHeight); return _KnobFrame(fontHeight); }
void BRadioButton::GetPreferredSize(float* _width, float* _height) { font_height fontHeight; GetFontHeight(&fontHeight); BRect rect(_KnobFrame(fontHeight)); float width = rect.right + rect.left; float height = rect.bottom + rect.top; const BBitmap* icon = IconBitmap(B_INACTIVE_ICON_BITMAP); if (icon != NULL) { width += be_control_look->DefaultLabelSpacing() + icon->Bounds().Width() + 1; height = std::max(height, icon->Bounds().Height()); } if (const char* label = Label()) { width += be_control_look->DefaultLabelSpacing() + ceilf(StringWidth(label)); height = std::max(height, ceilf(6.0f + fontHeight.ascent + fontHeight.descent)); } if (_width != NULL) *_width = width; if (_height != NULL) *_height = height; }
void BRadioButton::SetValue(int32 value) { if (value != Value()) { BControl::SetValueNoUpdate(value); Invalidate(_KnobFrame()); } if (value == 0) return; BView* parent = Parent(); BView* child = NULL; if (parent != NULL) { // If the parent is a BBox, the group parent is the parent of the BBox BBox* box = dynamic_cast<BBox*>(parent); if (box != NULL && box->LabelView() == this) parent = box->Parent(); if (parent != NULL) { BBox* box = dynamic_cast<BBox*>(parent); // If the parent is a BBox, skip the label if there is one if (box != NULL && box->LabelView()) child = parent->ChildAt(1); else child = parent->ChildAt(0); } else child = Window()->ChildAt(0); } else if (Window() != NULL) child = Window()->ChildAt(0); while (child != NULL) { BRadioButton* radio = dynamic_cast<BRadioButton*>(child); if (radio != NULL && (radio != this)) radio->SetValue(B_CONTROL_OFF); else { // If the child is a BBox, check if the label is a radiobutton BBox* box = dynamic_cast<BBox*>(child); if (box != NULL && box->LabelView()) { radio = dynamic_cast<BRadioButton*>(box->LabelView()); if (radio != NULL && (radio != this)) radio->SetValue(B_CONTROL_OFF); } } child = child->NextSibling(); } ASSERT(Value() == B_CONTROL_ON); }
void BRadioButton::GetPreferredSize(float* _width, float* _height) { font_height fontHeight; GetFontHeight(&fontHeight); if (_width) { BRect rect = _KnobFrame(fontHeight); float width = rect.right + floorf(ceilf(fontHeight.ascent + fontHeight.descent) / 2.0); if (Label()) width += StringWidth(Label()); *_width = ceilf(width); } if (_height) *_height = ceilf(fontHeight.ascent + fontHeight.descent) + 6.0; }
void BRadioButton::Draw(BRect updateRect) { // its size depends on the text height font_height fontHeight; GetFontHeight(&fontHeight); if (be_control_look != NULL) { rgb_color base = ui_color(B_PANEL_BACKGROUND_COLOR); uint32 flags = be_control_look->Flags(this); if (fOutlined) flags |= BControlLook::B_CLICKED; BRect knobRect(_KnobFrame(fontHeight)); BRect rect(knobRect); be_control_look->DrawRadioButton(this, rect, updateRect, base, flags); BRect labelRect(Bounds()); labelRect.left = knobRect.right + be_control_look->DefaultLabelSpacing(); be_control_look->DrawLabel(this, Label(), labelRect, updateRect, base, flags); return; } float textHeight = ceilf(fontHeight.ascent + fontHeight.descent); // layout the rect for the dot BRect rect = _KnobFrame(fontHeight); BPoint labelPos(rect.right + floorf(textHeight / 2.0), floorf((rect.top + rect.bottom + textHeight) / 2.0 - fontHeight.descent + 0.5) + 1.0); // if the focus is changing, just redraw the focus indicator if (IsFocusChanging()) { if (IsFocus()) SetHighColor(ui_color(B_KEYBOARD_NAVIGATION_COLOR)); else SetHighColor(ui_color(B_PANEL_BACKGROUND_COLOR)); BPoint underLine = labelPos; underLine.y += fontHeight.descent; StrokeLine(underLine, underLine + BPoint(StringWidth(Label()), 0.0)); return; } // colors rgb_color bg = ui_color(B_PANEL_BACKGROUND_COLOR); rgb_color lightenmax; rgb_color lighten1; rgb_color darken1; rgb_color darken2; rgb_color darken3; rgb_color darkenmax; rgb_color naviColor = ui_color(B_KEYBOARD_NAVIGATION_COLOR); rgb_color knob; rgb_color knobDark; rgb_color knobLight; if (IsEnabled()) { lightenmax = tint_color(bg, B_LIGHTEN_MAX_TINT); lighten1 = tint_color(bg, B_LIGHTEN_1_TINT); darken1 = tint_color(bg, B_DARKEN_1_TINT); darken2 = tint_color(bg, B_DARKEN_2_TINT); darken3 = tint_color(bg, B_DARKEN_3_TINT); darkenmax = tint_color(bg, B_DARKEN_MAX_TINT); knob = naviColor; knobDark = tint_color(naviColor, B_DARKEN_3_TINT); knobLight = tint_color(naviColor, 0.15); } else { lightenmax = tint_color(bg, B_LIGHTEN_2_TINT); lighten1 = bg; darken1 = bg; darken2 = tint_color(bg, B_DARKEN_1_TINT); darken3 = tint_color(bg, B_DARKEN_2_TINT); darkenmax = tint_color(bg, B_DISABLED_LABEL_TINT); knob = tint_color(naviColor, B_LIGHTEN_2_TINT); knobDark = tint_color(naviColor, B_LIGHTEN_1_TINT); knobLight = tint_color(naviColor, (B_LIGHTEN_2_TINT + B_LIGHTEN_MAX_TINT) / 2.0); } // dot if (Value() == B_CONTROL_ON) { // full SetHighColor(knobDark); FillEllipse(rect); SetHighColor(knob); FillEllipse(BRect(rect.left + 2, rect.top + 2, rect.right - 3, rect.bottom - 3)); SetHighColor(knobLight); FillEllipse(BRect(rect.left + 3, rect.top + 3, rect.right - 5, rect.bottom - 5)); } else { // empty SetHighColor(lightenmax); FillEllipse(rect); } rect.InsetBy(-1.0, -1.0); // outer circle if (fOutlined) { // indicating "about to change value" SetHighColor(darken3); StrokeEllipse(rect); } else { SetHighColor(darken1); StrokeArc(rect, 45.0, 180.0); SetHighColor(lightenmax); StrokeArc(rect, 45.0, -180.0); } rect.InsetBy(1, 1); // inner circle SetHighColor(darken3); StrokeArc(rect, 45.0, 180.0); SetHighColor(bg); StrokeArc(rect, 45.0, -180.0); // for faster font rendering, we can restore B_OP_COPY SetDrawingMode(B_OP_COPY); // label SetHighColor(darkenmax); DrawString(Label(), labelPos); // underline label if focused if (IsFocus()) { SetHighColor(naviColor); BPoint underLine = labelPos; underLine.y += fontHeight.descent; StrokeLine(underLine, underLine + BPoint(StringWidth(Label()), 0.0)); } }