Exemple #1
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;
}
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));
	}
}
Exemple #3
0
void
BRadioButton::Draw(BRect updateRect)
{
	if (Window() == NULL) return;

	BFont font;
	GetFont(&font);
	font_height fontHeight;
	font.GetHeight(&fontHeight);
	float sHeight = fontHeight.ascent + fontHeight.descent;

	BRect rect = Frame().OffsetToSelf(B_ORIGIN);
	rect.InsetBy(5, (rect.Height() - sHeight) / 2);
	if (rect.IsValid() == false) return;

	if ((IsFocus() || IsFocusChanging()) && IsEnabled() && Label() != NULL) {
		BPoint penLocation;
		penLocation.Set(rect.left + rect.Height() + 5, rect.Center().y + sHeight / 2 + 1);

		SetHighColor((IsFocus() && Window()->IsActivate()) ? ui_color(B_NAVIGATION_BASE_COLOR) : ViewColor());
		StrokeLine(penLocation, penLocation + BPoint(font.StringWidth(Label()), 0));
	}

	if (IsFocusChanging()) return;

	rgb_color shineColor = ui_color(B_SHINE_COLOR);
	rgb_color shadowColor = ui_color(B_SHADOW_COLOR);

	if (!IsEnabled()) {
		shineColor.disable(ViewColor());
		shadowColor.disable(ViewColor());
	}

	rect.right = rect.left + rect.Height();
	SetHighColor(shineColor.mix_copy(0, 0, 0, 5));
	FillEllipse(rect);
	SetHighColor(shineColor);
	StrokeArc(rect, 225, 180);
	SetHighColor(shadowColor);
	StrokeArc(rect, 45, 180);

	if (Value() == B_CONTROL_ON) {
		SetHighColor(shadowColor.mix_copy(255, 255, 255, 50));
		BRect r = rect.InsetByCopy(3, 3);
		FillEllipse(r);
	}

	if (Label() != NULL) {
		BPoint penLocation;
		penLocation.x = rect.right + 5;
		penLocation.y = rect.Center().y - sHeight / 2.f;
		penLocation.y += fontHeight.ascent + 1;

		SetHighColor(IsEnabled() ? ui_color(B_PANEL_TEXT_COLOR) : ui_color(B_SHINE_COLOR).disable(ViewColor()));
		SetLowColor(ViewColor());

		DrawString(Label(), penLocation);
		if (!IsEnabled()) {
			SetHighColor(ui_color(B_SHADOW_COLOR).disable(ViewColor()));
			DrawString(Label(), penLocation - BPoint(1, 1));
		}
	}
}