本文整理汇总了C++中BView::SetBlendingMode方法的典型用法代码示例。如果您正苦于以下问题:C++ BView::SetBlendingMode方法的具体用法?C++ BView::SetBlendingMode怎么用?C++ BView::SetBlendingMode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BView
的用法示例。
在下文中一共展示了BView::SetBlendingMode方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: BView
/***********************************************************
* Make outside state picture.
***********************************************************/
BPicture*
HToolbarButton::MakeOutsidePicture(BBitmap *in)
{
HToolbar *toolbar = cast_as(Parent(),HToolbar);
BRect buttonRect = toolbar->ButtonRect();
BView *view = new BView(BRect(0,0,buttonRect.Width(),buttonRect.Height())
,"offview",0,0);
BBitmap *bitmap = new BBitmap(BRect(0,0,15,15), in->ColorSpace(), true);
BPicture *pict;
bitmap->AddChild(view);
bitmap->Lock();
view->SetDrawingMode(B_OP_ALPHA);
view->SetBlendingMode(B_PIXEL_ALPHA, B_ALPHA_OVERLAY);
view->BeginPicture(new BPicture);
DrawBitmap(view,in);
DrawString(view,fName.String());
pict = view->EndPicture();
bitmap->Unlock();
delete bitmap;
return pict;
}
示例2: message
void
IconView::MouseMoved(BPoint where, uint32 transit, const BMessage* dragMessage)
{
if (fTracking && !fDragging && fIcon != NULL
&& (abs((int32)(where.x - fDragPoint.x)) > 3
|| abs((int32)(where.y - fDragPoint.y)) > 3)) {
// Start drag
BMessage message(B_SIMPLE_DATA);
::Icon* icon = fIconData;
if (fHasRef || fHasType) {
icon = new ::Icon;
if (fHasRef)
icon->SetTo(fRef, fType.Type());
else if (fHasType)
icon->SetTo(fType);
}
icon->CopyTo(message);
if (icon != fIconData)
delete icon;
BBitmap *dragBitmap = new BBitmap(fIcon->Bounds(), B_RGBA32, true);
dragBitmap->Lock();
BView *view
= new BView(dragBitmap->Bounds(), B_EMPTY_STRING, B_FOLLOW_NONE, 0);
dragBitmap->AddChild(view);
view->SetHighColor(B_TRANSPARENT_COLOR);
view->FillRect(dragBitmap->Bounds());
view->SetBlendingMode(B_CONSTANT_ALPHA, B_ALPHA_COMPOSITE);
view->SetDrawingMode(B_OP_ALPHA);
view->SetHighColor(0, 0, 0, 160);
view->DrawBitmap(fIcon);
view->Sync();
dragBitmap->Unlock();
DragMessage(&message, dragBitmap, B_OP_ALPHA,
fDragPoint - BitmapRect().LeftTop(), this);
fDragging = true;
SetMouseEventMask(B_POINTER_EVENTS, B_NO_POINTER_HISTORY);
}
if (dragMessage != NULL && !fDragging && AcceptsDrag(dragMessage)) {
bool dropTarget = transit == B_ENTERED_VIEW || transit == B_INSIDE_VIEW;
if (dropTarget != fDropTarget) {
fDropTarget = dropTarget;
Invalidate();
}
} else if (fDropTarget) {
fDropTarget = false;
Invalidate();
}
}
示例3: rect
BBitmap *DragonView::_MakeDragBitmap( void )
{
// If the currently displayed bitmap is too large to drag around,
// we'll just drag around a rectangle.
BRect drag_rect = _bits->Bounds();
if( drag_rect.Width() > _drag_max_size.x ||
drag_rect.Height() > _drag_max_size.y ) return NULL;
// If we've got a PNG image, we'll assume that it's got
// "interesting" alpha information. The ones that are built
// into DragonDrop's resources all have "interesting" alpha
// channels.
if( _image_is_png ) {
BBitmap *drag_me = new BBitmap( _bits );
memcpy( drag_me->Bits(), _bits->Bits(), _bits->BitsLength() );
return drag_me;
}
// If you've made it here, we'll need to build a semi-transparent image
// to drag around. This magic is from Pavel Cisler, and it ensures that
// you've got a drag bitmap that's translucent.
BRect rect( _bits->Bounds() );
BBitmap *bitmap = new BBitmap( rect, B_RGBA32, true );
BView *view = new BView( rect, "drag view", B_FOLLOW_NONE, 0 );
bitmap->Lock();
bitmap->AddChild( view );
BRegion new_clip;
new_clip.Set( rect );
view->ConstrainClippingRegion( &new_clip );
view->SetHighColor( 0, 0, 0, 0 );
view->FillRect( rect );
view->SetDrawingMode( B_OP_ALPHA );
view->SetHighColor( 0, 0, 0, 128 );
view->SetBlendingMode( B_CONSTANT_ALPHA, B_ALPHA_COMPOSITE );
view->DrawBitmap( _bits );
view->Sync();
bitmap->Unlock();
return bitmap;
}
示例4: rect
/*
* Make inside state picture.
*/
BPicture*
HToolbarButton::MakeInsidePicture(BBitmap *in)
{
HToolbar *toolbar = cast_as(Parent(),HToolbar);
BRect buttonRect = toolbar->ButtonRect();
BView *view = new BView(BRect(0,0,buttonRect.Width(),buttonRect.Height())
,"offview",0,0);
BBitmap *bitmap = new BBitmap(view->Bounds(), in->ColorSpace(), true);
BPicture *pict;
bitmap->AddChild(view);
bitmap->Lock();
view->SetDrawingMode(B_OP_ALPHA);
view->SetBlendingMode(B_PIXEL_ALPHA, B_ALPHA_OVERLAY);
view->BeginPicture(new BPicture);
DrawBitmap(view,in);
DrawString(view,fName.String());
//view->SetHighColor(White);
//view->FillRect(BRect(0,0,0,22));
//view->FillRect(BRect(0,0,22,0));
//view->SetHighColor(BeShadow);
//view->FillRect(BRect(21,0,21,21));
//view->FillRect(BRect(0,21,21,21));
BRect rect(Bounds());
view->SetDrawingMode(B_OP_OVER);
rect.InsetBy(1,1);
view->BeginLineArray(5);
view->AddLine(rect.LeftTop(), rect.LeftBottom(),
tint_color(ui_color(B_PANEL_BACKGROUND_COLOR), B_LIGHTEN_MAX_TINT));
view->AddLine(rect.LeftTop(), rect.RightTop(),
tint_color(ui_color(B_PANEL_BACKGROUND_COLOR), B_LIGHTEN_MAX_TINT));
view->AddLine(rect.LeftBottom(), rect.RightBottom(),
tint_color(ui_color(B_PANEL_BACKGROUND_COLOR), B_DARKEN_3_TINT));
rect.bottom--;
view->AddLine(rect.LeftBottom(), rect.RightBottom(),
tint_color(ui_color(B_PANEL_BACKGROUND_COLOR), B_DARKEN_1_TINT));
view->AddLine(rect.RightTop(), rect.RightBottom(),
tint_color(ui_color(B_PANEL_BACKGROUND_COLOR), B_DARKEN_3_TINT));
view->EndLineArray();
view->SetHighColor(tint_color(ui_color(B_PANEL_BACKGROUND_COLOR), B_DARKEN_3_TINT));
view->StrokeRect(Bounds());
pict = view->EndPicture();
bitmap->Unlock();
delete bitmap;
return pict;
}
示例5: Read
status_t
CanvasMessage::ReadViewState(BView& view, ::pattern& pattern)
{
bool subPixelPrecise;
float penSize, miterLimit;
drawing_mode drawingMode;
source_alpha sourceAlpha;
alpha_function alphaFunction;
cap_mode capMode;
join_mode joinMode;
rgb_color highColor, lowColor;
Read(penSize);
Read(subPixelPrecise);
Read(drawingMode);
Read(sourceAlpha);
Read(alphaFunction);
Read(pattern);
Read(capMode);
Read(joinMode);
Read(miterLimit);
Read(highColor);
status_t result = Read(lowColor);
if (result != B_OK)
return result;
uint32 flags = view.Flags() & ~B_SUBPIXEL_PRECISE;
view.SetFlags(flags | (subPixelPrecise ? B_SUBPIXEL_PRECISE : 0));
view.SetPenSize(penSize);
view.SetDrawingMode(drawingMode);
view.SetBlendingMode(sourceAlpha, alphaFunction);
view.SetLineMode(capMode, joinMode, miterLimit);
view.SetHighColor(highColor);
view.SetLowColor(lowColor);
return B_OK;
}
示例6: cursor
// MouseMoved
void
ObjectView::MouseMoved(BPoint where, uint32 transit,
const BMessage* dragMessage)
{
// BRect dirty(where, where);
// dirty.InsetBy(-10, -10);
// Invalidate(dirty);
if (dragMessage) {
//printf("ObjectView::MouseMoved(BPoint(%.1f, %.1f)) - DRAG MESSAGE\n", where.x, where.y);
//Window()->CurrentMessage()->PrintToStream();
} else {
//printf("ObjectView::MouseMoved(BPoint(%.1f, %.1f))\n", where.x, where.y);
}
if (fScrolling) {
BCursor cursor(kGrabCursor);
SetViewCursor(&cursor);
BPoint offset = fLastMousePos - where;
ScrollBy(offset.x, offset.y);
fLastMousePos = where + offset;
} else if (fInitiatingDrag) {
BPoint offset = fLastMousePos - where;
if (sqrtf(offset.x * offset.x + offset.y * offset.y) > 5.0) {
BMessage newDragMessage('drag');
BBitmap* dragBitmap = new BBitmap(BRect(0, 0, 40, 40), B_RGBA32,
true);
if (dragBitmap->Lock()) {
BView* helper = new BView(dragBitmap->Bounds(),
"offscreen view", B_FOLLOW_ALL, B_WILL_DRAW);
dragBitmap->AddChild(helper);
helper->SetDrawingMode(B_OP_ALPHA);
helper->SetBlendingMode(B_CONSTANT_ALPHA, B_ALPHA_COMPOSITE);
BRect r(helper->Bounds());
helper->SetHighColor(0, 0, 0, 128);
helper->StrokeRect(r);
helper->SetHighColor(200, 200, 200, 100);
r.InsetBy(1, 1);
helper->FillRect(r);
helper->SetHighColor(0, 0, 0, 255);
const char* text = B_TRANSLATE("Test");
float pos = (r.Width() - helper->StringWidth(text)) / 2;
helper->DrawString(text, BPoint(pos, 25));
helper->Sync();
}
DragMessage(&newDragMessage, dragBitmap, B_OP_ALPHA, B_ORIGIN,
this);
fInitiatingDrag = false;
}
} else {
BCursor cursor(kMoveCursor);
SetViewCursor(&cursor);
if (fState && fState->IsTracking()) {
BRect before = fState->Bounds();
fState->MouseMoved(where);
BRect after = fState->Bounds();
BRect invalid(before | after);
Invalidate(invalid);
}
}
// SetViewCursor();
}
示例7: reply
//.........这里部分代码省略.........
float newPenSize;
if (message.Read(newPenSize) != B_OK)
continue;
offscreen->SetPenSize(newPenSize);
penSize = newPenSize / 2;
break;
}
case RP_SET_STROKE_MODE:
{
cap_mode capMode;
join_mode joinMode;
float miterLimit;
message.Read(capMode);
message.Read(joinMode);
if (message.Read(miterLimit) != B_OK)
continue;
offscreen->SetLineMode(capMode, joinMode, miterLimit);
break;
}
case RP_SET_BLENDING_MODE:
{
source_alpha sourceAlpha;
alpha_function alphaFunction;
message.Read(sourceAlpha);
if (message.Read(alphaFunction) != B_OK)
continue;
offscreen->SetBlendingMode(sourceAlpha, alphaFunction);
break;
}
case RP_SET_PATTERN:
{
if (message.Read(pattern) != B_OK)
continue;
break;
}
case RP_SET_DRAWING_MODE:
{
drawing_mode drawingMode;
if (message.Read(drawingMode) != B_OK)
continue;
offscreen->SetDrawingMode(drawingMode);
break;
}
case RP_SET_FONT:
{
BFont font;
if (message.ReadFontState(font) != B_OK)
continue;
offscreen->SetFont(&font);
break;
}
case RP_CONSTRAIN_CLIPPING_REGION:
{
示例8: CreatePicture
//.........这里部分代码省略.........
// Icon + Label/Left
float d = (width-(mNeedsLatch ? DIVLATCHW : 0)-DIVW-labelWidth-iconWidth)/2;
posLabel = BPoint( d,(height-labelHeight)/2);
posIcon = BPoint( d+DIVW+labelWidth+(mNeedsLatch ? DIVLATCHW : 0),
(height-iconHeight)/2-1);
} else if (showIcons && (labelMode == "Right")) {
// Icon + Label/Right
float d = (width-(mNeedsLatch ? DIVLATCHW : 0)-DIVW-labelWidth-iconWidth)/2;
posLabel = BPoint( d+DIVW+iconWidth,(height-labelHeight)/2);
posIcon = BPoint( d,(height-iconHeight)/2-1);
} else if (showIcons && (labelMode == "Top")) {
// Icon + Label/top
float d = (height-DIVH-labelHeight-iconHeight)/2-2;
posLabel = BPoint( (width-labelWidth-(mNeedsLatch ? DIVLATCHW : 0))/2, d);
posIcon = BPoint( (width-iconWidth)/2-1,d+DIVH+labelHeight);
} else if (showIcons && (labelMode == "Bottom")) {
// Icon + Label/bottom
float d = (height-DIVH-labelHeight-iconHeight)/2;
posLabel = BPoint( (width-labelWidth-(mNeedsLatch ? DIVLATCHW : 0))/2,
d+DIVH+iconHeight);
posIcon = BPoint( (width-iconWidth)/2-1,d);
} else if (!showIcons && labelMode != "Hide") {
// Label only
posLabel = BPoint( (width-labelWidth-(mNeedsLatch ? DIVLATCHW : 0))/2,
(height-labelHeight)/2);
} else if (showIcons && labelMode == "Hide") {
// Icon only
posIcon = BPoint( (width-iconWidth-(mNeedsLatch ? DIVLATCHW : 0))/2,
(height-iconHeight)/2);
}
if (mNeedsLatch) {
if (labelMode == "Hide")
mLatchRect.Set( posIcon.x+iconWidth+2,
posIcon.y+iconHeight/2-LATCHSZ/2,
width, height);
else
mLatchRect.Set( posLabel.x+labelWidth+2,
posLabel.y+labelHeight/2-LATCHSZ/2,
width, height);
} else
mLatchRect.Set( -1, -1, -1, -1);
// Draw
BRect rect(0,0,width-1,height-1);
BView* view = new BView( rect, NULL, B_FOLLOW_NONE, 0);
BBitmap* drawImage = new BBitmap( rect, B_RGBA32, true);
drawImage->AddChild( view);
drawImage->Lock();
BPicture* picture = new BPicture();
view->BeginPicture( picture);
view->SetHighColor( ui_color( B_PANEL_TEXT_COLOR));
view->SetViewColor( B_TRANSPARENT_COLOR);
view->SetLowColor( ui_color( B_PANEL_BACKGROUND_COLOR));
#ifndef __HAIKU__
BmToolbar* toolbar = dynamic_cast<BmToolbar*>(Parent()->Parent());
BBitmap* toolbarBackground = NULL;
if (toolbar) {
toolbarBackground = toolbar->BackgroundBitmap();
if (toolbarBackground)
view->DrawBitmap( toolbarBackground, Frame(), rect);
}
if (mode == STATE_ON) {
rect.InsetBy( 1, 1);
view->BeginLineArray(4);
view->AddLine( rect.LeftBottom(), rect.LeftTop(),
BmWeakenColor(B_SHADOW_COLOR, BeShadowMod));
view->AddLine( rect.LeftTop(), rect.RightTop(),
BmWeakenColor(B_SHADOW_COLOR, BeShadowMod));
view->AddLine( rect.LeftBottom(), rect.RightBottom(),
ui_color( B_SHINE_COLOR));
view->AddLine( rect.RightBottom(), rect.RightTop(),
ui_color( B_SHINE_COLOR));
view->EndLineArray();
}
#endif
// Draw Icon
if (showIcons && image) {
view->SetDrawingMode( B_OP_ALPHA);
view->SetBlendingMode( B_PIXEL_ALPHA, B_ALPHA_OVERLAY);
#ifdef __HAIKU__
BBitmap disabledImage(image);
if (mode == STATE_DISABLED) {
image = &disabledImage;
uint8* bits = (uint8*)image->Bits();
uint32 width = image->Bounds().IntegerWidth() + 1;
uint32 height = image->Bounds().IntegerWidth() + 1;
uint32 bpr = image->BytesPerRow();
for (uint32 y = 0; y < height; y++) {
uint8* b = bits;
for (uint32 x = 0; x < width; x++) {
b[3] = (uint8)(((int)b[3] * 100) >> 8);
b += 4;
}
bits += bpr;
}
}
示例9: DoPersonDrag
void URLView::DoPersonDrag() {
// Handle all of the bookmark dragging. This includes setting up
// the drag message and drawing the dragged bitmap.
// Set up the drag message to support both BTextView dragging (using
// the e-mail address) and file dropping (to Tracker).
BMessage *dragMessage = new BMessage( B_MIME_DATA );
dragMessage->AddInt32( "be:actions", B_COPY_TARGET );
dragMessage->AddString( "be:types", "application/octet-stream" );
dragMessage->AddString( "be:filetypes", "application/x-person" );
dragMessage->AddString( "be:type_descriptions", "person" );
dragMessage->AddString( "be:clip_name", Text() );
// This allows the user to drag the e-mail address into a
// standard BTextView.
BString email = GetImportantURL();
dragMessage->AddData( "text/plain", B_MIME_DATA, email.String(),
email.Length() + 1 );
// Query for the system's icon for bookmarks.
BBitmap *personIcon = new BBitmap( BRect( 0, 0, iconSize - 1,
iconSize - 1 ), B_CMAP8 );
#ifdef ZETA
BMimeType mime( "application/x-vnd.Be-PEPL" );
#else
BMimeType mime( "application/x-person" );
#endif
if( iconSize == 16 ) mime.GetIcon( personIcon, B_MINI_ICON );
else mime.GetIcon( personIcon, B_LARGE_ICON );
// Find the size of the bitmap to drag. If the text is bigger than the
// icon, use that size. Otherwise, use the icon's. Center the icon
// vertically in the bitmap.
BRect rect = GetTextRect();
rect.right += iconSize + 4;
if( (rect.bottom - rect.top) < iconSize ) {
int adjustment = (int) ((iconSize - (rect.bottom - rect.top)) / 2) + 1;
rect.top -= adjustment;
rect.bottom += adjustment;
}
// Make sure the rectangle starts at 0,0.
rect.bottom += 0 - rect.top;
rect.top = 0;
// Create the bitmap to draw the dragged image in.
BBitmap *dragBitmap = new BBitmap( rect, B_RGBA32, true );
BView *dragView = new BView( rect, "Drag View", 0, 0 );
dragBitmap->Lock();
dragBitmap->AddChild( dragView );
BRect frameRect = dragView->Frame();
// Make the background of the dragged image transparent.
dragView->SetHighColor( B_TRANSPARENT_COLOR );
dragView->FillRect( frameRect );
// We want 'g's, etc. to go below the underline. When the BeOS can
// do underlining of any font, this code can be removed.
font_height height;
GetFontHeight( &height );
float descent = height.descent;
// Find the vertical center of the view so we can vertically
// center everything.
int centerPixel = (int) ((frameRect.bottom - frameRect.top) / 2);
int textCenter = (int) (descent + underlineThickness) + centerPixel;
// We want to draw everything only half opaque.
dragView->SetDrawingMode( B_OP_ALPHA );
dragView->SetHighColor( 0.0, 0.0, 0.0, 128.0 );
dragView->SetBlendingMode( B_CONSTANT_ALPHA, B_ALPHA_COMPOSITE );
// Center the icon in the view.
dragView->MovePenTo( BPoint( frameRect.left,
centerPixel - (iconSize / 2) ) );
dragView->DrawBitmap( personIcon );
// Draw the text in the same font (size, etc.) as the link view.
// Note: DrawString() draws the text at one pixel above the pen's
// current y coordinate.
BFont font;
GetFont( &font );
dragView->SetFont( &font );
dragView->MovePenTo( BPoint( frameRect.left + iconSize + 4, textCenter ) );
dragView->DrawString( Text() );
// Be sure to flush the view buffer so everything is drawn.
dragView->Flush();
dragBitmap->Unlock();
// The Person icon adds some width to the bitmap that we are
// going to draw. So horizontally offset the bitmap proportionally
// to where the user clicked on the link.
float horiz = dragOffset.x / GetTextRect().Width();
dragOffset.x = horiz * frameRect.right;
DragMessage( dragMessage, dragBitmap, B_OP_ALPHA,
BPoint( dragOffset.x,
(rect.Height() + underlineThickness) / 2 + 2), this );
//.........这里部分代码省略.........
示例10: drag
void
KeyboardLayoutView::MouseMoved(BPoint point, uint32 transit,
const BMessage* dragMessage)
{
if (fKeymap == NULL)
return;
// prevent dragging for tertiary mouse button
if ((fButtons & B_TERTIARY_MOUSE_BUTTON) != 0)
return;
if (dragMessage != NULL) {
if (fEditable) {
_InvalidateKey(fDropTarget);
fDropPoint = point;
_EvaluateDropTarget(point);
}
return;
}
int32 buttons;
if (Window()->CurrentMessage() == NULL
|| Window()->CurrentMessage()->FindInt32("buttons", &buttons) != B_OK
|| buttons == 0)
return;
if (fDragKey == NULL && (fabs(point.x - fClickPoint.x) > 4
|| fabs(point.y - fClickPoint.y) > 4)) {
// start dragging
Key* key = _KeyAt(fClickPoint);
if (key == NULL)
return;
BRect frame = _FrameFor(key);
BPoint offset = fClickPoint - frame.LeftTop();
frame.OffsetTo(B_ORIGIN);
BRect rect = frame;
rect.right--;
rect.bottom--;
BBitmap* bitmap = new BBitmap(rect, B_RGBA32, true);
bitmap->Lock();
BView* view = new BView(rect, "drag", B_FOLLOW_NONE, 0);
bitmap->AddChild(view);
view->SetHighColor(0, 0, 0, 0);
view->FillRect(view->Bounds());
view->SetDrawingMode(B_OP_ALPHA);
view->SetHighColor(0, 0, 0, 128);
// set the level of transparency by value
view->SetBlendingMode(B_CONSTANT_ALPHA, B_ALPHA_COMPOSITE);
_DrawKey(view, frame, key, frame, false);
view->Sync();
bitmap->Unlock();
BMessage drag(B_MIME_DATA);
drag.AddInt32("key", key->code);
char* string;
int32 numBytes;
fKeymap->GetChars(key->code, fModifiers, fDeadKey, &string,
&numBytes);
if (string != NULL) {
drag.AddData("text/plain", B_MIME_DATA, string, numBytes);
delete[] string;
}
DragMessage(&drag, bitmap, B_OP_ALPHA, offset);
fDragKey = key;
fDragModifiers = fModifiers;
fKeyState[key->code / 8] &= ~(1 << (7 - (key->code & 7)));
_InvalidateKey(key);
}
}