void TextDiffView::Draw(BRect updateRect) { rgb_color oldHighColor = HighColor(); float oldPenSize = PenSize(); BRect bounds = Bounds(); float leftWidth = floor((bounds.Width() + 1 - B_H_SCROLL_BAR_HEIGHT - PANE_SPLITTER_WIDTH) / 2); if (updateRect.left <= leftWidth + 1) { SetPenSize(0); SetHighColor(tint_color(ui_color(B_PANEL_BACKGROUND_COLOR), B_DARKEN_2_TINT)); StrokeLine(BPoint(leftWidth, updateRect.top), BPoint(leftWidth, updateRect.bottom), B_SOLID_HIGH); SetHighColor(tint_color(ui_color(B_PANEL_BACKGROUND_COLOR), B_LIGHTEN_1_TINT)); StrokeLine(BPoint(leftWidth + 1, updateRect.top), BPoint(leftWidth + 1, updateRect.bottom), B_SOLID_HIGH); } if (updateRect.right >= leftWidth + PANE_SPLITTER_WIDTH - 2) { SetPenSize(0); SetHighColor(tint_color(ui_color(B_PANEL_BACKGROUND_COLOR), B_DARKEN_1_TINT)); StrokeLine(BPoint(leftWidth + PANE_SPLITTER_WIDTH - 2, updateRect.top), BPoint(leftWidth + PANE_SPLITTER_WIDTH - 2, updateRect.bottom), B_SOLID_HIGH); SetHighColor(tint_color(ui_color(B_PANEL_BACKGROUND_COLOR), B_DARKEN_2_TINT)); StrokeLine(BPoint(leftWidth + PANE_SPLITTER_WIDTH - 1, updateRect.top), BPoint(leftWidth + PANE_SPLITTER_WIDTH - 1, updateRect.bottom), B_SOLID_HIGH); } SetPenSize(oldPenSize); SetHighColor(oldHighColor); }
int ScrolledListView::TrackInsertionStep(BPoint point, int prevInsertionIndex) { BRect bounds = Bounds(); float itemHeight = ItemHeight(); int32 numItems = NumItems(); // autoscroll if (point.y < bounds.top) { if (bounds.top > 0) { ScrollBy(0, -itemHeight); bounds.OffsetBy(0, -itemHeight); } point.y = bounds.top; } else if (point.y > bounds.bottom) { if (bounds.bottom < numItems * itemHeight - 1) { ScrollBy(0, itemHeight); bounds.OffsetBy(0, itemHeight); } point.y = bounds.bottom + 1; // need the +1 to let it get beyond the last item } // figure out where it is now int32 curInsertionIndex = (int) (point.y / itemHeight); if (curInsertionIndex < 0) curInsertionIndex = 0; else if (curInsertionIndex > numItems) // can move beyond the last item curInsertionIndex = numItems; // draw if (curInsertionIndex != prevInsertionIndex) { // redraw items bordering old indicator, to clear it if (prevInsertionIndex >= 0) { if (prevInsertionIndex > 0) DrawItemAt(prevInsertionIndex - 1); if (prevInsertionIndex < numItems) DrawItemAt(prevInsertionIndex); else { // need to clean up bottom BRect bottomRect = bounds; bottomRect.top = prevInsertionIndex * itemHeight; FillRect(bottomRect, B_SOLID_LOW); } } // draw new indicator SetHighColor(insertionIndicatorColor); SetPenSize(2.0); float indicatorY = curInsertionIndex * itemHeight; StrokeLine(BPoint(bounds.left, indicatorY), BPoint(bounds.right, indicatorY)); SetPenSize(1.0); } Flush(); return curInsertionIndex; }
void TVolumenob::Update(){ rgb_color color = {128, 128, 128}; rgb_color color2= {100, 100, 100}; rgb_color color3= {150, 150, 150}; SetHighColor( color ); FillEllipse(nbcenter,r+1,r+1,B_SOLID_HIGH); SetHighColor( color2 ); FillArc(nbcenter,r+1,r+1,225,180,B_SOLID_HIGH); SetHighColor( color3 ); FillEllipse(nbcenter,r-3,r-3,B_SOLID_HIGH); SetPenSize(3); StrokeLine(nbcenter,nbpoint,B_SOLID_LOW); SetPenSize(1); }
// Draw void BoolValueView::Draw(BRect updateRect) { BRect b(Bounds()); // focus indication if (IsFocus()) { SetHighColor(ui_color(B_KEYBOARD_NAVIGATION_COLOR)); StrokeRect(b); b.InsetBy(1.0, 1.0); } // background FillRect(b, B_SOLID_LOW); // checkmark box rgb_color crossOutline = kBlack; rgb_color crossColor = ui_color(B_KEYBOARD_NAVIGATION_COLOR); if (!fEnabled) { crossOutline = tint_color(crossOutline, B_LIGHTEN_2_TINT); crossColor = tint_color(crossColor, B_LIGHTEN_2_TINT); } SetHighColor(crossOutline); b = fCheckBoxRect; StrokeRect(b); // checkmark if (fProperty && fProperty->Value()) { SetHighColor(crossColor); b.InsetBy(3.0, 3.0); SetPenSize(2.0); StrokeLine(b.LeftTop(), b.RightBottom()); StrokeLine(b.LeftBottom(), b.RightTop()); } }
void AppGroupView::_DrawCloseButton(const BRect& updateRect) { PushState(); BRect closeRect = fCloseRect; rgb_color base = ui_color(B_PANEL_BACKGROUND_COLOR); float tint = B_DARKEN_2_TINT; if (fCloseClicked) { BRect buttonRect(closeRect.InsetByCopy(-4, -4)); be_control_look->DrawButtonFrame(this, buttonRect, updateRect, base, base, BControlLook::B_ACTIVATED | BControlLook::B_BLEND_FRAME); be_control_look->DrawButtonBackground(this, buttonRect, updateRect, base, BControlLook::B_ACTIVATED); tint *= 1.2; closeRect.OffsetBy(1, 1); } base = tint_color(base, tint); SetHighColor(base); SetPenSize(2); StrokeLine(closeRect.LeftTop(), closeRect.RightBottom()); StrokeLine(closeRect.LeftBottom(), closeRect.RightTop()); PopState(); }
void SButton::DrawContent(BRect content_rect, bool pushed, bool window_activated) { SetPenSize(1); if(label) { if(IsEnabled()) { if((!pushed && Behavior() != S_TWO_STATE_BUTTON) || (Value() == 0 && Behavior() == S_TWO_STATE_BUTTON)) { SetDrawingMode(B_OP_COPY); if(button_style == DANO_STYLE) #ifdef B_BEOS_VERSION_DANO { SetHighColor(ui_color(B_CONTROL_TEXT_COLOR)); SetLowColor(ui_color(B_CONTROL_BACKGROUND_COLOR)); } #else { SetHighColor(0, 0, 0, 255); SetLowColor(245, 245, 245, 255); } #endif else { SetHighColor(0, 0, 0, 255); SetLowColor(232, 232, 232, 255); } } else { if(button_style == DANO_STYLE)
void TestPageView::DrawAfterChildren(BRect updateRect) { // Draw corners marks float width = Bounds().Width(); float height = Bounds().Height(); float minDimension = MIN(width, height); float size = minDimension * 0.05; SetPenSize(3.0); BPoint pt = Bounds().LeftTop(); StrokeLine(pt, BPoint(pt.x + size, pt.y)); StrokeLine(pt, BPoint(pt.x, pt.y + size)); pt = Bounds().RightTop(); StrokeLine(pt, BPoint(pt.x - size, pt.y)); StrokeLine(pt, BPoint(pt.x, pt.y + size)); pt = Bounds().RightBottom(); StrokeLine(pt, BPoint(pt.x - size, pt.y)); StrokeLine(pt, BPoint(pt.x, pt.y - size)); pt = Bounds().LeftBottom(); StrokeLine(pt, BPoint(pt.x + size, pt.y)); StrokeLine(pt, BPoint(pt.x, pt.y - size)); }
void AppGroupView::Draw(BRect updateRect) { rgb_color menuColor = ViewColor(); BRect bounds = Bounds(); rgb_color hilite = tint_color(menuColor, B_DARKEN_1_TINT); rgb_color vlight = tint_color(menuColor, B_LIGHTEN_2_TINT); bounds.bottom = bounds.top + kHeaderSize; // Draw the header background SetHighColor(tint_color(menuColor, 1.22)); SetLowColor(ui_color(B_PANEL_BACKGROUND_COLOR)); StrokeLine(bounds.LeftTop(), bounds.LeftBottom()); uint32 borders = BControlLook::B_TOP_BORDER | BControlLook::B_BOTTOM_BORDER | BControlLook::B_RIGHT_BORDER; be_control_look->DrawButtonBackground(this, bounds, bounds, menuColor, 0, borders); // Draw the buttons fCollapseRect.top = (kHeaderSize - kExpandSize) / 2; fCollapseRect.left = kEdgePadding * 2; fCollapseRect.right = fCollapseRect.left + 1.5 * kExpandSize; fCollapseRect.bottom = fCollapseRect.top + kExpandSize; fCloseRect = bounds; fCloseRect.top = (kHeaderSize - kExpandSize) / 2; fCloseRect.right -= kEdgePadding * 2; fCloseRect.left = fCloseRect.right - kCloseSize; fCloseRect.bottom = fCloseRect.top + kCloseSize; uint32 arrowDirection = fCollapsed ? BControlLook::B_DOWN_ARROW : BControlLook::B_UP_ARROW; be_control_look->DrawArrowShape(this, fCollapseRect, fCollapseRect, LowColor(), arrowDirection, 0, B_DARKEN_3_TINT); SetPenSize(kPenSize); // Draw the dismiss widget BRect closeCross = fCloseRect; closeCross.InsetBy(kSmallPadding, kSmallPadding); rgb_color detailCol = ui_color(B_CONTROL_BORDER_COLOR); detailCol = tint_color(detailCol, B_LIGHTEN_2_TINT); StrokeRoundRect(fCloseRect, kSmallPadding, kSmallPadding); StrokeLine(closeCross.LeftTop(), closeCross.RightBottom()); StrokeLine(closeCross.RightTop(), closeCross.LeftBottom()); // Draw the label SetHighColor(ui_color(B_PANEL_TEXT_COLOR)); BString label = fLabel; if (fCollapsed) label << " (" << fInfo.size() << ")"; SetFont(be_bold_font); DrawString(label.String(), BPoint(fCollapseRect.right + 2 * kEdgePadding, fCloseRect.bottom)); }
void AppGroupView::Draw(BRect updateRect) { rgb_color menuColor = ViewColor(); BRect bounds = Bounds(); rgb_color hilite = tint_color(menuColor, B_DARKEN_1_TINT); rgb_color vlight = tint_color(menuColor, B_LIGHTEN_2_TINT); bounds.bottom = bounds.top + kHeaderSize; // Draw the header background SetHighColor(tint_color(menuColor, 1.22)); SetLowColor(ui_color(B_PANEL_BACKGROUND_COLOR)); StrokeLine(bounds.LeftTop(), bounds.LeftBottom()); uint32 borders = BControlLook::B_TOP_BORDER | BControlLook::B_BOTTOM_BORDER | BControlLook::B_RIGHT_BORDER; be_control_look->DrawButtonBackground(this, bounds, bounds, menuColor, 0, borders); // Draw the buttons fCollapseRect.top = (kHeaderSize - kExpandSize) / 2; fCollapseRect.left = kEdgePadding * 3; fCollapseRect.right = fCollapseRect.left + 1.5 * kExpandSize; fCollapseRect.bottom = fCollapseRect.top + kExpandSize; fCloseRect = bounds; fCloseRect.top = (kHeaderSize - kCloseSize) / 2; // Take off the 1 to line this up with the close button on the // notification view fCloseRect.right -= kEdgePadding * 3 - 1; fCloseRect.left = fCloseRect.right - kCloseSize; fCloseRect.bottom = fCloseRect.top + kCloseSize; uint32 arrowDirection = fCollapsed ? BControlLook::B_DOWN_ARROW : BControlLook::B_UP_ARROW; be_control_look->DrawArrowShape(this, fCollapseRect, fCollapseRect, LowColor(), arrowDirection, 0, B_DARKEN_3_TINT); SetPenSize(kPenSize); // Draw the dismiss widget _DrawCloseButton(updateRect); // Draw the label SetHighColor(ui_color(B_PANEL_TEXT_COLOR)); BString label = fLabel; if (fCollapsed) label << " (" << fInfo.size() << ")"; SetFont(be_bold_font); font_height fontHeight; GetFontHeight(&fontHeight); float y = (bounds.top + bounds.bottom - ceilf(fontHeight.ascent) - ceilf(fontHeight.descent)) / 2.0 + ceilf(fontHeight.ascent); DrawString(label.String(), BPoint(fCollapseRect.right + 4 * kEdgePadding, y)); }
ImageView::ImageView(BRect rect, const char *name) : BView(rect, name, B_FOLLOW_ALL, B_WILL_DRAW | B_FRAME_EVENTS) { fpbitmap = NULL; fdocumentIndex = 1; fdocumentCount = 1; SetViewColor(192, 192, 192); SetHighColor(0, 0, 0); SetPenSize(PEN_SIZE); }
void ETextEditable::DrawSelectedBackground(ERect updateRect) { if(fCount <= 0 || !IsEnabled()) return; if(fSelectStart < 0 || fSelectEnd < 0 || fSelectEnd < fSelectStart || fSelectEnd >= fCount || fCharWidths == NULL) return; ERect rect = Frame().OffsetToSelf(E_ORIGIN); rect.left += fMargins.left; rect.top += fMargins.top; rect.right -= fMargins.right; rect.bottom -= fMargins.bottom; if(!rect.IsValid()) return; EFont font; e_font_height fontHeight; GetFont(&font); font.GetHeight(&fontHeight); float sHeight = fontHeight.ascent + fontHeight.descent; ERect hlRect; if(!GetCharLocation(0, &(hlRect.left), NULL, &font)) return; hlRect.top = rect.Center().y - sHeight / 2.f - 1; hlRect.bottom = rect.Center().y + sHeight / 2.f + 1; for(eint32 i = 0; i < fSelectStart; i++) { hlRect.left += (float)ceil((double)fCharWidths[i]); hlRect.left += (float)ceil((double)(font.Spacing() * font.Size())); } hlRect.right = hlRect.left; for(eint32 i = fSelectStart; i <= fSelectEnd; i++) { hlRect.right += (float)ceil((double)fCharWidths[i]); if(i != fSelectEnd) hlRect.right += (float)ceil((double)(font.Spacing() * font.Size())); } hlRect &= updateRect; if(!hlRect.IsValid()) return; e_rgb_color hlColor = e_ui_color(E_DOCUMENT_HIGHLIGHT_COLOR); PushState(); SetDrawingMode(E_OP_COPY); SetPenSize(0); SetHighColor(hlColor); FillRect(hlRect, E_SOLID_HIGH); PopState(); }
void ETextEditable::DrawCursor() { if(!IsEnabled() || !IsEditable() || fPosition < 0 || fPosition > fCount || (fCount > 0 && fCharWidths == NULL)) return; if(Window() == NULL || Window()->IsActivate() == false) return; if(!(IsFocus() || IsFocusChanging())) return; ERect rect = Frame().OffsetToSelf(E_ORIGIN); rect.left += fMargins.left; rect.top += fMargins.top; rect.right -= fMargins.right; rect.bottom -= fMargins.bottom; if(!rect.IsValid()) return; EFont font; e_font_height fontHeight; GetFont(&font); font.GetHeight(&fontHeight); float sHeight = fontHeight.ascent + fontHeight.descent; EPoint pt1; if(!GetCharLocation(fPosition, &(pt1.x), NULL, &font)) return; pt1.x -= 1; pt1.y = rect.Center().y - sHeight / 2.f; EPoint pt2 = pt1; pt2.y += sHeight; e_rgb_color crColor = e_ui_color(E_DOCUMENT_CURSOR_COLOR); if(IsFocusChanging() && !IsFocus()) { if(fPosition > fSelectStart && fPosition <= fSelectEnd && fSelectEnd > fSelectStart) { crColor = e_ui_color(E_DOCUMENT_HIGHLIGHT_COLOR); } else { crColor = e_ui_color(E_DOCUMENT_BACKGROUND_COLOR); } } PushState(); SetDrawingMode(E_OP_COPY); SetPenSize(0); SetHighColor(crColor); StrokeLine(pt1, pt2, E_SOLID_HIGH); PopState(); }
void TranslatorListView::MouseMoved(BPoint point, uint32 transit, const BMessage *dragMessage) { if (dragMessage != NULL && transit == B_ENTERED_VIEW) { // Draw a red box around the inside of the view // to tell the user that this view accepts drops SetHighColor(220,0,0); SetPenSize(4); StrokeRect(Bounds()); SetHighColor(0,0,0); } else if (dragMessage != NULL && transit == B_EXITED_VIEW) Invalidate(); }
void TestView::Draw(BRect updateRect) { printf("Draw(BRect(%.1f, %.1f, %.1f, %.1f))\n", updateRect.left, updateRect.top, updateRect.right, updateRect.bottom); printf("pensize: %.2f\n", PenSize()); SetHighColor(0, 0, 255); StrokeLine(Bounds().LeftBottom(), Bounds().RightTop()); SetPenSize(5); }
void CharView::Draw(BRect urect) { BPoint point; font_height fheight; char utf8Char[3]; uint16 uniChar[1]; urect = Bounds(); // SetLowColor(def_viewcolor); SetDrawingMode(B_OP_COPY); SetHighColor(strokeColor); SetPenSize(1); StrokeRect(urect); urect.InsetBy(1, 1); SetHighColor(bgColor); FillRect(urect); SetLowColor(bgColor); SetHighColor(displayColor); if (drawmode) { font.SetSize(urect.Width() * 0.6); font.GetHeight(&fheight); // Unicode to UTF8 Character encoding uniChar[0] = B_HOST_TO_BENDIAN_INT16(((mutf == 0) || (mutf == 65535)) ? 1 : mutf); int32 state = 0; int32 srcLen = 2; int32 destLen = sizeof(utf8Char); convert_to_utf8(B_UNICODE_CONVERSION, (const char*)uniChar, &srcLen, utf8Char, &destLen, &state); SetFont(&font); bool hasGlyph[1]; font.GetHasGlyphs(utf8Char, 1, hasGlyph); if (hasGlyph[0]) { float choffset = (urect.right - urect.left - StringWidth(utf8Char, destLen)) / 2; float cvoffset = (urect.Height() - fheight.ascent - fheight.descent) / 2 + fheight.ascent; point.Set(choffset, cvoffset); DrawString(utf8Char, destLen, point); } } /* printf("\nCharView!\n"); printf("utf8Char[0]: %x\n", utf8Char[0]); printf("utf8Char[1]: %x\n", utf8Char[1]); printf("utf8Char[2]: %x\n", utf8Char[2]);*/ }
void TestView::DrawAfterChildren(BRect updateRect) { printf("DrawAfterChildren(BRect(%.1f, %.1f, %.1f, %.1f))\n", updateRect.left, updateRect.top, updateRect.right, updateRect.bottom); printf("pensize: %.2f\n", PenSize()); SetHighColor(255, 0, 0); StrokeLine(Bounds().LeftTop(), Bounds().RightBottom()); Sync(); SetPenSize(7); }
// 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 PathView::Draw(BRect updateRect) { if (fMode == kDrawOutline) { } else if (fMode == kStroke) { const int n = fPath.CountPoints(); BShape shape; for (int i = 0; i < n; i++) { if (i == 0) shape.MoveTo(fPath.PointAt(i)); else shape.LineTo(fPath.PointAt(i)); } if (fPath.IsClosed()) shape.Close(); SetPenSize(fWidth); StrokeShape(&shape); ShapeLPB path(&fPath, fWidth, LineCapMode(), LineJoinMode(), LineMiterLimit()); path.CreateLinePath(); SetPenSize(1); BPicture picture; BeginPicture(&picture); FillShape(path.Shape()); EndPicture(); PushState(); ClipToPicture(&picture); SetHighColor(0, 255, 0); FillRect(Bounds()); PopState(); SetOrigin(200, 0); SetHighColor(255, 0, 0); StrokeShape(path.Shape()); Flush(); } }
// SetDrawData void Painter::SetDrawData(const DrawData* data) { // for now... SetHighColor(data->highcolor.GetColor32()); SetLowColor(data->lowcolor.GetColor32()); SetScale(data->scale); SetPenSize(data->pensize); // fOrigin = data->coordOrigin; SetDrawingMode(data->draw_mode); SetBlendingMode(data->alphaSrcMode, data->alphaFncMode); SetPenLocation(data->penlocation); SetFont(data->font); // if (data->clipReg) { // ConstrainClipping(*data->clipReg); // } fPatternHandler->SetPattern(data->patt); }
void RemoteDrawingEngine::SetDrawState(const DrawState* state, int32 xOffset, int32 yOffset) { SetPenSize(state->PenSize()); SetDrawingMode(state->GetDrawingMode()); SetBlendingMode(state->AlphaSrcMode(), state->AlphaFncMode()); SetPattern(state->GetPattern().GetPattern()); SetStrokeMode(state->LineCapMode(), state->LineJoinMode(), state->MiterLimit()); SetHighColor(state->HighColor()); SetLowColor(state->LowColor()); SetFont(state->Font()); RemoteMessage message(NULL, fHWInterface->SendBuffer()); message.Start(RP_SET_OFFSETS); message.Add(fToken); message.Add(xOffset); message.Add(yOffset); }
void LeafView::Draw(BRect updateRect) { float scale = Bounds().Width() / kLeafWidth; BAffineTransform transform; transform.ScaleBy(scale); // BGradientRadial gradient(BPoint(kLeafWidth * 0.75, kLeafHeight * 1.5), // kLeafWidth * 2); BGradientLinear gradient(B_ORIGIN, transform.Apply(BPoint(kLeafWidth, kLeafHeight))); rgb_color lightBlue = make_color(6, 169, 255); rgb_color darkBlue = make_color(0, 50, 126); gradient.AddColor(darkBlue, 0.0); gradient.AddColor(lightBlue, 255.0); // build leaf shape BShape leafShape; leafShape.MoveTo(transform.Apply(kLeafBegin)); for (int i = 0; i < kNumLeafCurves; ++i) { BPoint controlPoints[3]; for (int j = 0; j < 3; ++j) controlPoints[j] = transform.Apply(kLeafCurves[i][j]); leafShape.BezierTo(controlPoints); } leafShape.Close(); PushState(); SetDrawingMode(B_OP_ALPHA); SetHighColor(0, 0, 0, 50); for (int i = 2; i >= 0; --i) { SetOrigin(i * 0.1, i * 0.3); SetPenSize(i * 2); StrokeShape(&leafShape); } PopState(); FillShape(&leafShape, gradient); }
void MouseView::Draw(BRect updateFrame) { SetDrawingMode(B_OP_ALPHA); SetBlendingMode(B_PIXEL_ALPHA, B_ALPHA_OVERLAY); SetScale(fScaling * 1.8); BShape mouseShape; mouseShape.MoveTo(BPoint(16, 12)); // left BPoint control[3] = { BPoint(12, 16), BPoint(8, 64), BPoint(32, 64) }; mouseShape.BezierTo(control); // right BPoint control2[3] = { BPoint(56, 64), BPoint(52, 16), BPoint(48, 12) }; mouseShape.BezierTo(control2); // top BPoint control3[3] = { BPoint(44, 8), BPoint(20, 8), BPoint(16, 12) }; mouseShape.BezierTo(control3); mouseShape.Close(); // Draw the shadow SetOrigin(-17 * fScaling, -11 * fScaling); SetHighColor(kMouseShadowColor); FillShape(&mouseShape, B_SOLID_HIGH); // Draw the body SetOrigin(-21 * fScaling, -14 * fScaling); BGradientRadial bodyGradient(28, 24, 128); bodyGradient.AddColor(kMouseBodyTopColor, 0); bodyGradient.AddColor(kMouseBodyBottomColor, 255); FillShape(&mouseShape, bodyGradient); // Draw the outline SetPenSize(1 / 1.8 / fScaling); SetDrawingMode(B_OP_OVER); SetHighColor(kMouseOutlineColor); StrokeShape(&mouseShape, B_SOLID_HIGH); // bottom button border BShape buttonsOutline; buttonsOutline.MoveTo(BPoint(13, 27)); BPoint control4[] = { BPoint(18, 30), BPoint(46, 30), BPoint(51, 27) }; buttonsOutline.BezierTo(control4); SetHighColor(kMouseButtonOutlineColor); StrokeShape(&buttonsOutline, B_SOLID_HIGH); SetScale(1); SetOrigin(0, 0); // Separator between the buttons const int32* offset = getButtonOffsets(fType); for (int32 i = 1; i < fType; i++) { BRect buttonRect = _ButtonRect(offset, i); StrokeLine(buttonRect.LeftTop(), buttonRect.LeftBottom()); } mouse_map map; fSettings.Mapping(map); SetDrawingMode(B_OP_OVER); if (fButtons != 0) ClipToPicture(&fButtonsPicture, B_ORIGIN, false); for (int32 i = 0; i < fType; i++) { // draw mapping number centered over the button bool pressed = (fButtons & map.button[_ConvertFromVisualOrder(i)]) != 0; // is button currently pressed? if (pressed) { SetDrawingMode(B_OP_ALPHA); SetHighColor(kButtonPressedColor); FillRect(_ButtonRect(offset, i)); } BRect border(fScaling * (offset[i] + 1), fScaling * (kButtonTop + 5), fScaling * offset[i + 1] - 1, fScaling * (kButtonTop + kMouseDownHeight - 4)); if (i == 0) border.left += fScaling * 5; if (i == fType - 1) border.right -= fScaling * 4; char number[2] = {0}; number[0] = getMappingNumber(map.button[_ConvertFromVisualOrder(i)]) + '1'; SetDrawingMode(B_OP_OVER); SetHighColor(kButtonTextColor); DrawString(number, BPoint( border.left + (border.Width() - StringWidth(number)) / 2, border.top + fDigitBaseline + (border.IntegerHeight() - fDigitHeight) / 2)); } if (fButtons != 0) ClipToPicture(NULL); }
// Draw void TestView::Draw(BRect updateRect) { if (fCopyBitsJustCalled) { printf("TestView::Draw(%.1f, %.1f, %.1f, %.1f) after CopyBits()\n", updateRect.left, updateRect.top, updateRect.right, updateRect.bottom); fCopyBitsJustCalled = false; } // background // SetHighColor(ui_color(B_PANEL_BACKGROUND_COLOR)); // FillRect(updateRect); BRect r(Bounds()); // draw some pattern with lines float width = r.Width(); float height = r.Height(); int32 lineCount = 20; SetPenSize(2.0); for (int32 i = 0; i < lineCount; i++) { SetHighColor(255, (255 / lineCount) * i, 255 - (255 / lineCount) * i); StrokeLine(BPoint(r.left + (width / lineCount) * i, r.top), BPoint(r.left, r.top + (height / lineCount) * i)); StrokeLine(BPoint(r.right - (width / lineCount) * i, r.bottom), BPoint(r.right, r.bottom - (height / lineCount) * i)); } StrokeLine(BPoint(r.left, r.bottom), BPoint(r.right, r.top)); // source and dest rect SetPenSize(1.0); SetHighColor(0, 255, 0, 255); StrokeRect(fSourceRect); SetHighColor(0, 0, 255, 255); StrokeRect(fDestRect); // text SetHighColor(128, 0, 50, 255); const char* message = "Left-Click and drag"; width = StringWidth(message); BPoint p(r.left + r.Width() / 2.0 - width / 2.0, r.top + r.Height() / 2.0 - 50.0); DrawString(message, p); message = "to set source rect!"; width = StringWidth(message); p.x = r.left + r.Width() / 2.0 - width / 2.0; p.y += 20; DrawString(message, p); message = "Right-Click and drag"; width = StringWidth(message); p.x = r.left + r.Width() / 2.0 - width / 2.0; p.y += 30.0; DrawString(message, p); message = "to set destination rect!"; width = StringWidth(message); p.x = r.left + r.Width() / 2.0 - width / 2.0; p.y += 20; DrawString(message, p); }
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; }
void BasicPreviewView::Draw(BRect updateRect) { BRect bounds = Bounds(); if (fEngine == nullptr) { BView::Draw(updateRect); return; } SetHighColor(0, 0, 0, 255); BPoint where(0, 0); if (fColumnWidth > 0 && fColumnWidth < bounds.Width()) { fRows = ceil(static_cast<float>(_Pages()) / fColumns); _SetColumns((Bounds().Width() - 2*fHMargin + fHSpace) / (fColumnWidth + fHSpace)); fPageHeight = _PageHeight(); int lowerbound = fCurrentPageNumber; int upperbound = 2 + (bounds.Height() -fVSpace) / (fPageHeight + fVSpace); upperbound *= fColumns; upperbound += fCurrentPageNumber; if (upperbound > _Pages()) upperbound = _Pages(); BRect rect; int i = lowerbound; where.y = fVMargin + fCurrentRow * (fPageHeight + fVSpace); for ( ; i < upperbound;) { where.x = fHMargin; for (int j = 0; j < fColumns && i < upperbound; ++j, ++i) { rect.left = 0; rect.top = 0; rect.right = fColumnWidth; rect.bottom = fPageHeight = _PageHeight(i); rect.OffsetBySelf(where); if (rect.Intersects(updateRect)) { DrawBitmapAsync(_Page(i), rect); if (i == fHighlightPageNumber) { SetHighColor(0, 0, 255, 255); SetPenSize(2); StrokeRect(rect); SetHighColor(0, 0, 0, 255); SetPenSize(1); } else { StrokeRect(rect); } } where.x += fColumnWidth + fHSpace; } where.y += rect.Height() + fVSpace; } fZoom = fColumnWidth / fEngine->Page(upperbound - 1)->Bounds().Width(); } else { where.x = fHMargin; fRows = fEngine->PageCount(); fPageHeight = _PageHeight(); float width = bounds.Width() - 2*fHMargin; int upperbound = bounds.Height() / fPageHeight; upperbound = upperbound + fCurrentPageNumber + 2; if (upperbound > fEngine->PageCount()) upperbound = fEngine->PageCount(); where.y = fVMargin + fCurrentRow * (fPageHeight + fVSpace); bool hasDrawn = false; for (int i = fCurrentPageNumber; i < upperbound; ++i) { fPageHeight = _PageHeight(i); BRect rect(0, 0, width, fPageHeight); rect.OffsetBySelf(where); if (rect.Intersects(updateRect)){ hasDrawn = true; DrawBitmapAsync(_Page(i), rect); if (i == fHighlightPageNumber) { SetHighColor(0, 0, 255, 255); SetPenSize(2); } else { SetHighColor(0, 0, 0, 255); SetPenSize(1); } StrokeRect(rect); } else if (hasDrawn) { break; } where.y += (fPageHeight + fVSpace); } fZoom = width / (fZoom * fEngine->Page(upperbound - 1)->Bounds().Width()); } }
void ETextEditable::Draw(ERect updateRect) { if(!IsVisible()) return; ERect rect = Frame().OffsetToSelf(E_ORIGIN); rect.left += fMargins.left; rect.top += fMargins.top; rect.right -= fMargins.right; rect.bottom -= fMargins.bottom; if(!rect.IsValid()) return; ERegion clipping; GetClippingRegion(&clipping); if(clipping.CountRects() > 0) clipping &= (rect & updateRect); else clipping = (rect & updateRect); if(clipping.CountRects() <= 0) return; e_rgb_color bkColor = e_ui_color(E_DOCUMENT_BACKGROUND_COLOR); e_rgb_color fgColor = e_ui_color(E_DOCUMENT_TEXT_COLOR); if(!IsEnabled()) { bkColor.disable(ViewColor()); fgColor.disable(ViewColor()); } if(!IsFocusChanging()) { PushState(); ConstrainClippingRegion(&clipping); SetDrawingMode(E_OP_COPY); SetPenSize(0); SetHighColor(bkColor); FillRect(rect & updateRect, E_SOLID_HIGH); PopState(); } EFont font; e_font_height fontHeight; GetFont(&font); font.GetHeight(&fontHeight); if(fCount > 0 && !IsFocusChanging()) { PushState(); ConstrainClippingRegion(&clipping); float x = 0, y = 0; if(GetCharLocation(0, &x, &y, &font)) { SetDrawingMode(E_OP_COPY); SetPenSize(0); SetHighColor(fgColor); SetLowColor(bkColor); _DrawString(fText, EPoint(x, y)); if(IsEnabled() && IsSelected()) { char *selectedText = DuplicateText(fSelectStart, fSelectEnd); if(selectedText != NULL) { x = 0; y = 0; if(GetCharLocation(fSelectStart, &x, &y, &font)) { DrawSelectedBackground(updateRect); SetLowColor(e_ui_color(E_DOCUMENT_HIGHLIGHT_COLOR)); _DrawString(selectedText, EPoint(x, y)); } free(selectedText); } } } PopState(); } if(IsEnabled() && IsEditable() && (IsFocus() || IsFocusChanging())) { PushState(); ConstrainClippingRegion(&clipping); DrawCursor(); PopState(); } if((IsFocus() || IsFocusChanging()) && Window()->IsActivate() && IsEnabled() && (Flags() & E_NAVIGABLE)) { e_rgb_color color = e_ui_color(E_NAVIGATION_BASE_COLOR); if(IsFocusChanging() && !IsFocus()) color = e_ui_color(E_DOCUMENT_BACKGROUND_COLOR); PushState(); ConstrainClippingRegion(&clipping); SetDrawingMode(E_OP_COPY); SetPenSize(0); SetHighColor(color); StrokeRect(rect, E_SOLID_HIGH); PopState(); } }