//calculate the view positions of all the MatrixLayoutItems //on the items list with offsets based upon matrixLeft //and matrixTop void LayoutMatrix :: Calc( const float paramMatrixLeft, const float paramMatrixTop, sem_id paramSemID) { int32 numItems = mpItemsList->CountItems(); if (!numItems) return; if (acquire_sem(paramSemID) != B_NO_ERROR) { warning(myPrefs->FailAqSem); return; } bool hasPopUpMenu = false; TextItem * scratchTextItem; for ( int i = 0; i < numItems; i++) { ((LayoutMatrixItem *)(mpItemsList->ItemAt(i)))->Calc(); } float widest = 0; float tallest = 0; int32 index = 0; for ( int i = 0; i < numItems; i++) { LayoutMatrixItem * lmi = (LayoutMatrixItem *)mpItemsList->ItemAt(index++); if (lmi->mfWidthPref > widest) { widest = lmi->mfWidthPref; } if (lmi->mfHeightPref > tallest) { tallest = lmi->mfHeightPref; } } if (mui32Flags & SAMESIZE) {//SAMESIZE makes all items the same size as the largest index = 0; //Resize all items to match largest: for ( uint32 i = 0; i < mui32Rows; i++) { for ( uint32 j = 0; j < mui32Columns; j++) { LayoutMatrixItem * lmi = (LayoutMatrixItem *)mpItemsList->ItemAt(index++); switch (lmi->mui32Kind) { case KIND_MYSPACER: { MySpacer * scratchMySpacer = (MySpacer *)lmi->mpItem; if (scratchMySpacer->mbSAMEFromWidest) { scratchMySpacer->ResizeTo(widest, tallest); } } break; case KIND_MYBUTTON: { BButton * scratchMyButton = (BButton *)lmi->mpItem; scratchMyButton->ResizeTo(widest, tallest); } break; case KIND_MYSLIDER: { BSlider * scratchMySlider = (BSlider *)lmi->mpItem; scratchMySlider->ResizeTo(widest, tallest); } break; case KIND_STRINGDRAWER: { BStringView * scratchMyStringView = (BStringView *)lmi->mpItem; scratchMyStringView->ResizeTo(widest, tallest); } break; case KIND_MYCHECKBOX: { BCheckBox * scratchMyCheckBox = (BCheckBox *)lmi->mpItem; scratchMyCheckBox->ResizeTo(widest, tallest); } break; case KIND_MYPICTUREBUTTON: { BPictureButton * scratchMyPictureButton = (BPictureButton *)lmi->mpItem; scratchMyPictureButton->ResizeTo(widest, tallest); } break; case KIND_MYCOLORCONTROL: { BColorControl * scratchMyColorControl = (BColorControl *)lmi->mpItem; scratchMyColorControl->ResizeTo(widest, tallest); } break; case KIND_MYSTATUSBAR: { BStatusBar * scratchMyStatusBar = (BStatusBar *)lmi->mpItem; scratchMyStatusBar->ResizeTo(widest, tallest); } break; case KIND_UINT32CONTROL: { UInt32Control * scratchUInt32Control = (UInt32Control *)lmi->mpItem; scratchUInt32Control->ResizeTo(widest, tallest); } break; case KIND_FLOATCONTROL: { FloatControl * scratchFloatControl = (FloatControl *)lmi->mpItem; scratchFloatControl->ResizeTo(widest, tallest); } break; case KIND_STRINGCONTROL: { StringControl * scratchStringControl = (StringControl *)lmi->mpItem; scratchStringControl->ResizeTo(widest, tallest); } break; } } } } index = 0; //move every item based upon size and padding: const float hpad = 2;//horizontal spacing between items const float vpad = 2;//vertical spacing between items float localLeft; float localTop = vpad + paramMatrixTop; float excessRight = 0, excessRightHold = 0; float excessBottom = 0, excessBottomHold = 0; for ( uint32 ii = 0; ii < mui32Rows; ii++) { localLeft = paramMatrixLeft + hpad; float columnRight = 0; excessBottom = 0; for ( uint32 jj = 0; jj < mui32Columns; jj++) { excessRight = 0; LayoutMatrixItem * lmi = (LayoutMatrixItem *)mpItemsList->ItemAt(index++); switch (lmi->mui32Kind) { case KIND_MYPOPUPMENU: { hasPopUpMenu = true; MyPopUpMenu * scratchPopUpMenu = (MyPopUpMenu *)lmi->mpItem; scratchPopUpMenu->mfLabelLeft = localLeft; excessRightHold = lmi->mfWidthPref + scratchPopUpMenu->mfLabelWidth; scratchPopUpMenu->SetLeft(localLeft); scratchPopUpMenu->mfLabelTop = localTop; if ((scratchPopUpMenu->mfHeight + 9) > scratchPopUpMenu->mfLabelHeight) { excessBottomHold = scratchPopUpMenu->mfHeight + 10; } else { excessBottomHold = scratchPopUpMenu->mfLabelHeight + 1; } } break; case KIND_MYTEXTVIEW: { BTextView * scratchTextView = (BTextView *)lmi->mpItem; scratchTextView->MoveTo(localLeft, localTop); excessRightHold = ((MyTextView *)scratchTextView)->mfWidth; excessBottomHold = ((MyTextView *)scratchTextView)->mfHeight; } break; case KIND_MYLISTVIEW: { BListView * scratchListView = (BListView *)lmi->mpItem; scratchListView->MoveTo(localLeft, localTop); ((BListView *)(lmi->mpItem))->GetPreferredSize(&excessRightHold, &excessBottomHold); } break; case KIND_MYBUTTON: { BButton * scratchMyButton = (BButton *)lmi->mpItem; scratchMyButton->MoveTo(localLeft, localTop); excessRightHold = lmi->mfWidthPref; excessBottomHold = lmi->mfHeightPref; } break; case KIND_MYSLIDER: { BSlider * scratchMySlider = (BSlider *)lmi->mpItem; scratchMySlider->MoveTo(localLeft, localTop); excessRightHold = lmi->mfWidthPref; excessBottomHold = lmi->mfHeightPref; } break; case KIND_MYSPACER: { MySpacer * scratchMySpacer = (MySpacer *)lmi->mpItem; if ( (mui32Flags & SAMESIZE) && scratchMySpacer->mbSAMEFromWidest) { excessRightHold = widest; excessBottomHold = tallest; } else { excessRightHold = scratchMySpacer->mfPreferredWidth; excessBottomHold = scratchMySpacer->mfPreferredHeight; } } break; case KIND_MYRADIOVIEW: { MyRadioView * scratchRadioView = (MyRadioView *)lmi->mpItem; scratchRadioView->MoveTo(localLeft, localTop); excessRightHold = lmi->mfWidthPref; excessBottomHold = lmi->mfHeightPref; } break; case KIND_STRINGDRAWER: { BStringView * scratchMyStringView = (BStringView *)lmi->mpItem; TextItem * scratchTextItem = ((MyStringDrawer *)lmi->mpItem)->GetTextItem(); scratchTextItem->mfLeft = localLeft; scratchTextItem->mfTop = localTop + lmi->mfHeightPref - ((MyStringDrawer *)lmi->mpItem)->mfDescender - vpad; scratchMyStringView->MoveTo(localLeft, localTop); excessRightHold = lmi->mfWidthPref; excessBottomHold = lmi->mfHeightPref; } break; case KIND_MYCHECKBOX: { BCheckBox * scratchMyCheckBox = (BCheckBox *)lmi->mpItem; scratchMyCheckBox->MoveTo(localLeft, localTop + 1); excessRightHold = lmi->mfWidthPref; excessBottomHold = lmi->mfHeightPref + 1; } break; case KIND_MYPICTUREBUTTON: { BPictureButton * scratchMyPictureButton = (BPictureButton *)lmi->mpItem; scratchMyPictureButton->MoveTo(localLeft, localTop); excessRightHold = scratchMyPictureButton->Bounds().Width() + 1; excessBottomHold = scratchMyPictureButton->Bounds().Height() + 1; } break; case KIND_MYCOLORCONTROL: { BColorControl * scratchMyColorControl = (BColorControl *)lmi->mpItem; scratchMyColorControl->MoveTo(localLeft, localTop); excessRightHold = lmi->mfWidthPref; excessBottomHold = lmi->mfHeightPref; ; } break; case KIND_MYSTATUSBAR: { MyStatusBar * scratchMyStatusBar = (MyStatusBar *)lmi->mpItem; scratchMyStatusBar->MoveTo(localLeft, localTop); excessRightHold = lmi->mfWidthPref; excessBottomHold = lmi->mfHeightPref; } break; case KIND_UINT32CONTROL: { UInt32Control * scratchUInt32Control = (UInt32Control *)lmi->mpItem; scratchUInt32Control->MoveTo(localLeft, localTop); excessRightHold = lmi->mfWidthPref; excessBottomHold = lmi->mfHeightPref; } break; case KIND_FLOATCONTROL: { FloatControl * scratchFloatControl = (FloatControl *)lmi->mpItem; scratchFloatControl->MoveTo(localLeft, localTop); excessRightHold = lmi->mfWidthPref; excessBottomHold = lmi->mfHeightPref; } break; case KIND_STRINGCONTROL: { StringControl * scratchStringControl = (StringControl *)lmi->mpItem; scratchStringControl->MoveTo(localLeft, localTop); excessRightHold = lmi->mfWidthPref; excessBottomHold = lmi->mfHeightPref; } break; case KIND_TEXT: scratchTextItem = (TextItem *)lmi->mpItem; scratchTextItem->mfLeft = localLeft; scratchTextItem->mfTop = localTop + lmi->mfHeightPref; excessRightHold = lmi->mfWidthPref; excessBottomHold = lmi->mfHeightPref; break; case KIND_COLORWELL: ((ColorWell *)lmi->mpItem)->mfLabelLeft = localLeft; ((ColorWell *)lmi->mpItem)->SetLeft(((ColorWell *)lmi->mpItem)->GetLeft() + localLeft); excessRightHold = lmi->mfWidthPref; ((ColorWell *)lmi->mpItem)->mfLabelTop = localTop; ((ColorWell *)lmi->mpItem)->SetTop(((ColorWell *)lmi->mpItem)->GetTop() + localTop); excessBottomHold = lmi->mfHeightPref; break; case KIND_INT8GADGET: case KIND_UINT8GADGET: case KIND_INT16GADGET: case KIND_UINT16GADGET: case KIND_INT32GADGET: case KIND_UINT32GADGET: case KIND_INT64GADGET: case KIND_UINT64GADGET: case KIND_FLOATGADGET: case KIND_HEXGADGET: case KIND_STRINGGADGET: ((GadgetBase *)lmi->mpItem)->mfLabelLeft = localLeft; ((GadgetBase *)lmi->mpItem)->SetLeft(((GadgetBase *)lmi->mpItem)->GetLeft() + localLeft); excessRightHold = lmi->mfWidthPref; ((GadgetBase *)lmi->mpItem)->mfLabelTop = localTop; ((GadgetBase *)lmi->mpItem)->SetTop(((GadgetBase *)lmi->mpItem)->GetTop() + localTop); excessBottomHold = lmi->mfHeightPref + 1; break; } if (mui32Flags & SAMESIZE) { excessRightHold = widest; excessBottomHold = tallest; } excessRightHold += hpad; if (excessRightHold > excessRight) { excessRight = excessRightHold; } localLeft += excessRight; if (mui32Columns - 1) { if (jj != (mui32Columns - 1)) { if (localLeft > columnRight) { columnRight = localLeft; } } else { columnRight = localLeft; } } else { if (localLeft > columnRight) { columnRight = localLeft; } } //mfRight is stored so that another MatrixLayout //can know where a previous one ended up if (excessBottomHold > excessBottom) { excessBottom = excessBottomHold; } } if (columnRight > mfRight) { mfRight = columnRight; } excessBottomHold += vpad; localTop += excessBottom; if (mui32Rows - 1) { if (ii != (mui32Rows - 1)) { if (localTop > mfBottom) { mfBottom = localTop; } } else { mfBottom = localTop; } } else { if (localTop > mfBottom) { mfBottom = localTop; } } //mfBottom is stored so that another MatrixLayout //can know where a previous one ended up } if (hasPopUpMenu) { mfRight += 30; } release_sem(paramSemID); }//end
BControl * DefaultMediaTheme::MakeViewFor(BParameter *parameter, const BRect *hintRect) { BRect rect; if (hintRect) rect = *hintRect; else rect.Set(0, 0, 50, 100); switch (parameter->Type()) { case BParameter::B_NULL_PARAMETER: // there is no default view for a null parameter return NULL; case BParameter::B_DISCRETE_PARAMETER: { BDiscreteParameter &discrete = static_cast<BDiscreteParameter &>(*parameter); if (!strcmp(discrete.Kind(), B_ENABLE) || !strcmp(discrete.Kind(), B_MUTE) || discrete.CountItems() == 0) { // create a checkbox item BCheckBox *checkBox = new BCheckBox(rect, discrete.Name(), discrete.Name(), NULL); checkBox->ResizeToPreferred(); return checkBox; } else { // create a pop up menu field // ToDo: replace BOptionPopUp (or fix it in Antares...) // this is a workaround for a bug in BOptionPopUp - you need to // know the actual width before creating the object - very nice... BFont font; float width = 0; for (int32 i = 0; i < discrete.CountItems(); i++) { float labelWidth = font.StringWidth(discrete.ItemNameAt(i)); if (labelWidth > width) width = labelWidth; } width += font.StringWidth(discrete.Name()) + 55; rect.right = rect.left + width; BOptionPopUp *popUp = new BOptionPopUp(rect, discrete.Name(), discrete.Name(), NULL); for (int32 i = 0; i < discrete.CountItems(); i++) { popUp->AddOption(discrete.ItemNameAt(i), discrete.ItemValueAt(i)); } popUp->ResizeToPreferred(); return popUp; } } case BParameter::B_CONTINUOUS_PARAMETER: { BContinuousParameter &continuous = static_cast<BContinuousParameter &>(*parameter); if (!strcmp(continuous.Kind(), B_MASTER_GAIN) || !strcmp(continuous.Kind(), B_GAIN)) { BChannelSlider *slider = new BChannelSlider(rect, continuous.Name(), continuous.Name(), NULL, B_VERTICAL, continuous.CountChannels()); char minLabel[64], maxLabel[64]; const char *unit = continuous.Unit(); if (unit[0]) { // if we have a unit, print it next to the limit values sprintf(minLabel, "%g %s", continuous.MinValue(), continuous.Unit()); sprintf(maxLabel, "%g %s", continuous.MaxValue(), continuous.Unit()); } else { sprintf(minLabel, "%g", continuous.MinValue()); sprintf(maxLabel, "%g", continuous.MaxValue()); } slider->SetLimitLabels(minLabel, maxLabel); float width, height; slider->GetPreferredSize(&width, &height); slider->ResizeTo(width, 190); // ToDo: take BContinuousParameter::GetResponse() & ValueStep() into account! for (int32 i = 0; i < continuous.CountChannels(); i++) { slider->SetLimitsFor(i, int32(continuous.MinValue() * 1000), int32(continuous.MaxValue() * 1000)); } return slider; } BSlider *slider = new BSlider(rect, parameter->Name(), parameter->Name(), NULL, 0, 100); float width, height; slider->GetPreferredSize(&width, &height); slider->ResizeTo(100, height); return slider; } default: ERROR("BMediaTheme: Don't know parameter type: 0x%x\n", parameter->Type()); } return NULL; }