void CCrossHairView::Draw(BRect updateRect) { BRect bounds = Bounds(); SetHighColor(CColor::Transparent); FillRect(bounds); BRect bigCircle, smallCircle; float width = bounds.Width(); float height = bounds.Height(); bigCircle = bounds.InsetByCopy(5, 5); smallCircle = bounds.InsetByCopy(10, 10); SetHighColor(CColor::White); StrokeEllipse(bigCircle.OffsetByCopy(1, 1)); StrokeEllipse(smallCircle.OffsetByCopy(1, 1)); StrokeLine(BPoint(2, height/2+1), BPoint(width, height/2+1)); StrokeLine(BPoint(width/2+1, 2), BPoint(width/2+1, height)); SetHighColor(CColor::Black); StrokeEllipse(bigCircle); StrokeEllipse(smallCircle); StrokeLine(BPoint(1, height/2), BPoint(width-1, height/2)); StrokeLine(BPoint(width/2, 1), BPoint(width/2, height-1)); Sync(); }
// Draw void ColorField::Draw(BRect updateRect) { if (fBitmapDirty && fBitmap != NULL) { _FillBitmap(fBitmap, fMode, fFixedValue, fOrientation); fBitmapDirty = false; } BRect bounds = Bounds(); // Frame if (fBorderStyle == B_FANCY_BORDER) { rgb_color color = LowColor(); be_control_look->DrawTextControlBorder(this, bounds, updateRect, color); BRegion region(bounds); ConstrainClippingRegion(®ion); } // Color field fill if (fBitmap != NULL) DrawBitmap(fBitmap, bounds.LeftTop()); else { SetHighColor(255, 0, 0); FillRect(bounds); } // Marker SetHighColor(0, 0, 0); StrokeEllipse(fMarkerPosition + bounds.LeftTop(), 5.0, 5.0); SetHighColor(255.0, 255.0, 255.0); StrokeEllipse(fMarkerPosition + bounds.LeftTop(), 4.0, 4.0); }
void RenderView::Draw(BRect updateRect) { static int count = 0; BRect frame = Frame(); // Erase previous drawing (this is the lazy and slow way) FillRect(frame, B_SOLID_LOW); frame.InsetBy(50, 50); StrokeEllipse(frame); if (fInHoverArea) FillRect(fHoverRect); else StrokeRect(fHoverRect); MovePenTo(25, 25); rgb_color color = HighColor(); char str[100]; sprintf(str, "Hello from RenderBoy! Count is %d, high color is RGB(%d, %d, %d)", count, color.red, color.green, color.blue); DrawString(str); // Change the color for next Draw call color.red += 3; color.green += 3; color.blue += 3; SetHighColor(color); count++; }
void ColorPreview::Draw(BRect update) { rgb_color color; if (is_enabled) color = currentcol; else color = disabledcol; if (is_rect) { if (is_enabled) { rgb_color background = ui_color(B_PANEL_BACKGROUND_COLOR); rgb_color shadow = tint_color(background, B_DARKEN_1_TINT); rgb_color darkShadow = tint_color(background, B_DARKEN_3_TINT); rgb_color light = tint_color(background, B_LIGHTEN_MAX_TINT); BRect bounds(Bounds()); BeginLineArray(4); AddLine(BPoint(bounds.left, bounds.bottom), BPoint(bounds.left, bounds.top), shadow); AddLine(BPoint(bounds.left + 1.0, bounds.top), BPoint(bounds.right, bounds.top), shadow); AddLine(BPoint(bounds.right, bounds.top + 1.0), BPoint(bounds.right, bounds.bottom), light); AddLine(BPoint(bounds.right - 1.0, bounds.bottom), BPoint(bounds.left + 1.0, bounds.bottom), light); EndLineArray(); bounds.InsetBy(1.0, 1.0); BeginLineArray(4); AddLine(BPoint(bounds.left, bounds.bottom), BPoint(bounds.left, bounds.top), darkShadow); AddLine(BPoint(bounds.left + 1.0, bounds.top), BPoint(bounds.right, bounds.top), darkShadow); AddLine(BPoint(bounds.right, bounds.top + 1.0), BPoint(bounds.right, bounds.bottom), background); AddLine(BPoint(bounds.right - 1.0, bounds.bottom), BPoint(bounds.left + 1.0, bounds.bottom), background); EndLineArray(); bounds.InsetBy(1.0, 1.0); SetHighColor(color); FillRect(bounds); } else { SetHighColor(color); FillRect(Bounds()); } } else { // fill background SetHighColor(ui_color(B_PANEL_BACKGROUND_COLOR)); FillRect(update); SetHighColor(color); FillEllipse(Bounds()); if (is_enabled) StrokeEllipse(Bounds(), B_SOLID_LOW); } }
void Activity::Draw(BRect rect) { bigtime_t present = system_time() - 600000; for (int i = 0; i < 4; i++) for (int j = 0; j < 4; j++) { BPoint aPoint(i * 60 + 70, j * 60 + 70); SetHighColor(0, 0, 0); StrokeEllipse(aPoint, 5, 5); SetHighColor(0, 255, 0); if (present < fActivity[j * 4 + i]) FillEllipse(aPoint, 4, 4); } }
// Draw void TestView::Draw(BRect updateRect) { // ellipses SetHighColor(200, 90, 0, 100); StrokeEllipse(BPoint(80.0, 50.0), 70.0, 40.0); SetDrawingMode(B_OP_ALPHA); SetPenSize(2.0); SetHighColor(20, 40, 180, 150); StrokeEllipse(BPoint(230.0, 90.0), 14.0, 60.0); SetPenSize(5.0); SetHighColor(60, 20, 110, 100); StrokeEllipse(BPoint(100.0, 180.0), 35.0, 25.0); // text SetHighColor(0, 0, 0, 255); SetDrawingMode(B_OP_OVER); const char* message = "Click and drag to scroll this view!"; DrawString(message, BPoint(0.0, 30.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)); } }
float PieView::_DrawDirectory(BRect b, FileInfo* info, float parentSpan, float beginAngle, int colorIdx, int level) { if (b.Width() < 2.0 * (kPieCenterSize + level * kPieRingSize + kPieOuterMargin + kPieInnerMargin)) { return 0.0; } if (info != NULL && info->color >= 0 && level == 0) colorIdx = info->color % kBasePieColorCount; else if (info != NULL) info->color = colorIdx; VolumeSnapshot* snapshot = fScanner->Snapshot(); float cx = floorf(b.left + b.Width() / 2.0 + 0.5); float cy = floorf(b.top + b.Height() / 2.0 + 0.5); float mySpan; if (level == 0) { // Make room for mouse over info. fMouseOverInfo.clear(); fMouseOverInfo[0] = SegmentList(); // Draw the center circle. const char* displayName; if (info == NULL) { // NULL represents the entire volume. Show used and free space in // the center circle, with the used segment representing the // volume's root directory. off_t volCapacity = snapshot->capacity; mySpan = 360.0 * (volCapacity - snapshot->freeBytes) / volCapacity; SetHighColor(kEmptySpcColor); FillEllipse(BPoint(cx, cy), kPieCenterSize, kPieCenterSize); SetHighColor(kBasePieColor[0]); FillArc(BPoint(cx, cy), kPieCenterSize, kPieCenterSize, 0.0, mySpan); // Show total volume capacity. char label[B_PATH_NAME_LENGTH]; size_to_string(volCapacity, label, sizeof(label)); SetHighColor(kPieBGColor); SetDrawingMode(B_OP_OVER); DrawString(label, BPoint(cx - StringWidth(label) / 2.0, cy + fFontHeight + kSmallVMargin)); SetDrawingMode(B_OP_COPY); displayName = snapshot->name.c_str(); // Record in-use space and free space for use during MouseMoved(). info = snapshot->rootDir; info->color = colorIdx; fMouseOverInfo[0].push_back(Segment(0.0, mySpan, info)); if (mySpan < 360.0 - kMinSegmentSpan) { fMouseOverInfo[0].push_back(Segment(mySpan, 360.0, snapshot->freeSpace)); } } else { // Show a normal directory. SetHighColor(kBasePieColor[colorIdx]); FillEllipse(BRect(cx - kPieCenterSize, cy - kPieCenterSize, cx + kPieCenterSize + 0.5, cy + kPieCenterSize + 0.5)); displayName = info->ref.name; mySpan = 360.0; // Record the segment for use during MouseMoved(). fMouseOverInfo[0].push_back(Segment(0.0, mySpan, info)); } SetPenSize(1.0); SetHighColor(kOutlineColor); StrokeEllipse(BPoint(cx, cy), kPieCenterSize + 0.5, kPieCenterSize + 0.5); // Show the name of the volume or directory. BString label(displayName); BFont font; GetFont(&font); font.TruncateString(&label, B_TRUNCATE_END, 2.0 * (kPieCenterSize - kSmallHMargin)); float labelWidth = font.StringWidth(label.String()); SetHighColor(kPieBGColor); SetDrawingMode(B_OP_OVER); DrawString(label.String(), BPoint(cx - labelWidth / 2.0, cy)); SetDrawingMode(B_OP_COPY); beginAngle = 0.0; } else { // Draw an exterior segment. float parentSize; if (info->parent == NULL) parentSize = (float)snapshot->capacity; else parentSize = (float)info->parent->size; mySpan = parentSpan * (float)info->size / parentSize; if (mySpan >= kMinSegmentSpan) { const float tint = 1.4f - level * 0.08f; float radius = kPieCenterSize + level * kPieRingSize - kPieRingSize / 2.0; // Draw the grey border SetHighColor(tint_color(kOutlineColor, tint)); SetPenSize(kPieRingSize + 1.5f); StrokeArc(BPoint(cx, cy), radius, radius, beginAngle - 0.001f * radius, mySpan + 0.002f * radius); // Draw the colored area rgb_color color = tint_color(kBasePieColor[colorIdx], tint); SetHighColor(color); SetPenSize(kPieRingSize); StrokeArc(BPoint(cx, cy), radius, radius, beginAngle, mySpan); // Record the segment for use during MouseMoved(). if (fMouseOverInfo.find(level) == fMouseOverInfo.end()) fMouseOverInfo[level] = SegmentList(); fMouseOverInfo[level].push_back( Segment(beginAngle, beginAngle + mySpan, info)); } } // Draw children. vector<FileInfo*>::iterator i = info->children.begin(); while (i != info->children.end()) { float childSpan = _DrawDirectory(b, *i, mySpan, beginAngle, colorIdx, level + 1); if (childSpan >= kMinSegmentSpan) { beginAngle += childSpan; colorIdx = (colorIdx + 1) % kBasePieColorCount; } i++; } return mySpan; }