DialUpView::DialUpView(BRect frame) : BView(frame, "DialUpView", B_FOLLOW_ALL, 0), fListener(this), fUpDownThread(-1), fDriverSettings(NULL), fCurrentItem(NULL), fWatching(PPP_UNDEFINED_INTERFACE_ID), fKeepLabel(false) { BRect bounds = Bounds(); // for caching SetViewUIColor(B_PANEL_BACKGROUND_COLOR); // add messenger to us so add-ons can contact us BMessenger messenger(this); fAddons.AddMessenger(DUN_MESSENGER, messenger); // create pop-up with all interfaces and "New..."/"Delete current" items fInterfaceMenu = new BPopUpMenu(kLabelCreateNew); BRect rect = bounds; rect.InsetBy(5, 5); rect.bottom = rect.top + 20; fMenuField = new BMenuField(rect, "Interfaces", kLabelInterface, fInterfaceMenu); fMenuField->SetDivider(StringWidth(fMenuField->Label()) + 5); rect.top = rect.bottom + 10; rect.bottom = bounds.bottom - 20 // height of bottom controls - 20; // space for bottom controls fTabView = new BTabView(rect, "TabView", B_WIDTH_FROM_LABEL); BRect tabViewRect(fTabView->Bounds()); tabViewRect.bottom -= fTabView->TabHeight(); fAddons.AddRect(DUN_TAB_VIEW_RECT, tabViewRect); BRect tmpRect(rect); tmpRect.top += (tmpRect.Height() - 15) / 2; tmpRect.bottom = tmpRect.top + 15; fStringView = new BStringView(tmpRect, "NoInterfacesFound", kTextNoInterfacesFound); fStringView->SetAlignment(B_ALIGN_CENTER); fStringView->Hide(); tmpRect.top = tmpRect.bottom + 10; tmpRect.bottom = tmpRect.top + 25; fCreateNewButton = new BButton(tmpRect, "CreateNewButton", kLabelCreateNewInterface, new BMessage(kMsgCreateNew)); fCreateNewButton->ResizeToPreferred(); tmpRect.left = (rect.Width() - fCreateNewButton->Bounds().Width()) / 2 + rect.left; fCreateNewButton->MoveTo(tmpRect.left, tmpRect.top); fCreateNewButton->Hide(); rect.top = rect.bottom + 15; rect.bottom = rect.top + 15; rect.right = rect.left + 200; fStatusView = new BStringView(rect, "StatusView", kTextNotConnected, B_FOLLOW_BOTTOM); rect.InsetBy(0, -5); rect.left = rect.right + 5; rect.right = bounds.right - 5; fConnectButton = new BButton(rect, "ConnectButton", kLabelConnect, new BMessage(kMsgConnectButton), B_FOLLOW_BOTTOM); AddChild(fMenuField); AddChild(fTabView); AddChild(fStringView); AddChild(fCreateNewButton); AddChild(fStatusView); AddChild(fConnectButton); // initialize LoadInterfaces(); LoadAddons(); CreateTabs(); fCurrentItem = NULL; // reset, otherwise SelectInterface will not load the settings SelectInterface(0); UpdateControls(); }
void PasswordWindow::_Setup() { BRect bounds = Bounds(); BView* topView = new BView(bounds, "topView", B_FOLLOW_ALL, B_WILL_DRAW); topView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); AddChild(topView); bounds.InsetBy(10.0, 10.0); fUseNetwork = new BRadioButton(bounds, "useNetwork", "Use network password", new BMessage(kMsgPasswordTypeChanged), B_FOLLOW_NONE); topView->AddChild(fUseNetwork); fUseNetwork->ResizeToPreferred(); fUseNetwork->MoveBy(10.0, 0.0); bounds.OffsetBy(0.0, fUseNetwork->Bounds().Height()); BBox *customBox = new BBox(bounds, "customBox", B_FOLLOW_NONE); topView->AddChild(customBox); fUseCustom = new BRadioButton(BRect(), "useCustom", "Use custom password", new BMessage(kMsgPasswordTypeChanged), B_FOLLOW_NONE); customBox->SetLabel(fUseCustom); fUseCustom->ResizeToPreferred(); fPasswordControl = new BTextControl(bounds, "passwordControl", "Password:"******"confirmControl", "Confirm password:"******"VeryLongPasswordPossible", B_FOLLOW_NONE); customBox->AddChild(fConfirmControl); fConfirmControl->TextView()->HideTyping(true); fConfirmControl->SetAlignment(B_ALIGN_RIGHT, B_ALIGN_LEFT); float width, height; fConfirmControl->GetPreferredSize(&width, &height); fPasswordControl->ResizeTo(width, height); fConfirmControl->ResizeTo(width, height); float divider = be_plain_font->StringWidth("Confirm password:"******"done", "Done", new BMessage(kMsgDone)); topView->AddChild(button); button->ResizeToPreferred(); BRect frame = customBox->Frame(); button->MoveTo(frame.right - button->Bounds().Width(), frame.bottom + 10.0); frame = button->Frame(); button->MakeDefault(true); button = new BButton(frame, "cancel", "Cancel", new BMessage(B_CANCEL)); topView->AddChild(button); button->ResizeToPreferred(); button->MoveBy(-(button->Bounds().Width() + 10.0), 0.0); ResizeTo(customBox->Frame().right + 10.0, frame.bottom + 10.0); }
void PowerStatusView::_DrawBattery(BRect rect) { float quarter = floorf((rect.Height() + 1) / 4); rect.top += quarter; rect.bottom -= quarter; rect.InsetBy(2, 0); float left = rect.left; rect.left += rect.Width() / 11; SetHighColor(0, 0, 0); float gap = 1; if (rect.Height() > 8) { gap = ceilf((rect.left - left) / 2); // left FillRect(BRect(rect.left, rect.top, rect.left + gap - 1, rect.bottom)); // right FillRect(BRect(rect.right - gap + 1, rect.top, rect.right, rect.bottom)); // top FillRect(BRect(rect.left + gap, rect.top, rect.right - gap, rect.top + gap - 1)); // bottom FillRect(BRect(rect.left + gap, rect.bottom + 1 - gap, rect.right - gap, rect.bottom)); } else StrokeRect(rect); FillRect(BRect(left, floorf(rect.top + rect.Height() / 4) + 1, rect.left - 1, floorf(rect.bottom - rect.Height() / 4))); int32 percent = fPercent; if (percent > 100) percent = 100; else if (percent < 0 || !fHasBattery) percent = 0; if (percent > 0) { rect.InsetBy(gap, gap); rgb_color base = {84, 84, 84, 255}; if (be_control_look != NULL) { BRect empty = rect; if (fHasBattery && percent > 0) empty.left += empty.Width() * percent / 100.0; be_control_look->DrawButtonBackground(this, empty, empty, base, fHasBattery ? BControlLook::B_ACTIVATED : BControlLook::B_DISABLED, fHasBattery && percent > 0 ? (BControlLook::B_ALL_BORDERS & ~BControlLook::B_LEFT_BORDER) : BControlLook::B_ALL_BORDERS); } if (fHasBattery) { if (percent <= 15) base.set_to(180, 0, 0); else base.set_to(20, 180, 0); rect.right = rect.left + rect.Width() * percent / 100.0; if (be_control_look != NULL) { be_control_look->DrawButtonBackground(this, rect, rect, base, fHasBattery ? 0 : BControlLook::B_DISABLED); } else FillRect(rect); } } SetHighColor(0, 0, 0); }
void NotificationView::Draw(BRect updateRect) { BRect progRect; // Draw progress background if (fType == B_PROGRESS_NOTIFICATION) { PushState(); font_height fh; be_plain_font->GetHeight(&fh); float fontHeight = fh.ascent + fh.descent + fh.leading; progRect = Bounds(); progRect.InsetBy(kEdgePadding, kEdgePadding); progRect.top = progRect.bottom - (kSmallPadding * 2) - fontHeight; StrokeRect(progRect); BRect barRect = progRect; barRect.InsetBy(1.0, 1.0); barRect.right *= fProgress; SetHighColor(ui_color(B_CONTROL_HIGHLIGHT_COLOR)); FillRect(barRect); SetHighColor(ui_color(B_PANEL_TEXT_COLOR)); BString label = ""; label << (int)(fProgress * 100) << " %"; float labelWidth = be_plain_font->StringWidth(label.String()); float labelX = progRect.left + (progRect.IntegerWidth() / 2) - (labelWidth / 2); SetLowColor(B_TRANSPARENT_COLOR); SetDrawingMode(B_OP_ALPHA); DrawString(label.String(), label.Length(), BPoint(labelX, progRect.top + fh.ascent + fh.leading + kSmallPadding)); PopState(); } SetDrawingMode(B_OP_ALPHA); SetBlendingMode(B_PIXEL_ALPHA, B_ALPHA_OVERLAY); // Icon size float iconSize = (float)fParent->IconSize(); // Rectangle for icon and overlay icon BRect iconRect(0, 0, 0, 0); // Draw icon if (fBitmap) { LineInfo* appLine = fLines.back(); font_height fh; appLine->font.GetHeight(&fh); float title_bottom = appLine->location.y + fh.descent; float ix = kEdgePadding; float iy = 0; if (fParent->Layout() == TitleAboveIcon) iy = title_bottom + kEdgePadding + (Bounds().Height() - title_bottom - kEdgePadding * 2 - iconSize) / 2; else iy = (Bounds().Height() - iconSize) / 2.0; if (fType == B_PROGRESS_NOTIFICATION) // Move icon up by half progress bar height if it's present iy -= (progRect.Height() + kEdgePadding) / 2.0; iconRect.left = ix; iconRect.top = iy; iconRect.right = ix + iconSize; iconRect.bottom = iy + iconSize; DrawBitmapAsync(fBitmap, fBitmap->Bounds(), iconRect, B_FILTER_BITMAP_BILINEAR); } // Draw content LineInfoList::iterator lIt; for (lIt = fLines.begin(); lIt != fLines.end(); lIt++) { LineInfo *l = (*lIt); SetFont(&l->font); DrawString(l->text.String(), l->text.Length(), l->location); } rgb_color detailCol = ui_color(B_CONTROL_BORDER_COLOR); detailCol = tint_color(detailCol, B_LIGHTEN_2_TINT); // Draw the close widget BRect closeRect = Bounds(); closeRect.InsetBy(kEdgePadding, kEdgePadding); closeRect.left = closeRect.right - kCloseSize; closeRect.bottom = closeRect.top + kCloseSize; PushState(); SetHighColor(detailCol); StrokeRoundRect(closeRect, kSmallPadding, kSmallPadding); BRect closeCross = closeRect.InsetByCopy(kSmallPadding, kSmallPadding); StrokeLine(closeCross.LeftTop(), closeCross.RightBottom()); StrokeLine(closeCross.LeftBottom(), closeCross.RightTop()); PopState(); Sync(); }
void MacDecorator::_DrawFrame(BRect invalid) { if (fLook == B_NO_BORDER_WINDOW_LOOK) return; if (fBorderWidth <= 0) return; BRect r = fBorderRect; switch (fLook) { case B_TITLED_WINDOW_LOOK: case B_DOCUMENT_WINDOW_LOOK: case B_MODAL_WINDOW_LOOK: { if (IsFocus()) { BPoint offset = r.LeftTop(); BPoint pt2 = r.LeftBottom(); // Draw the left side of the frame fDrawingEngine->StrokeLine(offset,pt2,frame_lowercol); offset.x++; pt2.x++; pt2.y--; fDrawingEngine->StrokeLine(offset,pt2,frame_highcol); offset.x++; pt2.x++; pt2.y--; fDrawingEngine->StrokeLine(offset,pt2,frame_midcol); offset.x++; pt2.x++; fDrawingEngine->StrokeLine(offset,pt2,frame_midcol); offset.x++; pt2.x++; pt2.y--; fDrawingEngine->StrokeLine(offset,pt2,frame_lowcol); offset.x++; offset.y+=2; BPoint topleftpt=offset; pt2.x++; pt2.y--; fDrawingEngine->StrokeLine(offset,pt2,frame_lowercol); offset=r.RightTop(); pt2=r.RightBottom(); // Draw the right side of the frame fDrawingEngine->StrokeLine(offset,pt2,frame_lowercol); offset.x--; pt2.x--; fDrawingEngine->StrokeLine(offset,pt2,frame_lowcol); offset.x--; pt2.x--; fDrawingEngine->StrokeLine(offset,pt2,frame_midcol); offset.x--; pt2.x--; fDrawingEngine->StrokeLine(offset,pt2,frame_midcol); offset.x--; pt2.x--; fDrawingEngine->StrokeLine(offset,pt2,frame_highcol); offset.x--; offset.y+=2; BPoint toprightpt=offset; pt2.x--; fDrawingEngine->StrokeLine(offset,pt2,frame_lowercol); // Draw the top side of the frame that is not in the tab offset=r.RightTop(); pt2=r.RightBottom(); fDrawingEngine->StrokeLine(topleftpt,toprightpt,frame_lowercol); topleftpt.y--; toprightpt.x++; toprightpt.y--; fDrawingEngine->StrokeLine(topleftpt,toprightpt,frame_lowcol); offset=r.LeftBottom(); pt2=r.RightBottom(); // Draw the bottom side of the frame fDrawingEngine->StrokeLine(offset,pt2,frame_lowercol); offset.x++; offset.y--; pt2.x--; pt2.y--; fDrawingEngine->StrokeLine(offset,pt2,frame_lowcol); offset.x++; offset.y--; pt2.x--; pt2.y--; fDrawingEngine->StrokeLine(offset,pt2,frame_midcol); offset.x++; offset.y--; pt2.x--; pt2.y--; fDrawingEngine->StrokeLine(offset,pt2,frame_midcol); offset.x++; offset.y--; pt2.x--; pt2.y--; fDrawingEngine->StrokeLine(offset,pt2,frame_highcol); offset.x+=2; offset.y--; pt2.x--; pt2.y--; fDrawingEngine->StrokeLine(offset,pt2,frame_lowercol); offset.y--; pt2.x--; pt2.y--; } else { fDrawingEngine->StrokeLine(r.LeftTop(), r.LeftBottom(), frame_lowcol); fDrawingEngine->StrokeLine(r.RightTop(), r.RightBottom(), frame_lowcol); fDrawingEngine->StrokeLine(r.LeftBottom(), r.RightBottom(), frame_lowcol); for (int i = 0; i < 4; i++) { r.InsetBy(1, 1); fDrawingEngine->StrokeLine(r.LeftTop(), r.LeftBottom(), frame_midcol); fDrawingEngine->StrokeLine(r.RightTop(), r.RightBottom(), frame_midcol); fDrawingEngine->StrokeLine(r.LeftBottom(), r.RightBottom(), frame_midcol); } r.InsetBy(1, 1); fDrawingEngine->StrokeLine(r.LeftTop(), r.LeftBottom(), frame_lowcol); fDrawingEngine->StrokeLine(r.RightTop(), r.RightBottom(), frame_lowcol); fDrawingEngine->StrokeLine(r.LeftBottom(), r.RightBottom(), frame_lowcol); } break; } case B_BORDERED_WINDOW_LOOK: fDrawingEngine->StrokeRect(r, frame_midcol); break; default: // don't draw a border frame break; } }
PPPStatusView::PPPStatusView(BRect rect, ppp_interface_id id) : BView(rect, "PPPStatusView", B_FOLLOW_NONE, B_PULSE_NEEDED), fInterface(id) { SetViewUIColor(B_PANEL_BACKGROUND_COLOR); rect = Bounds(); rect.InsetBy(5, 5); rect.left = rect.right - 80; rect.bottom = rect.top + 25; fButton = new BButton(rect, "DisconnectButton", kLabelDisconnect, new BMessage(kMsgDisconnect)); rect.right = rect.left - 10; rect.left = rect.right - 80; rect.top += 5; rect.bottom = rect.top + 15; fTime = new BStringView(rect, "Time", ""); fTime->SetAlignment(B_ALIGN_RIGHT); fTime->SetFont(be_fixed_font); rect.right = rect.left - 10; rect.left = 5; BStringView *connectedSince = new BStringView(rect, "ConnectedSince", kLabelConnectedSince); connectedSince->SetFont(be_fixed_font); rect = Bounds(); rect.InsetBy(5, 5); rect.top += 35; rect.right = rect.left + (rect.Width() - 5) / 2; BBox *received = new BBox(rect, "Received"); received->SetLabel(kLabelReceived); rect = received->Bounds(); rect.InsetBy(10, 15); rect.bottom = rect.top + 15; fBytesReceived = new BStringView(rect, "BytesReceived", ""); fBytesReceived->SetAlignment(B_ALIGN_RIGHT); fBytesReceived->SetFont(be_fixed_font); rect.top = rect.bottom + 5; rect.bottom = rect.top + 15; fPacketsReceived = new BStringView(rect, "PacketsReceived", ""); fPacketsReceived->SetAlignment(B_ALIGN_RIGHT); fPacketsReceived->SetFont(be_fixed_font); rect = received->Frame(); rect.OffsetBy(rect.Width() + 5, 0); BBox *sent = new BBox(rect, "sent"); sent->SetLabel(kLabelSent); rect = received->Bounds(); rect.InsetBy(10, 15); rect.bottom = rect.top + 15; fBytesSent = new BStringView(rect, "BytesSent", ""); fBytesSent->SetAlignment(B_ALIGN_RIGHT); fBytesSent->SetFont(be_fixed_font); rect.top = rect.bottom + 5; rect.bottom = rect.top + 15; fPacketsSent = new BStringView(rect, "PacketsSent", ""); fPacketsSent->SetAlignment(B_ALIGN_RIGHT); fPacketsSent->SetFont(be_fixed_font); received->AddChild(fBytesReceived); received->AddChild(fPacketsReceived); sent->AddChild(fBytesSent); sent->AddChild(fPacketsSent); AddChild(fButton); AddChild(fTime); AddChild(connectedSince); AddChild(received); AddChild(sent); ppp_interface_info_t info; fInterface.GetInterfaceInfo(&info); fConnectedSince = info.info.connectedSince; }
ChatWindow::ChatWindow(entry_ref & ref) : BWindow( BRect(100,100,400,300), "unknown contact - unknown status", B_TITLED_WINDOW, B_ASYNCHRONOUS_CONTROLS | B_AVOID_FOCUS ), fEntry(ref), fMan( new IM::Manager(BMessenger(this))), fChangedNotActivated(false), fStatusBar(NULL), fSendButton(NULL), fProtocolHack(NULL) { bool command, sendButton; int32 iconBarSize; BMessage chatSettings; im_load_client_settings("im_emoclient", &chatSettings); if ( chatSettings.FindBool("command_sends", &command) != B_OK ) command = true; if ( chatSettings.FindBool("show_send_button", &sendButton) != B_OK ) sendButton = true; if ( chatSettings.FindInt32("icon_size", &iconBarSize) != B_OK ) iconBarSize = kLargeIcon; if ( iconBarSize <= 0 ) iconBarSize = kLargeIcon; if (chatSettings.FindString("people_handler", &fPeopleHandler) != B_OK) { fPeopleHandler = kDefaultPeopleHandler; }; if (chatSettings.FindString("other", &fOtherText) != B_OK ) { fOtherText.SetTo( "$name$ ($nickname$) ($protocol$) "); } // Set window size limits SetSizeLimits( 220, 8000, // width, 150, 8000 // height ); // get the size of various things font_height height; be_plain_font->GetHeight(&height); fFontHeight = height.ascent + height.descent + height.leading; // default window size BRect windowRect(100, 100, 400, 300); BPoint inputDivider(0, 150); // load window size if possible if (LoadSettings() == B_OK) { bool was_ok = true; if (fWindowSettings.FindRect("windowrect", &windowRect) != B_OK) { was_ok = false; } if (fWindowSettings.FindPoint("inputdivider", &inputDivider) != B_OK) { was_ok = false; } if ( !was_ok ) { windowRect = BRect(100, 100, 400, 300); inputDivider = BPoint(0, 200); } } // sanity check for divider location if ( inputDivider.y > windowRect.Height() - 50 ) { LOG("im_emoclient", liLow, "Insane divider, fixed."); inputDivider.y = windowRect.Height() - 50; }; // set size and position MoveTo(windowRect.left, windowRect.top); ResizeTo(windowRect.Width(), windowRect.Height()); // create views BRect textRect = Bounds(); BRect inputRect = Bounds(); BRect dockRect = Bounds(); dockRect.bottom = iconBarSize + kDockPadding; fDock = new IconBar(dockRect); #if B_BEOS_VERSION > B_BEOS_VERSION_5 fDock->SetViewUIColor(B_UI_PANEL_BACKGROUND_COLOR); fDock->SetLowUIColor(B_UI_PANEL_BACKGROUND_COLOR); fDock->SetHighUIColor(B_UI_PANEL_TEXT_COLOR); #else fDock->SetViewColor( ui_color(B_PANEL_BACKGROUND_COLOR) ); fDock->SetLowColor( ui_color(B_PANEL_BACKGROUND_COLOR) ); fDock->SetHighColor(0, 0, 0, 0); #endif AddChild(fDock); // add buttons ImageButton * btn; BBitmap * icon; // long err = 0; BPath iconDir; BPath iconPath; BRect buttonRect(0,0,iconBarSize+8,iconBarSize+8); find_directory(B_USER_SETTINGS_DIRECTORY, &iconDir, true); iconDir.Append("im_kit/icons"); // People Button icon = IconForHandler(fPeopleHandler.String(), iconBarSize); btn = MakeButton(icon, "Show contact in People", new BMessage(SHOW_INFO), buttonRect); fDock->AddItem(btn); // Email button icon = IconForHandler("text/x-email", iconBarSize); btn = MakeButton(icon, "Send email to contact", new BMessage(EMAIL), buttonRect); fDock->AddItem(btn); // Block Button iconPath = iconDir; iconPath.Append("Block"); icon = ReadNodeIcon(iconPath.Path(), iconBarSize, true); btn = MakeButton(icon, "Block messages from contact", new BMessage(BLOCK), buttonRect); fDock->AddItem(btn); // Log Button icon = IconForHandler("application/x-vnd.BeClan.im_binlog_viewer", iconBarSize); btn = MakeButton(icon, "View chat history for contact", new BMessage(VIEW_LOG), buttonRect); fDock->AddItem(btn); // Webpage Button icon = IconForHandler("text/html", iconBarSize); btn = MakeButton(icon, "View contact's web page", new BMessage(VIEW_WEBPAGE), buttonRect); fDock->AddItem(btn); // Emoticons iconPath = iconDir; iconPath.Append("emoticons"); icon = ReadNodeIcon(iconPath.Path(), iconBarSize); btn = MakeButton(icon, "Emoticons", new BMessage(VIEW_EMOTICONS), buttonRect); fDock->AddItem(btn); textRect.top = fDock->Bounds().bottom+1; textRect.InsetBy(2,2); textRect.bottom = inputDivider.y; textRect.right -= B_V_SCROLL_BAR_WIDTH; float sendButtonWidth = sendButton ? 50 : 0; inputRect.InsetBy(2.0, 2.0); inputRect.top = inputDivider.y + 7; inputRect.right -= B_V_SCROLL_BAR_WIDTH + sendButtonWidth; inputRect.bottom -= fFontHeight + (kPadding * 4); BRect inputTextRect = inputRect; inputTextRect.OffsetTo(kPadding, kPadding); inputTextRect.InsetBy(kPadding * 2, kPadding * 2); fInput = new BTextView(inputRect, "input", inputTextRect, B_FOLLOW_ALL, B_WILL_DRAW); #if B_BEOS_VERSION > B_BEOS_VERSION_5 fInput->SetViewUIColor(B_UI_DOCUMENT_BACKGROUND_COLOR); fInput->SetLowUIColor(B_UI_DOCUMENT_BACKGROUND_COLOR); fInput->SetHighUIColor(B_UI_DOCUMENT_TEXT_COLOR); #else fInput->SetViewColor(245, 245, 245, 0); fInput->SetLowColor(245, 245, 245, 0); fInput->SetHighColor(0, 0, 0, 0); #endif fInputScroll = new BScrollView( "input_scroller", fInput, B_FOLLOW_LEFT_RIGHT | B_FOLLOW_BOTTOM, 0, false, true, B_PLAIN_BORDER ); AddChild(fInputScroll); fInput->SetWordWrap(true); fInput->SetStylable(false); fInput->MakeSelectable(true); if ( sendButton ) { BRect sendRect = fInputScroll->Frame(); sendRect.left = sendRect.right+1; sendRect.right = Bounds().right; fSendButton = new BButton( sendRect, "sendButton", _T("Send"), new BMessage(SEND_MESSAGE), B_FOLLOW_RIGHT|B_FOLLOW_BOTTOM ); AddChild( fSendButton ); } BRect statusRect = Bounds(); statusRect.top = inputRect.bottom + kPadding; fStatusBar = new StatusBar(statusRect); AddChild(fStatusBar); #if B_BEOS_VERSION > B_BEOS_VERSION_5 fStatusBar->SetViewUIColor(B_UI_PANEL_BACKGROUND_COLOR); fStatusBar->SetLowUIColor(B_UI_PANEL_BACKGROUND_COLOR); fStatusBar->SetHighUIColor(B_UI_PANEL_TEXT_COLOR); #else fStatusBar->SetViewColor(245, 245, 245, 0); fStatusBar->SetLowColor(245, 245, 245, 0); fStatusBar->SetHighColor(0, 0, 0, 0); #endif BPopUpMenu *pop = new BPopUpMenu("Protocols", true, true); fProtocolMenu = new BMenuField( BRect(kPadding, kPadding, Bounds().bottom - kPadding, 100), "Field", NULL, pop); fStatusBar->AddItem(fProtocolMenu); // fInfoView must be the LAST thing added to fStatusBar, otherwise the // resizing of it will be all bonkers. fInfoView = new BStringView(BRect(fProtocolMenu->Frame().right+5, 2, fStatusBar->Bounds().right - kPadding, fStatusBar->Bounds().bottom - kPadding), "infoView", "", B_FOLLOW_LEFT_RIGHT | B_FOLLOW_BOTTOM, B_WILL_DRAW); fStatusBar->AddItem(fInfoView); #if B_BEOS_VERSION > B_BEOS_VERSION_5 fInfoView->SetViewUIColor(B_UI_PANEL_BACKGROUND_COLOR); fInfoView->SetLowUIColor(B_UI_PANEL_BACKGROUND_COLOR); fInfoView->SetHighUIColor(B_UI_PANEL_TEXT_COLOR); #else fInfoView->SetViewColor(245, 245, 245, 0); fInfoView->SetLowColor(245, 245, 245, 0); fInfoView->SetHighColor(0, 0, 0, 0); #endif // need to build the menu here since it fiddles with fInfoView BuildProtocolMenu(); BMenuItem *first = pop->ItemAt(0); if (first) first->SetMarked(true); BRect resizeRect = Bounds(); resizeRect.top = inputDivider.y + 1; resizeRect.bottom = inputDivider.y + 4; fResize = new ResizeView(fInputScroll, resizeRect, "resizer", B_FOLLOW_BOTTOM | B_FOLLOW_LEFT_RIGHT); AddChild(fResize); Theme::TimestampFore = C_TIMESTAMP_DUMMY; Theme::TimestampBack = C_TIMESTAMP_DUMMY; Theme::TimespaceFore = MAX_COLORS; Theme::TimespaceBack = MAX_COLORS; Theme::TimespaceFont = MAX_FONTS; Theme::TimestampFont = F_TIMESTAMP_DUMMY; Theme::NormalFore = C_TEXT; Theme::NormalBack = C_TEXT; Theme::NormalFont = F_TEXT; Theme::SelectionBack = C_SELECTION; fTheme = new Theme("ChatWindow", MAX_COLORS + 1, MAX_COLORS + 1, MAX_FONTS + 1); //NormalTextRender *ntr=new NormalTextRender(be_plain_font); fTheme->WriteLock(); fTheme->SetForeground(C_URL, 5, 5, 150); fTheme->SetBackground(C_URL, 255, 255, 255); //fTheme->SetTextRender(C_URL, ntr); fTheme->SetForeground(C_TIMESTAMP, 130, 130, 130); fTheme->SetBackground(C_TIMESTAMP, 255, 255, 255); //fTheme->SetTextRender(F_TIMESTAMP, ntr); fTheme->SetForeground(C_TEXT, 0, 0, 0); fTheme->SetBackground(C_TEXT, 255, 255, 255); //fTheme->SetTextRender(F_TEXT, ntr); fTheme->SetForeground(C_ACTION, 0, 0, 0); fTheme->SetBackground(C_ACTION, 255, 255, 255); //fTheme->SetTextRender(F_ACTION, ntr); fTheme->SetForeground(C_SELECTION, 255, 255, 255); fTheme->SetBackground(C_SELECTION, 0, 0, 0); fTheme->SetForeground(C_OWNNICK, 0, 0, 255); fTheme->SetBackground(C_OWNNICK, 255, 255, 255); fTheme->SetForeground(C_OTHERNICK, 255, 0, 0); fTheme->SetBackground(C_OTHERNICK, 255, 255, 255); //SmileTextRender *str=new SmileTextRender(); fTheme->SetTextRender(F_EMOTICON,&str); fTheme->WriteUnlock(); // IM::Contact con(&fEntry); // char id[256]; // con.ConnectionAt(0, id); fText = ((ChatApp *)be_app)->GetRunView(/*id*/ fEntry); if (fText == NULL) { fText = new RunView( textRect, "text", fTheme, B_FOLLOW_ALL, B_WILL_DRAW ); #if B_BEOS_VERSION > B_BEOS_VERSION_5 fText->SetViewUIColor(B_UI_DOCUMENT_BACKGROUND_COLOR); fText->SetLowUIColor(B_UI_DOCUMENT_BACKGROUND_COLOR); fText->SetHighUIColor(B_UI_DOCUMENT_TEXT_COLOR); #else fText->SetViewColor(245, 245, 245, 0); fText->SetLowColor(245, 245, 245, 0); fText->SetHighColor(0, 0, 0, 0); #endif fText->SetTimeStampFormat(NULL); }; fTextScroll = new BScrollView( "scroller", fText, B_FOLLOW_ALL, 0, false, // horiz true, // vert B_PLAIN_BORDER ); AddChild(fTextScroll); fTextScroll->MoveTo(0,fDock->Bounds().bottom+1); if ( fText->IsHidden() ) fText->Show(); fText->ScrollToBottom(); fInput->MakeFocus(); // add input filter that generates "user typing" messages and routes copy-commands fFilter = new InputFilter(fInput, new BMessage(SEND_MESSAGE), command, fText, kTypingSendRate); fInput->AddFilter((BMessageFilter *)fFilter); // monitor node so we get updates to status etc BEntry entry(&ref); node_ref node; entry.GetNodeRef(&node); watch_node( &node, B_WATCH_ALL, BMessenger(this) ); // get contact info reloadContact(); // set up timer for clearing typing view fTypingTimer = NULL; fTypingTimerSelf = NULL; // this message runner needed to fix a BMenuField bug. BMessage protoHack(PROTOCOL_SELECTED2); fProtocolHack = new BMessageRunner( BMessenger(this), &protoHack, 10000, 1 ); }
BView * DefaultMediaTheme::MakeViewFor(BParameterWeb *web, const BRect *hintRect) { CALLED(); if (web == NULL) return NULL; BRect rect; if (hintRect) rect = *hintRect; BRect bestRect; // do we have more than one attached parameter group? // if so, use a tabbed view with a tab for each group TabView *tabView = NULL; if (web->CountGroups() > 1) tabView = new TabView(rect, "web"); rect.OffsetTo(B_ORIGIN); for (int32 i = 0; i < web->CountGroups(); i++) { BParameterGroup *group = web->GroupAt(i); if (group == NULL) continue; BView *groupView = MakeViewFor(*group, hintRect ? &rect : NULL); if (groupView == NULL) continue; if (GroupView *view = dynamic_cast<GroupView *>(groupView)) { // the top-level group views must not be larger than their hintRect, // but unlike their children, they should follow all sides when // their parent is resized if (hintRect != NULL) view->ResizeTo(rect.Width() - 10, rect.Height() - 10); view->SetResizingMode(B_FOLLOW_ALL); } if (tabView == NULL) { // if we don't need a container to put that view into, // we're done here (but the groupView may span over the // whole hintRect) if (groupView->Frame().LeftTop() == BPoint(5, 5)) { // remove insets, as they are not needed groupView->MoveBy(-5, -5); groupView->ResizeBy(10, 10); } return new DynamicScrollView(groupView->Name(), groupView); } DynamicScrollView *scrollView = new DynamicScrollView(groupView->Name(), groupView); tabView->AddTab(scrollView); if (!hintRect) { bestRect = bestRect | scrollView->Bounds(); } } if (tabView != NULL) { // this adjustment must be kept in sync with TabView::FrameResized bestRect.bottom += tabView->TabHeight(); bestRect.InsetBy(-3.0,-3.0); tabView->ResizeTo(bestRect.Width(), bestRect.Height()); tabView->FrameResized(bestRect.Width(), bestRect.Height()); //needed since we're not attached to a window yet } return tabView; }
// Draw void AlphaSlider::Draw(BRect updateRect) { BRect b = _BitmapRect(); b.InsetBy(-2.0, -2.0); bool isFocus = IsFocus() && Window()->IsActive(); rgb_color bg = LowColor(); rgb_color shadow; rgb_color darkShadow; rgb_color light; rgb_color black; if (IsEnabled()) { shadow = tint_color(bg, B_DARKEN_1_TINT); darkShadow = tint_color(bg, B_DARKEN_3_TINT); light = tint_color(bg, B_LIGHTEN_MAX_TINT); black = tint_color(bg, B_DARKEN_MAX_TINT); } else { shadow = bg; darkShadow = tint_color(bg, B_DARKEN_1_TINT); light = tint_color(bg, B_LIGHTEN_2_TINT); black = tint_color(bg, B_DARKEN_2_TINT); } rgb_color focus = isFocus ? ui_color(B_KEYBOARD_NAVIGATION_COLOR) : black; stroke_frame(this, b, shadow, shadow, light, light); b.InsetBy(1.0, 1.0); if (isFocus) stroke_frame(this, b, focus, focus, focus, focus); else stroke_frame(this, b, darkShadow, darkShadow, bg, bg); b.InsetBy(1.0, 1.0); DrawBitmap(fBitmap, b.LeftTop()); // value marker if (fOrientation == B_HORIZONTAL) { float pos = floorf(b.left + Value() * b.Width() / 255.0 + 0.5); if (pos - 2 >= b.left) { SetHighColor(kWhite); StrokeLine(BPoint(pos - 2, b.top), BPoint(pos - 2, b.bottom)); } if (pos - 1 >= b.left) { SetHighColor(kBlack); StrokeLine(BPoint(pos - 1, b.top), BPoint(pos - 1, b.bottom)); } if (pos + 1 <= b.right) { SetHighColor(kBlack); StrokeLine(BPoint(pos + 1, b.top), BPoint(pos + 1, b.bottom)); } if (pos + 2 <= b.right) { SetHighColor(kWhite); StrokeLine(BPoint(pos + 2, b.top), BPoint(pos + 2, b.bottom)); } } else { float pos = floorf(b.top + Value() * b.Height() / 255.0 + 0.5); if (pos - 2 >= b.top) { SetHighColor(kWhite); StrokeLine(BPoint(b.left, pos - 2), BPoint(b.right, pos - 2)); } if (pos - 1 >= b.top) { SetHighColor(kBlack); StrokeLine(BPoint(b.left, pos - 1), BPoint(b.right, pos - 1)); } if (pos + 1 <= b.bottom) { SetHighColor(kBlack); StrokeLine(BPoint(b.left, pos + 1), BPoint(b.right, pos + 1)); } if (pos + 2 <= b.bottom) { SetHighColor(kWhite); StrokeLine(BPoint(b.left, pos + 2), BPoint(b.right, pos + 2)); } } }
void WorkspacesView::MouseMoved(BMessage* message, BPoint where) { if (fSelectedWindow == NULL && fSelectedWorkspace < 0) return; // check if the correct mouse button is pressed int32 buttons; if (message->FindInt32("buttons", &buttons) != B_OK || (buttons & B_PRIMARY_MOUSE_BUTTON) == 0) return; if (!fHasMoved) { Window()->Desktop()->SetMouseEventWindow(Window()); // don't let us off the mouse } int32 index; BRect workspaceFrame = _WorkspaceAt(where, index); if (fSelectedWindow == NULL) { if (fSelectedWorkspace >= 0 && fSelectedWorkspace != index) { fSelectedWorkspace = index; _Invalidate(); } return; } workspaceFrame.InsetBy(1, 1); if (index != fSelectedWorkspace) { if (fSelectedWindow->IsNormal() && !fSelectedWindow->InWorkspace(index)) { // move window to this new workspace uint32 newWorkspaces = (fSelectedWindow->Workspaces() & ~(1UL << fSelectedWorkspace)) | (1UL << index); Window()->Desktop()->SetWindowWorkspaces(fSelectedWindow, newWorkspaces); } fSelectedWorkspace = index; } BRect screenFrame = _ScreenFrame(index); float left = rintf((where.x - workspaceFrame.left - fLeftTopOffset.x) * screenFrame.Width() / workspaceFrame.Width()); float top = rintf((where.y - workspaceFrame.top - fLeftTopOffset.y) * screenFrame.Height() / workspaceFrame.Height()); BPoint leftTop; if (fSelectedWorkspace == Window()->Desktop()->CurrentWorkspace()) leftTop = fSelectedWindow->Frame().LeftTop(); else { if (fSelectedWindow->Anchor(fSelectedWorkspace).position == kInvalidWindowPosition) { fSelectedWindow->Anchor(fSelectedWorkspace).position = fSelectedWindow->Frame().LeftTop(); } leftTop = fSelectedWindow->Anchor(fSelectedWorkspace).position; } // Don't treat every little mouse move as a window move - this would // make it too hard to activate a workspace. float diff = max_c(fabs(fClickPoint.x - where.x), fabs(fClickPoint.y - where.y)); if (!fHasMoved && diff > 2) fHasMoved = true; if (fHasMoved) { Window()->Desktop()->MoveWindowBy(fSelectedWindow, left - leftTop.x, top - leftTop.y, fSelectedWorkspace); } }
PoorManPreferencesWindow::PoorManPreferencesWindow(BRect frame, char * name) : BWindow(frame, name, B_TITLED_WINDOW, B_NOT_ZOOMABLE | B_NOT_RESIZABLE | B_CLOSE_ON_ESCAPE), webDirFilePanel(NULL), logFilePanel(NULL) { frame = Bounds(); prefView = new PoorManView(frame, STR_WIN_NAME_PREF); //prefView->SetViewColor(216,216,216,255); prefView->SetViewColor(BACKGROUND_COLOR); AddChild(prefView); // Button View BRect buttonRect; buttonRect = Bounds(); buttonRect.top = buttonRect.bottom - 30; buttonView = new PoorManView(buttonRect, "Button View"); buttonView->SetViewColor(BACKGROUND_COLOR); prefView->AddChild(buttonView); // Buttons float buttonTop = 0.0f; float buttonHeight = 26.0f; float widthCancel = prefView->StringWidth(B_TRANSLATE("Cancel")) + 24.0f; float widthDone = prefView->StringWidth(B_TRANSLATE("Done")) + 24.0f; float gap = 5.0f; BRect button1(prefView->Bounds().Width() - 2 * gap - widthCancel - widthDone, buttonTop, prefView->Bounds().Width() - 2 * gap - widthDone, buttonTop + buttonHeight); cancelButton = new BButton(button1, "Cancel Button", B_TRANSLATE("Cancel"), new BMessage(MSG_PREF_BTN_CANCEL)); BRect button2(prefView->Bounds().Width() - gap - widthDone, buttonTop, prefView->Bounds().Width() - gap, buttonTop + buttonHeight); doneButton = new BButton(button2, "Done Button", B_TRANSLATE("Done"), new BMessage(MSG_PREF_BTN_DONE)); buttonView->AddChild(cancelButton); buttonView->AddChild(doneButton); // Create tabs BRect r; r = Bounds(); //r.InsetBy(5, 5); r.top += 8.0; r.bottom -= 38.0; prefTabView = new BTabView(r, "Pref Tab View"); prefTabView->SetViewColor(BACKGROUND_COLOR); r = prefTabView->Bounds(); r.InsetBy(5, 5); r.bottom -= prefTabView->TabHeight(); // Site Tab siteTab = new BTab(); siteView = new PoorManSiteView(r, "Site View"); prefTabView->AddTab(siteView, siteTab); siteTab->SetLabel(STR_TAB_SITE); // Logging Tab loggingTab = new BTab(); loggingView = new PoorManLoggingView(r, "Logging View"); prefTabView->AddTab(loggingView, loggingTab); loggingTab->SetLabel(STR_TAB_LOGGING); // Advanced Tab advancedTab = new BTab(); advancedView = new PoorManAdvancedView(r, "Advanced View"); prefTabView->AddTab(advancedView, advancedTab); advancedTab->SetLabel(STR_TAB_ADVANCED); prefView->AddChild(prefTabView); // FilePanels BWindow * change_title; BMessenger messenger(this); BMessage message(MSG_FILE_PANEL_SELECT_WEB_DIR); webDirFilePanel = new BFilePanel(B_OPEN_PANEL, &messenger, NULL, B_DIRECTORY_NODE, false, &message, NULL, true); webDirFilePanel->SetPanelDirectory(new BDirectory("/boot/home/public_html")); webDirFilePanel->SetButtonLabel(B_DEFAULT_BUTTON, B_TRANSLATE("Select")); change_title = webDirFilePanel->Window(); change_title->SetTitle(STR_FILEPANEL_SELECT_WEB_DIR); message.what = MSG_FILE_PANEL_CREATE_LOG_FILE; logFilePanel = new BFilePanel(B_SAVE_PANEL, &messenger, NULL, B_FILE_NODE, false, &message); logFilePanel->SetButtonLabel(B_DEFAULT_BUTTON, B_TRANSLATE("Create")); change_title = logFilePanel->Window(); change_title->SetTitle(STR_FILEPANEL_CREATE_LOG_FILE); }
void WorkspacesView::MouseDown(BMessage* message, BPoint where) { // reset tracking variables fSelectedWorkspace = -1; fSelectedWindow = NULL; fHasMoved = false; // check if the correct mouse button is pressed int32 buttons; if (message->FindInt32("buttons", &buttons) != B_OK || (buttons & B_PRIMARY_MOUSE_BUTTON) == 0) return; int32 index; BRect workspaceFrame = _WorkspaceAt(where, index); if (index < 0) return; Workspace workspace(*Window()->Desktop(), index); workspaceFrame.InsetBy(1, 1); BRect screenFrame = _ScreenFrame(index); ::Window* window; BRect windowFrame; BPoint leftTop; while (workspace.GetPreviousWindow(window, leftTop) == B_OK) { BRect frame = _WindowFrame(workspaceFrame, screenFrame, window->Frame(), leftTop); if (frame.Contains(where) && window->Feel() != kDesktopWindowFeel && window->Feel() != kWindowScreenFeel) { fSelectedWindow = window; windowFrame = frame; break; } } // Some special functionality (clicked with modifiers) int32 modifiers; if (fSelectedWindow != NULL && message->FindInt32("modifiers", &modifiers) == B_OK) { if ((modifiers & B_CONTROL_KEY) != 0) { // Activate window if clicked with the control key pressed, // minimize it if control+shift - this mirrors Deskbar // shortcuts (when pressing a team menu item). if ((modifiers & B_SHIFT_KEY) != 0) fSelectedWindow->ServerWindow()->NotifyMinimize(true); else Window()->Desktop()->ActivateWindow(fSelectedWindow); fSelectedWindow = NULL; } else if ((modifiers & B_OPTION_KEY) != 0) { // Also, send window to back if clicked with the option // key pressed. Window()->Desktop()->SendWindowBehind(fSelectedWindow); fSelectedWindow = NULL; } } // If this window is movable, we keep it selected // (we prevent our own window from being moved, too) if ((fSelectedWindow != NULL && (fSelectedWindow->Flags() & B_NOT_MOVABLE) != 0) || fSelectedWindow == Window()) { fSelectedWindow = NULL; } fLeftTopOffset = where - windowFrame.LeftTop(); fSelectedWorkspace = index; fClickPoint = where; if (index >= 0) _Invalidate(); }
ExtensionWindow::ExtensionWindow(FileTypesWindow* target, BMimeType& type, const char* extension) : BWindow(BRect(100, 100, 350, 200), "Extension", B_MODAL_WINDOW_LOOK, B_MODAL_SUBSET_WINDOW_FEEL, B_NOT_ZOOMABLE | B_NOT_V_RESIZABLE | B_ASYNCHRONOUS_CONTROLS), fTarget(target), fMimeType(type.Type()), fExtension(extension) { BRect rect = Bounds(); BView* topView = new BView(rect, NULL, B_FOLLOW_ALL, B_WILL_DRAW); topView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); AddChild(topView); rect.InsetBy(8.0f, 8.0f); fExtensionControl = new BTextControl(rect, "extension", "Extension:", extension, NULL, B_FOLLOW_LEFT_RIGHT); float labelWidth = fExtensionControl->StringWidth(fExtensionControl->Label()) + 2.0f; fExtensionControl->SetModificationMessage(new BMessage(kMsgExtensionUpdated)); fExtensionControl->SetDivider(labelWidth); fExtensionControl->SetAlignment(B_ALIGN_RIGHT, B_ALIGN_LEFT); // filter out invalid characters that can't be part of an extension BTextView* textView = fExtensionControl->TextView(); const char* disallowedCharacters = "/:"; for (int32 i = 0; disallowedCharacters[i]; i++) { textView->DisallowChar(disallowedCharacters[i]); } float width, height; fExtensionControl->GetPreferredSize(&width, &height); fExtensionControl->ResizeTo(rect.Width(), height); topView->AddChild(fExtensionControl); fAcceptButton = new BButton(rect, "add", extension ? "Done" : "Add", new BMessage(kMsgAccept), B_FOLLOW_RIGHT | B_FOLLOW_BOTTOM); fAcceptButton->ResizeToPreferred(); fAcceptButton->MoveTo(Bounds().Width() - 8.0f - fAcceptButton->Bounds().Width(), Bounds().Height() - 8.0f - fAcceptButton->Bounds().Height()); fAcceptButton->SetEnabled(false); topView->AddChild(fAcceptButton); BButton* button = new BButton(rect, "cancel", "Cancel", new BMessage(B_QUIT_REQUESTED), B_FOLLOW_RIGHT | B_FOLLOW_BOTTOM); button->ResizeToPreferred(); button->MoveTo(fAcceptButton->Frame().left - 10.0f - button->Bounds().Width(), fAcceptButton->Frame().top); topView->AddChild(button); ResizeTo(labelWidth * 4.0f + 24.0f, fExtensionControl->Bounds().Height() + fAcceptButton->Bounds().Height() + 28.0f); SetSizeLimits(button->Bounds().Width() + fAcceptButton->Bounds().Width() + 26.0f, 32767.0f, Frame().Height(), Frame().Height()); // omit the leading dot if (fExtension.ByteAt(0) == '.') fExtension.Remove(0, 1); fAcceptButton->MakeDefault(true); fExtensionControl->MakeFocus(true); target->PlaceSubWindow(this); AddToSubset(target); }
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)); } } }
void KernelMemoryBarMenuItem::DrawBar(bool force) { bool selected = IsSelected(); BRect frame = Frame(); BMenu* menu = Menu(); // draw the bar itself BRect cadre (frame.right - kMargin - kBarWidth, frame.top + 5, frame.right - kMargin, frame.top + 13); if (fLastSum < 0) force = true; if (force) { if (selected) menu->SetHighColor(gFrameColorSelected); else menu->SetHighColor(gFrameColor); menu->StrokeRect (cadre); } cadre.InsetBy(1, 1); BRect r = cadre; float grenze1 = cadre.left + (cadre.right - cadre.left) * fCachedMemory / fPhysicalMemory; float grenze2 = cadre.left + (cadre.right - cadre.left) * fCommittedMemory / fPhysicalMemory; if (grenze1 > cadre.right) grenze1 = cadre.right; if (grenze2 > cadre.right) grenze2 = cadre.right; r.right = grenze1; if (!force) r.left = fGrenze1; if (r.left < r.right) { if (selected) menu->SetHighColor(gKernelColorSelected); else menu->SetHighColor(gKernelColor); // menu->SetHighColor(gKernelColor); menu->FillRect (r); } r.left = grenze1; r.right = grenze2; if (!force) { if (fGrenze2 > r.left && r.left >= fGrenze1) r.left = fGrenze2; if (fGrenze1 < r.right && r.right <= fGrenze2) r.right = fGrenze1; } if (r.left < r.right) { if (selected) menu->SetHighColor(tint_color (kLavender, B_HIGHLIGHT_BACKGROUND_TINT)); else menu->SetHighColor(kLavender); // menu->SetHighColor(gUserColor); menu->FillRect (r); } r.left = grenze2; r.right = cadre.right; if (!force) r.right = fGrenze2; if (r.left < r.right) { if (selected) menu->SetHighColor(gWhiteSelected); else menu->SetHighColor(kWhite); menu->FillRect(r); } menu->SetHighColor(kBlack); fGrenze1 = grenze1; fGrenze2 = grenze2; // draw the value double sum = fCachedMemory * FLT_MAX + fCommittedMemory; if (force || sum != fLastSum) { if (selected) { menu->SetLowColor(gMenuBackColorSelected); menu->SetHighColor(gMenuBackColorSelected); } else { menu->SetLowColor(gMenuBackColor); menu->SetHighColor(gMenuBackColor); } BRect trect(cadre.left - kMargin - gMemoryTextWidth, frame.top, cadre.left - kMargin, frame.bottom); menu->FillRect(trect); menu->SetHighColor(kBlack); char infos[128]; string_for_size(fCachedMemory * 1024.0, infos, sizeof(infos)); BPoint loc(cadre.left, cadre.bottom + 1); loc.x -= kMargin + gMemoryTextWidth / 2 + menu->StringWidth(infos); menu->DrawString(infos, loc); string_for_size(fCommittedMemory * 1024.0, infos, sizeof(infos)); loc.x = cadre.left - kMargin - menu->StringWidth(infos); menu->DrawString(infos, loc); fLastSum = sum; } }
void BTextControl::Draw(BRect updateRect) { bool enabled = IsEnabled(); bool active = fText->IsFocus() && Window()->IsActive(); BRect rect = fText->Frame(); rect.InsetBy(-2, -2); if (be_control_look != NULL) { rgb_color base = ui_color(B_PANEL_BACKGROUND_COLOR); uint32 flags = 0; if (!enabled) flags |= BControlLook::B_DISABLED; if (active) flags |= BControlLook::B_FOCUSED; be_control_look->DrawTextControlBorder(this, rect, updateRect, base, flags); rect = Bounds(); rect.right = fDivider - kLabelInputSpacing; // rect.right = fText->Frame().left - 2; // rect.right -= 3;//be_control_look->DefaultLabelSpacing(); be_control_look->DrawLabel(this, Label(), rect, updateRect, base, flags, BAlignment(fLabelAlign, B_ALIGN_MIDDLE)); return; } // outer bevel rgb_color noTint = ui_color(B_PANEL_BACKGROUND_COLOR); rgb_color lighten1 = tint_color(noTint, B_LIGHTEN_1_TINT); rgb_color lighten2 = tint_color(noTint, B_LIGHTEN_2_TINT); rgb_color lightenMax = tint_color(noTint, B_LIGHTEN_MAX_TINT); rgb_color darken1 = tint_color(noTint, B_DARKEN_1_TINT); rgb_color darken2 = tint_color(noTint, B_DARKEN_2_TINT); rgb_color darken4 = tint_color(noTint, B_DARKEN_4_TINT); rgb_color navigationColor = ui_color(B_KEYBOARD_NAVIGATION_COLOR); if (enabled) SetHighColor(darken1); else SetHighColor(noTint); StrokeLine(rect.LeftBottom(), rect.LeftTop()); StrokeLine(rect.RightTop()); if (enabled) SetHighColor(lighten2); else SetHighColor(lighten1); StrokeLine(BPoint(rect.left + 1.0f, rect.bottom), rect.RightBottom()); StrokeLine(BPoint(rect.right, rect.top + 1.0f), rect.RightBottom()); // inner bevel rect.InsetBy(1.0f, 1.0f); if (active) { SetHighColor(navigationColor); StrokeRect(rect); } else { if (enabled) SetHighColor(darken4); else SetHighColor(darken2); StrokeLine(rect.LeftTop(), rect.LeftBottom()); StrokeLine(rect.LeftTop(), rect.RightTop()); SetHighColor(noTint); StrokeLine(BPoint(rect.left + 1.0f, rect.bottom), rect.RightBottom()); StrokeLine(BPoint(rect.right, rect.top + 1.0f)); } // label if (Label()) { _ValidateLayoutData(); font_height& fontHeight = fLayoutData->font_info; float y = Bounds().top + (Bounds().Height() + 1 - fontHeight.ascent - fontHeight.descent) / 2 + fontHeight.ascent; float x; float labelWidth = StringWidth(Label()); switch (fLabelAlign) { case B_ALIGN_RIGHT: x = fDivider - labelWidth - kLabelInputSpacing; break; case B_ALIGN_CENTER: x = fDivider - labelWidth / 2.0; break; default: x = 0.0; break; } BRect labelArea(x, Bounds().top, x + labelWidth, Bounds().bottom); if (x < fDivider && updateRect.Intersects(labelArea)) { labelArea.right = fText->Frame().left - kLabelInputSpacing; BRegion clipRegion(labelArea); ConstrainClippingRegion(&clipRegion); SetHighColor(IsEnabled() ? ui_color(B_CONTROL_TEXT_COLOR) : tint_color(noTint, B_DISABLED_LABEL_TINT)); DrawString(Label(), BPoint(x, y)); } } }
// constructor NavigationInfoPanel::NavigationInfoPanel(BWindow* parent, const BMessage& message, const BMessenger& target) : BWindow(BRect(0, 0, 200, 30), "Navigation Info", B_FLOATING_WINDOW_LOOK, B_FLOATING_SUBSET_WINDOW_FEEL, B_ASYNCHRONOUS_CONTROLS | B_NOT_ZOOMABLE | B_NOT_V_RESIZABLE) , fMessage(message) , fTarget(target) { // create the interface and resize to fit BRect frame = Bounds(); frame.InsetBy(5, 5); frame.bottom = frame.top + 15; // label string view fLabelView = new BStringView(frame, "label", kLabel, B_FOLLOW_LEFT_RIGHT | B_FOLLOW_TOP); fLabelView->ResizeToPreferred(); frame = fLabelView->Frame(); // target clip text control frame.OffsetBy(0, frame.Height() + 5); fTargetClipTC = new BTextControl(frame, "clip id", "Target Playlist ID", "", new BMessage(MSG_INVOKE), B_FOLLOW_TOP | B_FOLLOW_LEFT_RIGHT); fTargetClipTC->ResizeToPreferred(); frame = fTargetClipTC->Frame(); // help string view frame.OffsetBy(0, frame.Height() + 5); BStringView* helpView = new BStringView(frame, "help", "Drag and drop a playlist clip here.", B_FOLLOW_LEFT_RIGHT | B_FOLLOW_TOP); BFont font; helpView->GetFont(&font); font.SetFace(B_ITALIC_FACE); font.SetSize(font.Size() * 0.9); helpView->SetFont(&font); helpView->SetAlignment(B_ALIGN_CENTER); helpView->ResizeToPreferred(); // parent view frame = fLabelView->Frame() | fTargetClipTC->Frame() | helpView->Frame(); frame.InsetBy(-5, -5); fInfoView = new InfoView(frame, this); fInfoView->AddChild(fLabelView); fInfoView->AddChild(fTargetClipTC); fInfoView->AddChild(helpView); // resize to fit and adjust size limits ResizeTo(fInfoView->Frame().Width(), fInfoView->Frame().Height()); AddChild(fInfoView); float minWidth, maxWidth, minHeight, maxHeight; GetSizeLimits(&minWidth, &maxWidth, &minHeight, &maxHeight); minWidth = Frame().Width(); minHeight = maxHeight = Frame().Height(); SetSizeLimits(minWidth, maxWidth, minHeight, maxHeight); // modify the high color after the help view is attached to a window helpView->SetHighColor(tint_color(helpView->LowColor(), B_DISABLED_LABEL_TINT)); helpView->SetFlags(helpView->Flags() | B_FULL_UPDATE_ON_RESIZE); // help the buggy BeOS BStringView (when text alignment != left...) fInfoView->SetEventMask(B_POINTER_EVENTS); // resize controls to the same (maximum) width float maxControlWidth = fLabelView->Frame().Width(); maxControlWidth = max_c(maxControlWidth, fTargetClipTC->Frame().Width()); maxControlWidth = max_c(maxControlWidth, helpView->Frame().Width()); fLabelView->ResizeTo(maxControlWidth, fLabelView->Frame().Height()); fTargetClipTC->ResizeTo(maxControlWidth, fTargetClipTC->Frame().Height()); helpView->ResizeTo(maxControlWidth, helpView->Frame().Height()); // center above parent window BAutolock _(parent); frame = Frame(); BRect parentFrame = parent->Frame(); MoveTo((parentFrame.left + parentFrame.right - frame.Width()) / 2, (parentFrame.top + parentFrame.bottom - frame.Height()) / 2); AddToSubset(parent); }
static void testFillRoundRect(BView *view, BRect frame) { frame.InsetBy(2, 2); view->FillRoundRect(frame, 5, 3); }
void SATGroup::_EnsureGroupIsOnScreen(SATGroup* group) { STRACE_SAT("SATGroup::_EnsureGroupIsOnScreen\n"); if (group == NULL || group->CountItems() < 1) return; SATWindow* window = group->WindowAt(0); Desktop* desktop = window->GetWindow()->Desktop(); if (desktop == NULL) return; const float kBigDistance = 1E+10; float minLeftDistance = kBigDistance; BRect leftRect; float minTopDistance = kBigDistance; BRect topRect; float minRightDistance = kBigDistance; BRect rightRect; float minBottomDistance = kBigDistance; BRect bottomRect; BRect screen = window->GetWindow()->Screen()->Frame(); BRect reducedScreen = screen; reducedScreen.InsetBy(kMinOverlap, kMinOverlap); for (int i = 0; i < group->CountItems(); i++) { SATWindow* window = group->WindowAt(i); BRect frame = window->CompleteWindowFrame(); if (reducedScreen.Intersects(frame)) return; if (frame.right < screen.left + kMinOverlap) { float dist = fabs(screen.left - frame.right); if (dist < minLeftDistance) { minLeftDistance = dist; leftRect = frame; } else if (dist == minLeftDistance) leftRect = leftRect | frame; } if (frame.top > screen.bottom - kMinOverlap) { float dist = fabs(frame.top - screen.bottom); if (dist < minBottomDistance) { minBottomDistance = dist; bottomRect = frame; } else if (dist == minBottomDistance) bottomRect = bottomRect | frame; } if (frame.left > screen.right - kMinOverlap) { float dist = fabs(frame.left - screen.right); if (dist < minRightDistance) { minRightDistance = dist; rightRect = frame; } else if (dist == minRightDistance) rightRect = rightRect | frame; } if (frame.bottom < screen.top + kMinOverlap) { float dist = fabs(frame.bottom - screen.top); if (dist < minTopDistance) { minTopDistance = dist; topRect = frame; } else if (dist == minTopDistance) topRect = topRect | frame; } } BPoint offset; if (minLeftDistance < kBigDistance) { offset.x = screen.left - leftRect.right + kMoveToScreen; _CallculateYOffset(offset, leftRect, screen); } else if (minTopDistance < kBigDistance) { offset.y = screen.top - topRect.bottom + kMoveToScreen; _CallculateXOffset(offset, topRect, screen); } else if (minRightDistance < kBigDistance) { offset.x = screen.right - rightRect.left - kMoveToScreen; _CallculateYOffset(offset, rightRect, screen); } else if (minBottomDistance < kBigDistance) { offset.y = screen.bottom - bottomRect.top - kMoveToScreen; _CallculateXOffset(offset, bottomRect, screen); } if (offset.x == 0. && offset.y == 0.) return; STRACE_SAT("move group back to screen: offset x: %f offset y: %f\n", offset.x, offset.y); desktop->MoveWindowBy(window->GetWindow(), offset.x, offset.y); window->DoGroupLayout(); }
static void testStrokeRoundRect(BView *view, BRect frame) { frame.InsetBy(2, 2); view->StrokeRoundRect(frame, 5, 3); }
void ThemeInterfaceView::AllAttached() { BView::AllAttached(); SetViewPanelBgColor(); fThemeManager = new ThemeManager; BRect frame = Bounds(); frame.InsetBy(10.0, 10.0); // add the theme listview BRect list_frame = frame; list_frame.right = 130; fThemeList = new BListView(list_frame.InsetByCopy(3.0, 3.0), "themelist"); fThemeListSV = new BScrollView("themelistsv", fThemeList, B_FOLLOW_LEFT|B_FOLLOW_TOP, 0, false, true); AddChild(fThemeListSV); fThemeList->SetSelectionMessage(new BMessage(kThemeSelected)); fThemeList->SetInvocationMessage(new BMessage(kApplyThemeBtn)); fThemeList->SetTarget(this); // buttons... fNewBtn = new BButton(BRect(), "create", B_TRANSLATE("New"), new BMessage(kCreateThemeBtn)); AddChild(fNewBtn); fNewBtn->SetTarget(this); fNewBtn->ResizeToPreferred(); fNewBtn->MoveTo(fThemeListSV->Frame().right + 15.0, frame.bottom - fNewBtn->Bounds().Height()); BPoint lt = fNewBtn->Frame().LeftTop(); fNameText = new BTextControl(BRect(), "text", "", "My Theme", new BMessage(kCreateThemeBtn)); AddChild(fNameText); fNameText->SetTarget(this); fNameText->ResizeToPreferred(); // default is a bit small fNameText->ResizeBy(fNameText->Bounds().Width(), 0); fNameText->MoveTo(lt); fNameText->MoveBy(0, (fNewBtn->Bounds().Height() - fNameText->Bounds().Height()) / 2); //fNameText->MoveBy(0, - fNewBtn->Bounds().Height()); fNameText->Hide(); lt.x = fNewBtn->Frame().right + 10.0; fSaveBtn = new BButton(BRect(), "save", B_TRANSLATE("Save"), new BMessage(kSaveThemeBtn)); AddChild(fSaveBtn); fSaveBtn->SetTarget(this); fSaveBtn->ResizeToPreferred(); fSaveBtn->MoveTo(lt); lt.x = fSaveBtn->Frame().right + 10.0; fDeleteBtn = new BButton(BRect(), "delete", B_TRANSLATE("Delete"), new BMessage(kDeleteThemeBtn)); AddChild(fDeleteBtn); fDeleteBtn->SetTarget(this); fDeleteBtn->ResizeToPreferred(); fDeleteBtn->MoveTo(lt); // buttons... fSetShotBtn = new BButton(BRect(), "makeshot", B_TRANSLATE("Add screenshot"), new BMessage(kMakeScreenshot), B_FOLLOW_RIGHT | B_FOLLOW_TOP); AddChild(fSetShotBtn); fSetShotBtn->SetTarget(this); fSetShotBtn->ResizeToPreferred(); fMoreThemesBtn = new BButton(BRect(), "getthemes", B_TRANSLATE("More themes"), new BMessage(skOnlineThemes), B_FOLLOW_RIGHT | B_FOLLOW_TOP); AddChild(fMoreThemesBtn); fMoreThemesBtn->SetTarget(this); fMoreThemesBtn->ResizeToPreferred(); fDefaultsBtn = new BButton(BRect(), "defaults", B_TRANSLATE("Defaults"), new BMessage(B_PREF_APP_SET_DEFAULTS), B_FOLLOW_RIGHT | B_FOLLOW_TOP); AddChild(fDefaultsBtn); fDefaultsBtn->ResizeToPreferred(); fDefaultsBtn->SetTarget(this); fApplyBtn = new BButton(BRect(), "apply", B_TRANSLATE("Apply"), new BMessage(kApplyThemeBtn), B_FOLLOW_RIGHT | B_FOLLOW_TOP); AddChild(fApplyBtn); fApplyBtn->ResizeToPreferred(); fApplyBtn->SetTarget(this); float widest = max_c(fSetShotBtn->Bounds().Width(), fMoreThemesBtn->Bounds().Width()); widest = max_c(widest, fDefaultsBtn->Bounds().Width()); widest = max_c(widest, fApplyBtn->Bounds().Width()); float height = fSetShotBtn->Bounds().Height(); fSetShotBtn->ResizeTo(widest, height); fMoreThemesBtn->ResizeTo(widest, height); fDefaultsBtn->ResizeTo(widest, height); fApplyBtn->ResizeTo(widest, height); fSetShotBtn->MoveTo(frame.right - widest, frame.top + 5.0); fMoreThemesBtn->MoveTo(frame.right - widest, fSetShotBtn->Frame().bottom + 10.0); fApplyBtn->MoveTo(frame.right - widest, fNewBtn->Frame().top - fApplyBtn->Bounds().Height() - 10); fDefaultsBtn->MoveTo(frame.right - widest, fNewBtn->Frame().top - (fApplyBtn->Bounds().Height() + 10) * 2); // add the preview screen BRect preview_frame(fNewBtn->Frame().left, fThemeListSV->Frame().top, frame.right - widest - 10, fNewBtn->Frame().top - 10); fTabView = new BTabView(preview_frame, "tabs"); fTabView->SetViewPanelBgColor(); AddChild(fTabView); preview_frame = fTabView->ContainerView()->Bounds(); fScreenshotTab = new BView(preview_frame, B_TRANSLATE("Screenshot"), B_FOLLOW_ALL, B_WILL_DRAW); fScreenshotTab->SetViewPanelBgColor(); //AddChild(fScreenshotTab); fTabView->AddTab(fScreenshotTab); fTabView->Select(0L); fScreenshotPane = new ScreenshotView(preview_frame, "screenshot", B_FOLLOW_ALL, B_WILL_DRAW); fScreenshotTab->AddChild(fScreenshotPane); fScreenshotPane->SetViewPanelBgColor(); fScreenshotText = new BStringView(BRect(), "sshotnone", B_TRANSLATE("No theme selected"), B_FOLLOW_ALL); fScreenshotText->SetFontSize(20.0); fScreenshotText->SetAlignment(B_ALIGN_CENTER); fScreenshotTab->AddChild(fScreenshotText); fScreenshotText->SetViewPanelBgColor(); fScreenshotText->ResizeToPreferred(); fScreenshotText->ResizeTo(fScreenshotTab->Bounds().Width() - 10.0, fScreenshotText->Bounds().Height()); fScreenshotText->MoveTo(fScreenshotTab->Bounds().left + 5.0, ((fScreenshotTab->Frame().Height() - fScreenshotText->Frame().Height()) / 2.0)); // TODO: real preview from actual data and BControlLook & co //fTabView->AddTab(new BStringView(fTabView->ContainerView()->Bounds(), B_TRANSLATE("Preview"), "TODO", B_FOLLOW_ALL, B_WILL_DRAW)); // TODO: theme informations fDetails = new BTextView(preview_frame, B_TRANSLATE("Details"), preview_frame.InsetByCopy(3,3), B_FOLLOW_ALL, B_WILL_DRAW); fDetails->SetText("TODO"); fTabView->AddTab(fDetails); // Theme hyperlink /* BStringView* hlink = new BStringView(BRect(), "theme_hyperlink", B_TRANSLATE("More themes online"), new BMessage(skOnlineThemes), B_FOLLOW_RIGHT | B_FOLLOW_BOTTOM); AddChild(hlink); hlink->SetClickText(hlink->GetText(), *this); hlink->ResizeToPreferred(); hlink->MoveTo(frame.right - hlink->Bounds().Width(), fNewBtn->Frame().top + 5); */ // the addons list view preview_frame = fTabView->ContainerView()->Bounds(); preview_frame.right -= B_V_SCROLL_BAR_WIDTH; fAddonList = new BListView(preview_frame/*BRect()*/, "addonlist"); PopulateAddonList(); fAddonListSV = new BScrollView(B_TRANSLATE("Options"), fAddonList, B_FOLLOW_LEFT|B_FOLLOW_TOP, 0, false, true); fAddonList->SetSelectionMessage(new BMessage(kThemeSelected)); fAddonList->SetInvocationMessage(new BMessage(kApplyThemeBtn)); fAddonList->SetTarget(this); fTabView->AddTab(fAddonListSV); PopulateThemeList(); }
static void testInvertRect(BView *view, BRect frame) { frame.InsetBy(2, 2); view->InvertRect(frame); }
void BStatusBar::Draw(BRect updateRect) { rgb_color backgroundColor = LowColor(); font_height fontHeight; GetFontHeight(&fontHeight); BRect barFrame = _BarFrame(&fontHeight); BRect outerFrame = barFrame.InsetByCopy(-2, -2); BRegion background(updateRect); background.Exclude(outerFrame); FillRegion(&background, B_SOLID_LOW); // Draw labels/texts BRect rect = outerFrame; rect.top = 0; rect.bottom = outerFrame.top - 1; if (updateRect.Intersects(rect)) { // update labels BString leftText; leftText << fLabel << fText; BString rightText; rightText << fTrailingText << fTrailingLabel; float baseLine = ceilf(fontHeight.ascent) + 1; fTextDivider = rect.right; BFont font; GetFont(&font); if (rightText.Length()) { font.TruncateString(&rightText, B_TRUNCATE_BEGINNING, rect.Width()); fTextDivider -= StringWidth(rightText.String()); } if (leftText.Length()) { float width = max_c(0.0, fTextDivider - rect.left); font.TruncateString(&leftText, B_TRUNCATE_END, width); } rgb_color textColor = ui_color(B_PANEL_TEXT_COLOR); if (backgroundColor != ui_color(B_PANEL_BACKGROUND_COLOR)) { if (backgroundColor.Brightness() > 100) textColor = make_color(0, 0, 0, 255); else textColor = make_color(255, 255, 255, 255); } SetHighColor(textColor); if (leftText.Length()) DrawString(leftText.String(), BPoint(rect.left, baseLine)); if (rightText.Length()) DrawString(rightText.String(), BPoint(fTextDivider, baseLine)); } // Draw bar if (!updateRect.Intersects(outerFrame)) return; rect = outerFrame; if (be_control_look != NULL) { be_control_look->DrawStatusBar(this, rect, updateRect, backgroundColor, fBarColor, _BarPosition(barFrame)); return; } // First bevel SetHighColor(tint_color(backgroundColor, B_DARKEN_1_TINT)); StrokeLine(rect.LeftBottom(), rect.LeftTop()); StrokeLine(rect.RightTop()); SetHighColor(tint_color(backgroundColor, B_LIGHTEN_2_TINT)); StrokeLine(BPoint(rect.left + 1, rect.bottom), rect.RightBottom()); StrokeLine(BPoint(rect.right, rect.top + 1)); rect.InsetBy(1, 1); // Second bevel SetHighColor(tint_color(backgroundColor, B_DARKEN_4_TINT)); StrokeLine(rect.LeftBottom(), rect.LeftTop()); StrokeLine(rect.RightTop()); SetHighColor(backgroundColor); StrokeLine(BPoint(rect.left + 1, rect.bottom), rect.RightBottom()); StrokeLine(BPoint(rect.right, rect.top + 1)); rect = barFrame; rect.right = _BarPosition(barFrame); // draw bar itself if (rect.right >= rect.left) { // Bevel SetHighColor(tint_color(fBarColor, B_LIGHTEN_2_TINT)); StrokeLine(rect.LeftBottom(), rect.LeftTop()); StrokeLine(rect.RightTop()); SetHighColor(tint_color(fBarColor, B_DARKEN_2_TINT)); StrokeLine(BPoint(rect.left + 1, rect.bottom), rect.RightBottom()); StrokeLine(BPoint(rect.right, rect.top + 1)); // filling SetHighColor(fBarColor); FillRect(rect.InsetByCopy(1, 1)); } if (rect.right < barFrame.right) { // empty space rect.left = rect.right + 1; rect.right = barFrame.right; SetHighColor(tint_color(backgroundColor, B_LIGHTEN_MAX_TINT)); FillRect(rect); } }
static void testFillArc(BView *view, BRect frame) { frame.InsetBy(2, 2); view->FillArc(frame, 45, 180); }
void CColorSlider::Draw(BRect /* updateRect */) { BRect r = Bounds(); if (IsFocus()) { SetHighColor(keyboard_navigation_color()); StrokeRect(r); } else { SetHighColor(kB_GrayTable[13]); StrokeLine(r.LeftTop(), r.LeftBottom()); StrokeLine(r.LeftTop(), r.RightTop()); SetHighColor(kWhite); StrokeLine(r.LeftBottom(), r.RightBottom()); StrokeLine(r.RightTop(), r.RightBottom()); } r.InsetBy(1, 1); BRect knob; float m = std::min(r.Width(), r.Height()), a; knob.Set(1, 1, m + 1, m + 1); if (fHorizontal) { a = r.Width() - m; knob.OffsetBy(a * fValue, 0); BeginLineArray((int)a + 1); float x = r.left; for (;x <= r.right; x += 1) { float v = (x - 1) / a; rgb_color c = fMax; c.red = (int)((float)c.red * v); c.green = (int)((float)c.green * v); c.blue = (int)((float)c.blue * v); float X = x < knob.left ? x : x + knob.Width(); AddLine(BPoint(X, r.top), BPoint(X, r.bottom), c); } EndLineArray(); } else { a = r.Height() - m; knob.OffsetBy(0, a * (1.0 - fValue)); BeginLineArray((int)a + 1); float y = r.top; for (;y <= r.bottom; y += 1) { float v = 1.0 - (y - 1) / a; rgb_color c = fMax; c.red = (int)((float)c.red * v); c.green = (int)((float)c.green * v); c.blue = (int)((float)c.blue * v); float Y = y < knob.top ? y : y + knob.Height(); AddLine(BPoint(r.left, Y), BPoint(r.right, Y), c); } EndLineArray(); } SetHighColor(kWhite); StrokeLine(knob.LeftTop(), knob.LeftBottom()); StrokeLine(knob.LeftTop(), knob.RightTop()); SetHighColor(kB_GrayTable[13]); StrokeLine(knob.LeftBottom(), knob.RightBottom()); StrokeLine(knob.RightTop(), knob.RightBottom()); SetHighColor(kGray); knob.InsetBy(1, 1); StrokeRect(knob); knob.InsetBy(1, 1); rgb_color c = fMax; c.red = (int)((float)c.red * fValue); c.green = (int)((float)c.green * fValue); c.blue = (int)((float)c.blue * fValue); SetHighColor(c); FillRect(knob); SetHighColor(kBlack); Sync(); } /* CColorSlider::Draw */
static void testStrokeArc(BView *view, BRect frame) { frame.InsetBy(2, 2); view->StrokeArc(frame, 45, 180); }
virtual void DrawContent() { BRect b = Frame(); BMenu *parent = Menu(); BPoint loc = parent->PenLocation(); enum { W_CHAR = 0, A_CHAR = 1, OPEN_CHAR = 2, CLOSE_CHAR = 3, SPACE_CHAR = 4, NUM_CHARS = 5 }; float escapements[NUM_CHARS]; BFont font; parent->GetFont(&font); font.GetEscapements("WA() ", NUM_CHARS, escapements); for (int32 i=0; i<NUM_CHARS; i++) { escapements[i] *= font.Size(); } const float blockWidth = escapements[W_CHAR]+escapements[A_CHAR]; const rgb_color old_col = parent->HighColor(); font_height fh; const bool showInitial = !CompareColors(fInitialColor, fColor); b.InsetBy(1, 1); b.bottom -= 1; b.left = loc.x; if (showInitial) { parent->GetFontHeight(&fh); parent->DrawString("(", BPoint(b.left, loc.y+fh.ascent)); } b.left += escapements[OPEN_CHAR]; b.InsetBy(2, 2); b.right = b.left + escapements[W_CHAR]; if (showInitial) { parent->SetHighColor(fInitialColor); parent->FillRect(b); } b.InsetBy(-1, -1); if (showInitial) { parent->SetHighColor(old_col); parent->StrokeRect(b); } b.InsetBy(-1, -1); if (showInitial) { parent->DrawString(")", BPoint(b.right+1, loc.y+fh.ascent)); } b.right += escapements[CLOSE_CHAR] + 1; b.left = b.right + escapements[SPACE_CHAR]; b.right = b.left + blockWidth; parent->SetHighColor(fColor); parent->FillRect(b); parent->SetHighColor(old_col); b.InsetBy(-1, -1); parent->StrokeRect(b); parent->MovePenTo(b.right + escapements[SPACE_CHAR]*2 + 2, loc.y); BMenuItem::DrawContent(); }
CDRWView::CDRWView(BRect size) : BView(size, "CDRWView", B_FOLLOW_NONE, B_WILL_DRAW) { BRect r; char temp_char[100]; SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); // CDRW BOX IconLabel* CDRWLabel = new IconLabel(BRect(0, 0, 19 + be_bold_font->StringWidth(""), 19), "", "cd_16.png"); CDRWLabel->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); CDRWLabel->SetDrawingMode(B_OP_ALPHA); r = Bounds(); r.InsetBy(5.0, 5.0); r.bottom = r.top + 160; BBox* CDRWBox = new BBox(r, "CDRWBox", B_FOLLOW_NONE, B_WILL_DRAW | B_FRAME_EVENTS, B_PLAIN_BORDER); CDRWBox->SetLabel(CDRWLabel); AddChild(CDRWBox); // BlankMenu (CDRWBOX) r = CDRWBox->Bounds(); r.InsetBy(5.0, 5.0); r.top += 25; fBlankMenu = new BMenu("Select"); fBlankMenu->SetLabelFromMarked(true); BMenuField* blankMenuField = new BMenuField(r, "blank", "Blank:", fBlankMenu); blankMenuField->SetDivider(be_plain_font->StringWidth("Blank: ")); CDRWBox->AddChild(blankMenuField); fBlankMenu->AddItem(new BMenuItem("Full", new BMessage(BLANK_FULL))); fBlankMenu->AddItem(new BMenuItem("Fast", new BMessage(BLANK_FAST))); fBlankMenu->AddItem(new BMenuItem("Session", new BMessage(BLANK_SESSION))); fBlankMenu->AddItem(new BMenuItem("Track", new BMessage(BLANK_TRACK))); fBlankMenu->AddItem(new BMenuItem("Track tail", new BMessage(BLANK_TRACK_TAIL))); fBlankMenu->AddItem(new BMenuItem("Unreserve", new BMessage(BLANK_UNRES))); fBlankMenu->AddItem(new BMenuItem("Unclose", new BMessage(BLANK_UNCLOSE))); r = CDRWBox->Bounds(); r.left = 150; r.right = 278; r.top = 60; r.bottom = 128; IconLabel* BGLabel1 = new IconLabel(r, "", "cdrw_64.png"); //cdrw_64.png BGLabel1->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); BGLabel1->SetDrawingMode(B_OP_BLEND); CDRWBox->AddChild(BGLabel1); IconLabel* BGLabel2 = new IconLabel(r, "", "erase_64.png"); //erase_64.png BGLabel2->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); BGLabel2->SetDrawingMode(B_OP_BLEND); CDRWBox->AddChild(BGLabel2); // BlankSpeed r = CDRWBox->Bounds(); r.InsetBy(5.0, 5.0); r.top += 15; r.left = 155; r.right = 270; sprintf(temp_char,"Blank Speed [%dx]", BLANK_SPD); fBlankSpeedSlider = new BSlider(r, "BlankSpeed", temp_char, new BMessage(BLANK_SPEED_CHANGE), 0, 5, B_BLOCK_THUMB, B_FOLLOW_NONE); fBlankSpeedSlider->SetHashMarks(B_HASH_MARKS_BOTTOM); fBlankSpeedSlider->SetHashMarkCount(6); fBlankSpeedSlider->SetValue((int32)(BLANK_SPD / 2) - 1); CDRWBox->AddChild(fBlankSpeedSlider); // BlankButton r = CDRWBox->Bounds(); r.InsetBy(5.0, 5.0); r.top += 10; r.bottom = r.top + 50; r.left = 330; r.right = 415; fBlankButton = new BButton(r, "BlankButton", "Blank!", new BMessage(BLANK_IT_NOW)); CDRWBox->AddChild(fBlankButton); }
void BTabView::DrawBox(BRect selTabRect) { if (be_control_look != NULL) { BRect rect(Bounds()); rect.top = selTabRect.bottom; if (fBorderStyle != B_FANCY_BORDER) rect.top += 1.0f; rgb_color base = ui_color(B_PANEL_BACKGROUND_COLOR); if (fBorderStyle == B_FANCY_BORDER) be_control_look->DrawGroupFrame(this, rect, rect, base); else { uint32 borders = BControlLook::B_TOP_BORDER; if (fBorderStyle == B_PLAIN_BORDER) borders = BControlLook::B_ALL_BORDERS; be_control_look->DrawBorder(this, rect, rect, base, B_PLAIN_BORDER, 0, borders); } return; } BRect rect = Bounds(); BRect lastTabRect = TabFrame(CountTabs() - 1); rgb_color noTint = ui_color(B_PANEL_BACKGROUND_COLOR); rgb_color lightenMax = tint_color(noTint, B_LIGHTEN_MAX_TINT); rgb_color darken1 = tint_color(noTint, B_DARKEN_1_TINT); rgb_color darken2 = tint_color(noTint, B_DARKEN_2_TINT); rgb_color darken4 = tint_color(noTint, B_DARKEN_4_TINT); BeginLineArray(12); int32 offset = (int32)ceilf(selTabRect.Height() / 2.0); // outer lines AddLine(BPoint(rect.left, rect.bottom - 1), BPoint(rect.left, selTabRect.bottom), darken2); if (selTabRect.left >= rect.left + 1) AddLine(BPoint(rect.left + 1, selTabRect.bottom), BPoint(selTabRect.left, selTabRect.bottom), darken2); if (lastTabRect.right + offset + 1 <= rect.right - 1) AddLine(BPoint(lastTabRect.right + offset + 1, selTabRect.bottom), BPoint(rect.right - 1, selTabRect.bottom), darken2); AddLine(BPoint(rect.right, selTabRect.bottom + 2), BPoint(rect.right, rect.bottom), darken2); AddLine(BPoint(rect.right - 1, rect.bottom), BPoint(rect.left + 2, rect.bottom), darken2); // inner lines rect.InsetBy(1, 1); selTabRect.bottom += 1; AddLine(BPoint(rect.left, rect.bottom - 2), BPoint(rect.left, selTabRect.bottom), lightenMax); if (selTabRect.left >= rect.left + 1) AddLine(BPoint(rect.left + 1, selTabRect.bottom), BPoint(selTabRect.left, selTabRect.bottom), lightenMax); if (selTabRect.right + offset + 1 <= rect.right - 2) AddLine(BPoint(selTabRect.right + offset + 1, selTabRect.bottom), BPoint(rect.right - 2, selTabRect.bottom), lightenMax); AddLine(BPoint(rect.right, selTabRect.bottom), BPoint(rect.right, rect.bottom), darken4); AddLine(BPoint(rect.right - 1, rect.bottom), BPoint(rect.left, rect.bottom), darken4); // soft inner bevel at right/bottom rect.right--; rect.bottom--; AddLine(BPoint(rect.right, selTabRect.bottom + 1), BPoint(rect.right, rect.bottom), darken1); AddLine(BPoint(rect.right - 1, rect.bottom), BPoint(rect.left + 1, rect.bottom), darken1); EndLineArray(); }
BamKeysPrefsWindow::BamKeysPrefsWindow() : BWindow(BRect(40, 30, 40 + WIDTH, 30 + HEIGHT), "BamKeys", B_TITLED_WINDOW, B_NOT_ZOOMABLE)// | B_NOT_RESIZABLE) { fModified = false; fRootView = new BBox(BRect(0, 0, WIDTH, HEIGHT), "root_view", B_FOLLOW_ALL, B_WILL_DRAW, B_PLAIN_BORDER); fRootView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); AddChild(fRootView); // Screen area selection box fScreenBox = new BBox(BRect(10, 10, ((WIDTH / 3) * 2) - 5, (HEIGHT - 50)), "screen_box", B_FOLLOW_ALL, B_WILL_DRAW, B_FANCY_BORDER); BRect gridRect = fScreenBox->Frame(); gridRect.OffsetTo(0, 0); gridRect.InsetBy(5, 5); fGrid = new BamKeysGridControl(gridRect, "screen_grid", "", new BMessage('grid')); fScreenBox->AddChild(fGrid); // Settings Box fSettingBox = new BBox(BRect(((WIDTH / 3) * 2) + 5, 10, WIDTH - 10, (HEIGHT - 50)), "settings_box", B_FOLLOW_RIGHT | B_FOLLOW_TOP_BOTTOM, B_WILL_DRAW, B_FANCY_BORDER); BRect itmRect = fSettingBox->Frame(); itmRect.Set(5, 10, itmRect.Width() - 5, (itmRect.Height() - 10) / 8); // Filter Enabled fChkEnabled = new BCheckBox(itmRect, "chkGrid", "Enable BamKeys", new BMessage('fltr'), B_FOLLOW_TOP | B_FOLLOW_RIGHT); fChkEnabled->SetValue(fGrid->IsFiltering() ? B_CONTROL_ON : B_CONTROL_OFF); fSettingBox->AddChild(fChkEnabled); itmRect.OffsetBy(0, itmRect.Height()); // Rows and Columns int32 rows; int32 columns; fGrid->GetSize(&rows, &columns); BPopUpMenu *mnuRows = new BPopUpMenu(""); for (int i = 1; i <= MAX_DIVIDE; i++) { BString numb(""); numb << i; BMenuItem *mnuItem = new BMenuItem(numb.String(), new BMessage('rowC')); mnuRows->AddItem(mnuItem); if (i == rows) { mnuItem->SetMarked(true); } } fMnuFldRows = new BMenuField(itmRect, "mnuRows", "Rows:", mnuRows, B_FOLLOW_TOP | B_FOLLOW_RIGHT); fSettingBox->AddChild(fMnuFldRows); itmRect.OffsetBy(0, itmRect.Height()); BPopUpMenu *mnuColumns = new BPopUpMenu(""); for (int i = 1; i <= MAX_DIVIDE; i++) { BString numb(""); numb << i; BMenuItem *mnuItem = new BMenuItem(numb.String(), new BMessage('colC')); mnuColumns->AddItem(mnuItem); if (i == columns) { mnuItem->SetMarked(true); } } fMnuFldColumns = new BMenuField(itmRect, "mnuCols", "Columns:", mnuColumns, B_FOLLOW_TOP | B_FOLLOW_RIGHT); fSettingBox->AddChild(fMnuFldColumns); itmRect.OffsetBy(0, itmRect.Height()); // Hotkey BRect stringRect(itmRect); stringRect.OffsetBy(0, -(itmRect.Height() / 3)); fStrHotKey = new BStringView(stringRect, "lblModifiers", "Modifiers:", B_FOLLOW_TOP | B_FOLLOW_LEFT); fSettingBox->AddChild(fStrHotKey); itmRect.OffsetBy(0, itmRect.Height()); // Caps Lock fCapsLock = new BamKeysKeyView(itmRect, "capsLock", B_CAPS_LOCK, B_FOLLOW_TOP | B_FOLLOW_LEFT); fSettingBox->AddChild(fCapsLock); itmRect.OffsetBy(0, itmRect.Height()); // Num Lock fNumLock = new BamKeysKeyView(itmRect, "numLock", B_NUM_LOCK, B_FOLLOW_TOP | B_FOLLOW_LEFT); fSettingBox->AddChild(fNumLock); itmRect.OffsetBy(0, itmRect.Height()); // Scroll Lock fScrlLock = new BamKeysKeyView(itmRect, "scrollLock", B_SCROLL_LOCK, B_FOLLOW_TOP | B_FOLLOW_LEFT); fSettingBox->AddChild(fScrlLock); itmRect.OffsetBy(0, itmRect.Height()); BPoint half = itmRect.RightBottom(); half.x = half.x / 2; itmRect.SetRightBottom(half); // Command Keys fLeftCommand = new BamKeysKeyView(itmRect, "leftCommand", B_LEFT_COMMAND_KEY, B_FOLLOW_TOP | B_FOLLOW_LEFT); fSettingBox->AddChild(fLeftCommand); itmRect.OffsetBy((itmRect.Width() + 5), 0); fRightCommand = new BamKeysKeyView(itmRect, "rightCommand", B_RIGHT_COMMAND_KEY, B_FOLLOW_TOP | B_FOLLOW_LEFT); fSettingBox->AddChild(fRightCommand); itmRect.OffsetBy(-(itmRect.Width() + 5), itmRect.Height()); // Ctrl Keys fLeftControl = new BamKeysKeyView(itmRect, "leftControl", B_LEFT_CONTROL_KEY, B_FOLLOW_TOP | B_FOLLOW_LEFT); fSettingBox->AddChild(fLeftControl); itmRect.OffsetBy((itmRect.Width() + 5), 0); fRightControl = new BamKeysKeyView(itmRect, "rightControl", B_RIGHT_CONTROL_KEY, B_FOLLOW_TOP | B_FOLLOW_LEFT); fSettingBox->AddChild(fRightControl); itmRect.OffsetBy(-(itmRect.Width() + 5), itmRect.Height()); // Option Keys fLeftOption = new BamKeysKeyView(itmRect, "leftOption", B_LEFT_OPTION_KEY, B_FOLLOW_TOP | B_FOLLOW_LEFT); fSettingBox->AddChild(fLeftOption); itmRect.OffsetBy((itmRect.Width() + 5), 0); fRightOption = new BamKeysKeyView(itmRect, "rightOption", B_RIGHT_OPTION_KEY, B_FOLLOW_TOP | B_FOLLOW_LEFT); fSettingBox->AddChild(fRightOption); itmRect.OffsetBy(-(itmRect.Width() + 5), itmRect.Height()); // Shift Keys fLeftShift = new BamKeysKeyView(itmRect, "leftShift", B_LEFT_SHIFT_KEY, B_FOLLOW_TOP | B_FOLLOW_LEFT); fSettingBox->AddChild(fLeftShift); itmRect.OffsetBy((itmRect.Width() + 5), 0); fRightShift = new BamKeysKeyView(itmRect, "rightShift", B_RIGHT_SHIFT_KEY, B_FOLLOW_TOP | B_FOLLOW_LEFT); fSettingBox->AddChild(fRightShift); itmRect.OffsetBy(-(itmRect.Width() + 5), itmRect.Height()); // Buttons that do things! fBtnDefaults = new BButton(BRect(10, HEIGHT - 35, 85, HEIGHT - 15), "btn_defaults", "Defaults", new BMessage('deft'), B_FOLLOW_BOTTOM | B_FOLLOW_LEFT); fBtnRevert = new BButton(BRect(95, HEIGHT - 35, 170, HEIGHT - 15), "btn_revert", "Revert", new BMessage('revt'), B_FOLLOW_BOTTOM | B_FOLLOW_LEFT); fRootView->AddChild(fScreenBox); fRootView->AddChild(fSettingBox, fScreenBox); fRootView->AddChild(fBtnDefaults, fSettingBox); fRootView->AddChild(fBtnRevert, fBtnDefaults); // If the fGrid couldn't load it settings, force our applications' defaults. if (fGrid->InitCheck() != B_OK) { BMessage *defaults = new BMessage('deft'); MessageReceived(defaults); fGrid->SaveSettings(); delete defaults; fModified = false; } fBtnRevert->SetEnabled(fModified); }