status_t
CanvasMessage::ReadFontState(BFont& font)
{
	uint8 encoding, spacing;
	uint16 face;
	uint32 flags, familyAndStyle;
	font_direction direction;
	float falseBoldWidth, rotation, shear, size;

	Read(direction);
	Read(encoding);
	Read(flags);
	Read(spacing);
	Read(shear);
	Read(rotation);
	Read(falseBoldWidth);
	Read(size);
	Read(face);
	status_t result = Read(familyAndStyle);
	if (result != B_OK)
		return result;

	font.SetFamilyAndStyle(familyAndStyle);
	font.SetEncoding(encoding);
	font.SetFlags(flags);
	font.SetSpacing(spacing);
	font.SetShear(shear);
	font.SetRotation(rotation);
	font.SetFalseBoldWidth(falseBoldWidth);
	font.SetSize(size);
	font.SetFace(face);
	return B_OK;
}
Beispiel #2
0
void
BTextWidget::Draw(BRect eraseRect, BRect textRect, float, BPoseView *view,
	BView *drawView, bool selected, uint32 clipboardMode, BPoint offset, bool direct)
{
	textRect.OffsetBy(offset);

	if (direct) {
#ifdef __HAIKU__
		// draw selection box if selected
		if (selected) {
#else
		// erase area we're going to draw in
		// NOTE: WidgetTextOutline() is reused for
		// erasing background on R5 here
		if (view->WidgetTextOutline() || selected) {
#endif
			drawView->SetDrawingMode(B_OP_COPY);
			eraseRect.OffsetBy(offset);
//			drawView->FillRect(eraseRect, B_SOLID_LOW);
			drawView->FillRect(textRect, B_SOLID_LOW);
		} else
			drawView->SetDrawingMode(B_OP_OVER);

		// set high color
		rgb_color highColor;
		if (view->IsDesktopWindow()) {
			if (selected)
				highColor = kWhite;
			else
				highColor = view->DeskTextColor();
		} else if (selected && view->Window()->IsActive()) {
			highColor = kWhite;
		} else
			highColor = kBlack;

		if (clipboardMode == kMoveSelectionTo && !selected) {
			drawView->SetDrawingMode(B_OP_ALPHA);
			drawView->SetBlendingMode(B_PIXEL_ALPHA, B_ALPHA_OVERLAY);
			highColor.alpha = 64;
		}
		drawView->SetHighColor(highColor);
	}

	BPoint loc;
	loc.y = textRect.bottom - view->FontInfo().descent;
	loc.x = textRect.left + 1;

	const char* fittingText = fText->FittingText(view);

#ifdef __HAIKU__
	// TODO: Comparing view and drawView here to avoid rendering
	// the text outline when producing a drag bitmap. The check is
	// not fully correct, since an offscreen view is also used in some
	// other rare cases (something to do with columns). But for now, this
	// fixes the broken drag bitmaps when dragging icons from the Desktop.
	if (!selected && view == drawView && view->WidgetTextOutline()) {
		// draw a halo around the text by using the "false bold"
		// feature for text rendering. Either black or white is used for
		// the glow (whatever acts as contrast) with a some alpha value,
		drawView->SetDrawingMode(B_OP_ALPHA);
		drawView->SetBlendingMode(B_CONSTANT_ALPHA, B_ALPHA_OVERLAY);

		BFont font;
		drawView->GetFont(&font);

		rgb_color textColor = drawView->HighColor();
		if (textColor.red + textColor.green + textColor.blue < 128 * 3) {
			// dark text on light outline
			rgb_color glowColor = kWhite;

			font.SetFalseBoldWidth(2.0);
			drawView->SetFont(&font, B_FONT_FALSE_BOLD_WIDTH);
			glowColor.alpha = 30;
			drawView->SetHighColor(glowColor);

			drawView->DrawString(fittingText, loc);

			font.SetFalseBoldWidth(1.0);
			drawView->SetFont(&font, B_FONT_FALSE_BOLD_WIDTH);
			glowColor.alpha = 65;
			drawView->SetHighColor(glowColor);

			drawView->DrawString(fittingText, loc);

			font.SetFalseBoldWidth(0.0);
			drawView->SetFont(&font, B_FONT_FALSE_BOLD_WIDTH);
		} else {
			// light text on dark outline
			rgb_color outlineColor = kBlack;

			font.SetFalseBoldWidth(1.0);
			drawView->SetFont(&font, B_FONT_FALSE_BOLD_WIDTH);
			outlineColor.alpha = 30;
			drawView->SetHighColor(outlineColor);

			drawView->DrawString(fittingText, loc);

			font.SetFalseBoldWidth(0.0);
			drawView->SetFont(&font, B_FONT_FALSE_BOLD_WIDTH);

			outlineColor.alpha = 200;
			drawView->SetHighColor(outlineColor);

			drawView->DrawString(fittingText, loc + BPoint(1, 1));
		}

		drawView->SetDrawingMode(B_OP_OVER);
		drawView->SetHighColor(textColor);
	}
#endif // __HAIKU__

	drawView->DrawString(fittingText, loc);

	if (fSymLink && (fAttrHash == view->FirstColumn()->AttrHash())) {
		// ToDo:
		// this should be exported to the WidgetAttribute class, probably
		// by having a per widget kind style
		if (direct) {
			rgb_color underlineColor = drawView->HighColor();
			underlineColor.alpha = 180;
			drawView->SetHighColor(underlineColor);
			drawView->SetDrawingMode(B_OP_ALPHA);
			drawView->SetBlendingMode(B_CONSTANT_ALPHA, B_ALPHA_OVERLAY);
		}

		textRect.right = textRect.left + fText->Width(view);
			// only underline text part
		drawView->StrokeLine(textRect.LeftBottom(), textRect.RightBottom(),
			B_MIXED_COLORS);
	}
}
Beispiel #3
0
void
ActivityView::Draw(BRect updateRect)
{
	bool drawBackground = true;
	if (Parent() && (Parent()->Flags() & B_DRAW_ON_CHILDREN) != 0)
		drawBackground = false;

	_DrawHistory(drawBackground);

	if (!fShowLegend)
		return;

	// draw legend
	BRect legendFrame = _LegendFrame();
	SetLowColor(fLegendBackgroundColor);
	if (drawBackground) {
		BRect backgroundFrame(legendFrame);
		backgroundFrame.bottom += kDraggerSize;
		FillRect(backgroundFrame, B_SOLID_LOW);
	}

	BAutolock _(fSourcesLock);

	font_height fontHeight;
	GetFontHeight(&fontHeight);

	for (int32 i = 0; i < fSources.CountItems(); i++) {
		DataSource* source = fSources.ItemAt(i);
		DataHistory* values = fValues.ItemAt(i);
		BRect frame = _LegendFrameAt(legendFrame, i);

		// draw color box
		BRect colorBox = _LegendColorFrameAt(legendFrame, i);
		BRect rect = colorBox;
		uint32 flags = BControlLook::B_BLEND_FRAME;
		be_control_look->DrawTextControlBorder(this, rect,
			rect, fLegendBackgroundColor, flags);
		SetHighColor(source->Color());
		FillRect(rect);

		// show current value and label
		float y = frame.top + ceilf(fontHeight.ascent);
		int64 value = values->ValueAt(values->End());
		BString text;
		source->Print(text, value);
		float width = StringWidth(text.String());

		BString label = source->Label();
		float possibleLabelWidth = frame.right - colorBox.right - 12 - width;
		// TODO: TruncateString() is broken... remove + 5 when fixed!
		if (ceilf(StringWidth(label.String()) + 5) > possibleLabelWidth)
			label = source->ShortLabel();
		TruncateString(&label, B_TRUNCATE_MIDDLE, possibleLabelWidth);

		if (drawBackground)
			SetHighColor(ui_color(B_CONTROL_TEXT_COLOR));
		else {
			rgb_color c = Parent()->ViewColor();
			rgb_color textColor = c.red + c.green * 1.5f + c.blue * 0.50f
				>= 300 ? kBlack : kWhite;

			int32 mask;
			bool tmpOutline = false;
			bool outline = fCachedOutline;
			int8 indice = 0;

			if (fCachedWorkspace != current_workspace()) {
				while (fBackgroundInfo.FindInt32("be:bgndimginfoworkspaces",
						indice, &mask) == B_OK
					&& fBackgroundInfo.FindBool("be:bgndimginfoerasetext",
						indice, &tmpOutline) == B_OK) {
					if (((1 << current_workspace()) & mask) != 0) {
						outline = tmpOutline;
						fCachedWorkspace = current_workspace();
						fCachedOutline = outline;
						break;
					}
					indice++;
				}
			}

			if (outline) {
				SetDrawingMode(B_OP_ALPHA);
				SetBlendingMode(B_CONSTANT_ALPHA, B_ALPHA_OVERLAY);

				BFont font;
				GetFont(&font);
				if (textColor == kBlack) {
					// Black text with white halo/glow
					rgb_color glowColor = kWhite;

					font.SetFalseBoldWidth(2.0);
					SetFont(&font, B_FONT_FALSE_BOLD_WIDTH);

					glowColor.alpha = 30;
					SetHighColor(glowColor);
					DrawString(label.String(), BPoint(6 + colorBox.right, y));
					DrawString(text.String(), BPoint(frame.right - width, y));

					font.SetFalseBoldWidth(1.0);
					SetFont(&font, B_FONT_FALSE_BOLD_WIDTH);

					glowColor.alpha = 65;
					SetHighColor(glowColor);
					DrawString(label.String(), BPoint(6 + colorBox.right, y));
					DrawString(text.String(), BPoint(frame.right - width, y));

					font.SetFalseBoldWidth(0.0);
					SetFont(&font, B_FONT_FALSE_BOLD_WIDTH);
				} else {
					// white text with black outline
					rgb_color outlineColor = kBlack;

					font.SetFalseBoldWidth(1.0);
					SetFont(&font, B_FONT_FALSE_BOLD_WIDTH);

					outlineColor.alpha = 30;
					SetHighColor(outlineColor);
					DrawString(label.String(), BPoint(6 + colorBox.right, y));
					DrawString(text.String(), BPoint(frame.right - width, y));

					font.SetFalseBoldWidth(0.0);
					SetFont(&font, B_FONT_FALSE_BOLD_WIDTH);

					outlineColor.alpha = 200;
					SetHighColor(outlineColor);
					DrawString(label.String(), BPoint(6 + colorBox.right + 1,
						y + 1));
					DrawString(text.String(), BPoint(frame.right - width + 1,
						y + 1));
				}
			}
			SetDrawingMode(B_OP_OVER);
			SetHighColor(textColor);
		}
		DrawString(label.String(), BPoint(6 + colorBox.right, y));
		DrawString(text.String(), BPoint(frame.right - width, y));
	}
}