本文整理汇总了C++中BRect::InsetBySelf方法的典型用法代码示例。如果您正苦于以下问题:C++ BRect::InsetBySelf方法的具体用法?C++ BRect::InsetBySelf怎么用?C++ BRect::InsetBySelf使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BRect
的用法示例。
在下文中一共展示了BRect::InsetBySelf方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: TR
MouseWindow::MouseWindow(BRect _rect)
:
BWindow(_rect, TR("Mouse"), B_TITLED_WINDOW,
B_NOT_RESIZABLE | B_NOT_ZOOMABLE | B_ASYNCHRONOUS_CONTROLS |
B_AUTO_UPDATE_SIZE_LIMITS)
{
// Add the main settings view
fSettingsView = new SettingsView(fSettings);
fSettingsBox = new BBox("main box");
fSettingsBox->AddChild(fSettingsView);
// Add the "Default" button
fDefaultsButton = new BButton(TR("Defaults"), new BMessage(kMsgDefaults));
fDefaultsButton->SetEnabled(fSettings.IsDefaultable());
// Add the "Revert" button
fRevertButton = new BButton(TR("Revert"), new BMessage(kMsgRevert));
fRevertButton->SetEnabled(false);
SetPulseRate(100000);
// we are using the pulse rate to scan pressed mouse
// buttons and draw the selected imagery
// Build the layout
SetLayout(new BGroupLayout(B_VERTICAL));
AddChild(BGroupLayoutBuilder(B_VERTICAL, 10)
.Add(fSettingsBox)
.AddGroup(B_HORIZONTAL, 5)
.Add(fDefaultsButton)
.Add(fRevertButton)
.AddGlue()
.End()
.SetInsets(10, 10, 10, 10)
);
// check if the window is on screen
BRect rect = BScreen().Frame();
rect.InsetBySelf(20, 20);
BPoint position = fSettings.WindowPosition();
BRect windowFrame = Frame().OffsetToSelf(position);
if (!rect.Contains(windowFrame)) {
// center window on screen as it doesn't fit on the saved position
position.x = (rect.Width() - windowFrame.Width()) / 2;
position.y = (rect.Height() - windowFrame.Height()) / 2;
if (position.x < 0)
position.x = 0;
if (position.y < 0)
position.y = 15;
}
MoveTo(position);
}
示例2: BRect
/*!
* \brief Default constructor
* \param[in] frame The rectangle enclosing the view
* \param[in] name Name of the view. Will be passed to BView's constructor.
*
*/
CalendarModulePreferencesView::CalendarModulePreferencesView( BRect frame )
:
BView( BRect( frame.left, frame.top, frame.right, frame.bottom-10 ),
"Calendar Module Preferences",
B_FOLLOW_LEFT | B_FOLLOW_TOP,
B_NAVIGABLE | B_WILL_DRAW | B_FRAME_EVENTS )
{
BRect tempFrame = this->Bounds(); // Got the boundaries
this->SetViewColor( ui_color( B_PANEL_BACKGROUND_COLOR ) );
tempFrame.InsetBySelf( 5, 5 );
tempFrame.bottom -= 10;
/* Add the chooser for the calendar modules */
BGroupLayout* groupLayout = new BGroupLayout( B_VERTICAL );
if ( !groupLayout ) {
/* Panic! */
exit( 1 );
}
groupLayout->SetSpacing( 2 );
this->SetLayout( groupLayout );
// Create the menu with all supported calendar modules
calendarModules = PopulateModulesMenu();
if ( ! calendarModules ) {
/* Panic! */
exit ( 1 );
}
calendarModuleSelector = new BMenuField( BRect( 0, 0, this->Bounds().Width() - 10, 1 ),
"Calendar Modules selector",
"Calendar module:",
calendarModules,
B_FOLLOW_H_CENTER | B_FOLLOW_TOP );
if ( !calendarModuleSelector ) {
/* Panic! */
exit ( 1 );
}
calendarModuleSelector->ResizeToPreferred();
// Add the menu with all calendar modules to the layout
BLayoutItem* layoutItem = groupLayout->AddView( 0, calendarModuleSelector, 1 );
if ( layoutItem ) {
layoutItem->SetExplicitAlignment( BAlignment( B_ALIGN_CENTER, B_ALIGN_TOP ) );
}
// Relayout
groupLayout->Relayout();
} // <-- end of constructor for CalendarModulePreferencesView
示例3: ceilf
/*! \function CategoryMenuItem::CreateIcon
* \brief Create the square icon filled with submitted color.
* \param[in] color The color of the requested icon.
* \param[in] toChange If there is an allocated item, it may be changed.
* If the submitted pointer is not NULL (which is default),
* this BBitmap is tested for dimensions match, and if dimensions
* allow, its contents are replaced with new icon. Else, old icon
* is deleted, and a new is created. In this case, both the
* "toChange" pointer and returned pointer point to the same
* BBitmap.
*/
BBitmap* CategoryMenuItem::CreateIcon( const rgb_color color,
BBitmap* toChange )
{
BBitmap* toReturn = NULL; //!< This is the value to be returned.
BRect tempRect;
float width, height, squareSide;
// Get size of the square
this->GetContentSize( &width, &height );
squareSide = ceilf( height ) - 2;
// Compare submitted bitmap to calculated size
if ( toChange )
{
tempRect = toChange->Bounds();
if ( ( tempRect.Width() != squareSide ) ||
( tempRect.Height() != squareSide ) )
{
// Dimensions don't match - need to delete the bitmap and reallocate it
delete toChange;
tempRect.Set( 0, 0, squareSide, squareSide );
toChange = new BBitmap( tempRect, B_RGB32, true );
if ( !toChange )
{
/* Panic! */
exit(1);
}
toReturn = toChange;
}
else
{
/*! \note Note about color spaces
* Actually, even if the dimensions are correct, the existing
* BBitmap may be not suitable due to incorrect color space.
* However, BBitmap may change the color space on its own, (and
* probably will, since there's no much sense in having 32 bits
* per pixel for bitmap with only 2 colors - black for the frame
* and Category's color for the inside). Therefore, color space is
* not checked. It's assumed that existing color space is good enough.
*/
// Dimensions match, color space is not checked - continuing
toReturn = toChange;
}
}
else // No bitmap is submitted
{
toReturn = new BBitmap( tempRect, B_RGB32, true );
if ( !toReturn )
{
/* Panic! */
exit(1);
}
}
/* Here toReturn is already set. */
// Add the drawing view to the bitmap
tempRect.Set( 0, 0, squareSide, squareSide );
BView* drawing = new BView (tempRect,
"Drawer",
B_FOLLOW_LEFT | B_FOLLOW_TOP,
B_WILL_DRAW);
if (!drawing || !toReturn) {
/* Panic! */
return NULL;
}
toReturn->AddChild(drawing);
if (toReturn->Lock()) {
// Clean the area
drawing->SetHighColor( ui_color( B_MENU_BACKGROUND_COLOR ) );
drawing->FillRect( tempRect );
// Draw the black square
drawing->SetHighColor( ui_color( B_MENU_ITEM_TEXT_COLOR ) );
drawing->SetPenSize( 1 );
drawing->StrokeRect( tempRect );
// Fill the inside of the square
drawing->SetHighColor( color );
drawing->FillRect( tempRect.InsetBySelf( 1, 1 ) );
// Flush the actions to BBitmap
drawing->Sync();
toReturn->Unlock();
}
toReturn->RemoveChild( drawing );
//.........这里部分代码省略.........
示例4: MessageReceived
//.........这里部分代码省略.........
if ( ! messageToSend )
{
if ( this->dirty )
{
this->messageToSend = new BMessage( kColorSelected );
} else {
this->messageToSend = new BMessage( kColorReverted );
}
if ( ! this->messageToSend ) {
/* Panic! */
exit(1);
}
}
// Stuff the message with needed data
messageToSend->AddBool( "Dirty", this->dirty );
messageToSend->AddString ( "Original string", this->originalString );
if ( this->dirty ) {
messageToSend->AddString("New string", currentString );
}
messageToSend->AddInt32( "Original color", RepresentColorAsUint32( this->originalColor ) );
messageToSend->AddInt32( "New color", RepresentColorAsUint32( this->currentColor ) );
// Send the message and close current window
// mesg = new BMessenger( (BHandler* )target, NULL, &errorCode );
mesg = new BMessenger( "application/x-vnd.Hitech.Skeleton", -1, &errorCode );
if ( errorCode == B_OK ) {
mesg->SendMessage( messageToSend, ( BHandler* )NULL );
deb = new DebuggerPrintout( "Message was sent" );
} else {
deb = new DebuggerPrintout( "Message wasn't sent" );
}
this->Quit();
break;
case kColorReverted:
/* Returning to original settings */
if ( colorControl )
{
colorControl->SetValue( originalColor );
colorControl->Invoke();
}
if ( enableEditingLabel && this->labelView )
{
( (BTextControl*)this->labelView )->SetText( this->originalString.String() );
( (BTextControl*)this->labelView )->MakeFocus( false ); // Prevent accidental change of text
}
break;
case kColorChanged:
// We need to reflect the change in color.
// We'll do it using the current view's high color. For this, we need to
// back up current high color in order to restore it later.
background = this->FindView( "Background" );
if ( ! background )
{
deb = new DebuggerPrintout( "Didn't find background!" );
return;
}
previousHighColor = background->HighColor();
background->SetHighColor( 0, 0, 1 ); // almost black
tempRect = BRect( ( revertButton->Frame() ).right + 10,
( revertButton->Frame() ).top,
( okButton->Frame() ).left - 10,
( revertButton->Frame() ).bottom );
// Actual drawing
if ( this->Lock() ) {
background->SetPenSize( 1 );
// Create border
background->StrokeRoundRect( tempRect.InsetBySelf( 1, 1 ), 4, 4 );
// Fill the rectangle
background->SetHighColor( colorControl->ValueAsColor() );
background->FillRoundRect( tempRect.InsetBySelf( 1, 1 ), 4, 4 );
background->Flush();
this->Flush();
this->Unlock();
}
background->SetHighColor( previousHighColor );
break;
default:
BWindow::MessageReceived( in );
};
} // <-- end of function "ColorUpdateWindow::MessageReceived"
示例5: bounds
AboutWindow::AboutWindow ()
: BWindow (BRect (0, 0, 300, 200), "About", B_MODAL_WINDOW,
B_NOT_ZOOMABLE | B_NOT_MINIMIZABLE | B_NOT_RESIZABLE)
{
PRINT (("AboutWindow::AboutWindow ()\n"));
SetFeel (B_MODAL_APP_WINDOW_FEEL);
SetLook (B_MODAL_WINDOW_LOOK);
/* Create the BBitmap objects and set its data with error checking */
BBitmap *appIcon = new BBitmap (BRect (0, 0, kLargeIconWidth - 1, kLargeIconHeight - 1), B_COLOR_8_BIT);
appIcon->SetBits (iconBits, 32 * 32 * 8, 0, B_COLOR_8_BIT);
BBitmap *bmp = BTranslationUtils::GetBitmap ('PNG ', "Image:AboutTitle");
if (bmp == NULL)
{
BAlert *err = new BAlert ("Error", "An error was encountered while "
"trying to load the resource element \"Image:AboutTitle\"\n", "Hmm..",
NULL, NULL, B_WIDTH_AS_USUAL, B_OFFSET_SPACING, B_STOP_ALERT);
err->Go();
Hide();
Quit();
QuitRequested();
return;
}
/* Yet another annoying control rendering section :( */
BRect bounds (Bounds());
backView = new BView (bounds.InsetBySelf (1, 1), "AboutWindow:BackView", B_FOLLOW_ALL_SIDES, B_WILL_DRAW);
AddChild (backView);
iconView = new BView (BRect (1.5 * DialogMargin + 3, 1.5 * DialogMargin,
1.5 * DialogMargin + kLargeIconWidth - 1 + 3, 1.5 * DialogMargin + kLargeIconWidth - 1),
"AboutWindow:IconView", B_FOLLOW_LEFT, B_WILL_DRAW);
backView->AddChild (iconView);
iconView->SetViewBitmap (appIcon);
float left = DialogMargin + kLargeIconWidth + 1.5 * ButtonSpacing - 3;
float top = DialogMargin / 2.0;
titleView = new BView (BRect (left, top, 214 + left, 58 + top), "AboutWindow:TitleView",
B_FOLLOW_LEFT, B_WILL_DRAW);
backView->AddChild (titleView);
titleView->SetViewBitmap (bmp);
lineView = new BView (BRect (0, titleView->Frame().bottom + 3, bounds.right, titleView->Frame().bottom + 3),
"AboutWindow:LineView", B_FOLLOW_LEFT, B_WILL_DRAW);
lineView->SetViewColor (128, 128, 128);
backView->AddChild (lineView);
textView = new MarqueeView (BRect (2, lineView->Frame().bottom + ButtonSpacing / 2 + 2,
bounds.right - DialogMargin - 1, bounds.bottom - 2 - ButtonSpacing / 2),
"AboutWindow:CreditsView", BRect (0, 0, bounds.right - DialogMargin, 0),
B_FOLLOW_LEFT, B_WILL_DRAW);
backView->AddChild (textView);
textView->SetStylable (true);
textView->MakeSelectable (false);
textView->MakeEditable (false);
textView->SetAlignment (B_ALIGN_CENTER);
textView->SetViewColor (BePureWhite);
backView->SetViewColor (BePureWhite);
textView->SetFontAndColor (be_plain_font, B_FONT_ALL, &BeJetBlack);
/* Calculate no of '\n's to leave to make the text go to the bottom, calculate the no. of lines */
font_height fntHt;
textView->GetFontHeight (&fntHt);
int32 noOfLines = (int32)(textView->Frame().Height() / fntHt.ascent) - 1;
for (int32 i = 1; i < (int32)noOfLines; i++)
lineFeeds << "\n";
creditsText =
"Freeware, Version " AppVersion "\n"
"Copyright " B_UTF8_COPYRIGHT " 2002 Ramshankar\n\n\n"
CODING "\nRamshankar\n([email protected])\n\n* * *\n\n\n\n\n\n\n\n\n"
THANKS_TO "\n\n"
BUBBLEHELP "\nMarco Nelissen\n\n"
BESHARE "\nJeremy Friesner\n\n"
"Thank you all for your\n"
"contributions with the code...\n\n* * *\n\n\n\n\n\n\n\n\n"
"Also thanks to\n\n"
"John Trujillo\nSebastian Benner\nM Floro\n\n"
"for your support and contributions...\n\n* * *\n\n\n\n\n\n\n\n\n"
"A special round of applause\n"
"to BeShare members (in no\n"
"particular order) :\n\n"
"lillo\nshatty\nProcton\n"
"Bryan\nPahtz\nmmu_man\nBeMikko\nNeil\nskiBUM\nand "
"others\n\n"
"for being so good... :)\n\n* * *\n\n\n\n\n\n\n\n\n"
LEGAL_MUMBO_JUMBO "\n\n"
"This program is distributed under\n"
"its own license, and the gist of\n"
"the license is attached to each\n"
"source file of this program\n\n"
"For third party code, the license's\n"
"terms and conditions are explicitly\n"
"stated and the author disclaimed of\n"
"any and all liabilities\n\n"
"For the full license read the\n"
//.........这里部分代码省略.........
示例6: reply
//.........这里部分代码省略.........
if (message.Read(bounds) != B_OK)
continue;
if (code == RP_STROKE_TRIANGLE) {
offscreen->StrokeTriangle(points[0], points[1], points[2],
bounds, pattern);
bounds.InsetBy(-penSize, -penSize);
} else if (code == RP_FILL_TRIANGLE) {
offscreen->FillTriangle(points[0], points[1], points[2],
bounds, pattern);
} else {
BGradient *gradient;
if (message.ReadGradient(&gradient) != B_OK)
continue;
offscreen->FillTriangle(points[0], points[1], points[2],
bounds, *gradient);
delete gradient;
}
invalidRegion.Include(bounds);
break;
}
case RP_STROKE_LINE:
{
BPoint points[2];
if (message.ReadList(points, 2) != B_OK)
continue;
offscreen->StrokeLine(points[0], points[1], pattern);
BRect bounds = _BuildInvalidateRect(points, 2);
invalidRegion.Include(bounds.InsetBySelf(-penSize, -penSize));
break;
}
case RP_STROKE_LINE_ARRAY:
{
int32 numLines;
if (message.Read(numLines) != B_OK)
continue;
BRect bounds;
offscreen->BeginLineArray(numLines);
for (int32 i = 0; i < numLines; i++) {
rgb_color color;
BPoint start, end;
message.ReadArrayLine(start, end, color);
offscreen->AddLine(start, end, color);
bounds.left = min_c(bounds.left, min_c(start.x, end.x));
bounds.top = min_c(bounds.top, min_c(start.y, end.y));
bounds.right = max_c(bounds.right, max_c(start.x, end.x));
bounds.bottom = max_c(bounds.bottom, max_c(start.y, end.y));
}
offscreen->EndLineArray();
invalidRegion.Include(bounds);
break;
}
case RP_FILL_REGION:
case RP_FILL_REGION_GRADIENT:
{
BRegion region;
示例7: separatorRect
BView *
DefaultMediaTheme::MakeViewFor(BParameterGroup& group, const BRect* hintRect)
{
CALLED();
if (group.Flags() & B_HIDDEN_PARAMETER)
return NULL;
BRect rect;
if (hintRect != NULL)
rect = *hintRect;
GroupView *view = new GroupView(rect, group.Name());
// Create the parameter views - but don't add them yet
rect.OffsetTo(B_ORIGIN);
rect.InsetBySelf(5, 5);
BList views;
for (int32 i = 0; i < group.CountParameters(); i++) {
BParameter *parameter = group.ParameterAt(i);
if (parameter == NULL)
continue;
BView *parameterView = MakeSelfHostingViewFor(*parameter,
hintRect ? &rect : NULL);
if (parameterView == NULL)
continue;
parameterView->SetViewColor(view->ViewColor());
// ToDo: dunno why this is needed, but the controls
// sometimes (!) have a white background without it
views.AddItem(parameterView);
}
// Identify a title view, and add it at the top if present
TitleView *titleView = dynamic_cast<TitleView *>((BView *)views.ItemAt(0));
if (titleView != NULL) {
view->AddChild(titleView);
rect.OffsetBy(0, titleView->Bounds().Height());
}
// Add the sub-group views
rect.right = rect.left + 20;
rect.bottom = rect.top + 20;
float lastHeight = 0;
for (int32 i = 0; i < group.CountGroups(); i++) {
BParameterGroup *subGroup = group.GroupAt(i);
if (subGroup == NULL)
continue;
BView *groupView = MakeViewFor(*subGroup, &rect);
if (groupView == NULL)
continue;
if (i > 0) {
// add separator view
BRect separatorRect(groupView->Frame());
separatorRect.left -= 3;
separatorRect.right = separatorRect.left + 1;
if (lastHeight > separatorRect.Height())
separatorRect.bottom = separatorRect.top + lastHeight;
view->AddChild(new SeparatorView(separatorRect));
}
view->AddChild(groupView);
rect.OffsetBy(groupView->Bounds().Width() + 5, 0);
lastHeight = groupView->Bounds().Height();
if (lastHeight > rect.Height())
rect.bottom = rect.top + lastHeight - 1;
}
view->ResizeTo(rect.left + 10, rect.bottom + 5);
view->SetContentBounds(view->Bounds());
if (group.CountParameters() == 0)
return view;
// add the parameter views part of the group
if (group.CountGroups() > 0) {
rect.top = rect.bottom + 10;
rect.bottom = rect.top + 20;
}
bool center = false;
for (int32 i = 0; i < views.CountItems(); i++) {
BView *parameterView = static_cast<BView *>(views.ItemAt(i));
if (parameterView->Bounds().Width() + 5 > rect.Width())
rect.right = parameterView->Bounds().Width() + rect.left + 5;
//.........这里部分代码省略.........
示例8: CreateWeekendSelectionBox
/*! \brief Builds the interface for a selected calendar module.
* \param[in] id Name of the calendar module to build the interface for.
* \details If the interface for a module already exists, this function
* deletes it without affecting the already set preferences.
*/
void CalendarModulePreferencesView::BuildInterfaceForModule( const BString& id )
{
BGroupLayout* layout = ( BGroupLayout* )( BView::GetLayout() );
BLayoutItem* layoutItem = NULL;
BBox* tempBBox = NULL;
if ( !this->Window() || this->Window()->Lock() )
{
// First, clean up old interface items if they existed
this->ClearOldInterface();
// Prepare the frame for the BBox for weekends selection
BRect r = this->Bounds();
r.InsetBySelf( 5, 5 );
r.right -= 10;
r.bottom -= 10;
if ( calendarModuleSelector )
r.top += ( calendarModuleSelector->Bounds().Height() + 10 );
// Build weekend selection
tempBBox = CreateWeekendSelectionBox( r, id );
if ( tempBBox )
{
// After the call, the BBox is resized to minimal required size.
layoutItem = layout->AddView( 1, tempBBox, 0 );
layoutItem->SetExplicitAlignment( BAlignment( B_ALIGN_CENTER, B_ALIGN_TOP ) );
}
else
{
utl_Deb = new DebuggerPrintout( "Error - Weekend selection box is NULL." );
}
// Start day chooser
BMenuField* startDayChooser = CreateWeekStartDayChooser( r, id );
if ( startDayChooser )
{
layoutItem = layout->AddView( 2, startDayChooser, 0 );
if ( layoutItem )
layoutItem->SetExplicitAlignment( BAlignment( B_ALIGN_LEFT, B_ALIGN_TOP ) );
}
// Day-month-year order
BMenuField* dmyChooser = CreateDayMonthYearOrderChooser( r, id );
if ( dmyChooser )
{
layoutItem = layout->AddView( 3, dmyChooser, 0 );
if ( layoutItem )
layoutItem->SetExplicitAlignment( BAlignment( B_ALIGN_LEFT, B_ALIGN_TOP ) );
}
// Colors selection
tempBBox = BuildColorSelectors( r, id );
if ( tempBBox ) {
layoutItem = layout->AddView( 4, tempBBox, 0 );
}
/* At the end, all children are targetted at current window */
UpdateTargetting();
if ( this->Window() ) { this->Window()->Unlock(); }
} // <-- end of lock-only section
} // <-- end of function CalendarModulePreferencesView::BuildInterfaceForModule