/*------------------------------------------------------------------------------*\ ( ) - \*------------------------------------------------------------------------------*/ BPicture* BmToolbarButton::CreatePicture( int32 mode, float width, float height) { const char* label = mLabel.String(); BmBitmapHandle* imageHandle = TheResources->IconByName(BmString("Button_")<<mResourceName); BBitmap* image = imageHandle ? imageHandle->bitmap : NULL; // Calc icon/label positions BFont font( be_plain_font); bool showIcons = ThePrefs->GetBool( "ShowToolbarIcons", true); BmString labelMode = ThePrefs->GetString( "ShowToolbarLabel", "Bottom"); float labelWidth = (label && labelMode != "Hide") ? font.StringWidth( label) : 0; float labelHeight = (label && labelMode != "Hide") ? TheResources->FontLineHeight( &font) : 0; float iconWidth = (showIcons && image) ? image->Bounds().Width() : 0; float iconHeight = (showIcons && image) ? image->Bounds().Height() : 0; BPoint posIcon( 0,0), posLabel( 0,0); if (showIcons && (labelMode == "Left")) { // Icon + Label/Left float d = (width-(mNeedsLatch ? DIVLATCHW : 0)-DIVW-labelWidth-iconWidth)/2; posLabel = BPoint( d,(height-labelHeight)/2); posIcon = BPoint( d+DIVW+labelWidth+(mNeedsLatch ? DIVLATCHW : 0), (height-iconHeight)/2-1); } else if (showIcons && (labelMode == "Right")) { // Icon + Label/Right float d = (width-(mNeedsLatch ? DIVLATCHW : 0)-DIVW-labelWidth-iconWidth)/2; posLabel = BPoint( d+DIVW+iconWidth,(height-labelHeight)/2); posIcon = BPoint( d,(height-iconHeight)/2-1); } else if (showIcons && (labelMode == "Top")) { // Icon + Label/top float d = (height-DIVH-labelHeight-iconHeight)/2-2; posLabel = BPoint( (width-labelWidth-(mNeedsLatch ? DIVLATCHW : 0))/2, d); posIcon = BPoint( (width-iconWidth)/2-1,d+DIVH+labelHeight); } else if (showIcons && (labelMode == "Bottom")) { // Icon + Label/bottom float d = (height-DIVH-labelHeight-iconHeight)/2; posLabel = BPoint( (width-labelWidth-(mNeedsLatch ? DIVLATCHW : 0))/2, d+DIVH+iconHeight); posIcon = BPoint( (width-iconWidth)/2-1,d); } else if (!showIcons && labelMode != "Hide") { // Label only posLabel = BPoint( (width-labelWidth-(mNeedsLatch ? DIVLATCHW : 0))/2, (height-labelHeight)/2); } else if (showIcons && labelMode == "Hide") { // Icon only posIcon = BPoint( (width-iconWidth-(mNeedsLatch ? DIVLATCHW : 0))/2, (height-iconHeight)/2); } if (mNeedsLatch) { if (labelMode == "Hide") mLatchRect.Set( posIcon.x+iconWidth+2, posIcon.y+iconHeight/2-LATCHSZ/2, width, height); else mLatchRect.Set( posLabel.x+labelWidth+2, posLabel.y+labelHeight/2-LATCHSZ/2, width, height); } else mLatchRect.Set( -1, -1, -1, -1); // Draw BRect rect(0,0,width-1,height-1); BView* view = new BView( rect, NULL, B_FOLLOW_NONE, 0); BBitmap* drawImage = new BBitmap( rect, B_RGBA32, true); drawImage->AddChild( view); drawImage->Lock(); BPicture* picture = new BPicture(); view->BeginPicture( picture); view->SetHighColor( ui_color( B_PANEL_TEXT_COLOR)); view->SetViewColor( B_TRANSPARENT_COLOR); view->SetLowColor( ui_color( B_PANEL_BACKGROUND_COLOR)); #ifndef __HAIKU__ BmToolbar* toolbar = dynamic_cast<BmToolbar*>(Parent()->Parent()); BBitmap* toolbarBackground = NULL; if (toolbar) { toolbarBackground = toolbar->BackgroundBitmap(); if (toolbarBackground) view->DrawBitmap( toolbarBackground, Frame(), rect); } if (mode == STATE_ON) { rect.InsetBy( 1, 1); view->BeginLineArray(4); view->AddLine( rect.LeftBottom(), rect.LeftTop(), BmWeakenColor(B_SHADOW_COLOR, BeShadowMod)); view->AddLine( rect.LeftTop(), rect.RightTop(), BmWeakenColor(B_SHADOW_COLOR, BeShadowMod)); view->AddLine( rect.LeftBottom(), rect.RightBottom(), ui_color( B_SHINE_COLOR)); view->AddLine( rect.RightBottom(), rect.RightTop(), ui_color( B_SHINE_COLOR)); view->EndLineArray(); } #endif // Draw Icon if (showIcons && image) { view->SetDrawingMode( B_OP_ALPHA); view->SetBlendingMode( B_PIXEL_ALPHA, B_ALPHA_OVERLAY); #ifdef __HAIKU__ BBitmap disabledImage(image); if (mode == STATE_DISABLED) { image = &disabledImage; uint8* bits = (uint8*)image->Bits(); uint32 width = image->Bounds().IntegerWidth() + 1; uint32 height = image->Bounds().IntegerWidth() + 1; uint32 bpr = image->BytesPerRow(); for (uint32 y = 0; y < height; y++) { uint8* b = bits; for (uint32 x = 0; x < width; x++) { b[3] = (uint8)(((int)b[3] * 100) >> 8); b += 4; } bits += bpr; } }
void CControlTest::Test() { // create window window_.Create(MemToolParam); // window_->Create(NULL, WindowStyle::Layered); window_->Create(NULL, WindowStyle::Sizable); window_->SetSize(520, 420); window_->CenterWindow(NULL); window_->SetText(_T("Test Window")); window_->SetVisible(true); NInstPtr<NTimerSrv> timerSrv(MemToolParam); timerSrv->startTimer(100, MakeDelegate(this, &CControlTest::PaintTest)); // setup controls NResourceLoader* loader = NUiBus::Instance().GetResourceLoader(); NAutoPtr<NShapeDraw> pBkgDraw = loader->CreateShape(MemToolParam); pBkgDraw->SetStyle(NShapeDraw::Rect)->SetFillColor(MakeArgb(255, 255, 255, 0)); window_->GetRootFrame()->SetBkgDraw(pBkgDraw); //* // VertScroll NInstPtr<NScroll> pVertScroll(MemToolParam); pVertScroll->SetPos(100, 200); pVertScroll->SetSize(16, 200); pVertScroll->SetScrollRange(4); pVertScroll->SetScrollPos(3); window_->GetRootFrame()->AddChild(pVertScroll); // HorzScroll NInstPtr<NScroll> pHorzScroll(MemToolParam); pHorzScroll->SetPos(100, 180); pHorzScroll->SetSize(200, 16); pHorzScroll->SetScrollType(true); pHorzScroll->SetScrollRange(1); pHorzScroll->SetScrollPos(1); window_->GetRootFrame()->AddChild(pHorzScroll); // Button NInstPtr<NButton> pButton1(MemToolParam); pButton1->SetLayout(NFrame::LayoutHCenter | NFrame::LayoutTop); pButton1->SetMargin(10, 10, 20, 40); window_->GetRootFrame()->AddChild(pButton1); pButton1->SetClickCallback(MakeDelegate(this, &CControlTest::OnButtonClicked)); //*/ /* // Static Image NInstPtr<NImage> pImg1(MemToolParam); pImg1->LoadImage(_T("@skin:images\\514540469.png")); window_->GetRootFrame()->AddChild(pImg1); */ NInstPtr<NFrame> posLabel(MemToolParam); posLabel->SetPos(10, 100); posLabel->SetText(_T("Pos: ")); window_->GetRootFrame()->AddChild(posLabel); NInstPtr<NFrame> rangeLabel(MemToolParam); rangeLabel->SetPos(10, 130); rangeLabel->SetText(_T("Range: ")); window_->GetRootFrame()->AddChild(rangeLabel); NInstPtr<NEdit> pEdit1(MemToolParam); pEdit1->SetLayout(NFrame::LayoutLeft | NFrame::LayoutTop); pEdit1->SetMargin(60, 100, 0, 0); pEdit1->SetAutoSize(false); pEdit1->SetSize(100, 18); pEdit1->SetTextChangeCallback(MakeDelegate(this, &CControlTest::OnEditTextChanged)); window_->GetRootFrame()->AddChild(pEdit1); NInstPtr<NEdit> pEdit2(MemToolParam); pEdit2->SetLayout(NFrame::LayoutLeft | NFrame::LayoutTop); pEdit2->SetMargin(60, 130, 0, 0); pEdit2->SetAutoSize(false); pEdit2->SetSize(100, 18); pEdit2->SetTextChangeCallback(MakeDelegate(this, &CControlTest::OnEditTextChanged)); window_->GetRootFrame()->AddChild(pEdit2); // Gif Image for(int i=0; i<0; ++ i) { NInstPtr<NImage> pImg2(MemToolParam); pImg2->LoadImage(_T("@skin:images\\3.gif")); pImg2->SetPos(i * 10, i % 5 * 50); window_->GetRootFrame()->AddChild(pImg2); } // Label NInstPtr<NFrame> label(MemToolParam); label->SetText(_T("1111111111\r\n2222222222\r\n33333333333333\r\n444444444\r\n55555555555555555\r\n")); label->GetRichText()->SetSingleLine(false); window_->GetRootFrame()->AddChild(label); // loop nui::Ui::NMsgLoop loop; loop.Loop(window_->GetNative()); // destroy window_ = NULL; }