Esempio n. 1
0
float
TeamsColumn::GetPreferredWidth(BField *_field, BView* parent) const
{
	BBitmapStringField* bitmapField
		= dynamic_cast<BBitmapStringField*>(_field);
	BStringField* stringField = dynamic_cast<BStringField*>(_field);

	float parentWidth = Inherited::GetPreferredWidth(_field, parent);
	float width = 0.0;

	if (bitmapField) {
		const BBitmap* bitmap = bitmapField->Bitmap();
		BFont font;
		parent->GetFont(&font);
		width = font.StringWidth(bitmapField->String()) + 3 * sTextMargin;
		if (bitmap)
			width += bitmap->Bounds().Width();
		else
			width += 16;
	} else if (stringField) {
		BFont font;
		parent->GetFont(&font);
		width = font.StringWidth(stringField->String()) + 2 * sTextMargin;
	}
	return max_c(width, parentWidth);
}
const char*
PartitionListRow::DevicePath()
{
	BBitmapStringField* stringField
		= dynamic_cast<BBitmapStringField*>(GetField(kDeviceColumn));

	if (stringField == NULL)
		return NULL;

	return stringField->String();
}
Esempio n. 3
0
void
TeamsColumn::DrawField(BField* field, BRect rect, BView* parent)
{
	BBitmapStringField* bitmapField
		= dynamic_cast<BBitmapStringField*>(field);
	BStringField* stringField = dynamic_cast<BStringField*>(field);

	if (bitmapField) {
		const BBitmap* bitmap = bitmapField->Bitmap();

		// figure out the placement
		float x = 0.0;
		BRect r = bitmap ? bitmap->Bounds() : BRect(0, 0, 15, 15);
		float y = rect.top + ((rect.Height() - r.Height()) / 2);
		float width = 0.0;

		switch (Alignment()) {
			default:
			case B_ALIGN_LEFT:
			case B_ALIGN_CENTER:
				x = rect.left + sTextMargin;
				width = rect.right - (x + r.Width()) - (2 * sTextMargin);
				r.Set(x + r.Width(), rect.top, rect.right - width, rect.bottom);
				break;

			case B_ALIGN_RIGHT:
				x = rect.right - sTextMargin - r.Width();
				width = (x - rect.left - (2 * sTextMargin));
				r.Set(rect.left, rect.top, rect.left + width, rect.bottom);
				break;
		}

		if (width != bitmapField->Width()) {
			BString truncatedString(bitmapField->String());
			parent->TruncateString(&truncatedString, fTruncateMode, width + 2);
			bitmapField->SetClippedString(truncatedString.String());
			bitmapField->SetWidth(width);
		}

		// draw the bitmap
		if (bitmap) {
			parent->SetDrawingMode(B_OP_ALPHA);
			parent->DrawBitmap(bitmap, BPoint(x, y));
			parent->SetDrawingMode(B_OP_OVER);
		}

		// draw the string
		DrawString(bitmapField->ClippedString(), parent, r);

	} else if (stringField) {

		float width = rect.Width() - (2 * sTextMargin);

		if (width != stringField->Width()) {
			BString truncatedString(stringField->String());

			parent->TruncateString(&truncatedString, fTruncateMode, width + 2);
			stringField->SetClippedString(truncatedString.String());
			stringField->SetWidth(width);
		}

		DrawString(stringField->ClippedString(), parent, rect);
	}
}
Esempio n. 4
0
void
PackageColumn::DrawField(BField* field, BRect rect, BView* parent)
{
    BBitmapStringField* bitmapField
        = dynamic_cast<BBitmapStringField*>(field);
    BStringField* stringField = dynamic_cast<BStringField*>(field);
    RatingField* ratingField = dynamic_cast<RatingField*>(field);

    if (bitmapField != NULL) {
        const BBitmap* bitmap = bitmapField->Bitmap();

        // figure out the placement
        float x = 0.0;
        BRect r = bitmap ? bitmap->Bounds() : BRect(0, 0, 15, 15);
        float y = rect.top + ((rect.Height() - r.Height()) / 2);
        float width = 0.0;

        switch (Alignment()) {
        default:
        case B_ALIGN_LEFT:
        case B_ALIGN_CENTER:
            x = rect.left + sTextMargin;
            width = rect.right - (x + r.Width()) - (2 * sTextMargin);
            r.Set(x + r.Width(), rect.top, rect.right - width, rect.bottom);
            break;

        case B_ALIGN_RIGHT:
            x = rect.right - sTextMargin - r.Width();
            width = (x - rect.left - (2 * sTextMargin));
            r.Set(rect.left, rect.top, rect.left + width, rect.bottom);
            break;
        }

        if (width != bitmapField->Width()) {
            BString truncatedString(bitmapField->String());
            parent->TruncateString(&truncatedString, fTruncateMode, width + 2);
            bitmapField->SetClippedString(truncatedString.String());
            bitmapField->SetWidth(width);
        }

        // draw the bitmap
        if (bitmap != NULL) {
            parent->SetDrawingMode(B_OP_ALPHA);
            parent->DrawBitmap(bitmap, BPoint(x, y));
            parent->SetDrawingMode(B_OP_OVER);
        }

        // draw the string
        DrawString(bitmapField->ClippedString(), parent, r);

    } else if (stringField != NULL) {

        float width = rect.Width() - (2 * sTextMargin);

        if (width != stringField->Width()) {
            BString truncatedString(stringField->String());

            parent->TruncateString(&truncatedString, fTruncateMode, width + 2);
            stringField->SetClippedString(truncatedString.String());
            stringField->SetWidth(width);
        }

        DrawString(stringField->ClippedString(), parent, rect);

    } else if (ratingField != NULL) {

        const float kDefaultTextMargin = 8;

        float width = rect.Width() - (2 * kDefaultTextMargin);

        BString string = "★★★★★";
        float stringWidth = parent->StringWidth(string);
        bool drawOverlay = true;

        if (width < stringWidth) {
            string.SetToFormat("%.1f", ratingField->Rating());
            drawOverlay = false;
            stringWidth = parent->StringWidth(string);
        }

        switch (Alignment()) {
        default:
        case B_ALIGN_LEFT:
            rect.left += kDefaultTextMargin;
            break;
        case B_ALIGN_CENTER:
            rect.left = rect.left + (width - stringWidth) / 2.0f;
            break;

        case B_ALIGN_RIGHT:
            rect.left = rect.right - (stringWidth + kDefaultTextMargin);
            break;
        }

        rect.left = floorf(rect.left);
        rect.right = rect.left + stringWidth;

        if (drawOverlay)
            parent->SetHighColor(0, 170, 255);

        font_height	fontHeight;
        parent->GetFontHeight(&fontHeight);
        float y = rect.top + (rect.Height()
                              - (fontHeight.ascent + fontHeight.descent)) / 2
                  + fontHeight.ascent;

        parent->DrawString(string, BPoint(rect.left, y));

        if (drawOverlay) {
            rect.left = ceilf(rect.left
                              + (ratingField->Rating() / 5.0f) * rect.Width());

            rgb_color color = parent->LowColor();
            color.alpha = 190;
            parent->SetHighColor(color);

            parent->SetDrawingMode(B_OP_ALPHA);
            parent->FillRect(rect, B_SOLID_HIGH);

        }
    }
}